18 class Theme_Installer_Skin extends WP_Upgrader_Skin { |
18 class Theme_Installer_Skin extends WP_Upgrader_Skin { |
19 public $api; |
19 public $api; |
20 public $type; |
20 public $type; |
21 |
21 |
22 /** |
22 /** |
23 * |
|
24 * @param array $args |
23 * @param array $args |
25 */ |
24 */ |
26 public function __construct($args = array()) { |
25 public function __construct( $args = array() ) { |
27 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); |
26 $defaults = array( |
28 $args = wp_parse_args($args, $defaults); |
27 'type' => 'web', |
|
28 'url' => '', |
|
29 'theme' => '', |
|
30 'nonce' => '', |
|
31 'title' => '', |
|
32 ); |
|
33 $args = wp_parse_args( $args, $defaults ); |
29 |
34 |
30 $this->type = $args['type']; |
35 $this->type = $args['type']; |
31 $this->api = isset($args['api']) ? $args['api'] : array(); |
36 $this->api = isset( $args['api'] ) ? $args['api'] : array(); |
32 |
37 |
33 parent::__construct($args); |
38 parent::__construct( $args ); |
34 } |
39 } |
35 |
40 |
36 /** |
41 /** |
37 */ |
42 */ |
38 public function before() { |
43 public function before() { |
39 if ( !empty($this->api) ) |
44 if ( ! empty( $this->api ) ) { |
40 $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); |
45 $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version ); |
|
46 } |
41 } |
47 } |
42 |
48 |
43 /** |
49 /** |
44 */ |
50 */ |
45 public function after() { |
51 public function after() { |
46 if ( empty($this->upgrader->result['destination_name']) ) |
52 if ( empty( $this->upgrader->result['destination_name'] ) ) { |
47 return; |
53 return; |
|
54 } |
48 |
55 |
49 $theme_info = $this->upgrader->theme_info(); |
56 $theme_info = $this->upgrader->theme_info(); |
50 if ( empty( $theme_info ) ) |
57 if ( empty( $theme_info ) ) { |
51 return; |
58 return; |
|
59 } |
52 |
60 |
53 $name = $theme_info->display('Name'); |
61 $name = $theme_info->display( 'Name' ); |
54 $stylesheet = $this->upgrader->result['destination_name']; |
62 $stylesheet = $this->upgrader->result['destination_name']; |
55 $template = $theme_info->get_template(); |
63 $template = $theme_info->get_template(); |
56 |
64 |
57 $activate_link = add_query_arg( array( |
65 $activate_link = add_query_arg( |
58 'action' => 'activate', |
66 array( |
59 'template' => urlencode( $template ), |
67 'action' => 'activate', |
60 'stylesheet' => urlencode( $stylesheet ), |
68 'template' => urlencode( $template ), |
61 ), admin_url('themes.php') ); |
69 'stylesheet' => urlencode( $stylesheet ), |
|
70 ), |
|
71 admin_url( 'themes.php' ) |
|
72 ); |
62 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
73 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
63 |
74 |
64 $install_actions = array(); |
75 $install_actions = array(); |
65 |
76 |
66 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
77 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
67 $customize_url = add_query_arg( |
78 $customize_url = add_query_arg( |
68 array( |
79 array( |
69 'theme' => urlencode( $stylesheet ), |
80 'theme' => urlencode( $stylesheet ), |
70 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), |
81 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), |
71 ), |
82 ), |
72 admin_url( 'customize.php' ) |
83 admin_url( 'customize.php' ) |
73 ); |
84 ); |
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>'; |
85 $install_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">'; |
|
86 $install_actions['preview'] .= '<span aria-hidden="true">' . __( 'Live Preview' ) . '</span>'; |
|
87 /* translators: %s: theme name */ |
|
88 $install_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Live Preview “%s”' ), $name ) . '</span></a>'; |
75 } |
89 } |
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>'; |
90 $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink">'; |
|
91 $install_actions['activate'] .= '<span aria-hidden="true">' . __( 'Activate' ) . '</span>'; |
|
92 /* translators: %s: theme name */ |
|
93 $install_actions['activate'] .= '<span class="screen-reader-text">' . sprintf( __( 'Activate “%s”' ), $name ) . '</span></a>'; |
77 |
94 |
78 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) |
95 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>'; |
96 $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>'; |
|
97 } |
80 |
98 |
81 if ( $this->type == 'web' ) |
99 if ( $this->type == 'web' ) { |
82 $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>'; |
100 $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' ) ) |
101 } 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>'; |
102 $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>'; |
|
103 } |
85 |
104 |
86 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) |
105 if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) { |
87 unset( $install_actions['activate'], $install_actions['preview'] ); |
106 unset( $install_actions['activate'], $install_actions['preview'] ); |
|
107 } |
88 |
108 |
89 /** |
109 /** |
90 * Filters the list of action links available following a single theme installation. |
110 * Filters the list of action links available following a single theme installation. |
91 * |
111 * |
92 * @since 2.8.0 |
112 * @since 2.8.0 |
93 * |
113 * |
94 * @param array $install_actions Array of theme action links. |
114 * @param string[] $install_actions Array of theme action links. |
95 * @param object $api Object containing WordPress.org API theme data. |
115 * @param object $api Object containing WordPress.org API theme data. |
96 * @param string $stylesheet Theme directory name. |
116 * @param string $stylesheet Theme directory name. |
97 * @param WP_Theme $theme_info Theme object. |
117 * @param WP_Theme $theme_info Theme object. |
98 */ |
118 */ |
99 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); |
119 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); |
100 if ( ! empty($install_actions) ) |
120 if ( ! empty( $install_actions ) ) { |
101 $this->feedback(implode(' | ', (array)$install_actions)); |
121 $this->feedback( implode( ' | ', (array) $install_actions ) ); |
|
122 } |
102 } |
123 } |
103 } |
124 } |