Make WordPress Core

Changeset 19683


Ignore:
Timestamp:
01/05/2012 07:49:47 PM (13 years ago)
Author:
ryan
Message:

Check for plugin and theme updates more often when visitng update-core.php. Props kurtpayne. fixes #18876

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/update.php

    r19312 r19683  
    3434        $current->version_checked = $wp_version;
    3535    }
     36
     37    // Wait 60 seconds between multiple version check requests
     38    $timeout = 60;
     39    $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
     40    if ( $time_not_changed )
     41        return false;
    3642
    3743    $locale = apply_filters( 'core_version_check_locale', get_locale() );
     
    144150    $new_option = new stdClass;
    145151    $new_option->last_checked = time();
    146     // Check for updated every 60 minutes if hitting update pages; else, check every 12 hours.
    147     $timeout = in_array( current_filter(), array( 'load-plugins.php', 'load-update.php', 'load-update-core.php' ) ) ? 3600 : 43200;
     152
     153    // Check for update on a different schedule, depending on the page.
     154    switch ( current_filter() ) {
     155        case 'load-update-core.php' :
     156            $timeout = 60; // 1 min
     157            break;
     158        case 'load-plugins.php' :
     159        case 'load-update.php' :
     160            $timeout = 3600; // 1 hour
     161            break;
     162        default :
     163            $timeout = 43200; // 12 hours
     164    }
     165   
    148166    $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
    149167
    150     $plugin_changed = false;
    151     foreach ( $plugins as $file => $p ) {
    152         $new_option->checked[ $file ] = $p['Version'];
    153 
    154         if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
    155             $plugin_changed = true;
    156     }
    157 
    158     if ( isset ( $current->response ) && is_array( $current->response ) ) {
    159         foreach ( $current->response as $plugin_file => $update_details ) {
    160             if ( ! isset($plugins[ $plugin_file ]) ) {
     168    if ( $time_not_changed ) {
     169        $plugin_changed = false;
     170        foreach ( $plugins as $file => $p ) {
     171            $new_option->checked[ $file ] = $p['Version'];
     172
     173            if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
    161174                $plugin_changed = true;
    162                 break;
     175        }
     176
     177        if ( isset ( $current->response ) && is_array( $current->response ) ) {
     178            foreach ( $current->response as $plugin_file => $update_details ) {
     179                if ( ! isset($plugins[ $plugin_file ]) ) {
     180                    $plugin_changed = true;
     181                    break;
     182                }
    163183            }
    164184        }
    165     }
    166 
    167     // Bail if we've checked in the last 12 hours and if nothing has changed
    168     if ( $time_not_changed && !$plugin_changed )
    169         return false;
     185
     186        // Bail if we've checked recently and if nothing has changed
     187        if ( ! $plugin_changed )
     188            return false;
     189    }
    170190
    171191    // Update last_checked for current to prevent multiple blocking requests if request hangs
     
    223243        $last_update = new stdClass;
    224244
    225     // Check for updated every 60 minutes if hitting update pages; else, check every 12 hours.
    226     $timeout = in_array( current_filter(), array( 'load-themes.php', 'load-update.php', 'load-update-core.php' ) ) ? 3600 : 43200;
    227     $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time( ) - $last_update->last_checked );
    228 
    229245    $themes = array();
    230246    $checked = array();
     
    247263    }
    248264
    249     $theme_changed = false;
    250     foreach ( $checked as $slug => $v ) {
    251         $update_request->checked[ $slug ] = $v;
    252 
    253         if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
    254             $theme_changed = true;
    255     }
    256 
    257     if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
    258         foreach ( $last_update->response as $slug => $update_details ) {
    259             if ( ! isset($checked[ $slug ]) ) {
     265    // Check for update on a different schedule, depending on the page.
     266    switch ( current_filter() ) {
     267        case 'load-update-core.php' :
     268            $timeout = 60; // 1 min
     269            break;
     270        case 'load-plugins.php' :
     271        case 'load-update.php' :
     272            $timeout = 3600; // 1 hour
     273            break;
     274        default :
     275            $timeout = 43200; // 12 hours
     276    }
     277   
     278    $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time( ) - $last_update->last_checked );
     279
     280    if ( $time_not_changed ) {
     281        $theme_changed = false;
     282        foreach ( $checked as $slug => $v ) {
     283            $update_request->checked[ $slug ] = $v;
     284
     285            if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
    260286                $theme_changed = true;
    261                 break;
     287        }
     288
     289        if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
     290            foreach ( $last_update->response as $slug => $update_details ) {
     291                if ( ! isset($checked[ $slug ]) ) {
     292                    $theme_changed = true;
     293                    break;
     294                }
    262295            }
    263296        }
    264     }
    265 
    266     if ( $time_not_changed && !$theme_changed )
    267         return false;
     297
     298        // Bail if we've checked recently and if nothing has changed
     299        if ( ! $theme_changed )
     300            return false;
     301    }
    268302
    269303    // Update last_checked for current to prevent multiple blocking requests if request hangs
Note: See TracChangeset for help on using the changeset viewer.