PageRenderTime 59ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

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

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