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['incompatible_archive'] = __('The package could not be installed.');
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);
156 if ( 'incompatible_archive' == $result->get_error_code() ) {
157 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
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( 'incompatible_archive', $this->strings['incompatible_archive'], __( 'The plugin contains no files.' ) ); //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.
198 $source = trailingslashit($source);
200 //Hook ability to change the source file location..
201 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
202 if ( is_wp_error($source) )
205 //Has the source location changed? If so, we need a new source_files list.
206 if ( $source !== $remote_source )
207 $source_files = array_keys( $wp_filesystem->dirlist($source) );
209 //Protection against deleting files in any important base directories.
210 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
211 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
212 $destination = trailingslashit($destination) . trailingslashit(basename($source));
215 if ( $clear_destination ) {
216 //We're going to clear the destination if there's something there
217 $this->skin->feedback('remove_old');
219 if ( $wp_filesystem->exists($remote_destination) )
220 $removed = $wp_filesystem->delete($remote_destination, true);
221 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
223 if ( is_wp_error($removed) )
225 else if ( ! $removed )
226 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
227 } elseif ( $wp_filesystem->exists($remote_destination) ) {
228 //If we're not clearing the destination folder and something exists there already, Bail.
229 //But first check to see if there are actually any files in the folder.
230 $_files = $wp_filesystem->dirlist($remote_destination);
231 if ( ! empty($_files) ) {
232 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
233 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
237 //Create destination if needed
238 if ( !$wp_filesystem->exists($remote_destination) )
239 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
240 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
242 // Copy new version of item into place.
243 $result = copy_dir($source, $remote_destination);
244 if ( is_wp_error($result) ) {
245 if ( $clear_working )
246 $wp_filesystem->delete($remote_source, true);
250 //Clear the Working folder?
251 if ( $clear_working )
252 $wp_filesystem->delete($remote_source, true);
254 $destination_name = basename( str_replace($local_destination, '', $destination) );
255 if ( '.' == $destination_name )
256 $destination_name = '';
258 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
260 $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
261 if ( is_wp_error($res) ) {
262 $this->result = $res;
266 //Bombard the calling function will all the info which we've just used.
267 return $this->result;
270 function run($options) {
272 $defaults = array( 'package' => '', //Please always pass this.
273 'destination' => '', //And this
274 'clear_destination' => false,
275 'clear_working' => true,
277 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
280 $options = wp_parse_args($options, $defaults);
283 //Connect to the Filesystem first.
284 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
285 if ( ! $res ) //Mainly for non-connected filesystem.
288 if ( is_wp_error($res) ) {
289 $this->skin->error($res);
293 if ( !$is_multi ) // call $this->header separately if running multiple times
294 $this->skin->header();
296 $this->skin->before();
298 //Download the package (Note, This just returns the filename of the file if the package is a local file)
299 $download = $this->download_package( $package );
300 if ( is_wp_error($download) ) {
301 $this->skin->error($download);
302 $this->skin->after();
306 $delete_package = ($download != $package); // Do not delete a "local" file
308 //Unzips the file into a temporary directory
309 $working_dir = $this->unpack_package( $download, $delete_package );
310 if ( is_wp_error($working_dir) ) {
311 $this->skin->error($working_dir);
312 $this->skin->after();
316 //With the given options, this installs it to the destination directory.
317 $result = $this->install_package( array(
318 'source' => $working_dir,
319 'destination' => $destination,
320 'clear_destination' => $clear_destination,
321 'clear_working' => $clear_working,
322 'hook_extra' => $hook_extra
324 $this->skin->set_result($result);
325 if ( is_wp_error($result) ) {
326 $this->skin->error($result);
327 $this->skin->feedback('process_failed');
330 $this->skin->feedback('process_success');
332 $this->skin->after();
335 $this->skin->footer();
340 function maintenance_mode($enable = false) {
341 global $wp_filesystem;
342 $file = $wp_filesystem->abspath() . '.maintenance';
344 $this->skin->feedback('maintenance_start');
345 // Create maintenance file to signal that we are upgrading
346 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
347 $wp_filesystem->delete($file);
348 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
349 } else if ( !$enable && $wp_filesystem->exists($file) ) {
350 $this->skin->feedback('maintenance_end');
351 $wp_filesystem->delete($file);
358 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
360 * @TODO More Detailed docs, for methods as well.
363 * @subpackage Upgrader
366 class Plugin_Upgrader extends WP_Upgrader {
370 var $show_before = '';
372 function upgrade_strings() {
373 $this->strings['up_to_date'] = __('The plugin is at the latest version.');
374 $this->strings['no_package'] = __('Update package not available.');
375 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
376 $this->strings['unpack_package'] = __('Unpacking the update…');
377 $this->strings['deactivate_plugin'] = __('Deactivating the plugin…');
378 $this->strings['remove_old'] = __('Removing the old version of the plugin…');
379 $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
380 $this->strings['process_failed'] = __('Plugin update failed.');
381 $this->strings['process_success'] = __('Plugin updated successfully.');
384 function install_strings() {
385 $this->strings['no_package'] = __('Install package not available.');
386 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
387 $this->strings['unpack_package'] = __('Unpacking the package…');
388 $this->strings['installing_package'] = __('Installing the plugin…');
389 $this->strings['process_failed'] = __('Plugin install failed.');
390 $this->strings['process_success'] = __('Plugin installed successfully.');
393 function install($package) {
396 $this->install_strings();
398 add_filter('upgrader_source_selection', array(&$this, 'check_package') );
401 'package' => $package,
402 'destination' => WP_PLUGIN_DIR,
403 'clear_destination' => false, //Do not overwrite files.
404 'clear_working' => true,
405 'hook_extra' => array()
408 remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
410 if ( ! $this->result || is_wp_error($this->result) )
411 return $this->result;
413 // Force refresh of plugin update information
414 delete_site_transient('update_plugins');
419 function upgrade($plugin) {
422 $this->upgrade_strings();
424 $current = get_site_transient( 'update_plugins' );
425 if ( !isset( $current->response[ $plugin ] ) ) {
426 $this->skin->before();
427 $this->skin->set_result(false);
428 $this->skin->error('up_to_date');
429 $this->skin->after();
433 // Get the URL to the zip file
434 $r = $current->response[ $plugin ];
436 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
437 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
438 //'source_selection' => array(&$this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
441 'package' => $r->package,
442 'destination' => WP_PLUGIN_DIR,
443 'clear_destination' => true,
444 'clear_working' => true,
445 'hook_extra' => array(
450 // Cleanup our hooks, in case something else does a upgrade on this connection.
451 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
452 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
454 if ( ! $this->result || is_wp_error($this->result) )
455 return $this->result;
457 // Force refresh of plugin update information
458 delete_site_transient('update_plugins');
461 function bulk_upgrade($plugins) {
465 $this->upgrade_strings();
467 $current = get_site_transient( 'update_plugins' );
469 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
471 $this->skin->header();
473 // Connect to the Filesystem first.
474 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
476 $this->skin->footer();
480 $this->skin->bulk_header();
482 // Only start maintenance mode if running in Multisite OR the plugin is in use
483 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
484 foreach ( $plugins as $plugin )
485 $maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available
487 $this->maintenance_mode(true);
491 $this->update_count = count($plugins);
492 $this->update_current = 0;
493 foreach ( $plugins as $plugin ) {
494 $this->update_current++;
495 $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
497 if ( !isset( $current->response[ $plugin ] ) ) {
498 $this->skin->set_result(false);
499 $this->skin->before();
500 $this->skin->error('up_to_date');
501 $this->skin->after();
502 $results[$plugin] = false;
506 // Get the URL to the zip file
507 $r = $current->response[ $plugin ];
509 $this->skin->plugin_active = is_plugin_active($plugin);
511 $result = $this->run(array(
512 'package' => $r->package,
513 'destination' => WP_PLUGIN_DIR,
514 'clear_destination' => true,
515 'clear_working' => true,
517 'hook_extra' => array(
522 $results[$plugin] = $this->result;
524 // Prevent credentials auth screen from displaying multiple times
525 if ( false === $result )
527 } //end foreach $plugins
529 $this->maintenance_mode(false);
531 $this->skin->bulk_footer();
533 $this->skin->footer();
535 // Cleanup our hooks, in case something else does a upgrade on this connection.
536 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
538 // Force refresh of plugin update information
539 delete_site_transient('update_plugins');
544 function check_package($source) {
545 global $wp_filesystem;
547 if ( is_wp_error($source) )
550 $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
551 if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
554 // Check the folder contains at least 1 valid plugin.
555 $plugins_found = false;
556 foreach ( glob( $working_directory . '*.php' ) as $file ) {
557 $info = get_plugin_data($file, false, false);
558 if ( !empty( $info['Name'] ) ) {
559 $plugins_found = true;
564 if ( ! $plugins_found )
565 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
570 //return plugin info.
571 function plugin_info() {
572 if ( ! is_array($this->result) )
574 if ( empty($this->result['destination_name']) )
577 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
578 if ( empty($plugin) )
581 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
583 return $this->result['destination_name'] . '/' . $pluginfiles[0];
586 //Hooked to pre_install
587 function deactivate_plugin_before_upgrade($return, $plugin) {
589 if ( is_wp_error($return) ) //Bypass.
592 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
593 if ( empty($plugin) )
594 return new WP_Error('bad_request', $this->strings['bad_request']);
596 if ( is_plugin_active($plugin) ) {
597 $this->skin->feedback('deactivate_plugin');
598 //Deactivate the plugin silently, Prevent deactivation hooks from running.
599 deactivate_plugins($plugin, true);
603 //Hooked to upgrade_clear_destination
604 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
605 global $wp_filesystem;
607 if ( is_wp_error($removed) )
608 return $removed; //Pass errors through.
610 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
611 if ( empty($plugin) )
612 return new WP_Error('bad_request', $this->strings['bad_request']);
614 $plugins_dir = $wp_filesystem->wp_plugins_dir();
615 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
617 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
620 // If plugin is in its own directory, recursively delete the directory.
621 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder
622 $deleted = $wp_filesystem->delete($this_plugin_dir, true);
624 $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
627 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
634 * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
636 * @TODO More Detailed docs, for methods as well.
639 * @subpackage Upgrader
642 class Theme_Upgrader extends WP_Upgrader {
647 function upgrade_strings() {
648 $this->strings['up_to_date'] = __('The theme is at the latest version.');
649 $this->strings['no_package'] = __('Update package not available.');
650 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
651 $this->strings['unpack_package'] = __('Unpacking the update…');
652 $this->strings['remove_old'] = __('Removing the old version of the theme…');
653 $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
654 $this->strings['process_failed'] = __('Theme update failed.');
655 $this->strings['process_success'] = __('Theme updated successfully.');
658 function install_strings() {
659 $this->strings['no_package'] = __('Install package not available.');
660 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
661 $this->strings['unpack_package'] = __('Unpacking the package…');
662 $this->strings['installing_package'] = __('Installing the theme…');
663 $this->strings['process_failed'] = __('Theme install failed.');
664 $this->strings['process_success'] = __('Theme installed successfully.');
667 function install($package) {
670 $this->install_strings();
672 add_filter('upgrader_source_selection', array(&$this, 'check_package') );
675 'package' => $package,
676 'destination' => WP_CONTENT_DIR . '/themes',
677 'clear_destination' => false, //Do not overwrite files.
678 'clear_working' => true
681 $this->run($options);
683 remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
685 if ( ! $this->result || is_wp_error($this->result) )
686 return $this->result;
688 // Force refresh of theme update information
689 delete_site_transient('update_themes');
694 function upgrade($theme) {
697 $this->upgrade_strings();
699 // Is an update available?
700 $current = get_site_transient( 'update_themes' );
701 if ( !isset( $current->response[ $theme ] ) ) {
702 $this->skin->before();
703 $this->skin->set_result(false);
704 $this->skin->error('up_to_date');
705 $this->skin->after();
709 $r = $current->response[ $theme ];
711 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
712 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
713 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
716 'package' => $r['package'],
717 'destination' => WP_CONTENT_DIR . '/themes',
718 'clear_destination' => true,
719 'clear_working' => true,
720 'hook_extra' => array(
725 $this->run($options);
727 remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
728 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
729 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
731 if ( ! $this->result || is_wp_error($this->result) )
732 return $this->result;
734 // Force refresh of theme update information
735 delete_site_transient('update_themes');
740 function bulk_upgrade($themes) {
744 $this->upgrade_strings();
746 $current = get_site_transient( 'update_themes' );
748 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
749 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
750 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
752 $this->skin->header();
754 // Connect to the Filesystem first.
755 $res = $this->fs_connect( array(WP_CONTENT_DIR) );
757 $this->skin->footer();
761 $this->skin->bulk_header();
763 // Only start maintenance mode if running in Multisite OR the theme is in use
764 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
765 foreach ( $themes as $theme )
766 $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
768 $this->maintenance_mode(true);
772 $this->update_count = count($themes);
773 $this->update_current = 0;
774 foreach ( $themes as $theme ) {
775 $this->update_current++;
777 if ( !isset( $current->response[ $theme ] ) ) {
778 $this->skin->set_result(false);
779 $this->skin->before();
780 $this->skin->error('up_to_date');
781 $this->skin->after();
782 $results[$theme] = false;
786 $this->skin->theme_info = $this->theme_info($theme);
788 // Get the URL to the zip file
789 $r = $current->response[ $theme ];
792 'package' => $r['package'],
793 'destination' => WP_CONTENT_DIR . '/themes',
794 'clear_destination' => true,
795 'clear_working' => true,
796 'hook_extra' => array(
801 $result = $this->run($options);
803 $results[$theme] = $this->result;
805 // Prevent credentials auth screen from displaying multiple times
806 if ( false === $result )
808 } //end foreach $plugins
810 $this->maintenance_mode(false);
812 $this->skin->bulk_footer();
814 $this->skin->footer();
816 // Cleanup our hooks, in case something else does a upgrade on this connection.
817 remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
818 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
819 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
821 // Force refresh of theme update information
822 delete_site_transient('update_themes');
827 function check_package($source) {
828 global $wp_filesystem;
830 if ( is_wp_error($source) )
833 // Check the folder contains a valid theme
834 $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
835 if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
838 if ( ! file_exists( $working_directory . 'style.css' ) ) // A proper archive should have a style.css file in the single subdirectory
839 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
841 $info = get_theme_data( $working_directory . 'style.css' );
842 if ( empty($info['Name']) )
843 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
845 if ( empty($info['Template']) && ! file_exists( $working_directory . 'index.php' ) ) // If no template is set, it must have at least an index.php to be legit.
846 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
851 function current_before($return, $theme) {
853 if ( is_wp_error($return) )
856 $theme = isset($theme['theme']) ? $theme['theme'] : '';
858 if ( $theme != get_stylesheet() ) //If not current
860 //Change to maintenance mode now.
862 $this->maintenance_mode(true);
867 function current_after($return, $theme) {
868 if ( is_wp_error($return) )
871 $theme = isset($theme['theme']) ? $theme['theme'] : '';
873 if ( $theme != get_stylesheet() ) //If not current
876 //Ensure stylesheet name hasnt changed after the upgrade:
877 // @TODO: Note, This doesn't handle the Template changing, or the Template name changing.
878 if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
879 $theme_info = $this->theme_info();
880 $stylesheet = $this->result['destination_name'];
881 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
882 switch_theme($template, $stylesheet, true);
885 //Time to remove maintenance mode
887 $this->maintenance_mode(false);
891 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
892 global $wp_filesystem;
894 $theme = isset($theme['theme']) ? $theme['theme'] : '';
896 if ( is_wp_error($removed) || empty($theme) )
897 return $removed; //Pass errors through.
899 $themes_dir = $wp_filesystem->wp_themes_dir();
900 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
901 if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
906 function theme_info($theme = null) {
908 if ( empty($theme) ) {
909 if ( !empty($this->result['destination_name']) )
910 $theme = $this->result['destination_name'];
914 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
920 * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file
922 * @TODO More Detailed docs, for methods as well.
925 * @subpackage Upgrader
928 class Core_Upgrader extends WP_Upgrader {
930 function upgrade_strings() {
931 $this->strings['up_to_date'] = __('WordPress is at the latest version.');
932 $this->strings['no_package'] = __('Update package not available.');
933 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
934 $this->strings['unpack_package'] = __('Unpacking the update…');
935 $this->strings['copy_failed'] = __('Could not copy files.');
938 function upgrade($current) {
939 global $wp_filesystem, $wp_version;
942 $this->upgrade_strings();
944 if ( !empty($feedback) )
945 add_filter('update_feedback', $feedback);
947 // Is an update available?
948 if ( !isset( $current->response ) || $current->response == 'latest' )
949 return new WP_Error('up_to_date', $this->strings['up_to_date']);
951 $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
952 if ( is_wp_error($res) )
955 $wp_dir = trailingslashit($wp_filesystem->abspath());
957 // If partial update is returned from the API, use that, unless we're doing a reinstall.
958 // If we cross the new_bundled version number, then use the new_bundled zip.
959 // Don't though if the constant is set to skip bundled items.
960 // If the API returns a no_content zip, go with it. Finally, default to the full zip.
961 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
962 $to_download = 'partial';
963 elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
964 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
965 $to_download = 'new_bundled';
966 elseif ( $current->packages->no_content )
967 $to_download = 'no_content';
969 $to_download = 'full';
971 $download = $this->download_package( $current->packages->$to_download );
972 if ( is_wp_error($download) )
975 $working_dir = $this->unpack_package( $download );
976 if ( is_wp_error($working_dir) )
979 // Copy update-core.php from the new version into place.
980 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
981 $wp_filesystem->delete($working_dir, true);
982 return new WP_Error('copy_failed', $this->strings['copy_failed']);
984 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
986 require(ABSPATH . 'wp-admin/includes/update-core.php');
988 return update_core($working_dir, $wp_dir);
994 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
996 * @TODO More Detailed docs, for methods as well.
999 * @subpackage Upgrader
1002 class WP_Upgrader_Skin {
1005 var $done_header = false;
1006 var $result = false;
1008 function __construct($args = array()) {
1009 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
1010 $this->options = wp_parse_args($args, $defaults);
1013 function set_upgrader(&$upgrader) {
1014 if ( is_object($upgrader) )
1015 $this->upgrader =& $upgrader;
1016 $this->add_strings();
1019 function add_strings() {
1022 function set_result($result) {
1023 $this->result = $result;
1026 function request_filesystem_credentials($error = false) {
1027 $url = $this->options['url'];
1028 $context = $this->options['context'];
1029 if ( !empty($this->options['nonce']) )
1030 $url = wp_nonce_url($url, $this->options['nonce']);
1031 return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
1035 if ( $this->done_header )
1037 $this->done_header = true;
1038 echo '<div class="wrap">';
1040 echo '<h2>' . $this->options['title'] . '</h2>';
1046 function error($errors) {
1047 if ( ! $this->done_header )
1049 if ( is_string($errors) ) {
1050 $this->feedback($errors);
1051 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
1052 foreach ( $errors->get_error_messages() as $message ) {
1053 if ( $errors->get_error_data() )
1054 $this->feedback($message . ' ' . $errors->get_error_data() );
1056 $this->feedback($message);
1061 function feedback($string) {
1062 if ( isset( $this->upgrader->strings[$string] ) )
1063 $string = $this->upgrader->strings[$string];
1065 if ( strpos($string, '%') !== false ) {
1066 $args = func_get_args();
1067 $args = array_splice($args, 1);
1068 if ( !empty($args) )
1069 $string = vsprintf($string, $args);
1071 if ( empty($string) )
1073 show_message($string);
1075 function before() {}
1081 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1083 * @TODO More Detailed docs, for methods as well.
1085 * @package WordPress
1086 * @subpackage Upgrader
1089 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
1091 var $plugin_active = false;
1092 var $plugin_network_active = false;
1094 function __construct($args = array()) {
1095 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
1096 $args = wp_parse_args($args, $defaults);
1098 $this->plugin = $args['plugin'];
1100 $this->plugin_active = is_plugin_active( $this->plugin );
1101 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
1103 parent::__construct($args);
1107 $this->plugin = $this->upgrader->plugin_info();
1108 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
1109 show_message(__('Reactivating the plugin…'));
1110 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>';
1113 $update_actions = array(
1114 '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>',
1115 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
1117 if ( $this->plugin_active )
1118 unset( $update_actions['activate_plugin'] );
1119 if ( ! $this->result || is_wp_error($this->result) )
1120 unset( $update_actions['activate_plugin'] );
1122 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
1123 if ( ! empty($update_actions) )
1124 $this->feedback(implode(' | ', (array)$update_actions));
1128 if ( $this->upgrader->show_before ) {
1129 echo $this->upgrader->show_before;
1130 $this->upgrader->show_before = '';
1136 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1138 * @package WordPress
1139 * @subpackage Upgrader
1142 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
1143 var $in_loop = false;
1146 function __construct($args = array()) {
1147 $defaults = array( 'url' => '', 'nonce' => '' );
1148 $args = wp_parse_args($args, $defaults);
1150 parent::__construct($args);
1153 function add_strings() {
1154 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
1155 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.');
1156 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
1157 $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>';
1158 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
1161 function feedback($string) {
1162 if ( isset( $this->upgrader->strings[$string] ) )
1163 $string = $this->upgrader->strings[$string];
1165 if ( strpos($string, '%') !== false ) {
1166 $args = func_get_args();
1167 $args = array_splice($args, 1);
1168 if ( !empty($args) )
1169 $string = vsprintf($string, $args);
1171 if ( empty($string) )
1173 if ( $this->in_loop )
1174 echo "$string<br />\n";
1176 echo "<p>$string</p>\n";
1180 // Nothing, This will be displayed within a iframe.
1184 // Nothing, This will be displayed within a iframe.
1186 function error($error) {
1187 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
1188 $this->error = $this->upgrader->strings[$error];
1190 if ( is_wp_error($error) ) {
1191 foreach ( $error->get_error_messages() as $emessage ) {
1192 if ( $error->get_error_data() )
1193 $messages[] = $emessage . ' ' . $error->get_error_data();
1195 $messages[] = $emessage;
1197 $this->error = implode(', ', $messages);
1199 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1202 function bulk_header() {
1203 $this->feedback('skin_upgrade_start');
1206 function bulk_footer() {
1207 $this->feedback('skin_upgrade_end');
1210 function before($title = '') {
1211 $this->in_loop = true;
1212 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);
1213 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1214 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
1215 $this->flush_output();
1218 function after($title = '') {
1220 if ( $this->error || ! $this->result ) {
1222 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
1224 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
1226 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1228 if ( !empty($this->result) && !is_wp_error($this->result) ) {
1229 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>';
1230 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1234 $this->flush_output();
1238 $this->in_loop = false;
1239 $this->error = false;
1242 function flush_output() {
1243 wp_ob_end_flush_all();
1248 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
1249 var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
1251 function __construct($args = array()) {
1252 parent::__construct($args);
1255 function add_strings() {
1256 parent::add_strings();
1257 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
1261 parent::before($this->plugin_info['Title']);
1265 parent::after($this->plugin_info['Title']);
1267 function bulk_footer() {
1268 parent::bulk_footer();
1269 $update_actions = array(
1270 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
1271 '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>'
1274 $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
1275 if ( ! empty($update_actions) )
1276 $this->feedback(implode(' | ', (array)$update_actions));
1280 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
1281 var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
1283 function __construct($args = array()) {
1284 parent::__construct($args);
1287 function add_strings() {
1288 parent::add_strings();
1289 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
1293 parent::before($this->theme_info['Name']);
1297 parent::after($this->theme_info['Name']);
1299 function bulk_footer() {
1300 parent::bulk_footer();
1301 $update_actions = array(
1302 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
1303 '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>'
1306 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
1307 if ( ! empty($update_actions) )
1308 $this->feedback(implode(' | ', (array)$update_actions));
1313 * Plugin Installer Skin for WordPress Plugin Installer.
1315 * @TODO More Detailed docs, for methods as well.
1317 * @package WordPress
1318 * @subpackage Upgrader
1321 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
1325 function __construct($args = array()) {
1326 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
1327 $args = wp_parse_args($args, $defaults);
1329 $this->type = $args['type'];
1330 $this->api = isset($args['api']) ? $args['api'] : array();
1332 parent::__construct($args);
1336 if ( !empty($this->api) )
1337 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
1342 $plugin_file = $this->upgrader->plugin_info();
1344 $install_actions = array();
1346 $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
1348 if ( 'import' == $from )
1349 $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>';
1351 $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>';
1353 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
1354 $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>';
1355 unset( $install_actions['activate_plugin'] );
1358 if ( 'import' == $from )
1359 $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
1360 else if ( $this->type == 'web' )
1361 $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>';
1363 $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>';
1366 if ( ! $this->result || is_wp_error($this->result) ) {
1367 unset( $install_actions['activate_plugin'] );
1368 unset( $install_actions['network_activate'] );
1370 $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
1371 if ( ! empty($install_actions) )
1372 $this->feedback(implode(' | ', (array)$install_actions));
1377 * Theme Installer Skin for the WordPress Theme Installer.
1379 * @TODO More Detailed docs, for methods as well.
1381 * @package WordPress
1382 * @subpackage Upgrader
1385 class Theme_Installer_Skin extends WP_Upgrader_Skin {
1389 function __construct($args = array()) {
1390 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
1391 $args = wp_parse_args($args, $defaults);
1393 $this->type = $args['type'];
1394 $this->api = isset($args['api']) ? $args['api'] : array();
1396 parent::__construct($args);
1400 if ( !empty($this->api) ) {
1401 /* translators: 1: theme name, 2: version */
1402 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
1407 if ( empty($this->upgrader->result['destination_name']) )
1410 $theme_info = $this->upgrader->theme_info();
1411 if ( empty($theme_info) )
1413 $name = $theme_info['Name'];
1414 $stylesheet = $this->upgrader->result['destination_name'];
1415 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1417 $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'))) ) );
1418 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1420 $install_actions = array(
1421 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>',
1422 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'
1425 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
1426 $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . $template, 'enable-theme_' . $template ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
1428 if ( $this->type == 'web' )
1429 $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>';
1431 $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
1433 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() )
1434 unset( $install_actions['activate'], $install_actions['preview'] );
1436 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
1437 if ( ! empty($install_actions) )
1438 $this->feedback(implode(' | ', (array)$install_actions));
1443 * Theme Upgrader Skin for WordPress Theme Upgrades.
1445 * @TODO More Detailed docs, for methods as well.
1447 * @package WordPress
1448 * @subpackage Upgrader
1451 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
1454 function __construct($args = array()) {
1455 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
1456 $args = wp_parse_args($args, $defaults);
1458 $this->theme = $args['theme'];
1460 parent::__construct($args);
1465 $update_actions = array();
1466 if ( !empty($this->upgrader->result['destination_name']) &&
1467 ($theme_info = $this->upgrader->theme_info()) &&
1468 !empty($theme_info) ) {
1470 $name = $theme_info['Name'];
1471 $stylesheet = $this->upgrader->result['destination_name'];
1472 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1474 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1475 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1477 $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>';
1478 $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
1480 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
1481 unset($update_actions['preview'], $update_actions['activate']);
1484 $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>';
1486 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
1487 if ( ! empty($update_actions) )
1488 $this->feedback(implode(' | ', (array)$update_actions));
1493 * 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.
1495 * @TODO More Detailed docs, for methods as well.
1497 * @package WordPress
1498 * @subpackage Upgrader
1501 class File_Upload_Upgrader {
1506 function __construct($form, $urlholder) {
1508 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
1509 wp_die(__('Please select a file'));
1511 //Handle a newly uploaded file, Else assume its already been uploaded
1512 if ( ! empty($_FILES) ) {
1513 $overrides = array( 'test_form' => false, 'test_type' => false );
1514 $file = wp_handle_upload( $_FILES[$form], $overrides );
1516 if ( isset( $file['error'] ) )
1517 wp_die( $file['error'] );
1519 $this->filename = $_FILES[$form]['name'];
1520 $this->package = $file['file'];
1522 // Construct the object array
1524 'post_title' => $this->filename,
1525 'post_content' => $file['url'],
1526 'post_mime_type' => $file['type'],
1527 'guid' => $file['url'],
1528 'context' => 'upgrader',
1529 'post_status' => 'private'
1533 $this->id = wp_insert_attachment( $object, $file['file'] );
1535 // schedule a cleanup for 2 hours from now in case of failed install
1536 wp_schedule_single_event( time() + 7200, 'upgrader_scheduled_cleanup', array( $this->id ) );
1538 } elseif ( is_numeric( $_GET[$urlholder] ) ) {
1539 // Numeric Package = previously uploaded file, see above.
1540 $this->id = (int) $_GET[$urlholder];
1541 $attachment = get_post( $this->id );
1542 if ( empty($attachment) )
1543 wp_die(__('Please select a file'));
1545 $this->filename = $attachment->post_title;
1546 $this->package = get_attached_file( $attachment->ID );
1548 // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
1549 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
1550 wp_die( $uploads['error'] );
1552 $this->filename = $_GET[$urlholder];
1553 $this->package = $uploads['basedir'] . '/' . $this->filename;
1557 function cleanup() {
1559 wp_delete_attachment( $this->id );
1561 elseif ( file_exists( $this->package ) )
1562 return @unlink( $this->package );