- // Get the URL to the zip file
- $r = $current->response[ $plugin ];
-
- $this->skin->plugin_active = is_plugin_active($plugin);
-
- $result = $this->run(array(
- 'package' => $r->package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => true,
- 'clear_working' => true,
- 'is_multi' => true,
- 'hook_extra' => array(
- 'plugin' => $plugin
- )
- ));
-
- $results[$plugin] = $this->result;
-
- // Prevent credentials auth screen from displaying multiple times
- if ( false === $result )
- break;
- }
- $this->maintenance_mode(false);
- $this->skin->footer();
-
- // Cleanup our hooks, incase something else does a upgrade on this connection.
- remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
-
- // Force refresh of plugin update information
- delete_transient('update_plugins');
-
- return $results;
- }
-
- //return plugin info.
- function plugin_info() {
- if ( ! is_array($this->result) )
- return false;
- if ( empty($this->result['destination_name']) )
- return false;
-
- $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
- if ( empty($plugin) )
- return false;
-
- $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
-
- return $this->result['destination_name'] . '/' . $pluginfiles[0];
- }
-
- //Hooked to pre_install
- function deactivate_plugin_before_upgrade($return, $plugin) {
-
- if ( is_wp_error($return) ) //Bypass.
- return $return;
-
- $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
- if ( empty($plugin) )
- return new WP_Error('bad_request', $this->strings['bad_request']);
-
- if ( is_plugin_active($plugin) ) {
- $this->skin->feedback('deactivate_plugin');
- //Deactivate the plugin silently, Prevent deactivation hooks from running.
- deactivate_plugins($plugin, true);
- }
- }
-
- //Hooked to upgrade_clear_destination
- function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
- global $wp_filesystem;
-
- if ( is_wp_error($removed) )
- return $removed; //Pass errors through.
-
- $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
- if ( empty($plugin) )
- return new WP_Error('bad_request', $this->strings['bad_request']);
-
- $plugins_dir = $wp_filesystem->wp_plugins_dir();
- $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
-
- if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
- return $removed;
-
- // If plugin is in its own directory, recursively delete the directory.
- if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
- $deleted = $wp_filesystem->delete($this_plugin_dir, true);
- else
- $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
-
- if ( ! $deleted )
- return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
-
- return $removed;
- }
-}
-
-/**
- * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
- *
- * @TODO More Detailed docs, for methods as well.
- *
- * @package WordPress
- * @subpackage Upgrader
- * @since 2.8.0
- */
-class Theme_Upgrader extends WP_Upgrader {
-
- var $result;
-
- function upgrade_strings() {
- $this->strings['up_to_date'] = __('The theme is at the latest version.');
- $this->strings['no_package'] = __('Upgrade package not available.');
- $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>.');
- $this->strings['unpack_package'] = __('Unpacking the update.');
- $this->strings['remove_old'] = __('Removing the old version of the theme.');
- $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
- $this->strings['process_failed'] = __('Theme upgrade Failed.');
- $this->strings['process_success'] = __('Theme upgraded successfully.');
- }
-
- function install_strings() {
- $this->strings['no_package'] = __('Install package not available.');
- $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>.');
- $this->strings['unpack_package'] = __('Unpacking the package.');
- $this->strings['installing_package'] = __('Installing the theme.');
- $this->strings['process_failed'] = __('Theme Install Failed.');
- $this->strings['process_success'] = __('Theme Installed successfully.');
- }
-
- function install($package) {
-
- $this->init();
- $this->install_strings();
-
- $options = array(
- 'package' => $package,
- 'destination' => WP_CONTENT_DIR . '/themes',
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true
- );
-
- $this->run($options);
-
- if ( ! $this->result || is_wp_error($this->result) )
- return $this->result;
-
- // Force refresh of theme update information
- delete_transient('update_themes');
-
- if ( empty($result['destination_name']) )
- return false;
- else
- return $result['destination_name'];
- }
-
- function upgrade($theme) {
-
- $this->init();
- $this->upgrade_strings();
-
- // Is an update available?
- $current = get_transient( 'update_themes' );
- if ( !isset( $current->response[ $theme ] ) ) {
- $this->skin->set_result(false);
- $this->skin->error('up_to_date');
- $this->skin->after();
- return false;
- }
-
- $r = $current->response[ $theme ];
-
- add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
- add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
- add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
-
- $options = array(
- 'package' => $r['package'],
- 'destination' => WP_CONTENT_DIR . '/themes',
- 'clear_destination' => true,
- 'clear_working' => true,
- 'hook_extra' => array(
- 'theme' => $theme
- )
- );
-
- $this->run($options);
-
- if ( ! $this->result || is_wp_error($this->result) )
- return $this->result;
-
- // Force refresh of theme update information
- delete_transient('update_themes');
-
- return true;
- }
-
- function current_before($return, $theme) {
-
- if ( is_wp_error($return) )
- return $return;
-
- $theme = isset($theme['theme']) ? $theme['theme'] : '';
-
- if ( $theme != get_stylesheet() ) //If not current
- return $return;
- //Change to maintainence mode now.
- $this->maintenance_mode(true);
-
- return $return;
- }
- function current_after($return, $theme) {
- if ( is_wp_error($return) )
- return $return;
-
- $theme = isset($theme['theme']) ? $theme['theme'] : '';
-
- if ( $theme != get_stylesheet() ) //If not current
- return $return;
-
- //Ensure stylesheet name hasnt changed after the upgrade:
- if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
- $theme_info = $this->theme_info();
- $stylesheet = $this->result['destination_name'];
- $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
- switch_theme($template, $stylesheet, true);
- }
-
- //Time to remove maintainence mode
- $this->maintenance_mode(false);
- return $return;
- }
-
- function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
- global $wp_filesystem;
-
- $theme = isset($theme['theme']) ? $theme['theme'] : '';
-
- if ( is_wp_error($removed) || empty($theme) )
- return $removed; //Pass errors through.
-
- $themes_dir = $wp_filesystem->wp_themes_dir();
- if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
- if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )