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.

Built from https://develop.svn.wordpress.org/trunk@49587


git-svn-id: http://core.svn.wordpress.org/trunk@49325 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2020-11-12 22:37:10 +00:00
parent c5257328b7
commit 582ca50733
7 changed files with 141 additions and 57 deletions

View File

@ -1601,6 +1601,19 @@ form.upgrade .hint {
margin: -4px 0; 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-loading, .ajax-loading,
.ajax-feedback, .ajax-feedback,

File diff suppressed because one or more lines are too long

View File

@ -1600,6 +1600,19 @@ form.upgrade .hint {
margin: -4px 0; 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-loading, .ajax-loading,
.ajax-feedback, .ajax-feedback,

File diff suppressed because one or more lines are too long

View File

@ -279,9 +279,9 @@ class Core_Upgrader extends WP_Upgrader {
$current_is_development_version = (bool) strpos( $wp_version, '-' ); $current_is_development_version = (bool) strpos( $wp_version, '-' );
// Defaults: // Defaults:
$upgrade_dev = get_site_option( 'auto_update_core_dev', true ); $upgrade_dev = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
$upgrade_minor = get_site_option( 'auto_update_core_minor', true ); $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
$upgrade_major = get_site_option( 'auto_update_core_major', false ); $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
// WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false. // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false.
if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {

View File

@ -62,7 +62,7 @@ function list_core_update( $update ) {
$show_buttons = true; $show_buttons = true;
if ( 'development' === $update->response ) { 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 { } else {
if ( $current ) { if ( $current ) {
/* translators: %s: WordPress version. */ /* translators: %s: WordPress version. */
@ -127,7 +127,7 @@ function list_core_update( $update ) {
} else { } else {
$message = sprintf( $message = sprintf(
/* translators: 1: Installed WordPress version number, 2: URL to WordPress release notes, 3: New WordPress version number, including locale if necessary. */ /* 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 <a href="%2$s">WordPress %3$s</a> automatically:' ), __( 'You can update from WordPress %1$s to <a href="%2$s">WordPress %3$s</a> manually:' ),
$wp_version, $wp_version,
$version_url, $version_url,
$version_string $version_string
@ -254,7 +254,11 @@ function core_upgrade_preamble() {
} }
if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) { if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
echo '<div class="notice notice-warning"><p>'; echo '<h2 class="response">';
_e( 'An updated version of WordPress is available.' );
echo '</h2>';
echo '<div class="notice notice-warning inline"><p>';
printf( printf(
/* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */ /* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */
__( '<strong>Important:</strong> Before updating, please <a href="%1$s">back up your database and files</a>. For help with updates, visit the <a href="%2$s">Updating WordPress</a> documentation page.' ), __( '<strong>Important:</strong> Before updating, please <a href="%1$s">back up your database and files</a>. For help with updates, visit the <a href="%2$s">Updating WordPress</a> documentation page.' ),
@ -262,10 +266,6 @@ function core_upgrade_preamble() {
__( 'https://wordpress.org/support/article/updating-wordpress/' ) __( 'https://wordpress.org/support/article/updating-wordpress/' )
); );
echo '</p></div>'; echo '</p></div>';
echo '<h2 class="response">';
_e( 'An updated version of WordPress is available.' );
echo '</h2>';
} }
if ( isset( $updates[0] ) && 'development' === $updates[0]->response ) { if ( isset( $updates[0] ) && 'development' === $updates[0]->response ) {
@ -306,22 +306,22 @@ function core_upgrade_preamble() {
* @since 5.6.0 * @since 5.6.0
*/ */
function core_auto_updates_settings() { function core_auto_updates_settings() {
$upgrade_major_value = ''; if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
if ( isset( $_POST['core-auto-updates-settings'] ) && wp_verify_nonce( $_POST['set_core_auto_updates_settings'], 'core-auto-updates-nonce' ) ) { if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
if ( isset( $_POST['core-auto-updates-major'] ) && 1 === (int) $_POST['core-auto-updates-major'] ) { $notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
update_site_option( 'auto_update_core_major', 1 ); echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
} else { } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
update_site_option( 'auto_update_core_major', 0 ); $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>';
} }
echo '<div class="notice notice-success is-dismissible"><p>';
_e( 'WordPress auto-update settings updated.' );
echo '</p></div>';
} }
$upgrade_dev = get_site_option( 'auto_update_core_dev', true ); // Defaults:
$upgrade_minor = get_site_option( 'auto_update_core_minor', true ); $upgrade_dev = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
$upgrade_major = get_site_option( 'auto_update_core_major', false ); $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. // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false.
if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
if ( false === WP_AUTO_UPDATE_CORE ) { if ( false === WP_AUTO_UPDATE_CORE ) {
@ -343,6 +343,24 @@ function core_auto_updates_settings() {
$upgrade_minor = true; $upgrade_minor = true;
$upgrade_major = false; $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 */ /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
@ -357,40 +375,56 @@ function core_auto_updates_settings() {
'minor' => $upgrade_minor, 'minor' => $upgrade_minor,
'major' => $upgrade_major, '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' );
?> ?>
<form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" name="core-auto-updates" class="form-core-auto-updates">
<?php wp_nonce_field( 'core-auto-updates-nonce', 'set_core_auto_updates_settings' ); ?> <p class="auto-update-status">
<h2><?php _e( 'Auto-update settings' ); ?></h2>
<p>
<?php
if ( $auto_update_settings['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();
}
}
?>
</p>
<p>
<input type="checkbox" name="core-auto-updates-major" id="core-auto-updates-major" value="1" <?php checked( $auto_update_settings['major'], 1 ); ?> />
<label for="core-auto-updates-major">
<?php _e( 'Automatically keep this site up-to-date with regular feature updates.' ); ?>
</label>
</p>
<?php <?php
/** if ( $upgrade_major ) {
* Fires after the major core auto-update checkbox. _e( 'This site is automatically kept up to date with each new version of WordPress.' );
*
* @since 5.6.0 if ( $can_set_update_option ) {
*/ echo '<br>';
do_action( 'after_core_auto_updates_settings_fields', $auto_update_settings ); echo sprintf(
/* Translators: Action link to disable core auto-updates. */
__( '<a href="%s">Switch to automatic updates for maintenance and security releases only.</a>' ),
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 '<br>';
echo sprintf(
/* Translators: Action link to enable core auto-updates. */
__( '<a href="%s">Enable automatic updates for all new versions of WordPress.</a>' ),
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.' );
}
?> ?>
<p> </p>
<input id="core-auto-updates-settings" class="button" type="submit" value="<?php esc_attr_e( 'Save' ); ?>" name="core-auto-updates-settings" />
</p>
</form>
<?php <?php
/**
* Fires after the major core auto-update settings.
*
* @since 5.6.0
*/
do_action( 'after_core_auto_updates_settings', $auto_update_settings );
} }
/** /**
@ -957,6 +991,8 @@ if ( 'upgrade-core' === $action ) {
?> ?>
<div class="wrap"> <div class="wrap">
<h1><?php _e( 'WordPress Updates' ); ?></h1> <h1><?php _e( 'WordPress Updates' ); ?></h1>
<p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>
<?php <?php
if ( $upgrade_error ) { if ( $upgrade_error ) {
echo '<div class="error"><p>'; echo '<div class="error"><p>';
@ -975,15 +1011,20 @@ if ( 'upgrade-core' === $action ) {
$last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
} }
echo '<p>'; echo '<h2 class="wp-current-version">';
/* translators: Current version of WordPress. */
printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
echo '</h2>';
echo '<p class="update-last-checked">';
/* translators: 1: Date, 2: Time. */ /* 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 ) ); 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 ' <a href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check again.' ) . '</a>'; echo ' <a href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check again.' ) . '</a>';
echo '</p>'; echo '</p>';
if ( current_user_can( 'update_core' ) ) { if ( current_user_can( 'update_core' ) ) {
core_upgrade_preamble();
core_auto_updates_settings(); core_auto_updates_settings();
core_upgrade_preamble();
} }
if ( current_user_can( 'update_plugins' ) ) { if ( current_user_can( 'update_plugins' ) ) {
list_plugin_updates(); list_plugin_updates();
@ -1158,6 +1199,23 @@ if ( 'upgrade-core' === $action ) {
require_once ABSPATH . 'wp-admin/admin-footer.php'; 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 { } else {
/** /**
* Fires for each custom update action on the WordPress Updates screen. * Fires for each custom update action on the WordPress Updates screen.

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6-beta3-49586'; $wp_version = '5.6-beta3-49587';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.