0
|
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 |
|
5
|
19 |
public $upgrader; |
|
20 |
public $done_header = false; |
|
21 |
public $done_footer = false; |
|
22 |
public $result = false; |
|
23 |
public $options = array(); |
0
|
24 |
|
5
|
25 |
public function __construct($args = array()) { |
0
|
26 |
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); |
|
27 |
$this->options = wp_parse_args($args, $defaults); |
|
28 |
} |
|
29 |
|
5
|
30 |
/** |
|
31 |
* @param WP_Upgrader $upgrader |
|
32 |
*/ |
|
33 |
public function set_upgrader(&$upgrader) { |
0
|
34 |
if ( is_object($upgrader) ) |
|
35 |
$this->upgrader =& $upgrader; |
|
36 |
$this->add_strings(); |
|
37 |
} |
|
38 |
|
5
|
39 |
public function add_strings() { |
0
|
40 |
} |
|
41 |
|
5
|
42 |
public function set_result($result) { |
0
|
43 |
$this->result = $result; |
|
44 |
} |
|
45 |
|
5
|
46 |
public function request_filesystem_credentials( $error = false, $context = false, $allow_relaxed_file_ownership = false ) { |
0
|
47 |
$url = $this->options['url']; |
5
|
48 |
if ( ! $context ) { |
|
49 |
$context = $this->options['context']; |
|
50 |
} |
|
51 |
if ( !empty($this->options['nonce']) ) { |
0
|
52 |
$url = wp_nonce_url($url, $this->options['nonce']); |
5
|
53 |
} |
|
54 |
|
|
55 |
$extra_fields = array(); |
|
56 |
|
|
57 |
return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership ); |
0
|
58 |
} |
|
59 |
|
5
|
60 |
public function header() { |
|
61 |
if ( $this->done_header ) { |
0
|
62 |
return; |
5
|
63 |
} |
0
|
64 |
$this->done_header = true; |
|
65 |
echo '<div class="wrap">'; |
|
66 |
echo '<h2>' . $this->options['title'] . '</h2>'; |
|
67 |
} |
5
|
68 |
public function footer() { |
|
69 |
if ( $this->done_footer ) { |
|
70 |
return; |
|
71 |
} |
|
72 |
$this->done_footer = true; |
0
|
73 |
echo '</div>'; |
|
74 |
} |
|
75 |
|
5
|
76 |
public function error($errors) { |
0
|
77 |
if ( ! $this->done_header ) |
|
78 |
$this->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() ) ) |
5
|
84 |
$this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) ); |
0
|
85 |
else |
|
86 |
$this->feedback($message); |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
|
5
|
91 |
public function feedback($string) { |
0
|
92 |
if ( isset( $this->upgrader->strings[$string] ) ) |
|
93 |
$string = $this->upgrader->strings[$string]; |
|
94 |
|
|
95 |
if ( strpos($string, '%') !== false ) { |
|
96 |
$args = func_get_args(); |
|
97 |
$args = array_splice($args, 1); |
|
98 |
if ( $args ) { |
|
99 |
$args = array_map( 'strip_tags', $args ); |
|
100 |
$args = array_map( 'esc_html', $args ); |
|
101 |
$string = vsprintf($string, $args); |
|
102 |
} |
|
103 |
} |
|
104 |
if ( empty($string) ) |
|
105 |
return; |
|
106 |
show_message($string); |
|
107 |
} |
5
|
108 |
public function before() {} |
|
109 |
public function after() {} |
|
110 |
|
|
111 |
/** |
|
112 |
* Output JavaScript that calls function to decrement the update counts. |
|
113 |
* |
|
114 |
* @since 3.9.0 |
|
115 |
* |
|
116 |
* @param string $type Type of update count to decrement. Likely values include 'plugin', |
|
117 |
* 'theme', 'translation', etc. |
|
118 |
*/ |
|
119 |
protected function decrement_update_count( $type ) { |
|
120 |
if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) { |
|
121 |
return; |
|
122 |
} |
0
|
123 |
|
5
|
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 ); |
|
128 |
} |
|
129 |
</script>'; |
|
130 |
} else { |
|
131 |
echo '<script type="text/javascript"> |
|
132 |
(function( wp ) { |
|
133 |
if ( wp && wp.updates.decrementCount ) { |
|
134 |
wp.updates.decrementCount( "' . $type . '" ); |
|
135 |
} |
|
136 |
})( window.wp ); |
|
137 |
</script>'; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
public function bulk_header() {} |
|
142 |
public function bulk_footer() {} |
0
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* Plugin Upgrader Skin for WordPress Plugin Upgrades. |
|
147 |
* |
|
148 |
* @package WordPress |
|
149 |
* @subpackage Upgrader |
|
150 |
* @since 2.8.0 |
|
151 |
*/ |
|
152 |
class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { |
5
|
153 |
public $plugin = ''; |
|
154 |
public $plugin_active = false; |
|
155 |
public $plugin_network_active = false; |
0
|
156 |
|
5
|
157 |
public function __construct($args = array()) { |
0
|
158 |
$defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') ); |
|
159 |
$args = wp_parse_args($args, $defaults); |
|
160 |
|
|
161 |
$this->plugin = $args['plugin']; |
|
162 |
|
|
163 |
$this->plugin_active = is_plugin_active( $this->plugin ); |
|
164 |
$this->plugin_network_active = is_plugin_active_for_network( $this->plugin ); |
|
165 |
|
|
166 |
parent::__construct($args); |
|
167 |
} |
|
168 |
|
5
|
169 |
public function after() { |
0
|
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>'; |
|
173 |
} |
|
174 |
|
5
|
175 |
$this->decrement_update_count( 'plugin' ); |
|
176 |
|
0
|
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>' |
|
180 |
); |
|
181 |
if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) ) |
|
182 |
unset( $update_actions['activate_plugin'] ); |
|
183 |
|
5
|
184 |
/** |
|
185 |
* Filter the list of action links available following a single plugin update. |
|
186 |
* |
|
187 |
* @since 2.7.0 |
|
188 |
* |
|
189 |
* @param array $update_actions Array of plugin action links. |
|
190 |
* @param string $plugin Path to the plugin file. |
|
191 |
*/ |
|
192 |
$update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin ); |
|
193 |
|
0
|
194 |
if ( ! empty($update_actions) ) |
|
195 |
$this->feedback(implode(' | ', (array)$update_actions)); |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Plugin Upgrader Skin for WordPress Plugin Upgrades. |
|
201 |
* |
|
202 |
* @package WordPress |
|
203 |
* @subpackage Upgrader |
|
204 |
* @since 3.0.0 |
|
205 |
*/ |
|
206 |
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { |
5
|
207 |
public $in_loop = false; |
|
208 |
/** |
|
209 |
* @var string|false |
|
210 |
*/ |
|
211 |
public $error = false; |
0
|
212 |
|
5
|
213 |
public function __construct($args = array()) { |
0
|
214 |
$defaults = array( 'url' => '', 'nonce' => '' ); |
|
215 |
$args = wp_parse_args($args, $defaults); |
|
216 |
|
|
217 |
parent::__construct($args); |
|
218 |
} |
|
219 |
|
5
|
220 |
public function add_strings() { |
0
|
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.'); |
5
|
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>'; |
0
|
225 |
$this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); |
|
226 |
} |
|
227 |
|
5
|
228 |
/** |
|
229 |
* @param string $string |
|
230 |
*/ |
|
231 |
public function feedback($string) { |
0
|
232 |
if ( isset( $this->upgrader->strings[$string] ) ) |
|
233 |
$string = $this->upgrader->strings[$string]; |
|
234 |
|
|
235 |
if ( strpos($string, '%') !== false ) { |
|
236 |
$args = func_get_args(); |
|
237 |
$args = array_splice($args, 1); |
|
238 |
if ( $args ) { |
|
239 |
$args = array_map( 'strip_tags', $args ); |
|
240 |
$args = array_map( 'esc_html', $args ); |
|
241 |
$string = vsprintf($string, $args); |
|
242 |
} |
|
243 |
} |
|
244 |
if ( empty($string) ) |
|
245 |
return; |
|
246 |
if ( $this->in_loop ) |
|
247 |
echo "$string<br />\n"; |
|
248 |
else |
|
249 |
echo "<p>$string</p>\n"; |
|
250 |
} |
|
251 |
|
5
|
252 |
public function header() { |
0
|
253 |
// Nothing, This will be displayed within a iframe. |
|
254 |
} |
|
255 |
|
5
|
256 |
public function footer() { |
0
|
257 |
// Nothing, This will be displayed within a iframe. |
|
258 |
} |
5
|
259 |
public function error($error) { |
0
|
260 |
if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) |
|
261 |
$this->error = $this->upgrader->strings[$error]; |
|
262 |
|
|
263 |
if ( is_wp_error($error) ) { |
5
|
264 |
$messages = array(); |
0
|
265 |
foreach ( $error->get_error_messages() as $emessage ) { |
|
266 |
if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) |
5
|
267 |
$messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) ); |
0
|
268 |
else |
|
269 |
$messages[] = $emessage; |
|
270 |
} |
|
271 |
$this->error = implode(', ', $messages); |
|
272 |
} |
|
273 |
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; |
|
274 |
} |
|
275 |
|
5
|
276 |
public function bulk_header() { |
0
|
277 |
$this->feedback('skin_upgrade_start'); |
|
278 |
} |
|
279 |
|
5
|
280 |
public function bulk_footer() { |
0
|
281 |
$this->feedback('skin_upgrade_end'); |
|
282 |
} |
|
283 |
|
5
|
284 |
public function before($title = '') { |
0
|
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(); |
|
290 |
} |
|
291 |
|
5
|
292 |
public function after($title = '') { |
0
|
293 |
echo '</p></div>'; |
|
294 |
if ( $this->error || ! $this->result ) { |
|
295 |
if ( $this->error ) |
|
296 |
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>'; |
|
297 |
else |
|
298 |
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>'; |
|
299 |
|
|
300 |
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>'; |
|
301 |
} |
|
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>'; |
|
306 |
} |
|
307 |
|
|
308 |
$this->reset(); |
|
309 |
$this->flush_output(); |
|
310 |
} |
|
311 |
|
5
|
312 |
public function reset() { |
0
|
313 |
$this->in_loop = false; |
|
314 |
$this->error = false; |
|
315 |
} |
|
316 |
|
5
|
317 |
public function flush_output() { |
0
|
318 |
wp_ob_end_flush_all(); |
|
319 |
flush(); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { |
5
|
324 |
public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in. |
0
|
325 |
|
5
|
326 |
public function add_strings() { |
0
|
327 |
parent::add_strings(); |
|
328 |
$this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); |
|
329 |
} |
|
330 |
|
5
|
331 |
public function before($title = '') { |
0
|
332 |
parent::before($this->plugin_info['Title']); |
|
333 |
} |
|
334 |
|
5
|
335 |
public function after($title = '') { |
0
|
336 |
parent::after($this->plugin_info['Title']); |
5
|
337 |
$this->decrement_update_count( 'plugin' ); |
0
|
338 |
} |
5
|
339 |
public function bulk_footer() { |
0
|
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>' |
|
344 |
); |
|
345 |
if ( ! current_user_can( 'activate_plugins' ) ) |
|
346 |
unset( $update_actions['plugins_page'] ); |
|
347 |
|
5
|
348 |
/** |
|
349 |
* Filter the list of action links available following bulk plugin updates. |
|
350 |
* |
|
351 |
* @since 3.0.0 |
|
352 |
* |
|
353 |
* @param array $update_actions Array of plugin action links. |
|
354 |
* @param array $plugin_info Array of information for the last-updated plugin. |
|
355 |
*/ |
|
356 |
$update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info ); |
|
357 |
|
0
|
358 |
if ( ! empty($update_actions) ) |
|
359 |
$this->feedback(implode(' | ', (array)$update_actions)); |
|
360 |
} |
|
361 |
} |
|
362 |
|
|
363 |
class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { |
5
|
364 |
public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in. |
0
|
365 |
|
5
|
366 |
public function add_strings() { |
0
|
367 |
parent::add_strings(); |
|
368 |
$this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); |
|
369 |
} |
|
370 |
|
5
|
371 |
public function before($title = '') { |
0
|
372 |
parent::before( $this->theme_info->display('Name') ); |
|
373 |
} |
|
374 |
|
5
|
375 |
public function after($title = '') { |
0
|
376 |
parent::after( $this->theme_info->display('Name') ); |
5
|
377 |
$this->decrement_update_count( 'theme' ); |
0
|
378 |
} |
|
379 |
|
5
|
380 |
public function bulk_footer() { |
0
|
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>' |
|
385 |
); |
|
386 |
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) |
|
387 |
unset( $update_actions['themes_page'] ); |
|
388 |
|
5
|
389 |
/** |
|
390 |
* Filter the list of action links available following bulk theme updates. |
|
391 |
* |
|
392 |
* @since 3.0.0 |
|
393 |
* |
|
394 |
* @param array $update_actions Array of theme action links. |
|
395 |
* @param array $theme_info Array of information for the last-updated theme. |
|
396 |
*/ |
|
397 |
$update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info ); |
|
398 |
|
0
|
399 |
if ( ! empty($update_actions) ) |
|
400 |
$this->feedback(implode(' | ', (array)$update_actions)); |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
/** |
|
405 |
* Plugin Installer Skin for WordPress Plugin Installer. |
|
406 |
* |
|
407 |
* @package WordPress |
|
408 |
* @subpackage Upgrader |
|
409 |
* @since 2.8.0 |
|
410 |
*/ |
|
411 |
class Plugin_Installer_Skin extends WP_Upgrader_Skin { |
5
|
412 |
public $api; |
|
413 |
public $type; |
0
|
414 |
|
5
|
415 |
public function __construct($args = array()) { |
0
|
416 |
$defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); |
|
417 |
$args = wp_parse_args($args, $defaults); |
|
418 |
|
|
419 |
$this->type = $args['type']; |
|
420 |
$this->api = isset($args['api']) ? $args['api'] : array(); |
|
421 |
|
|
422 |
parent::__construct($args); |
|
423 |
} |
|
424 |
|
5
|
425 |
public function before() { |
0
|
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); |
|
428 |
} |
|
429 |
|
5
|
430 |
public function after() { |
0
|
431 |
|
|
432 |
$plugin_file = $this->upgrader->plugin_info(); |
|
433 |
|
|
434 |
$install_actions = array(); |
|
435 |
|
|
436 |
$from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins'; |
|
437 |
|
|
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>'; |
|
440 |
else |
|
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>'; |
|
442 |
|
|
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'] ); |
|
446 |
} |
|
447 |
|
5
|
448 |
if ( 'import' == $from ) { |
0
|
449 |
$install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>'; |
5
|
450 |
} elseif ( $this->type == 'web' ) { |
0
|
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>'; |
5
|
452 |
} else { |
0
|
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>'; |
5
|
454 |
} |
0
|
455 |
|
|
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'] ); |
|
460 |
} |
|
461 |
|
5
|
462 |
/** |
|
463 |
* Filter the list of action links available following a single plugin installation. |
|
464 |
* |
|
465 |
* @since 2.7.0 |
|
466 |
* |
|
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 |
|
470 |
* via upload. |
|
471 |
* @param string $plugin_file Path to the plugin file. |
|
472 |
*/ |
|
473 |
$install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file ); |
|
474 |
|
0
|
475 |
if ( ! empty($install_actions) ) |
|
476 |
$this->feedback(implode(' | ', (array)$install_actions)); |
|
477 |
} |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Theme Installer Skin for the WordPress Theme Installer. |
|
482 |
* |
|
483 |
* @package WordPress |
|
484 |
* @subpackage Upgrader |
|
485 |
* @since 2.8.0 |
|
486 |
*/ |
|
487 |
class Theme_Installer_Skin extends WP_Upgrader_Skin { |
5
|
488 |
public $api; |
|
489 |
public $type; |
0
|
490 |
|
5
|
491 |
public function __construct($args = array()) { |
0
|
492 |
$defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); |
|
493 |
$args = wp_parse_args($args, $defaults); |
|
494 |
|
|
495 |
$this->type = $args['type']; |
|
496 |
$this->api = isset($args['api']) ? $args['api'] : array(); |
|
497 |
|
|
498 |
parent::__construct($args); |
|
499 |
} |
|
500 |
|
5
|
501 |
public function before() { |
0
|
502 |
if ( !empty($this->api) ) |
|
503 |
$this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); |
|
504 |
} |
|
505 |
|
5
|
506 |
public function after() { |
0
|
507 |
if ( empty($this->upgrader->result['destination_name']) ) |
|
508 |
return; |
|
509 |
|
|
510 |
$theme_info = $this->upgrader->theme_info(); |
|
511 |
if ( empty( $theme_info ) ) |
|
512 |
return; |
|
513 |
|
|
514 |
$name = $theme_info->display('Name'); |
|
515 |
$stylesheet = $this->upgrader->result['destination_name']; |
|
516 |
$template = $theme_info->get_template(); |
|
517 |
|
|
518 |
$preview_link = add_query_arg( array( |
|
519 |
'preview' => 1, |
|
520 |
'template' => urlencode( $template ), |
|
521 |
'stylesheet' => urlencode( $stylesheet ), |
|
522 |
), trailingslashit( home_url() ) ); |
|
523 |
|
|
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 ); |
|
530 |
|
|
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>'; |
5
|
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>'; |
|
535 |
} |
0
|
536 |
$install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; |
|
537 |
|
|
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>'; |
|
540 |
|
|
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>'; |
|
545 |
|
|
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'] ); |
|
548 |
|
5
|
549 |
/** |
|
550 |
* Filter the list of action links available following a single theme installation. |
|
551 |
* |
|
552 |
* @since 2.8.0 |
|
553 |
* |
|
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. |
|
558 |
*/ |
|
559 |
$install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); |
0
|
560 |
if ( ! empty($install_actions) ) |
|
561 |
$this->feedback(implode(' | ', (array)$install_actions)); |
|
562 |
} |
|
563 |
} |
|
564 |
|
|
565 |
/** |
|
566 |
* Theme Upgrader Skin for WordPress Theme Upgrades. |
|
567 |
* |
|
568 |
* @package WordPress |
|
569 |
* @subpackage Upgrader |
|
570 |
* @since 2.8.0 |
|
571 |
*/ |
|
572 |
class Theme_Upgrader_Skin extends WP_Upgrader_Skin { |
5
|
573 |
public $theme = ''; |
0
|
574 |
|
5
|
575 |
public function __construct($args = array()) { |
0
|
576 |
$defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); |
|
577 |
$args = wp_parse_args($args, $defaults); |
|
578 |
|
|
579 |
$this->theme = $args['theme']; |
|
580 |
|
|
581 |
parent::__construct($args); |
|
582 |
} |
|
583 |
|
5
|
584 |
public function after() { |
|
585 |
$this->decrement_update_count( 'theme' ); |
0
|
586 |
|
|
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(); |
|
592 |
|
|
593 |
$preview_link = add_query_arg( array( |
|
594 |
'preview' => 1, |
|
595 |
'template' => urlencode( $template ), |
|
596 |
'stylesheet' => urlencode( $stylesheet ), |
|
597 |
), trailingslashit( home_url() ) ); |
|
598 |
|
|
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 ); |
|
605 |
|
|
606 |
if ( get_stylesheet() == $stylesheet ) { |
5
|
607 |
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
0
|
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>'; |
5
|
609 |
} |
0
|
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>'; |
5
|
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>'; |
|
614 |
} |
0
|
615 |
$update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; |
|
616 |
} |
|
617 |
|
|
618 |
if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) |
|
619 |
unset( $update_actions['preview'], $update_actions['activate'] ); |
|
620 |
} |
|
621 |
|
|
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>'; |
|
623 |
|
5
|
624 |
/** |
|
625 |
* Filter the list of action links available following a single theme update. |
|
626 |
* |
|
627 |
* @since 2.8.0 |
|
628 |
* |
|
629 |
* @param array $update_actions Array of theme action links. |
|
630 |
* @param string $theme Theme directory name. |
|
631 |
*/ |
|
632 |
$update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme ); |
|
633 |
|
0
|
634 |
if ( ! empty($update_actions) ) |
|
635 |
$this->feedback(implode(' | ', (array)$update_actions)); |
|
636 |
} |
|
637 |
} |
|
638 |
|
|
639 |
/** |
|
640 |
* Translation Upgrader Skin for WordPress Translation Upgrades. |
|
641 |
* |
|
642 |
* @package WordPress |
|
643 |
* @subpackage Upgrader |
|
644 |
* @since 3.7.0 |
|
645 |
*/ |
|
646 |
class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin { |
5
|
647 |
public $language_update = null; |
|
648 |
public $done_header = false; |
|
649 |
public $done_footer = false; |
|
650 |
public $display_footer_actions = true; |
0
|
651 |
|
5
|
652 |
public function __construct( $args = array() ) { |
0
|
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; |
5
|
657 |
$this->done_footer = true; |
0
|
658 |
$this->display_footer_actions = false; |
|
659 |
} |
|
660 |
parent::__construct( $args ); |
|
661 |
} |
|
662 |
|
5
|
663 |
public function before() { |
0
|
664 |
$name = $this->upgrader->get_name_for_update( $this->language_update ); |
|
665 |
|
|
666 |
echo '<div class="update-messages lp-show-latest">'; |
|
667 |
|
|
668 |
printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)…' ) . '</h4>', $name, $this->language_update->language ); |
|
669 |
} |
|
670 |
|
5
|
671 |
public function error( $error ) { |
0
|
672 |
echo '<div class="lp-error">'; |
|
673 |
parent::error( $error ); |
|
674 |
echo '</div>'; |
|
675 |
} |
|
676 |
|
5
|
677 |
public function after() { |
0
|
678 |
echo '</div>'; |
|
679 |
} |
|
680 |
|
5
|
681 |
public function bulk_footer() { |
|
682 |
$this->decrement_update_count( 'translation' ); |
0
|
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>'; |
5
|
685 |
|
|
686 |
/** |
|
687 |
* Filter the list of action links available following a translations update. |
|
688 |
* |
|
689 |
* @since 3.7.0 |
|
690 |
* |
|
691 |
* @param array $update_actions Array of translations update links. |
|
692 |
*/ |
0
|
693 |
$update_actions = apply_filters( 'update_translations_complete_actions', $update_actions ); |
|
694 |
|
|
695 |
if ( $update_actions && $this->display_footer_actions ) |
|
696 |
$this->feedback( implode( ' | ', $update_actions ) ); |
|
697 |
} |
|
698 |
} |
|
699 |
|
|
700 |
/** |
|
701 |
* Upgrader Skin for Automatic WordPress Upgrades |
|
702 |
* |
|
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. |
|
705 |
* |
|
706 |
* @package WordPress |
|
707 |
* @subpackage Upgrader |
|
708 |
* @since 3.7.0 |
|
709 |
*/ |
|
710 |
class Automatic_Upgrader_Skin extends WP_Upgrader_Skin { |
|
711 |
protected $messages = array(); |
|
712 |
|
5
|
713 |
public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) { |
|
714 |
if ( $context ) { |
0
|
715 |
$this->options['context'] = $context; |
5
|
716 |
} |
0
|
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 |
|
719 |
ob_start(); |
5
|
720 |
$result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership ); |
0
|
721 |
ob_end_clean(); |
|
722 |
return $result; |
|
723 |
} |
|
724 |
|
5
|
725 |
public function get_upgrade_messages() { |
0
|
726 |
return $this->messages; |
|
727 |
} |
|
728 |
|
5
|
729 |
/** |
|
730 |
* @param string|array|WP_Error $data |
|
731 |
*/ |
|
732 |
public function feedback( $data ) { |
|
733 |
if ( is_wp_error( $data ) ) { |
0
|
734 |
$string = $data->get_error_message(); |
5
|
735 |
} elseif ( is_array( $data ) ) { |
0
|
736 |
return; |
5
|
737 |
} else { |
0
|
738 |
$string = $data; |
5
|
739 |
} |
0
|
740 |
if ( ! empty( $this->upgrader->strings[ $string ] ) ) |
|
741 |
$string = $this->upgrader->strings[ $string ]; |
|
742 |
|
|
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 ); |
|
748 |
} |
|
749 |
|
|
750 |
$string = trim( $string ); |
|
751 |
|
|
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( |
|
754 |
'a' => array( |
|
755 |
'href' => true |
|
756 |
), |
|
757 |
'br' => true, |
|
758 |
'em' => true, |
|
759 |
'strong' => true, |
|
760 |
) ); |
|
761 |
|
|
762 |
if ( empty( $string ) ) |
|
763 |
return; |
|
764 |
|
|
765 |
$this->messages[] = $string; |
|
766 |
} |
|
767 |
|
5
|
768 |
public function header() { |
0
|
769 |
ob_start(); |
|
770 |
} |
|
771 |
|
5
|
772 |
public function footer() { |
0
|
773 |
$output = ob_get_contents(); |
|
774 |
if ( ! empty( $output ) ) |
|
775 |
$this->feedback( $output ); |
|
776 |
ob_end_clean(); |
|
777 |
} |
|
778 |
|
5
|
779 |
public function bulk_header() {} |
|
780 |
public function bulk_footer() {} |
|
781 |
public function before() {} |
|
782 |
public function after() {} |
0
|
783 |
} |