How To/What triggers a WordPress auto update?

The question:

I installed WordPress 4.0.1 and added this to my wp-config.php (via this link)

define( 'WP_AUTO_UPDATE_CORE', true );

I then visited my site (I read somewhere before that the site has to be visited to trigger the auto update)…but hours later and nothing has happened (my site has not auto updated to 4.1.1).

I cannot find any information on what triggers/causes WordPress to auto update (and cannot find the bookmark I had of where I read that visiting the site is part of it).

Does anyone know and/or can point me to some hard data of how to/what triggers WordPress to auto update?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment