Make WordPress Core


Ignore:
Timestamp:
09/13/2013 06:18:16 AM (13 years ago)
Author:
dd32
Message:

WordPress Core Automatic Updates: Add the first slice of Automatic Upgrades, This is presently disabled, and requires a filter to enable ( 'auto_upgrade_core' ). See #22704

File:
1 edited

Legend:

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

    r25308 r25421  
    121121    $updates->version_checked = $wp_version;
    122122    set_site_transient( 'update_core',  $updates);
     123
     124    wp_auto_updates_maybe_queue( 'core' );
    123125}
    124126
     
    222224
    223225    set_site_transient( 'update_plugins', $new_option );
     226
     227    wp_auto_updates_maybe_queue( 'plugins' );
    224228}
    225229
     
    332336
    333337    set_site_transient( 'update_themes', $new_update );
     338
     339    wp_auto_updates_maybe_queue( 'themes' );
     340}
     341
     342/**
     343 * Queues a cron entry if a potentially upgrade is detected.
     344 *
     345 * @since 3.7.0
     346 *
     347 * @param string $type The type of update to check for, may be 'core', 'plugins', or, 'themes'.
     348 */
     349function wp_auto_updates_maybe_queue( $type = 'core' ) {
     350    include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     351    include_once ABSPATH . '/wp-admin/includes/update.php';
     352
     353    if ( WP_Automatic_Upgrader::upgrader_disabled() )
     354        return;
     355
     356    $updates_available = false;
     357    if ( 'core' == $type ) {
     358        $updates_available = (bool) find_core_auto_update();
     359    } elseif ( 'plugins' == $type ) {
     360        $plugin_updates = get_site_transient( 'update_plugins' );
     361        $updates_available = !empty( $plugin_updates->response );
     362    } elseif ( 'themes' == $type ) {
     363        $theme_updates = get_site_transient( 'update_themes' );
     364        $updates_available = empty( $theme_updates->response );
     365    }
     366
     367    if ( $updates_available && ! wp_next_scheduled( 'wp_auto_updates_execute' ) ) {
     368        // If the transient update was triggered by a user pageview, update in an hours time, else, now.
     369        $when_to_update = get_current_user_id() ? time() + HOUR_IN_SECONDS : time();
     370        $when_to_update = apply_filters( 'auto_upgrade_when_to_upgrade', $when_to_update );
     371
     372        wp_schedule_single_event( $when_to_update, 'wp_auto_updates_execute' );
     373    }
     374
     375}
     376
     377function wp_auto_updates_execute() {
     378    include_once ABSPATH . '/wp-admin/includes/admin.php';
     379    include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     380
     381    if ( WP_Automatic_Upgrader::upgrader_disabled() )
     382        return;
     383
     384    WP_Automatic_Upgrader::perform_auto_updates();
    334385}
    335386
     
    457508add_action( 'wp_update_themes', 'wp_update_themes' );
    458509
     510// Automatic Updates - Cron callback
     511add_action( 'wp_auto_updates_execute', 'wp_auto_updates_execute' );
     512
    459513add_action('init', 'wp_schedule_update_checks');
Note: See TracChangeset for help on using the changeset viewer.