protected function find_latest_update_offer()
 {
     // Select the latest update.
     // Remove filters to bypass automattic updates.
     add_filter('request_filesystem_credentials', '__return_true');
     add_filter('automatic_updates_is_vcs_checkout', '__return_false');
     add_filter('allow_major_auto_core_updates', '__return_true');
     add_filter('send_core_update_notification_email', '__return_false');
     $update = find_core_auto_update();
     remove_filter('request_filesystem_credentials', '__return_true');
     remove_filter('automatic_updates_is_vcs_checkout', '__return_false');
     remove_filter('allow_major_auto_core_updates', '__return_true');
     remove_filter('send_core_update_notification_email', '__return_false');
     return $update;
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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');
 }