Upgrade/Install: Add UI for opting in to core auto-updates for major versions.

Props audrasjb, karmatosed, aaroncampbell, paaljoachim, davidbaumwald.
Fixes #50907.

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


git-svn-id: http://core.svn.wordpress.org/trunk@49016 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2020-10-20 19:35:06 +00:00
parent 874b812ce3
commit 9ab2f1ae3e
7 changed files with 101 additions and 15 deletions

View File

@ -345,7 +345,7 @@ h3 {
}
.update-core-php h2 {
margin-top: 2em;
margin-top: 4em;
}
.update-php h2,

File diff suppressed because one or more lines are too long

View File

@ -344,7 +344,7 @@ h3 {
}
.update-core-php h2 {
margin-top: 2em;
margin-top: 4em;
}
.update-php h2,

File diff suppressed because one or more lines are too long

View File

@ -48,14 +48,14 @@ class Core_Upgrader extends WP_Upgrader {
*
* @param object $current Response object for whether WordPress is current.
* @param array $args {
* Optional. Arguments for upgrading WordPress core. Default empty array.
* Optional. Arguments for upgrading WordPress core. Default empty array.
*
* @type bool $pre_check_md5 Whether to check the file checksums before
* attempting the upgrade. Default true.
* @type bool $attempt_rollback Whether to attempt to rollback the chances if
* there is a problem. Default false.
* @type bool $do_rollback Whether to perform this "upgrade" as a rollback.
* Default false.
* @type bool $pre_check_md5 Whether to check the file checksums before
* attempting the upgrade. Default true.
* @type bool $attempt_rollback Whether to attempt to rollback the chances if
* there is a problem. Default false.
* @type bool $do_rollback Whether to perform this "upgrade" as a rollback.
* Default false.
* }
* @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure.
*/
@ -279,9 +279,9 @@ class Core_Upgrader extends WP_Upgrader {
$current_is_development_version = (bool) strpos( $wp_version, '-' );
// Defaults:
$upgrade_dev = true;
$upgrade_minor = true;
$upgrade_major = false;
$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 );
// WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false.
if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {

View File

@ -300,6 +300,91 @@ function core_upgrade_preamble() {
dismissed_updates();
}
/**
* Display WordPress auto-updates settings.
*
* @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 );
}
echo '<div class="notice notice-info is-dismissible"><p>';
_e( 'WordPress auto-updates settings updated.' );
echo '</p></div>';
}
$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 );
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 ) {
// 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;
}
}
$upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev );
$upgrade_minor = apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
$upgrade_major = apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
$auto_update_settings = array(
'dev' => $upgrade_dev,
'minor' => $upgrade_minor,
'major' => $upgrade_major,
);
?>
<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' ); ?>
<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( 'Keep my site up-to-date with regular feature updates (major versions).' ); ?>
</label>
</p>
<?php
/**
* Fires after the major core auto-update checkbox.
*
* @since 5.6.0
*/
do_action( 'after_core_auto_updates_settings_fields', $auto_update_settings );
?>
<p>
<input id="core-auto-updates-settings" class="button" type="submit" value="<?php esc_attr_e( 'Save' ); ?>" name="core-auto-updates-settings" />
</p>
<?php
}
/**
* Display the upgrade plugins form.
*
@ -890,6 +975,7 @@ if ( 'upgrade-core' === $action ) {
if ( current_user_can( 'update_core' ) ) {
core_upgrade_preamble();
core_auto_updates_settings();
}
if ( current_user_can( 'update_plugins' ) ) {
list_plugin_updates();

View File

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