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-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Upgrade API: WP_Upgrader class |
0 | 4 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* Requires skin classes and WP_Upgrader subclasses for backward compatibility. |
0 | 6 |
* |
7 |
* @package WordPress |
|
8 |
* @subpackage Upgrader |
|
9 |
* @since 2.8.0 |
|
10 |
*/ |
|
11 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
/** WP_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
/** Plugin_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
/** Theme_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
/** Bulk_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
require_once ABSPATH . 'wp-admin/includes/class-bulk-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
/** Bulk_Plugin_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
require_once ABSPATH . 'wp-admin/includes/class-bulk-plugin-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
/** Bulk_Theme_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
require_once ABSPATH . 'wp-admin/includes/class-bulk-theme-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
/** Plugin_Installer_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
require_once ABSPATH . 'wp-admin/includes/class-plugin-installer-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
/** Theme_Installer_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
require_once ABSPATH . 'wp-admin/includes/class-theme-installer-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
/** Language_Pack_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
/** Automatic_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
/** WP_Ajax_Upgrader_Skin class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; |
0 | 44 |
|
45 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* Core class used for upgrading/installing a local set of files via |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* the Filesystem Abstraction classes from a Zip file. |
0 | 48 |
* |
49 |
* @since 2.8.0 |
|
50 |
*/ |
|
51 |
class WP_Upgrader { |
|
5 | 52 |
|
53 |
/** |
|
54 |
* The error/notification strings used to update the user on the progress. |
|
55 |
* |
|
56 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* @var array $strings |
5 | 58 |
*/ |
59 |
public $strings = array(); |
|
60 |
||
61 |
/** |
|
62 |
* The upgrader skin being used. |
|
63 |
* |
|
64 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* @var Automatic_Upgrader_Skin|WP_Upgrader_Skin $skin |
5 | 66 |
*/ |
67 |
public $skin = null; |
|
68 |
||
69 |
/** |
|
70 |
* The result of the installation. |
|
71 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* This is set by WP_Upgrader::install_package(), only when the package is installed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* successfully. It will then be an array, unless a WP_Error is returned by the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* {@see 'upgrader_post_install'} filter. In that case, the WP_Error will be assigned to |
5 | 75 |
* it. |
76 |
* |
|
77 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
* |
16 | 79 |
* @var array|WP_Error $result { |
80 |
* @type string $source The full path to the source the files were installed from. |
|
81 |
* @type string $source_files List of all the files in the source directory. |
|
82 |
* @type string $destination The full path to the installation destination folder. |
|
83 |
* @type string $destination_name The name of the destination folder, or empty if `$destination` |
|
84 |
* and `$local_destination` are the same. |
|
85 |
* @type string $local_destination The full local path to the destination folder. This is usually |
|
86 |
* the same as `$destination`. |
|
87 |
* @type string $remote_destination The full remote path to the destination folder |
|
88 |
* (i.e., from `$wp_filesystem`). |
|
89 |
* @type bool $clear_destination Whether the destination folder was cleared. |
|
5 | 90 |
* } |
91 |
*/ |
|
92 |
public $result = array(); |
|
93 |
||
94 |
/** |
|
95 |
* The total number of updates being performed. |
|
96 |
* |
|
97 |
* Set by the bulk update methods. |
|
98 |
* |
|
99 |
* @since 3.0.0 |
|
100 |
* @var int $update_count |
|
101 |
*/ |
|
102 |
public $update_count = 0; |
|
103 |
||
104 |
/** |
|
105 |
* The current update if multiple updates are being performed. |
|
106 |
* |
|
107 |
* Used by the bulk update methods, and incremented for each update. |
|
108 |
* |
|
109 |
* @since 3.0.0 |
|
110 |
* @var int |
|
111 |
*/ |
|
112 |
public $update_current = 0; |
|
113 |
||
114 |
/** |
|
115 |
* Construct the upgrader with a skin. |
|
116 |
* |
|
117 |
* @since 2.8.0 |
|
118 |
* |
|
16 | 119 |
* @param WP_Upgrader_Skin $skin The upgrader skin to use. Default is a WP_Upgrader_Skin |
5 | 120 |
* instance. |
121 |
*/ |
|
122 |
public function __construct( $skin = null ) { |
|
9 | 123 |
if ( null == $skin ) { |
0 | 124 |
$this->skin = new WP_Upgrader_Skin(); |
9 | 125 |
} else { |
0 | 126 |
$this->skin = $skin; |
9 | 127 |
} |
0 | 128 |
} |
129 |
||
5 | 130 |
/** |
131 |
* Initialize the upgrader. |
|
132 |
* |
|
133 |
* This will set the relationship between the skin being used and this upgrader, |
|
134 |
* and also add the generic strings to `WP_Upgrader::$strings`. |
|
135 |
* |
|
136 |
* @since 2.8.0 |
|
137 |
*/ |
|
138 |
public function init() { |
|
9 | 139 |
$this->skin->set_upgrader( $this ); |
0 | 140 |
$this->generic_strings(); |
141 |
} |
|
142 |
||
5 | 143 |
/** |
144 |
* Add the generic strings to WP_Upgrader::$strings. |
|
145 |
* |
|
146 |
* @since 2.8.0 |
|
147 |
*/ |
|
148 |
public function generic_strings() { |
|
9 | 149 |
$this->strings['bad_request'] = __( 'Invalid data provided.' ); |
150 |
$this->strings['fs_unavailable'] = __( 'Could not access filesystem.' ); |
|
151 |
$this->strings['fs_error'] = __( 'Filesystem error.' ); |
|
152 |
$this->strings['fs_no_root_dir'] = __( 'Unable to locate WordPress root directory.' ); |
|
153 |
$this->strings['fs_no_content_dir'] = __( 'Unable to locate WordPress content directory (wp-content).' ); |
|
154 |
$this->strings['fs_no_plugins_dir'] = __( 'Unable to locate WordPress plugin directory.' ); |
|
155 |
$this->strings['fs_no_themes_dir'] = __( 'Unable to locate WordPress theme directory.' ); |
|
16 | 156 |
/* translators: %s: Directory name. */ |
9 | 157 |
$this->strings['fs_no_folder'] = __( 'Unable to locate needed folder (%s).' ); |
0 | 158 |
|
9 | 159 |
$this->strings['download_failed'] = __( 'Download failed.' ); |
160 |
$this->strings['installing_package'] = __( 'Installing the latest version…' ); |
|
161 |
$this->strings['no_files'] = __( 'The package contains no files.' ); |
|
162 |
$this->strings['folder_exists'] = __( 'Destination folder already exists.' ); |
|
163 |
$this->strings['mkdir_failed'] = __( 'Could not create directory.' ); |
|
164 |
$this->strings['incompatible_archive'] = __( 'The package could not be installed.' ); |
|
165 |
$this->strings['files_not_writable'] = __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ); |
|
0 | 166 |
|
9 | 167 |
$this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' ); |
168 |
$this->strings['maintenance_end'] = __( 'Disabling Maintenance mode…' ); |
|
0 | 169 |
} |
170 |
||
5 | 171 |
/** |
172 |
* Connect to the filesystem. |
|
173 |
* |
|
174 |
* @since 2.8.0 |
|
175 |
* |
|
9 | 176 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* |
16 | 178 |
* @param string[] $directories Optional. Array of directories. If any of these do |
179 |
* not exist, a WP_Error object will be returned. |
|
180 |
* Default empty array. |
|
181 |
* @param bool $allow_relaxed_file_ownership Whether to allow relaxed file ownership. |
|
182 |
* Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* @return bool|WP_Error True if able to connect, false or a WP_Error otherwise. |
5 | 184 |
*/ |
185 |
public function fs_connect( $directories = array(), $allow_relaxed_file_ownership = false ) { |
|
0 | 186 |
global $wp_filesystem; |
187 |
||
16 | 188 |
$credentials = $this->skin->request_filesystem_credentials( false, $directories[0], $allow_relaxed_file_ownership ); |
189 |
if ( false === $credentials ) { |
|
0 | 190 |
return false; |
5 | 191 |
} |
192 |
||
193 |
if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) { |
|
0 | 194 |
$error = true; |
9 | 195 |
if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) { |
0 | 196 |
$error = $wp_filesystem->errors; |
9 | 197 |
} |
16 | 198 |
// Failed to connect. Error and request again. |
5 | 199 |
$this->skin->request_filesystem_credentials( $error, $directories[0], $allow_relaxed_file_ownership ); |
0 | 200 |
return false; |
201 |
} |
|
202 |
||
9 | 203 |
if ( ! is_object( $wp_filesystem ) ) { |
204 |
return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] ); |
|
205 |
} |
|
0 | 206 |
|
9 | 207 |
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
208 |
return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors ); |
|
209 |
} |
|
0 | 210 |
|
9 | 211 |
foreach ( (array) $directories as $dir ) { |
0 | 212 |
switch ( $dir ) { |
213 |
case ABSPATH: |
|
9 | 214 |
if ( ! $wp_filesystem->abspath() ) { |
215 |
return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'] ); |
|
216 |
} |
|
0 | 217 |
break; |
218 |
case WP_CONTENT_DIR: |
|
9 | 219 |
if ( ! $wp_filesystem->wp_content_dir() ) { |
220 |
return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] ); |
|
221 |
} |
|
0 | 222 |
break; |
223 |
case WP_PLUGIN_DIR: |
|
9 | 224 |
if ( ! $wp_filesystem->wp_plugins_dir() ) { |
225 |
return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'] ); |
|
226 |
} |
|
0 | 227 |
break; |
228 |
case get_theme_root(): |
|
9 | 229 |
if ( ! $wp_filesystem->wp_themes_dir() ) { |
230 |
return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'] ); |
|
231 |
} |
|
0 | 232 |
break; |
233 |
default: |
|
9 | 234 |
if ( ! $wp_filesystem->find_folder( $dir ) ) { |
0 | 235 |
return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) ); |
9 | 236 |
} |
0 | 237 |
break; |
238 |
} |
|
239 |
} |
|
240 |
return true; |
|
16 | 241 |
} |
0 | 242 |
|
5 | 243 |
/** |
244 |
* Download a package. |
|
245 |
* |
|
246 |
* @since 2.8.0 |
|
16 | 247 |
* @since 5.5.0 Added the `$hook_extra` parameter. |
5 | 248 |
* |
9 | 249 |
* @param string $package The URI of the package. If this is the full path to an |
250 |
* existing local file, it will be returned untouched. |
|
251 |
* @param bool $check_signatures Whether to validate file signatures. Default false. |
|
16 | 252 |
* @param array $hook_extra Extra arguments to pass to the filter hooks. Default empty array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object. |
5 | 254 |
*/ |
16 | 255 |
public function download_package( $package, $check_signatures = false, $hook_extra = array() ) { |
0 | 256 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* Filters whether to return the package. |
0 | 258 |
* |
259 |
* @since 3.7.0 |
|
16 | 260 |
* @since 5.5.0 Added the `$hook_extra` parameter. |
0 | 261 |
* |
16 | 262 |
* @param bool $reply Whether to bail without returning the package. |
263 |
* Default false. |
|
264 |
* @param string $package The package file name. |
|
265 |
* @param WP_Upgrader $this The WP_Upgrader instance. |
|
266 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
|
0 | 267 |
*/ |
16 | 268 |
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra ); |
9 | 269 |
if ( false !== $reply ) { |
0 | 270 |
return $reply; |
9 | 271 |
} |
0 | 272 |
|
16 | 273 |
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { // Local file or remote? |
274 |
return $package; // Must be a local file. |
|
9 | 275 |
} |
0 | 276 |
|
9 | 277 |
if ( empty( $package ) ) { |
278 |
return new WP_Error( 'no_package', $this->strings['no_package'] ); |
|
279 |
} |
|
0 | 280 |
|
9 | 281 |
$this->skin->feedback( 'downloading_package', $package ); |
0 | 282 |
|
9 | 283 |
$download_file = download_url( $package, 300, $check_signatures ); |
0 | 284 |
|
9 | 285 |
if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) { |
286 |
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() ); |
|
287 |
} |
|
0 | 288 |
|
289 |
return $download_file; |
|
290 |
} |
|
291 |
||
5 | 292 |
/** |
293 |
* Unpack a compressed package file. |
|
294 |
* |
|
295 |
* @since 2.8.0 |
|
296 |
* |
|
9 | 297 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* |
5 | 299 |
* @param string $package Full path to the package file. |
300 |
* @param bool $delete_package Optional. Whether to delete the package file after attempting |
|
301 |
* to unpack it. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure. |
5 | 303 |
*/ |
304 |
public function unpack_package( $package, $delete_package = true ) { |
|
0 | 305 |
global $wp_filesystem; |
306 |
||
9 | 307 |
$this->skin->feedback( 'unpack_package' ); |
0 | 308 |
|
309 |
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; |
|
310 |
||
16 | 311 |
// Clean up contents of upgrade directory beforehand. |
9 | 312 |
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder ); |
313 |
if ( ! empty( $upgrade_files ) ) { |
|
314 |
foreach ( $upgrade_files as $file ) { |
|
315 |
$wp_filesystem->delete( $upgrade_folder . $file['name'], true ); |
|
316 |
} |
|
0 | 317 |
} |
318 |
||
16 | 319 |
// We need a working directory - strip off any .tmp or .zip suffixes. |
5 | 320 |
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' ); |
0 | 321 |
|
16 | 322 |
// Clean up working directory. |
9 | 323 |
if ( $wp_filesystem->is_dir( $working_dir ) ) { |
324 |
$wp_filesystem->delete( $working_dir, true ); |
|
325 |
} |
|
0 | 326 |
|
16 | 327 |
// Unzip package to working directory. |
0 | 328 |
$result = unzip_file( $package, $working_dir ); |
329 |
||
330 |
// Once extracted, delete the package if required. |
|
9 | 331 |
if ( $delete_package ) { |
332 |
unlink( $package ); |
|
333 |
} |
|
0 | 334 |
|
9 | 335 |
if ( is_wp_error( $result ) ) { |
336 |
$wp_filesystem->delete( $working_dir, true ); |
|
16 | 337 |
if ( 'incompatible_archive' === $result->get_error_code() ) { |
0 | 338 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() ); |
339 |
} |
|
340 |
return $result; |
|
341 |
} |
|
342 |
||
343 |
return $working_dir; |
|
344 |
} |
|
345 |
||
5 | 346 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
* Flatten the results of WP_Filesystem::dirlist() for iterating over. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
* |
16 | 352 |
* @param array $nested_files Array of files as returned by WP_Filesystem::dirlist(). |
353 |
* @param string $path Relative path to prepend to child nodes. Optional. |
|
354 |
* @return array A flattened array of the $nested_files specified. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
protected function flatten_dirlist( $nested_files, $path = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
$files = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
foreach ( $nested_files as $name => $details ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
$files[ $path . $name ] = $details; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
|
16 | 362 |
// Append children recursively. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
if ( ! empty( $details['files'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
$children = $this->flatten_dirlist( $details['files'], $path . $name . '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
|
16 | 366 |
// Merge keeping possible numeric keys, which array_merge() will reindex from 0..n. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
$files = $files + $children; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
return $files; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* Clears the directory where this item is going to be installed into. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* |
9 | 379 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* @param string $remote_destination The location on the remote filesystem to be cleared |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* @return bool|WP_Error True upon success, WP_Error on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
public function clear_destination( $remote_destination ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
$files = $wp_filesystem->dirlist( $remote_destination, true, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
// False indicates that the $remote_destination doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
if ( false === $files ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
|
16 | 394 |
// Flatten the file list to iterate over. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
$files = $this->flatten_dirlist( $files ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
// Check all files are writable before attempting to clear the destination. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
$unwritable_files = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
// Check writability. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
foreach ( $files as $filename => $file_details ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
// Attempt to alter permissions to allow writes and try again. |
16 | 404 |
$wp_filesystem->chmod( $remote_destination . $filename, ( 'd' === $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
$unwritable_files[] = $filename; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
if ( ! empty( $unwritable_files ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
if ( ! $wp_filesystem->delete( $remote_destination, true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
/** |
5 | 423 |
* Install a package. |
424 |
* |
|
425 |
* Copies the contents of a package form a source directory, and installs them in |
|
426 |
* a destination directory. Optionally removes the source. It can also optionally |
|
427 |
* clear out the destination folder if it already exists. |
|
428 |
* |
|
429 |
* @since 2.8.0 |
|
430 |
* |
|
9 | 431 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
* |
5 | 434 |
* @param array|string $args { |
435 |
* Optional. Array or string of arguments for installing a package. Default empty array. |
|
436 |
* |
|
437 |
* @type string $source Required path to the package source. Default empty. |
|
438 |
* @type string $destination Required path to a folder to install the package in. |
|
439 |
* Default empty. |
|
440 |
* @type bool $clear_destination Whether to delete any files already in the destination |
|
441 |
* folder. Default false. |
|
442 |
* @type bool $clear_working Whether to delete the files form the working directory |
|
443 |
* after copying to the destination. Default false. |
|
444 |
* @type bool $abort_if_destination_exists Whether to abort the installation if |
|
445 |
* the destination folder already exists. Default true. |
|
446 |
* @type array $hook_extra Extra arguments to pass to the filter hooks called by |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* WP_Upgrader::install_package(). Default empty array. |
5 | 448 |
* } |
449 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure. |
5 | 451 |
*/ |
452 |
public function install_package( $args = array() ) { |
|
0 | 453 |
global $wp_filesystem, $wp_theme_directories; |
454 |
||
455 |
$defaults = array( |
|
16 | 456 |
'source' => '', // Please always pass this. |
457 |
'destination' => '', // ...and this. |
|
9 | 458 |
'clear_destination' => false, |
459 |
'clear_working' => false, |
|
0 | 460 |
'abort_if_destination_exists' => true, |
9 | 461 |
'hook_extra' => array(), |
0 | 462 |
); |
463 |
||
9 | 464 |
$args = wp_parse_args( $args, $defaults ); |
5 | 465 |
|
466 |
// These were previously extract()'d. |
|
9 | 467 |
$source = $args['source']; |
468 |
$destination = $args['destination']; |
|
5 | 469 |
$clear_destination = $args['clear_destination']; |
0 | 470 |
|
16 | 471 |
set_time_limit( 300 ); |
0 | 472 |
|
5 | 473 |
if ( empty( $source ) || empty( $destination ) ) { |
474 |
return new WP_Error( 'bad_request', $this->strings['bad_request'] ); |
|
475 |
} |
|
476 |
$this->skin->feedback( 'installing_package' ); |
|
477 |
||
478 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
* Filters the install response before the installation has started. |
5 | 480 |
* |
481 |
* Returning a truthy value, or one that could be evaluated as a WP_Error |
|
482 |
* will effectively short-circuit the installation, returning that value |
|
483 |
* instead. |
|
484 |
* |
|
485 |
* @since 2.8.0 |
|
486 |
* |
|
487 |
* @param bool|WP_Error $response Response. |
|
488 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
|
489 |
*/ |
|
490 |
$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
|
5 | 492 |
if ( is_wp_error( $res ) ) { |
0 | 493 |
return $res; |
5 | 494 |
} |
0 | 495 |
|
16 | 496 |
// Retain the original source and destinations. |
9 | 497 |
$remote_source = $args['source']; |
0 | 498 |
$local_destination = $destination; |
499 |
||
9 | 500 |
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) ); |
5 | 501 |
$remote_destination = $wp_filesystem->find_folder( $local_destination ); |
0 | 502 |
|
16 | 503 |
// Locate which directory to copy to the new folder. This is based on the actual folder holding the files. |
504 |
if ( 1 === count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { |
|
505 |
// Only one folder? Then we want its contents. |
|
5 | 506 |
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] ); |
507 |
} elseif ( count( $source_files ) == 0 ) { |
|
16 | 508 |
// There are no files? |
509 |
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); |
|
510 |
} else { |
|
511 |
// It's only a single file, the upgrader will use the folder name of this file as the destination folder. |
|
512 |
// Folder name is based on zip filename. |
|
5 | 513 |
$source = trailingslashit( $args['source'] ); |
514 |
} |
|
515 |
||
516 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* Filters the source file location for the upgrade package. |
5 | 518 |
* |
519 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* @since 4.4.0 The $hook_extra parameter became available. |
5 | 521 |
* |
522 |
* @param string $source File source location. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* @param string $remote_source Remote file source location. |
5 | 524 |
* @param WP_Upgrader $this WP_Upgrader instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
5 | 526 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
|
5 | 529 |
if ( is_wp_error( $source ) ) { |
0 | 530 |
return $source; |
5 | 531 |
} |
532 |
||
533 |
// Has the source location changed? If so, we need a new source_files list. |
|
534 |
if ( $source !== $remote_source ) { |
|
535 |
$source_files = array_keys( $wp_filesystem->dirlist( $source ) ); |
|
536 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
|
5 | 538 |
/* |
539 |
* Protection against deleting files in any important base directories. |
|
540 |
* Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the |
|
541 |
* destination directory (WP_PLUGIN_DIR / wp-content/themes) intending |
|
542 |
* to copy the directory into the directory, whilst they pass the source |
|
543 |
* as the actual files to copy. |
|
544 |
*/ |
|
0 | 545 |
$protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' ); |
5 | 546 |
|
547 |
if ( is_array( $wp_theme_directories ) ) { |
|
0 | 548 |
$protected_directories = array_merge( $protected_directories, $wp_theme_directories ); |
5 | 549 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
|
16 | 551 |
if ( in_array( $destination, $protected_directories, true ) ) { |
5 | 552 |
$remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) ); |
9 | 553 |
$destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) ); |
0 | 554 |
} |
555 |
||
556 |
if ( $clear_destination ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
// We're going to clear the destination if there's something there. |
9 | 558 |
$this->skin->feedback( 'remove_old' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
$removed = $this->clear_destination( $remote_destination ); |
5 | 561 |
|
562 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
* Filters whether the upgrader cleared the destination. |
5 | 564 |
* |
565 |
* @since 2.8.0 |
|
566 |
* |
|
16 | 567 |
* @param true|WP_Error $removed Whether the destination was cleared. true upon success, WP_Error on failure. |
568 |
* @param string $local_destination The local package destination. |
|
569 |
* @param string $remote_destination The remote package destination. |
|
570 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
|
5 | 571 |
*/ |
572 |
$removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] ); |
|
573 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
if ( is_wp_error( $removed ) ) { |
0 | 575 |
return $removed; |
5 | 576 |
} |
9 | 577 |
} elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) { |
16 | 578 |
// If we're not clearing the destination folder and something exists there already, bail. |
579 |
// But first check to see if there are actually any files in the folder. |
|
9 | 580 |
$_files = $wp_filesystem->dirlist( $remote_destination ); |
581 |
if ( ! empty( $_files ) ) { |
|
16 | 582 |
$wp_filesystem->delete( $remote_source, true ); // Clear out the source files. |
9 | 583 |
return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination ); |
0 | 584 |
} |
585 |
} |
|
586 |
||
16 | 587 |
// Create destination if needed. |
5 | 588 |
if ( ! $wp_filesystem->exists( $remote_destination ) ) { |
589 |
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { |
|
0 | 590 |
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination ); |
5 | 591 |
} |
592 |
} |
|
16 | 593 |
|
0 | 594 |
// Copy new version of item into place. |
9 | 595 |
$result = copy_dir( $source, $remote_destination ); |
596 |
if ( is_wp_error( $result ) ) { |
|
5 | 597 |
if ( $args['clear_working'] ) { |
598 |
$wp_filesystem->delete( $remote_source, true ); |
|
599 |
} |
|
0 | 600 |
return $result; |
601 |
} |
|
602 |
||
16 | 603 |
// Clear the working folder? |
5 | 604 |
if ( $args['clear_working'] ) { |
605 |
$wp_filesystem->delete( $remote_source, true ); |
|
606 |
} |
|
0 | 607 |
|
9 | 608 |
$destination_name = basename( str_replace( $local_destination, '', $destination ) ); |
16 | 609 |
if ( '.' === $destination_name ) { |
0 | 610 |
$destination_name = ''; |
5 | 611 |
} |
612 |
||
613 |
$this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' ); |
|
614 |
||
615 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* Filters the installation response after the installation has finished. |
5 | 617 |
* |
618 |
* @since 2.8.0 |
|
619 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* @param bool $response Installation response. |
5 | 621 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
622 |
* @param array $result Installation result data. |
|
623 |
*/ |
|
624 |
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result ); |
|
625 |
||
9 | 626 |
if ( is_wp_error( $res ) ) { |
0 | 627 |
$this->result = $res; |
628 |
return $res; |
|
629 |
} |
|
630 |
||
16 | 631 |
// Bombard the calling function will all the info which we've just used. |
0 | 632 |
return $this->result; |
633 |
} |
|
634 |
||
5 | 635 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* Run an upgrade/installation. |
5 | 637 |
* |
638 |
* Attempts to download the package (if it is not a local file), unpack it, and |
|
639 |
* install it in the destination folder. |
|
640 |
* |
|
641 |
* @since 2.8.0 |
|
642 |
* |
|
643 |
* @param array $options { |
|
644 |
* Array or string of arguments for upgrading/installing a package. |
|
645 |
* |
|
646 |
* @type string $package The full path or URI of the package to install. |
|
647 |
* Default empty. |
|
648 |
* @type string $destination The full path to the destination folder. |
|
649 |
* Default empty. |
|
650 |
* @type bool $clear_destination Whether to delete any files already in the |
|
651 |
* destination folder. Default false. |
|
652 |
* @type bool $clear_working Whether to delete the files form the working |
|
653 |
* directory after copying to the destination. |
|
654 |
* Default false. |
|
655 |
* @type bool $abort_if_destination_exists Whether to abort the installation if the destination |
|
656 |
* folder already exists. When true, `$clear_destination` |
|
657 |
* should be false. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
* @type bool $is_multi Whether this run is one of multiple upgrade/installation |
5 | 659 |
* actions being performed in bulk. When true, the skin |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
* WP_Upgrader::header() and WP_Upgrader::footer() |
5 | 661 |
* aren't called. Default false. |
662 |
* @type array $hook_extra Extra arguments to pass to the filter hooks called by |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
* WP_Upgrader::run(). |
5 | 664 |
* } |
16 | 665 |
* @return array|false|WP_Error The result from self::install_package() on success, otherwise a WP_Error, |
5 | 666 |
* or false if unable to connect to the filesystem. |
667 |
*/ |
|
668 |
public function run( $options ) { |
|
0 | 669 |
|
670 |
$defaults = array( |
|
9 | 671 |
'package' => '', // Please always pass this. |
16 | 672 |
'destination' => '', // ...and this. |
9 | 673 |
'clear_destination' => false, |
16 | 674 |
'abort_if_destination_exists' => true, // Abort if the destination directory exists. Pass clear_destination as false please. |
9 | 675 |
'clear_working' => true, |
676 |
'is_multi' => false, |
|
677 |
'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
|
0 | 678 |
); |
679 |
||
5 | 680 |
$options = wp_parse_args( $options, $defaults ); |
681 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
* Filters the package options before running an update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
* See also {@see 'upgrader_process_complete'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
* @param array $options { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* Options used by the upgrader. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
* @type string $package Package for update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
* @type string $destination Update location. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
* @type bool $clear_destination Clear the destination resource. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
* @type bool $clear_working Clear the working resource. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
* @type bool $abort_if_destination_exists Abort if the Destination directory exists. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
* @type bool $is_multi Whether the upgrader is running multiple times. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
* @type array $hook_extra { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
* Extra hook arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
* @type string $action Type of action. Default 'update'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* @type bool $bulk Whether the update process is a bulk update. Default true. |
9 | 704 |
* @type string $plugin Path to the plugin file relative to the plugins directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
* @type string $theme The stylesheet or template name of the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
* @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* or 'core'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
* @type object $language_update The language pack update offer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
$options = apply_filters( 'upgrader_package_options', $options ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
|
16 | 714 |
if ( ! $options['is_multi'] ) { // Call $this->header separately if running multiple times. |
0 | 715 |
$this->skin->header(); |
5 | 716 |
} |
0 | 717 |
|
16 | 718 |
// Connect to the filesystem first. |
5 | 719 |
$res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) ); |
0 | 720 |
// Mainly for non-connected filesystem. |
721 |
if ( ! $res ) { |
|
5 | 722 |
if ( ! $options['is_multi'] ) { |
0 | 723 |
$this->skin->footer(); |
5 | 724 |
} |
0 | 725 |
return false; |
726 |
} |
|
727 |
||
728 |
$this->skin->before(); |
|
729 |
||
9 | 730 |
if ( is_wp_error( $res ) ) { |
731 |
$this->skin->error( $res ); |
|
0 | 732 |
$this->skin->after(); |
5 | 733 |
if ( ! $options['is_multi'] ) { |
0 | 734 |
$this->skin->footer(); |
5 | 735 |
} |
0 | 736 |
return $res; |
737 |
} |
|
738 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
* Download the package (Note, This just returns the filename |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
* of the file if the package is a local file) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
*/ |
16 | 743 |
$download = $this->download_package( $options['package'], true, $options['hook_extra'] ); |
9 | 744 |
|
745 |
// Allow for signature soft-fail. |
|
746 |
// WARNING: This may be removed in the future. |
|
747 |
if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) { |
|
748 |
||
749 |
// Don't output the 'no signature could be found' failure message for now. |
|
16 | 750 |
if ( 'signature_verification_no_signature' !== $download->get_error_code() || WP_DEBUG ) { |
751 |
// Output the failure error as a normal feedback, and not as an error. |
|
9 | 752 |
$this->skin->feedback( $download->get_error_message() ); |
753 |
||
754 |
// Report this failure back to WordPress.org for debugging purposes. |
|
755 |
wp_version_check( |
|
756 |
array( |
|
757 |
'signature_failure_code' => $download->get_error_code(), |
|
758 |
'signature_failure_data' => $download->get_error_data(), |
|
759 |
) |
|
760 |
); |
|
761 |
} |
|
762 |
||
763 |
// Pretend this error didn't happen. |
|
764 |
$download = $download->get_error_data( 'softfail-filename' ); |
|
765 |
} |
|
766 |
||
767 |
if ( is_wp_error( $download ) ) { |
|
768 |
$this->skin->error( $download ); |
|
0 | 769 |
$this->skin->after(); |
5 | 770 |
if ( ! $options['is_multi'] ) { |
0 | 771 |
$this->skin->footer(); |
5 | 772 |
} |
0 | 773 |
return $download; |
774 |
} |
|
775 |
||
16 | 776 |
$delete_package = ( $download != $options['package'] ); // Do not delete a "local" file. |
0 | 777 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
// Unzips the file into a temporary directory. |
0 | 779 |
$working_dir = $this->unpack_package( $download, $delete_package ); |
9 | 780 |
if ( is_wp_error( $working_dir ) ) { |
781 |
$this->skin->error( $working_dir ); |
|
0 | 782 |
$this->skin->after(); |
5 | 783 |
if ( ! $options['is_multi'] ) { |
0 | 784 |
$this->skin->footer(); |
5 | 785 |
} |
0 | 786 |
return $working_dir; |
787 |
} |
|
788 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
// With the given options, this installs it to the destination directory. |
9 | 790 |
$result = $this->install_package( |
791 |
array( |
|
792 |
'source' => $working_dir, |
|
793 |
'destination' => $options['destination'], |
|
794 |
'clear_destination' => $options['clear_destination'], |
|
795 |
'abort_if_destination_exists' => $options['abort_if_destination_exists'], |
|
796 |
'clear_working' => $options['clear_working'], |
|
797 |
'hook_extra' => $options['hook_extra'], |
|
798 |
) |
|
799 |
); |
|
0 | 800 |
|
9 | 801 |
$this->skin->set_result( $result ); |
802 |
if ( is_wp_error( $result ) ) { |
|
803 |
$this->skin->error( $result ); |
|
16 | 804 |
|
805 |
if ( ! method_exists( $this->skin, 'hide_process_failed' ) || ! $this->skin->hide_process_failed( $result ) ) { |
|
806 |
$this->skin->feedback( 'process_failed' ); |
|
807 |
} |
|
0 | 808 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
// Installation succeeded. |
9 | 810 |
$this->skin->feedback( 'process_success' ); |
0 | 811 |
} |
812 |
||
813 |
$this->skin->after(); |
|
814 |
||
5 | 815 |
if ( ! $options['is_multi'] ) { |
816 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
* Fires when the upgrader process is complete. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
* See also {@see 'upgrader_package_options'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* @since 3.7.0 Added to WP_Upgrader::run(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* @param array $hook_extra { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* Array of bulk item update data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
* @type string $action Type of action. Default 'update'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
* @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
* @type bool $bulk Whether the update process is a bulk update. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
* @type array $plugins Array of the basename paths of the plugins' main files. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
* @type array $themes The theme slugs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* @type array $translations { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* Array of translations update data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
* @type string $language The locale the translation is for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
* @type string $type Type of translation. Accepts 'plugin', 'theme', or 'core'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
* @type string $slug Text domain the translation is for. The slug of a theme/plugin or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
* 'default' for core translations. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
* @type string $version The version of a theme, plugin, or core. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
*/ |
5 | 847 |
do_action( 'upgrader_process_complete', $this, $options['hook_extra'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
|
0 | 849 |
$this->skin->footer(); |
850 |
} |
|
851 |
||
852 |
return $result; |
|
853 |
} |
|
854 |
||
5 | 855 |
/** |
856 |
* Toggle maintenance mode for the site. |
|
857 |
* |
|
858 |
* Creates/deletes the maintenance file to enable/disable maintenance mode. |
|
859 |
* |
|
860 |
* @since 2.8.0 |
|
861 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* @global WP_Filesystem_Base $wp_filesystem Subclass |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* |
5 | 864 |
* @param bool $enable True to enable maintenance mode, false to disable. |
865 |
*/ |
|
866 |
public function maintenance_mode( $enable = false ) { |
|
0 | 867 |
global $wp_filesystem; |
868 |
$file = $wp_filesystem->abspath() . '.maintenance'; |
|
869 |
if ( $enable ) { |
|
9 | 870 |
$this->skin->feedback( 'maintenance_start' ); |
16 | 871 |
// Create maintenance file to signal that we are upgrading. |
0 | 872 |
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; |
9 | 873 |
$wp_filesystem->delete( $file ); |
874 |
$wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE ); |
|
5 | 875 |
} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) { |
9 | 876 |
$this->skin->feedback( 'maintenance_end' ); |
877 |
$wp_filesystem->delete( $file ); |
|
0 | 878 |
} |
879 |
} |
|
880 |
||
5 | 881 |
/** |
9 | 882 |
* Creates a lock using WordPress options. |
883 |
* |
|
884 |
* @since 4.5.0 |
|
885 |
* |
|
886 |
* @param string $lock_name The name of this unique lock. |
|
887 |
* @param int $release_timeout Optional. The duration in seconds to respect an existing lock. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
* Default: 1 hour. |
9 | 889 |
* @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise. |
890 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
public static function create_lock( $lock_name, $release_timeout = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
if ( ! $release_timeout ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
$release_timeout = HOUR_IN_SECONDS; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
$lock_option = $lock_name . '.lock'; |
0 | 897 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
// Try to lock. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) ); |
0 | 900 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
if ( ! $lock_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
$lock_result = get_option( $lock_option ); |
0 | 903 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
// If a lock couldn't be created, and there isn't a lock, bail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
if ( ! $lock_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
return false; |
0 | 907 |
} |
908 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
// Check to see if the lock is still valid. If it is, bail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
if ( $lock_result > ( time() - $release_timeout ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
} |
0 | 913 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
// There must exist an expired lock, clear it and re-gain it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
WP_Upgrader::release_lock( $lock_name ); |
0 | 916 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
return WP_Upgrader::create_lock( $lock_name, $release_timeout ); |
0 | 918 |
} |
5 | 919 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
update_option( $lock_option, time() ); |
0 | 922 |
|
923 |
return true; |
|
924 |
} |
|
925 |
||
5 | 926 |
/** |
9 | 927 |
* Releases an upgrader lock. |
928 |
* |
|
929 |
* @since 4.5.0 |
|
5 | 930 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
* @see WP_Upgrader::create_lock() |
9 | 932 |
* |
933 |
* @param string $lock_name The name of this unique lock. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
* @return bool True if the lock was successfully released. False on failure. |
9 | 935 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
public static function release_lock( $lock_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
return delete_option( $lock_name . '.lock' ); |
0 | 938 |
} |
939 |
||
940 |
} |
|
941 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
/** Plugin_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
0 | 944 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
/** Theme_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader.php'; |
0 | 947 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
/** Language_Pack_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader.php'; |
0 | 950 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
/** Core_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
require_once ABSPATH . 'wp-admin/includes/class-core-upgrader.php'; |
0 | 953 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
/** File_Upload_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
require_once ABSPATH . 'wp-admin/includes/class-file-upload-upgrader.php'; |
5 | 956 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
/** WP_Automatic_Updater class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php'; |