|
1 <?php |
|
2 /** |
|
3 * Upgrader API: Theme_Upgrader_Skin class |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Upgrader |
|
7 * @since 4.6.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Theme Upgrader Skin for WordPress Theme Upgrades. |
|
12 * |
|
13 * @since 2.8.0 |
|
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
|
15 * |
|
16 * @see WP_Upgrader_Skin |
|
17 */ |
|
18 class Theme_Upgrader_Skin extends WP_Upgrader_Skin { |
|
19 public $theme = ''; |
|
20 |
|
21 /** |
|
22 * |
|
23 * @param array $args |
|
24 */ |
|
25 public function __construct($args = array()) { |
|
26 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); |
|
27 $args = wp_parse_args($args, $defaults); |
|
28 |
|
29 $this->theme = $args['theme']; |
|
30 |
|
31 parent::__construct($args); |
|
32 } |
|
33 |
|
34 /** |
|
35 */ |
|
36 public function after() { |
|
37 $this->decrement_update_count( 'theme' ); |
|
38 |
|
39 $update_actions = array(); |
|
40 if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { |
|
41 $name = $theme_info->display('Name'); |
|
42 $stylesheet = $this->upgrader->result['destination_name']; |
|
43 $template = $theme_info->get_template(); |
|
44 |
|
45 $activate_link = add_query_arg( array( |
|
46 'action' => 'activate', |
|
47 'template' => urlencode( $template ), |
|
48 'stylesheet' => urlencode( $stylesheet ), |
|
49 ), admin_url('themes.php') ); |
|
50 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
|
51 |
|
52 $customize_url = add_query_arg( |
|
53 array( |
|
54 'theme' => urlencode( $stylesheet ), |
|
55 'return' => urlencode( admin_url( 'themes.php' ) ), |
|
56 ), |
|
57 admin_url( 'customize.php' ) |
|
58 ); |
|
59 if ( get_stylesheet() == $stylesheet ) { |
|
60 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
61 $update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize “%s”' ), $name ) . '</span></a>'; |
|
62 } |
|
63 } elseif ( current_user_can( 'switch_themes' ) ) { |
|
64 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
65 $update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview “%s”' ), $name ) . '</span></a>'; |
|
66 } |
|
67 $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate “%s”' ), $name ) . '</span></a>'; |
|
68 } |
|
69 |
|
70 if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) |
|
71 unset( $update_actions['preview'], $update_actions['activate'] ); |
|
72 } |
|
73 |
|
74 $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>'; |
|
75 |
|
76 /** |
|
77 * Filters the list of action links available following a single theme update. |
|
78 * |
|
79 * @since 2.8.0 |
|
80 * |
|
81 * @param array $update_actions Array of theme action links. |
|
82 * @param string $theme Theme directory name. |
|
83 */ |
|
84 $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme ); |
|
85 |
|
86 if ( ! empty($update_actions) ) |
|
87 $this->feedback(implode(' | ', (array)$update_actions)); |
|
88 } |
|
89 } |