author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:30:03 +0200 | |
changeset 10 | 372f2766ea20 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
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 |
* |
5 | 79 |
* @var WP_Error|array $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. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* @type string $destination The full path to the installation destination folder. |
5 | 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. |
|
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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
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.' ); |
|
0 | 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 |
* |
5 | 178 |
* @param array $directories Optional. A list of directories. If any of these do |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* not exist, a WP_Error object will be returned. |
5 | 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 |
||
5 | 188 |
if ( false === ( $credentials = $this->skin->request_filesystem_credentials( false, $directories[0], $allow_relaxed_file_ownership ) ) ) { |
0 | 189 |
return false; |
5 | 190 |
} |
191 |
||
192 |
if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) { |
|
0 | 193 |
$error = true; |
9 | 194 |
if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) { |
0 | 195 |
$error = $wp_filesystem->errors; |
9 | 196 |
} |
5 | 197 |
// Failed to connect, Error and request again |
198 |
$this->skin->request_filesystem_credentials( $error, $directories[0], $allow_relaxed_file_ownership ); |
|
0 | 199 |
return false; |
200 |
} |
|
201 |
||
9 | 202 |
if ( ! is_object( $wp_filesystem ) ) { |
203 |
return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] ); |
|
204 |
} |
|
0 | 205 |
|
9 | 206 |
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
207 |
return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors ); |
|
208 |
} |
|
0 | 209 |
|
9 | 210 |
foreach ( (array) $directories as $dir ) { |
0 | 211 |
switch ( $dir ) { |
212 |
case ABSPATH: |
|
9 | 213 |
if ( ! $wp_filesystem->abspath() ) { |
214 |
return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'] ); |
|
215 |
} |
|
0 | 216 |
break; |
217 |
case WP_CONTENT_DIR: |
|
9 | 218 |
if ( ! $wp_filesystem->wp_content_dir() ) { |
219 |
return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] ); |
|
220 |
} |
|
0 | 221 |
break; |
222 |
case WP_PLUGIN_DIR: |
|
9 | 223 |
if ( ! $wp_filesystem->wp_plugins_dir() ) { |
224 |
return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'] ); |
|
225 |
} |
|
0 | 226 |
break; |
227 |
case get_theme_root(): |
|
9 | 228 |
if ( ! $wp_filesystem->wp_themes_dir() ) { |
229 |
return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'] ); |
|
230 |
} |
|
0 | 231 |
break; |
232 |
default: |
|
9 | 233 |
if ( ! $wp_filesystem->find_folder( $dir ) ) { |
0 | 234 |
return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) ); |
9 | 235 |
} |
0 | 236 |
break; |
237 |
} |
|
238 |
} |
|
239 |
return true; |
|
240 |
} //end fs_connect(); |
|
241 |
||
5 | 242 |
/** |
243 |
* Download a package. |
|
244 |
* |
|
245 |
* @since 2.8.0 |
|
246 |
* |
|
9 | 247 |
* @param string $package The URI of the package. If this is the full path to an |
248 |
* existing local file, it will be returned untouched. |
|
249 |
* @param bool $check_signatures Whether to validate file signatures. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object. |
5 | 251 |
*/ |
9 | 252 |
public function download_package( $package, $check_signatures = false ) { |
0 | 253 |
|
254 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* Filters whether to return the package. |
0 | 256 |
* |
257 |
* @since 3.7.0 |
|
258 |
* |
|
5 | 259 |
* @param bool $reply Whether to bail without returning the package. |
260 |
* Default false. |
|
261 |
* @param string $package The package file name. |
|
262 |
* @param WP_Upgrader $this The WP_Upgrader instance. |
|
0 | 263 |
*/ |
264 |
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this ); |
|
9 | 265 |
if ( false !== $reply ) { |
0 | 266 |
return $reply; |
9 | 267 |
} |
0 | 268 |
|
9 | 269 |
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { //Local file or remote? |
0 | 270 |
return $package; //must be a local file.. |
9 | 271 |
} |
0 | 272 |
|
9 | 273 |
if ( empty( $package ) ) { |
274 |
return new WP_Error( 'no_package', $this->strings['no_package'] ); |
|
275 |
} |
|
0 | 276 |
|
9 | 277 |
$this->skin->feedback( 'downloading_package', $package ); |
0 | 278 |
|
9 | 279 |
$download_file = download_url( $package, 300, $check_signatures ); |
0 | 280 |
|
9 | 281 |
if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) { |
282 |
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() ); |
|
283 |
} |
|
0 | 284 |
|
285 |
return $download_file; |
|
286 |
} |
|
287 |
||
5 | 288 |
/** |
289 |
* Unpack a compressed package file. |
|
290 |
* |
|
291 |
* @since 2.8.0 |
|
292 |
* |
|
9 | 293 |
* @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
|
294 |
* |
5 | 295 |
* @param string $package Full path to the package file. |
296 |
* @param bool $delete_package Optional. Whether to delete the package file after attempting |
|
297 |
* to unpack it. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure. |
5 | 299 |
*/ |
300 |
public function unpack_package( $package, $delete_package = true ) { |
|
0 | 301 |
global $wp_filesystem; |
302 |
||
9 | 303 |
$this->skin->feedback( 'unpack_package' ); |
0 | 304 |
|
305 |
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; |
|
306 |
||
307 |
//Clean up contents of upgrade directory beforehand. |
|
9 | 308 |
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder ); |
309 |
if ( ! empty( $upgrade_files ) ) { |
|
310 |
foreach ( $upgrade_files as $file ) { |
|
311 |
$wp_filesystem->delete( $upgrade_folder . $file['name'], true ); |
|
312 |
} |
|
0 | 313 |
} |
314 |
||
5 | 315 |
// We need a working directory - Strip off any .tmp or .zip suffixes |
316 |
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' ); |
|
0 | 317 |
|
318 |
// Clean up working directory |
|
9 | 319 |
if ( $wp_filesystem->is_dir( $working_dir ) ) { |
320 |
$wp_filesystem->delete( $working_dir, true ); |
|
321 |
} |
|
0 | 322 |
|
323 |
// Unzip package to working directory |
|
324 |
$result = unzip_file( $package, $working_dir ); |
|
325 |
||
326 |
// Once extracted, delete the package if required. |
|
9 | 327 |
if ( $delete_package ) { |
328 |
unlink( $package ); |
|
329 |
} |
|
0 | 330 |
|
9 | 331 |
if ( is_wp_error( $result ) ) { |
332 |
$wp_filesystem->delete( $working_dir, true ); |
|
0 | 333 |
if ( 'incompatible_archive' == $result->get_error_code() ) { |
334 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() ); |
|
335 |
} |
|
336 |
return $result; |
|
337 |
} |
|
338 |
||
339 |
return $working_dir; |
|
340 |
} |
|
341 |
||
5 | 342 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
* 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
|
344 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
* @param array $nested_files Array of files as returned by WP_Filesystem::dirlist() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
* @param string $path Relative path to prepend to child nodes. Optional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* @return array $files A flattened array of the $nested_files specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
protected function flatten_dirlist( $nested_files, $path = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
$files = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
foreach ( $nested_files as $name => $details ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
$files[ $path . $name ] = $details; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
// Append children recursively |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
if ( ! empty( $details['files'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
$children = $this->flatten_dirlist( $details['files'], $path . $name . '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
// Merge keeping possible numeric keys, which array_merge() will reindex from 0..n |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
$files = $files + $children; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
return $files; |
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 |
* 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
|
372 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* |
9 | 375 |
* @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
|
376 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* @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
|
378 |
* @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
|
379 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
public function clear_destination( $remote_destination ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
$files = $wp_filesystem->dirlist( $remote_destination, true, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
// False indicates that the $remote_destination doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
if ( false === $files ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
return 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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
// Flatten the file list to iterate over |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
$files = $this->flatten_dirlist( $files ); |
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 |
// 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
|
394 |
$unwritable_files = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
// Check writability. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
foreach ( $files as $filename => $file_details ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
// Attempt to alter permissions to allow writes and try again. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
$wp_filesystem->chmod( $remote_destination . $filename, ( 'd' == $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
$unwritable_files[] = $filename; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
if ( ! empty( $unwritable_files ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
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
|
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 ( ! $wp_filesystem->delete( $remote_destination, true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
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
|
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 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
} |
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 |
/** |
5 | 419 |
* Install a package. |
420 |
* |
|
421 |
* Copies the contents of a package form a source directory, and installs them in |
|
422 |
* a destination directory. Optionally removes the source. It can also optionally |
|
423 |
* clear out the destination folder if it already exists. |
|
424 |
* |
|
425 |
* @since 2.8.0 |
|
426 |
* |
|
9 | 427 |
* @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
|
428 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* |
5 | 430 |
* @param array|string $args { |
431 |
* Optional. Array or string of arguments for installing a package. Default empty array. |
|
432 |
* |
|
433 |
* @type string $source Required path to the package source. Default empty. |
|
434 |
* @type string $destination Required path to a folder to install the package in. |
|
435 |
* Default empty. |
|
436 |
* @type bool $clear_destination Whether to delete any files already in the destination |
|
437 |
* folder. Default false. |
|
438 |
* @type bool $clear_working Whether to delete the files form the working directory |
|
439 |
* after copying to the destination. Default false. |
|
440 |
* @type bool $abort_if_destination_exists Whether to abort the installation if |
|
441 |
* the destination folder already exists. Default true. |
|
442 |
* @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
|
443 |
* WP_Upgrader::install_package(). Default empty array. |
5 | 444 |
* } |
445 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
* @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure. |
5 | 447 |
*/ |
448 |
public function install_package( $args = array() ) { |
|
0 | 449 |
global $wp_filesystem, $wp_theme_directories; |
450 |
||
451 |
$defaults = array( |
|
9 | 452 |
'source' => '', // Please always pass this |
453 |
'destination' => '', // and this |
|
454 |
'clear_destination' => false, |
|
455 |
'clear_working' => false, |
|
0 | 456 |
'abort_if_destination_exists' => true, |
9 | 457 |
'hook_extra' => array(), |
0 | 458 |
); |
459 |
||
9 | 460 |
$args = wp_parse_args( $args, $defaults ); |
5 | 461 |
|
462 |
// These were previously extract()'d. |
|
9 | 463 |
$source = $args['source']; |
464 |
$destination = $args['destination']; |
|
5 | 465 |
$clear_destination = $args['clear_destination']; |
0 | 466 |
|
467 |
@set_time_limit( 300 ); |
|
468 |
||
5 | 469 |
if ( empty( $source ) || empty( $destination ) ) { |
470 |
return new WP_Error( 'bad_request', $this->strings['bad_request'] ); |
|
471 |
} |
|
472 |
$this->skin->feedback( 'installing_package' ); |
|
473 |
||
474 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* Filters the install response before the installation has started. |
5 | 476 |
* |
477 |
* Returning a truthy value, or one that could be evaluated as a WP_Error |
|
478 |
* will effectively short-circuit the installation, returning that value |
|
479 |
* instead. |
|
480 |
* |
|
481 |
* @since 2.8.0 |
|
482 |
* |
|
483 |
* @param bool|WP_Error $response Response. |
|
484 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
|
485 |
*/ |
|
486 |
$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
|
487 |
|
5 | 488 |
if ( is_wp_error( $res ) ) { |
0 | 489 |
return $res; |
5 | 490 |
} |
0 | 491 |
|
492 |
//Retain the Original source and destinations |
|
9 | 493 |
$remote_source = $args['source']; |
0 | 494 |
$local_destination = $destination; |
495 |
||
9 | 496 |
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) ); |
5 | 497 |
$remote_destination = $wp_filesystem->find_folder( $local_destination ); |
0 | 498 |
|
499 |
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files. |
|
5 | 500 |
if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents. |
501 |
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] ); |
|
502 |
} elseif ( count( $source_files ) == 0 ) { |
|
0 | 503 |
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files? |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
} else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename. |
5 | 505 |
$source = trailingslashit( $args['source'] ); |
506 |
} |
|
507 |
||
508 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
* Filters the source file location for the upgrade package. |
5 | 510 |
* |
511 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
* @since 4.4.0 The $hook_extra parameter became available. |
5 | 513 |
* |
514 |
* @param string $source File source location. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* @param string $remote_source Remote file source location. |
5 | 516 |
* @param WP_Upgrader $this WP_Upgrader instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
5 | 518 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
$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
|
520 |
|
5 | 521 |
if ( is_wp_error( $source ) ) { |
0 | 522 |
return $source; |
5 | 523 |
} |
524 |
||
525 |
// Has the source location changed? If so, we need a new source_files list. |
|
526 |
if ( $source !== $remote_source ) { |
|
527 |
$source_files = array_keys( $wp_filesystem->dirlist( $source ) ); |
|
528 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
|
5 | 530 |
/* |
531 |
* Protection against deleting files in any important base directories. |
|
532 |
* Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the |
|
533 |
* destination directory (WP_PLUGIN_DIR / wp-content/themes) intending |
|
534 |
* to copy the directory into the directory, whilst they pass the source |
|
535 |
* as the actual files to copy. |
|
536 |
*/ |
|
0 | 537 |
$protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' ); |
5 | 538 |
|
539 |
if ( is_array( $wp_theme_directories ) ) { |
|
0 | 540 |
$protected_directories = array_merge( $protected_directories, $wp_theme_directories ); |
5 | 541 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
0 | 543 |
if ( in_array( $destination, $protected_directories ) ) { |
5 | 544 |
$remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) ); |
9 | 545 |
$destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) ); |
0 | 546 |
} |
547 |
||
548 |
if ( $clear_destination ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
// We're going to clear the destination if there's something there. |
9 | 550 |
$this->skin->feedback( 'remove_old' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
$removed = $this->clear_destination( $remote_destination ); |
5 | 553 |
|
554 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
* Filters whether the upgrader cleared the destination. |
5 | 556 |
* |
557 |
* @since 2.8.0 |
|
558 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
* @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure |
5 | 560 |
* @param string $local_destination The local package destination. |
561 |
* @param string $remote_destination The remote package destination. |
|
562 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
|
563 |
*/ |
|
564 |
$removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] ); |
|
565 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
if ( is_wp_error( $removed ) ) { |
0 | 567 |
return $removed; |
5 | 568 |
} |
9 | 569 |
} elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) { |
0 | 570 |
//If we're not clearing the destination folder and something exists there already, Bail. |
571 |
//But first check to see if there are actually any files in the folder. |
|
9 | 572 |
$_files = $wp_filesystem->dirlist( $remote_destination ); |
573 |
if ( ! empty( $_files ) ) { |
|
574 |
$wp_filesystem->delete( $remote_source, true ); //Clear out the source files. |
|
575 |
return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination ); |
|
0 | 576 |
} |
577 |
} |
|
578 |
||
579 |
//Create destination if needed |
|
5 | 580 |
if ( ! $wp_filesystem->exists( $remote_destination ) ) { |
581 |
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { |
|
0 | 582 |
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination ); |
5 | 583 |
} |
584 |
} |
|
0 | 585 |
// Copy new version of item into place. |
9 | 586 |
$result = copy_dir( $source, $remote_destination ); |
587 |
if ( is_wp_error( $result ) ) { |
|
5 | 588 |
if ( $args['clear_working'] ) { |
589 |
$wp_filesystem->delete( $remote_source, true ); |
|
590 |
} |
|
0 | 591 |
return $result; |
592 |
} |
|
593 |
||
594 |
//Clear the Working folder? |
|
5 | 595 |
if ( $args['clear_working'] ) { |
596 |
$wp_filesystem->delete( $remote_source, true ); |
|
597 |
} |
|
0 | 598 |
|
9 | 599 |
$destination_name = basename( str_replace( $local_destination, '', $destination ) ); |
5 | 600 |
if ( '.' == $destination_name ) { |
0 | 601 |
$destination_name = ''; |
5 | 602 |
} |
603 |
||
604 |
$this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' ); |
|
605 |
||
606 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* Filters the installation response after the installation has finished. |
5 | 608 |
* |
609 |
* @since 2.8.0 |
|
610 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
* @param bool $response Installation response. |
5 | 612 |
* @param array $hook_extra Extra arguments passed to hooked filters. |
613 |
* @param array $result Installation result data. |
|
614 |
*/ |
|
615 |
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result ); |
|
616 |
||
9 | 617 |
if ( is_wp_error( $res ) ) { |
0 | 618 |
$this->result = $res; |
619 |
return $res; |
|
620 |
} |
|
621 |
||
622 |
//Bombard the calling function will all the info which we've just used. |
|
623 |
return $this->result; |
|
624 |
} |
|
625 |
||
5 | 626 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* Run an upgrade/installation. |
5 | 628 |
* |
629 |
* Attempts to download the package (if it is not a local file), unpack it, and |
|
630 |
* install it in the destination folder. |
|
631 |
* |
|
632 |
* @since 2.8.0 |
|
633 |
* |
|
634 |
* @param array $options { |
|
635 |
* Array or string of arguments for upgrading/installing a package. |
|
636 |
* |
|
637 |
* @type string $package The full path or URI of the package to install. |
|
638 |
* Default empty. |
|
639 |
* @type string $destination The full path to the destination folder. |
|
640 |
* Default empty. |
|
641 |
* @type bool $clear_destination Whether to delete any files already in the |
|
642 |
* destination folder. Default false. |
|
643 |
* @type bool $clear_working Whether to delete the files form the working |
|
644 |
* directory after copying to the destination. |
|
645 |
* Default false. |
|
646 |
* @type bool $abort_if_destination_exists Whether to abort the installation if the destination |
|
647 |
* folder already exists. When true, `$clear_destination` |
|
648 |
* should be false. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* @type bool $is_multi Whether this run is one of multiple upgrade/installation |
5 | 650 |
* 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
|
651 |
* WP_Upgrader::header() and WP_Upgrader::footer() |
5 | 652 |
* aren't called. Default false. |
653 |
* @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
|
654 |
* WP_Upgrader::run(). |
5 | 655 |
* } |
656 |
* @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error, |
|
657 |
* or false if unable to connect to the filesystem. |
|
658 |
*/ |
|
659 |
public function run( $options ) { |
|
0 | 660 |
|
661 |
$defaults = array( |
|
9 | 662 |
'package' => '', // Please always pass this. |
663 |
'destination' => '', // And this |
|
664 |
'clear_destination' => false, |
|
0 | 665 |
'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please |
9 | 666 |
'clear_working' => true, |
667 |
'is_multi' => false, |
|
668 |
'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
|
0 | 669 |
); |
670 |
||
5 | 671 |
$options = wp_parse_args( $options, $defaults ); |
672 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* Filters the package options before running an update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
* See also {@see 'upgrader_process_complete'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
* @param array $options { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
* Options used by the upgrader. |
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 |
* @type string $package Package for update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
* @type string $destination Update location. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
* @type bool $clear_destination Clear the destination resource. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
* @type bool $clear_working Clear the working resource. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
* @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
|
688 |
* @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
|
689 |
* @type array $hook_extra { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* Extra hook arguments. |
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 $action Type of action. Default 'update'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
* @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
|
694 |
* @type bool $bulk Whether the update process is a bulk update. Default true. |
9 | 695 |
* @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
|
696 |
* @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
|
697 |
* @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
|
698 |
* or 'core'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
* @type object $language_update The language pack update offer. |
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 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
$options = apply_filters( 'upgrader_package_options', $options ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
|
5 | 705 |
if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times |
0 | 706 |
$this->skin->header(); |
5 | 707 |
} |
0 | 708 |
|
709 |
// Connect to the Filesystem first. |
|
5 | 710 |
$res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) ); |
0 | 711 |
// Mainly for non-connected filesystem. |
712 |
if ( ! $res ) { |
|
5 | 713 |
if ( ! $options['is_multi'] ) { |
0 | 714 |
$this->skin->footer(); |
5 | 715 |
} |
0 | 716 |
return false; |
717 |
} |
|
718 |
||
719 |
$this->skin->before(); |
|
720 |
||
9 | 721 |
if ( is_wp_error( $res ) ) { |
722 |
$this->skin->error( $res ); |
|
0 | 723 |
$this->skin->after(); |
5 | 724 |
if ( ! $options['is_multi'] ) { |
0 | 725 |
$this->skin->footer(); |
5 | 726 |
} |
0 | 727 |
return $res; |
728 |
} |
|
729 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* Download the package (Note, This just returns the filename |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
* 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
|
733 |
*/ |
9 | 734 |
$download = $this->download_package( $options['package'], true ); |
735 |
||
736 |
// Allow for signature soft-fail. |
|
737 |
// WARNING: This may be removed in the future. |
|
738 |
if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) { |
|
739 |
||
740 |
// Don't output the 'no signature could be found' failure message for now. |
|
741 |
if ( 'signature_verification_no_signature' != $download->get_error_code() || WP_DEBUG ) { |
|
742 |
// Outout the failure error as a normal feedback, and not as an error: |
|
743 |
$this->skin->feedback( $download->get_error_message() ); |
|
744 |
||
745 |
// Report this failure back to WordPress.org for debugging purposes. |
|
746 |
wp_version_check( |
|
747 |
array( |
|
748 |
'signature_failure_code' => $download->get_error_code(), |
|
749 |
'signature_failure_data' => $download->get_error_data(), |
|
750 |
) |
|
751 |
); |
|
752 |
} |
|
753 |
||
754 |
// Pretend this error didn't happen. |
|
755 |
$download = $download->get_error_data( 'softfail-filename' ); |
|
756 |
} |
|
757 |
||
758 |
if ( is_wp_error( $download ) ) { |
|
759 |
$this->skin->error( $download ); |
|
0 | 760 |
$this->skin->after(); |
5 | 761 |
if ( ! $options['is_multi'] ) { |
0 | 762 |
$this->skin->footer(); |
5 | 763 |
} |
0 | 764 |
return $download; |
765 |
} |
|
766 |
||
5 | 767 |
$delete_package = ( $download != $options['package'] ); // Do not delete a "local" file |
0 | 768 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
// Unzips the file into a temporary directory. |
0 | 770 |
$working_dir = $this->unpack_package( $download, $delete_package ); |
9 | 771 |
if ( is_wp_error( $working_dir ) ) { |
772 |
$this->skin->error( $working_dir ); |
|
0 | 773 |
$this->skin->after(); |
5 | 774 |
if ( ! $options['is_multi'] ) { |
0 | 775 |
$this->skin->footer(); |
5 | 776 |
} |
0 | 777 |
return $working_dir; |
778 |
} |
|
779 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
// With the given options, this installs it to the destination directory. |
9 | 781 |
$result = $this->install_package( |
782 |
array( |
|
783 |
'source' => $working_dir, |
|
784 |
'destination' => $options['destination'], |
|
785 |
'clear_destination' => $options['clear_destination'], |
|
786 |
'abort_if_destination_exists' => $options['abort_if_destination_exists'], |
|
787 |
'clear_working' => $options['clear_working'], |
|
788 |
'hook_extra' => $options['hook_extra'], |
|
789 |
) |
|
790 |
); |
|
0 | 791 |
|
9 | 792 |
$this->skin->set_result( $result ); |
793 |
if ( is_wp_error( $result ) ) { |
|
794 |
$this->skin->error( $result ); |
|
795 |
$this->skin->feedback( 'process_failed' ); |
|
0 | 796 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
// Installation succeeded. |
9 | 798 |
$this->skin->feedback( 'process_success' ); |
0 | 799 |
} |
800 |
||
801 |
$this->skin->after(); |
|
802 |
||
5 | 803 |
if ( ! $options['is_multi'] ) { |
804 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
* Fires when the upgrader process is complete. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
* See also {@see 'upgrader_package_options'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* @since 3.7.0 Added to WP_Upgrader::run(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
* @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
|
813 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
* @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
|
815 |
* 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
|
816 |
* @param array $hook_extra { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
* Array of bulk item update data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
* @type string $action Type of action. Default 'update'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
* @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
|
821 |
* @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
|
822 |
* @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
|
823 |
* @type array $themes The theme slugs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* @type array $translations { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* Array of translations update data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @type string $language The locale the translation is for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* @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
|
829 |
* @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
|
830 |
* 'default' for core translations. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
* @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
|
832 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
*/ |
5 | 835 |
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
|
836 |
|
0 | 837 |
$this->skin->footer(); |
838 |
} |
|
839 |
||
840 |
return $result; |
|
841 |
} |
|
842 |
||
5 | 843 |
/** |
844 |
* Toggle maintenance mode for the site. |
|
845 |
* |
|
846 |
* Creates/deletes the maintenance file to enable/disable maintenance mode. |
|
847 |
* |
|
848 |
* @since 2.8.0 |
|
849 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
* @global WP_Filesystem_Base $wp_filesystem Subclass |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
* |
5 | 852 |
* @param bool $enable True to enable maintenance mode, false to disable. |
853 |
*/ |
|
854 |
public function maintenance_mode( $enable = false ) { |
|
0 | 855 |
global $wp_filesystem; |
856 |
$file = $wp_filesystem->abspath() . '.maintenance'; |
|
857 |
if ( $enable ) { |
|
9 | 858 |
$this->skin->feedback( 'maintenance_start' ); |
0 | 859 |
// Create maintenance file to signal that we are upgrading |
860 |
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; |
|
9 | 861 |
$wp_filesystem->delete( $file ); |
862 |
$wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE ); |
|
5 | 863 |
} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) { |
9 | 864 |
$this->skin->feedback( 'maintenance_end' ); |
865 |
$wp_filesystem->delete( $file ); |
|
0 | 866 |
} |
867 |
} |
|
868 |
||
5 | 869 |
/** |
9 | 870 |
* Creates a lock using WordPress options. |
871 |
* |
|
872 |
* @since 4.5.0 |
|
873 |
* |
|
874 |
* @param string $lock_name The name of this unique lock. |
|
875 |
* @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
|
876 |
* Default: 1 hour. |
9 | 877 |
* @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise. |
878 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
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
|
880 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
if ( ! $release_timeout ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
$release_timeout = HOUR_IN_SECONDS; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
$lock_option = $lock_name . '.lock'; |
0 | 885 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
// Try to lock. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
$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 | 888 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
if ( ! $lock_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
$lock_result = get_option( $lock_option ); |
0 | 891 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
// 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
|
893 |
if ( ! $lock_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
return false; |
0 | 895 |
} |
896 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
// 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
|
898 |
if ( $lock_result > ( time() - $release_timeout ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
} |
0 | 901 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
// 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
|
903 |
WP_Upgrader::release_lock( $lock_name ); |
0 | 904 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
return WP_Upgrader::create_lock( $lock_name, $release_timeout ); |
0 | 906 |
} |
5 | 907 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
// 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
|
909 |
update_option( $lock_option, time() ); |
0 | 910 |
|
911 |
return true; |
|
912 |
} |
|
913 |
||
5 | 914 |
/** |
9 | 915 |
* Releases an upgrader lock. |
916 |
* |
|
917 |
* @since 4.5.0 |
|
5 | 918 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
* @see WP_Upgrader::create_lock() |
9 | 920 |
* |
921 |
* @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
|
922 |
* @return bool True if the lock was successfully released. False on failure. |
9 | 923 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
public static function release_lock( $lock_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
return delete_option( $lock_name . '.lock' ); |
0 | 926 |
} |
927 |
||
928 |
} |
|
929 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
/** Plugin_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
0 | 932 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
/** Theme_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader.php'; |
0 | 935 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
/** Language_Pack_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader.php'; |
0 | 938 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
/** Core_Upgrader class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
require_once ABSPATH . 'wp-admin/includes/class-core-upgrader.php'; |
0 | 941 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
/** File_Upload_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-file-upload-upgrader.php'; |
5 | 944 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
/** WP_Automatic_Updater class */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php'; |