3 * The User Interface "Skins" for the WordPress File Upgrader
11 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
14 * @subpackage Upgrader
17 class WP_Upgrader_Skin {
20 public $done_header = false;
21 public $done_footer = false;
22 public $result = false;
23 public $options = array();
25 public function __construct($args = array()) {
26 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
27 $this->options = wp_parse_args($args, $defaults);
31 * @param WP_Upgrader $upgrader
33 public function set_upgrader(&$upgrader) {
34 if ( is_object($upgrader) )
35 $this->upgrader =& $upgrader;
39 public function add_strings() {
42 public function set_result($result) {
43 $this->result = $result;
46 public function request_filesystem_credentials( $error = false, $context = false, $allow_relaxed_file_ownership = false ) {
47 $url = $this->options['url'];
49 $context = $this->options['context'];
51 if ( !empty($this->options['nonce']) ) {
52 $url = wp_nonce_url($url, $this->options['nonce']);
55 $extra_fields = array();
57 return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
60 public function header() {
61 if ( $this->done_header ) {
64 $this->done_header = true;
65 echo '<div class="wrap">';
66 echo '<h2>' . $this->options['title'] . '</h2>';
68 public function footer() {
69 if ( $this->done_footer ) {
72 $this->done_footer = true;
76 public function error($errors) {
77 if ( ! $this->done_header )
79 if ( is_string($errors) ) {
80 $this->feedback($errors);
81 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
82 foreach ( $errors->get_error_messages() as $message ) {
83 if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
84 $this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
86 $this->feedback($message);
91 public function feedback($string) {
92 if ( isset( $this->upgrader->strings[$string] ) )
93 $string = $this->upgrader->strings[$string];
95 if ( strpos($string, '%') !== false ) {
96 $args = func_get_args();
97 $args = array_splice($args, 1);
99 $args = array_map( 'strip_tags', $args );
100 $args = array_map( 'esc_html', $args );
101 $string = vsprintf($string, $args);
104 if ( empty($string) )
106 show_message($string);
108 public function before() {}
109 public function after() {}
112 * Output JavaScript that calls function to decrement the update counts.
116 * @param string $type Type of update count to decrement. Likely values include 'plugin',
117 * 'theme', 'translation', etc.
119 protected function decrement_update_count( $type ) {
120 if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
124 if ( defined( 'IFRAME_REQUEST' ) ) {
125 echo '<script type="text/javascript">
126 if ( window.postMessage && JSON ) {
127 window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
131 echo '<script type="text/javascript">
133 if ( wp && wp.updates.decrementCount ) {
134 wp.updates.decrementCount( "' . $type . '" );
141 public function bulk_header() {}
142 public function bulk_footer() {}
146 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
149 * @subpackage Upgrader
152 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
154 public $plugin_active = false;
155 public $plugin_network_active = false;
157 public function __construct($args = array()) {
158 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
159 $args = wp_parse_args($args, $defaults);
161 $this->plugin = $args['plugin'];
163 $this->plugin_active = is_plugin_active( $this->plugin );
164 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
166 parent::__construct($args);
169 public function after() {
170 $this->plugin = $this->upgrader->plugin_info();
171 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
172 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>';
175 $this->decrement_update_count( 'plugin' );
177 $update_actions = array(
178 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
179 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
181 if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
182 unset( $update_actions['activate_plugin'] );
185 * Filter the list of action links available following a single plugin update.
189 * @param array $update_actions Array of plugin action links.
190 * @param string $plugin Path to the plugin file.
192 $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
194 if ( ! empty($update_actions) )
195 $this->feedback(implode(' | ', (array)$update_actions));
200 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
203 * @subpackage Upgrader
206 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
207 public $in_loop = false;
211 public $error = false;
213 public function __construct($args = array()) {
214 $defaults = array( 'url' => '', 'nonce' => '' );
215 $args = wp_parse_args($args, $defaults);
217 parent::__construct($args);
220 public function add_strings() {
221 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
222 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
223 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
224 $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>';
225 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
229 * @param string $string
231 public function feedback($string) {
232 if ( isset( $this->upgrader->strings[$string] ) )
233 $string = $this->upgrader->strings[$string];
235 if ( strpos($string, '%') !== false ) {
236 $args = func_get_args();
237 $args = array_splice($args, 1);
239 $args = array_map( 'strip_tags', $args );
240 $args = array_map( 'esc_html', $args );
241 $string = vsprintf($string, $args);
244 if ( empty($string) )
246 if ( $this->in_loop )
247 echo "$string<br />\n";
249 echo "<p>$string</p>\n";
252 public function header() {
253 // Nothing, This will be displayed within a iframe.
256 public function footer() {
257 // Nothing, This will be displayed within a iframe.
259 public function error($error) {
260 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
261 $this->error = $this->upgrader->strings[$error];
263 if ( is_wp_error($error) ) {
265 foreach ( $error->get_error_messages() as $emessage ) {
266 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
267 $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
269 $messages[] = $emessage;
271 $this->error = implode(', ', $messages);
273 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
276 public function bulk_header() {
277 $this->feedback('skin_upgrade_start');
280 public function bulk_footer() {
281 $this->feedback('skin_upgrade_end');
284 public function before($title = '') {
285 $this->in_loop = true;
286 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);
287 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
288 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
289 $this->flush_output();
292 public function after($title = '') {
294 if ( $this->error || ! $this->result ) {
296 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
298 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
300 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
302 if ( $this->result && ! is_wp_error( $this->result ) ) {
303 if ( ! $this->error )
304 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>';
305 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
309 $this->flush_output();
312 public function reset() {
313 $this->in_loop = false;
314 $this->error = false;
317 public function flush_output() {
318 wp_ob_end_flush_all();
323 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
324 public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
326 public function add_strings() {
327 parent::add_strings();
328 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
331 public function before($title = '') {
332 parent::before($this->plugin_info['Title']);
335 public function after($title = '') {
336 parent::after($this->plugin_info['Title']);
337 $this->decrement_update_count( 'plugin' );
339 public function bulk_footer() {
340 parent::bulk_footer();
341 $update_actions = array(
342 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
343 '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>'
345 if ( ! current_user_can( 'activate_plugins' ) )
346 unset( $update_actions['plugins_page'] );
349 * Filter the list of action links available following bulk plugin updates.
353 * @param array $update_actions Array of plugin action links.
354 * @param array $plugin_info Array of information for the last-updated plugin.
356 $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
358 if ( ! empty($update_actions) )
359 $this->feedback(implode(' | ', (array)$update_actions));
363 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
364 public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
366 public function add_strings() {
367 parent::add_strings();
368 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
371 public function before($title = '') {
372 parent::before( $this->theme_info->display('Name') );
375 public function after($title = '') {
376 parent::after( $this->theme_info->display('Name') );
377 $this->decrement_update_count( 'theme' );
380 public function bulk_footer() {
381 parent::bulk_footer();
382 $update_actions = array(
383 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
384 '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>'
386 if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
387 unset( $update_actions['themes_page'] );
390 * Filter the list of action links available following bulk theme updates.
394 * @param array $update_actions Array of theme action links.
395 * @param array $theme_info Array of information for the last-updated theme.
397 $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
399 if ( ! empty($update_actions) )
400 $this->feedback(implode(' | ', (array)$update_actions));
405 * Plugin Installer Skin for WordPress Plugin Installer.
408 * @subpackage Upgrader
411 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
415 public function __construct($args = array()) {
416 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
417 $args = wp_parse_args($args, $defaults);
419 $this->type = $args['type'];
420 $this->api = isset($args['api']) ? $args['api'] : array();
422 parent::__construct($args);
425 public function before() {
426 if ( !empty($this->api) )
427 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
430 public function after() {
432 $plugin_file = $this->upgrader->plugin_info();
434 $install_actions = array();
436 $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
438 if ( 'import' == $from )
439 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>';
441 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
443 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
444 $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&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>';
445 unset( $install_actions['activate_plugin'] );
448 if ( 'import' == $from ) {
449 $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
450 } elseif ( $this->type == 'web' ) {
451 $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>';
453 $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>';
456 if ( ! $this->result || is_wp_error($this->result) ) {
457 unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
458 } elseif ( ! current_user_can( 'activate_plugins' ) ) {
459 unset( $install_actions['activate_plugin'] );
463 * Filter the list of action links available following a single plugin installation.
467 * @param array $install_actions Array of plugin action links.
468 * @param object $api Object containing WordPress.org API plugin data. Empty
469 * for non-API installs, such as when a plugin is installed
471 * @param string $plugin_file Path to the plugin file.
473 $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
475 if ( ! empty($install_actions) )
476 $this->feedback(implode(' | ', (array)$install_actions));
481 * Theme Installer Skin for the WordPress Theme Installer.
484 * @subpackage Upgrader
487 class Theme_Installer_Skin extends WP_Upgrader_Skin {
491 public function __construct($args = array()) {
492 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
493 $args = wp_parse_args($args, $defaults);
495 $this->type = $args['type'];
496 $this->api = isset($args['api']) ? $args['api'] : array();
498 parent::__construct($args);
501 public function before() {
502 if ( !empty($this->api) )
503 $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
506 public function after() {
507 if ( empty($this->upgrader->result['destination_name']) )
510 $theme_info = $this->upgrader->theme_info();
511 if ( empty( $theme_info ) )
514 $name = $theme_info->display('Name');
515 $stylesheet = $this->upgrader->result['destination_name'];
516 $template = $theme_info->get_template();
518 $preview_link = add_query_arg( array(
520 'template' => urlencode( $template ),
521 'stylesheet' => urlencode( $stylesheet ),
522 ), trailingslashit( home_url() ) );
524 $activate_link = add_query_arg( array(
525 'action' => 'activate',
526 'template' => urlencode( $template ),
527 'stylesheet' => urlencode( $stylesheet ),
528 ), admin_url('themes.php') );
529 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
531 $install_actions = array();
532 $install_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>';
533 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
534 $install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Live Preview') . '</a>';
536 $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
538 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
539 $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
541 if ( $this->type == 'web' )
542 $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>';
543 elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
544 $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
546 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
547 unset( $install_actions['activate'], $install_actions['preview'] );
550 * Filter the list of action links available following a single theme installation.
554 * @param array $install_actions Array of theme action links.
555 * @param object $api Object containing WordPress.org API theme data.
556 * @param string $stylesheet Theme directory name.
557 * @param WP_Theme $theme_info Theme object.
559 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
560 if ( ! empty($install_actions) )
561 $this->feedback(implode(' | ', (array)$install_actions));
566 * Theme Upgrader Skin for WordPress Theme Upgrades.
569 * @subpackage Upgrader
572 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
575 public function __construct($args = array()) {
576 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
577 $args = wp_parse_args($args, $defaults);
579 $this->theme = $args['theme'];
581 parent::__construct($args);
584 public function after() {
585 $this->decrement_update_count( 'theme' );
587 $update_actions = array();
588 if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
589 $name = $theme_info->display('Name');
590 $stylesheet = $this->upgrader->result['destination_name'];
591 $template = $theme_info->get_template();
593 $preview_link = add_query_arg( array(
595 'template' => urlencode( $template ),
596 'stylesheet' => urlencode( $stylesheet ),
597 ), trailingslashit( home_url() ) );
599 $activate_link = add_query_arg( array(
600 'action' => 'activate',
601 'template' => urlencode( $template ),
602 'stylesheet' => urlencode( $stylesheet ),
603 ), admin_url('themes.php') );
604 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
606 if ( get_stylesheet() == $stylesheet ) {
607 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
608 $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize “%s”'), $name ) ) . '">' . __('Customize') . '</a>';
610 } elseif ( current_user_can( 'switch_themes' ) ) {
611 $update_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>';
612 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
613 $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Live Preview') . '</a>';
615 $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
618 if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
619 unset( $update_actions['preview'], $update_actions['activate'] );
622 $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>';
625 * Filter the list of action links available following a single theme update.
629 * @param array $update_actions Array of theme action links.
630 * @param string $theme Theme directory name.
632 $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
634 if ( ! empty($update_actions) )
635 $this->feedback(implode(' | ', (array)$update_actions));
640 * Translation Upgrader Skin for WordPress Translation Upgrades.
643 * @subpackage Upgrader
646 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
647 public $language_update = null;
648 public $done_header = false;
649 public $done_footer = false;
650 public $display_footer_actions = true;
652 public function __construct( $args = array() ) {
653 $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
654 $args = wp_parse_args( $args, $defaults );
655 if ( $args['skip_header_footer'] ) {
656 $this->done_header = true;
657 $this->done_footer = true;
658 $this->display_footer_actions = false;
660 parent::__construct( $args );
663 public function before() {
664 $name = $this->upgrader->get_name_for_update( $this->language_update );
666 echo '<div class="update-messages lp-show-latest">';
668 printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)…' ) . '</h4>', $name, $this->language_update->language );
671 public function error( $error ) {
672 echo '<div class="lp-error">';
673 parent::error( $error );
677 public function after() {
681 public function bulk_footer() {
682 $this->decrement_update_count( 'translation' );
683 $update_actions = array();
684 $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>';
687 * Filter the list of action links available following a translations update.
691 * @param array $update_actions Array of translations update links.
693 $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
695 if ( $update_actions && $this->display_footer_actions )
696 $this->feedback( implode( ' | ', $update_actions ) );
701 * Upgrader Skin for Automatic WordPress Upgrades
703 * This skin is designed to be used when no output is intended, all output
704 * is captured and stored for the caller to process and log/email/discard.
707 * @subpackage Upgrader
710 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
711 protected $messages = array();
713 public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
715 $this->options['context'] = $context;
717 // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
718 // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
720 $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
725 public function get_upgrade_messages() {
726 return $this->messages;
730 * @param string|array|WP_Error $data
732 public function feedback( $data ) {
733 if ( is_wp_error( $data ) ) {
734 $string = $data->get_error_message();
735 } elseif ( is_array( $data ) ) {
740 if ( ! empty( $this->upgrader->strings[ $string ] ) )
741 $string = $this->upgrader->strings[ $string ];
743 if ( strpos( $string, '%' ) !== false ) {
744 $args = func_get_args();
745 $args = array_splice( $args, 1 );
746 if ( ! empty( $args ) )
747 $string = vsprintf( $string, $args );
750 $string = trim( $string );
752 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
753 $string = wp_kses( $string, array(
762 if ( empty( $string ) )
765 $this->messages[] = $string;
768 public function header() {
772 public function footer() {
773 $output = ob_get_contents();
774 if ( ! empty( $output ) )
775 $this->feedback( $output );
779 public function bulk_header() {}
780 public function bulk_footer() {}
781 public function before() {}
782 public function after() {}