WordPress.org

Make WordPress Core

Changeset 28418


Ignore:
Timestamp:
05/15/2014 05:01:02 AM (7 years ago)
Author:
wonderboymusic
Message:

Eliminate the use of extract() in WP_Upgrader.

See #22400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r28253 r28418  
    191191
    192192        $args = wp_parse_args($args, $defaults);
    193         extract($args);
     193        $destination = $args['destination'];
     194        $clear_destination = $args['clear_destination'];
    194195
    195196        @set_time_limit( 300 );
    196197
    197         if ( empty($source) || empty($destination) )
    198             return new WP_Error('bad_request', $this->strings['bad_request']);
    199 
    200         $this->skin->feedback('installing_package');
     198        if ( empty( $source ) || empty( $destination ) ) {
     199            return new WP_Error( 'bad_request', $this->strings['bad_request'] );
     200        }
     201        $this->skin->feedback( 'installing_package' );
    201202
    202203        /**
     
    212213         * @param array         $hook_extra Extra arguments passed to hooked filters.
    213214         */
    214         $res = apply_filters( 'upgrader_pre_install', true, $hook_extra );
    215         if ( is_wp_error($res) )
     215        $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
     216        if ( is_wp_error( $res ) ) {
    216217            return $res;
     218        }
    217219
    218220        //Retain the Original source and destinations
    219         $remote_source = $source;
     221        $remote_source = $args['source'];
    220222        $local_destination = $destination;
    221223
    222         $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
    223         $remote_destination = $wp_filesystem->find_folder($local_destination);
     224        $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
     225        $remote_destination = $wp_filesystem->find_folder( $local_destination );
    224226
    225227        //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
    226         if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
    227             $source = trailingslashit($source) . trailingslashit($source_files[0]);
    228         elseif ( count($source_files) == 0 )
     228        if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents.
     229            $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
     230        } elseif ( count( $source_files ) == 0 ) {
    229231            return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
    230         else //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
    231             $source = trailingslashit($source);
     232        } else { //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
     233            $source = trailingslashit( $args['source'] );
     234        }
    232235
    233236        /**
     
    241244         */
    242245        $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this );
    243         if ( is_wp_error($source) )
     246        if ( is_wp_error( $source ) ) {
    244247            return $source;
     248        }
    245249
    246250        //Has the source location changed? If so, we need a new source_files list.
    247         if ( $source !== $remote_source )
    248             $source_files = array_keys( $wp_filesystem->dirlist($source) );
    249 
     251        if ( $source !== $remote_source ) {
     252            $source_files = array_keys( $wp_filesystem->dirlist( $source ) );
     253        }
    250254        // Protection against deleting files in any important base directories.
    251255        // Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes)
    252256        // intending to copy the directory into the directory, whilst they pass the source as the actual files to copy.
    253257        $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
    254         if ( is_array( $wp_theme_directories ) )
     258        if ( is_array( $wp_theme_directories ) ) {
    255259            $protected_directories = array_merge( $protected_directories, $wp_theme_directories );
     260        }
    256261        if ( in_array( $destination, $protected_directories ) ) {
    257             $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
    258             $destination = trailingslashit($destination) . trailingslashit(basename($source));
     262            $remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
     263            $destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
    259264        }
    260265
     
    263268            $this->skin->feedback('remove_old');
    264269            $removed = true;
    265             if ( $wp_filesystem->exists($remote_destination) )
    266                 $removed = $wp_filesystem->delete($remote_destination, true);
     270            if ( $wp_filesystem->exists( $remote_destination ) ) {
     271                $removed = $wp_filesystem->delete( $remote_destination, true );
     272            }
    267273
    268274            /**
     
    276282             * @param array  $hook_extra         Extra arguments passed to hooked filters.
    277283             */
    278             $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra );
    279 
    280             if ( is_wp_error($removed) )
     284            $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
     285
     286            if ( is_wp_error($removed) ) {
    281287                return $removed;
    282             else if ( ! $removed )
     288            } else if ( ! $removed ) {
    283289                return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
    284         } elseif ( $abort_if_destination_exists && $wp_filesystem->exists($remote_destination) ) {
     290            }
     291        } elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination) ) {
    285292            //If we're not clearing the destination folder and something exists there already, Bail.
    286293            //But first check to see if there are actually any files in the folder.
     
    293300
    294301        //Create destination if needed
    295         if ( !$wp_filesystem->exists($remote_destination) )
    296             if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
     302        if ( ! $wp_filesystem->exists( $remote_destination ) ) {
     303            if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
    297304                return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
    298 
     305            }
     306        }
    299307        // Copy new version of item into place.
    300308        $result = copy_dir($source, $remote_destination);
    301309        if ( is_wp_error($result) ) {
    302             if ( $clear_working )
    303                 $wp_filesystem->delete($remote_source, true);
     310            if ( $args['clear_working'] ) {
     311                $wp_filesystem->delete( $remote_source, true );
     312            }
    304313            return $result;
    305314        }
    306315
    307316        //Clear the Working folder?
    308         if ( $clear_working )
    309             $wp_filesystem->delete($remote_source, true);
     317        if ( $args['clear_working'] ) {
     318            $wp_filesystem->delete( $remote_source, true );
     319        }
    310320
    311321        $destination_name = basename( str_replace($local_destination, '', $destination) );
    312         if ( '.' == $destination_name )
     322        if ( '.' == $destination_name ) {
    313323            $destination_name = '';
     324        }
    314325
    315326        $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
     
    324335         * @param array $result     Installation result data.
    325336         */
    326         $res = apply_filters( 'upgrader_post_install', true, $hook_extra, $this->result );
     337        $res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
    327338
    328339        if ( is_wp_error($res) ) {
     
    335346    }
    336347
    337     function run($options) {
     348    function run( $options ) {
    338349
    339350        $defaults = array(
     
    347358        );
    348359
    349         $options = wp_parse_args($options, $defaults);
    350         extract($options);
    351 
    352         if ( ! $is_multi ) // call $this->header separately if running multiple times
     360        $options = wp_parse_args( $options, $defaults );
     361
     362        if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
    353363            $this->skin->header();
     364        }
    354365
    355366        // Connect to the Filesystem first.
    356         $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
     367        $res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
    357368        // Mainly for non-connected filesystem.
    358369        if ( ! $res ) {
    359             if ( ! $is_multi )
     370            if ( ! $options['is_multi'] ) {
    360371                $this->skin->footer();
     372            }
    361373            return false;
    362374        }
     
    367379            $this->skin->error($res);
    368380            $this->skin->after();
    369             if ( ! $is_multi )
     381            if ( ! $options['is_multi'] ) {
    370382                $this->skin->footer();
     383            }
    371384            return $res;
    372385        }
    373386
    374387        //Download the package (Note, This just returns the filename of the file if the package is a local file)
    375         $download = $this->download_package( $package );
     388        $download = $this->download_package( $options['package'] );
    376389        if ( is_wp_error($download) ) {
    377390            $this->skin->error($download);
    378391            $this->skin->after();
    379             if ( ! $is_multi )
     392            if ( ! $options['is_multi'] ) {
    380393                $this->skin->footer();
     394            }
    381395            return $download;
    382396        }
    383397
    384         $delete_package = ($download != $package); // Do not delete a "local" file
     398        $delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
    385399
    386400        //Unzips the file into a temporary directory
     
    389403            $this->skin->error($working_dir);
    390404            $this->skin->after();
    391             if ( ! $is_multi )
     405            if ( ! $options['is_multi'] ) {
    392406                $this->skin->footer();
     407            }
    393408            return $working_dir;
    394409        }
     
    397412        $result = $this->install_package( array(
    398413            'source' => $working_dir,
    399             'destination' => $destination,
    400             'clear_destination' => $clear_destination,
    401             'abort_if_destination_exists' => $abort_if_destination_exists,
    402             'clear_working' => $clear_working,
    403             'hook_extra' => $hook_extra
     414            'destination' => $options['destination'],
     415            'clear_destination' => $options['clear_destination'],
     416            'abort_if_destination_exists' => $options['abort_if_destination_exists'],
     417            'clear_working' => $options['clear_working'],
     418            'hook_extra' => $options['hook_extra']
    404419        ) );
    405420
     
    415430        $this->skin->after();
    416431
    417         if ( ! $is_multi ) {
     432        if ( ! $options['is_multi'] ) {
    418433
    419434            /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
    420             do_action( 'upgrader_process_complete', $this, $hook_extra );
     435            do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
    421436            $this->skin->footer();
    422437        }
Note: See TracChangeset for help on using the changeset viewer.