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 __construct($skin = null) {
30 $this->skin = new WP_Upgrader_Skin();
36 $this->skin->set_upgrader($this);
37 $this->generic_strings();
40 function generic_strings() {
41 $this->strings['bad_request'] = __('Invalid Data provided.');
42 $this->strings['fs_unavailable'] = __('Could not access filesystem.');
43 $this->strings['fs_error'] = __('Filesystem error.');
44 $this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.');
45 $this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).');
46 $this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.');
47 $this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.');
48 /* translators: %s: directory name */
49 $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
51 $this->strings['download_failed'] = __('Download failed.');
52 $this->strings['installing_package'] = __('Installing the latest version…');
53 $this->strings['folder_exists'] = __('Destination folder already exists.');
54 $this->strings['mkdir_failed'] = __('Could not create directory.');
55 $this->strings['bad_package'] = __('Incompatible Archive.');
57 $this->strings['maintenance_start'] = __('Enabling Maintenance mode…');
58 $this->strings['maintenance_end'] = __('Disabling Maintenance mode…');
61 function fs_connect( $directories = array() ) {
62 global $wp_filesystem;
64 if ( false === ($credentials = $this->skin->request_filesystem_credentials()) )
67 if ( ! WP_Filesystem($credentials) ) {
69 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
70 $error = $wp_filesystem->errors;
71 $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again
75 if ( ! is_object($wp_filesystem) )
76 return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
78 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
79 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
81 foreach ( (array)$directories as $dir ) {
84 if ( ! $wp_filesystem->abspath() )
85 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
88 if ( ! $wp_filesystem->wp_content_dir() )
89 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
92 if ( ! $wp_filesystem->wp_plugins_dir() )
93 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
95 case WP_CONTENT_DIR . '/themes':
96 if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
97 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
100 if ( ! $wp_filesystem->find_folder($dir) )
101 return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
106 } //end fs_connect();
108 function download_package($package) {
110 if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
111 return $package; //must be a local file..
113 if ( empty($package) )
114 return new WP_Error('no_package', $this->strings['no_package']);
116 $this->skin->feedback('downloading_package', $package);
118 $download_file = download_url($package);
120 if ( is_wp_error($download_file) )
121 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
123 return $download_file;
126 function unpack_package($package, $delete_package = true) {
127 global $wp_filesystem;
129 $this->skin->feedback('unpack_package');
131 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
133 //Clean up contents of upgrade directory beforehand.
134 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
135 if ( !empty($upgrade_files) ) {
136 foreach ( $upgrade_files as $file )
137 $wp_filesystem->delete($upgrade_folder . $file['name'], true);
140 //We need a working directory
141 $working_dir = $upgrade_folder . basename($package, '.zip');
143 // Clean up working directory
144 if ( $wp_filesystem->is_dir($working_dir) )
145 $wp_filesystem->delete($working_dir, true);
147 // Unzip package to working directory
148 $result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice?
150 // Once extracted, delete the package if required.
151 if ( $delete_package )
154 if ( is_wp_error($result) ) {
155 $wp_filesystem->delete($working_dir, true);
162 function install_package($args = array()) {
163 global $wp_filesystem;
164 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
165 'clear_destination' => false, 'clear_working' => false,
166 'hook_extra' => array());
168 $args = wp_parse_args($args, $defaults);
171 @set_time_limit( 300 );
173 if ( empty($source) || empty($destination) )
174 return new WP_Error('bad_request', $this->strings['bad_request']);
176 $this->skin->feedback('installing_package');
178 $res = apply_filters('upgrader_pre_install', true, $hook_extra);
179 if ( is_wp_error($res) )
182 //Retain the Original source and destinations
183 $remote_source = $source;
184 $local_destination = $destination;
186 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
187 $remote_destination = $wp_filesystem->find_folder($local_destination);
189 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
190 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
191 $source = trailingslashit($source) . trailingslashit($source_files[0]);
192 elseif ( count($source_files) == 0 )
193 return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files?
194 //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.
196 //Hook ability to change the source file location..
197 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
198 if ( is_wp_error($source) )
201 //Has the source location changed? If so, we need a new source_files list.
202 if ( $source !== $remote_source )
203 $source_files = array_keys( $wp_filesystem->dirlist($source) );
205 //Protection against deleting files in any important base directories.
206 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
207 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
208 $destination = trailingslashit($destination) . trailingslashit(basename($source));
211 if ( $clear_destination ) {
212 //We're going to clear the destination if theres something there
213 $this->skin->feedback('remove_old');
215 if ( $wp_filesystem->exists($remote_destination) )
216 $removed = $wp_filesystem->delete($remote_destination, true);
217 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
219 if ( is_wp_error($removed) )
221 else if ( ! $removed )
222 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
223 } elseif ( $wp_filesystem->exists($remote_destination) ) {
224 //If we're not clearing the destination folder and something exists there allready, Bail.
225 //But first check to see if there are actually any files in the folder.
226 $_files = $wp_filesystem->dirlist($remote_destination);
227 if ( ! empty($_files) ) {
228 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
229 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
233 //Create destination if needed
234 if ( !$wp_filesystem->exists($remote_destination) )
235 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
236 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
238 // Copy new version of item into place.
239 $result = copy_dir($source, $remote_destination);
240 if ( is_wp_error($result) ) {
241 if ( $clear_working )
242 $wp_filesystem->delete($remote_source, true);
246 //Clear the Working folder?
247 if ( $clear_working )
248 $wp_filesystem->delete($remote_source, true);
250 $destination_name = basename( str_replace($local_destination, '', $destination) );
251 if ( '.' == $destination_name )
252 $destination_name = '';
254 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
256 $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
257 if ( is_wp_error($res) ) {
258 $this->result = $res;
262 //Bombard the calling function will all the info which we've just used.
263 return $this->result;
266 function run($options) {
268 $defaults = array( 'package' => '', //Please always pass this.
269 'destination' => '', //And this
270 'clear_destination' => false,
271 'clear_working' => true,
273 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
276 $options = wp_parse_args($options, $defaults);
279 //Connect to the Filesystem first.
280 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
281 if ( ! $res ) //Mainly for non-connected filesystem.
284 if ( is_wp_error($res) ) {
285 $this->skin->error($res);
289 if ( !$is_multi ) // call $this->header separately if running multiple times
290 $this->skin->header();
292 $this->skin->before();
294 //Download the package (Note, This just returns the filename of the file if the package is a local file)
295 $download = $this->download_package( $package );
296 if ( is_wp_error($download) ) {
297 $this->skin->error($download);
298 $this->skin->after();
302 $delete_package = ($download != $package); // Do not delete a "local" file
304 //Unzip's the file into a temporary directory
305 $working_dir = $this->unpack_package( $download, $delete_package );
306 if ( is_wp_error($working_dir) ) {
307 $this->skin->error($working_dir);
308 $this->skin->after();
312 //With the given options, this installs it to the destination directory.
313 $result = $this->install_package( array(
314 'source' => $working_dir,
315 'destination' => $destination,
316 'clear_destination' => $clear_destination,
317 'clear_working' => $clear_working,
318 'hook_extra' => $hook_extra
320 $this->skin->set_result($result);
321 if ( is_wp_error($result) ) {
322 $this->skin->error($result);
323 $this->skin->feedback('process_failed');
326 $this->skin->feedback('process_success');
328 $this->skin->after();
331 $this->skin->footer();
336 function maintenance_mode($enable = false) {
337 global $wp_filesystem;
338 $file = $wp_filesystem->abspath() . '.maintenance';
340 $this->skin->feedback('maintenance_start');
341 // Create maintenance file to signal that we are upgrading
342 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
343 $wp_filesystem->delete($file);
344 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
345 } else if ( !$enable && $wp_filesystem->exists($file) ) {
346 $this->skin->feedback('maintenance_end');
347 $wp_filesystem->delete($file);
354 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
356 * @TODO More Detailed docs, for methods as well.
359 * @subpackage Upgrader
362 class Plugin_Upgrader extends WP_Upgrader {
366 var $show_before = '';
368 function upgrade_strings() {
369 $this->strings['up_to_date'] = __('The plugin is at the latest version.');
370 $this->strings['no_package'] = __('Update package not available.');
371 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
372 $this->strings['unpack_package'] = __('Unpacking the update…');
373 $this->strings['deactivate_plugin'] = __('Deactivating the plugin…');
374 $this->strings['remove_old'] = __('Removing the old version of the plugin…');
375 $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
376 $this->strings['process_failed'] = __('Plugin update failed.');
377 $this->strings['process_success'] = __('Plugin updated successfully.');
380 function install_strings() {
381 $this->strings['no_package'] = __('Install package not available.');
382 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
383 $this->strings['unpack_package'] = __('Unpacking the package…');
384 $this->strings['installing_package'] = __('Installing the plugin…');
385 $this->strings['process_failed'] = __('Plugin install failed.');
386 $this->strings['process_success'] = __('Plugin installed successfully.');
389 function install($package) {
392 $this->install_strings();
395 'package' => $package,
396 'destination' => WP_PLUGIN_DIR,
397 'clear_destination' => false, //Do not overwrite files.
398 'clear_working' => true,
399 'hook_extra' => array()
402 // Force refresh of plugin update information
403 delete_site_transient('update_plugins');
407 function upgrade($plugin) {
410 $this->upgrade_strings();
412 $current = get_site_transient( 'update_plugins' );
413 if ( !isset( $current->response[ $plugin ] ) ) {
414 $this->skin->before();
415 $this->skin->set_result(false);
416 $this->skin->error('up_to_date');
417 $this->skin->after();
421 // Get the URL to the zip file
422 $r = $current->response[ $plugin ];
424 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
425 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
426 //'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.
429 'package' => $r->package,
430 'destination' => WP_PLUGIN_DIR,
431 'clear_destination' => true,
432 'clear_working' => true,
433 'hook_extra' => array(
438 // Cleanup our hooks, incase something else does a upgrade on this connection.
439 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
440 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
442 if ( ! $this->result || is_wp_error($this->result) )
443 return $this->result;
445 // Force refresh of plugin update information
446 delete_site_transient('update_plugins');
449 function bulk_upgrade($plugins) {
453 $this->upgrade_strings();
455 $current = get_site_transient( 'update_plugins' );
457 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
459 $this->skin->header();
461 // Connect to the Filesystem first.
462 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
464 $this->skin->footer();
468 $this->skin->bulk_header();
470 // Only start maintenance mode if running in Multisite OR the plugin is in use
471 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
472 foreach ( $plugins as $plugin )
473 $maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available
475 $this->maintenance_mode(true);
479 $this->update_count = count($plugins);
480 $this->update_current = 0;
481 foreach ( $plugins as $plugin ) {
482 $this->update_current++;
483 $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
485 if ( !isset( $current->response[ $plugin ] ) ) {
486 $this->skin->set_result(false);
487 $this->skin->before();
488 $this->skin->error('up_to_date');
489 $this->skin->after();
490 $results[$plugin] = false;
494 // Get the URL to the zip file
495 $r = $current->response[ $plugin ];
497 $this->skin->plugin_active = is_plugin_active($plugin);
499 $result = $this->run(array(
500 'package' => $r->package,
501 'destination' => WP_PLUGIN_DIR,
502 'clear_destination' => true,
503 'clear_working' => true,
505 'hook_extra' => array(
510 $results[$plugin] = $this->result;
512 // Prevent credentials auth screen from displaying multiple times
513 if ( false === $result )
515 } //end foreach $plugins
517 $this->maintenance_mode(false);
519 $this->skin->bulk_footer();
521 $this->skin->footer();
523 // Cleanup our hooks, incase something else does a upgrade on this connection.
524 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
526 // Force refresh of plugin update information
527 delete_site_transient('update_plugins');
532 //return plugin info.
533 function plugin_info() {
534 if ( ! is_array($this->result) )
536 if ( empty($this->result['destination_name']) )
539 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
540 if ( empty($plugin) )
543 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
545 return $this->result['destination_name'] . '/' . $pluginfiles[0];
548 //Hooked to pre_install
549 function deactivate_plugin_before_upgrade($return, $plugin) {
551 if ( is_wp_error($return) ) //Bypass.
554 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
555 if ( empty($plugin) )
556 return new WP_Error('bad_request', $this->strings['bad_request']);
558 if ( is_plugin_active($plugin) ) {
559 $this->skin->feedback('deactivate_plugin');
560 //Deactivate the plugin silently, Prevent deactivation hooks from running.
561 deactivate_plugins($plugin, true);
565 //Hooked to upgrade_clear_destination
566 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
567 global $wp_filesystem;
569 if ( is_wp_error($removed) )
570 return $removed; //Pass errors through.
572 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
573 if ( empty($plugin) )
574 return new WP_Error('bad_request', $this->strings['bad_request']);
576 $plugins_dir = $wp_filesystem->wp_plugins_dir();
577 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
579 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
582 // If plugin is in its own directory, recursively delete the directory.
583 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder
584 $deleted = $wp_filesystem->delete($this_plugin_dir, true);
586 $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
589 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
596 * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
598 * @TODO More Detailed docs, for methods as well.
601 * @subpackage Upgrader
604 class Theme_Upgrader extends WP_Upgrader {
608 function upgrade_strings() {
609 $this->strings['up_to_date'] = __('The theme is at the latest version.');
610 $this->strings['no_package'] = __('Update package not available.');
611 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
612 $this->strings['unpack_package'] = __('Unpacking the update…');
613 $this->strings['remove_old'] = __('Removing the old version of the theme…');
614 $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
615 $this->strings['process_failed'] = __('Theme update failed.');
616 $this->strings['process_success'] = __('Theme updated successfully.');
619 function install_strings() {
620 $this->strings['no_package'] = __('Install package not available.');
621 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
622 $this->strings['unpack_package'] = __('Unpacking the package…');
623 $this->strings['installing_package'] = __('Installing the theme…');
624 $this->strings['process_failed'] = __('Theme install failed.');
625 $this->strings['process_success'] = __('Theme installed successfully.');
628 function install($package) {
631 $this->install_strings();
634 'package' => $package,
635 'destination' => WP_CONTENT_DIR . '/themes',
636 'clear_destination' => false, //Do not overwrite files.
637 'clear_working' => true
640 $this->run($options);
642 if ( ! $this->result || is_wp_error($this->result) )
643 return $this->result;
645 // Force refresh of theme update information
646 delete_site_transient('update_themes');
648 if ( empty($result['destination_name']) )
651 return $result['destination_name'];
654 function upgrade($theme) {
657 $this->upgrade_strings();
659 // Is an update available?
660 $current = get_site_transient( 'update_themes' );
661 if ( !isset( $current->response[ $theme ] ) ) {
662 $this->skin->before();
663 $this->skin->set_result(false);
664 $this->skin->error('up_to_date');
665 $this->skin->after();
669 $r = $current->response[ $theme ];
671 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
672 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
673 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
676 'package' => $r['package'],
677 'destination' => WP_CONTENT_DIR . '/themes',
678 'clear_destination' => true,
679 'clear_working' => true,
680 'hook_extra' => array(
685 $this->run($options);
687 if ( ! $this->result || is_wp_error($this->result) )
688 return $this->result;
690 // Force refresh of theme update information
691 delete_site_transient('update_themes');
696 function bulk_upgrade($themes) {
700 $this->upgrade_strings();
702 $current = get_site_transient( 'update_themes' );
704 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
705 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
706 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
708 $this->skin->header();
710 // Connect to the Filesystem first.
711 $res = $this->fs_connect( array(WP_CONTENT_DIR) );
713 $this->skin->footer();
717 $this->skin->bulk_header();
719 // Only start maintenance mode if running in Multisite OR the theme is in use
720 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
721 foreach ( $themes as $theme )
722 $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
724 $this->maintenance_mode(true);
728 $this->update_count = count($themes);
729 $this->update_current = 0;
730 foreach ( $themes as $theme ) {
731 $this->update_current++;
733 if ( !isset( $current->response[ $theme ] ) ) {
734 $this->skin->set_result(false);
735 $this->skin->before();
736 $this->skin->error('up_to_date');
737 $this->skin->after();
738 $results[$theme] = false;
742 $this->skin->theme_info = $this->theme_info($theme);
744 // Get the URL to the zip file
745 $r = $current->response[ $theme ];
748 'package' => $r['package'],
749 'destination' => WP_CONTENT_DIR . '/themes',
750 'clear_destination' => true,
751 'clear_working' => true,
752 'hook_extra' => array(
757 $result = $this->run($options);
759 $results[$theme] = $this->result;
761 // Prevent credentials auth screen from displaying multiple times
762 if ( false === $result )
764 } //end foreach $plugins
766 $this->maintenance_mode(false);
768 $this->skin->bulk_footer();
770 $this->skin->footer();
772 // Cleanup our hooks, incase something else does a upgrade on this connection.
773 remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
774 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
775 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
777 // Force refresh of theme update information
778 delete_site_transient('update_themes');
783 function current_before($return, $theme) {
785 if ( is_wp_error($return) )
788 $theme = isset($theme['theme']) ? $theme['theme'] : '';
790 if ( $theme != get_stylesheet() ) //If not current
792 //Change to maintenance mode now.
794 $this->maintenance_mode(true);
798 function current_after($return, $theme) {
799 if ( is_wp_error($return) )
802 $theme = isset($theme['theme']) ? $theme['theme'] : '';
804 if ( $theme != get_stylesheet() ) //If not current
807 //Ensure stylesheet name hasnt changed after the upgrade:
808 // @TODO: Note, This doesnt handle the Template changing, or the Template name changing.
809 if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
810 $theme_info = $this->theme_info();
811 $stylesheet = $this->result['destination_name'];
812 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
813 switch_theme($template, $stylesheet, true);
816 //Time to remove maintenance mode
818 $this->maintenance_mode(false);
822 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
823 global $wp_filesystem;
825 $theme = isset($theme['theme']) ? $theme['theme'] : '';
827 if ( is_wp_error($removed) || empty($theme) )
828 return $removed; //Pass errors through.
830 $themes_dir = $wp_filesystem->wp_themes_dir();
831 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
832 if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
837 function theme_info($theme = null) {
839 if ( empty($theme) ) {
840 if ( !empty($this->result['destination_name']) )
841 $theme = $this->result['destination_name'];
845 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
851 * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
853 * @TODO More Detailed docs, for methods as well.
856 * @subpackage Upgrader
859 class Core_Upgrader extends WP_Upgrader {
861 function upgrade_strings() {
862 $this->strings['up_to_date'] = __('WordPress is at the latest version.');
863 $this->strings['no_package'] = __('Update package not available.');
864 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
865 $this->strings['unpack_package'] = __('Unpacking the update…');
866 $this->strings['copy_failed'] = __('Could not copy files.');
869 function upgrade($current) {
870 global $wp_filesystem, $wp_version;
873 $this->upgrade_strings();
875 if ( !empty($feedback) )
876 add_filter('update_feedback', $feedback);
878 // Is an update available?
879 if ( !isset( $current->response ) || $current->response == 'latest' )
880 return new WP_Error('up_to_date', $this->strings['up_to_date']);
882 $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
883 if ( is_wp_error($res) )
886 $wp_dir = trailingslashit($wp_filesystem->abspath());
888 // If partial update is returned from the API, use that, unless we're doing a reinstall.
889 // If we cross the new_bundled version number, then use the new_bundled zip.
890 // Don't though if the constant is set to skip bundled items.
891 // If the API returns a no_content zip, go with it. Finally, default to the full zip.
892 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
893 $to_download = 'partial';
894 elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
895 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
896 $to_download = 'new_bundled';
897 elseif ( $current->packages->no_content )
898 $to_download = 'no_content';
900 $to_download = 'full';
902 $download = $this->download_package( $current->packages->$to_download );
903 if ( is_wp_error($download) )
906 $working_dir = $this->unpack_package( $download );
907 if ( is_wp_error($working_dir) )
910 // Copy update-core.php from the new version into place.
911 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
912 $wp_filesystem->delete($working_dir, true);
913 return new WP_Error('copy_failed', $this->strings['copy_failed']);
915 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
917 require(ABSPATH . 'wp-admin/includes/update-core.php');
919 return update_core($working_dir, $wp_dir);
925 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
927 * @TODO More Detailed docs, for methods as well.
930 * @subpackage Upgrader
933 class WP_Upgrader_Skin {
936 var $done_header = false;
939 function __construct($args = array()) {
940 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
941 $this->options = wp_parse_args($args, $defaults);
944 function set_upgrader(&$upgrader) {
945 if ( is_object($upgrader) )
946 $this->upgrader =& $upgrader;
947 $this->add_strings();
950 function add_strings() {
953 function set_result($result) {
954 $this->result = $result;
957 function request_filesystem_credentials($error = false) {
958 $url = $this->options['url'];
959 $context = $this->options['context'];
960 if ( !empty($this->options['nonce']) )
961 $url = wp_nonce_url($url, $this->options['nonce']);
962 return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
966 if ( $this->done_header )
968 $this->done_header = true;
969 echo '<div class="wrap">';
971 echo '<h2>' . $this->options['title'] . '</h2>';
977 function error($errors) {
978 if ( ! $this->done_header )
980 if ( is_string($errors) ) {
981 $this->feedback($errors);
982 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
983 foreach ( $errors->get_error_messages() as $message ) {
984 if ( $errors->get_error_data() )
985 $this->feedback($message . ' ' . $errors->get_error_data() );
987 $this->feedback($message);
992 function feedback($string) {
993 if ( isset( $this->upgrader->strings[$string] ) )
994 $string = $this->upgrader->strings[$string];
996 if ( strpos($string, '%') !== false ) {
997 $args = func_get_args();
998 $args = array_splice($args, 1);
1000 $string = vsprintf($string, $args);
1002 if ( empty($string) )
1004 show_message($string);
1006 function before() {}
1012 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1014 * @TODO More Detailed docs, for methods as well.
1016 * @package WordPress
1017 * @subpackage Upgrader
1020 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
1022 var $plugin_active = false;
1023 var $plugin_network_active = false;
1025 function __construct($args = array()) {
1026 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
1027 $args = wp_parse_args($args, $defaults);
1029 $this->plugin = $args['plugin'];
1031 $this->plugin_active = is_plugin_active( $this->plugin );
1032 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
1034 parent::__construct($args);
1038 $this->plugin = $this->upgrader->plugin_info();
1039 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
1040 show_message(__('Reactivating the plugin…'));
1041 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>';
1044 $update_actions = array(
1045 '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>',
1046 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
1048 if ( $this->plugin_active )
1049 unset( $update_actions['activate_plugin'] );
1050 if ( ! $this->result || is_wp_error($this->result) )
1051 unset( $update_actions['activate_plugin'] );
1053 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
1054 if ( ! empty($update_actions) )
1055 $this->feedback(implode(' | ', (array)$update_actions));
1059 if ( $this->upgrader->show_before ) {
1060 echo $this->upgrader->show_before;
1061 $this->upgrader->show_before = '';
1067 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1069 * @package WordPress
1070 * @subpackage Upgrader
1073 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
1074 var $in_loop = false;
1077 function __construct($args = array()) {
1078 $defaults = array( 'url' => '', 'nonce' => '' );
1079 $args = wp_parse_args($args, $defaults);
1081 parent::__construct($args);
1084 function add_strings() {
1085 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
1086 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.');
1087 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
1088 $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>';
1089 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
1092 function feedback($string) {
1093 if ( isset( $this->upgrader->strings[$string] ) )
1094 $string = $this->upgrader->strings[$string];
1096 if ( strpos($string, '%') !== false ) {
1097 $args = func_get_args();
1098 $args = array_splice($args, 1);
1099 if ( !empty($args) )
1100 $string = vsprintf($string, $args);
1102 if ( empty($string) )
1104 if ( $this->in_loop )
1105 echo "$string<br />\n";
1107 echo "<p>$string</p>\n";
1111 // Nothing, This will be displayed within a iframe.
1115 // Nothing, This will be displayed within a iframe.
1117 function error($error) {
1118 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
1119 $this->error = $this->upgrader->strings[$error];
1121 if ( is_wp_error($error) ) {
1122 foreach ( $error->get_error_messages() as $emessage ) {
1123 if ( $error->get_error_data() )
1124 $messages[] = $emessage . ' ' . $error->get_error_data();
1126 $messages[] = $emessage;
1128 $this->error = implode(', ', $messages);
1130 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1133 function bulk_header() {
1134 $this->feedback('skin_upgrade_start');
1137 function bulk_footer() {
1138 $this->feedback('skin_upgrade_end');
1141 function before($title = '') {
1142 $this->in_loop = true;
1143 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);
1144 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1145 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
1146 $this->flush_output();
1149 function after($title = '') {
1151 if ( $this->error || ! $this->result ) {
1153 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
1155 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
1157 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1159 if ( !empty($this->result) && !is_wp_error($this->result) ) {
1160 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>';
1161 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1165 $this->flush_output();
1169 $this->in_loop = false;
1170 $this->error = false;
1173 function flush_output() {
1174 wp_ob_end_flush_all();
1179 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
1180 var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
1182 function __construct($args = array()) {
1183 parent::__construct($args);
1186 function add_strings() {
1187 parent::add_strings();
1188 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
1192 parent::before($this->plugin_info['Title']);
1196 parent::after($this->plugin_info['Title']);
1198 function bulk_footer() {
1199 parent::bulk_footer();
1200 $update_actions = array(
1201 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
1202 '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>'
1205 $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
1206 if ( ! empty($update_actions) )
1207 $this->feedback(implode(' | ', (array)$update_actions));
1211 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
1212 var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
1214 function __construct($args = array()) {
1215 parent::__construct($args);
1218 function add_strings() {
1219 parent::add_strings();
1220 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
1224 parent::before($this->theme_info['Name']);
1228 parent::after($this->theme_info['Name']);
1230 function bulk_footer() {
1231 parent::bulk_footer();
1232 $update_actions = array(
1233 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
1234 '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>'
1237 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
1238 if ( ! empty($update_actions) )
1239 $this->feedback(implode(' | ', (array)$update_actions));
1244 * Plugin Installer Skin for WordPress Plugin Installer.
1246 * @TODO More Detailed docs, for methods as well.
1248 * @package WordPress
1249 * @subpackage Upgrader
1252 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
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 __construct($args = array()) {
1321 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
1322 $args = wp_parse_args($args, $defaults);
1324 $this->type = $args['type'];
1325 $this->api = isset($args['api']) ? $args['api'] : array();
1327 parent::__construct($args);
1331 if ( !empty($this->api) ) {
1332 /* translators: 1: theme name, 2: version */
1333 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
1338 if ( empty($this->upgrader->result['destination_name']) )
1341 $theme_info = $this->upgrader->theme_info();
1342 if ( empty($theme_info) )
1344 $name = $theme_info['Name'];
1345 $stylesheet = $this->upgrader->result['destination_name'];
1346 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1348 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1349 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1351 $install_actions = array(
1352 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>',
1353 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'
1356 if ( $this->type == 'web' )
1357 $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>';
1359 $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
1361 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() )
1362 unset( $install_actions['activate'], $install_actions['preview'] );
1364 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
1365 if ( ! empty($install_actions) )
1366 $this->feedback(implode(' | ', (array)$install_actions));
1371 * Theme Upgrader Skin for WordPress Theme Upgrades.
1373 * @TODO More Detailed docs, for methods as well.
1375 * @package WordPress
1376 * @subpackage Upgrader
1379 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
1382 function __construct($args = array()) {
1383 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
1384 $args = wp_parse_args($args, $defaults);
1386 $this->theme = $args['theme'];
1388 parent::__construct($args);
1393 $update_actions = array();
1394 if ( !empty($this->upgrader->result['destination_name']) &&
1395 ($theme_info = $this->upgrader->theme_info()) &&
1396 !empty($theme_info) ) {
1398 $name = $theme_info['Name'];
1399 $stylesheet = $this->upgrader->result['destination_name'];
1400 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1402 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1403 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1405 $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>';
1406 $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
1408 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
1409 unset($update_actions['preview'], $update_actions['activate']);
1412 $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>';
1414 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
1415 if ( ! empty($update_actions) )
1416 $this->feedback(implode(' | ', (array)$update_actions));
1421 * 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.
1423 * @TODO More Detailed docs, for methods as well.
1425 * @package WordPress
1426 * @subpackage Upgrader
1429 class File_Upload_Upgrader {
1433 function __construct($form, $urlholder) {
1434 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
1435 wp_die($uploads['error']);
1437 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
1438 wp_die(__('Please select a file'));
1440 if ( !empty($_FILES) )
1441 $this->filename = $_FILES[$form]['name'];
1442 else if ( isset($_GET[$urlholder]) )
1443 $this->filename = $_GET[$urlholder];
1445 //Handle a newly uploaded file, Else assume its already been uploaded
1446 if ( !empty($_FILES) ) {
1447 $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename );
1448 $this->package = $uploads['basedir'] . '/' . $this->filename;
1450 // Move the file to the uploads dir
1451 if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
1452 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
1454 $this->package = $uploads['basedir'] . '/' . $this->filename;