14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
15 * |
15 * |
16 * @see WP_Upgrader_Skin |
16 * @see WP_Upgrader_Skin |
17 */ |
17 */ |
18 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { |
18 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { |
|
19 |
|
20 /** |
|
21 * Whether the bulk update process has started. |
|
22 * |
|
23 * @since 3.0.0 |
|
24 * @var bool |
|
25 */ |
19 public $in_loop = false; |
26 public $in_loop = false; |
20 /** |
27 |
|
28 /** |
|
29 * Stores an error message about the update. |
|
30 * |
|
31 * @since 3.0.0 |
21 * @var string|false |
32 * @var string|false |
22 */ |
33 */ |
23 public $error = false; |
34 public $error = false; |
24 |
35 |
25 /** |
36 /** |
|
37 * Constructor. |
|
38 * |
|
39 * Sets up the generic skin for the Bulk Upgrader classes. |
|
40 * |
|
41 * @since 3.0.0 |
|
42 * |
26 * @param array $args |
43 * @param array $args |
27 */ |
44 */ |
28 public function __construct( $args = array() ) { |
45 public function __construct( $args = array() ) { |
29 $defaults = array( |
46 $defaults = array( |
30 'url' => '', |
47 'url' => '', |
47 $this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' ); |
67 $this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' ); |
48 $this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' ); |
68 $this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' ); |
49 } |
69 } |
50 |
70 |
51 /** |
71 /** |
|
72 * Displays a message about the update. |
|
73 * |
|
74 * @since 3.0.0 |
52 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support. |
75 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support. |
53 * |
76 * |
54 * @param string $feedback Message data. |
77 * @param string $feedback Message data. |
55 * @param mixed ...$args Optional text replacements. |
78 * @param mixed ...$args Optional text replacements. |
56 */ |
79 */ |
57 public function feedback( $feedback, ...$args ) { |
80 public function feedback( $feedback, ...$args ) { |
58 if ( isset( $this->upgrader->strings[ $feedback ] ) ) { |
81 if ( isset( $this->upgrader->strings[ $feedback ] ) ) { |
59 $feedback = $this->upgrader->strings[ $feedback ]; |
82 $feedback = $this->upgrader->strings[ $feedback ]; |
60 } |
83 } |
61 |
84 |
62 if ( strpos( $feedback, '%' ) !== false ) { |
85 if ( str_contains( $feedback, '%' ) ) { |
63 if ( $args ) { |
86 if ( $args ) { |
64 $args = array_map( 'strip_tags', $args ); |
87 $args = array_map( 'strip_tags', $args ); |
65 $args = array_map( 'esc_html', $args ); |
88 $args = array_map( 'esc_html', $args ); |
66 $feedback = vsprintf( $feedback, $args ); |
89 $feedback = vsprintf( $feedback, $args ); |
67 } |
90 } |
75 echo "<p>$feedback</p>\n"; |
98 echo "<p>$feedback</p>\n"; |
76 } |
99 } |
77 } |
100 } |
78 |
101 |
79 /** |
102 /** |
|
103 * Displays the header before the update process. |
|
104 * |
|
105 * @since 3.0.0 |
80 */ |
106 */ |
81 public function header() { |
107 public function header() { |
82 // Nothing, This will be displayed within a iframe. |
108 // Nothing. This will be displayed within an iframe. |
83 } |
109 } |
84 |
110 |
85 /** |
111 /** |
|
112 * Displays the footer following the update process. |
|
113 * |
|
114 * @since 3.0.0 |
86 */ |
115 */ |
87 public function footer() { |
116 public function footer() { |
88 // Nothing, This will be displayed within a iframe. |
117 // Nothing. This will be displayed within an iframe. |
89 } |
118 } |
90 |
119 |
91 /** |
120 /** |
|
121 * Displays an error message about the update. |
|
122 * |
|
123 * @since 3.0.0 |
92 * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support. |
124 * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support. |
93 * |
125 * |
94 * @param string|WP_Error $errors Errors. |
126 * @param string|WP_Error $errors Errors. |
95 */ |
127 */ |
96 public function error( $errors ) { |
128 public function error( $errors ) { |
111 } |
143 } |
112 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; |
144 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; |
113 } |
145 } |
114 |
146 |
115 /** |
147 /** |
|
148 * Displays the header before the bulk update process. |
|
149 * |
|
150 * @since 3.0.0 |
116 */ |
151 */ |
117 public function bulk_header() { |
152 public function bulk_header() { |
118 $this->feedback( 'skin_upgrade_start' ); |
153 $this->feedback( 'skin_upgrade_start' ); |
119 } |
154 } |
120 |
155 |
121 /** |
156 /** |
|
157 * Displays the footer following the bulk update process. |
|
158 * |
|
159 * @since 3.0.0 |
122 */ |
160 */ |
123 public function bulk_footer() { |
161 public function bulk_footer() { |
124 $this->feedback( 'skin_upgrade_end' ); |
162 $this->feedback( 'skin_upgrade_end' ); |
125 } |
163 } |
126 |
164 |
127 /** |
165 /** |
|
166 * Performs an action before a bulk update. |
|
167 * |
|
168 * @since 3.0.0 |
|
169 * |
128 * @param string $title |
170 * @param string $title |
129 */ |
171 */ |
130 public function before( $title = '' ) { |
172 public function before( $title = '' ) { |
131 $this->in_loop = true; |
173 $this->in_loop = true; |
132 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 ); |
174 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 ); |
133 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>'; |
175 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>'; |
134 // This progress messages div gets moved via JavaScript when clicking on "Show details.". |
176 // This progress messages div gets moved via JavaScript when clicking on "More details.". |
135 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>'; |
177 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>'; |
136 $this->flush_output(); |
178 $this->flush_output(); |
137 } |
179 } |
138 |
180 |
139 /** |
181 /** |
|
182 * Performs an action following a bulk update. |
|
183 * |
|
184 * @since 3.0.0 |
|
185 * |
140 * @param string $title |
186 * @param string $title |
141 */ |
187 */ |
142 public function after( $title = '' ) { |
188 public function after( $title = '' ) { |
143 echo '</p></div>'; |
189 echo '</p></div>'; |
144 if ( $this->error || ! $this->result ) { |
190 if ( $this->error || ! $this->result ) { |
145 if ( $this->error ) { |
191 if ( $this->error ) { |
146 echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>'; |
192 $after_error_message = sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ); |
147 } else { |
193 } else { |
148 echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>'; |
194 $after_error_message = sprintf( $this->upgrader->strings['skin_update_failed'], $title ); |
149 } |
195 } |
|
196 wp_admin_notice( |
|
197 $after_error_message, |
|
198 array( |
|
199 'additional_classes' => array( 'error' ), |
|
200 ) |
|
201 ); |
150 |
202 |
151 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>'; |
203 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>'; |
152 } |
204 } |
153 if ( $this->result && ! is_wp_error( $this->result ) ) { |
205 if ( $this->result && ! is_wp_error( $this->result ) ) { |
154 if ( ! $this->error ) { |
206 if ( ! $this->error ) { |
155 echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' . |
207 echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' . |
156 '<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) . |
208 '<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) . |
157 ' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' . |
209 ' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'More details.' ) . '<span class="dashicons dashicons-arrow-down" aria-hidden="true"></span></button>' . |
158 '</p></div>'; |
210 '</p></div>'; |
159 } |
211 } |
160 |
212 |
161 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; |
213 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; |
162 } |
214 } |