WP_Upgrader::run() – Run an upgrade/installation.

You appear to be a bot. Output may be restricted

Description

Run an upgrade/installation.

Attempts to download the package (if it is not a local file), unpack it, and install it in the destination folder.

Usage

$array|false|WP_Error = WP_Upgrader::run( $options );

Parameters

$options
( array ) required – { Array or string of arguments for upgrading/installing a package.
$package
( string ) required – The full path or URI of the package to install. Default empty.
$destination
( string ) required – The full path to the destination folder. Default empty.
$clear_destination
( bool ) required – Whether to delete any files already in the destination folder. Default false.
$clear_working
( bool ) required – Whether to delete the files from the working directory after copying them to the destination. Default true.
$abort_if_destination_exists
( bool ) required – Whether to abort the installation if the destination folder already exists. When true, $clear_destination should be false. Default true.
$is_multi
( bool ) required – Whether this run is one of multiple upgrade/installation actions being performed in bulk. When true, the skin WP_Upgrader::header() and WP_Upgrader::footer() aren't called. Default false.
$hook_extra
( array ) required – Extra arguments to pass to the filter hooks called by WP_Upgrader::run(). }

Returns

array|false|WP_Error The result from self::install_package() on success, otherwise a WP_Error, or false if unable to connect to the filesystem.

Source

File name: wordpress/wp-admin/includes/class-wp-upgrader.php
Lines:

1 to 100 of 196
  public function run( $options ) {

    $defaults = array(
      'package'                     => '', // Please always pass this.
      'destination'                 => '', // ...and this.
      'clear_destination'           => false,
      'clear_working'               => true,
      'abort_if_destination_exists' => true, // Abort if the destination directory exists. Pass clear_destination as false please.
      'is_multi'                    => false,
      'hook_extra'                  => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
    );

    $options = wp_parse_args( $options, $defaults );

    
/**
 * Filters the package options before running an update.
 *
 * See also {@see 'upgrader_process_complete'}.
 *
 * @since 4.3.0
 *
 * @param array $options {
 *     Options used by the upgrader.
 *
 *     @type string $package                     Package for update.
 *     @type string $destination                 Update location.
 *     @type bool   $clear_destination           Clear the destination resource.
 *     @type bool   $clear_working               Clear the working resource.
 *     @type bool   $abort_if_destination_exists Abort if the Destination directory exists.
 *     @type bool   $is_multi                    Whether the upgrader is running multiple times.
 *     @type array  $hook_extra {
 *         Extra hook arguments.
 *
 *         @type string $action               Type of action. Default 'update'.
 *         @type string $type                 Type of update process. Accepts 'plugin', 'theme', or 'core'.
 *         @type bool   $bulk                 Whether the update process is a bulk update. Default true.
 *         @type string $plugin               Path to the plugin file relative to the plugins directory.
 *         @type string $theme                The stylesheet or template name of the theme.
 *         @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme',
 *                                            or 'core'.
 *         @type object $language_update      The language pack update offer.
 *     }
 * }
 */
    $options = apply_filters( 'upgrader_package_options', $options );

    if ( ! $options['is_multi'] ) { // Call $this->header separately if running multiple times.
      $this->skin->header();
    }

    // Connect to the filesystem first.
    $res = $this->WP_Upgrader::fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
    // Mainly for non-connected filesystem.
    if ( ! $res ) {
      if ( ! $options['is_multi'] ) {
        $this->skin->footer();
      }
      return false;
    }

    $this->skin->before();

    if ( is_wp_error( $res ) ) {
      $this->skin->error( $res );
      $this->skin->after();
      if ( ! $options['is_multi'] ) {
        $this->skin->footer();
      }
      return $res;
    }

    /*
		 * Download the package. Note: If the package is the full path
		 * to an existing local file, it will be returned untouched.
		 */
    $download = $this->WP_Upgrader::download_package( $options['package'], true, $options['hook_extra'] );

    // Allow for signature soft-fail.
    // WARNING: This may be removed in the future.
    if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {

      // Don't output the 'no signature could be found' failure message for now.
      if ( 'signature_verification_no_signature' !== $download->get_error_code() || WP_DEBUG ) {
        // Output the failure error as a normal feedback, and not as an error.
        $this->skin->feedback( $download->get_error_message() );

        // Report this failure back to WordPress.org for debugging purposes.
        wp_version_check(
          array(
            'signature_failure_code' => $download->get_error_code(),
            'signature_failure_data' => $download->get_error_data(),
          )
        );
      }

      // Pretend this error didn't happen.
      $download = $download->get_error_data( 'softfail-filename' );
    }

    if ( is_wp_error( $download ) ) {
 

 View on GitHub View on Trac