3 * A File upgrader class for WordPress.
5 * This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes.
7 * @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions
10 * @subpackage Upgrader
15 * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file.
17 * @TODO More Detailed docs, for methods as well.
20 * @subpackage Upgrader
24 var $strings = array();
26 var $result = array();
28 function WP_Upgrader($skin = null) {
29 return $this->__construct($skin);
31 function __construct($skin = null) {
33 $this->skin = new WP_Upgrader_Skin();
39 $this->skin->set_upgrader($this);
40 $this->generic_strings();
43 function generic_strings() {
44 $this->strings['bad_request'] = __('Invalid Data provided.');
45 $this->strings['fs_unavailable'] = __('Could not access filesystem.');
46 $this->strings['fs_error'] = __('Filesystem error.');
47 $this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.');
48 $this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).');
49 $this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.');
50 $this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.');
51 /* translators: %s: directory name */
52 $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
54 $this->strings['download_failed'] = __('Download failed.');
55 $this->strings['installing_package'] = __('Installing the latest version…');
56 $this->strings['folder_exists'] = __('Destination folder already exists.');
57 $this->strings['mkdir_failed'] = __('Could not create directory.');
58 $this->strings['bad_package'] = __('Incompatible Archive.');
60 $this->strings['maintenance_start'] = __('Enabling Maintenance mode…');
61 $this->strings['maintenance_end'] = __('Disabling Maintenance mode…');
64 function fs_connect( $directories = array() ) {
65 global $wp_filesystem;
67 if ( false === ($credentials = $this->skin->request_filesystem_credentials()) )
70 if ( ! WP_Filesystem($credentials) ) {
72 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
73 $error = $wp_filesystem->errors;
74 $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again
78 if ( ! is_object($wp_filesystem) )
79 return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
81 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
82 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
84 foreach ( (array)$directories as $dir ) {
87 if ( ! $wp_filesystem->abspath() )
88 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
91 if ( ! $wp_filesystem->wp_content_dir() )
92 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
95 if ( ! $wp_filesystem->wp_plugins_dir() )
96 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
98 case WP_CONTENT_DIR . '/themes':
99 if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
100 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
103 if ( ! $wp_filesystem->find_folder($dir) )
104 return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
109 } //end fs_connect();
111 function download_package($package) {
113 if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
114 return $package; //must be a local file..
116 if ( empty($package) )
117 return new WP_Error('no_package', $this->strings['no_package']);
119 $this->skin->feedback('downloading_package', $package);
121 $download_file = download_url($package);
123 if ( is_wp_error($download_file) )
124 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
126 return $download_file;
129 function unpack_package($package, $delete_package = true) {
130 global $wp_filesystem;
132 $this->skin->feedback('unpack_package');
134 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
136 //Clean up contents of upgrade directory beforehand.
137 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
138 if ( !empty($upgrade_files) ) {
139 foreach ( $upgrade_files as $file )
140 $wp_filesystem->delete($upgrade_folder . $file['name'], true);
143 //We need a working directory
144 $working_dir = $upgrade_folder . basename($package, '.zip');
146 // Clean up working directory
147 if ( $wp_filesystem->is_dir($working_dir) )
148 $wp_filesystem->delete($working_dir, true);
150 // Unzip package to working directory
151 $result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice?
153 // Once extracted, delete the package if required.
154 if ( $delete_package )
157 if ( is_wp_error($result) ) {
158 $wp_filesystem->delete($working_dir, true);
165 function install_package($args = array()) {
166 global $wp_filesystem;
167 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
168 'clear_destination' => false, 'clear_working' => false,
169 'hook_extra' => array());
171 $args = wp_parse_args($args, $defaults);
174 @set_time_limit( 300 );
176 if ( empty($source) || empty($destination) )
177 return new WP_Error('bad_request', $this->strings['bad_request']);
179 $this->skin->feedback('installing_package');
181 $res = apply_filters('upgrader_pre_install', true, $hook_extra);
182 if ( is_wp_error($res) )
185 //Retain the Original source and destinations
186 $remote_source = $source;
187 $local_destination = $destination;
189 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
190 $remote_destination = $wp_filesystem->find_folder($local_destination);
192 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
193 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
194 $source = trailingslashit($source) . trailingslashit($source_files[0]);
195 elseif ( count($source_files) == 0 )
196 return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files?
197 //else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
199 //Hook ability to change the source file location..
200 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
201 if ( is_wp_error($source) )
204 //Has the source location changed? If so, we need a new source_files list.
205 if ( $source !== $remote_source )
206 $source_files = array_keys( $wp_filesystem->dirlist($source) );
208 //Protection against deleting files in any important base directories.
209 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
210 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
211 $destination = trailingslashit($destination) . trailingslashit(basename($source));
214 if ( $wp_filesystem->exists($remote_destination) ) {
215 if ( $clear_destination ) {
216 //We're going to clear the destination if theres something there
217 $this->skin->feedback('remove_old');
218 $removed = $wp_filesystem->delete($remote_destination, true);
219 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
221 if ( is_wp_error($removed) )
223 else if ( ! $removed )
224 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
226 //If we're not clearing the destination folder and something exists there allready, Bail.
227 //But first check to see if there are actually any files in the folder.
228 $_files = $wp_filesystem->dirlist($remote_destination);
229 if ( ! empty($_files) ) {
230 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
231 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
236 //Create destination if needed
237 if ( !$wp_filesystem->exists($remote_destination) )
238 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
239 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
241 // Copy new version of item into place.
242 $result = copy_dir($source, $remote_destination);
243 if ( is_wp_error($result) ) {
244 if ( $clear_working )
245 $wp_filesystem->delete($remote_source, true);
249 //Clear the Working folder?
250 if ( $clear_working )
251 $wp_filesystem->delete($remote_source, true);
253 $destination_name = basename( str_replace($local_destination, '', $destination) );
254 if ( '.' == $destination_name )
255 $destination_name = '';
257 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
259 $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
260 if ( is_wp_error($res) ) {
261 $this->result = $res;
265 //Bombard the calling function will all the info which we've just used.
266 return $this->result;
269 function run($options) {
271 $defaults = array( 'package' => '', //Please always pass this.
272 'destination' => '', //And this
273 'clear_destination' => false,
274 'clear_working' => true,
276 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
279 $options = wp_parse_args($options, $defaults);
282 //Connect to the Filesystem first.
283 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
284 if ( ! $res ) //Mainly for non-connected filesystem.
287 if ( is_wp_error($res) ) {
288 $this->skin->error($res);
292 if ( !$is_multi ) // call $this->header separately if running multiple times
293 $this->skin->header();
295 $this->skin->before();
297 //Download the package (Note, This just returns the filename of the file if the package is a local file)
298 $download = $this->download_package( $package );
299 if ( is_wp_error($download) ) {
300 $this->skin->error($download);
301 $this->skin->after();
305 //Unzip's the file into a temporary directory
306 $working_dir = $this->unpack_package( $download );
307 if ( is_wp_error($working_dir) ) {
308 $this->skin->error($working_dir);
309 $this->skin->after();
313 //With the given options, this installs it to the destination directory.
314 $result = $this->install_package( array(
315 'source' => $working_dir,
316 'destination' => $destination,
317 'clear_destination' => $clear_destination,
318 'clear_working' => $clear_working,
319 'hook_extra' => $hook_extra
321 $this->skin->set_result($result);
322 if ( is_wp_error($result) ) {
323 $this->skin->error($result);
324 $this->skin->feedback('process_failed');
327 $this->skin->feedback('process_success');
329 $this->skin->after();
332 $this->skin->footer();
337 function maintenance_mode($enable = false) {
338 global $wp_filesystem;
339 $file = $wp_filesystem->abspath() . '.maintenance';
341 $this->skin->feedback('maintenance_start');
342 // Create maintenance file to signal that we are upgrading
343 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
344 $wp_filesystem->delete($file);
345 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
346 } else if ( !$enable && $wp_filesystem->exists($file) ) {
347 $this->skin->feedback('maintenance_end');
348 $wp_filesystem->delete($file);
355 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
357 * @TODO More Detailed docs, for methods as well.
360 * @subpackage Upgrader
363 class Plugin_Upgrader extends WP_Upgrader {
367 var $show_before = '';
369 function upgrade_strings() {
370 $this->strings['up_to_date'] = __('The plugin is at the latest version.');
371 $this->strings['no_package'] = __('Update package not available.');
372 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
373 $this->strings['unpack_package'] = __('Unpacking the update…');
374 $this->strings['deactivate_plugin'] = __('Deactivating the plugin…');
375 $this->strings['remove_old'] = __('Removing the old version of the plugin…');
376 $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
377 $this->strings['process_failed'] = __('Plugin update failed.');
378 $this->strings['process_success'] = __('Plugin updated successfully.');
381 function install_strings() {
382 $this->strings['no_package'] = __('Install package not available.');
383 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
384 $this->strings['unpack_package'] = __('Unpacking the package…');
385 $this->strings['installing_package'] = __('Installing the plugin…');
386 $this->strings['process_failed'] = __('Plugin install failed.');
387 $this->strings['process_success'] = __('Plugin installed successfully.');
390 function install($package) {
393 $this->install_strings();
396 'package' => $package,
397 'destination' => WP_PLUGIN_DIR,
398 'clear_destination' => false, //Do not overwrite files.
399 'clear_working' => true,
400 'hook_extra' => array()
403 // Force refresh of plugin update information
404 delete_site_transient('update_plugins');
408 function upgrade($plugin) {
411 $this->upgrade_strings();
413 $current = get_site_transient( 'update_plugins' );
414 if ( !isset( $current->response[ $plugin ] ) ) {
415 $this->skin->before();
416 $this->skin->set_result(false);
417 $this->skin->error('up_to_date');
418 $this->skin->after();
422 // Get the URL to the zip file
423 $r = $current->response[ $plugin ];
425 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
426 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
427 //'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
430 'package' => $r->package,
431 'destination' => WP_PLUGIN_DIR,
432 'clear_destination' => true,
433 'clear_working' => true,
434 'hook_extra' => array(
439 // Cleanup our hooks, incase something else does a upgrade on this connection.
440 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
441 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
443 if ( ! $this->result || is_wp_error($this->result) )
444 return $this->result;
446 // Force refresh of plugin update information
447 delete_site_transient('update_plugins');
450 function bulk_upgrade($plugins) {
454 $this->upgrade_strings();
456 $current = get_site_transient( 'update_plugins' );
458 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
460 $this->skin->header();
462 // Connect to the Filesystem first.
463 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
465 $this->skin->footer();
469 $this->skin->bulk_header();
471 // Only start maintenance mode if running in Multisite OR the plugin is in use
472 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
473 foreach ( $plugins as $plugin )
474 $maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available
476 $this->maintenance_mode(true);
480 $this->update_count = count($plugins);
481 $this->update_current = 0;
482 foreach ( $plugins as $plugin ) {
483 $this->update_current++;
484 $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
486 if ( !isset( $current->response[ $plugin ] ) ) {
487 $this->skin->set_result(false);
488 $this->skin->before();
489 $this->skin->error('up_to_date');
490 $this->skin->after();
491 $results[$plugin] = false;
495 // Get the URL to the zip file
496 $r = $current->response[ $plugin ];
498 $this->skin->plugin_active = is_plugin_active($plugin);
500 $result = $this->run(array(
501 'package' => $r->package,
502 'destination' => WP_PLUGIN_DIR,
503 'clear_destination' => true,
504 'clear_working' => true,
506 'hook_extra' => array(
511 $results[$plugin] = $this->result;
513 // Prevent credentials auth screen from displaying multiple times
514 if ( false === $result )
516 } //end foreach $plugins
518 $this->maintenance_mode(false);
520 $this->skin->bulk_footer();
522 $this->skin->footer();
524 // Cleanup our hooks, incase something else does a upgrade on this connection.
525 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
527 // Force refresh of plugin update information
528 delete_site_transient('update_plugins');
533 //return plugin info.
534 function plugin_info() {
535 if ( ! is_array($this->result) )
537 if ( empty($this->result['destination_name']) )
540 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
541 if ( empty($plugin) )
544 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
546 return $this->result['destination_name'] . '/' . $pluginfiles[0];
549 //Hooked to pre_install
550 function deactivate_plugin_before_upgrade($return, $plugin) {
552 if ( is_wp_error($return) ) //Bypass.
555 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
556 if ( empty($plugin) )
557 return new WP_Error('bad_request', $this->strings['bad_request']);
559 if ( is_plugin_active($plugin) ) {
560 $this->skin->feedback('deactivate_plugin');
561 //Deactivate the plugin silently, Prevent deactivation hooks from running.
562 deactivate_plugins($plugin, true);
566 //Hooked to upgrade_clear_destination
567 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
568 global $wp_filesystem;
570 if ( is_wp_error($removed) )
571 return $removed; //Pass errors through.
573 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
574 if ( empty($plugin) )
575 return new WP_Error('bad_request', $this->strings['bad_request']);
577 $plugins_dir = $wp_filesystem->wp_plugins_dir();
578 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
580 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
583 // If plugin is in its own directory, recursively delete the directory.
584 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
585 $deleted = $wp_filesystem->delete($this_plugin_dir, true);
587 $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
590 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
597 * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
599 * @TODO More Detailed docs, for methods as well.
602 * @subpackage Upgrader
605 class Theme_Upgrader extends WP_Upgrader {
609 function upgrade_strings() {
610 $this->strings['up_to_date'] = __('The theme is at the latest version.');
611 $this->strings['no_package'] = __('Update package not available.');
612 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
613 $this->strings['unpack_package'] = __('Unpacking the update…');
614 $this->strings['remove_old'] = __('Removing the old version of the theme…');
615 $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
616 $this->strings['process_failed'] = __('Theme update failed.');
617 $this->strings['process_success'] = __('Theme updated successfully.');
620 function install_strings() {
621 $this->strings['no_package'] = __('Install package not available.');
622 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
623 $this->strings['unpack_package'] = __('Unpacking the package…');
624 $this->strings['installing_package'] = __('Installing the theme…');
625 $this->strings['process_failed'] = __('Theme install failed.');
626 $this->strings['process_success'] = __('Theme installed successfully.');
629 function install($package) {
632 $this->install_strings();
635 'package' => $package,
636 'destination' => WP_CONTENT_DIR . '/themes',
637 'clear_destination' => false, //Do not overwrite files.
638 'clear_working' => true
641 $this->run($options);
643 if ( ! $this->result || is_wp_error($this->result) )
644 return $this->result;
646 // Force refresh of theme update information
647 delete_site_transient('update_themes');
649 if ( empty($result['destination_name']) )
652 return $result['destination_name'];
655 function upgrade($theme) {
658 $this->upgrade_strings();
660 // Is an update available?
661 $current = get_site_transient( 'update_themes' );
662 if ( !isset( $current->response[ $theme ] ) ) {
663 $this->skin->before();
664 $this->skin->set_result(false);
665 $this->skin->error('up_to_date');
666 $this->skin->after();
670 $r = $current->response[ $theme ];
672 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
673 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
674 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
677 'package' => $r['package'],
678 'destination' => WP_CONTENT_DIR . '/themes',
679 'clear_destination' => true,
680 'clear_working' => true,
681 'hook_extra' => array(
686 $this->run($options);
688 if ( ! $this->result || is_wp_error($this->result) )
689 return $this->result;
691 // Force refresh of theme update information
692 delete_site_transient('update_themes');
697 function bulk_upgrade($themes) {
701 $this->upgrade_strings();
703 $current = get_site_transient( 'update_themes' );
705 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
706 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
707 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
709 $this->skin->header();
711 // Connect to the Filesystem first.
712 $res = $this->fs_connect( array(WP_CONTENT_DIR) );
714 $this->skin->footer();
718 $this->skin->bulk_header();
720 // Only start maintenance mode if running in Multisite OR the theme is in use
721 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
722 foreach ( $themes as $theme )
723 $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
725 $this->maintenance_mode(true);
729 $this->update_count = count($themes);
730 $this->update_current = 0;
731 foreach ( $themes as $theme ) {
732 $this->update_current++;
734 if ( !isset( $current->response[ $theme ] ) ) {
735 $this->skin->set_result(false);
736 $this->skin->before();
737 $this->skin->error('up_to_date');
738 $this->skin->after();
739 $results[$theme] = false;
743 $this->skin->theme_info = $this->theme_info($theme);
745 // Get the URL to the zip file
746 $r = $current->response[ $theme ];
749 'package' => $r['package'],
750 'destination' => WP_CONTENT_DIR . '/themes',
751 'clear_destination' => true,
752 'clear_working' => true,
753 'hook_extra' => array(
758 $result = $this->run($options);
760 $results[$theme] = $this->result;
762 // Prevent credentials auth screen from displaying multiple times
763 if ( false === $result )
765 } //end foreach $plugins
767 $this->maintenance_mode(false);
769 $this->skin->bulk_footer();
771 $this->skin->footer();
773 // Cleanup our hooks, incase something else does a upgrade on this connection.
774 remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
775 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
776 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
778 // Force refresh of theme update information
779 delete_site_transient('update_themes');
784 function current_before($return, $theme) {
786 if ( is_wp_error($return) )
789 $theme = isset($theme['theme']) ? $theme['theme'] : '';
791 if ( $theme != get_stylesheet() ) //If not current
793 //Change to maintenance mode now.
795 $this->maintenance_mode(true);
799 function current_after($return, $theme) {
800 if ( is_wp_error($return) )
803 $theme = isset($theme['theme']) ? $theme['theme'] : '';
805 if ( $theme != get_stylesheet() ) //If not current
808 //Ensure stylesheet name hasnt changed after the upgrade:
809 // @TODO: Note, This doesnt handle the Template changing, or the Template name changing.
810 if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
811 $theme_info = $this->theme_info();
812 $stylesheet = $this->result['destination_name'];
813 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
814 switch_theme($template, $stylesheet, true);
817 //Time to remove maintenance mode
819 $this->maintenance_mode(false);
823 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
824 global $wp_filesystem;
826 $theme = isset($theme['theme']) ? $theme['theme'] : '';
828 if ( is_wp_error($removed) || empty($theme) )
829 return $removed; //Pass errors through.
831 $themes_dir = $wp_filesystem->wp_themes_dir();
832 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
833 if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
838 function theme_info($theme = null) {
840 if ( empty($theme) ) {
841 if ( !empty($this->result['destination_name']) )
842 $theme = $this->result['destination_name'];
846 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
852 * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
854 * @TODO More Detailed docs, for methods as well.
857 * @subpackage Upgrader
860 class Core_Upgrader extends WP_Upgrader {
862 function upgrade_strings() {
863 $this->strings['up_to_date'] = __('WordPress is at the latest version.');
864 $this->strings['no_package'] = __('Update package not available.');
865 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
866 $this->strings['unpack_package'] = __('Unpacking the update…');
867 $this->strings['copy_failed'] = __('Could not copy files.');
870 function upgrade($current) {
871 global $wp_filesystem;
874 $this->upgrade_strings();
876 if ( !empty($feedback) )
877 add_filter('update_feedback', $feedback);
879 // Is an update available?
880 if ( !isset( $current->response ) || $current->response == 'latest' )
881 return new WP_Error('up_to_date', $this->strings['up_to_date']);
883 $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
884 if ( is_wp_error($res) )
887 $wp_dir = trailingslashit($wp_filesystem->abspath());
889 $download = $this->download_package( $current->package );
890 if ( is_wp_error($download) )
893 $working_dir = $this->unpack_package( $download );
894 if ( is_wp_error($working_dir) )
897 // Copy update-core.php from the new version into place.
898 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
899 $wp_filesystem->delete($working_dir, true);
900 return new WP_Error('copy_failed', $this->strings['copy_failed']);
902 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
904 require(ABSPATH . 'wp-admin/includes/update-core.php');
906 return update_core($working_dir, $wp_dir);
912 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
914 * @TODO More Detailed docs, for methods as well.
917 * @subpackage Upgrader
920 class WP_Upgrader_Skin {
923 var $done_header = false;
926 function WP_Upgrader_Skin($args = array()) {
927 return $this->__construct($args);
929 function __construct($args = array()) {
930 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
931 $this->options = wp_parse_args($args, $defaults);
934 function set_upgrader(&$upgrader) {
935 if ( is_object($upgrader) )
936 $this->upgrader =& $upgrader;
937 $this->add_strings();
940 function add_strings() {
943 function set_result($result) {
944 $this->result = $result;
947 function request_filesystem_credentials($error = false) {
948 $url = $this->options['url'];
949 $context = $this->options['context'];
950 if ( !empty($this->options['nonce']) )
951 $url = wp_nonce_url($url, $this->options['nonce']);
952 return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
956 if ( $this->done_header )
958 $this->done_header = true;
959 echo '<div class="wrap">';
961 echo '<h2>' . $this->options['title'] . '</h2>';
967 function error($errors) {
968 if ( ! $this->done_header )
970 if ( is_string($errors) ) {
971 $this->feedback($errors);
972 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
973 foreach ( $errors->get_error_messages() as $message ) {
974 if ( $errors->get_error_data() )
975 $this->feedback($message . ' ' . $errors->get_error_data() );
977 $this->feedback($message);
982 function feedback($string) {
983 if ( isset( $this->upgrader->strings[$string] ) )
984 $string = $this->upgrader->strings[$string];
986 if ( strpos($string, '%') !== false ) {
987 $args = func_get_args();
988 $args = array_splice($args, 1);
990 $string = vsprintf($string, $args);
992 if ( empty($string) )
994 show_message($string);
1002 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1004 * @TODO More Detailed docs, for methods as well.
1006 * @package WordPress
1007 * @subpackage Upgrader
1010 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
1012 var $plugin_active = false;
1013 var $plugin_network_active = false;
1015 function Plugin_Upgrader_Skin($args = array()) {
1016 return $this->__construct($args);
1019 function __construct($args = array()) {
1020 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
1021 $args = wp_parse_args($args, $defaults);
1023 $this->plugin = $args['plugin'];
1025 $this->plugin_active = is_plugin_active( $this->plugin );
1026 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
1028 parent::__construct($args);
1032 $this->plugin = $this->upgrader->plugin_info();
1033 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
1034 show_message(__('Reactivating the plugin…'));
1035 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>';
1038 $update_actions = array(
1039 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
1040 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
1042 if ( $this->plugin_active )
1043 unset( $update_actions['activate_plugin'] );
1044 if ( ! $this->result || is_wp_error($this->result) )
1045 unset( $update_actions['activate_plugin'] );
1047 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
1048 if ( ! empty($update_actions) )
1049 $this->feedback(implode(' | ', (array)$update_actions));
1053 if ( $this->upgrader->show_before ) {
1054 echo $this->upgrader->show_before;
1055 $this->upgrader->show_before = '';
1061 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1063 * @package WordPress
1064 * @subpackage Upgrader
1067 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
1068 var $in_loop = false;
1071 function Bulk_Upgrader_Skin($args = array()) {
1072 return $this->__construct($args);
1075 function __construct($args = array()) {
1076 $defaults = array( 'url' => '', 'nonce' => '' );
1077 $args = wp_parse_args($args, $defaults);
1079 parent::__construct($args);
1082 function add_strings() {
1083 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
1084 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.');
1085 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
1086 $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>';
1087 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
1090 function feedback($string) {
1091 if ( isset( $this->upgrader->strings[$string] ) )
1092 $string = $this->upgrader->strings[$string];
1094 if ( strpos($string, '%') !== false ) {
1095 $args = func_get_args();
1096 $args = array_splice($args, 1);
1097 if ( !empty($args) )
1098 $string = vsprintf($string, $args);
1100 if ( empty($string) )
1102 if ( $this->in_loop )
1103 echo "$string<br />\n";
1105 echo "<p>$string</p>\n";
1109 // Nothing, This will be displayed within a iframe.
1113 // Nothing, This will be displayed within a iframe.
1115 function error($error) {
1116 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
1117 $this->error = $this->upgrader->strings[$error];
1119 if ( is_wp_error($error) ) {
1120 foreach ( $error->get_error_messages() as $emessage ) {
1121 if ( $error->get_error_data() )
1122 $messages[] = $emessage . ' ' . $error->get_error_data();
1124 $messages[] = $emessage;
1126 $this->error = implode(', ', $messages);
1128 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1131 function bulk_header() {
1132 $this->feedback('skin_upgrade_start');
1135 function bulk_footer() {
1136 $this->feedback('skin_upgrade_end');
1139 function before($title = '') {
1140 $this->in_loop = true;
1141 printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <img alt="" src="' . admin_url( 'images/wpspin_light.gif' ) . '" class="hidden waiting-' . $this->upgrader->update_current . '" style="vertical-align:middle;" /></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count);
1142 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1143 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
1144 $this->flush_output();
1147 function after($title = '') {
1149 if ( $this->error || ! $this->result ) {
1151 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
1153 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
1155 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1157 if ( !empty($this->result) && !is_wp_error($this->result) ) {
1158 echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
1159 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1163 $this->flush_output();
1167 $this->in_loop = false;
1168 $this->error = false;
1171 function flush_output() {
1172 wp_ob_end_flush_all();
1177 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
1178 var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
1179 function Plugin_Upgrader_Skin($args = array()) {
1180 parent::__construct($args);
1183 function add_strings() {
1184 parent::add_strings();
1185 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
1189 parent::before($this->plugin_info['Title']);
1193 parent::after($this->plugin_info['Title']);
1195 function bulk_footer() {
1196 parent::bulk_footer();
1197 $update_actions = array(
1198 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
1199 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
1202 $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
1203 if ( ! empty($update_actions) )
1204 $this->feedback(implode(' | ', (array)$update_actions));
1208 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
1209 var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
1210 function Theme_Upgrader_Skin($args = array()) {
1211 parent::__construct($args);
1214 function add_strings() {
1215 parent::add_strings();
1216 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
1220 parent::before($this->theme_info['Name']);
1224 parent::after($this->theme_info['Name']);
1226 function bulk_footer() {
1227 parent::bulk_footer();
1228 $update_actions = array(
1229 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
1230 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
1233 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
1234 if ( ! empty($update_actions) )
1235 $this->feedback(implode(' | ', (array)$update_actions));
1240 * Plugin Installer Skin for WordPress Plugin Installer.
1242 * @TODO More Detailed docs, for methods as well.
1244 * @package WordPress
1245 * @subpackage Upgrader
1248 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
1252 function Plugin_Installer_Skin($args = array()) {
1253 return $this->__construct($args);
1256 function __construct($args = array()) {
1257 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
1258 $args = wp_parse_args($args, $defaults);
1260 $this->type = $args['type'];
1261 $this->api = isset($args['api']) ? $args['api'] : array();
1263 parent::__construct($args);
1267 if ( !empty($this->api) )
1268 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
1273 $plugin_file = $this->upgrader->plugin_info();
1275 $install_actions = array();
1277 $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
1279 if ( 'import' == $from )
1280 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>';
1282 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
1284 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
1285 $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
1286 unset( $install_actions['activate_plugin'] );
1289 if ( 'import' == $from )
1290 $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
1291 else if ( $this->type == 'web' )
1292 $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>';
1294 $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
1297 if ( ! $this->result || is_wp_error($this->result) ) {
1298 unset( $install_actions['activate_plugin'] );
1299 unset( $install_actions['network_activate'] );
1301 $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
1302 if ( ! empty($install_actions) )
1303 $this->feedback(implode(' | ', (array)$install_actions));
1308 * Theme Installer Skin for the WordPress Theme Installer.
1310 * @TODO More Detailed docs, for methods as well.
1312 * @package WordPress
1313 * @subpackage Upgrader
1316 class Theme_Installer_Skin extends WP_Upgrader_Skin {
1320 function Theme_Installer_Skin($args = array()) {
1321 return $this->__construct($args);
1324 function __construct($args = array()) {
1325 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
1326 $args = wp_parse_args($args, $defaults);
1328 $this->type = $args['type'];
1329 $this->api = isset($args['api']) ? $args['api'] : array();
1331 parent::__construct($args);
1335 if ( !empty($this->api) ) {
1336 /* translators: 1: theme name, 2: version */
1337 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
1342 if ( empty($this->upgrader->result['destination_name']) )
1345 $theme_info = $this->upgrader->theme_info();
1346 if ( empty($theme_info) )
1348 $name = $theme_info['Name'];
1349 $stylesheet = $this->upgrader->result['destination_name'];
1350 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1352 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1353 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1355 $install_actions = array(
1356 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>',
1357 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'
1360 if ( $this->type == 'web' )
1361 $install_actions['themes_page'] = '<a href="' . self_admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>';
1363 $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
1365 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() )
1366 unset( $install_actions['activate'], $install_actions['preview'] );
1368 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
1369 if ( ! empty($install_actions) )
1370 $this->feedback(implode(' | ', (array)$install_actions));
1375 * Theme Upgrader Skin for WordPress Theme Upgrades.
1377 * @TODO More Detailed docs, for methods as well.
1379 * @package WordPress
1380 * @subpackage Upgrader
1383 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
1386 function Theme_Upgrader_Skin($args = array()) {
1387 return $this->__construct($args);
1390 function __construct($args = array()) {
1391 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
1392 $args = wp_parse_args($args, $defaults);
1394 $this->theme = $args['theme'];
1396 parent::__construct($args);
1401 $update_actions = array();
1402 if ( !empty($this->upgrader->result['destination_name']) &&
1403 ($theme_info = $this->upgrader->theme_info()) &&
1404 !empty($theme_info) ) {
1406 $name = $theme_info['Name'];
1407 $stylesheet = $this->upgrader->result['destination_name'];
1408 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1410 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1411 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1413 $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>';
1414 $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
1416 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
1417 unset($update_actions['preview'], $update_actions['activate']);
1420 $update_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
1422 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
1423 if ( ! empty($update_actions) )
1424 $this->feedback(implode(' | ', (array)$update_actions));
1429 * Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if its a local file to the Upgrade/Installer functions.
1431 * @TODO More Detailed docs, for methods as well.
1433 * @package WordPress
1434 * @subpackage Upgrader
1437 class File_Upload_Upgrader {
1441 function File_Upload_Upgrader($form, $urlholder) {
1442 return $this->__construct($form, $urlholder);
1444 function __construct($form, $urlholder) {
1445 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
1446 wp_die($uploads['error']);
1448 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
1449 wp_die(__('Please select a file'));
1451 if ( !empty($_FILES) )
1452 $this->filename = $_FILES[$form]['name'];
1453 else if ( isset($_GET[$urlholder]) )
1454 $this->filename = $_GET[$urlholder];
1456 //Handle a newly uploaded file, Else assume its already been uploaded
1457 if ( !empty($_FILES) ) {
1458 $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename );
1459 $this->package = $uploads['basedir'] . '/' . $this->filename;
1461 // Move the file to the uploads dir
1462 if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
1463 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
1465 $this->package = $uploads['basedir'] . '/' . $this->filename;