<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[28418] trunk/src/wp-admin/includes/class-wp-upgrader.php: Eliminate the use of `extract()` in `WP_Upgrader`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28418">28418</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-05-15 05:01:02 +0000 (Thu, 15 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Eliminate the use of `extract()` in `WP_Upgrader`.
        
See <a href="http://core.trac.wordpress.org/ticket/22400">#22400</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (28417 => 28418)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php        2014-05-15 04:30:32 UTC (rev 28417)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php   2014-05-15 05:01:02 UTC (rev 28418)
</span><span class="lines">@@ -190,15 +190,16 @@
</span><span class="cx">          );
</span><span class="cx"> 
</span><span class="cx">          $args = wp_parse_args($args, $defaults);
</span><del>-               extract($args);
</del><ins>+                $destination = $args['destination'];
+               $clear_destination = $args['clear_destination'];
</ins><span class="cx"> 
</span><span class="cx">          @set_time_limit( 300 );
</span><span class="cx"> 
</span><del>-               if ( empty($source) || empty($destination) )
-                       return new WP_Error('bad_request', $this->strings['bad_request']);
</del><ins>+                if ( empty( $source ) || empty( $destination ) ) {
+                       return new WP_Error( 'bad_request', $this->strings['bad_request'] );
+               }
+               $this->skin->feedback( 'installing_package' );
</ins><span class="cx"> 
</span><del>-               $this->skin->feedback('installing_package');
-
</del><span class="cx">           /**
</span><span class="cx">           * Filter the install response before the installation has started.
</span><span class="cx">           *
</span><span class="lines">@@ -211,24 +212,26 @@
</span><span class="cx">           * @param bool|WP_Error $response   Response.
</span><span class="cx">           * @param array         $hook_extra Extra arguments passed to hooked filters.
</span><span class="cx">           */
</span><del>-               $res = apply_filters( 'upgrader_pre_install', true, $hook_extra );
-               if ( is_wp_error($res) )
</del><ins>+                $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
+               if ( is_wp_error( $res ) ) {
</ins><span class="cx">                   return $res;
</span><ins>+               }
</ins><span class="cx"> 
</span><span class="cx">          //Retain the Original source and destinations
</span><del>-               $remote_source = $source;
</del><ins>+                $remote_source = $args['source'];
</ins><span class="cx">           $local_destination = $destination;
</span><span class="cx"> 
</span><del>-               $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
-               $remote_destination = $wp_filesystem->find_folder($local_destination);
</del><ins>+                $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
+               $remote_destination = $wp_filesystem->find_folder( $local_destination );
</ins><span class="cx"> 
</span><span class="cx">          //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
</span><del>-               if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
-                       $source = trailingslashit($source) . trailingslashit($source_files[0]);
-               elseif ( count($source_files) == 0 )
</del><ins>+                if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents.
+                       $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
+               } elseif ( count( $source_files ) == 0 ) {
</ins><span class="cx">                   return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
</span><del>-               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.
-                       $source = trailingslashit($source);
</del><ins>+                } 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.
+                       $source = trailingslashit( $args['source'] );
+               }
</ins><span class="cx"> 
</span><span class="cx">          /**
</span><span class="cx">           * Filter the source file location for the upgrade package.
</span><span class="lines">@@ -240,30 +243,33 @@
</span><span class="cx">           * @param WP_Upgrader $this          WP_Upgrader instance.
</span><span class="cx">           */
</span><span class="cx">          $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this );
</span><del>-               if ( is_wp_error($source) )
</del><ins>+                if ( is_wp_error( $source ) ) {
</ins><span class="cx">                   return $source;
</span><ins>+               }
</ins><span class="cx"> 
</span><span class="cx">          //Has the source location changed? If so, we need a new source_files list.
</span><del>-               if ( $source !== $remote_source )
-                       $source_files = array_keys( $wp_filesystem->dirlist($source) );
-
</del><ins>+                if ( $source !== $remote_source ) {
+                       $source_files = array_keys( $wp_filesystem->dirlist( $source ) );
+               }
</ins><span class="cx">           // Protection against deleting files in any important base directories.
</span><span class="cx">          // Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes)
</span><span class="cx">          // intending to copy the directory into the directory, whilst they pass the source as the actual files to copy.
</span><span class="cx">          $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
</span><del>-               if ( is_array( $wp_theme_directories ) )
</del><ins>+                if ( is_array( $wp_theme_directories ) ) {
</ins><span class="cx">                   $protected_directories = array_merge( $protected_directories, $wp_theme_directories );
</span><ins>+               }
</ins><span class="cx">           if ( in_array( $destination, $protected_directories ) ) {
</span><del>-                       $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
-                       $destination = trailingslashit($destination) . trailingslashit(basename($source));
</del><ins>+                        $remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
+                       $destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          if ( $clear_destination ) {
</span><span class="cx">                  //We're going to clear the destination if there's something there
</span><span class="cx">                  $this->skin->feedback('remove_old');
</span><span class="cx">                  $removed = true;
</span><del>-                       if ( $wp_filesystem->exists($remote_destination) )
-                               $removed = $wp_filesystem->delete($remote_destination, true);
</del><ins>+                        if ( $wp_filesystem->exists( $remote_destination ) ) {
+                               $removed = $wp_filesystem->delete( $remote_destination, true );
+                       }
</ins><span class="cx"> 
</span><span class="cx">                  /**
</span><span class="cx">                   * Filter whether the upgrader cleared the destination.
</span><span class="lines">@@ -275,13 +281,14 @@
</span><span class="cx">                   * @param string $remote_destination The remote package destination.
</span><span class="cx">                   * @param array  $hook_extra         Extra arguments passed to hooked filters.
</span><span class="cx">                   */
</span><del>-                       $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra );
</del><ins>+                        $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
</ins><span class="cx"> 
</span><del>-                       if ( is_wp_error($removed) )
</del><ins>+                        if ( is_wp_error($removed) ) {
</ins><span class="cx">                           return $removed;
</span><del>-                       else if ( ! $removed )
</del><ins>+                        } else if ( ! $removed ) {
</ins><span class="cx">                           return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
</span><del>-               } elseif ( $abort_if_destination_exists && $wp_filesystem->exists($remote_destination) ) {
</del><ins>+                        }
+               } elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination) ) {
</ins><span class="cx">                   //If we're not clearing the destination folder and something exists there already, Bail.
</span><span class="cx">                  //But first check to see if there are actually any files in the folder.
</span><span class="cx">                  $_files = $wp_filesystem->dirlist($remote_destination);
</span><span class="lines">@@ -292,25 +299,29 @@
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          //Create destination if needed
</span><del>-               if ( !$wp_filesystem->exists($remote_destination) )
-                       if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
</del><ins>+                if ( ! $wp_filesystem->exists( $remote_destination ) ) {
+                       if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
</ins><span class="cx">                           return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
</span><del>-
</del><ins>+                        }
+               }
</ins><span class="cx">           // Copy new version of item into place.
</span><span class="cx">          $result = copy_dir($source, $remote_destination);
</span><span class="cx">          if ( is_wp_error($result) ) {
</span><del>-                       if ( $clear_working )
-                               $wp_filesystem->delete($remote_source, true);
</del><ins>+                        if ( $args['clear_working'] ) {
+                               $wp_filesystem->delete( $remote_source, true );
+                       }
</ins><span class="cx">                   return $result;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          //Clear the Working folder?
</span><del>-               if ( $clear_working )
-                       $wp_filesystem->delete($remote_source, true);
</del><ins>+                if ( $args['clear_working'] ) {
+                       $wp_filesystem->delete( $remote_source, true );
+               }
</ins><span class="cx"> 
</span><span class="cx">          $destination_name = basename( str_replace($local_destination, '', $destination) );
</span><del>-               if ( '.' == $destination_name )
</del><ins>+                if ( '.' == $destination_name ) {
</ins><span class="cx">                   $destination_name = '';
</span><ins>+               }
</ins><span class="cx"> 
</span><span class="cx">          $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
</span><span class="cx"> 
</span><span class="lines">@@ -323,7 +334,7 @@
</span><span class="cx">           * @param array $hook_extra Extra arguments passed to hooked filters.
</span><span class="cx">           * @param array $result     Installation result data.
</span><span class="cx">           */
</span><del>-               $res = apply_filters( 'upgrader_post_install', true, $hook_extra, $this->result );
</del><ins>+                $res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
</ins><span class="cx"> 
</span><span class="cx">          if ( is_wp_error($res) ) {
</span><span class="cx">                  $this->result = $res;
</span><span class="lines">@@ -334,7 +345,7 @@
</span><span class="cx">          return $this->result;
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       function run($options) {
</del><ins>+        function run( $options ) {
</ins><span class="cx"> 
</span><span class="cx">          $defaults = array(
</span><span class="cx">                  'package' => '', // Please always pass this.
</span><span class="lines">@@ -346,18 +357,19 @@
</span><span class="cx">                  'hook_extra' => array() // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
</span><span class="cx">          );
</span><span class="cx"> 
</span><del>-               $options = wp_parse_args($options, $defaults);
-               extract($options);
</del><ins>+                $options = wp_parse_args( $options, $defaults );
</ins><span class="cx"> 
</span><del>-               if ( ! $is_multi ) // call $this->header separately if running multiple times
</del><ins>+                if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
</ins><span class="cx">                   $this->skin->header();
</span><ins>+               }
</ins><span class="cx"> 
</span><span class="cx">          // Connect to the Filesystem first.
</span><del>-               $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
</del><ins>+                $res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
</ins><span class="cx">           // Mainly for non-connected filesystem.
</span><span class="cx">          if ( ! $res ) {
</span><del>-                       if ( ! $is_multi )
</del><ins>+                        if ( ! $options['is_multi'] ) {
</ins><span class="cx">                           $this->skin->footer();
</span><ins>+                       }
</ins><span class="cx">                   return false;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="lines">@@ -366,41 +378,44 @@
</span><span class="cx">          if ( is_wp_error($res) ) {
</span><span class="cx">                  $this->skin->error($res);
</span><span class="cx">                  $this->skin->after();
</span><del>-                       if ( ! $is_multi )
</del><ins>+                        if ( ! $options['is_multi'] ) {
</ins><span class="cx">                           $this->skin->footer();
</span><ins>+                       }
</ins><span class="cx">                   return $res;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          //Download the package (Note, This just returns the filename of the file if the package is a local file)
</span><del>-               $download = $this->download_package( $package );
</del><ins>+                $download = $this->download_package( $options['package'] );
</ins><span class="cx">           if ( is_wp_error($download) ) {
</span><span class="cx">                  $this->skin->error($download);
</span><span class="cx">                  $this->skin->after();
</span><del>-                       if ( ! $is_multi )
</del><ins>+                        if ( ! $options['is_multi'] ) {
</ins><span class="cx">                           $this->skin->footer();
</span><ins>+                       }
</ins><span class="cx">                   return $download;
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               $delete_package = ($download != $package); // Do not delete a "local" file
</del><ins>+                $delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
</ins><span class="cx"> 
</span><span class="cx">          //Unzips the file into a temporary directory
</span><span class="cx">          $working_dir = $this->unpack_package( $download, $delete_package );
</span><span class="cx">          if ( is_wp_error($working_dir) ) {
</span><span class="cx">                  $this->skin->error($working_dir);
</span><span class="cx">                  $this->skin->after();
</span><del>-                       if ( ! $is_multi )
</del><ins>+                        if ( ! $options['is_multi'] ) {
</ins><span class="cx">                           $this->skin->footer();
</span><ins>+                       }
</ins><span class="cx">                   return $working_dir;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          //With the given options, this installs it to the destination directory.
</span><span class="cx">          $result = $this->install_package( array(
</span><span class="cx">                  'source' => $working_dir,
</span><del>-                       'destination' => $destination,
-                       'clear_destination' => $clear_destination,
-                       'abort_if_destination_exists' => $abort_if_destination_exists,
-                       'clear_working' => $clear_working,
-                       'hook_extra' => $hook_extra
</del><ins>+                        'destination' => $options['destination'],
+                       'clear_destination' => $options['clear_destination'],
+                       'abort_if_destination_exists' => $options['abort_if_destination_exists'],
+                       'clear_working' => $options['clear_working'],
+                       'hook_extra' => $options['hook_extra']
</ins><span class="cx">           ) );
</span><span class="cx"> 
</span><span class="cx">          $this->skin->set_result($result);
</span><span class="lines">@@ -414,10 +429,10 @@
</span><span class="cx"> 
</span><span class="cx">          $this->skin->after();
</span><span class="cx"> 
</span><del>-               if ( ! $is_multi ) {
</del><ins>+                if ( ! $options['is_multi'] ) {
</ins><span class="cx"> 
</span><span class="cx">                  /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
</span><del>-                       do_action( 'upgrader_process_complete', $this, $hook_extra );
</del><ins>+                        do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
</ins><span class="cx">                   $this->skin->footer();
</span><span class="cx">          }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>