-}
-
-/**
- * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins 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 Plugin_Upgrader extends WP_Upgrader {
-
- var $result;
-
- function upgrade_strings() {
- $this->strings['up_to_date'] = __('The plugin 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['deactivate_plugin'] = __('Deactivating the plugin.');
- $this->strings['remove_old'] = __('Removing the old version of the plugin.');
- $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
- $this->strings['process_failed'] = __('Plugin upgrade Failed.');
- $this->strings['process_success'] = __('Plugin 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 plugin.');
- $this->strings['process_failed'] = __('Plugin Install Failed.');
- $this->strings['process_success'] = __('Plugin Installed successfully.');
- }
-
- function install($package) {
-
- $this->init();
- $this->install_strings();
-
- $this->run(array(
- 'package' => $package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true,
- 'hook_extra' => array()
- ));
-
- // Force refresh of plugin update information
- delete_transient('update_plugins');
-
- }
-
- function upgrade($plugin) {
-
- $this->init();
- $this->upgrade_strings();
-
- $current = get_transient( 'update_plugins' );
- if ( !isset( $current->response[ $plugin ] ) ) {
- $this->skin->set_result(false);
- $this->skin->error('up_to_date');
- $this->skin->after();
- return false;
- }
-
- // Get the URL to the zip file
- $r = $current->response[ $plugin ];
-
- add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
- add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
- //'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.
-
- $this->run(array(
- 'package' => $r->package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => true,
- 'clear_working' => true,
- 'hook_extra' => array(
- 'plugin' => $plugin
- )
- ));
-
- //Cleanup our hooks, incase something else does a upgrade on this connection.
- remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
- remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
-
- if ( ! $this->result || is_wp_error($this->result) )
- return $this->result;
-
- // Force refresh of plugin update information
- delete_transient('update_plugins');
- }
-
- //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;