author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
* Upgrade API: Theme_Upgrader class |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
* @subpackage Upgrader |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
* Core class used for upgrading/installing themes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
* It is designed to upgrade/install themes from a local zip, remote zip URL, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
* or uploaded zip file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
* @see WP_Upgrader |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
class Theme_Upgrader extends WP_Upgrader { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
* Result of the theme upgrade offer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
* @var array|WP_Error $result |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
* @see WP_Upgrader::$result |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
public $result; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
* Whether multiple themes are being upgraded/installed in bulk. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
* @var bool $bulk |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
public $bulk = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
/** |
16 | 41 |
* New theme info. |
42 |
* |
|
43 |
* @since 5.5.0 |
|
44 |
* @var array $new_theme_data |
|
45 |
* |
|
46 |
* @see check_package() |
|
47 |
*/ |
|
48 |
public $new_theme_data = array(); |
|
49 |
||
50 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
* Initialize the upgrade strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
public function upgrade_strings() { |
9 | 56 |
$this->strings['up_to_date'] = __( 'The theme is at the latest version.' ); |
57 |
$this->strings['no_package'] = __( 'Update package not available.' ); |
|
16 | 58 |
/* translators: %s: Package URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' ); |
9 | 60 |
$this->strings['unpack_package'] = __( 'Unpacking the update…' ); |
61 |
$this->strings['remove_old'] = __( 'Removing the old version of the theme…' ); |
|
62 |
$this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' ); |
|
63 |
$this->strings['process_failed'] = __( 'Theme update failed.' ); |
|
64 |
$this->strings['process_success'] = __( 'Theme updated successfully.' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
* Initialize the installation strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
public function install_strings() { |
9 | 73 |
$this->strings['no_package'] = __( 'Installation package not available.' ); |
16 | 74 |
/* translators: %s: Package URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' ); |
9 | 76 |
$this->strings['unpack_package'] = __( 'Unpacking the package…' ); |
77 |
$this->strings['installing_package'] = __( 'Installing the theme…' ); |
|
16 | 78 |
$this->strings['remove_old'] = __( 'Removing the old version of the theme…' ); |
79 |
$this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' ); |
|
9 | 80 |
$this->strings['no_files'] = __( 'The theme contains no files.' ); |
81 |
$this->strings['process_failed'] = __( 'Theme installation failed.' ); |
|
82 |
$this->strings['process_success'] = __( 'Theme installed successfully.' ); |
|
16 | 83 |
/* translators: 1: Theme name, 2: Theme version. */ |
9 | 84 |
$this->strings['process_success_specific'] = __( 'Successfully installed the theme <strong>%1$s %2$s</strong>.' ); |
85 |
$this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed…' ); |
|
16 | 86 |
/* translators: 1: Theme name, 2: Theme version. */ |
9 | 87 |
$this->strings['parent_theme_prepare_install'] = __( 'Preparing to install <strong>%1$s %2$s</strong>…' ); |
16 | 88 |
/* translators: 1: Theme name, 2: Theme version. */ |
9 | 89 |
$this->strings['parent_theme_currently_installed'] = __( 'The parent theme, <strong>%1$s %2$s</strong>, is currently installed.' ); |
16 | 90 |
/* translators: 1: Theme name, 2: Theme version. */ |
9 | 91 |
$this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' ); |
16 | 92 |
/* translators: %s: Theme name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
$this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' ); |
16 | 94 |
/* translators: %s: Theme error. */ |
95 |
$this->strings['current_theme_has_errors'] = __( 'The current theme has the following error: "%s".' ); |
|
96 |
||
97 |
if ( ! empty( $this->skin->overwrite ) ) { |
|
98 |
if ( 'update-theme' === $this->skin->overwrite ) { |
|
99 |
$this->strings['installing_package'] = __( 'Updating the theme…' ); |
|
100 |
$this->strings['process_failed'] = __( 'Theme update failed.' ); |
|
101 |
$this->strings['process_success'] = __( 'Theme updated successfully.' ); |
|
102 |
} |
|
103 |
||
104 |
if ( 'downgrade-theme' === $this->skin->overwrite ) { |
|
105 |
$this->strings['installing_package'] = __( 'Downgrading the theme…' ); |
|
106 |
$this->strings['process_failed'] = __( 'Theme downgrade failed.' ); |
|
107 |
$this->strings['process_success'] = __( 'Theme downgraded successfully.' ); |
|
108 |
} |
|
109 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
* Check if a child theme is being installed and we need to install its parent. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
115 |
* Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::install(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
116 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
118 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
119 |
* @param bool $install_result |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
120 |
* @param array $hook_extra |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
121 |
* @param array $child_result |
16 | 122 |
* @return bool |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
123 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
public function check_parent_theme_filter( $install_result, $hook_extra, $child_result ) { |
16 | 125 |
// Check to see if we need to install a parent theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
$theme_info = $this->theme_info(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
127 |
|
9 | 128 |
if ( ! $theme_info->parent() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
return $install_result; |
9 | 130 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
131 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
$this->skin->feedback( 'parent_theme_search' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
133 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
if ( ! $theme_info->parent()->errors() ) { |
9 | 135 |
$this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
136 |
// We already have the theme, fall through. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
137 |
return $install_result; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
// We don't have the parent theme, let's install it. |
9 | 141 |
$api = themes_api( |
142 |
'theme_information', |
|
143 |
array( |
|
144 |
'slug' => $theme_info->get( 'Template' ), |
|
145 |
'fields' => array( |
|
146 |
'sections' => false, |
|
147 |
'tags' => false, |
|
148 |
), |
|
149 |
) |
|
16 | 150 |
); // Save on a bit of bandwidth. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
151 |
|
9 | 152 |
if ( ! $api || is_wp_error( $api ) ) { |
153 |
$this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) ); |
|
16 | 154 |
// Don't show activate or preview actions after installation. |
9 | 155 |
add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
return $install_result; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
159 |
// Backup required data we're going to override: |
9 | 160 |
$child_api = $this->skin->api; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
161 |
$child_success_message = $this->strings['process_success']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
162 |
|
16 | 163 |
// Override them. |
164 |
$this->skin->api = $api; |
|
165 |
||
166 |
$this->strings['process_success_specific'] = $this->strings['parent_theme_install_success']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
167 |
|
9 | 168 |
$this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
169 |
|
9 | 170 |
add_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Don't show any actions after installing the theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
171 |
|
16 | 172 |
// Install the parent theme. |
9 | 173 |
$parent_result = $this->run( |
174 |
array( |
|
175 |
'package' => $api->download_link, |
|
176 |
'destination' => get_theme_root(), |
|
16 | 177 |
'clear_destination' => false, // Do not overwrite files. |
9 | 178 |
'clear_working' => true, |
179 |
) |
|
180 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
181 |
|
9 | 182 |
if ( is_wp_error( $parent_result ) ) { |
183 |
add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) ); |
|
184 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
185 |
|
16 | 186 |
// Start cleaning up after the parent's installation. |
9 | 187 |
remove_filter( 'install_theme_complete_actions', '__return_false', 999 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
|
16 | 189 |
// Reset child's result and data. |
9 | 190 |
$this->result = $child_result; |
191 |
$this->skin->api = $child_api; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
192 |
$this->strings['process_success'] = $child_success_message; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
194 |
return $install_result; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
195 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
196 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
197 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
198 |
* Don't display the activate and preview actions to the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
199 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
200 |
* Hooked to the {@see 'install_theme_complete_actions'} filter by |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
201 |
* Theme_Upgrader::check_parent_theme_filter() when installing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
202 |
* a child theme and installing the parent theme fails. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
203 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
206 |
* @param array $actions Preview actions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
207 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
208 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
209 |
public function hide_activate_preview_actions( $actions ) { |
9 | 210 |
unset( $actions['activate'], $actions['preview'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
211 |
return $actions; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
212 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
213 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
214 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
215 |
* Install a theme package. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
216 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
217 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
218 |
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
219 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
220 |
* @param string $package The full local path or URI of the package. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
221 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
222 |
* Optional. Other arguments for installing a theme package. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
223 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
224 |
* @type bool $clear_update_cache Whether to clear the updates cache if successful. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
225 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
226 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
227 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
228 |
* @return bool|WP_Error True if the installation was successful, false or a WP_Error object otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
229 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
230 |
public function install( $package, $args = array() ) { |
9 | 231 |
$defaults = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
232 |
'clear_update_cache' => true, |
16 | 233 |
'overwrite_package' => false, // Do not overwrite files. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
234 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
235 |
$parsed_args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
236 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
237 |
$this->init(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
238 |
$this->install_strings(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
239 |
|
9 | 240 |
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); |
241 |
add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 ); |
|
16 | 242 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
243 |
if ( $parsed_args['clear_update_cache'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
244 |
// Clear cache so wp_update_themes() knows about the new theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
245 |
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
246 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
247 |
|
9 | 248 |
$this->run( |
249 |
array( |
|
250 |
'package' => $package, |
|
251 |
'destination' => get_theme_root(), |
|
16 | 252 |
'clear_destination' => $parsed_args['overwrite_package'], |
9 | 253 |
'clear_working' => true, |
254 |
'hook_extra' => array( |
|
255 |
'type' => 'theme', |
|
256 |
'action' => 'install', |
|
257 |
), |
|
258 |
) |
|
259 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
261 |
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); |
9 | 262 |
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); |
263 |
remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
264 |
|
9 | 265 |
if ( ! $this->result || is_wp_error( $this->result ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
266 |
return $this->result; |
9 | 267 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
268 |
|
16 | 269 |
// Refresh the Theme Update information. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
270 |
wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
271 |
|
16 | 272 |
if ( $parsed_args['overwrite_package'] ) { |
273 |
/** |
|
274 |
* Fires when the upgrader has successfully overwritten a currently installed |
|
275 |
* plugin or theme with an uploaded zip package. |
|
276 |
* |
|
277 |
* @since 5.5.0 |
|
278 |
* |
|
279 |
* @param string $package The package file. |
|
280 |
* @param array $new_theme_data The new theme data. |
|
281 |
* @param string $package_type The package type (plugin or theme). |
|
282 |
*/ |
|
283 |
do_action( 'upgrader_overwrote_package', $package, $this->new_theme_data, 'theme' ); |
|
284 |
} |
|
285 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
286 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
289 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
290 |
* Upgrade a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
291 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
292 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
293 |
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
294 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
295 |
* @param string $theme The theme slug. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
296 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
297 |
* Optional. Other arguments for upgrading a theme. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
298 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
299 |
* @type bool $clear_update_cache Whether to clear the update cache if successful. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
300 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
301 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
302 |
* @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
303 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
304 |
public function upgrade( $theme, $args = array() ) { |
9 | 305 |
$defaults = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
306 |
'clear_update_cache' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
307 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
308 |
$parsed_args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
309 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
310 |
$this->init(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
311 |
$this->upgrade_strings(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
312 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
313 |
// Is an update available? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
314 |
$current = get_site_transient( 'update_themes' ); |
9 | 315 |
if ( ! isset( $current->response[ $theme ] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
316 |
$this->skin->before(); |
9 | 317 |
$this->skin->set_result( false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
318 |
$this->skin->error( 'up_to_date' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
319 |
$this->skin->after(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
320 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
321 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
322 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
323 |
$r = $current->response[ $theme ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
324 |
|
9 | 325 |
add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 ); |
326 |
add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 ); |
|
327 |
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
328 |
if ( $parsed_args['clear_update_cache'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
329 |
// Clear cache so wp_update_themes() knows about the new theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
330 |
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
331 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
332 |
|
9 | 333 |
$this->run( |
334 |
array( |
|
335 |
'package' => $r['package'], |
|
336 |
'destination' => get_theme_root( $theme ), |
|
337 |
'clear_destination' => true, |
|
338 |
'clear_working' => true, |
|
339 |
'hook_extra' => array( |
|
340 |
'theme' => $theme, |
|
341 |
'type' => 'theme', |
|
342 |
'action' => 'update', |
|
343 |
), |
|
344 |
) |
|
345 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
346 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
347 |
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); |
9 | 348 |
remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) ); |
349 |
remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) ); |
|
350 |
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
351 |
|
9 | 352 |
if ( ! $this->result || is_wp_error( $this->result ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
353 |
return $this->result; |
9 | 354 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
355 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
356 |
wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
357 |
|
16 | 358 |
// Ensure any future auto-update failures trigger a failure email by removing |
359 |
// the last failure notification from the list when themes update successfully. |
|
360 |
$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() ); |
|
361 |
||
362 |
if ( isset( $past_failure_emails[ $theme ] ) ) { |
|
363 |
unset( $past_failure_emails[ $theme ] ); |
|
364 |
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); |
|
365 |
} |
|
366 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
367 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
368 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
369 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
370 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
371 |
* Upgrade several themes at once. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
372 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
373 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
374 |
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
375 |
* |
9 | 376 |
* @param string[] $themes Array of the theme slugs. |
377 |
* @param array $args { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
378 |
* Optional. Other arguments for upgrading several themes at once. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
379 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
380 |
* @type bool $clear_update_cache Whether to clear the update cache if successful. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
381 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
382 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
383 |
* @return array[]|false An array of results, or false if unable to connect to the filesystem. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
384 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
385 |
public function bulk_upgrade( $themes, $args = array() ) { |
9 | 386 |
$defaults = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
387 |
'clear_update_cache' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
388 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
389 |
$parsed_args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
391 |
$this->init(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
392 |
$this->bulk = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
393 |
$this->upgrade_strings(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
395 |
$current = get_site_transient( 'update_themes' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
396 |
|
9 | 397 |
add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 ); |
398 |
add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 ); |
|
399 |
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
400 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
401 |
$this->skin->header(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
402 |
|
16 | 403 |
// Connect to the filesystem first. |
9 | 404 |
$res = $this->fs_connect( array( WP_CONTENT_DIR ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
405 |
if ( ! $res ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
406 |
$this->skin->footer(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
407 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
408 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
409 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
410 |
$this->skin->bulk_header(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
411 |
|
16 | 412 |
/* |
413 |
* Only start maintenance mode if: |
|
414 |
* - running Multisite and there are one or more themes specified, OR |
|
415 |
* - a theme with an update available is currently in use. |
|
416 |
* @todo For multisite, maintenance mode should only kick in for individual sites if at all possible. |
|
417 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
418 |
$maintenance = ( is_multisite() && ! empty( $themes ) ); |
9 | 419 |
foreach ( $themes as $theme ) { |
16 | 420 |
$maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme; |
9 | 421 |
} |
422 |
if ( $maintenance ) { |
|
423 |
$this->maintenance_mode( true ); |
|
424 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
426 |
$results = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
427 |
|
9 | 428 |
$this->update_count = count( $themes ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
429 |
$this->update_current = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
430 |
foreach ( $themes as $theme ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
431 |
$this->update_current++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
432 |
|
9 | 433 |
$this->skin->theme_info = $this->theme_info( $theme ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
434 |
|
9 | 435 |
if ( ! isset( $current->response[ $theme ] ) ) { |
436 |
$this->skin->set_result( true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
437 |
$this->skin->before(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
438 |
$this->skin->feedback( 'up_to_date' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
439 |
$this->skin->after(); |
9 | 440 |
$results[ $theme ] = true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
441 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
442 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
443 |
|
16 | 444 |
// Get the URL to the zip file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
445 |
$r = $current->response[ $theme ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
446 |
|
9 | 447 |
$result = $this->run( |
448 |
array( |
|
449 |
'package' => $r['package'], |
|
450 |
'destination' => get_theme_root( $theme ), |
|
451 |
'clear_destination' => true, |
|
452 |
'clear_working' => true, |
|
453 |
'is_multi' => true, |
|
454 |
'hook_extra' => array( |
|
455 |
'theme' => $theme, |
|
456 |
), |
|
457 |
) |
|
458 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
459 |
|
9 | 460 |
$results[ $theme ] = $this->result; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
461 |
|
16 | 462 |
// Prevent credentials auth screen from displaying multiple times. |
9 | 463 |
if ( false === $result ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
464 |
break; |
9 | 465 |
} |
16 | 466 |
} // End foreach $themes. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
467 |
|
9 | 468 |
$this->maintenance_mode( false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
469 |
|
16 | 470 |
// Refresh the Theme Update information. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
471 |
wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
472 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
473 |
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */ |
9 | 474 |
do_action( |
475 |
'upgrader_process_complete', |
|
476 |
$this, |
|
477 |
array( |
|
478 |
'action' => 'update', |
|
479 |
'type' => 'theme', |
|
480 |
'bulk' => true, |
|
481 |
'themes' => $themes, |
|
482 |
) |
|
483 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
484 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
485 |
$this->skin->bulk_footer(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
486 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
487 |
$this->skin->footer(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
488 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
489 |
// Cleanup our hooks, in case something else does a upgrade on this connection. |
9 | 490 |
remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) ); |
491 |
remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) ); |
|
492 |
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
493 |
|
16 | 494 |
// Ensure any future auto-update failures trigger a failure email by removing |
495 |
// the last failure notification from the list when themes update successfully. |
|
496 |
$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() ); |
|
497 |
||
498 |
foreach ( $results as $theme => $result ) { |
|
499 |
// Maintain last failure notification when themes failed to update manually. |
|
500 |
if ( ! $result || is_wp_error( $result ) || ! isset( $past_failure_emails[ $theme ] ) ) { |
|
501 |
continue; |
|
502 |
} |
|
503 |
||
504 |
unset( $past_failure_emails[ $theme ] ); |
|
505 |
} |
|
506 |
||
507 |
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); |
|
508 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
509 |
return $results; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
510 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
511 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
512 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
513 |
* Check that the package source contains a valid theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
514 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
515 |
* Hooked to the {@see 'upgrader_source_selection'} filter by Theme_Upgrader::install(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
516 |
* It will return an error if the theme doesn't have style.css or index.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
517 |
* files. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
518 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
519 |
* @since 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
520 |
* |
9 | 521 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
522 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
523 |
* @param string $source The full path to the package source. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
524 |
* @return string|WP_Error The source or a WP_Error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
525 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
526 |
public function check_package( $source ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
527 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
528 |
|
16 | 529 |
$this->new_theme_data = array(); |
530 |
||
9 | 531 |
if ( is_wp_error( $source ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
532 |
return $source; |
9 | 533 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
534 |
|
16 | 535 |
// Check that the folder contains a valid theme. |
9 | 536 |
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source ); |
537 |
if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
538 |
return $source; |
9 | 539 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
540 |
|
16 | 541 |
// A proper archive should have a style.css file in the single subdirectory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
542 |
if ( ! file_exists( $working_directory . 'style.css' ) ) { |
9 | 543 |
return new WP_Error( |
544 |
'incompatible_archive_theme_no_style', |
|
545 |
$this->strings['incompatible_archive'], |
|
546 |
sprintf( |
|
547 |
/* translators: %s: style.css */ |
|
548 |
__( 'The theme is missing the %s stylesheet.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
549 |
'<code>style.css</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
550 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
551 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
553 |
|
16 | 554 |
// All these headers are needed on Theme_Installer_Skin::do_overwrite(). |
9 | 555 |
$info = get_file_data( |
556 |
$working_directory . 'style.css', |
|
557 |
array( |
|
16 | 558 |
'Name' => 'Theme Name', |
559 |
'Version' => 'Version', |
|
560 |
'Author' => 'Author', |
|
561 |
'Template' => 'Template', |
|
562 |
'RequiresWP' => 'Requires at least', |
|
563 |
'RequiresPHP' => 'Requires PHP', |
|
9 | 564 |
) |
565 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
566 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
567 |
if ( empty( $info['Name'] ) ) { |
9 | 568 |
return new WP_Error( |
569 |
'incompatible_archive_theme_no_name', |
|
570 |
$this->strings['incompatible_archive'], |
|
571 |
sprintf( |
|
572 |
/* translators: %s: style.css */ |
|
573 |
__( 'The %s stylesheet doesn’t contain a valid theme header.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
574 |
'<code>style.css</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
575 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
576 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
577 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
578 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
579 |
// If it's not a child theme, it must have at least an index.php to be legit. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
580 |
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) { |
9 | 581 |
return new WP_Error( |
582 |
'incompatible_archive_theme_no_index', |
|
583 |
$this->strings['incompatible_archive'], |
|
584 |
sprintf( |
|
585 |
/* translators: %s: index.php */ |
|
586 |
__( 'The theme is missing the %s file.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
587 |
'<code>index.php</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
588 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
589 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
590 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
591 |
|
16 | 592 |
$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null; |
593 |
$requires_wp = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null; |
|
594 |
||
595 |
if ( ! is_php_version_compatible( $requires_php ) ) { |
|
596 |
$error = sprintf( |
|
597 |
/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */ |
|
598 |
__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ), |
|
599 |
phpversion(), |
|
600 |
$requires_php |
|
601 |
); |
|
602 |
||
603 |
return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error ); |
|
604 |
} |
|
605 |
if ( ! is_wp_version_compatible( $requires_wp ) ) { |
|
606 |
$error = sprintf( |
|
607 |
/* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */ |
|
608 |
__( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ), |
|
609 |
$GLOBALS['wp_version'], |
|
610 |
$requires_wp |
|
611 |
); |
|
612 |
||
613 |
return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error ); |
|
614 |
} |
|
615 |
||
616 |
$this->new_theme_data = $info; |
|
617 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
618 |
return $source; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
619 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
620 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
621 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
622 |
* Turn on maintenance mode before attempting to upgrade the current theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
623 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
624 |
* Hooked to the {@see 'upgrader_pre_install'} filter by Theme_Upgrader::upgrade() and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
625 |
* Theme_Upgrader::bulk_upgrade(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
626 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
627 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
628 |
* |
16 | 629 |
* @param bool|WP_Error $return Upgrade offer return. |
630 |
* @param array $theme Theme arguments. |
|
631 |
* @return bool|WP_Error The passed in $return param or WP_Error. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
632 |
*/ |
9 | 633 |
public function current_before( $return, $theme ) { |
634 |
if ( is_wp_error( $return ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
635 |
return $return; |
9 | 636 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
637 |
|
9 | 638 |
$theme = isset( $theme['theme'] ) ? $theme['theme'] : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
639 |
|
16 | 640 |
// Only run if current theme |
641 |
if ( get_stylesheet() !== $theme ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
642 |
return $return; |
9 | 643 |
} |
16 | 644 |
|
645 |
// Change to maintenance mode. Bulk edit handles this separately. |
|
9 | 646 |
if ( ! $this->bulk ) { |
647 |
$this->maintenance_mode( true ); |
|
648 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
649 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
650 |
return $return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
651 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
652 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
653 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
654 |
* Turn off maintenance mode after upgrading the current theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
655 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
656 |
* Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::upgrade() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
657 |
* and Theme_Upgrader::bulk_upgrade(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
658 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
659 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
660 |
* |
16 | 661 |
* @param bool|WP_Error $return Upgrade offer return. |
662 |
* @param array $theme Theme arguments. |
|
663 |
* @return bool|WP_Error The passed in $return param or WP_Error. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
664 |
*/ |
9 | 665 |
public function current_after( $return, $theme ) { |
666 |
if ( is_wp_error( $return ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
667 |
return $return; |
9 | 668 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
669 |
|
9 | 670 |
$theme = isset( $theme['theme'] ) ? $theme['theme'] : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
671 |
|
16 | 672 |
// Only run if current theme. |
673 |
if ( get_stylesheet() !== $theme ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
674 |
return $return; |
9 | 675 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
676 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
677 |
// Ensure stylesheet name hasn't changed after the upgrade: |
16 | 678 |
if ( get_stylesheet() === $theme && $theme !== $this->result['destination_name'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
679 |
wp_clean_themes_cache(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
680 |
$stylesheet = $this->result['destination_name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
681 |
switch_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
682 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
683 |
|
16 | 684 |
// Time to remove maintenance mode. Bulk edit handles this separately. |
9 | 685 |
if ( ! $this->bulk ) { |
686 |
$this->maintenance_mode( false ); |
|
687 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
688 |
return $return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
689 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
690 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
691 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
692 |
* Delete the old theme during an upgrade. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
693 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
694 |
* Hooked to the {@see 'upgrader_clear_destination'} filter by Theme_Upgrader::upgrade() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
695 |
* and Theme_Upgrader::bulk_upgrade(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
696 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
697 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
698 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
699 |
* @global WP_Filesystem_Base $wp_filesystem Subclass |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
700 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
701 |
* @param bool $removed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
702 |
* @param string $local_destination |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
703 |
* @param string $remote_destination |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
704 |
* @param array $theme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
705 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
706 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
707 |
public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
708 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
709 |
|
9 | 710 |
if ( is_wp_error( $removed ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
711 |
return $removed; // Pass errors through. |
9 | 712 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
713 |
|
9 | 714 |
if ( ! isset( $theme['theme'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
715 |
return $removed; |
9 | 716 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
717 |
|
9 | 718 |
$theme = $theme['theme']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
719 |
$themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
720 |
if ( $wp_filesystem->exists( $themes_dir . $theme ) ) { |
9 | 721 |
if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
722 |
return false; |
9 | 723 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
724 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
725 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
726 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
727 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
728 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
729 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
730 |
* Get the WP_Theme object for a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
731 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
732 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
733 |
* @since 3.0.0 The `$theme` argument was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
734 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
735 |
* @param string $theme The directory name of the theme. This is optional, and if not supplied, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
736 |
* the directory name from the last result will be used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
737 |
* @return WP_Theme|false The theme's info object, or false `$theme` is not supplied |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
738 |
* and the last result isn't set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
739 |
*/ |
9 | 740 |
public function theme_info( $theme = null ) { |
741 |
if ( empty( $theme ) ) { |
|
742 |
if ( ! empty( $this->result['destination_name'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
743 |
$theme = $this->result['destination_name']; |
9 | 744 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
745 |
return false; |
9 | 746 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
747 |
} |
16 | 748 |
|
749 |
$theme = wp_get_theme( $theme ); |
|
750 |
$theme->cache_delete(); |
|
751 |
||
752 |
return $theme; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
753 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
754 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
755 |
} |