public function test_sync_update_themes()
 {
     wp_update_themes();
     $this->client->do_sync();
     $updates = $this->server_replica_storage->get_updates('themes');
     $this->assertTrue(is_int($updates->last_checked));
 }
/**
 * Return an array of installed themes
 *
 * @return array
 */
function _wprp_get_themes()
{
    require_once ABSPATH . '/wp-admin/includes/theme.php';
    // Get all themes
    $themes = get_themes();
    // Get the list of active themes
    $active = get_option('current_theme');
    // Force a theme update check
    wp_update_themes();
    // Different versions of wp store the updates in different places
    // TODO can we depreciate
    if (function_exists('get_site_transient') && ($transient = get_site_transient('update_themes'))) {
        $current = $transient;
    } elseif ($transient = get_transient('update_themes')) {
        $current = $transient;
    } else {
        $current = get_option('update_themes');
    }
    foreach ((array) $themes as $theme) {
        $new_version = isset($current->response[$theme['Template']]) ? $current->response[$theme['Template']]['new_version'] : null;
        if ($active == $theme['Name']) {
            $themes[$theme['Name']]['active'] = true;
        } else {
            $themes[$theme['Name']]['active'] = false;
        }
        if ($new_version) {
            $themes[$theme['Name']]['latest_version'] = $new_version;
            $themes[$theme['Name']]['latest_package'] = $current->response[$theme['Template']]['package'];
        } else {
            $themes[$theme['Name']]['latest_version'] = $theme['Version'];
        }
    }
    return $themes;
}
 function update()
 {
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     // Clear the cache.
     wp_update_themes();
     foreach ($this->themes as $theme) {
         /**
          * Pre-upgrade action
          * 
          * @since 3.9.3
          * 
          * @param object $theme WP_Theme object
          * @param array $themes Array of theme objects
          */
         do_action('jetpack_pre_theme_upgrade', $theme, $this->themes);
         // Objects created inside the for loop to clean the messages for each theme
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new Theme_Upgrader($skin);
         $upgrader->init();
         $result = $upgrader->upgrade($theme);
         $this->log[$theme][] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && !$result) {
         return new WP_Error('update_fail', __('There was an error updating your theme', 'jetpack'), 400);
     }
     return true;
 }
 public function test_sync_update_themes()
 {
     if (is_multisite()) {
         $this->markTestSkipped('Not compatible with multisite mode');
     }
     wp_update_themes();
     $this->sender->do_sync();
     $updates = $this->server_replica_storage->get_updates('themes');
     $this->assertTrue(is_int($updates->last_checked));
 }
/**
 * AJAX handler for updating a theme.
 *
 * @since 4.X.0
 */
function wp_ajax_update_theme()
{
    check_ajax_referer('updates');
    if (empty($_POST['slug'])) {
        wp_send_json_error(array('slug' => '', 'errorCode' => 'no_theme_specified', 'error' => __('No theme specified.')));
    }
    $stylesheet = sanitize_key($_POST['slug']);
    $status = array('update' => 'theme', 'slug' => $stylesheet, 'oldVersion' => sprintf(__('Version %s'), wp_get_theme($stylesheet)->get('Version')), 'newVersion' => '');
    if (!current_user_can('update_themes')) {
        $status['error'] = __('You do not have sufficient permissions to update themes on this site.');
        wp_send_json_error($status);
    }
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $current = get_site_transient('update_themes');
    if (empty($current)) {
        wp_update_themes();
    }
    $upgrader = new Theme_Upgrader(new Automatic_Upgrader_Skin());
    $result = $upgrader->bulk_upgrade(array($stylesheet));
    if (defined('WP_DEBUG') && WP_DEBUG) {
        $status['debug'] = $upgrader->skin->get_upgrade_messages();
    }
    if (is_array($result) && !empty($result[$stylesheet])) {
        // Theme is already at the latest version.
        if (true === $result[$stylesheet]) {
            $status['error'] = $upgrader->strings['up_to_date'];
            wp_send_json_error($status);
        }
        $theme = wp_get_theme($stylesheet);
        if ($theme->get('Version')) {
            $status['theme'] = wp_prepare_themes_for_js(array($theme));
            $status['newVersion'] = sprintf(__('Version %s'), $theme->get('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) {
                global $wp_filesystem;
                $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 ($wp_filesystem instanceof WP_Filesystem_Base && 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);
            }
        }
    }
    // An unhandled error occurred.
    $status['error'] = __('Update failed.');
    wp_send_json_error($status);
}
Beispiel #6
0
/**
 * Return an array of installed themes
 *
 * @return array
 */
function _wprp_get_themes()
{
    require_once ABSPATH . '/wp-admin/includes/theme.php';
    // Get all themes
    if (function_exists('wp_get_themes')) {
        $themes = wp_get_themes();
    } else {
        $themes = get_themes();
    }
    // Get the active theme
    $active = get_option('current_theme');
    // Delete the transient so wp_update_themes can get fresh data
    if (function_exists('get_site_transient')) {
        delete_site_transient('update_themes');
    } else {
        delete_transient('update_themes');
    }
    // Force a theme update check
    wp_update_themes();
    // Different versions of wp store the updates in different places
    // TODO can we depreciate
    if (function_exists('get_site_transient') && ($transient = get_site_transient('update_themes'))) {
        $current = $transient;
    } elseif ($transient = get_transient('update_themes')) {
        $current = $transient;
    } else {
        $current = get_option('update_themes');
    }
    foreach ((array) $themes as $key => $theme) {
        // WordPress 3.4+
        if (is_object($theme) && is_a($theme, 'WP_Theme')) {
            /* @var $theme WP_Theme */
            $new_version = isset($current->response[$theme->get_stylesheet()]) ? $current->response[$theme->get_stylesheet()]['new_version'] : null;
            $theme_array = array('Name' => $theme->get('Name'), 'active' => $active == $theme->get('Name'), 'Template' => $theme->get_template(), 'Stylesheet' => $theme->get_stylesheet(), 'Screenshot' => $theme->get_screenshot(), 'AuthorURI' => $theme->get('AuthorURI'), 'Author' => $theme->get('Author'), 'latest_version' => $new_version ? $new_version : $theme->get('Version'), 'Version' => $theme->get('Version'), 'ThemeURI' => $theme->get('ThemeURI'));
            $themes[$key] = $theme_array;
        } else {
            $new_version = isset($current->response[$theme['Stylesheet']]) ? $current->response[$theme['Stylesheet']]['new_version'] : null;
            if ($active == $theme['Name']) {
                $themes[$key]['active'] = true;
            } else {
                $themes[$key]['active'] = false;
            }
            if ($new_version) {
                $themes[$key]['latest_version'] = $new_version;
                $themes[$key]['latest_package'] = $current->response[$theme['Template']]['package'];
            } else {
                $themes[$key]['latest_version'] = $theme['Version'];
            }
        }
    }
    return $themes;
}
 public function wp_oracle_get_theme_updates()
 {
     if (!function_exists('get_theme_updates')) {
         require_once ABSPATH . 'wp-admin/includes/update.php';
     }
     // force refresh
     wp_update_themes();
     $updates = get_theme_updates();
     if (empty($updates)) {
         return array('blog' => array('themes' => 'no_updates'));
     } else {
         return $updates;
     }
 }
 protected function result()
 {
     // pass an option to do it conditional;
     wp_update_themes();
     $update_data = wp_get_update_data();
     if (!isset($update_data['counts'])) {
         return new WP_Error('get_update_data_error', __('There was an error while getting the update data for this site.', 'jetpack'), 500);
     }
     $result = $update_data['counts'];
     include ABSPATH . WPINC . '/version.php';
     // $wp_version;
     $result['wp_version'] = isset($wp_version) ? $wp_version : null;
     $result['jp_version'] = JETPACK__VERSION;
     return $result;
 }
 protected function result()
 {
     wp_update_themes();
     wp_update_plugins();
     $update_data = wp_get_update_data();
     if (!isset($update_data['counts'])) {
         return new WP_Error('get_update_data_error', __('There was an error while getting the update data for this site.', 'jetpack'), 500);
     }
     $result = $update_data['counts'];
     include ABSPATH . WPINC . '/version.php';
     // $wp_version;
     $result['wp_version'] = isset($wp_version) ? $wp_version : null;
     if (!empty($result['wordpress'])) {
         $cur = get_preferred_from_update_core();
         if (isset($cur->response) && $cur->response === 'upgrade') {
             $result['wp_update_version'] = $cur->current;
         }
     }
     $result['jp_version'] = JETPACK__VERSION;
     return $result;
 }
 function update_translations()
 {
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     // Clear the cache.
     wp_update_themes();
     $available_themes_updates = get_site_transient('update_themes');
     if (!isset($available_themes_updates->translations) || empty($available_themes_updates->translations)) {
         return new WP_Error('nothing_to_translate');
     }
     foreach ($available_themes_updates->translations as $translation) {
         $theme = $translation['slug'];
         if (!in_array($translation['slug'], $this->themes)) {
             $this->log[$theme][] = __('No update needed', 'jetpack');
             continue;
         }
         /**
          * Pre-upgrade action
          *
          * @since 4.4
          *
          * @param object $theme WP_Theme object
          * @param array $themes Array of theme objects
          */
         do_action('jetpack_pre_theme_upgrade_translations', $theme, $this->themes);
         // Objects created inside the for loop to clean the messages for each theme
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new Language_Pack_Upgrader($skin);
         $upgrader->init();
         $result = $upgrader->upgrade((object) $translation);
         $this->log[$theme] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && !$result) {
         return new WP_Error('update_fail', __('There was an error updating your theme', 'jetpack'), 400);
     }
     return true;
 }
 function getSiteStats($information = array(), $exit = true)
 {
     global $wp_version;
     if ($exit) {
         $this->updateExternalSettings();
     }
     MainWP_Helper::update_option('mainwp_child_branding_disconnected', '', 'yes');
     if (isset($_POST['server'])) {
         MainWP_Helper::update_option('mainwp_child_server', $_POST['server']);
     }
     if (isset($_POST['numberdaysOutdatePluginTheme']) && !empty($_POST['numberdaysOutdatePluginTheme'])) {
         $days_outdate = get_option('mainwp_child_plugintheme_days_outdate', 365);
         if ($days_outdate !== $_POST['numberdaysOutdatePluginTheme']) {
             $days_outdate = $_POST['numberdaysOutdatePluginTheme'];
             MainWP_Helper::update_option('mainwp_child_plugintheme_days_outdate', $days_outdate);
             MainWP_Child_Plugins_Check::Instance()->cleanup_deactivation(false);
             MainWP_Child_Themes_Check::Instance()->cleanup_deactivation(false);
         }
     }
     $information['version'] = self::$version;
     $information['wpversion'] = $wp_version;
     $information['siteurl'] = get_option('siteurl');
     $information['nossl'] = '1' === get_option('mainwp_child_nossl') ? 1 : 0;
     include_once ABSPATH . '/wp-admin/includes/update.php';
     $timeout = 3 * 60 * 60;
     // 3minutes
     @set_time_limit($timeout);
     @ini_set('max_execution_time', $timeout);
     //Check for new versions
     if (null !== $this->filterFunction) {
         add_filter('pre_site_transient_update_core', $this->filterFunction, 99);
     }
     if (null !== $this->filterFunction) {
         add_filter('pre_transient_update_core', $this->filterFunction, 99);
     }
     @wp_version_check();
     $core_updates = get_core_updates();
     if (count($core_updates) > 0) {
         foreach ($core_updates as $core_update) {
             if ('latest' === $core_update->response) {
                 break;
             }
             if ('upgrade' === $core_update->response && version_compare($wp_version, $core_update->current, '<=')) {
                 $information['wp_updates'] = $core_update->current;
             }
         }
     }
     if (!isset($information['wp_updates'])) {
         $information['wp_updates'] = null;
     }
     if (null !== $this->filterFunction) {
         remove_filter('pre_site_transient_update_core', $this->filterFunction, 99);
     }
     if (null !== $this->filterFunction) {
         remove_filter('pre_transient_update_core', $this->filterFunction, 99);
     }
     add_filter('default_option_active_plugins', array(&$this, 'default_option_active_plugins'));
     add_filter('option_active_plugins', array(&$this, 'default_option_active_plugins'));
     //First check for new premium updates
     $update_check = apply_filters('mwp_premium_update_check', array());
     if (!empty($update_check)) {
         foreach ($update_check as $updateFeedback) {
             if (is_array($updateFeedback['callback']) && isset($updateFeedback['callback'][0]) && isset($updateFeedback['callback'][1])) {
                 @call_user_func(array($updateFeedback['callback'][0], $updateFeedback['callback'][1]));
             } else {
                 if (is_string($updateFeedback['callback'])) {
                     @call_user_func($updateFeedback['callback']);
                 }
             }
         }
     }
     $informationPremiumUpdates = apply_filters('mwp_premium_update_notification', array());
     $premiumPlugins = array();
     $premiumThemes = array();
     if (is_array($informationPremiumUpdates)) {
         $premiumUpdates = array();
         $information['premium_updates'] = array();
         $informationPremiumUpdatesLength = count($informationPremiumUpdates);
         for ($i = 0; $i < $informationPremiumUpdatesLength; $i++) {
             if (!isset($informationPremiumUpdates[$i]['new_version'])) {
                 continue;
             }
             $slug = isset($informationPremiumUpdates[$i]['slug']) ? $informationPremiumUpdates[$i]['slug'] : $informationPremiumUpdates[$i]['Name'];
             if ('plugin' === $informationPremiumUpdates[$i]['type']) {
                 $premiumPlugins[] = $slug;
             } else {
                 if ('theme' === $informationPremiumUpdates[$i]['type']) {
                     $premiumThemes[] = $slug;
                 }
             }
             $new_version = $informationPremiumUpdates[$i]['new_version'];
             unset($informationPremiumUpdates[$i]['old_version']);
             unset($informationPremiumUpdates[$i]['new_version']);
             $information['premium_updates'][$slug] = $informationPremiumUpdates[$i];
             $information['premium_updates'][$slug]['update'] = (object) array('new_version' => $new_version, 'premium' => true, 'slug' => $slug);
             if (!in_array($slug, $premiumUpdates)) {
                 $premiumUpdates[] = $slug;
             }
         }
         MainWP_Helper::update_option('mainwp_premium_updates', $premiumUpdates);
     }
     remove_filter('default_option_active_plugins', array(&$this, 'default_option_active_plugins'));
     remove_filter('option_active_plugins', array(&$this, 'default_option_active_plugins'));
     if (null !== $this->filterFunction) {
         add_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
     }
     global $wp_current_filter;
     $wp_current_filter[] = 'load-plugins.php';
     @wp_update_plugins();
     include_once ABSPATH . '/wp-admin/includes/plugin.php';
     $plugin_updates = get_plugin_updates();
     if (is_array($plugin_updates)) {
         $information['plugin_updates'] = array();
         foreach ($plugin_updates as $slug => $plugin_update) {
             if (in_array($plugin_update->Name, $premiumPlugins)) {
                 continue;
             }
             $information['plugin_updates'][$slug] = $plugin_update;
         }
     }
     if (null !== $this->filterFunction) {
         remove_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
     }
     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';
     $theme_updates = $this->upgrade_get_theme_updates();
     if (is_array($theme_updates)) {
         $information['theme_updates'] = array();
         foreach ($theme_updates as $slug => $theme_update) {
             $name = is_array($theme_update) ? $theme_update['Name'] : $theme_update->Name;
             if (in_array($name, $premiumThemes)) {
                 continue;
             }
             $information['theme_updates'][$slug] = $theme_update;
         }
     }
     if (null !== $this->filterFunction) {
         remove_filter('pre_site_transient_update_themes', $this->filterFunction, 99);
     }
     $information['recent_comments'] = $this->get_recent_comments(array('approve', 'hold'), 5);
     $information['recent_posts'] = $this->get_recent_posts(array('publish', 'draft', 'pending', 'trash'), 5);
     $information['recent_pages'] = $this->get_recent_posts(array('publish', 'draft', 'pending', 'trash'), 5, 'page');
     $securityIssuess = 0;
     if (!MainWP_Security::prevent_listing_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::remove_wp_version_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::remove_rsd_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::remove_wlw_ok()) {
         $securityIssuess++;
     }
     //        if (!MainWP_Security::remove_core_update_ok()) $securityIssuess++;
     //        if (!MainWP_Security::remove_plugin_update_ok()) $securityIssuess++;
     //        if (!MainWP_Security::remove_theme_update_ok()) $securityIssuess++;
     //        if (!MainWP_Security::fix_file_permissions_ok()) $securityIssuess++;
     if (!MainWP_Security::remove_database_reporting_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::remove_php_reporting_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::remove_scripts_version_ok() || !MainWP_Security::remove_styles_version_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::admin_user_ok()) {
         $securityIssuess++;
     }
     if (!MainWP_Security::remove_readme_ok()) {
         $securityIssuess++;
     }
     $information['securityIssues'] = $securityIssuess;
     //Directory listings!
     $information['directories'] = $this->scanDir(ABSPATH, 3);
     $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => true));
     $categories = array();
     foreach ($cats as $cat) {
         $categories[] = $cat->name;
     }
     $information['categories'] = $categories;
     $information['totalsize'] = $this->getTotalFileSize();
     $information['dbsize'] = MainWP_Child_DB::get_size();
     $auths = get_option('mainwp_child_auth');
     $information['extauth'] = $auths && isset($auths[$this->maxHistory]) ? $auths[$this->maxHistory] : null;
     $plugins = $this->get_all_plugins_int(false);
     $themes = $this->get_all_themes_int(false);
     $information['plugins'] = $plugins;
     $information['themes'] = $themes;
     if (isset($_POST['optimize']) && '1' === $_POST['optimize']) {
         $information['users'] = $this->get_all_users_int();
     }
     if (isset($_POST['pluginConflicts']) && '' !== $_POST['pluginConflicts']) {
         $pluginConflicts = json_decode(stripslashes($_POST['pluginConflicts']), true);
         $conflicts = array();
         if (count($pluginConflicts) > 0) {
             if (!$plugins) {
                 $plugins = $this->get_all_plugins_int(false);
             }
             if (is_array($plugins) && is_array($pluginConflicts)) {
                 foreach ($plugins as $plugin) {
                     foreach ($pluginConflicts as $pluginConflict) {
                         if ('1' === $plugin['active'] && ($plugin['name'] === $pluginConflict || $plugin['slug'] === $pluginConflict)) {
                             $conflicts[] = $plugin['name'];
                         }
                     }
                 }
             }
         }
         if (count($conflicts) > 0) {
             $information['pluginConflicts'] = $conflicts;
         }
     }
     if (isset($_POST['themeConflicts']) && '' !== $_POST['themeConflicts']) {
         $themeConflicts = json_decode(stripslashes($_POST['themeConflicts']), true);
         $conflicts = array();
         if (is_array($themeConflicts) && count($themeConflicts) > 0) {
             $theme = wp_get_theme()->get('Name');
             foreach ($themeConflicts as $themeConflict) {
                 if ($theme === $themeConflict) {
                     $conflicts[] = $theme;
                 }
             }
         }
         if (count($conflicts) > 0) {
             $information['themeConflicts'] = $conflicts;
         }
     }
     if (isset($_POST['othersData'])) {
         $othersData = json_decode(stripslashes($_POST['othersData']), true);
         if (!is_array($othersData)) {
             $othersData = array();
         }
         $information = apply_filters('mainwp-site-sync-others-data', $information, $othersData);
         if (version_compare(phpversion(), '5.3', '>=')) {
             if (isset($othersData['syncBackUpWordPress']) && $othersData['syncBackUpWordPress']) {
                 if (MainWP_Child_Back_Up_Wordpress::isActivated()) {
                     $information['syncBackUpWordPress'] = MainWP_Child_Back_Up_Wordpress::Instance()->syncData();
                 }
             }
         }
         if (isset($othersData['syncWPRocketData']) && 'yes' === $othersData['syncWPRocketData']) {
             $data = array();
             if (MainWP_Child_WP_Rocket::isActivated()) {
                 $boxes = get_user_meta($GLOBALS['current_user']->ID, 'rocket_boxes', true);
                 $data['rocket_boxes'] = $boxes;
             }
             $information['syncWPRocketData'] = $data;
         }
     }
     $information['faviIcon'] = $this->get_favicon();
     $last_post = wp_get_recent_posts(array('numberposts' => absint('1')));
     if (isset($last_post[0])) {
         $last_post = $last_post[0];
     }
     if (isset($last_post) && isset($last_post['post_modified_gmt'])) {
         $information['last_post_gmt'] = strtotime($last_post['post_modified_gmt']);
     }
     $information['mainwpdir'] = MainWP_Helper::validateMainWPDir() ? 1 : -1;
     $information['uniqueId'] = get_option('mainwp_child_uniqueId', '');
     $information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::Instance()->get_plugins_outdate_info();
     $information['themes_outdate_info'] = MainWP_Child_Themes_Check::Instance()->get_themes_outdate_info();
     if ($exit) {
         MainWP_Helper::write($information);
     }
     return $information;
 }
    $remote_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $remote_ip = $_SERVER['REMOTE_ADDR'];
}
// Check if the requesting server is allowed
if (!in_array($remote_ip, $allowed_ips)) {
    echo "CRITICAL#IP {$remote_ip} not allowed.";
    exit;
}
require_once 'wp-load.php';
global $wp_version;
$core_updates = FALSE;
$plugin_updates = FALSE;
wp_version_check();
wp_update_plugins();
wp_update_themes();
if (function_exists('get_transient')) {
    $core = get_transient('update_core');
    $plugins = get_transient('update_plugins');
    $themes = get_transient('update_themes');
    if ($core == FALSE) {
        $core = get_site_transient('update_core');
        $plugins = get_site_transient('update_plugins');
        $themes = get_site_transient('update_themes');
    }
} else {
    $core = get_site_transient('update_core');
    $plugins = get_site_transient('update_plugins');
    $themes = get_site_transient('update_themes');
}
$core_available = FALSE;
 /**
  * Kicks off a upgrade request for each item in the upgrade "queue"
  */
 static function perform_auto_updates()
 {
     $lock_name = 'auto_upgrader.lock';
     if (get_site_option($lock_name)) {
         // Test to see if it was set more than an hour ago, if so, cleanup.
         if (get_site_option($lock_name) < time() - HOUR_IN_SECONDS) {
             delete_site_option($lock_name);
         } else {
             // The process is already locked
             return;
         }
     }
     // Lock upgrades for us for half an hour
     if (!add_site_option($lock_name, microtime(true), HOUR_IN_SECONDS / 2)) {
         return;
     }
     // Don't automatically run these thins, as we'll handle it ourselves
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20, 3);
     remove_action('upgrader_process_complete', 'wp_version_check');
     remove_action('upgrader_process_complete', 'wp_update_plugins');
     remove_action('upgrader_process_complete', 'wp_update_themes');
     // Next, Plugins
     wp_update_plugins();
     // Check for Plugin updates
     $plugin_updates = get_site_transient('update_plugins');
     if ($plugin_updates && !empty($plugin_updates->response)) {
         foreach (array_keys($plugin_updates->response) as $plugin) {
             self::upgrade('plugin', $plugin);
         }
         // Force refresh of plugin update information
         wp_clean_plugins_cache();
     }
     // Next, those themes we all love
     wp_update_themes();
     // Check for Theme updates
     $theme_updates = get_site_transient('update_themes');
     if ($theme_updates && !empty($theme_updates->response)) {
         foreach (array_keys($theme_updates->response) as $theme) {
             self::upgrade('theme', $theme);
         }
         // Force refresh of theme update information
         wp_clean_themes_cache();
     }
     // Next, Process any core upgrade
     wp_version_check();
     // Check for Core updates
     $core_update = find_core_auto_update();
     if ($core_update) {
         self::upgrade('core', $core_update);
         delete_site_transient('update_core');
     }
     // Cleanup, and check for any pending translations
     wp_version_check();
     // check for Core updates
     wp_update_themes();
     // Check for Theme updates
     wp_update_plugins();
     // Check for Plugin updates
     // Finally, Process any new translations
     $language_updates = wp_get_translation_updates();
     if ($language_updates) {
         foreach ($language_updates as $update) {
             self::upgrade('language', $update);
         }
         // Clear existing caches
         wp_clean_plugins_cache();
         wp_clean_themes_cache();
         delete_site_transient('update_core');
         wp_version_check();
         // check for Core updates
         wp_update_themes();
         // Check for Theme updates
         wp_update_plugins();
         // Check for Plugin updates
     }
     /**
      * Filter whether to email an update summary to the site administrator.
      *
      * @since 3.7.0
      *
      * @param bool                         Whether or not email should be sent to administrator. Default true.
      * @param bool|array $core_update      An array of core update data, false otherwise.
      * @param object     $theme_updates    Object containing theme update properties.
      * @param object     $plugin_updates   Object containing plugin update properties.
      * @param array      $language_updates Array containing the Language updates available.
      * @param array      $upgrade_results  Array of the upgrade results keyed by upgrade type, and plugin/theme slug.
      */
     if (apply_filters('enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, $language_updates, self::$upgrade_results)) {
         self::send_email();
     }
     // Clear the lock
     delete_site_option($lock_name);
 }
Beispiel #14
0
 public function upgrade_themes($themes = false)
 {
     if (!$themes || empty($themes)) {
         return array('error' => 'No theme files for upgrade.');
     }
     $current = $this->mmb_get_transient('update_themes');
     $versions = array();
     if (!empty($current)) {
         foreach ($themes as $theme) {
             if (isset($current->checked[$theme])) {
                 $versions[$current->checked[$theme]] = $theme;
             }
         }
     }
     if (class_exists('Theme_Upgrader')) {
         /** @handled class */
         $upgrader = new Theme_Upgrader(mwp_container()->getUpdaterSkin());
         $result = $upgrader->bulk_upgrade($themes);
         if (!function_exists('wp_update_themes')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_themes();
         $current = $this->mmb_get_transient('update_themes');
         $return = array();
         if (!empty($result)) {
             foreach ($result as $theme_tmp => $theme_info) {
                 if (is_wp_error($theme_info) || empty($theme_info)) {
                     $return[$theme_tmp] = $this->mmb_get_error($theme_info);
                 } else {
                     if (!empty($result[$theme_tmp]) || isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true) {
                         $return[$theme_tmp] = 1;
                     } else {
                         $return[$theme_tmp] = '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');
     }
 }
Beispiel #15
0
 function upgrade_themes($themes = false)
 {
     if (!$themes || empty($themes)) {
         return array('error' => 'No theme files for upgrade.', 'error_code' => 'no_theme_files_for_upgrade');
     }
     $current = $this->iwp_mmb_get_transient('update_themes');
     $versions = array();
     if (!empty($current)) {
         foreach ($themes as $theme) {
             if (isset($current->checked[$theme])) {
                 $versions[$current->checked[$theme]] = $theme;
             }
         }
     }
     if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
         $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
         $result = $upgrader->bulk_upgrade($themes);
         if (!function_exists('wp_update_themes')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_themes();
         $current = $this->iwp_mmb_get_transient('update_themes');
         $return = array();
         if (!empty($result)) {
             foreach ($result as $theme_tmp => $theme_info) {
                 if (is_wp_error($theme_info) || empty($theme_info)) {
                     $return[$theme_tmp] = array('error' => $this->iwp_mmb_get_error($theme_info), 'error_code' => 'upgrade_themes_wp_error');
                 } else {
                     if (!empty($result[$theme_tmp]) || isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true) {
                         $return[$theme_tmp] = 1;
                     } else {
                         update_option('iwp_client_forcerefresh', true);
                         $return[$theme_tmp] = array('error' => 'Could not refresh upgrade transients, please reload website data', 'error_code' => 'upgrade_themes_could_not_refresh_upgrade_transients_reload_website');
                     }
                 }
             }
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.', 'error_code' => 'upgrade_failed_upgrade_themes');
         }
     } else {
         ob_end_clean();
         return array('error' => 'WordPress update required first', 'error_code' => 'wordPress_update_required_first_upgrade_themes');
     }
 }
/**
 * Check themes versions only after a duration of time.
 *
 * This is for performance reasons to make sure that on the theme version
 * checker is not run on every page load.
 *
 * @since 2.7.0
 * @access private
 */
function _maybe_update_themes() {
	$current = get_site_transient( 'update_themes' );
	if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
		return;

	wp_update_themes();
}
Beispiel #17
0
 function refresh_updates()
 {
     if (rand(1, 3) == '2') {
         require_once ABSPATH . WPINC . '/update.php';
         wp_update_plugins();
         wp_update_themes();
         wp_version_check();
     }
 }
Beispiel #18
0
/**
 * Check themes versions only after a duration of time.
 *
 * This is for performance reasons to make sure that on the theme version
 * checker is not run on every page load.
 *
 * @since 2.7.0
 * @access private
 */
function _maybe_update_themes()
{
    $current = get_site_transient('update_themes');
    if (isset($current->last_checked) && 43200 > time() - $current->last_checked) {
        return;
    }
    wp_update_themes();
}
 /**
  * Check if any themes need an update.
  *
  * @return $this
  */
 public function checkThemeUpdates()
 {
     $this->theme_updates = array();
     if (!function_exists('wp_update_themes')) {
         require_once ABSPATH . WPINC . '/update.php';
     }
     wp_update_themes();
     // Check for Theme updates
     $update_themes = get_site_transient('update_themes');
     if ($update_themes && !empty($update_themes->response)) {
         if (!function_exists('wp_get_themes')) {
             require_once ABSPATH . '/wp-includes/theme.php';
         }
         $themes = wp_get_themes();
         foreach ($update_themes->response as $theme => $vals) {
             foreach ($themes as $name => $themeData) {
                 if (strtolower($name) == $theme) {
                     $this->theme_updates[] = array('newVersion' => isset($vals['new_version']) ? $vals['new_version'] : 'Unknown', 'package' => isset($vals['package']) ? $vals['package'] : null, 'URL' => isset($vals['url']) ? $vals['url'] : null, 'Name' => $themeData['Name'], 'name' => $themeData['Name'], 'version' => $themeData['Version']);
                 }
             }
         }
     }
     return $this;
 }
Beispiel #20
0
 /**
  * Update language packs for plugins & themes
  *
  * @return array|bool
  */
 private function update_language_packs()
 {
     if ('en_US' === get_locale()) {
         return false;
     }
     if (!function_exists('wp_clean_update_cache')) {
         require_once ABSPATH . 'wp-includes/update.php';
     }
     if (!class_exists('\\Language_Pack_Upgrader')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     if (!class_exists('\\Automatic_Upgrader_Skin')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skins.php';
     }
     wp_clean_update_cache();
     wp_update_themes();
     wp_update_plugins();
     $upgrader = new \Language_Pack_Upgrader(new \Automatic_Upgrader_Skin());
     return $upgrader->bulk_upgrade();
 }
 private function enqueue_all_updates()
 {
     $this->set_status('updates', 0);
     // check for updates
     wp_update_plugins();
     wp_update_themes();
     _maybe_update_core();
     $this->set_status('updates', 100);
 }
 /**
  * Download and install a single plugin/theme update.
  *
  * @since  4.0.0
  * @param  int/string $pid The project ID or a plugin slug.
  * @return bool True on success.
  */
 public function upgrade($pid)
 {
     $this->clear_error();
     // Is a WPMU DEV project?
     $is_dev = is_numeric($pid);
     if ($is_dev) {
         $pid = (int) $pid;
         $infos = $this->prepare_dev_upgrade($pid);
         if (!$infos) {
             return false;
         }
         $filename = 'theme' == $infos['type'] ? dirname($infos['filename']) : $infos['filename'];
         $slug = $infos['slug'];
         $type = $infos['type'];
     } elseif (is_string($pid)) {
         // No need to check if the plugin exists/is installed. WP will check it.
         list($type, $filename) = explode(':', $pid);
         $slug = 'plugin' == $type && false !== strpos($filename, '/') ? dirname($filename) : $filename;
     } else {
         $this->set_error($pid, 'UPG.07', __('Invalid upgrade call', 'wdpmudev'));
         return false;
     }
     // For plugins_api/themes_api..
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     include_once ABSPATH . 'wp-admin/includes/theme-install.php';
     include_once ABSPATH . 'wp-admin/includes/file.php';
     ob_start();
     $skin = new Automatic_Upgrader_Skin();
     $result = false;
     $success = false;
     /*
      * 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.
      */
     WPMUDEV_Dashboard::$site->clear_local_file_cache();
     switch ($type) {
         case 'plugin':
             // Save on a bit of bandwidth.
             $api = plugins_api('plugin_information', array('slug' => $slug, 'fields' => array('sections' => false)));
             if (is_wp_error($api)) {
                 $this->set_error($pid, 'UPG.02', __('No data found', 'wdpmudev'));
                 return false;
             }
             wp_update_plugins();
             $active_blog = is_plugin_active($filename);
             $active_network = is_multisite() && is_plugin_active_for_network($filename);
             $upgrader = new Plugin_Upgrader($skin);
             $result = $upgrader->upgrade($filename);
             /*
              * Note: The following plugin activation is an intended and
              * needed step. During upgrade() WordPress deactivates the
              * plugin network- and site-wide. By default the user would
              * see a upgrade-results page with the option to activate the
              * plugin again. We skip that screen and restore original state.
              */
             if ($active_blog) {
                 activate_plugin($filename, false, false, true);
             }
             if ($active_network) {
                 activate_plugin($filename, false, true, true);
             }
             break;
         case 'theme':
             // Save on a bit of bandwidth.
             $api = themes_api('theme_information', array('slug' => $slug, 'fields' => array('sections' => false)));
             if (is_wp_error($api)) {
                 $this->set_error($pid, 'UPG.02', __('No data found', 'wdpmudev'));
                 return false;
             }
             wp_update_themes();
             $upgrader = new Theme_Upgrader($skin);
             $result = $upgrader->upgrade($filename);
             break;
         default:
             $this->set_error($pid, 'UPG.08', __('Invalid upgrade call', 'wpmudev'));
             return false;
     }
     // Check for errors.
     if (is_array($result) && empty($result[$filename]) && is_wp_error($skin->result)) {
         $result = $skin->result;
     }
     $details = ob_get_clean();
     if (is_array($result) && !empty($result[$filename])) {
         $plugin_update_data = current($result);
         if (true === $plugin_update_data) {
             $this->set_error($pid, 'UPG.03', implode('<br>', $skin->get_upgrade_messages()));
             return false;
         }
     } elseif (is_wp_error($result)) {
         $this->set_error($pid, 'UPG.04', $result->get_error_message());
         return false;
     } elseif (is_bool($result) && !$result) {
         // $upgrader->upgrade() returned false.
         // Possibly because WordPress did not find an update for the project.
         $this->set_error($pid, 'UPG.05', __('Could not find update in transient, or filesystem permissions', 'wpmudev'));
         return false;
     }
     if ($is_dev) {
         // API call to inform wpmudev site about the change, as it's a single we can let it do that at the end to avoid multiple pings
         WPMUDEV_Dashboard::$site->schedule_shutdown_refresh();
         // Check if the update was successful.
         $project = WPMUDEV_Dashboard::$site->get_project_infos($pid);
         if (version_compare($project->version_installed, $project->version_latest, '<')) {
             $this->set_error($pid, 'UPG.06', __('There was an unknown error', 'wpmudev'));
             return false;
         }
     }
     return true;
 }
Beispiel #23
0
 public function doThemeUpdateCheck()
 {
     global $wp_current_filter;
     $wp_current_filter[] = 'load-update-core.php';
     if (function_exists('wp_clean_update_cache')) {
         wp_clean_update_cache();
     }
     wp_update_themes();
     array_pop($wp_current_filter);
     do_action('load-plugins.php');
 }
 /**
  * Kicks off the background update process, looping through all pending updates.
  *
  * @since 3.7.0
  * @access public
  *
  * @global wpdb   $wpdb
  * @global string $wp_version
  */
 public function run()
 {
     global $wpdb, $wp_version;
     if ($this->is_disabled()) {
         return;
     }
     if (!is_main_network() || !is_main_site()) {
         return;
     }
     if (!$this->create_lock('auto_updater')) {
         return;
     }
     // Don't automatically run these thins, as we'll handle it ourselves
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
     remove_action('upgrader_process_complete', 'wp_version_check');
     remove_action('upgrader_process_complete', 'wp_update_plugins');
     remove_action('upgrader_process_complete', 'wp_update_themes');
     // Next, Plugins
     wp_update_plugins();
     // Check for Plugin updates
     $plugin_updates = get_site_transient('update_plugins');
     if ($plugin_updates && !empty($plugin_updates->response)) {
         foreach ($plugin_updates->response as $plugin) {
             $this->update('plugin', $plugin);
         }
         // Force refresh of plugin update information
         wp_clean_plugins_cache();
     }
     // Next, those themes we all love
     wp_update_themes();
     // Check for Theme updates
     $theme_updates = get_site_transient('update_themes');
     if ($theme_updates && !empty($theme_updates->response)) {
         foreach ($theme_updates->response as $theme) {
             $this->update('theme', (object) $theme);
         }
         // Force refresh of theme update information
         wp_clean_themes_cache();
     }
     // Next, Process any core update
     wp_version_check();
     // Check for Core updates
     $core_update = find_core_auto_update();
     if ($core_update) {
         $this->update('core', $core_update);
     }
     // Clean up, and check for any pending translations
     // (Core_Upgrader checks for core updates)
     $theme_stats = array();
     if (isset($this->update_results['theme'])) {
         foreach ($this->update_results['theme'] as $upgrade) {
             $theme_stats[$upgrade->item->theme] = true === $upgrade->result;
         }
     }
     wp_update_themes($theme_stats);
     // Check for Theme updates
     $plugin_stats = array();
     if (isset($this->update_results['plugin'])) {
         foreach ($this->update_results['plugin'] as $upgrade) {
             $plugin_stats[$upgrade->item->plugin] = true === $upgrade->result;
         }
     }
     wp_update_plugins($plugin_stats);
     // Check for Plugin updates
     // Finally, Process any new translations
     $language_updates = wp_get_translation_updates();
     if ($language_updates) {
         foreach ($language_updates as $update) {
             $this->update('translation', $update);
         }
         // Clear existing caches
         wp_clean_update_cache();
         wp_version_check();
         // check for Core updates
         wp_update_themes();
         // Check for Theme updates
         wp_update_plugins();
         // Check for Plugin updates
     }
     // Send debugging email to all development installs.
     if (!empty($this->update_results)) {
         $development_version = false !== strpos($wp_version, '-');
         /**
          * Filter whether to send a debugging email for each automatic background update.
          *
          * @since 3.7.0
          *
          * @param bool $development_version By default, emails are sent if the
          *                                  install is a development version.
          *                                  Return false to avoid the email.
          */
         if (apply_filters('automatic_updates_send_debug_email', $development_version)) {
             $this->send_debug_email();
         }
         if (!empty($this->update_results['core'])) {
             $this->after_core_update($this->update_results['core'][0]);
         }
         /**
          * Fires after all automatic updates have run.
          *
          * @since 3.8.0
          *
          * @param array $update_results The results of all attempted updates.
          */
         do_action('automatic_updates_complete', $this->update_results);
     }
     $this->release_lock('auto_updater');
 }
 /**
  * Kicks off the background update process, looping through all pending updates.
  *
  * @since 3.7.0
  */
 public function run()
 {
     global $wpdb, $wp_version;
     if ($this->is_disabled()) {
         return;
     }
     if (!is_main_network() || !is_main_site()) {
         return;
     }
     $lock_name = 'auto_updater.lock';
     // Try to lock
     $lock_result = $wpdb->query($wpdb->prepare("INSERT IGNORE INTO `{$wpdb->options}` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time()));
     if (!$lock_result) {
         $lock_result = get_option($lock_name);
         // If we couldn't create a lock, and there isn't a lock, bail
         if (!$lock_result) {
             return;
         }
         // Check to see if the lock is still valid
         if ($lock_result > time() - HOUR_IN_SECONDS) {
             return;
         }
     }
     // Update the lock, as by this point we've definitely got a lock, just need to fire the actions
     update_option($lock_name, time());
     // Don't automatically run these thins, as we'll handle it ourselves
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
     remove_action('upgrader_process_complete', 'wp_version_check');
     remove_action('upgrader_process_complete', 'wp_update_plugins');
     remove_action('upgrader_process_complete', 'wp_update_themes');
     // Next, Plugins
     wp_update_plugins();
     // Check for Plugin updates
     $plugin_updates = get_site_transient('update_plugins');
     if ($plugin_updates && !empty($plugin_updates->response)) {
         foreach ($plugin_updates->response as $plugin) {
             $this->update('plugin', $plugin);
         }
         // Force refresh of plugin update information
         wp_clean_plugins_cache();
     }
     // Next, those themes we all love
     wp_update_themes();
     // Check for Theme updates
     $theme_updates = get_site_transient('update_themes');
     if ($theme_updates && !empty($theme_updates->response)) {
         foreach ($theme_updates->response as $theme) {
             $this->update('theme', (object) $theme);
         }
         // Force refresh of theme update information
         wp_clean_themes_cache();
     }
     // Next, Process any core update
     wp_version_check();
     // Check for Core updates
     $core_update = find_core_auto_update();
     if ($core_update) {
         $this->update('core', $core_update);
     }
     // Clean up, and check for any pending translations
     // (Core_Upgrader checks for core updates)
     $theme_stats = array();
     if (isset($this->update_results['theme'])) {
         foreach ($this->update_results['theme'] as $upgrade) {
             $theme_stats[$upgrade->item->theme] = true === $upgrade->result;
         }
     }
     wp_update_themes($theme_stats);
     // Check for Theme updates
     $plugin_stats = array();
     if (isset($this->update_results['plugin'])) {
         foreach ($this->update_results['plugin'] as $upgrade) {
             $plugin_stats[$upgrade->item->plugin] = true === $upgrade->result;
         }
     }
     wp_update_plugins($plugin_stats);
     // Check for Plugin updates
     // Finally, Process any new translations
     $language_updates = wp_get_translation_updates();
     if ($language_updates) {
         foreach ($language_updates as $update) {
             $this->update('translation', $update);
         }
         // Clear existing caches
         wp_clean_update_cache();
         wp_version_check();
         // check for Core updates
         wp_update_themes();
         // Check for Theme updates
         wp_update_plugins();
         // Check for Plugin updates
     }
     // Send debugging email to all development installs.
     if (!empty($this->update_results)) {
         $development_version = false !== strpos($wp_version, '-');
         /**
          * Filter whether to send a debugging email for each automatic background update.
          *
          * @since 3.7.0
          *
          * @param bool $development_version By default, emails are sent if the
          *                                  install is a development version.
          *                                  Return false to avoid the email.
          */
         if (apply_filters('automatic_updates_send_debug_email', $development_version)) {
             $this->send_debug_email();
         }
         if (!empty($this->update_results['core'])) {
             $this->after_core_update($this->update_results['core'][0]);
         }
         /**
          * Fires after all automatic updates have run.
          *
          * @since 3.8.0
          *
          * @param array $update_results The results of all attempted updates.
          */
         do_action('automatic_updates_complete', $this->update_results);
     }
     // Clear the lock
     delete_option($lock_name);
 }
 public function get_updates($options)
 {
     if (!current_user_can('update_plugins') && !current_user_can('update_themes') && !current_user_can('update_core')) {
         return $this->_generic_error_response('updates_permission_denied');
     }
     $this->_admin_include('plugin.php', 'update.php', 'file.php', 'template.php');
     $this->_frontend_include('update.php');
     if (!is_array($options)) {
         $options = array();
     }
     // Normalise it
     $plugin_updates = array();
     if (current_user_can('update_plugins')) {
         // Detect if refresh needed
         $transient = get_site_transient('update_plugins');
         if (!empty($options['force_refresh']) || false === $transient) {
             delete_site_transient('update_plugins');
             wp_update_plugins();
         }
         $get_plugin_updates = get_plugin_updates();
         if (is_array($get_plugin_updates)) {
             foreach ($get_plugin_updates as $update) {
                 $plugin_updates[] = array('name' => $update->Name, 'plugin_uri' => $update->PluginURI, 'version' => $update->Version, 'description' => $update->Description, 'author' => $update->Author, 'author_uri' => $update->AuthorURI, 'title' => $update->Title, 'author_name' => $update->AuthorName, 'update' => array('plugin' => $update->update->plugin, 'slug' => $update->update->slug, 'new_version' => $update->update->new_version, 'package' => $update->update->package, 'tested' => isset($update->update->tested) ? $update->update->tested : null, 'compatibility' => isset($update->update->compatibility) ? (array) $update->update->compatibility : null, 'sections' => isset($update->update->sections) ? (array) $update->update->sections : null));
             }
         }
     }
     $theme_updates = array();
     if (current_user_can('update_themes')) {
         // Detect if refresh needed
         $transient = get_site_transient('update_themes');
         if (!empty($options['force_refresh']) || false === $transient) {
             delete_site_transient('update_themes');
             wp_update_themes();
         }
         $get_theme_updates = get_theme_updates();
         if (is_array($get_theme_updates)) {
             foreach ($get_theme_updates as $update) {
                 $theme_updates[] = array('name' => @$update->Name, 'theme_uri' => @$update->ThemeURI, 'version' => @$update->Version, 'description' => @$update->Description, 'author' => @$update->Author, 'author_uri' => @$update->AuthorURI, 'update' => array('theme' => @$update->update['theme'], 'new_version' => @$update->update['new_version'], 'package' => @$update->update['package'], 'url' => @$update->update['url']));
             }
         }
     }
     $core_updates = array();
     if (current_user_can('update_core')) {
         // Detect if refresh needed
         $transient = get_site_transient('update_core');
         if (!empty($options['force_refresh']) || false === $transient) {
             // The next line is only needed for older WP versions - otherwise, the parameter to wp_version_check forces a check.
             delete_site_transient('update_core');
             wp_version_check(array(), true);
         }
         $get_core_updates = get_core_updates();
         if (is_array($get_core_updates)) {
             $core_update_key = false;
             $core_update_latest_version = false;
             @(include ABSPATH . WPINC . '/version.php');
             foreach ($get_core_updates as $k => $core_update) {
                 if (isset($core_update->version) && version_compare($core_update->version, $wp_version, '>') && version_compare($core_update->version, $core_update_latest_version, '>')) {
                     $core_update_latest_version = $core_update->version;
                     $core_update_key = $k;
                 }
             }
             if ($core_update_key !== false) {
                 $update = $get_core_updates[$core_update_key];
                 global $wpdb;
                 $mysql_version = $wpdb->db_version();
                 $is_mysql = file_exists(WP_CONTENT_DIR . '/db.php') && empty($wpdb->is_mysql) ? false : true;
                 $core_updates[] = array('download' => $update->download, 'version' => $update->version, 'php_version' => $update->php_version, 'mysql_version' => $update->mysql_version, 'installed' => array('version' => $wp_version, 'mysql' => $mysql_version, 'php' => PHP_VERSION, 'is_mysql' => $is_mysql), 'sufficient' => array('mysql' => version_compare($mysql_version, $update->mysql_version, '>='), 'php' => version_compare(PHP_VERSION, $update->php_version, '>=')));
             }
         }
     }
     // Do we need to ask the user for filesystem credentials?
     $request_filesystem_credentials = array();
     $check_fs = array('plugins' => WP_PLUGIN_DIR, 'themes' => WP_CONTENT_DIR . '/themes', 'core' => untrailingslashit(ABSPATH));
     foreach ($check_fs as $entity => $dir) {
         $filesystem_method = get_filesystem_method(array(), $dir);
         ob_start();
         $filesystem_credentials_are_stored = request_filesystem_credentials(site_url());
         $filesystem_form = strip_tags(ob_get_contents(), '<div><h2><p><input><label><fieldset><legend><span><em>');
         ob_end_clean();
         $request_filesystem_credentials[$entity] = $filesystem_method != 'direct' && !$filesystem_credentials_are_stored;
     }
     $automatic_backups = class_exists('UpdraftPlus_Options') && class_exists('UpdraftPlus_Addon_Autobackup') && UpdraftPlus_Options::get_updraft_option('updraft_autobackup_default', true) ? true : false;
     return $this->_response(array('plugins' => $plugin_updates, 'themes' => $theme_updates, 'core' => $core_updates, 'meta' => array('request_filesystem_credentials' => $request_filesystem_credentials, 'filesystem_form' => $filesystem_form, 'automatic_backups' => $automatic_backups)));
 }
Beispiel #27
0
 public function check_notifications()
 {
     global $wp_version;
     $mwp_notifications = get_option('mwp_notifications', true);
     $args = array();
     $updates = array();
     $send = 0;
     if (is_array($mwp_notifications) && $mwp_notifications != false) {
         include_once ABSPATH . 'wp-includes/update.php';
         include_once ABSPATH . '/wp-admin/includes/update.php';
         extract($mwp_notifications);
         //Check wordpress core updates
         if ($wp) {
             @wp_version_check();
             if (function_exists('get_core_updates')) {
                 $wp_updates = get_core_updates();
                 if (!empty($wp_updates)) {
                     $current_transient = $wp_updates[0];
                     if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
                         $current_transient->current_version = $wp_version;
                         $updates['core_updates'] = $current_transient;
                     } else {
                         $updates['core_updates'] = array();
                     }
                 } else {
                     $updates['core_updates'] = array();
                 }
             }
         }
         //Check plugin updates
         if ($plugins) {
             @wp_update_plugins();
             $this->get_installer_instance();
             $updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
         }
         //Check theme updates
         if ($themes) {
             @wp_update_themes();
             $this->get_installer_instance();
             $updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
         }
         if ($backups) {
             $this->get_backup_instance();
             $backups = $this->backup_instance->get_backup_stats();
             $updates['backups'] = $backups;
             foreach ($backups as $task_name => $backup_results) {
                 foreach ($backup_results as $k => $backup) {
                     if (isset($backups[$task_name][$k]['server']['file_path'])) {
                         unset($backups[$task_name][$k]['server']['file_path']);
                     }
                 }
             }
             $updates['backups'] = $backups;
         }
         if (!empty($updates)) {
             $args['body']['updates'] = $updates;
             $args['body']['notification_key'] = $notification_key;
             $send = 1;
         }
     }
     $alert_data = get_option('mwp_pageview_alerts', true);
     if (is_array($alert_data) && $alert_data['alert']) {
         $pageviews = get_option('user_hit_count');
         $args['body']['alerts']['pageviews'] = $pageviews;
         $args['body']['alerts']['site_id'] = $alert_data['site_id'];
         if (!isset($url)) {
             $url = $alert_data['url'];
         }
         $send = 1;
     }
     if ($send) {
         if (!class_exists('WP_Http')) {
             include_once ABSPATH . WPINC . '/class-http.php';
         }
         $result = wp_remote_post($url, $args);
         if (is_array($result) && $result['body'] == 'mwp_delete_alert') {
             delete_option('mwp_pageview_alerts');
         }
     }
 }
 /**
  * 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;
 }
 function test_full_sync_sends_theme_updates()
 {
     wp_update_themes();
     $this->client->do_sync();
     // check that an update just finished
     $updates = $this->server_replica_storage->get_updates('themes');
     $this->assertTrue($updates->last_checked > strtotime("-2 seconds"));
     // we need to do this because there's a check for elapsed time since last update
     // in the wp_update_themes() function
     delete_site_transient('update_themes');
     $this->server_replica_storage->reset();
     $this->assertNull($this->server_replica_storage->get_updates('themes'));
     // full sync should re-check for plugin updates
     $this->full_sync->start();
     $this->client->do_sync();
     $updates = $this->server_replica_storage->get_updates('themes');
     $this->assertNotNull($updates);
     $this->assertTrue($updates->last_checked > strtotime("-10 seconds"));
 }
Beispiel #30
0
 public function languages_page()
 {
     // prepare the list of tabs
     $tabs = array('lang' => __('Languages', 'polylang'));
     // only if at least one language has been created
     if ($listlanguages = $this->model->get_languages_list()) {
         $tabs['strings'] = __('Strings translation', 'polylang');
         $tabs['settings'] = __('Settings', 'polylang');
     }
     $tabs = apply_filters('pll_settings_tabs', $tabs);
     switch ($this->active_tab) {
         case 'lang':
             // prepare the list table of languages
             $list_table = new PLL_Table_Languages();
             $list_table->prepare_items($listlanguages);
             break;
         case 'strings':
             // get the strings to translate
             $data = PLL_Admin_Strings::get_strings();
             // get the groups
             foreach ($data as $key => $row) {
                 $groups[] = $row['context'];
             }
             $groups = array_unique($groups);
             $selected = empty($_REQUEST['group']) || !in_array($_REQUEST['group'], $groups) ? -1 : $_REQUEST['group'];
             $s = empty($_REQUEST['s']) ? '' : wp_unslash($_REQUEST['s']);
             // filter for search string
             foreach ($data as $key => $row) {
                 if ($selected != -1 && $row['context'] != $selected || !empty($s) && stripos($row['name'], $s) === false && stripos($row['string'], $s) === false) {
                     unset($data[$key]);
                 }
             }
             // load translations
             foreach ($listlanguages as $language) {
                 // filters by language if requested
                 if (($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) && $language->slug != $lg) {
                     continue;
                 }
                 $mo = new PLL_MO();
                 // print_r($language);
                 $mo->import_from_db($language);
                 foreach ($data as $key => $row) {
                     $data[$key]['translations'][$language->slug] = $mo->translate($row['string']);
                     $data[$key]['row'] = $key;
                     // store the row number for convenience
                 }
             }
             // get an array with language slugs as keys, names as values
             $languages = array_combine(wp_list_pluck($listlanguages, 'slug'), wp_list_pluck($listlanguages, 'name'));
             $string_table = new PLL_Table_String(compact('languages', 'groups', 'selected'));
             $string_table->prepare_items($data);
             break;
         case 'settings':
             $post_types = get_post_types(array('public' => true, '_builtin' => false));
             $post_types = array_diff($post_types, get_post_types(array('_pll' => true)));
             $post_types = array_unique(apply_filters('pll_get_post_types', $post_types, true));
             $taxonomies = get_taxonomies(array('public' => true, '_builtin' => false));
             $taxonomies = array_diff($taxonomies, get_taxonomies(array('_pll' => true)));
             $taxonomies = array_unique(apply_filters('pll_get_taxonomies', $taxonomies, true));
             break;
         default:
             break;
     }
     $action = isset($_REQUEST['pll_action']) ? $_REQUEST['pll_action'] : '';
     switch ($action) {
         case 'add':
             check_admin_referer('add-lang', '_wpnonce_add-lang');
             if ($this->model->add_language($_POST)) {
                 // backward compatibility WP < 4.0
                 if (version_compare($GLOBALS['wp_version'], '4.0', '<')) {
                     PLL_Admin::download_mo($_POST['locale']);
                 } elseif ('en_US' != $_POST['locale']) {
                     // attempts to install the language pack
                     require_once ABSPATH . 'wp-admin/includes/translation-install.php';
                     if (!wp_download_language_pack($_POST['locale'])) {
                         add_settings_error('general', 'pll_download_mo', __('The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang'));
                     }
                     // force checking for themes and plugins translations updates
                     wp_update_themes();
                     wp_update_plugins();
                 }
             }
             $this->redirect();
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             break;
         case 'delete':
             check_admin_referer('delete-lang');
             if (!empty($_GET['lang'])) {
                 $this->model->delete_language((int) $_GET['lang']);
             }
             $this->redirect();
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             break;
         case 'edit':
             if (!empty($_GET['lang'])) {
                 $edit_lang = $this->model->get_language((int) $_GET['lang']);
             }
             break;
         case 'update':
             check_admin_referer('add-lang', '_wpnonce_add-lang');
             $error = $this->model->update_language($_POST);
             $this->redirect();
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             break;
         case 'string-translation':
             if (!empty($_REQUEST['submit'])) {
                 check_admin_referer('string-translation', '_wpnonce_string-translation');
                 $strings = PLL_Admin_Strings::get_strings();
                 foreach ($this->model->get_languages_list() as $language) {
                     if (empty($_POST['translation'][$language->slug])) {
                         // in case the language filter is active (thanks to John P. Bloch)
                         continue;
                     }
                     $mo = new PLL_MO();
                     $mo->import_from_db($language);
                     foreach ($_POST['translation'][$language->slug] as $key => $translation) {
                         $translation = apply_filters('pll_sanitize_string_translation', $translation, $strings[$key]['name'], $strings[$key]['context']);
                         $mo->add_entry($mo->make_entry($strings[$key]['string'], $translation));
                     }
                     // clean database (removes all strings which were registered some day but are no more)
                     if (!empty($_POST['clean'])) {
                         $new_mo = new PLL_MO();
                         foreach ($strings as $string) {
                             $new_mo->add_entry($mo->make_entry($string['string'], $mo->translate($string['string'])));
                         }
                     }
                     isset($new_mo) ? $new_mo->export_to_db($language) : $mo->export_to_db($language);
                 }
                 add_settings_error('general', 'pll_strings_translations_updated', __('Translations updated.', 'polylang'), 'updated');
             }
             do_action('pll_save_strings_translations');
             // unregisters strings registered through WPML API
             if ($string_table->current_action() == 'delete' && !empty($_REQUEST['strings']) && function_exists('icl_unregister_string')) {
                 check_admin_referer('string-translation', '_wpnonce_string-translation');
                 $strings = PLL_Admin_Strings::get_strings();
                 foreach ($_REQUEST['strings'] as $key) {
                     icl_unregister_string($strings[$key]['context'], $strings[$key]['name']);
                 }
             }
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             $this->redirect(array_intersect_key($_REQUEST, array_flip(array('s', 'paged', 'group'))));
             break;
         case 'options':
             check_admin_referer('options-lang', '_wpnonce_options-lang');
             $this->options['default_lang'] = sanitize_title($_POST['default_lang']);
             // we have slug as value
             foreach (array('force_lang', 'rewrite') as $key) {
                 $this->options[$key] = isset($_POST[$key]) ? (int) $_POST[$key] : 0;
             }
             if (3 == $this->options['force_lang'] && isset($_POST['domains']) && is_array($_POST['domains'])) {
                 foreach ($_POST['domains'] as $key => $domain) {
                     $this->options['domains'][$key] = esc_url_raw(trim($domain));
                 }
             }
             foreach (array('browser', 'hide_default', 'redirect_lang', 'media_support') as $key) {
                 $this->options[$key] = isset($_POST[$key]) ? 1 : 0;
             }
             if (3 == $this->options['force_lang']) {
                 $this->options['browser'] = $this->options['hide_default'] = 0;
             }
             foreach (array('sync', 'post_types', 'taxonomies') as $key) {
                 $this->options[$key] = empty($_POST[$key]) ? array() : array_keys($_POST[$key], 1);
             }
             update_option('polylang', $this->options);
             // refresh rewrite rules in case rewrite,  hide_default, post types or taxonomies options have been modified
             // it seems useless to refresh permastruct here
             flush_rewrite_rules();
             // refresh language cache in case home urls have been modified
             $this->model->clean_languages_cache();
             // fills existing posts & terms with default language
             if (isset($_POST['fill_languages']) && ($nolang = $this->model->get_objects_with_no_lang())) {
                 if (!empty($nolang['posts'])) {
                     $this->model->set_language_in_mass('post', $nolang['posts'], $this->options['default_lang']);
                 }
                 if (!empty($nolang['terms'])) {
                     $this->model->set_language_in_mass('term', $nolang['terms'], $this->options['default_lang']);
                 }
             }
             add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
             $this->redirect();
             break;
         default:
             break;
     }
     // displays the page
     include PLL_ADMIN_INC . '/view-languages.php';
 }