WordPress.org

Make WordPress Core

Ticket #7372: 7372.4.diff

File 7372.4.diff, 2.8 KB (added by ryan, 6 years ago)

Check if update needed on every admin page load

  • wp-includes/update.php

     
    9090        if ( !function_exists('fsockopen') || defined('WP_INSTALLING') ) 
    9191                return false; 
    9292 
    93         $current = get_option( 'update_plugins' ); 
    94  
    95         $time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ); 
    96  
    9793        // If running blog-side, bail unless we've not checked in the last 12 hours 
    98         if ( !function_exists( 'get_plugins' ) ) { 
    99                 if ( $time_not_changed ) 
    100                         return false; 
     94        if ( !function_exists( 'get_plugins' ) ) 
    10195                require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
    102         } 
    10396 
    10497        $plugins = get_plugins(); 
    10598        $active  = get_option( 'active_plugins' ); 
     99        $current = get_option( 'update_plugins' ); 
    106100 
    107101        $new_option = ''; 
    108102        $new_option->last_checked = time(); 
     103        $time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ); 
    109104 
    110105        $plugin_changed = false; 
    111106        foreach ( $plugins as $file => $p ) { 
     
    160155 
    161156        update_option( 'update_plugins', $new_option ); 
    162157} 
    163 if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) 
    164         add_action( 'admin_init', 'wp_update_plugins' ); 
    165 else 
    166         add_action( 'init', 'wp_update_plugins' ); 
    167158 
     159function _maybe_update_plugins() { 
     160        $current = get_option( 'update_plugins' ); 
     161        if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) ) 
     162                return; 
     163        wp_update_plugins(); 
     164} 
     165 
     166add_action( 'load-plugins.php', 'wp_update_plugins' ); 
     167add_action( 'admin_init', '_maybe_update_plugins' ); 
     168add_action( 'wp_update_plugins', 'wp_update_plugins' ); 
     169 
     170if ( !wp_next_scheduled('wp_update_plugins') ) 
     171        wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); 
     172 
    168173?> 
  • wp-includes/cron.php

     
    133133function wp_get_schedules() { 
    134134        $schedules = array( 
    135135                'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ), 
     136                'twicedaily' => array( 'interval' => 43200, 'display' => __('Twice Daily') ), 
    136137                'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ), 
    137138        ); 
    138139        return array_merge( apply_filters( 'cron_schedules', array() ), $schedules ); 
  • wp-admin/includes/plugin.php

     
    9999function get_plugins($plugin_folder = '') { 
    100100         
    101101        if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) 
    102                 $cached_plugins = array(); 
     102                $cache_plugins = array(); 
    103103         
    104104        if ( isset($cache_plugins[ $plugin_folder ]) ) 
    105105                return $cache_plugins[ $plugin_folder ];