How To/What triggers a WordPress auto update?

As of WordPress 4.7.3, auto-updates are triggered whenever the following sequence is successful. All the code is in the file wp-includes/update.php.

1. _maybe_update_core() is called (via the admin_init action).

This function is run via the the admin_init action, which executes at the beginning of every admin page before the page is rendered. The update process stops if the current time is less than 12 hours since the last version check (using Transient data), unless the version of the current wordpress has changed (e.g., if WordPress was manually updated since the last time a auto-update ran).

function _maybe_update_core() {
    // include an unmodified $wp_version
    include( ABSPATH . WPINC . '/version.php' );

    $current = get_site_transient( 'update_core' );

    if ( isset( $current->last_checked, $current->version_checked ) &&
        12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
        $current->version_checked == $wp_version ) {
        return;
    }
    wp_version_check();
}

2. wp_version_check() is run and checks for a new version, and decides if doing auto-update is appropriate.

This function is mainly used to ensure version checks don’t run too frequently (max once per minute) and retrieve the version info from the api.wordpress.org version-check API. However, at the very end of the function, updates will be run if the request that triggered the update was done via a CRON task and an auto-update is not currently in process:

if ( defined( 'DOING_CRON' ) && DOING_CRON && ! doing_action( 'wp_maybe_auto_update' ) ) {
    do_action( 'wp_maybe_auto_update' );
}

3. wp_maybe_auto_update() then does the actual upgrade.

function wp_maybe_auto_update() {
    include_once( ABSPATH . '/wp-admin/includes/admin.php' );
    include_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );

    $upgrader = new WP_Automatic_Updater;
    $upgrader->run();
}

Here is a tip how to force an auto-update manually.

Leave a Comment