PageRenderTime 42ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-upgrader-skins.php

https://gitlab.com/webkod3r/tripolis
PHP | 946 lines | 495 code | 124 blank | 327 comment | 99 complexity | 2cc57f84d91d3f5322ff8d4e66cfd065 MD5 | raw file
  1. <?php
  2. /**
  3. * The User Interface "Skins" for the WordPress File Upgrader
  4. *
  5. * @package WordPress
  6. * @subpackage Upgrader
  7. * @since 2.8.0
  8. */
  9. /**
  10. * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
  11. *
  12. * @package WordPress
  13. * @subpackage Upgrader
  14. * @since 2.8.0
  15. */
  16. class WP_Upgrader_Skin {
  17. public $upgrader;
  18. public $done_header = false;
  19. public $done_footer = false;
  20. public $result = false;
  21. public $options = array();
  22. /**
  23. *
  24. * @param array $args
  25. */
  26. public function __construct($args = array()) {
  27. $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
  28. $this->options = wp_parse_args($args, $defaults);
  29. }
  30. /**
  31. * @param WP_Upgrader $upgrader
  32. */
  33. public function set_upgrader(&$upgrader) {
  34. if ( is_object($upgrader) )
  35. $this->upgrader =& $upgrader;
  36. $this->add_strings();
  37. }
  38. /**
  39. * @access public
  40. */
  41. public function add_strings() {
  42. }
  43. /**
  44. *
  45. * @param string|false|WP_Error $result
  46. */
  47. public function set_result($result) {
  48. $this->result = $result;
  49. }
  50. /**
  51. *
  52. * @param bool $error
  53. * @param string $context
  54. * @param bool $allow_relaxed_file_ownership
  55. * @return type
  56. */
  57. public function request_filesystem_credentials( $error = false, $context = false, $allow_relaxed_file_ownership = false ) {
  58. $url = $this->options['url'];
  59. if ( ! $context ) {
  60. $context = $this->options['context'];
  61. }
  62. if ( !empty($this->options['nonce']) ) {
  63. $url = wp_nonce_url($url, $this->options['nonce']);
  64. }
  65. $extra_fields = array();
  66. return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
  67. }
  68. /**
  69. * @access public
  70. */
  71. public function header() {
  72. if ( $this->done_header ) {
  73. return;
  74. }
  75. $this->done_header = true;
  76. echo '<div class="wrap">';
  77. echo '<h1>' . $this->options['title'] . '</h1>';
  78. }
  79. /**
  80. * @access public
  81. */
  82. public function footer() {
  83. if ( $this->done_footer ) {
  84. return;
  85. }
  86. $this->done_footer = true;
  87. echo '</div>';
  88. }
  89. /**
  90. *
  91. * @param string|WP_Error $errors
  92. */
  93. public function error($errors) {
  94. if ( ! $this->done_header )
  95. $this->header();
  96. if ( is_string($errors) ) {
  97. $this->feedback($errors);
  98. } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
  99. foreach ( $errors->get_error_messages() as $message ) {
  100. if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
  101. $this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
  102. else
  103. $this->feedback($message);
  104. }
  105. }
  106. }
  107. /**
  108. *
  109. * @param string $string
  110. */
  111. public function feedback($string) {
  112. if ( isset( $this->upgrader->strings[$string] ) )
  113. $string = $this->upgrader->strings[$string];
  114. if ( strpos($string, '%') !== false ) {
  115. $args = func_get_args();
  116. $args = array_splice($args, 1);
  117. if ( $args ) {
  118. $args = array_map( 'strip_tags', $args );
  119. $args = array_map( 'esc_html', $args );
  120. $string = vsprintf($string, $args);
  121. }
  122. }
  123. if ( empty($string) )
  124. return;
  125. show_message($string);
  126. }
  127. /**
  128. * @access public
  129. */
  130. public function before() {}
  131. /**
  132. * @access public
  133. */
  134. public function after() {}
  135. /**
  136. * Output JavaScript that calls function to decrement the update counts.
  137. *
  138. * @since 3.9.0
  139. *
  140. * @param string $type Type of update count to decrement. Likely values include 'plugin',
  141. * 'theme', 'translation', etc.
  142. */
  143. protected function decrement_update_count( $type ) {
  144. if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
  145. return;
  146. }
  147. if ( defined( 'IFRAME_REQUEST' ) ) {
  148. echo '<script type="text/javascript">
  149. if ( window.postMessage && JSON ) {
  150. window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
  151. }
  152. </script>';
  153. } else {
  154. echo '<script type="text/javascript">
  155. (function( wp ) {
  156. if ( wp && wp.updates.decrementCount ) {
  157. wp.updates.decrementCount( "' . $type . '" );
  158. }
  159. })( window.wp );
  160. </script>';
  161. }
  162. }
  163. /**
  164. * @access public
  165. */
  166. public function bulk_header() {}
  167. /**
  168. * @access public
  169. */
  170. public function bulk_footer() {}
  171. }
  172. /**
  173. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  174. *
  175. * @package WordPress
  176. * @subpackage Upgrader
  177. * @since 2.8.0
  178. */
  179. class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
  180. public $plugin = '';
  181. public $plugin_active = false;
  182. public $plugin_network_active = false;
  183. /**
  184. *
  185. * @param array $args
  186. */
  187. public function __construct( $args = array() ) {
  188. $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
  189. $args = wp_parse_args($args, $defaults);
  190. $this->plugin = $args['plugin'];
  191. $this->plugin_active = is_plugin_active( $this->plugin );
  192. $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
  193. parent::__construct($args);
  194. }
  195. /**
  196. * @access public
  197. */
  198. public function after() {
  199. $this->plugin = $this->upgrader->plugin_info();
  200. if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
  201. // Currently used only when JS is off for a single plugin update?
  202. echo '<iframe title="' . esc_attr__( 'Update progress' ) . '" style="border:0;overflow:hidden" width="100%" height="170" src="' . wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ) . '"></iframe>';
  203. }
  204. $this->decrement_update_count( 'plugin' );
  205. $update_actions = array(
  206. 'activate_plugin' => '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>',
  207. 'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>'
  208. );
  209. if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
  210. unset( $update_actions['activate_plugin'] );
  211. /**
  212. * Filter the list of action links available following a single plugin update.
  213. *
  214. * @since 2.7.0
  215. *
  216. * @param array $update_actions Array of plugin action links.
  217. * @param string $plugin Path to the plugin file.
  218. */
  219. $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
  220. if ( ! empty($update_actions) )
  221. $this->feedback(implode(' | ', (array)$update_actions));
  222. }
  223. }
  224. /**
  225. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  226. *
  227. * @package WordPress
  228. * @subpackage Upgrader
  229. * @since 3.0.0
  230. */
  231. class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
  232. public $in_loop = false;
  233. /**
  234. * @var string|false
  235. */
  236. public $error = false;
  237. /**
  238. *
  239. * @param array $args
  240. */
  241. public function __construct($args = array()) {
  242. $defaults = array( 'url' => '', 'nonce' => '' );
  243. $args = wp_parse_args($args, $defaults);
  244. parent::__construct($args);
  245. }
  246. /**
  247. * @access public
  248. */
  249. public function add_strings() {
  250. $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
  251. /* translators: 1: Title of an update, 2: Error message */
  252. $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s');
  253. /* translators: 1: Title of an update */
  254. $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
  255. /* translators: 1: Title of an update */
  256. $this->upgrader->strings['skin_update_successful'] = __( '%1$s updated successfully.' ) . ' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>' . __( 'Show Details' ) . '</span><span class="hidden">' . __( 'Hide Details' ) . '</span></a>';
  257. $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
  258. }
  259. /**
  260. * @param string $string
  261. */
  262. public function feedback($string) {
  263. if ( isset( $this->upgrader->strings[$string] ) )
  264. $string = $this->upgrader->strings[$string];
  265. if ( strpos($string, '%') !== false ) {
  266. $args = func_get_args();
  267. $args = array_splice($args, 1);
  268. if ( $args ) {
  269. $args = array_map( 'strip_tags', $args );
  270. $args = array_map( 'esc_html', $args );
  271. $string = vsprintf($string, $args);
  272. }
  273. }
  274. if ( empty($string) )
  275. return;
  276. if ( $this->in_loop )
  277. echo "$string<br />\n";
  278. else
  279. echo "<p>$string</p>\n";
  280. }
  281. /**
  282. * @access public
  283. */
  284. public function header() {
  285. // Nothing, This will be displayed within a iframe.
  286. }
  287. /**
  288. * @access public
  289. */
  290. public function footer() {
  291. // Nothing, This will be displayed within a iframe.
  292. }
  293. /**
  294. *
  295. * @param string|WP_Error $error
  296. */
  297. public function error($error) {
  298. if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
  299. $this->error = $this->upgrader->strings[$error];
  300. if ( is_wp_error($error) ) {
  301. $messages = array();
  302. foreach ( $error->get_error_messages() as $emessage ) {
  303. if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
  304. $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
  305. else
  306. $messages[] = $emessage;
  307. }
  308. $this->error = implode(', ', $messages);
  309. }
  310. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  311. }
  312. /**
  313. * @access public
  314. */
  315. public function bulk_header() {
  316. $this->feedback('skin_upgrade_start');
  317. }
  318. /**
  319. * @access public
  320. */
  321. public function bulk_footer() {
  322. $this->feedback('skin_upgrade_end');
  323. }
  324. /**
  325. *
  326. * @param string $title
  327. */
  328. public function before($title = '') {
  329. $this->in_loop = true;
  330. printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
  331. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
  332. echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
  333. $this->flush_output();
  334. }
  335. /**
  336. *
  337. * @param string $title
  338. */
  339. public function after($title = '') {
  340. echo '</p></div>';
  341. if ( $this->error || ! $this->result ) {
  342. if ( $this->error ) {
  343. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
  344. } else {
  345. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
  346. }
  347. echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
  348. }
  349. if ( $this->result && ! is_wp_error( $this->result ) ) {
  350. if ( ! $this->error )
  351. echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
  352. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  353. }
  354. $this->reset();
  355. $this->flush_output();
  356. }
  357. /**
  358. * @access public
  359. */
  360. public function reset() {
  361. $this->in_loop = false;
  362. $this->error = false;
  363. }
  364. /**
  365. * @access public
  366. */
  367. public function flush_output() {
  368. wp_ob_end_flush_all();
  369. flush();
  370. }
  371. }
  372. class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
  373. public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
  374. public function add_strings() {
  375. parent::add_strings();
  376. $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
  377. }
  378. /**
  379. *
  380. * @param string $title
  381. */
  382. public function before($title = '') {
  383. parent::before($this->plugin_info['Title']);
  384. }
  385. /**
  386. *
  387. * @param string $title
  388. */
  389. public function after($title = '') {
  390. parent::after($this->plugin_info['Title']);
  391. $this->decrement_update_count( 'plugin' );
  392. }
  393. /**
  394. * @access public
  395. */
  396. public function bulk_footer() {
  397. parent::bulk_footer();
  398. $update_actions = array(
  399. 'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>',
  400. 'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
  401. );
  402. if ( ! current_user_can( 'activate_plugins' ) )
  403. unset( $update_actions['plugins_page'] );
  404. /**
  405. * Filter the list of action links available following bulk plugin updates.
  406. *
  407. * @since 3.0.0
  408. *
  409. * @param array $update_actions Array of plugin action links.
  410. * @param array $plugin_info Array of information for the last-updated plugin.
  411. */
  412. $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
  413. if ( ! empty($update_actions) )
  414. $this->feedback(implode(' | ', (array)$update_actions));
  415. }
  416. }
  417. class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
  418. public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
  419. public function add_strings() {
  420. parent::add_strings();
  421. $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
  422. }
  423. /**
  424. *
  425. * @param string $title
  426. */
  427. public function before($title = '') {
  428. parent::before( $this->theme_info->display('Name') );
  429. }
  430. /**
  431. *
  432. * @param string $title
  433. */
  434. public function after($title = '') {
  435. parent::after( $this->theme_info->display('Name') );
  436. $this->decrement_update_count( 'theme' );
  437. }
  438. /**
  439. * @access public
  440. */
  441. public function bulk_footer() {
  442. parent::bulk_footer();
  443. $update_actions = array(
  444. 'themes_page' => '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>',
  445. 'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
  446. );
  447. if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
  448. unset( $update_actions['themes_page'] );
  449. /**
  450. * Filter the list of action links available following bulk theme updates.
  451. *
  452. * @since 3.0.0
  453. *
  454. * @param array $update_actions Array of theme action links.
  455. * @param array $theme_info Array of information for the last-updated theme.
  456. */
  457. $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
  458. if ( ! empty($update_actions) )
  459. $this->feedback(implode(' | ', (array)$update_actions));
  460. }
  461. }
  462. /**
  463. * Plugin Installer Skin for WordPress Plugin Installer.
  464. *
  465. * @package WordPress
  466. * @subpackage Upgrader
  467. * @since 2.8.0
  468. */
  469. class Plugin_Installer_Skin extends WP_Upgrader_Skin {
  470. public $api;
  471. public $type;
  472. /**
  473. *
  474. * @param array $args
  475. */
  476. public function __construct($args = array()) {
  477. $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
  478. $args = wp_parse_args($args, $defaults);
  479. $this->type = $args['type'];
  480. $this->api = isset($args['api']) ? $args['api'] : array();
  481. parent::__construct($args);
  482. }
  483. /**
  484. * @access public
  485. */
  486. public function before() {
  487. if ( !empty($this->api) )
  488. $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
  489. }
  490. /**
  491. * @access public
  492. */
  493. public function after() {
  494. $plugin_file = $this->upgrader->plugin_info();
  495. $install_actions = array();
  496. $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
  497. if ( 'import' == $from )
  498. $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin &amp; Run Importer' ) . '</a>';
  499. else
  500. $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>';
  501. if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
  502. $install_actions['network_activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Network Activate' ) . '</a>';
  503. unset( $install_actions['activate_plugin'] );
  504. }
  505. if ( 'import' == $from ) {
  506. $install_actions['importers_page'] = '<a href="' . admin_url( 'import.php' ) . '" target="_parent">' . __( 'Return to Importers' ) . '</a>';
  507. } elseif ( $this->type == 'web' ) {
  508. $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '" target="_parent">' . __( 'Return to Plugin Installer' ) . '</a>';
  509. } else {
  510. $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>';
  511. }
  512. if ( ! $this->result || is_wp_error($this->result) ) {
  513. unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
  514. } elseif ( ! current_user_can( 'activate_plugins' ) ) {
  515. unset( $install_actions['activate_plugin'] );
  516. }
  517. /**
  518. * Filter the list of action links available following a single plugin installation.
  519. *
  520. * @since 2.7.0
  521. *
  522. * @param array $install_actions Array of plugin action links.
  523. * @param object $api Object containing WordPress.org API plugin data. Empty
  524. * for non-API installs, such as when a plugin is installed
  525. * via upload.
  526. * @param string $plugin_file Path to the plugin file.
  527. */
  528. $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
  529. if ( ! empty($install_actions) )
  530. $this->feedback(implode(' | ', (array)$install_actions));
  531. }
  532. }
  533. /**
  534. * Theme Installer Skin for the WordPress Theme Installer.
  535. *
  536. * @package WordPress
  537. * @subpackage Upgrader
  538. * @since 2.8.0
  539. */
  540. class Theme_Installer_Skin extends WP_Upgrader_Skin {
  541. public $api;
  542. public $type;
  543. /**
  544. *
  545. * @param array $args
  546. */
  547. public function __construct($args = array()) {
  548. $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
  549. $args = wp_parse_args($args, $defaults);
  550. $this->type = $args['type'];
  551. $this->api = isset($args['api']) ? $args['api'] : array();
  552. parent::__construct($args);
  553. }
  554. /**
  555. * @access public
  556. */
  557. public function before() {
  558. if ( !empty($this->api) )
  559. $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
  560. }
  561. /**
  562. * @access public
  563. */
  564. public function after() {
  565. if ( empty($this->upgrader->result['destination_name']) )
  566. return;
  567. $theme_info = $this->upgrader->theme_info();
  568. if ( empty( $theme_info ) )
  569. return;
  570. $name = $theme_info->display('Name');
  571. $stylesheet = $this->upgrader->result['destination_name'];
  572. $template = $theme_info->get_template();
  573. $activate_link = add_query_arg( array(
  574. 'action' => 'activate',
  575. 'template' => urlencode( $template ),
  576. 'stylesheet' => urlencode( $stylesheet ),
  577. ), admin_url('themes.php') );
  578. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  579. $install_actions = array();
  580. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  581. $install_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
  582. }
  583. $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
  584. if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
  585. $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
  586. if ( $this->type == 'web' )
  587. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
  588. elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
  589. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  590. if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
  591. unset( $install_actions['activate'], $install_actions['preview'] );
  592. /**
  593. * Filter the list of action links available following a single theme installation.
  594. *
  595. * @since 2.8.0
  596. *
  597. * @param array $install_actions Array of theme action links.
  598. * @param object $api Object containing WordPress.org API theme data.
  599. * @param string $stylesheet Theme directory name.
  600. * @param WP_Theme $theme_info Theme object.
  601. */
  602. $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
  603. if ( ! empty($install_actions) )
  604. $this->feedback(implode(' | ', (array)$install_actions));
  605. }
  606. }
  607. /**
  608. * Theme Upgrader Skin for WordPress Theme Upgrades.
  609. *
  610. * @package WordPress
  611. * @subpackage Upgrader
  612. * @since 2.8.0
  613. */
  614. class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
  615. public $theme = '';
  616. /**
  617. *
  618. * @param array $args
  619. */
  620. public function __construct($args = array()) {
  621. $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
  622. $args = wp_parse_args($args, $defaults);
  623. $this->theme = $args['theme'];
  624. parent::__construct($args);
  625. }
  626. /**
  627. * @access public
  628. */
  629. public function after() {
  630. $this->decrement_update_count( 'theme' );
  631. $update_actions = array();
  632. if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
  633. $name = $theme_info->display('Name');
  634. $stylesheet = $this->upgrader->result['destination_name'];
  635. $template = $theme_info->get_template();
  636. $activate_link = add_query_arg( array(
  637. 'action' => 'activate',
  638. 'template' => urlencode( $template ),
  639. 'stylesheet' => urlencode( $stylesheet ),
  640. ), admin_url('themes.php') );
  641. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  642. if ( get_stylesheet() == $stylesheet ) {
  643. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  644. $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
  645. }
  646. } elseif ( current_user_can( 'switch_themes' ) ) {
  647. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  648. $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
  649. }
  650. $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
  651. }
  652. if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
  653. unset( $update_actions['preview'], $update_actions['activate'] );
  654. }
  655. $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  656. /**
  657. * Filter the list of action links available following a single theme update.
  658. *
  659. * @since 2.8.0
  660. *
  661. * @param array $update_actions Array of theme action links.
  662. * @param string $theme Theme directory name.
  663. */
  664. $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
  665. if ( ! empty($update_actions) )
  666. $this->feedback(implode(' | ', (array)$update_actions));
  667. }
  668. }
  669. /**
  670. * Translation Upgrader Skin for WordPress Translation Upgrades.
  671. *
  672. * @package WordPress
  673. * @subpackage Upgrader
  674. * @since 3.7.0
  675. */
  676. class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
  677. public $language_update = null;
  678. public $done_header = false;
  679. public $done_footer = false;
  680. public $display_footer_actions = true;
  681. /**
  682. *
  683. * @param array $args
  684. */
  685. public function __construct( $args = array() ) {
  686. $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
  687. $args = wp_parse_args( $args, $defaults );
  688. if ( $args['skip_header_footer'] ) {
  689. $this->done_header = true;
  690. $this->done_footer = true;
  691. $this->display_footer_actions = false;
  692. }
  693. parent::__construct( $args );
  694. }
  695. /**
  696. * @access public
  697. */
  698. public function before() {
  699. $name = $this->upgrader->get_name_for_update( $this->language_update );
  700. echo '<div class="update-messages lp-show-latest">';
  701. printf( '<h2>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h2>', $name, $this->language_update->language );
  702. }
  703. /**
  704. *
  705. * @param string|WP_Error $error
  706. */
  707. public function error( $error ) {
  708. echo '<div class="lp-error">';
  709. parent::error( $error );
  710. echo '</div>';
  711. }
  712. /**
  713. * @access public
  714. */
  715. public function after() {
  716. echo '</div>';
  717. }
  718. /**
  719. * @access public
  720. */
  721. public function bulk_footer() {
  722. $this->decrement_update_count( 'translation' );
  723. $update_actions = array();
  724. $update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>';
  725. /**
  726. * Filter the list of action links available following a translations update.
  727. *
  728. * @since 3.7.0
  729. *
  730. * @param array $update_actions Array of translations update links.
  731. */
  732. $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
  733. if ( $update_actions && $this->display_footer_actions )
  734. $this->feedback( implode( ' | ', $update_actions ) );
  735. }
  736. }
  737. /**
  738. * Upgrader Skin for Automatic WordPress Upgrades
  739. *
  740. * This skin is designed to be used when no output is intended, all output
  741. * is captured and stored for the caller to process and log/email/discard.
  742. *
  743. * @package WordPress
  744. * @subpackage Upgrader
  745. * @since 3.7.0
  746. */
  747. class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
  748. protected $messages = array();
  749. /**
  750. *
  751. * @param bool $error
  752. * @param string $context
  753. * @param bool $allow_relaxed_file_ownership
  754. * @return bool
  755. */
  756. public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  757. if ( $context ) {
  758. $this->options['context'] = $context;
  759. }
  760. // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
  761. // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
  762. ob_start();
  763. $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
  764. ob_end_clean();
  765. return $result;
  766. }
  767. /**
  768. * @access public
  769. *
  770. * @return array
  771. */
  772. public function get_upgrade_messages() {
  773. return $this->messages;
  774. }
  775. /**
  776. * @param string|array|WP_Error $data
  777. */
  778. public function feedback( $data ) {
  779. if ( is_wp_error( $data ) ) {
  780. $string = $data->get_error_message();
  781. } elseif ( is_array( $data ) ) {
  782. return;
  783. } else {
  784. $string = $data;
  785. }
  786. if ( ! empty( $this->upgrader->strings[ $string ] ) )
  787. $string = $this->upgrader->strings[ $string ];
  788. if ( strpos( $string, '%' ) !== false ) {
  789. $args = func_get_args();
  790. $args = array_splice( $args, 1 );
  791. if ( ! empty( $args ) )
  792. $string = vsprintf( $string, $args );
  793. }
  794. $string = trim( $string );
  795. // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
  796. $string = wp_kses( $string, array(
  797. 'a' => array(
  798. 'href' => true
  799. ),
  800. 'br' => true,
  801. 'em' => true,
  802. 'strong' => true,
  803. ) );
  804. if ( empty( $string ) )
  805. return;
  806. $this->messages[] = $string;
  807. }
  808. /**
  809. * @access public
  810. */
  811. public function header() {
  812. ob_start();
  813. }
  814. /**
  815. * @access public
  816. */
  817. public function footer() {
  818. $output = ob_get_clean();
  819. if ( ! empty( $output ) )
  820. $this->feedback( $output );
  821. }
  822. }