Make WordPress Core


Ignore:
Timestamp:
11/12/2020 10:35:54 PM (3 years ago)
Author:
helen
Message:

Upgrade/Install: Better UI for auto-update settings on update screen.

This adds clearer messages about what your current settings mean for updates, uses a more compact link-based action instead of a checkbox to change the setting, and respects constants and filters.

Props audrasjb, karmatosed, helen, azaozz, hedgefield, marybaum.
Fixes #51742.

File:
1 edited

Legend:

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

    r49490 r49587  
    6363
    6464    if ( 'development' === $update->response ) {
    65         $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' );
     65        $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build manually:' );
    6666    } else {
    6767        if ( $current ) {
     
    128128                $message = sprintf(
    129129                    /* translators: 1: Installed WordPress version number, 2: URL to WordPress release notes, 3: New WordPress version number, including locale if necessary. */
    130                     __( 'You can update from WordPress %1$s to <a href="%2$s">WordPress %3$s</a> automatically:' ),
     130                    __( 'You can update from WordPress %1$s to <a href="%2$s">WordPress %3$s</a> manually:' ),
    131131                    $wp_version,
    132132                    $version_url,
     
    255255
    256256    if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
    257         echo '<div class="notice notice-warning"><p>';
     257        echo '<h2 class="response">';
     258        _e( 'An updated version of WordPress is available.' );
     259        echo '</h2>';
     260
     261        echo '<div class="notice notice-warning inline"><p>';
    258262        printf(
    259263            /* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */
     
    263267        );
    264268        echo '</p></div>';
    265 
    266         echo '<h2 class="response">';
    267         _e( 'An updated version of WordPress is available.' );
    268         echo '</h2>';
    269269    }
    270270
     
    307307 */
    308308function core_auto_updates_settings() {
    309     $upgrade_major_value = '';
    310     if ( isset( $_POST['core-auto-updates-settings'] ) && wp_verify_nonce( $_POST['set_core_auto_updates_settings'], 'core-auto-updates-nonce' ) ) {
    311         if ( isset( $_POST['core-auto-updates-major'] ) && 1 === (int) $_POST['core-auto-updates-major'] ) {
    312             update_site_option( 'auto_update_core_major', 1 );
    313         } else {
    314             update_site_option( 'auto_update_core_major', 0 );
    315         }
    316         echo '<div class="notice notice-success is-dismissible"><p>';
    317         _e( 'WordPress auto-update settings updated.' );
    318         echo '</p></div>';
    319     }
    320 
    321     $upgrade_dev   = get_site_option( 'auto_update_core_dev', true );
    322     $upgrade_minor = get_site_option( 'auto_update_core_minor', true );
    323     $upgrade_major = get_site_option( 'auto_update_core_major', false );
    324 
     309    if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
     310        if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
     311            $notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
     312            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
     313        } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
     314            $notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
     315            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
     316        }
     317    }
     318
     319    // Defaults:
     320    $upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
     321    $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
     322    $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
     323
     324    $can_set_update_option = true;
    325325    // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false.
    326326    if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
     
    344344            $upgrade_major = false;
    345345        }
     346
     347        // The UI is overridden by the WP_AUTO_UPDATE_CORE constant.
     348        $can_set_update_option = false;
     349    }
     350
     351    if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) ) {
     352        if ( true === AUTOMATIC_UPDATER_DISABLED ) {
     353            $upgrade_dev   = false;
     354            $upgrade_minor = false;
     355            $upgrade_major = false;
     356        }
     357        // The UI is overridden by the AUTOMATIC_UPDATER_DISABLED constant.
     358        $can_set_update_option = false;
     359    }
     360
     361    // Is the UI overridden by a plugin using the allow_major_auto_core_updates filter?
     362    if ( has_filter( 'allow_major_auto_core_updates' ) ) {
     363        $can_set_update_option = false;
    346364    }
    347365
     
    358376        'major' => $upgrade_major,
    359377    );
     378
     379    if ( $upgrade_major ) {
     380        $wp_version = get_bloginfo( 'version' );
     381        $updates    = get_core_updates();
     382
     383        if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
     384            echo '<p>' . wp_get_auto_update_message() . '</p>';
     385        }
     386    }
     387
     388    $action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' );
    360389    ?>
    361     <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" name="core-auto-updates" class="form-core-auto-updates">
    362         <?php wp_nonce_field( 'core-auto-updates-nonce', 'set_core_auto_updates_settings' ); ?>
    363         <h2><?php _e( 'Auto-update settings' ); ?></h2>
    364         <p>
    365             <?php
    366             if ( $auto_update_settings['major'] ) {
    367                 $wp_version = get_bloginfo( 'version' );
    368                 $updates    = get_core_updates();
    369                 if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
    370                     echo wp_get_auto_update_message();
    371                 }
    372             }
    373             ?>
    374         </p>
    375         <p>
    376             <input type="checkbox" name="core-auto-updates-major" id="core-auto-updates-major" value="1" <?php checked( $auto_update_settings['major'], 1 ); ?> />
    377             <label for="core-auto-updates-major">
    378                 <?php _e( 'Automatically keep this site up-to-date with regular feature updates.' ); ?>
    379             </label>
    380         </p>
     390
     391    <p class="auto-update-status">
    381392        <?php
    382         /**
    383          * Fires after the major core auto-update checkbox.
    384          *
    385          * @since 5.6.0
    386          */
    387         do_action( 'after_core_auto_updates_settings_fields', $auto_update_settings );
     393        if ( $upgrade_major ) {
     394            _e( 'This site is automatically kept up to date with each new version of WordPress.' );
     395
     396            if ( $can_set_update_option ) {
     397                echo '<br>';
     398                echo sprintf(
     399                    /* Translators: Action link to disable core auto-updates. */
     400                    __( '<a href="%s">Switch to automatic updates for maintenance and security releases only.</a>' ),
     401                    wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' )
     402                );
     403            }
     404        } elseif ( $upgrade_minor ) {
     405            _e( 'This site is automatically kept up to date with maintenance and security releases of WordPress.' );
     406
     407            if ( $can_set_update_option ) {
     408                echo '<br>';
     409                echo sprintf(
     410                    /* Translators: Action link to enable core auto-updates. */
     411                    __( '<a href="%s">Enable automatic updates for all new versions of WordPress.</a>' ),
     412                    wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' )
     413                );
     414            }
     415        } else {
     416            _e( 'This site will not receive automatic updates for new versions of WordPress.' );
     417        }
    388418        ?>
    389         <p>
    390             <input id="core-auto-updates-settings" class="button" type="submit" value="<?php esc_attr_e( 'Save' ); ?>" name="core-auto-updates-settings" />
    391         </p>
    392     </form>
     419    </p>
     420
    393421    <?php
     422    /**
     423     * Fires after the major core auto-update settings.
     424     *
     425     * @since 5.6.0
     426     */
     427    do_action( 'after_core_auto_updates_settings', $auto_update_settings );
    394428}
    395429
     
    958992    <div class="wrap">
    959993    <h1><?php _e( 'WordPress Updates' ); ?></h1>
     994    <p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>
     995
    960996    <?php
    961997    if ( $upgrade_error ) {
     
    9761012    }
    9771013
    978     echo '<p>';
     1014    echo '<h2 class="wp-current-version">';
     1015    /* translators: Current version of WordPress. */
     1016    printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
     1017    echo '</h2>';
     1018
     1019    echo '<p class="update-last-checked">';
    9791020    /* translators: 1: Date, 2: Time. */
    9801021    printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a' ), $last_update_check ) );
     
    9831024
    9841025    if ( current_user_can( 'update_core' ) ) {
     1026        core_auto_updates_settings();
    9851027        core_upgrade_preamble();
    986         core_auto_updates_settings();
    9871028    }
    9881029    if ( current_user_can( 'update_plugins' ) ) {
     
    11591200    require_once ABSPATH . 'wp-admin/admin-footer.php';
    11601201
     1202} elseif ( 'core-major-auto-updates-settings' === $action ) {
     1203    $redirect_url = self_admin_url( 'update-core.php' );
     1204
     1205    if ( isset( $_GET['value'] ) ) {
     1206        check_admin_referer( 'core-major-auto-updates-nonce' );
     1207
     1208        if ( 'enable' === $_GET['value'] ) {
     1209            update_site_option( 'auto_update_core_major', 'enabled' );
     1210            $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url );
     1211        } elseif ( 'disable' === $_GET['value'] ) {
     1212            update_site_option( 'auto_update_core_major', 'disabled' );
     1213            $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url );
     1214        }
     1215    }
     1216
     1217    wp_redirect( $redirect_url );
     1218    exit;
    11611219} else {
    11621220    /**
Note: See TracChangeset for help on using the changeset viewer.