|
1 <?php |
|
2 /** |
|
3 * Upgrader API: Theme_Installer_Skin class |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Upgrader |
|
7 * @since 4.6.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Theme Installer Skin for the WordPress Theme Installer. |
|
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_Installer_Skin extends WP_Upgrader_Skin { |
|
19 public $api; |
|
20 public $type; |
|
21 |
|
22 /** |
|
23 * |
|
24 * @param array $args |
|
25 */ |
|
26 public function __construct($args = array()) { |
|
27 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); |
|
28 $args = wp_parse_args($args, $defaults); |
|
29 |
|
30 $this->type = $args['type']; |
|
31 $this->api = isset($args['api']) ? $args['api'] : array(); |
|
32 |
|
33 parent::__construct($args); |
|
34 } |
|
35 |
|
36 /** |
|
37 */ |
|
38 public function before() { |
|
39 if ( !empty($this->api) ) |
|
40 $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); |
|
41 } |
|
42 |
|
43 /** |
|
44 */ |
|
45 public function after() { |
|
46 if ( empty($this->upgrader->result['destination_name']) ) |
|
47 return; |
|
48 |
|
49 $theme_info = $this->upgrader->theme_info(); |
|
50 if ( empty( $theme_info ) ) |
|
51 return; |
|
52 |
|
53 $name = $theme_info->display('Name'); |
|
54 $stylesheet = $this->upgrader->result['destination_name']; |
|
55 $template = $theme_info->get_template(); |
|
56 |
|
57 $activate_link = add_query_arg( array( |
|
58 'action' => 'activate', |
|
59 'template' => urlencode( $template ), |
|
60 'stylesheet' => urlencode( $stylesheet ), |
|
61 ), admin_url('themes.php') ); |
|
62 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
|
63 |
|
64 $install_actions = array(); |
|
65 |
|
66 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
67 $customize_url = add_query_arg( |
|
68 array( |
|
69 'theme' => urlencode( $stylesheet ), |
|
70 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), |
|
71 ), |
|
72 admin_url( 'customize.php' ) |
|
73 ); |
|
74 $install_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>'; |
|
75 } |
|
76 $install_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>'; |
|
77 |
|
78 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) |
|
79 $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>'; |
|
80 |
|
81 if ( $this->type == 'web' ) |
|
82 $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>'; |
|
83 elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) |
|
84 $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>'; |
|
85 |
|
86 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) |
|
87 unset( $install_actions['activate'], $install_actions['preview'] ); |
|
88 |
|
89 /** |
|
90 * Filters the list of action links available following a single theme installation. |
|
91 * |
|
92 * @since 2.8.0 |
|
93 * |
|
94 * @param array $install_actions Array of theme action links. |
|
95 * @param object $api Object containing WordPress.org API theme data. |
|
96 * @param string $stylesheet Theme directory name. |
|
97 * @param WP_Theme $theme_info Theme object. |
|
98 */ |
|
99 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); |
|
100 if ( ! empty($install_actions) ) |
|
101 $this->feedback(implode(' | ', (array)$install_actions)); |
|
102 } |
|
103 } |