From 9fb87a2d24c6eb723bf5f9d044c01d81012e963f Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Thu, 12 Nov 2020 22:35:54 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@49587 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/common.css | 13 ++ src/wp-admin/includes/class-core-upgrader.php | 6 +- src/wp-admin/update-core.php | 160 ++++++++++++------ 3 files changed, 125 insertions(+), 54 deletions(-) diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index 78fe695cb1..0d843cb5bf 100644 --- a/src/wp-admin/css/common.css +++ b/src/wp-admin/css/common.css @@ -1600,6 +1600,19 @@ form.upgrade .hint { margin: -4px 0; } +h2.wp-current-version { + margin-bottom: .3em; +} + +p.update-last-checked { + margin-top: 0; +} + +p.auto-update-status { + margin-top: 2em; + line-height: 1.8; +} + #ajax-loading, .ajax-loading, .ajax-feedback, diff --git a/src/wp-admin/includes/class-core-upgrader.php b/src/wp-admin/includes/class-core-upgrader.php index 6ffb98a7ec..b57a13fd7b 100644 --- a/src/wp-admin/includes/class-core-upgrader.php +++ b/src/wp-admin/includes/class-core-upgrader.php @@ -279,9 +279,9 @@ class Core_Upgrader extends WP_Upgrader { $current_is_development_version = (bool) strpos( $wp_version, '-' ); // Defaults: - $upgrade_dev = get_site_option( 'auto_update_core_dev', true ); - $upgrade_minor = get_site_option( 'auto_update_core_minor', true ); - $upgrade_major = get_site_option( 'auto_update_core_major', false ); + $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'; // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false. if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php index c08e57f6e9..904a76366a 100644 --- a/src/wp-admin/update-core.php +++ b/src/wp-admin/update-core.php @@ -62,7 +62,7 @@ function list_core_update( $update ) { $show_buttons = true; if ( 'development' === $update->response ) { - $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' ); + $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build manually:' ); } else { if ( $current ) { /* translators: %s: WordPress version. */ @@ -127,7 +127,7 @@ function list_core_update( $update ) { } else { $message = sprintf( /* translators: 1: Installed WordPress version number, 2: URL to WordPress release notes, 3: New WordPress version number, including locale if necessary. */ - __( 'You can update from WordPress %1$s to WordPress %3$s automatically:' ), + __( 'You can update from WordPress %1$s to WordPress %3$s manually:' ), $wp_version, $version_url, $version_string @@ -254,7 +254,11 @@ function core_upgrade_preamble() { } if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) { - echo '

'; + echo '

'; + _e( 'An updated version of WordPress is available.' ); + echo '

'; + + echo '

'; printf( /* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */ __( 'Important: Before updating, please back up your database and files. For help with updates, visit the Updating WordPress documentation page.' ), @@ -262,10 +266,6 @@ function core_upgrade_preamble() { __( 'https://wordpress.org/support/article/updating-wordpress/' ) ); echo '

'; - - echo '

'; - _e( 'An updated version of WordPress is available.' ); - echo '

'; } if ( isset( $updates[0] ) && 'development' === $updates[0]->response ) { @@ -306,22 +306,22 @@ function core_upgrade_preamble() { * @since 5.6.0 */ function core_auto_updates_settings() { - $upgrade_major_value = ''; - if ( isset( $_POST['core-auto-updates-settings'] ) && wp_verify_nonce( $_POST['set_core_auto_updates_settings'], 'core-auto-updates-nonce' ) ) { - if ( isset( $_POST['core-auto-updates-major'] ) && 1 === (int) $_POST['core-auto-updates-major'] ) { - update_site_option( 'auto_update_core_major', 1 ); - } else { - update_site_option( 'auto_update_core_major', 0 ); + 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 '

' . $notice_text . '

'; + } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) { + $notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' ); + echo '

' . $notice_text . '

'; } - echo '

'; - _e( 'WordPress auto-update settings updated.' ); - echo '

'; } - $upgrade_dev = get_site_option( 'auto_update_core_dev', true ); - $upgrade_minor = get_site_option( 'auto_update_core_minor', true ); - $upgrade_major = get_site_option( 'auto_update_core_major', false ); + // 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', 'minor', false. if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { if ( false === WP_AUTO_UPDATE_CORE ) { @@ -343,6 +343,24 @@ function core_auto_updates_settings() { $upgrade_minor = true; $upgrade_major = false; } + + // The UI is overridden by the WP_AUTO_UPDATE_CORE constant. + $can_set_update_option = false; + } + + if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) ) { + if ( true === AUTOMATIC_UPDATER_DISABLED ) { + $upgrade_dev = false; + $upgrade_minor = false; + $upgrade_major = false; + } + // The UI is overridden by the AUTOMATIC_UPDATER_DISABLED constant. + $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 */ @@ -357,40 +375,56 @@ function core_auto_updates_settings() { '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 '

' . wp_get_auto_update_message() . '

'; + } + } + + $action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' ); ?> -
- -

-

- version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) { - echo wp_get_auto_update_message(); - } - } - ?> -

-

- /> - -

+ +

'; + echo sprintf( + /* Translators: Action link to disable core auto-updates. */ + __( 'Switch to automatic updates for maintenance and security releases only.' ), + wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' ) + ); + } + } elseif ( $upgrade_minor ) { + _e( 'This site is automatically kept up to date with maintenance and security releases of WordPress.' ); + + if ( $can_set_update_option ) { + echo '
'; + echo sprintf( + /* Translators: Action link to enable core auto-updates. */ + __( 'Enable automatic updates for all new versions of WordPress.' ), + wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' ) + ); + } + } else { + _e( 'This site will not receive automatic updates for new versions of WordPress.' ); + } ?> -

- -

-
+

+

+

+

'; @@ -975,15 +1011,20 @@ if ( 'upgrade-core' === $action ) { $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; } - echo '

'; + echo '

'; + /* translators: Current version of WordPress. */ + printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) ); + echo '

'; + + echo '

'; /* translators: 1: Date, 2: Time. */ 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 ) ); echo ' ' . __( 'Check again.' ) . ''; echo '

'; if ( current_user_can( 'update_core' ) ) { - core_upgrade_preamble(); core_auto_updates_settings(); + core_upgrade_preamble(); } if ( current_user_can( 'update_plugins' ) ) { list_plugin_updates(); @@ -1158,6 +1199,23 @@ if ( 'upgrade-core' === $action ) { require_once ABSPATH . 'wp-admin/admin-footer.php'; +} elseif ( 'core-major-auto-updates-settings' === $action ) { + $redirect_url = self_admin_url( 'update-core.php' ); + + if ( isset( $_GET['value'] ) ) { + check_admin_referer( 'core-major-auto-updates-nonce' ); + + if ( 'enable' === $_GET['value'] ) { + update_site_option( 'auto_update_core_major', 'enabled' ); + $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url ); + } elseif ( 'disable' === $_GET['value'] ) { + update_site_option( 'auto_update_core_major', 'disabled' ); + $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url ); + } + } + + wp_redirect( $redirect_url ); + exit; } else { /** * Fires for each custom update action on the WordPress Updates screen.