wp/wp-admin/includes/class-wp-upgrader.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   118 	 *
   118 	 *
   119 	 * @param WP_Upgrader_Skin $skin The upgrader skin to use. Default is a WP_Upgrader_Skin
   119 	 * @param WP_Upgrader_Skin $skin The upgrader skin to use. Default is a WP_Upgrader_Skin
   120 	 *                               instance.
   120 	 *                               instance.
   121 	 */
   121 	 */
   122 	public function __construct( $skin = null ) {
   122 	public function __construct( $skin = null ) {
   123 		if ( null == $skin ) {
   123 		if ( null === $skin ) {
   124 			$this->skin = new WP_Upgrader_Skin();
   124 			$this->skin = new WP_Upgrader_Skin();
   125 		} else {
   125 		} else {
   126 			$this->skin = $skin;
   126 			$this->skin = $skin;
   127 		}
   127 		}
   128 	}
   128 	}
   260 		 * @since 5.5.0 Added the `$hook_extra` parameter.
   260 		 * @since 5.5.0 Added the `$hook_extra` parameter.
   261 		 *
   261 		 *
   262 		 * @param bool        $reply      Whether to bail without returning the package.
   262 		 * @param bool        $reply      Whether to bail without returning the package.
   263 		 *                                Default false.
   263 		 *                                Default false.
   264 		 * @param string      $package    The package file name.
   264 		 * @param string      $package    The package file name.
   265 		 * @param WP_Upgrader $this       The WP_Upgrader instance.
   265 		 * @param WP_Upgrader $upgrader   The WP_Upgrader instance.
   266 		 * @param array       $hook_extra Extra arguments passed to hooked filters.
   266 		 * @param array       $hook_extra Extra arguments passed to hooked filters.
   267 		 */
   267 		 */
   268 		$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
   268 		$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
   269 		if ( false !== $reply ) {
   269 		if ( false !== $reply ) {
   270 			return $reply;
   270 			return $reply;
   342 
   342 
   343 		return $working_dir;
   343 		return $working_dir;
   344 	}
   344 	}
   345 
   345 
   346 	/**
   346 	/**
   347 	 * Flatten the results of WP_Filesystem::dirlist() for iterating over.
   347 	 * Flatten the results of WP_Filesystem_Base::dirlist() for iterating over.
   348 	 *
   348 	 *
   349 	 * @since 4.9.0
   349 	 * @since 4.9.0
   350 	 * @access protected
   350 	 * @access protected
   351 	 *
   351 	 *
   352 	 * @param array  $nested_files Array of files as returned by WP_Filesystem::dirlist().
   352 	 * @param array  $nested_files Array of files as returned by WP_Filesystem_Base::dirlist().
   353 	 * @param string $path         Relative path to prepend to child nodes. Optional.
   353 	 * @param string $path         Relative path to prepend to child nodes. Optional.
   354 	 * @return array A flattened array of the $nested_files specified.
   354 	 * @return array A flattened array of the $nested_files specified.
   355 	 */
   355 	 */
   356 	protected function flatten_dirlist( $nested_files, $path = '' ) {
   356 	protected function flatten_dirlist( $nested_files, $path = '' ) {
   357 		$files = array();
   357 		$files = array();
   502 
   502 
   503 		// Locate which directory to copy to the new folder. This is based on the actual folder holding the files.
   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] . '/' ) ) {
   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.
   505 			// Only one folder? Then we want its contents.
   506 			$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
   506 			$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
   507 		} elseif ( count( $source_files ) == 0 ) {
   507 		} elseif ( 0 === count( $source_files ) ) {
   508 			// There are no files?
   508 			// There are no files?
   509 			return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] );
   509 			return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] );
   510 		} else {
   510 		} else {
   511 			// It's only a single file, the upgrader will use the folder name of this file as the destination folder.
   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.
   512 			// Folder name is based on zip filename.
   519 		 * @since 2.8.0
   519 		 * @since 2.8.0
   520 		 * @since 4.4.0 The $hook_extra parameter became available.
   520 		 * @since 4.4.0 The $hook_extra parameter became available.
   521 		 *
   521 		 *
   522 		 * @param string      $source        File source location.
   522 		 * @param string      $source        File source location.
   523 		 * @param string      $remote_source Remote file source location.
   523 		 * @param string      $remote_source Remote file source location.
   524 		 * @param WP_Upgrader $this          WP_Upgrader instance.
   524 		 * @param WP_Upgrader $upgrader      WP_Upgrader instance.
   525 		 * @param array       $hook_extra    Extra arguments passed to hooked filters.
   525 		 * @param array       $hook_extra    Extra arguments passed to hooked filters.
   526 		 */
   526 		 */
   527 		$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
   527 		$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
   528 
   528 
   529 		if ( is_wp_error( $source ) ) {
   529 		if ( is_wp_error( $source ) ) {
   771 				$this->skin->footer();
   771 				$this->skin->footer();
   772 			}
   772 			}
   773 			return $download;
   773 			return $download;
   774 		}
   774 		}
   775 
   775 
   776 		$delete_package = ( $download != $options['package'] ); // Do not delete a "local" file.
   776 		$delete_package = ( $download !== $options['package'] ); // Do not delete a "local" file.
   777 
   777 
   778 		// Unzips the file into a temporary directory.
   778 		// Unzips the file into a temporary directory.
   779 		$working_dir = $this->unpack_package( $download, $delete_package );
   779 		$working_dir = $this->unpack_package( $download, $delete_package );
   780 		if ( is_wp_error( $working_dir ) ) {
   780 		if ( is_wp_error( $working_dir ) ) {
   781 			$this->skin->error( $working_dir );
   781 			$this->skin->error( $working_dir );
   795 				'abort_if_destination_exists' => $options['abort_if_destination_exists'],
   795 				'abort_if_destination_exists' => $options['abort_if_destination_exists'],
   796 				'clear_working'               => $options['clear_working'],
   796 				'clear_working'               => $options['clear_working'],
   797 				'hook_extra'                  => $options['hook_extra'],
   797 				'hook_extra'                  => $options['hook_extra'],
   798 			)
   798 			)
   799 		);
   799 		);
       
   800 
       
   801 		/**
       
   802 		 * Filters the result of WP_Upgrader::install_package().
       
   803 		 *
       
   804 		 * @since 5.7.0
       
   805 		 *
       
   806 		 * @param array|WP_Error $result     Result from WP_Upgrader::install_package().
       
   807 		 * @param array          $hook_extra Extra arguments passed to hooked filters.
       
   808 		 */
       
   809 		$result = apply_filters( 'upgrader_install_package_result', $result, $options['hook_extra'] );
   800 
   810 
   801 		$this->skin->set_result( $result );
   811 		$this->skin->set_result( $result );
   802 		if ( is_wp_error( $result ) ) {
   812 		if ( is_wp_error( $result ) ) {
   803 			$this->skin->error( $result );
   813 			$this->skin->error( $result );
   804 
   814