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 | * @access public |
---|
36 | */ |
---|
37 | public function after() { |
---|
38 | $this->decrement_update_count( 'theme' ); |
---|
39 | |
---|
40 | $update_actions = array(); |
---|
41 | if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { |
---|
42 | $name = $theme_info->display('Name'); |
---|
43 | $stylesheet = $this->upgrader->result['destination_name']; |
---|
44 | $template = $theme_info->get_template(); |
---|
45 | |
---|
46 | $activate_link = add_query_arg( array( |
---|
47 | 'action' => 'activate', |
---|
48 | 'template' => urlencode( $template ), |
---|
49 | 'stylesheet' => urlencode( $stylesheet ), |
---|
50 | ), admin_url('themes.php') ); |
---|
51 | $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
---|
52 | |
---|
53 | if ( get_stylesheet() == $stylesheet ) { |
---|
54 | if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
---|
55 | $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize “%s”' ), $name ) . '</span></a>'; |
---|
56 | } |
---|
57 | } elseif ( current_user_can( 'switch_themes' ) ) { |
---|
58 | if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
---|
59 | $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" 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>'; |
---|
60 | } |
---|
61 | $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>'; |
---|
62 | } |
---|
63 | |
---|
64 | if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) |
---|
65 | unset( $update_actions['preview'], $update_actions['activate'] ); |
---|
66 | } |
---|
67 | |
---|
68 | $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>'; |
---|
69 | |
---|
70 | /** |
---|
71 | * Filters the list of action links available following a single theme update. |
---|
72 | * |
---|
73 | * @since 2.8.0 |
---|
74 | * |
---|
75 | * @param array $update_actions Array of theme action links. |
---|
76 | * @param string $theme Theme directory name. |
---|
77 | */ |
---|
78 | $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme ); |
---|
79 | |
---|
80 | if ( ! empty($update_actions) ) |
---|
81 | $this->feedback(implode(' | ', (array)$update_actions)); |
---|
82 | } |
---|
83 | } |
---|