equal
deleted
inserted
replaced
160 $this->strings['installing_package'] = __( 'Installing the latest version…' ); |
160 $this->strings['installing_package'] = __( 'Installing the latest version…' ); |
161 $this->strings['no_files'] = __( 'The package contains no files.' ); |
161 $this->strings['no_files'] = __( 'The package contains no files.' ); |
162 $this->strings['folder_exists'] = __( 'Destination folder already exists.' ); |
162 $this->strings['folder_exists'] = __( 'Destination folder already exists.' ); |
163 $this->strings['mkdir_failed'] = __( 'Could not create directory.' ); |
163 $this->strings['mkdir_failed'] = __( 'Could not create directory.' ); |
164 $this->strings['incompatible_archive'] = __( 'The package could not be installed.' ); |
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.' ); |
165 $this->strings['files_not_writable'] = __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ); |
166 |
166 |
167 $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' ); |
167 $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' ); |
168 $this->strings['maintenance_end'] = __( 'Disabling Maintenance mode…' ); |
168 $this->strings['maintenance_end'] = __( 'Disabling Maintenance mode…' ); |
169 } |
169 } |
170 |
170 |
242 |
242 |
243 /** |
243 /** |
244 * Download a package. |
244 * Download a package. |
245 * |
245 * |
246 * @since 2.8.0 |
246 * @since 2.8.0 |
|
247 * @since 5.2.0 Added the `$check_signatures` parameter. |
247 * @since 5.5.0 Added the `$hook_extra` parameter. |
248 * @since 5.5.0 Added the `$hook_extra` parameter. |
248 * |
249 * |
249 * @param string $package The URI of the package. If this is the full path to an |
250 * @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 * existing local file, it will be returned untouched. |
251 * @param bool $check_signatures Whether to validate file signatures. Default false. |
252 * @param bool $check_signatures Whether to validate file signatures. Default false. |
376 * |
377 * |
377 * @since 4.3.0 |
378 * @since 4.3.0 |
378 * |
379 * |
379 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
380 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
380 * |
381 * |
381 * @param string $remote_destination The location on the remote filesystem to be cleared |
382 * @param string $remote_destination The location on the remote filesystem to be cleared. |
382 * @return bool|WP_Error True upon success, WP_Error on failure. |
383 * @return true|WP_Error True upon success, WP_Error on failure. |
383 */ |
384 */ |
384 public function clear_destination( $remote_destination ) { |
385 public function clear_destination( $remote_destination ) { |
385 global $wp_filesystem; |
386 global $wp_filesystem; |
386 |
387 |
387 $files = $wp_filesystem->dirlist( $remote_destination, true, true ); |
388 $files = $wp_filesystem->dirlist( $remote_destination, true, true ); |
420 } |
421 } |
421 |
422 |
422 /** |
423 /** |
423 * Install a package. |
424 * Install a package. |
424 * |
425 * |
425 * Copies the contents of a package form a source directory, and installs them in |
426 * Copies the contents of a package from a source directory, and installs them in |
426 * a destination directory. Optionally removes the source. It can also optionally |
427 * a destination directory. Optionally removes the source. It can also optionally |
427 * clear out the destination folder if it already exists. |
428 * clear out the destination folder if it already exists. |
428 * |
429 * |
429 * @since 2.8.0 |
430 * @since 2.8.0 |
430 * |
431 * |
437 * @type string $source Required path to the package source. Default empty. |
438 * @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 * @type string $destination Required path to a folder to install the package in. |
439 * Default empty. |
440 * Default empty. |
440 * @type bool $clear_destination Whether to delete any files already in the destination |
441 * @type bool $clear_destination Whether to delete any files already in the destination |
441 * folder. Default false. |
442 * folder. Default false. |
442 * @type bool $clear_working Whether to delete the files form the working directory |
443 * @type bool $clear_working Whether to delete the files from the working directory |
443 * after copying to the destination. Default false. |
444 * after copying them to the destination. Default false. |
444 * @type bool $abort_if_destination_exists Whether to abort the installation if |
445 * @type bool $abort_if_destination_exists Whether to abort the installation if |
445 * the destination folder already exists. Default true. |
446 * the destination folder already exists. Default true. |
446 * @type array $hook_extra Extra arguments to pass to the filter hooks called by |
447 * @type array $hook_extra Extra arguments to pass to the filter hooks called by |
447 * WP_Upgrader::install_package(). Default empty array. |
448 * WP_Upgrader::install_package(). Default empty array. |
448 * } |
449 * } |
474 return new WP_Error( 'bad_request', $this->strings['bad_request'] ); |
475 return new WP_Error( 'bad_request', $this->strings['bad_request'] ); |
475 } |
476 } |
476 $this->skin->feedback( 'installing_package' ); |
477 $this->skin->feedback( 'installing_package' ); |
477 |
478 |
478 /** |
479 /** |
479 * Filters the install response before the installation has started. |
480 * Filters the installation response before the installation has started. |
480 * |
481 * |
481 * Returning a truthy value, or one that could be evaluated as a WP_Error |
482 * Returning a value that could be evaluated as a `WP_Error` will effectively |
482 * will effectively short-circuit the installation, returning that value |
483 * short-circuit the installation, returning that value instead. |
483 * instead. |
|
484 * |
484 * |
485 * @since 2.8.0 |
485 * @since 2.8.0 |
486 * |
486 * |
487 * @param bool|WP_Error $response Response. |
487 * @param bool|WP_Error $response Installation response. |
488 * @param array $hook_extra Extra arguments passed to hooked filters. |
488 * @param array $hook_extra Extra arguments passed to hooked filters. |
489 */ |
489 */ |
490 $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] ); |
490 $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] ); |
491 |
491 |
492 if ( is_wp_error( $res ) ) { |
492 if ( is_wp_error( $res ) ) { |
562 /** |
562 /** |
563 * Filters whether the upgrader cleared the destination. |
563 * Filters whether the upgrader cleared the destination. |
564 * |
564 * |
565 * @since 2.8.0 |
565 * @since 2.8.0 |
566 * |
566 * |
567 * @param true|WP_Error $removed Whether the destination was cleared. true upon success, WP_Error on failure. |
567 * @param true|WP_Error $removed Whether the destination was cleared. |
|
568 * True upon success, WP_Error on failure. |
568 * @param string $local_destination The local package destination. |
569 * @param string $local_destination The local package destination. |
569 * @param string $remote_destination The remote package destination. |
570 * @param string $remote_destination The remote package destination. |
570 * @param array $hook_extra Extra arguments passed to hooked filters. |
571 * @param array $hook_extra Extra arguments passed to hooked filters. |
571 */ |
572 */ |
572 $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] ); |
573 $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] ); |
647 * Default empty. |
648 * Default empty. |
648 * @type string $destination The full path to the destination folder. |
649 * @type string $destination The full path to the destination folder. |
649 * Default empty. |
650 * Default empty. |
650 * @type bool $clear_destination Whether to delete any files already in the |
651 * @type bool $clear_destination Whether to delete any files already in the |
651 * destination folder. Default false. |
652 * destination folder. Default false. |
652 * @type bool $clear_working Whether to delete the files form the working |
653 * @type bool $clear_working Whether to delete the files from the working |
653 * directory after copying to the destination. |
654 * directory after copying them to the destination. |
654 * Default false. |
655 * Default true. |
655 * @type bool $abort_if_destination_exists Whether to abort the installation if the destination |
656 * @type bool $abort_if_destination_exists Whether to abort the installation if the destination |
656 * folder already exists. When true, `$clear_destination` |
657 * folder already exists. When true, `$clear_destination` |
657 * should be false. Default true. |
658 * should be false. Default true. |
658 * @type bool $is_multi Whether this run is one of multiple upgrade/installation |
659 * @type bool $is_multi Whether this run is one of multiple upgrade/installation |
659 * actions being performed in bulk. When true, the skin |
660 * actions being performed in bulk. When true, the skin |
669 |
670 |
670 $defaults = array( |
671 $defaults = array( |
671 'package' => '', // Please always pass this. |
672 'package' => '', // Please always pass this. |
672 'destination' => '', // ...and this. |
673 'destination' => '', // ...and this. |
673 'clear_destination' => false, |
674 'clear_destination' => false, |
|
675 'clear_working' => true, |
674 'abort_if_destination_exists' => true, // Abort if the destination directory exists. Pass clear_destination as false please. |
676 'abort_if_destination_exists' => true, // Abort if the destination directory exists. Pass clear_destination as false please. |
675 'clear_working' => true, |
|
676 'is_multi' => false, |
677 'is_multi' => false, |
677 'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
678 'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
678 ); |
679 ); |
679 |
680 |
680 $options = wp_parse_args( $options, $defaults ); |
681 $options = wp_parse_args( $options, $defaults ); |
735 } |
736 } |
736 return $res; |
737 return $res; |
737 } |
738 } |
738 |
739 |
739 /* |
740 /* |
740 * Download the package (Note, This just returns the filename |
741 * Download the package. Note: If the package is the full path |
741 * of the file if the package is a local file) |
742 * to an existing local file, it will be returned untouched. |
742 */ |
743 */ |
743 $download = $this->download_package( $options['package'], true, $options['hook_extra'] ); |
744 $download = $this->download_package( $options['package'], true, $options['hook_extra'] ); |
744 |
745 |
745 // Allow for signature soft-fail. |
746 // Allow for signature soft-fail. |
746 // WARNING: This may be removed in the future. |
747 // WARNING: This may be removed in the future. |
831 * |
832 * |
832 * @since 3.6.0 |
833 * @since 3.6.0 |
833 * @since 3.7.0 Added to WP_Upgrader::run(). |
834 * @since 3.7.0 Added to WP_Upgrader::run(). |
834 * @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`. |
835 * @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`. |
835 * |
836 * |
836 * @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a |
837 * @param WP_Upgrader $upgrader WP_Upgrader instance. In other contexts this might be a |
837 * Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance. |
838 * Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance. |
838 * @param array $hook_extra { |
839 * @param array $hook_extra { |
839 * Array of bulk item update data. |
840 * Array of bulk item update data. |
840 * |
841 * |
841 * @type string $action Type of action. Default 'update'. |
842 * @type string $action Type of action. Default 'update'. |
842 * @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'. |
843 * @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'. |
867 * |
868 * |
868 * Creates/deletes the maintenance file to enable/disable maintenance mode. |
869 * Creates/deletes the maintenance file to enable/disable maintenance mode. |
869 * |
870 * |
870 * @since 2.8.0 |
871 * @since 2.8.0 |
871 * |
872 * |
872 * @global WP_Filesystem_Base $wp_filesystem Subclass |
873 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
873 * |
874 * |
874 * @param bool $enable True to enable maintenance mode, false to disable. |
875 * @param bool $enable True to enable maintenance mode, false to disable. |
875 */ |
876 */ |
876 public function maintenance_mode( $enable = false ) { |
877 public function maintenance_mode( $enable = false ) { |
877 global $wp_filesystem; |
878 global $wp_filesystem; |
944 * @return bool True if the lock was successfully released. False on failure. |
945 * @return bool True if the lock was successfully released. False on failure. |
945 */ |
946 */ |
946 public static function release_lock( $lock_name ) { |
947 public static function release_lock( $lock_name ) { |
947 return delete_option( $lock_name . '.lock' ); |
948 return delete_option( $lock_name . '.lock' ); |
948 } |
949 } |
949 |
|
950 } |
950 } |
951 |
951 |
952 /** Plugin_Upgrader class */ |
952 /** Plugin_Upgrader class */ |
953 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
953 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
954 |
954 |