File "class-plugin-upgrader.php"
Full path: /home/kosmetik/public_html/wp-includes/wp-admin/includes/class-plugin-upgrader.php
File
size: 13.4 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
class Plugin_Upgrader extends WP_Upgrader
{
public $result;
public $bulk = false;
public $new_plugin_data = array();
public function upgrade_strings()
{
$this->strings['up_to_date'] = __('The plugin is at the latest version.');
$this->strings['no_package'] = __('Update package not available.');
$this->strings['downloading_package'] = sprintf(__('Downloading update from %s…'), '<span class="code">%s</span>');
$this->strings['unpack_package'] = __('Unpacking the update…');
$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 update failed.');
$this->strings['process_success'] = __('Plugin updated successfully.');
$this->strings['process_bulk_success'] = __('Plugins updated successfully.');
}
public function install_strings()
{
$this->strings['no_package'] = __('Installation package not available.');
$this->strings['downloading_package'] = sprintf(__('Downloading installation package from %s…'), '<span class="code">%s</span>');
$this->strings['unpack_package'] = __('Unpacking the package…');
$this->strings['installing_package'] = __('Installing the plugin…');
$this->strings['remove_old'] = __('Removing the current plugin…');
$this->strings['remove_old_failed'] = __('Could not remove the current plugin.');
$this->strings['no_files'] = __('The plugin contains no files.');
$this->strings['process_failed'] = __('Plugin installation failed.');
$this->strings['process_success'] = __('Plugin installed successfully.');
$this->strings['process_success_specific'] = __('Successfully installed the plugin <strong>%1$s %2$s</strong>.');
if (!empty($this->skin->overwrite)) {
if ('update-plugin' === $this->skin->overwrite) {
$this->strings['installing_package'] = __('Updating the plugin…');
$this->strings['process_failed'] = __('Plugin update failed.');
$this->strings['process_success'] = __('Plugin updated successfully.');
}
if ('downgrade-plugin' === $this->skin->overwrite) {
$this->strings['installing_package'] = __('Downgrading the plugin…');
$this->strings['process_failed'] = __('Plugin downgrade failed.');
$this->strings['process_success'] = __('Plugin downgraded successfully.');
}
}
}
public function install($package, $args = array())
{
$defaults = array('clear_update_cache' => true, 'overwrite_package' => false);
$parsed_args = wp_parse_args($args, $defaults);
$this->init();
$this->install_strings();
add_filter('upgrader_source_selection', array($this, 'check_package'));
if ($parsed_args['clear_update_cache']) {
add_action('upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0);
}
$this->run(array('package' => $package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => $parsed_args['overwrite_package'], 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install')));
remove_action('upgrader_process_complete', 'wp_clean_plugins_cache', 9);
remove_filter('upgrader_source_selection', array($this, 'check_package'));
if (!$this->result || is_wp_error($this->result)) {
return $this->result;
}
wp_clean_plugins_cache($parsed_args['clear_update_cache']);
if ($parsed_args['overwrite_package']) {
do_action('upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin');
}
return true;
}
public function upgrade($plugin, $args = array())
{
$defaults = array('clear_update_cache' => true);
$parsed_args = wp_parse_args($args, $defaults);
$this->init();
$this->upgrade_strings();
$current = get_site_transient('update_plugins');
if (!isset($current->response[$plugin])) {
$this->skin->before();
$this->skin->set_result(false);
$this->skin->error('up_to_date');
$this->skin->after();
return false;
}
$r = $current->response[$plugin];
add_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'), 10, 2);
add_filter('upgrader_pre_install', array($this, 'active_before'), 10, 2);
add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
add_filter('upgrader_post_install', array($this, 'active_after'), 10, 2);
if ($parsed_args['clear_update_cache']) {
add_action('upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0);
}
$this->run(array('package' => $r->package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin, 'type' => 'plugin', 'action' => 'update')));
remove_action('upgrader_process_complete', 'wp_clean_plugins_cache', 9);
remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'));
remove_filter('upgrader_pre_install', array($this, 'active_before'));
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
remove_filter('upgrader_post_install', array($this, 'active_after'));
if (!$this->result || is_wp_error($this->result)) {
return $this->result;
}
wp_clean_plugins_cache($parsed_args['clear_update_cache']);
$past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
if (isset($past_failure_emails[$plugin])) {
unset($past_failure_emails[$plugin]);
update_option('auto_plugin_theme_update_emails', $past_failure_emails);
}
return true;
}
public function bulk_upgrade($plugins, $args = array())
{
$defaults = array('clear_update_cache' => true);
$parsed_args = wp_parse_args($args, $defaults);
$this->init();
$this->bulk = true;
$this->upgrade_strings();
$current = get_site_transient('update_plugins');
add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
$this->skin->header();
$res = $this->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
if (!$res) {
$this->skin->footer();
return false;
}
$this->skin->bulk_header();
$maintenance = is_multisite() && !empty($plugins);
foreach ($plugins as $plugin) {
$maintenance = $maintenance || is_plugin_active($plugin) && isset($current->response[$plugin]);
}
if ($maintenance) {
$this->maintenance_mode(true);
}
$results = array();
$this->update_count = count($plugins);
$this->update_current = 0;
foreach ($plugins as $plugin) {
$this->update_current++;
$this->skin->plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false, true);
if (!isset($current->response[$plugin])) {
$this->skin->set_result('up_to_date');
$this->skin->before();
$this->skin->feedback('up_to_date');
$this->skin->after();
$results[$plugin] = true;
continue;
}
$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;
if (false === $result) {
break;
}
}
$this->maintenance_mode(false);
wp_clean_plugins_cache($parsed_args['clear_update_cache']);
do_action('upgrader_process_complete', $this, array('action' => 'update', 'type' => 'plugin', 'bulk' => true, 'plugins' => $plugins));
$this->skin->bulk_footer();
$this->skin->footer();
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
$past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
foreach ($results as $plugin => $result) {
if (!$result || is_wp_error($result) || !isset($past_failure_emails[$plugin])) {
continue;
}
unset($past_failure_emails[$plugin]);
}
update_option('auto_plugin_theme_update_emails', $past_failure_emails);
return $results;
}
public function check_package($source)
{
global $wp_filesystem, $wp_version;
$this->new_plugin_data = array();
if (is_wp_error($source)) {
return $source;
}
$working_directory = str_replace($wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
if (!is_dir($working_directory)) {
return $source;
}
$files = glob($working_directory . '*.php');
if ($files) {
foreach ($files as $file) {
$info = get_plugin_data($file, false, false);
if (!empty($info['Name'])) {
$this->new_plugin_data = $info;
break;
}
}
}
if (empty($this->new_plugin_data)) {
return new WP_Error('incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __('No valid plugins were found.'));
}
$requires_php = isset($info['RequiresPHP']) ? $info['RequiresPHP'] : null;
$requires_wp = isset($info['RequiresWP']) ? $info['RequiresWP'] : null;
if (!is_php_version_compatible($requires_php)) {
$error = sprintf(__('The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.'), phpversion(), $requires_php);
return new WP_Error('incompatible_php_required_version', $this->strings['incompatible_archive'], $error);
}
if (!is_wp_version_compatible($requires_wp)) {
$error = sprintf(__('Your WordPress version is %1$s, however the uploaded plugin requires %2$s.'), $wp_version, $requires_wp);
return new WP_Error('incompatible_wp_required_version', $this->strings['incompatible_archive'], $error);
}
return $source;
}
public 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']);
if (empty($plugin)) {
return false;
}
$pluginfiles = array_keys($plugin);
return $this->result['destination_name'] . '/' . $pluginfiles[0];
}
public function deactivate_plugin_before_upgrade($return, $plugin)
{
if (is_wp_error($return)) {
return $return;
}
if (wp_doing_cron()) {
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)) {
deactivate_plugins($plugin, true);
}
return $return;
}
public function active_before($return, $plugin)
{
if (is_wp_error($return)) {
return $return;
}
if (!wp_doing_cron()) {
return $return;
}
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
if (!is_plugin_active($plugin)) {
return $return;
}
if (!$this->bulk) {
$this->maintenance_mode(true);
}
return $return;
}
public function active_after($return, $plugin)
{
if (is_wp_error($return)) {
return $return;
}
if (!wp_doing_cron()) {
return $return;
}
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
if (!is_plugin_active($plugin)) {
return $return;
}
if (!$this->bulk) {
$this->maintenance_mode(false);
}
return $return;
}
public function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin)
{
global $wp_filesystem;
if (is_wp_error($removed)) {
return $removed;
}
$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)) {
return $removed;
}
if (strpos($plugin, '/') && $this_plugin_dir !== $plugins_dir) {
$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 true;
}
}