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 . '" );
143 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
146 * @subpackage Upgrader
149 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
151 public $plugin_active = false;
152 public $plugin_network_active = false;
154 public function __construct($args = array()) {
155 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
156 $args = wp_parse_args($args, $defaults);
158 $this->plugin = $args['plugin'];
160 $this->plugin_active = is_plugin_active( $this->plugin );
161 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
163 parent::__construct($args);
166 public function after() {
167 $this->plugin = $this->upgrader->plugin_info();
168 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
169 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>';
172 $this->decrement_update_count( 'plugin' );
174 $update_actions = array(
175 '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>',
176 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
178 if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
179 unset( $update_actions['activate_plugin'] );
182 * Filter the list of action links available following a single plugin update.
186 * @param array $update_actions Array of plugin action links.
187 * @param string $plugin Path to the plugin file.
189 $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
191 if ( ! empty($update_actions) )
192 $this->feedback(implode(' | ', (array)$update_actions));
197 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
200 * @subpackage Upgrader
203 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
204 public $in_loop = false;
205 public $error = false;
207 public function __construct($args = array()) {
208 $defaults = array( 'url' => '', 'nonce' => '' );
209 $args = wp_parse_args($args, $defaults);
211 parent::__construct($args);
214 public function add_strings() {
215 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
216 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
217 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
218 $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>';
219 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
223 * @param string $string
225 public function feedback($string) {
226 if ( isset( $this->upgrader->strings[$string] ) )
227 $string = $this->upgrader->strings[$string];
229 if ( strpos($string, '%') !== false ) {
230 $args = func_get_args();
231 $args = array_splice($args, 1);
233 $args = array_map( 'strip_tags', $args );
234 $args = array_map( 'esc_html', $args );
235 $string = vsprintf($string, $args);
238 if ( empty($string) )
240 if ( $this->in_loop )
241 echo "$string<br />\n";
243 echo "<p>$string</p>\n";
246 public function header() {
247 // Nothing, This will be displayed within a iframe.
250 public function footer() {
251 // Nothing, This will be displayed within a iframe.
253 public function error($error) {
254 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
255 $this->error = $this->upgrader->strings[$error];
257 if ( is_wp_error($error) ) {
259 foreach ( $error->get_error_messages() as $emessage ) {
260 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
261 $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
263 $messages[] = $emessage;
265 $this->error = implode(', ', $messages);
267 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
270 public function bulk_header() {
271 $this->feedback('skin_upgrade_start');
274 public function bulk_footer() {
275 $this->feedback('skin_upgrade_end');
278 public function before($title = '') {
279 $this->in_loop = true;
280 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);
281 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
282 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
283 $this->flush_output();
286 public function after($title = '') {
288 if ( $this->error || ! $this->result ) {
290 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
292 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
294 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
296 if ( $this->result && ! is_wp_error( $this->result ) ) {
297 if ( ! $this->error )
298 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>';
299 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
303 $this->flush_output();
306 public function reset() {
307 $this->in_loop = false;
308 $this->error = false;
311 public function flush_output() {
312 wp_ob_end_flush_all();
317 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
318 public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
320 public function __construct($args = array()) {
321 parent::__construct($args);
324 public function add_strings() {
325 parent::add_strings();
326 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
329 public function before($title = '') {
330 parent::before($this->plugin_info['Title']);
333 public function after($title = '') {
334 parent::after($this->plugin_info['Title']);
335 $this->decrement_update_count( 'plugin' );
337 public function bulk_footer() {
338 parent::bulk_footer();
339 $update_actions = array(
340 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
341 '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>'
343 if ( ! current_user_can( 'activate_plugins' ) )
344 unset( $update_actions['plugins_page'] );
347 * Filter the list of action links available following bulk plugin updates.
351 * @param array $update_actions Array of plugin action links.
352 * @param array $plugin_info Array of information for the last-updated plugin.
354 $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
356 if ( ! empty($update_actions) )
357 $this->feedback(implode(' | ', (array)$update_actions));
361 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
362 public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
364 public function __construct($args = array()) {
365 parent::__construct($args);
368 public function add_strings() {
369 parent::add_strings();
370 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
373 public function before($title = '') {
374 parent::before( $this->theme_info->display('Name') );
377 public function after($title = '') {
378 parent::after( $this->theme_info->display('Name') );
379 $this->decrement_update_count( 'theme' );
382 public function bulk_footer() {
383 parent::bulk_footer();
384 $update_actions = array(
385 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
386 '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>'
388 if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
389 unset( $update_actions['themes_page'] );
392 * Filter the list of action links available following bulk theme updates.
396 * @param array $update_actions Array of theme action links.
397 * @param array $theme_info Array of information for the last-updated theme.
399 $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
401 if ( ! empty($update_actions) )
402 $this->feedback(implode(' | ', (array)$update_actions));
407 * Plugin Installer Skin for WordPress Plugin Installer.
410 * @subpackage Upgrader
413 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
417 public function __construct($args = array()) {
418 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
419 $args = wp_parse_args($args, $defaults);
421 $this->type = $args['type'];
422 $this->api = isset($args['api']) ? $args['api'] : array();
424 parent::__construct($args);
427 public function before() {
428 if ( !empty($this->api) )
429 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
432 public function after() {
434 $plugin_file = $this->upgrader->plugin_info();
436 $install_actions = array();
438 $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
440 if ( 'import' == $from )
441 $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>';
443 $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>';
445 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
446 $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>';
447 unset( $install_actions['activate_plugin'] );
450 if ( 'import' == $from )
451 $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
452 else if ( $this->type == 'web' )
453 $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>';
455 $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>';
457 if ( ! $this->result || is_wp_error($this->result) ) {
458 unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
459 } elseif ( ! current_user_can( 'activate_plugins' ) ) {
460 unset( $install_actions['activate_plugin'] );
464 * Filter the list of action links available following a single plugin installation.
468 * @param array $install_actions Array of plugin action links.
469 * @param object $api Object containing WordPress.org API plugin data. Empty
470 * for non-API installs, such as when a plugin is installed
472 * @param string $plugin_file Path to the plugin file.
474 $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
476 if ( ! empty($install_actions) )
477 $this->feedback(implode(' | ', (array)$install_actions));
482 * Theme Installer Skin for the WordPress Theme Installer.
485 * @subpackage Upgrader
488 class Theme_Installer_Skin extends WP_Upgrader_Skin {
492 public function __construct($args = array()) {
493 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
494 $args = wp_parse_args($args, $defaults);
496 $this->type = $args['type'];
497 $this->api = isset($args['api']) ? $args['api'] : array();
499 parent::__construct($args);
502 public function before() {
503 if ( !empty($this->api) )
504 $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
507 public function after() {
508 if ( empty($this->upgrader->result['destination_name']) )
511 $theme_info = $this->upgrader->theme_info();
512 if ( empty( $theme_info ) )
515 $name = $theme_info->display('Name');
516 $stylesheet = $this->upgrader->result['destination_name'];
517 $template = $theme_info->get_template();
519 $preview_link = add_query_arg( array(
521 'template' => urlencode( $template ),
522 'stylesheet' => urlencode( $stylesheet ),
523 ), trailingslashit( home_url() ) );
525 $activate_link = add_query_arg( array(
526 'action' => 'activate',
527 'template' => urlencode( $template ),
528 'stylesheet' => urlencode( $stylesheet ),
529 ), admin_url('themes.php') );
530 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
532 $install_actions = array();
533 $install_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>';
534 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
535 $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>';
537 $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
539 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
540 $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>';
542 if ( $this->type == 'web' )
543 $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>';
544 elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
545 $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
547 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
548 unset( $install_actions['activate'], $install_actions['preview'] );
551 * Filter the list of action links available following a single theme installation.
555 * @param array $install_actions Array of theme action links.
556 * @param object $api Object containing WordPress.org API theme data.
557 * @param string $stylesheet Theme directory name.
558 * @param WP_Theme $theme_info Theme object.
560 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
561 if ( ! empty($install_actions) )
562 $this->feedback(implode(' | ', (array)$install_actions));
567 * Theme Upgrader Skin for WordPress Theme Upgrades.
570 * @subpackage Upgrader
573 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
576 public function __construct($args = array()) {
577 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
578 $args = wp_parse_args($args, $defaults);
580 $this->theme = $args['theme'];
582 parent::__construct($args);
585 public function after() {
586 $this->decrement_update_count( 'theme' );
588 $update_actions = array();
589 if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
590 $name = $theme_info->display('Name');
591 $stylesheet = $this->upgrader->result['destination_name'];
592 $template = $theme_info->get_template();
594 $preview_link = add_query_arg( array(
596 'template' => urlencode( $template ),
597 'stylesheet' => urlencode( $stylesheet ),
598 ), trailingslashit( home_url() ) );
600 $activate_link = add_query_arg( array(
601 'action' => 'activate',
602 'template' => urlencode( $template ),
603 'stylesheet' => urlencode( $stylesheet ),
604 ), admin_url('themes.php') );
605 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
607 if ( get_stylesheet() == $stylesheet ) {
608 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
609 $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>';
611 } elseif ( current_user_can( 'switch_themes' ) ) {
612 $update_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>';
613 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
614 $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>';
616 $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
619 if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
620 unset( $update_actions['preview'], $update_actions['activate'] );
623 $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>';
626 * Filter the list of action links available following a single theme update.
630 * @param array $update_actions Array of theme action links.
631 * @param string $theme Theme directory name.
633 $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
635 if ( ! empty($update_actions) )
636 $this->feedback(implode(' | ', (array)$update_actions));
641 * Translation Upgrader Skin for WordPress Translation Upgrades.
644 * @subpackage Upgrader
647 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
648 public $language_update = null;
649 public $done_header = false;
650 public $done_footer = false;
651 public $display_footer_actions = true;
653 public function __construct( $args = array() ) {
654 $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
655 $args = wp_parse_args( $args, $defaults );
656 if ( $args['skip_header_footer'] ) {
657 $this->done_header = true;
658 $this->done_footer = true;
659 $this->display_footer_actions = false;
661 parent::__construct( $args );
664 public function before() {
665 $name = $this->upgrader->get_name_for_update( $this->language_update );
667 echo '<div class="update-messages lp-show-latest">';
669 printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)…' ) . '</h4>', $name, $this->language_update->language );
672 public function error( $error ) {
673 echo '<div class="lp-error">';
674 parent::error( $error );
678 public function after() {
682 public function bulk_footer() {
683 $this->decrement_update_count( 'translation' );
684 $update_actions = array();
685 $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>';
688 * Filter the list of action links available following a translations update.
692 * @param array $update_actions Array of translations update links.
694 $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
696 if ( $update_actions && $this->display_footer_actions )
697 $this->feedback( implode( ' | ', $update_actions ) );
702 * Upgrader Skin for Automatic WordPress Upgrades
704 * This skin is designed to be used when no output is intended, all output
705 * is captured and stored for the caller to process and log/email/discard.
708 * @subpackage Upgrader
711 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
712 protected $messages = array();
714 public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
716 $this->options['context'] = $context;
718 // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
719 // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
721 $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
726 public function get_upgrade_messages() {
727 return $this->messages;
731 * @param string|array|WP_Error $data
733 public function feedback( $data ) {
734 if ( is_wp_error( $data ) )
735 $string = $data->get_error_message();
736 else if ( is_array( $data ) )
741 if ( ! empty( $this->upgrader->strings[ $string ] ) )
742 $string = $this->upgrader->strings[ $string ];
744 if ( strpos( $string, '%' ) !== false ) {
745 $args = func_get_args();
746 $args = array_splice( $args, 1 );
747 if ( ! empty( $args ) )
748 $string = vsprintf( $string, $args );
751 $string = trim( $string );
753 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
754 $string = wp_kses( $string, array(
763 if ( empty( $string ) )
766 $this->messages[] = $string;
769 public function header() {
773 public function footer() {
774 $output = ob_get_contents();
775 if ( ! empty( $output ) )
776 $this->feedback( $output );
780 public function bulk_header() {}
781 public function bulk_footer() {}
782 public function before() {}
783 public function after() {}