Пример #1
0
/**
 * Updates the given list of plugins.
 * 
 * Accepts an array of plugin paths such as 'bruteprotect/bruteprotect.php'
 * Returns a detailed array showing the status of each plugin and a log of messages output during the process
 *
 * @param array $plugins
 * @return array
 */
function bruteprotect_bulk_update_plugins($plugins)
{
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Plugin_Upgrader($skin);
    $results = $upgrader->bulk_upgrade($plugins);
    $messages = $upgrader->skin->get_upgrade_messages();
    $o['results'] = $results;
    $o['messages'] = $messages;
    return $o;
}
Пример #2
0
 public function iframe_intercept($current_screen)
 {
     if ($current_screen->base !== 'mailpoet_page_wysija_config') {
         return;
     }
     if (!isset($_GET['action']) || $_GET['action'] !== 'packager-switch') {
         return;
     }
     // Verify if it's has been created within the last 12 hours (nonce)
     if (wp_verify_nonce($_GET['_wpnonce'], $_GET['action']) !== 1) {
         return;
     }
     // Require the Updater classes
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $to = isset($_GET['stable']) && $_GET['stable'] ? 'stable' : 'beta';
     add_filter('pre_site_transient_update_plugins', array($this, 'pre_site_transient_update_plugins'));
     $plugins = array();
     // Check for the action, it might be upgrading or installing
     $action = 'upgrade';
     if (isset($_GET['_mp_action']) && in_array($_GET['_mp_action'], array('upgrade', 'install'))) {
         $action = strtolower($_GET['_mp_action']);
     }
     foreach (self::$plugins as $k => $plugin) {
         if (is_plugin_active($plugin)) {
             $plugins[] = $plugin;
         }
     }
     // Ajust the Padding/margin of the iFrame
     define('IFRAME_REQUEST', true);
     echo "<div style='margin: 0 20px;'>";
     // Thats how WordPress calls for an iFrame page
     wp_enqueue_script('jquery');
     iframe_header();
     if ($action === 'upgrade') {
         $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
         $upgrader->bulk_upgrade($plugins);
     } elseif ($action === 'install') {
         // If the action is install, it will only happen if it's the Premium
         $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin());
         $result = $upgrader->install(self::get_url(self::$plugins[1], WYSIJA::is_beta(), 'zip'));
     }
     iframe_footer();
     echo "</div>";
     remove_filter('pre_site_transient_update_plugins', array($this, 'pre_site_transient_update_plugins'));
     $model_config = WYSIJA::get('config', 'model');
     $model_config->save(array('beta_mode' => $to === 'stable' ? false : true));
     set_site_transient('update_plugins', '');
     exit;
 }
 /**
  * Handle a bulk upgrade request.
  *
  * @since 2.5.0
  *
  * @see Plugin_Upgrader::bulk_upgrade()
  *
  * @param array $plugins The local WP file_path's of the plugins which should be upgraded.
  * @param array $args    Arbitrary passed extra arguments.
  * @return string|bool Install confirmation messages on success, false on failure.
  */
 public function bulk_upgrade($plugins, $args = array())
 {
     add_filter('upgrader_post_install', array($this, 'auto_activate'), 10);
     $result = parent::bulk_upgrade($plugins, $args);
     remove_filter('upgrader_post_install', array($this, 'auto_activate'), 10);
     return $result;
 }
Пример #4
0
/**
 * AJAX handler for updating a plugin.
 *
 * @since 4.2.0
 *
 * @see Plugin_Upgrader
 */
function wp_ajax_update_plugin()
{
    global $wp_filesystem;
    $plugin = urldecode($_POST['plugin']);
    $status = array('update' => 'plugin', 'plugin' => $plugin, 'slug' => sanitize_key($_POST['slug']), 'oldVersion' => '', 'newVersion' => '');
    $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
    if ($plugin_data['Version']) {
        $status['oldVersion'] = sprintf(__('Version %s'), $plugin_data['Version']);
    }
    if (!current_user_can('update_plugins')) {
        $status['error'] = __('You do not have sufficient permissions to update plugins for this site.');
        wp_send_json_error($status);
    }
    check_ajax_referer('updates');
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    wp_update_plugins();
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Plugin_Upgrader($skin);
    $result = $upgrader->bulk_upgrade(array($plugin));
    if (is_array($result) && empty($result[$plugin]) && is_wp_error($skin->result)) {
        $result = $skin->result;
    }
    if (is_array($result) && !empty($result[$plugin])) {
        $plugin_update_data = current($result);
        /*
         * If the `update_plugins` site transient is empty (e.g. when you update
         * two plugins in quick succession before the transient repopulates),
         * this may be the return.
         *
         * Preferably something can be done to ensure `update_plugins` isn't empty.
         * For now, surface some sort of error here.
         */
        if ($plugin_update_data === true) {
            $status['error'] = __('Plugin update failed.');
            wp_send_json_error($status);
        }
        $plugin_data = get_plugins('/' . $result[$plugin]['destination_name']);
        $plugin_data = reset($plugin_data);
        if ($plugin_data['Version']) {
            $status['newVersion'] = sprintf(__('Version %s'), $plugin_data['Version']);
        }
        wp_send_json_success($status);
    } else {
        if (is_wp_error($result)) {
            $status['error'] = $result->get_error_message();
            wp_send_json_error($status);
        } else {
            if (is_bool($result) && !$result) {
                $status['errorCode'] = 'unable_to_connect_to_filesystem';
                $status['error'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
                // Pass through the error from WP_Filesystem if one was raised
                if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
                    $status['error'] = $wp_filesystem->errors->get_error_message();
                }
                wp_send_json_error($status);
            } else {
                // An unhandled error occured
                $status['error'] = __('Plugin update failed.');
                wp_send_json_error($status);
            }
        }
    }
}
Пример #5
0
     }
     check_admin_referer('bulk-update-plugins');
     if (isset($_GET['plugins'])) {
         $plugins = explode(',', stripslashes($_GET['plugins']));
     } elseif (isset($_POST['checked'])) {
         $plugins = (array) $_POST['checked'];
     } else {
         $plugins = array();
     }
     $plugins = array_map('urldecode', $plugins);
     $url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
     $nonce = 'bulk-update-plugins';
     wp_enqueue_script('updates');
     iframe_header();
     $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
     $upgrader->bulk_upgrade($plugins);
     iframe_footer();
 } elseif ('upgrade-plugin' == $action) {
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
     }
     check_admin_referer('upgrade-plugin_' . $plugin);
     $title = __('Update Plugin');
     $parent_file = 'plugins.php';
     $submenu_file = 'plugins.php';
     wp_enqueue_script('updates');
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $nonce = 'upgrade-plugin_' . $plugin;
     $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode($plugin);
     $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')));
     $upgrader->upgrade($plugin);
Пример #6
0
 /**
  * Expects $_POST['type'] == plugin/theme
  * $_POST['list'] == 'theme1,theme2' or 'plugin1,plugin2'
  */
 function upgradePluginTheme()
 {
     //Prevent disable/re-enable at upgrade
     define('DOING_CRON', true);
     MainWP_Helper::getWPFilesystem();
     include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     //        if (file_exists(ABSPATH . '/wp-admin/includes/deprecated.php')) include_once(ABSPATH . '/wp-admin/includes/deprecated.php');
     if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) {
         include_once ABSPATH . '/wp-admin/includes/screen.php';
     }
     if (file_exists(ABSPATH . '/wp-admin/includes/template.php')) {
         include_once ABSPATH . '/wp-admin/includes/template.php';
     }
     if (file_exists(ABSPATH . '/wp-admin/includes/misc.php')) {
         include_once ABSPATH . '/wp-admin/includes/misc.php';
     }
     include_once ABSPATH . '/wp-admin/includes/file.php';
     include_once ABSPATH . '/wp-admin/includes/plugin.php';
     $information = array();
     $information['upgrades'] = array();
     $mwp_premium_updates_todo = array();
     $mwp_premium_updates_todo_slugs = array();
     if (isset($_POST['type']) && 'plugin' === $_POST['type']) {
         include_once ABSPATH . '/wp-admin/includes/update.php';
         if (null !== $this->filterFunction) {
             add_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
         }
         $plugins = explode(',', urldecode($_POST['list']));
         // To fix: backupbuddy update
         if (in_array('backupbuddy/backupbuddy.php', $plugins)) {
             if (isset($GLOBALS['ithemes_updater_path'])) {
                 if (!class_exists('Ithemes_Updater_Settings')) {
                     require $GLOBALS['ithemes_updater_path'] . '/settings.php';
                 }
                 if (class_exists('Ithemes_Updater_Settings')) {
                     $ithemes_updater = new Ithemes_Updater_Settings();
                     $ithemes_updater->update();
                 }
             }
         }
         ////
         global $wp_current_filter;
         $wp_current_filter[] = 'load-plugins.php';
         @wp_update_plugins();
         $information['plugin_updates'] = get_plugin_updates();
         $plugins = explode(',', urldecode($_POST['list']));
         $premiumPlugins = array();
         $premiumUpdates = get_option('mainwp_premium_updates');
         if (is_array($premiumUpdates)) {
             $newPlugins = array();
             foreach ($plugins as $plugin) {
                 if (in_array($plugin, $premiumUpdates)) {
                     $premiumPlugins[] = $plugin;
                 } else {
                     $newPlugins[] = $plugin;
                 }
             }
             $plugins = $newPlugins;
         }
         if (count($plugins) > 0) {
             //@see wp-admin/update.php
             $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
             $result = $upgrader->bulk_upgrade($plugins);
             if (!empty($result)) {
                 foreach ($result as $plugin => $info) {
                     if (empty($info)) {
                         $information['upgrades'][$plugin] = false;
                     } else {
                         $information['upgrades'][$plugin] = true;
                     }
                 }
             } else {
                 MainWP_Helper::error(__('Bad request', 'mainwp-child'));
             }
         }
         if (count($premiumPlugins) > 0) {
             $mwp_premium_updates = apply_filters('mwp_premium_perform_update', array());
             if (is_array($mwp_premium_updates) && is_array($premiumPlugins)) {
                 foreach ($premiumPlugins as $premiumPlugin) {
                     foreach ($mwp_premium_updates as $key => $update) {
                         $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                         if (0 === strcmp($slug, $premiumPlugin)) {
                             $mwp_premium_updates_todo[$key] = $update;
                             $mwp_premium_updates_todo_slugs[] = $premiumPlugin;
                         }
                     }
                 }
             }
             unset($mwp_premium_updates);
             $premiumUpgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
         }
         if (count($plugins) <= 0 && count($premiumPlugins) <= 0) {
             MainWP_Helper::error(__('Bad request', 'mainwp-child'));
         }
         if (null !== $this->filterFunction) {
             remove_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
         }
     } else {
         if (isset($_POST['type']) && 'theme' === $_POST['type']) {
             include_once ABSPATH . '/wp-admin/includes/update.php';
             if (null !== $this->filterFunction) {
                 add_filter('pre_site_transient_update_themes', $this->filterFunction, 99);
             }
             @wp_update_themes();
             include_once ABSPATH . '/wp-admin/includes/theme.php';
             $information['theme_updates'] = $this->upgrade_get_theme_updates();
             $themes = explode(',', $_POST['list']);
             $premiumThemes = array();
             $premiumUpdates = get_option('mainwp_premium_updates');
             if (is_array($premiumUpdates)) {
                 $newThemes = array();
                 foreach ($themes as $theme) {
                     if (in_array($theme, $premiumUpdates)) {
                         $premiumThemes[] = $theme;
                     } else {
                         $newThemes[] = $theme;
                     }
                 }
                 $themes = $newThemes;
             }
             if (count($themes) > 0) {
                 // To fix: optimizePressTheme update
                 $addFilterToFixUpdate_optimizePressTheme = false;
                 if (in_array('optimizePressTheme', $themes)) {
                     $addFilterToFixUpdate_optimizePressTheme = true;
                     add_filter('site_transient_update_themes', array($this, 'hookFixOptimizePressThemeUpdate'), 99);
                 }
                 //@see wp-admin/update.php
                 $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
                 $result = $upgrader->bulk_upgrade($themes);
                 if ($addFilterToFixUpdate_optimizePressTheme) {
                     remove_filter('site_transient_update_themes', array($this, 'hookFixOptimizePressThemeUpdate'), 99);
                 }
                 if (!empty($result)) {
                     foreach ($result as $theme => $info) {
                         if (empty($info)) {
                             $information['upgrades'][$theme] = false;
                         } else {
                             $information['upgrades'][$theme] = true;
                         }
                     }
                 } else {
                     MainWP_Helper::error(__('Bad request', 'mainwp-child'));
                 }
             }
             if (count($premiumThemes) > 0) {
                 $mwp_premium_updates = apply_filters('mwp_premium_perform_update', array());
                 $mwp_premium_updates_todo = array();
                 $mwp_premium_updates_todo_slugs = array();
                 if (is_array($premiumThemes) && is_array($mwp_premium_updates)) {
                     foreach ($premiumThemes as $premiumTheme) {
                         foreach ($mwp_premium_updates as $key => $update) {
                             $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                             if (0 === strcmp($slug, $premiumTheme)) {
                                 $mwp_premium_updates_todo[$key] = $update;
                                 $mwp_premium_updates_todo_slugs[] = $slug;
                             }
                         }
                     }
                 }
                 unset($mwp_premium_updates);
                 $premiumUpgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
             }
             if (count($themes) <= 0 && count($premiumThemes) <= 0) {
                 MainWP_Helper::error(__('Bad request', 'mainwp-child'));
             }
             if (null !== $this->filterFunction) {
                 remove_filter('pre_site_transient_update_themes', $this->filterFunction, 99);
             }
         } else {
             MainWP_Helper::error(__('Bad request', 'mainwp-child'));
         }
     }
     if (count($mwp_premium_updates_todo) > 0) {
         //Upgrade via WP
         //@see wp-admin/update.php
         $result = $premiumUpgrader->bulk_upgrade($mwp_premium_updates_todo_slugs);
         if (!empty($result)) {
             foreach ($result as $plugin => $info) {
                 if (!empty($info)) {
                     $information['upgrades'][$plugin] = true;
                     foreach ($mwp_premium_updates_todo as $key => $update) {
                         $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                         if (0 === strcmp($slug, $plugin)) {
                             //unset($mwp_premium_updates_todo[$key]);
                         }
                     }
                 }
             }
         }
         //Upgrade via callback
         foreach ($mwp_premium_updates_todo as $update) {
             $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
             if (isset($update['url'])) {
                 $installer = new WP_Upgrader();
                 //@see wp-admin/includes/class-wp-upgrader.php
                 $result = $installer->run(array('package' => $update['url'], 'destination' => 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes', 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array()));
                 $information['upgrades'][$slug] = !is_wp_error($result) && !empty($result);
             } else {
                 if (isset($update['callback'])) {
                     if (is_array($update['callback']) && isset($update['callback'][0]) && isset($update['callback'][1])) {
                         $update_result = @call_user_func(array($update['callback'][0], $update['callback'][1]));
                         $information['upgrades'][$slug] = $update_result && true;
                     } else {
                         if (is_string($update['callback'])) {
                             $update_result = @call_user_func($update['callback']);
                             $information['upgrades'][$slug] = $update_result && true;
                         } else {
                             $information['upgrades'][$slug] = false;
                         }
                     }
                 } else {
                     $information['upgrades'][$slug] = false;
                 }
             }
         }
     }
     $information['sync'] = $this->getSiteStats(array(), false);
     MainWP_Helper::write($information);
 }
Пример #7
0
function do_plugin_upgrade()
{
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    if (isset($_GET['plugins'])) {
        $plugins = explode(',', $_GET['plugins']);
    } elseif (isset($_POST['checked'])) {
        $plugins = (array) $_POST['checked'];
    } else {
        // Nothing to do.
        return;
    }
    $url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode(join(',', $plugins));
    $title = __('Upgrade Plugins');
    $nonce = 'upgrade-core';
    $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')));
    $upgrader->bulk_upgrade($plugins);
}
Пример #8
0
 public function upgrade_plugins($plugins = false)
 {
     if (!$plugins || empty($plugins)) {
         return array('error' => 'No plugin files for upgrade.');
     }
     $current = $this->mmb_get_transient('update_plugins');
     $versions = array();
     $return = array();
     if (!empty($current)) {
         foreach ($plugins as $plugin => $data) {
             if (isset($current->checked[$plugin])) {
                 $versions[$current->checked[$plugin]] = $plugin;
             }
         }
     }
     if (class_exists('Plugin_Upgrader')) {
         /** @handled class */
         $upgrader = new Plugin_Upgrader(mwp_container()->getUpdaterSkin());
         $result = $upgrader->bulk_upgrade(array_keys($plugins));
         if (!function_exists('wp_update_plugins')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_plugins();
         $current = $this->mmb_get_transient('update_plugins');
         if (!empty($result)) {
             foreach ($result as $plugin_slug => $plugin_info) {
                 if (!$plugin_info || is_wp_error($plugin_info)) {
                     $return[$plugin_slug] = $this->mmb_get_error($plugin_info);
                 } else {
                     if (!empty($result[$plugin_slug]) || isset($current->checked[$plugin_slug]) && version_compare(array_search($plugin_slug, $versions), $current->checked[$plugin_slug], '<') == true) {
                         $return[$plugin_slug] = 1;
                     } else {
                         $return[$plugin_slug] = 'Could not refresh upgrade transients, please reload website data';
                     }
                 }
             }
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.');
         }
     } else {
         return array('error' => 'WordPress update required first.');
     }
 }
Пример #9
0
 private function do_bulk_upgrade($packages, $type)
 {
     if (!in_array($type, array('plugin', 'theme'))) {
         return new WP_Error('unrecognized-bulk-upgrade-type', "An unrecognized type ({$type}) was passed to do_bulk_upgrade().");
     }
     Ithemes_Sync_Functions::set_time_limit(300);
     $original_versions = array();
     foreach ($packages as $package) {
         if ('plugin' === $type) {
             $file_data = Ithemes_Sync_Functions::get_file_data(WP_PLUGIN_DIR . "/{$package}");
         } else {
             $file_data = Ithemes_Sync_Functions::get_file_data(WP_CONTENT_DIR . "/themes/{$package}/style.css");
         }
         $original_versions[$package] = $file_data['version'];
     }
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     require_once ABSPATH . 'wp-admin/includes/misc.php';
     if ('plugin' === $type) {
         $upgrader = new Plugin_Upgrader($this->skin);
         $result = $upgrader->bulk_upgrade($packages);
         Ithemes_Sync_Functions::refresh_plugin_updates();
     } else {
         $upgrader = new Theme_Upgrader($this->skin);
         $result = $upgrader->bulk_upgrade($packages);
         Ithemes_Sync_Functions::refresh_theme_updates();
     }
     if (is_wp_error($result)) {
         return array('errors' => array($result->get_error_code() => $result->get_error_message()));
     } else {
         if (false === $result) {
             if ('plugin' === $type) {
                 $result = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
             } else {
                 $result = $upgrader->fs_connect(array(WP_CONTENT_DIR));
             }
             if (is_wp_error($result)) {
                 return array('errors' => array($result->get_error_code() => $result->get_error_message()));
             } else {
                 return array('errors' => array('non-connected-filesystem' => 'Unable to update due to a non-connected filesystem.'));
             }
         }
     }
     $update_details = Ithemes_Sync_Functions::get_update_details(array('verbose' => true));
     $response = array();
     $update_index = "{$type}s";
     foreach ($result as $package => $info) {
         if (false === $info) {
             $response[$package]['errors']['non-connected-filesystem'] = 'Unable to update due to a non-connected filesystem.';
         } else {
             if (is_wp_error($info)) {
                 $response[$package]['errors'][$info->get_error_code()] = $info->get_error_message();
             } else {
                 $response[$package]['wordpress_response'] = $info;
                 if ('plugin' === $type) {
                     $file_data = Ithemes_Sync_Functions::get_file_data(WP_PLUGIN_DIR . "/{$package}");
                 } else {
                     $file_data = Ithemes_Sync_Functions::get_file_data(WP_CONTENT_DIR . "/themes/{$package}/style.css");
                 }
                 $response[$package]['current_version'] = $file_data['version'];
                 if (isset($original_versions[$package])) {
                     $response[$package]['original_version'] = $original_versions[$package];
                 }
                 if (isset($update_details[$update_index][$package])) {
                     if ('plugin' === $type && isset($update_details[$update_index][$package]->new_version)) {
                         $response[$package]['current_update_version'] = $update_details[$update_index][$package]->new_version;
                     } else {
                         if ('theme' === $type && isset($update_details[$update_index][$package]['new_version'])) {
                             $response[$package]['current_update_version'] = $update_details[$update_index][$package]['new_version'];
                         }
                     }
                 }
                 if (isset($this->original_update_details[$update_index][$package])) {
                     if ('plugin' === $type && isset($this->original_update_details[$update_index][$package]->new_version)) {
                         $response[$package]['original_update_version'] = $this->original_update_details[$update_index][$package]->new_version;
                     } else {
                         if ('theme' === $type && isset($this->original_update_details[$update_index][$package]['new_version'])) {
                             $response[$package]['original_update_version'] = $this->original_update_details[$update_index][$package]['new_version'];
                         }
                     }
                 }
                 if ('plugin' === $type) {
                     $removed_old_update_data = $GLOBALS['ithemes_sync_request_handler']->remove_old_update_plugins_data($package);
                     if (!is_null($removed_old_update_data)) {
                         $response[$package]['removed_old_update_data'] = $removed_old_update_data;
                     }
                 }
                 if (!isset($response[$package]['original_update_version'])) {
                     $response[$package]['errors']['no-update'] = 'No update was available.';
                 } else {
                     if (version_compare($response[$package]['current_version'], $response[$package]['original_update_version'], '>=')) {
                         $response[$package]['success'] = 1;
                         if (isset($response[$package]['current_update_version'])) {
                             if (version_compare($response[$package]['current_version'], $response[$package]['current_update_version'], '>=')) {
                                 $response[$package]['errors']['old-update-remains-available'] = 'The original update is still listed despite the update working properly.';
                             } else {
                                 $response[$package]['errors']['new-update-available'] = 'An update is available.';
                             }
                         }
                     } else {
                         $response[$package]['errors']['unknown-error'] = 'An unknown error prevented the update from completing successfully.';
                     }
                 }
             }
         }
     }
     return $response;
 }
/**
 * Ajax handler for updating a plugin.
 *
 * @since 4.2.0
 *
 * @see Plugin_Upgrader
 */
function wp_ajax_update_plugin()
{
    check_ajax_referer('updates');
    if (empty($_POST['plugin']) || empty($_POST['slug'])) {
        wp_send_json_error(array('slug' => '', 'errorCode' => 'no_plugin_specified', 'errorMessage' => __('No plugin specified.')));
    }
    $plugin = plugin_basename(sanitize_text_field(wp_unslash($_POST['plugin'])));
    $status = array('update' => 'plugin', 'slug' => sanitize_key(wp_unslash($_POST['slug'])), 'oldVersion' => '', 'newVersion' => '');
    if (!current_user_can('update_plugins') || 0 !== validate_file($plugin)) {
        $status['errorMessage'] = __('Sorry, you are not allowed to update plugins for this site.');
        wp_send_json_error($status);
    }
    $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
    $status['plugin'] = $plugin;
    $status['pluginName'] = $plugin_data['Name'];
    if ($plugin_data['Version']) {
        /* translators: %s: Plugin version */
        $status['oldVersion'] = sprintf(__('Version %s'), $plugin_data['Version']);
    }
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    wp_update_plugins();
    $skin = new WP_Ajax_Upgrader_Skin();
    $upgrader = new Plugin_Upgrader($skin);
    $result = $upgrader->bulk_upgrade(array($plugin));
    if (defined('WP_DEBUG') && WP_DEBUG) {
        $status['debug'] = $skin->get_upgrade_messages();
    }
    if (is_wp_error($skin->result)) {
        $status['errorCode'] = $skin->result->get_error_code();
        $status['errorMessage'] = $skin->result->get_error_message();
        wp_send_json_error($status);
    } elseif ($skin->get_errors()->get_error_code()) {
        $status['errorMessage'] = $skin->get_error_messages();
        wp_send_json_error($status);
    } elseif (is_array($result) && !empty($result[$plugin])) {
        $plugin_update_data = current($result);
        /*
         * If the `update_plugins` site transient is empty (e.g. when you update
         * two plugins in quick succession before the transient repopulates),
         * this may be the return.
         *
         * Preferably something can be done to ensure `update_plugins` isn't empty.
         * For now, surface some sort of error here.
         */
        if (true === $plugin_update_data) {
            $status['errorMessage'] = __('Plugin update failed.');
            wp_send_json_error($status);
        }
        $plugin_data = get_plugins('/' . $result[$plugin]['destination_name']);
        $plugin_data = reset($plugin_data);
        if ($plugin_data['Version']) {
            /* translators: %s: Plugin version */
            $status['newVersion'] = sprintf(__('Version %s'), $plugin_data['Version']);
        }
        wp_send_json_success($status);
    } elseif (false === $result) {
        global $wp_filesystem;
        $status['errorCode'] = 'unable_to_connect_to_filesystem';
        $status['errorMessage'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
        // Pass through the error from WP_Filesystem if one was raised.
        if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
            $status['errorMessage'] = esc_html($wp_filesystem->errors->get_error_message());
        }
        wp_send_json_error($status);
    }
    // An unhandled error occurred.
    $status['errorMessage'] = __('Plugin update failed.');
    wp_send_json_error($status);
}
Пример #11
0
 function upgrade_plugins($plugins = false)
 {
     if (!$plugins || empty($plugins)) {
         return array('error' => 'No plugin files for upgrade.', 'error_code' => 'no_plugin_files_for_upgrade');
     }
     $current = $this->iwp_mmb_get_transient('update_plugins');
     $versions = array();
     if (!empty($current)) {
         foreach ($plugins as $plugin => $data) {
             if (isset($current->checked[$plugin])) {
                 $versions[$current->checked[$plugin]] = $plugin;
             }
         }
     }
     $return = array();
     if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
         $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
         $result = $upgrader->bulk_upgrade(array_keys($plugins));
         if (!function_exists('wp_update_plugins')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_plugins();
         $current = $this->iwp_mmb_get_transient('update_plugins');
         if (!empty($result)) {
             foreach ($result as $plugin_slug => $plugin_info) {
                 if (!$plugin_info || is_wp_error($plugin_info)) {
                     $return[$plugin_slug] = array('error' => $this->iwp_mmb_get_error($plugin_info), 'error_code' => 'upgrade_plugins_wp_error');
                 } else {
                     if (!empty($result[$plugin_slug]) || isset($current->checked[$plugin_slug]) && version_compare(array_search($plugin_slug, $versions), $current->checked[$plugin_slug], '<') == true) {
                         $return[$plugin_slug] = 1;
                     } else {
                         update_option('iwp_client_forcerefresh', true);
                         $return[$plugin_slug] = array('error' => 'Could not refresh upgrade transients, please reload website data', 'error_code' => 'upgrade_plugins_could_not_refresh_upgrade_transients_please_reload_website_data');
                     }
                 }
             }
             ob_end_clean();
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.', 'error_code' => 'upgrade_failed_upgrade_plugins');
         }
     } else {
         ob_end_clean();
         return array('error' => 'WordPress update required first.', 'error_code' => 'upgrade_plugins_wordPress_update_required_first');
     }
 }
 /**
  * Download and install a plugin update.
  *
  * @since  4.0.0
  * @param  int  $pid The project ID.
  * @param  bool $die_on_error Default is true. Otherwise function will
  *              return false on error.
  * @return bool True on success.
  */
 public function update_project($pid, $die_on_error = true)
 {
     // Refresh local project cache before the update starts.
     WPMUDEV_Dashboard::$site->set_option('refresh_local_flag', true);
     $local_projects = WPMUDEV_Dashboard::$site->get_cached_projects();
     // Now make sure that the project is updated, no matter what!
     WPMUDEV_Dashboard::$api->calculate_upgrades($local_projects, $pid);
     if (!$this->is_project_installed($pid)) {
         if ($die_on_error) {
             wp_send_json_error(array('message' => __('Project not installed', 'wdpmudev')));
         } else {
             error_log('WPMU DEV error: Update failed - project not installed');
             return false;
         }
     }
     $project = WPMUDEV_Dashboard::$site->get_project_infos($pid);
     // Upfront special: If updating a child theme first update parent.
     if ($project->need_upfront) {
         $upfront = WPMUDEV_Dashboard::$site->get_project_infos($this->id_upfront);
         // Time condition to avoid repeated UF checks if there was an error.
         $check = (int) WPMUDEV_Dashboard::$site->get_option('last_check_upfront');
         if (!$upfront->is_installed) {
             if (time() > $check + 3 * MINUTE_IN_SECONDS) {
                 WPMUDEV_Dashboard::$site->set_option('last_check_upfront', time());
                 $this->install_project($upfront->pid, $error, false);
             }
         } elseif ($upfront->version_installed != $upfront->version_latest) {
             if (time() > $check + 3 * MINUTE_IN_SECONDS) {
                 WPMUDEV_Dashboard::$site->set_option('last_check_upfront', time());
                 $this->update_project($upfront->pid, false);
             }
         }
     }
     // For plugins_api..
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     // Save on a bit of bandwidth.
     $api = plugins_api('plugin_information', array('slug' => 'wpmudev_install-' . $pid, 'fields' => array('sections' => false)));
     if (is_wp_error($api)) {
         if ($die_on_error) {
             wp_send_json_error(array('message' => __('No data found', 'wpmudev')));
         } else {
             error_log('WPMU DEV error: Update failed - no upgrade data found');
             return false;
         }
     }
     ob_start();
     $skin = new Automatic_Upgrader_Skin();
     $result = false;
     $success = false;
     $update_file = $project->filename;
     /*
      * Set before the update:
      * WP will refresh local cache via action-hook before the install()
      * method is finished. That refresh call must scan the FS again.
      */
     $this->flush_fs_cache = true;
     $this->flush_info_cache = true;
     switch ($project->type) {
         case 'plugin':
             wp_update_plugins();
             $upgrader = new Plugin_Upgrader($skin);
             $result = $upgrader->bulk_upgrade(array($update_file));
             break;
         case 'theme':
             wp_update_themes();
             $upgrader = new Theme_Upgrader($skin);
             $update_file = dirname($update_file);
             $result = $upgrader->upgrade($update_file);
             break;
     }
     // Check for errors.
     if (is_array($result) && empty($result[$update_file]) && is_wp_error($skin->result)) {
         $result = $skin->result;
     }
     $details = ob_get_clean();
     $err_data = array('error_code' => 'U000', 'message' => __('Update failed', 'wpmudev'), 'details' => $details, 'pid' => $pid);
     if (is_array($result) && !empty($result[$update_file])) {
         $plugin_update_data = current($result);
         if (true === $plugin_update_data) {
             $err_data['error_code'] = 'U001';
             $err_data['message'] = implode('<br>', $skin->get_upgrade_messages());
             error_log('WPMU DEV error: Update failed | ' . json_encode($err_data));
             if ($die_on_error) {
                 $this->send_json_error($err_data);
             } else {
                 return false;
             }
         }
     } elseif (is_wp_error($result)) {
         $err_data['error_code'] = 'U002';
         $err_data['message'] = $result->get_error_message();
         error_log('WPMU DEV error: Update failed | ' . json_encode($err_data));
         if ($die_on_error) {
             $this->send_json_error($err_data);
         } else {
             return false;
         }
     } elseif (is_bool($result) && !$result) {
         // $upgrader->upgrade() returned false.
         // Possibly because WordPress did not find an update for the project.
         $err_data['error_code'] = 'U003';
         $err_data['message'] = __('Could not find update source', 'wpmudev');
         error_log('WPMU DEV error: Update failed | ' . json_encode($err_data));
         if ($die_on_error) {
             $this->send_json_error($err_data);
         } else {
             return false;
         }
     }
     // API call to inform wpmudev site about the change.
     $this->refresh_local_projects('remote');
     // Check if the update was successful.
     $project = WPMUDEV_Dashboard::$site->get_project_infos($pid);
     if ($project->version_installed != $project->version_latest) {
         if ($die_on_error) {
             wp_send_json_error(array('message' => __('Update failed. Maybe wrong folder permissions.', 'wdpmudev')));
         } else {
             error_log('WPMU DEV error: Upgrade failed - Maybe wrong folder permissions.');
             return false;
         }
     }
     return true;
 }
Пример #13
0
 private function _update_plugin($plugin, $slug)
 {
     $status = array('update' => 'plugin', 'plugin' => $plugin, 'slug' => sanitize_key($slug), 'oldVersion' => '', 'newVersion' => '');
     if (false !== strpos($plugin, '..') || false !== strpos($plugin, ':') || !preg_match('#^[^\\/]#i', $plugin)) {
         $status['error'] = 'not_found';
         return $status;
     }
     $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
     if (!isset($plugin_data['Name']) || !isset($plugin_data['Author']) || '' == $plugin_data['Name'] && '' == $plugin_data['Author']) {
         $status['error'] = 'not_found';
         return $status;
     }
     if ($plugin_data['Version']) {
         $status['oldVersion'] = $plugin_data['Version'];
     }
     if (!current_user_can('update_plugins')) {
         $status['error'] = 'updates_permission_denied';
         return $status;
     }
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     wp_update_plugins();
     // WP < 3.7
     if (!class_exists('Automatic_Upgrader_Skin')) {
         require_once UPDRAFTPLUS_DIR . '/central/classes/class-automatic-upgrader-skin.php';
     }
     $skin = new Automatic_Upgrader_Skin();
     $upgrader = new Plugin_Upgrader($skin);
     $result = $upgrader->bulk_upgrade(array($plugin));
     if (is_array($result) && empty($result[$plugin]) && is_wp_error($skin->result)) {
         $result = $skin->result;
     }
     $status['messages'] = $upgrader->skin->get_upgrade_messages();
     if (is_array($result) && !empty($result[$plugin])) {
         $plugin_update_data = current($result);
         /*
          * If the `update_plugins` site transient is empty (e.g. when you update
          * two plugins in quick succession before the transient repopulates),
          * this may be the return.
          *
          * Preferably something can be done to ensure `update_plugins` isn't empty.
          * For now, surface some sort of error here.
          */
         if ($plugin_update_data === true) {
             $status['error'] = 'update_failed';
             return $status;
         }
         $plugin_data = get_plugins('/' . $result[$plugin]['destination_name']);
         $plugin_data = reset($plugin_data);
         if ($plugin_data['Version']) {
             $status['newVersion'] = $plugin_data['Version'];
         }
         return $status;
     } else {
         if (is_wp_error($result)) {
             $status['error'] = $result->get_error_code();
             $status['error_message'] = $result->get_error_message();
             return $status;
         } else {
             if (is_bool($result) && !$result) {
                 $status['error'] = 'unable_to_connect_to_filesystem';
                 global $wp_filesystem;
                 // Pass through the error from WP_Filesystem if one was raised
                 if (isset($wp_filesystem->errors) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
                     $status['error'] = $wp_filesystem->errors->get_error_code();
                     $status['error_message'] = $wp_filesystem->errors->get_error_message();
                 }
                 return $status;
             } else {
                 // An unhandled error occured
                 $status['error'] = 'update_failed';
                 return $status;
             }
         }
     }
 }
Пример #14
0
 function upgrade_plugins($plugins = false, $plugin_details = false, $userid)
 {
     global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
     if (!$plugins || empty($plugins)) {
         return array('error' => 'No plugin files for upgrade.', 'error_code' => 'no_plugin_files_for_upgrade');
     }
     $current = $this->iwp_mmb_get_transient('update_plugins');
     $versions = array();
     if (!empty($current)) {
         foreach ($plugins as $plugin => $data) {
             if (isset($current->checked[$plugin])) {
                 $versions[$current->checked[$plugin]] = $plugin;
             }
         }
     }
     $return = array();
     if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
         $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
         $result = $upgrader->bulk_upgrade(array_keys($plugins));
         if (!function_exists('wp_update_plugins')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_plugins();
         $current = $this->iwp_mmb_get_transient('update_plugins');
         if (!empty($result)) {
             foreach ($result as $plugin_slug => $plugin_info) {
                 if (!$plugin_info || is_wp_error($plugin_info)) {
                     $return[$plugin_slug] = array('error' => $this->iwp_mmb_get_error($plugin_info), 'error_code' => 'upgrade_plugins_wp_error');
                 } else {
                     if (!empty($result[$plugin_slug]) || isset($current->checked[$plugin_slug]) && version_compare(array_search($plugin_slug, $versions), $current->checked[$plugin_slug], '<') == true) {
                         foreach ($plugin_details as $key => $plugin_detail) {
                             /* the following "if" is used to detect premium plugin properties.*/
                             if (is_array($plugin_detail)) {
                                 $plugin_detail = (object) $plugin_detail;
                             }
                             /* the above "if" is used to detect premium plugin properties.*/
                             if (isset($plugin_detail->plugin) && $plugin_slug == $plugin_detail->plugin || isset($plugin_detail->slug) && $plugin_slug == $plugin_detail->slug) {
                                 $current_plugin = array();
                                 $current_plugin['name'] = isset($plugin_detail->name) ? $plugin_detail->name : '';
                                 if (isset($plugin_detail->textdomain)) {
                                     // this "if" is used to detect premium plugin properties.
                                     $current_plugin['slug'] = $plugin_detail->textdomain;
                                 } else {
                                     if (isset($plugin_detail->slug)) {
                                         $current_plugin['slug'] = $plugin_detail->slug;
                                     } else {
                                         $current_plugin['slug'] = '';
                                     }
                                 }
                                 if (isset($plugin_detail->old_version)) {
                                     $current_plugin['old_version'] = $plugin_detail->old_version;
                                 } else {
                                     if (isset($plugin_detail->version)) {
                                         $current_plugin['old_version'] = $plugin_detail->version;
                                     } else {
                                         $current_plugin['old_version'] = '';
                                     }
                                 }
                                 $current_plugin['updated_version'] = isset($plugin_detail->new_version) ? $plugin_detail->new_version : '';
                                 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('plugins', 'update', $iwp_activities_log_post_type, (object) $current_plugin, $userid);
                                 unset($current_plugin);
                                 break;
                             }
                         }
                         $return[$plugin_slug] = 1;
                     } else {
                         update_option('iwp_client_forcerefresh', true);
                         $return[$plugin_slug] = array('error' => 'Could not refresh upgrade transients, please reload website data', 'error_code' => 'upgrade_plugins_could_not_refresh_upgrade_transients_please_reload_website_data');
                     }
                 }
             }
             ob_end_clean();
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.', 'error_code' => 'upgrade_failed_upgrade_plugins');
         }
     } else {
         ob_end_clean();
         return array('error' => 'WordPress update required first.', 'error_code' => 'upgrade_plugins_wordPress_update_required_first');
     }
 }
Пример #15
0
     define("ABSPATH", dirname(__FILE__) . "/");
     include_once ABSPATH . "wp-config.php";
     include_once ABSPATH . "wp-admin/includes/file.php";
     include_once ABSPATH . "wp-admin/includes/plugin.php";
     include_once ABSPATH . "wp-admin/includes/theme.php";
     include_once ABSPATH . "wp-admin/includes/misc.php";
     include_once ABSPATH . "wp-admin/includes/template.php";
     include_once ABSPATH . "wp-admin/includes/class-wp-upgrader.php";
     include_once ABSPATH . "wp-includes/update.php";
     if (!class_exists("Plugin_Upgrader") || !class_exists("Bulk_Plugin_Upgrader_Skin")) {
         echo '__CLIENT__RESPONCE__START__' . serialize(array(2, $GLOBALS["__i_client_error_stack"])) . "__CLIENT__RESPONCE__END__";
         exit;
     }
     $plugins = $_POST["id"];
     $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact("nonce", "url")));
     $result = $upgrader->bulk_upgrade($plugins);
     @wp_update_plugins();
     echo '__CLIENT__RESPONCE__START__' . serialize(array($result, $GLOBALS["__i_client_error_stack"])) . "__CLIENT__RESPONCE__END__";
 } else {
     if ($_POST["cmd"] === "update-theme") {
         define("ABSPATH", dirname(__FILE__) . "/");
         include_once ABSPATH . "wp-config.php";
         include_once ABSPATH . "wp-admin/includes/file.php";
         include_once ABSPATH . "wp-admin/includes/plugin.php";
         include_once ABSPATH . "wp-admin/includes/theme.php";
         include_once ABSPATH . "wp-admin/includes/misc.php";
         include_once ABSPATH . "wp-admin/includes/template.php";
         include_once ABSPATH . "wp-admin/includes/class-wp-upgrader.php";
         include_once ABSPATH . "wp-includes/update.php";
         if (!class_exists("Theme_Upgrader") || !class_exists("Bulk_Theme_Upgrader_Skin")) {
             echo '__CLIENT__RESPONCE__START__' . serialize(array(2, $GLOBALS["__i_client_error_stack"])) . "__CLIENT__RESPONCE__END__";