PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/geyson/geyson
PHP | 941 lines | 494 code | 124 blank | 323 comment | 98 complexity | 5a015624e1434ba98bcbb2d57a3dedfd MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  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. echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) .'"></iframe>';
  202. }
  203. $this->decrement_update_count( 'plugin' );
  204. $update_actions = array(
  205. '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>',
  206. 'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>'
  207. );
  208. if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
  209. unset( $update_actions['activate_plugin'] );
  210. /**
  211. * Filter the list of action links available following a single plugin update.
  212. *
  213. * @since 2.7.0
  214. *
  215. * @param array $update_actions Array of plugin action links.
  216. * @param string $plugin Path to the plugin file.
  217. */
  218. $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
  219. if ( ! empty($update_actions) )
  220. $this->feedback(implode(' | ', (array)$update_actions));
  221. }
  222. }
  223. /**
  224. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  225. *
  226. * @package WordPress
  227. * @subpackage Upgrader
  228. * @since 3.0.0
  229. */
  230. class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
  231. public $in_loop = false;
  232. /**
  233. * @var string|false
  234. */
  235. public $error = false;
  236. /**
  237. *
  238. * @param array $args
  239. */
  240. public function __construct($args = array()) {
  241. $defaults = array( 'url' => '', 'nonce' => '' );
  242. $args = wp_parse_args($args, $defaults);
  243. parent::__construct($args);
  244. }
  245. /**
  246. * @access public
  247. */
  248. public function add_strings() {
  249. $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
  250. $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
  251. $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
  252. $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>';
  253. $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
  254. }
  255. /**
  256. * @param string $string
  257. */
  258. public function feedback($string) {
  259. if ( isset( $this->upgrader->strings[$string] ) )
  260. $string = $this->upgrader->strings[$string];
  261. if ( strpos($string, '%') !== false ) {
  262. $args = func_get_args();
  263. $args = array_splice($args, 1);
  264. if ( $args ) {
  265. $args = array_map( 'strip_tags', $args );
  266. $args = array_map( 'esc_html', $args );
  267. $string = vsprintf($string, $args);
  268. }
  269. }
  270. if ( empty($string) )
  271. return;
  272. if ( $this->in_loop )
  273. echo "$string<br />\n";
  274. else
  275. echo "<p>$string</p>\n";
  276. }
  277. /**
  278. * @access public
  279. */
  280. public function header() {
  281. // Nothing, This will be displayed within a iframe.
  282. }
  283. /**
  284. * @access public
  285. */
  286. public function footer() {
  287. // Nothing, This will be displayed within a iframe.
  288. }
  289. /**
  290. *
  291. * @param string|WP_Error $error
  292. */
  293. public function error($error) {
  294. if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
  295. $this->error = $this->upgrader->strings[$error];
  296. if ( is_wp_error($error) ) {
  297. $messages = array();
  298. foreach ( $error->get_error_messages() as $emessage ) {
  299. if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
  300. $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
  301. else
  302. $messages[] = $emessage;
  303. }
  304. $this->error = implode(', ', $messages);
  305. }
  306. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  307. }
  308. /**
  309. * @access public
  310. */
  311. public function bulk_header() {
  312. $this->feedback('skin_upgrade_start');
  313. }
  314. /**
  315. * @access public
  316. */
  317. public function bulk_footer() {
  318. $this->feedback('skin_upgrade_end');
  319. }
  320. /**
  321. *
  322. * @param string $title
  323. */
  324. public function before($title = '') {
  325. $this->in_loop = true;
  326. printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count);
  327. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
  328. echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
  329. $this->flush_output();
  330. }
  331. /**
  332. *
  333. * @param string $title
  334. */
  335. public function after($title = '') {
  336. echo '</p></div>';
  337. if ( $this->error || ! $this->result ) {
  338. if ( $this->error )
  339. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
  340. else
  341. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
  342. echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
  343. }
  344. if ( $this->result && ! is_wp_error( $this->result ) ) {
  345. if ( ! $this->error )
  346. 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>';
  347. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  348. }
  349. $this->reset();
  350. $this->flush_output();
  351. }
  352. /**
  353. * @access public
  354. */
  355. public function reset() {
  356. $this->in_loop = false;
  357. $this->error = false;
  358. }
  359. /**
  360. * @access public
  361. */
  362. public function flush_output() {
  363. wp_ob_end_flush_all();
  364. flush();
  365. }
  366. }
  367. class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
  368. public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
  369. public function add_strings() {
  370. parent::add_strings();
  371. $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
  372. }
  373. /**
  374. *
  375. * @param string $title
  376. */
  377. public function before($title = '') {
  378. parent::before($this->plugin_info['Title']);
  379. }
  380. /**
  381. *
  382. * @param string $title
  383. */
  384. public function after($title = '') {
  385. parent::after($this->plugin_info['Title']);
  386. $this->decrement_update_count( 'plugin' );
  387. }
  388. /**
  389. * @access public
  390. */
  391. public function bulk_footer() {
  392. parent::bulk_footer();
  393. $update_actions = array(
  394. 'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>',
  395. 'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
  396. );
  397. if ( ! current_user_can( 'activate_plugins' ) )
  398. unset( $update_actions['plugins_page'] );
  399. /**
  400. * Filter the list of action links available following bulk plugin updates.
  401. *
  402. * @since 3.0.0
  403. *
  404. * @param array $update_actions Array of plugin action links.
  405. * @param array $plugin_info Array of information for the last-updated plugin.
  406. */
  407. $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
  408. if ( ! empty($update_actions) )
  409. $this->feedback(implode(' | ', (array)$update_actions));
  410. }
  411. }
  412. class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
  413. public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
  414. public function add_strings() {
  415. parent::add_strings();
  416. $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
  417. }
  418. /**
  419. *
  420. * @param string $title
  421. */
  422. public function before($title = '') {
  423. parent::before( $this->theme_info->display('Name') );
  424. }
  425. /**
  426. *
  427. * @param string $title
  428. */
  429. public function after($title = '') {
  430. parent::after( $this->theme_info->display('Name') );
  431. $this->decrement_update_count( 'theme' );
  432. }
  433. /**
  434. * @access public
  435. */
  436. public function bulk_footer() {
  437. parent::bulk_footer();
  438. $update_actions = array(
  439. 'themes_page' => '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>',
  440. 'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
  441. );
  442. if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
  443. unset( $update_actions['themes_page'] );
  444. /**
  445. * Filter the list of action links available following bulk theme updates.
  446. *
  447. * @since 3.0.0
  448. *
  449. * @param array $update_actions Array of theme action links.
  450. * @param array $theme_info Array of information for the last-updated theme.
  451. */
  452. $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
  453. if ( ! empty($update_actions) )
  454. $this->feedback(implode(' | ', (array)$update_actions));
  455. }
  456. }
  457. /**
  458. * Plugin Installer Skin for WordPress Plugin Installer.
  459. *
  460. * @package WordPress
  461. * @subpackage Upgrader
  462. * @since 2.8.0
  463. */
  464. class Plugin_Installer_Skin extends WP_Upgrader_Skin {
  465. public $api;
  466. public $type;
  467. /**
  468. *
  469. * @param array $args
  470. */
  471. public function __construct($args = array()) {
  472. $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
  473. $args = wp_parse_args($args, $defaults);
  474. $this->type = $args['type'];
  475. $this->api = isset($args['api']) ? $args['api'] : array();
  476. parent::__construct($args);
  477. }
  478. /**
  479. * @access public
  480. */
  481. public function before() {
  482. if ( !empty($this->api) )
  483. $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
  484. }
  485. /**
  486. * @access public
  487. */
  488. public function after() {
  489. $plugin_file = $this->upgrader->plugin_info();
  490. $install_actions = array();
  491. $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
  492. if ( 'import' == $from )
  493. $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>';
  494. else
  495. $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>';
  496. if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
  497. $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>';
  498. unset( $install_actions['activate_plugin'] );
  499. }
  500. if ( 'import' == $from ) {
  501. $install_actions['importers_page'] = '<a href="' . admin_url( 'import.php' ) . '" target="_parent">' . __( 'Return to Importers' ) . '</a>';
  502. } elseif ( $this->type == 'web' ) {
  503. $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '" target="_parent">' . __( 'Return to Plugin Installer' ) . '</a>';
  504. } else {
  505. $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>';
  506. }
  507. if ( ! $this->result || is_wp_error($this->result) ) {
  508. unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
  509. } elseif ( ! current_user_can( 'activate_plugins' ) ) {
  510. unset( $install_actions['activate_plugin'] );
  511. }
  512. /**
  513. * Filter the list of action links available following a single plugin installation.
  514. *
  515. * @since 2.7.0
  516. *
  517. * @param array $install_actions Array of plugin action links.
  518. * @param object $api Object containing WordPress.org API plugin data. Empty
  519. * for non-API installs, such as when a plugin is installed
  520. * via upload.
  521. * @param string $plugin_file Path to the plugin file.
  522. */
  523. $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
  524. if ( ! empty($install_actions) )
  525. $this->feedback(implode(' | ', (array)$install_actions));
  526. }
  527. }
  528. /**
  529. * Theme Installer Skin for the WordPress Theme Installer.
  530. *
  531. * @package WordPress
  532. * @subpackage Upgrader
  533. * @since 2.8.0
  534. */
  535. class Theme_Installer_Skin extends WP_Upgrader_Skin {
  536. public $api;
  537. public $type;
  538. /**
  539. *
  540. * @param array $args
  541. */
  542. public function __construct($args = array()) {
  543. $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
  544. $args = wp_parse_args($args, $defaults);
  545. $this->type = $args['type'];
  546. $this->api = isset($args['api']) ? $args['api'] : array();
  547. parent::__construct($args);
  548. }
  549. /**
  550. * @access public
  551. */
  552. public function before() {
  553. if ( !empty($this->api) )
  554. $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
  555. }
  556. /**
  557. * @access public
  558. */
  559. public function after() {
  560. if ( empty($this->upgrader->result['destination_name']) )
  561. return;
  562. $theme_info = $this->upgrader->theme_info();
  563. if ( empty( $theme_info ) )
  564. return;
  565. $name = $theme_info->display('Name');
  566. $stylesheet = $this->upgrader->result['destination_name'];
  567. $template = $theme_info->get_template();
  568. $activate_link = add_query_arg( array(
  569. 'action' => 'activate',
  570. 'template' => urlencode( $template ),
  571. 'stylesheet' => urlencode( $stylesheet ),
  572. ), admin_url('themes.php') );
  573. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  574. $install_actions = array();
  575. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  576. $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>';
  577. }
  578. $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>';
  579. if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
  580. $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>';
  581. if ( $this->type == 'web' )
  582. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
  583. elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
  584. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  585. if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
  586. unset( $install_actions['activate'], $install_actions['preview'] );
  587. /**
  588. * Filter the list of action links available following a single theme installation.
  589. *
  590. * @since 2.8.0
  591. *
  592. * @param array $install_actions Array of theme action links.
  593. * @param object $api Object containing WordPress.org API theme data.
  594. * @param string $stylesheet Theme directory name.
  595. * @param WP_Theme $theme_info Theme object.
  596. */
  597. $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
  598. if ( ! empty($install_actions) )
  599. $this->feedback(implode(' | ', (array)$install_actions));
  600. }
  601. }
  602. /**
  603. * Theme Upgrader Skin for WordPress Theme Upgrades.
  604. *
  605. * @package WordPress
  606. * @subpackage Upgrader
  607. * @since 2.8.0
  608. */
  609. class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
  610. public $theme = '';
  611. /**
  612. *
  613. * @param array $args
  614. */
  615. public function __construct($args = array()) {
  616. $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
  617. $args = wp_parse_args($args, $defaults);
  618. $this->theme = $args['theme'];
  619. parent::__construct($args);
  620. }
  621. /**
  622. * @access public
  623. */
  624. public function after() {
  625. $this->decrement_update_count( 'theme' );
  626. $update_actions = array();
  627. if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
  628. $name = $theme_info->display('Name');
  629. $stylesheet = $this->upgrader->result['destination_name'];
  630. $template = $theme_info->get_template();
  631. $activate_link = add_query_arg( array(
  632. 'action' => 'activate',
  633. 'template' => urlencode( $template ),
  634. 'stylesheet' => urlencode( $stylesheet ),
  635. ), admin_url('themes.php') );
  636. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  637. if ( get_stylesheet() == $stylesheet ) {
  638. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  639. $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>';
  640. }
  641. } elseif ( current_user_can( 'switch_themes' ) ) {
  642. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  643. $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>';
  644. }
  645. $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>';
  646. }
  647. if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
  648. unset( $update_actions['preview'], $update_actions['activate'] );
  649. }
  650. $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  651. /**
  652. * Filter the list of action links available following a single theme update.
  653. *
  654. * @since 2.8.0
  655. *
  656. * @param array $update_actions Array of theme action links.
  657. * @param string $theme Theme directory name.
  658. */
  659. $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
  660. if ( ! empty($update_actions) )
  661. $this->feedback(implode(' | ', (array)$update_actions));
  662. }
  663. }
  664. /**
  665. * Translation Upgrader Skin for WordPress Translation Upgrades.
  666. *
  667. * @package WordPress
  668. * @subpackage Upgrader
  669. * @since 3.7.0
  670. */
  671. class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
  672. public $language_update = null;
  673. public $done_header = false;
  674. public $done_footer = false;
  675. public $display_footer_actions = true;
  676. /**
  677. *
  678. * @param array $args
  679. */
  680. public function __construct( $args = array() ) {
  681. $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
  682. $args = wp_parse_args( $args, $defaults );
  683. if ( $args['skip_header_footer'] ) {
  684. $this->done_header = true;
  685. $this->done_footer = true;
  686. $this->display_footer_actions = false;
  687. }
  688. parent::__construct( $args );
  689. }
  690. /**
  691. * @access public
  692. */
  693. public function before() {
  694. $name = $this->upgrader->get_name_for_update( $this->language_update );
  695. echo '<div class="update-messages lp-show-latest">';
  696. printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
  697. }
  698. /**
  699. *
  700. * @param string|WP_Error $error
  701. */
  702. public function error( $error ) {
  703. echo '<div class="lp-error">';
  704. parent::error( $error );
  705. echo '</div>';
  706. }
  707. /**
  708. * @access public
  709. */
  710. public function after() {
  711. echo '</div>';
  712. }
  713. /**
  714. * @access public
  715. */
  716. public function bulk_footer() {
  717. $this->decrement_update_count( 'translation' );
  718. $update_actions = array();
  719. $update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>';
  720. /**
  721. * Filter the list of action links available following a translations update.
  722. *
  723. * @since 3.7.0
  724. *
  725. * @param array $update_actions Array of translations update links.
  726. */
  727. $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
  728. if ( $update_actions && $this->display_footer_actions )
  729. $this->feedback( implode( ' | ', $update_actions ) );
  730. }
  731. }
  732. /**
  733. * Upgrader Skin for Automatic WordPress Upgrades
  734. *
  735. * This skin is designed to be used when no output is intended, all output
  736. * is captured and stored for the caller to process and log/email/discard.
  737. *
  738. * @package WordPress
  739. * @subpackage Upgrader
  740. * @since 3.7.0
  741. */
  742. class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
  743. protected $messages = array();
  744. /**
  745. *
  746. * @param bool $error
  747. * @param string $context
  748. * @param bool $allow_relaxed_file_ownership
  749. * @return bool
  750. */
  751. public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  752. if ( $context ) {
  753. $this->options['context'] = $context;
  754. }
  755. // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
  756. // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
  757. ob_start();
  758. $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
  759. ob_end_clean();
  760. return $result;
  761. }
  762. /**
  763. * @access public
  764. *
  765. * @return array
  766. */
  767. public function get_upgrade_messages() {
  768. return $this->messages;
  769. }
  770. /**
  771. * @param string|array|WP_Error $data
  772. */
  773. public function feedback( $data ) {
  774. if ( is_wp_error( $data ) ) {
  775. $string = $data->get_error_message();
  776. } elseif ( is_array( $data ) ) {
  777. return;
  778. } else {
  779. $string = $data;
  780. }
  781. if ( ! empty( $this->upgrader->strings[ $string ] ) )
  782. $string = $this->upgrader->strings[ $string ];
  783. if ( strpos( $string, '%' ) !== false ) {
  784. $args = func_get_args();
  785. $args = array_splice( $args, 1 );
  786. if ( ! empty( $args ) )
  787. $string = vsprintf( $string, $args );
  788. }
  789. $string = trim( $string );
  790. // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
  791. $string = wp_kses( $string, array(
  792. 'a' => array(
  793. 'href' => true
  794. ),
  795. 'br' => true,
  796. 'em' => true,
  797. 'strong' => true,
  798. ) );
  799. if ( empty( $string ) )
  800. return;
  801. $this->messages[] = $string;
  802. }
  803. /**
  804. * @access public
  805. */
  806. public function header() {
  807. ob_start();
  808. }
  809. /**
  810. * @access public
  811. */
  812. public function footer() {
  813. $output = ob_get_clean();
  814. if ( ! empty( $output ) )
  815. $this->feedback( $output );
  816. }
  817. }