core_auto_updates_settings() WordPress Function

The core_auto_updates_settings() function allows you to configure how WordPress handles automatic background updates. You can use this function to enable or disable automatic updates, as well as configure which types of updates are performed.

core_auto_updates_settings() #

Display WordPress auto-updates settings.


Source

File: wp-admin/update-core.php

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
function core_auto_updates_settings() {
    if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
        if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
            $notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
        } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
            $notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
        }
    }
 
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $updater = new WP_Automatic_Updater();
 
    // Defaults:
    $upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
    $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
    $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
 
    $can_set_update_option = true;
    // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
    if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
        if ( false === WP_AUTO_UPDATE_CORE ) {
            // Defaults to turned off, unless a filter allows it.
            $upgrade_dev   = false;
            $upgrade_minor = false;
            $upgrade_major = false;
        } elseif ( true === WP_AUTO_UPDATE_CORE
            || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
        ) {
            // ALL updates for core.
            $upgrade_dev   = true;
            $upgrade_minor = true;
            $upgrade_major = true;
        } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
            // Only minor updates for core.
            $upgrade_dev   = false;
            $upgrade_minor = true;
            $upgrade_major = false;
        }
 
        // The UI is overridden by the `WP_AUTO_UPDATE_CORE` constant.
        $can_set_update_option = false;
    }
 
    if ( $updater->is_disabled() ) {
        $upgrade_dev   = false;
        $upgrade_minor = false;
        $upgrade_major = false;
 
        /*
         * The UI is overridden by the `AUTOMATIC_UPDATER_DISABLED` constant
         * or the `automatic_updater_disabled` filter,
         * or by `wp_is_file_mod_allowed( 'automatic_updater' )`.
         * See `WP_Automatic_Updater::is_disabled()`.
         */
        $can_set_update_option = false;
    }
 
    // Is the UI overridden by a plugin using the `allow_major_auto_core_updates` filter?
    if ( has_filter( 'allow_major_auto_core_updates' ) ) {
        $can_set_update_option = false;
    }
 
    /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
    $upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev );
    /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
    $upgrade_minor = apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
    /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
    $upgrade_major = apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
 
    $auto_update_settings = array(
        'dev'   => $upgrade_dev,
        'minor' => $upgrade_minor,
        'major' => $upgrade_major,
    );
 
    if ( $upgrade_major ) {
        $wp_version = get_bloginfo( 'version' );
        $updates    = get_core_updates();
 
        if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
            echo '<p>' . wp_get_auto_update_message() . '</p>';
        }
    }
 
    $action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' );
    ?>
 
    <p class="auto-update-status">
        <?php
 
        if ( $updater->is_vcs_checkout( ABSPATH ) ) {
            _e( 'This site appears to be under version control. Automatic updates are disabled.' );
        } elseif ( $upgrade_major ) {
            _e( 'This site is automatically kept up to date with each new version of WordPress.' );
 
            if ( $can_set_update_option ) {
                echo '<br>';
                printf(
                    '<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-disable">%s</a>',
                    wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' ),
                    __( 'Switch to automatic updates for maintenance and security releases only.' )
                );
            }
        } elseif ( $upgrade_minor ) {
            _e( 'This site is automatically kept up to date with maintenance and security releases of WordPress only.' );
 
            if ( $can_set_update_option ) {
                echo '<br>';
                printf(
                    '<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-enable">%s</a>',
                    wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' ),
                    __( 'Enable automatic updates for all new versions of WordPress.' )
                );
            }
        } else {
            _e( 'This site will not receive automatic updates for new versions of WordPress.' );
        }
        ?>
    </p>
 
    <?php
    /**
     * Fires after the major core auto-update settings.
     *
     * @since 5.6.0
     *
     * @param array $auto_update_settings {
     *     Array of core auto-update settings.
     *
     *     @type bool $dev   Whether to enable automatic updates for development versions.
     *     @type bool $minor Whether to enable minor automatic core updates.
     *     @type bool $major Whether to enable major automatic core updates.
     * }
     */
    do_action( 'after_core_auto_updates_settings', $auto_update_settings );
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.