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