3 * Upgrader API: Bulk_Upgrader_Skin class
11 * Generic Bulk Upgrader Skin for WordPress Upgrades.
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
16 * @see WP_Upgrader_Skin
18 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
19 public $in_loop = false;
23 public $error = false;
29 public function __construct($args = array()) {
30 $defaults = array( 'url' => '', 'nonce' => '' );
31 $args = wp_parse_args($args, $defaults);
33 parent::__construct($args);
39 public function add_strings() {
40 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
41 /* translators: 1: Title of an update, 2: Error message */
42 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s');
43 /* translators: 1: Title of an update */
44 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
45 /* translators: 1: Title of an update */
46 $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>';
47 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
51 * @param string $string
53 public function feedback($string) {
54 if ( isset( $this->upgrader->strings[$string] ) )
55 $string = $this->upgrader->strings[$string];
57 if ( strpos($string, '%') !== false ) {
58 $args = func_get_args();
59 $args = array_splice($args, 1);
61 $args = array_map( 'strip_tags', $args );
62 $args = array_map( 'esc_html', $args );
63 $string = vsprintf($string, $args);
69 echo "$string<br />\n";
71 echo "<p>$string</p>\n";
77 public function header() {
78 // Nothing, This will be displayed within a iframe.
84 public function footer() {
85 // Nothing, This will be displayed within a iframe.
90 * @param string|WP_Error $error
92 public function error($error) {
93 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
94 $this->error = $this->upgrader->strings[$error];
96 if ( is_wp_error($error) ) {
98 foreach ( $error->get_error_messages() as $emessage ) {
99 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
100 $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
102 $messages[] = $emessage;
104 $this->error = implode(', ', $messages);
106 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
112 public function bulk_header() {
113 $this->feedback('skin_upgrade_start');
119 public function bulk_footer() {
120 $this->feedback('skin_upgrade_end');
125 * @param string $title
127 public function before($title = '') {
128 $this->in_loop = true;
129 printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
130 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
131 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
132 $this->flush_output();
137 * @param string $title
139 public function after($title = '') {
141 if ( $this->error || ! $this->result ) {
142 if ( $this->error ) {
143 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
145 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
148 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
150 if ( $this->result && ! is_wp_error( $this->result ) ) {
151 if ( ! $this->error )
152 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>';
153 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
157 $this->flush_output();
163 public function reset() {
164 $this->in_loop = false;
165 $this->error = false;
171 public function flush_output() {
172 wp_ob_end_flush_all();