wp/wp-admin/update-core.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
--- a/wp/wp-admin/update-core.php	Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-admin/update-core.php	Wed Sep 21 18:19:35 2022 +0200
@@ -38,7 +38,7 @@
 	static $first_pass = true;
 
 	$wp_version     = get_bloginfo( 'version' );
-	$version_string = sprintf( '%s&ndash;<strong>%s</strong>', $update->current, $update->locale );
+	$version_string = sprintf( '%s&ndash;%s', $update->current, get_locale() );
 
 	if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
 		$version_string = $update->current;
@@ -54,18 +54,30 @@
 	if ( ! isset( $update->response ) || 'latest' === $update->response ) {
 		$current = true;
 	}
-	$submit        = __( 'Update Now' );
+
+	$message       = '';
 	$form_action   = 'update-core.php?action=do-core-upgrade';
 	$php_version   = phpversion();
 	$mysql_version = $wpdb->db_version();
 	$show_buttons  = true;
+
+	// Nightly build versions have two hyphens and a commit number.
+	if ( preg_match( '/-\w+-\d+/', $update->current ) ) {
+		// Retrieve the major version number.
+		preg_match( '/^\d+.\d+/', $update->current, $update_major );
+		/* translators: %s: WordPress version. */
+		$submit = sprintf( __( 'Update to latest %s nightly' ), $update_major[0] );
+	} else {
+		/* translators: %s: WordPress version. */
+		$submit = sprintf( __( 'Update to version %s' ), $version_string );
+	}
+
 	if ( 'development' === $update->response ) {
-		$message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' );
+		$message = __( 'You can update to the latest nightly build manually:' );
 	} else {
 		if ( $current ) {
 			/* translators: %s: WordPress version. */
-			$message     = sprintf( __( 'If you need to re-install version %s, you can do so here:' ), $version_string );
-			$submit      = __( 'Re-install Now' );
+			$submit      = sprintf( __( 'Re-install version %s' ), $version_string );
 			$form_action = 'update-core.php?action=do-core-reinstall';
 		} else {
 			$php_compat = version_compare( $php_version, $update->php_version, '>=' );
@@ -124,12 +136,14 @@
 				);
 			} else {
 				$message = sprintf(
-					/* translators: 1: URL to WordPress release notes, 2: WordPress version number including locale if necessary. */
-					__( 'You can update to <a href="%1$s">WordPress %2$s</a> automatically:' ),
+					/* 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> manually:' ),
+					$wp_version,
 					$version_url,
 					$version_string
 				);
 			}
+
 			if ( ! $mysql_compat || ! $php_compat ) {
 				$show_buttons = false;
 			}
@@ -139,11 +153,13 @@
 	echo '<p>';
 	echo $message;
 	echo '</p>';
+
 	echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
 	wp_nonce_field( 'upgrade-core' );
+
 	echo '<p>';
-	echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden"/>';
-	echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden"/>';
+	echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden" />';
+	echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden" />';
 	if ( $show_buttons ) {
 		if ( $first_pass ) {
 			submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
@@ -160,6 +176,7 @@
 		}
 	}
 	echo '</p>';
+
 	if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
 		echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
 	} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
@@ -170,6 +187,7 @@
 			'development' !== $update->response ? $update->current : ''
 		) . '</p>';
 	}
+
 	echo '</form>';
 
 }
@@ -221,32 +239,19 @@
 function core_upgrade_preamble() {
 	global $required_php_version, $required_mysql_version;
 
-	$wp_version = get_bloginfo( 'version' );
-	$updates    = get_core_updates();
-
-	if ( ! isset( $updates[0]->response ) || 'latest' === $updates[0]->response ) {
-		echo '<h2>';
-		_e( 'You have the latest version of WordPress.' );
+	$updates = get_core_updates();
 
-		if ( wp_http_supports( array( 'ssl' ) ) ) {
-			require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-			$upgrader            = new WP_Automatic_Updater;
-			$future_minor_update = (object) array(
-				'current'       => $wp_version . '.1.next.minor',
-				'version'       => $wp_version . '.1.next.minor',
-				'php_version'   => $required_php_version,
-				'mysql_version' => $required_mysql_version,
-			);
-			$should_auto_update  = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
-			if ( $should_auto_update ) {
-				echo ' ' . __( 'Future security updates will be applied automatically.' );
-			}
-		}
-		echo '</h2>';
-	}
+	// Include an unmodified $wp_version.
+	require ABSPATH . WPINC . '/version.php';
+
+	$is_development_version = preg_match( '/alpha|beta|RC/', $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(
 			/* 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.' ),
@@ -254,20 +259,10 @@
 			__( 'https://wordpress.org/support/article/updating-wordpress/' )
 		);
 		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 ) {
-		require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-		$upgrader = new WP_Automatic_Updater;
-		if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) {
-			echo '<div class="updated inline"><p>';
-			echo '<strong>' . __( 'BETA TESTERS:' ) . '</strong> ' . __( 'This site is set up to install updates of future beta versions automatically.' );
-			echo '</p></div>';
-		}
+	} elseif ( $is_development_version ) {
+		echo '<h2 class="response">' . __( 'You are using a development version of WordPress.' ) . '</h2>';
+	} else {
+		echo '<h2 class="response">' . __( 'You have the latest version of WordPress.' ) . '</h2>';
 	}
 
 	echo '<ul class="core-updates">';
@@ -277,6 +272,7 @@
 		echo '</li>';
 	}
 	echo '</ul>';
+
 	// Don't show the maintenance mode notice when we are only showing a single re-install option.
 	if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) {
 		echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, this mode will be deactivated.' ) . '</p>';
@@ -289,10 +285,155 @@
 			$normalized_version
 		) . '</p>';
 	}
+
 	dismissed_updates();
 }
 
 /**
+ * Display WordPress auto-updates settings.
+ *
+ * @since 5.6.0
+ */
+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 );
+}
+
+/**
  * Display the upgrade plugins form.
  *
  * @since 2.9.0
@@ -316,8 +457,18 @@
 	} else {
 		$core_update_version = $core_updates[0]->current;
 	}
+
+	$plugins_count = count( $plugins );
 	?>
-<h2><?php _e( 'Plugins' ); ?></h2>
+<h2>
+	<?php
+	printf(
+		'%s <span class="count">(%d)</span>',
+		__( 'Plugins' ),
+		number_format_i18n( $plugins_count )
+	);
+	?>
+</h2>
 <p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click &#8220;Update Plugins&#8221;.' ); ?></p>
 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
 	<?php wp_nonce_field( 'upgrade-core' ); ?>
@@ -405,7 +556,7 @@
 			sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
 		);
 
-		$checkbox_id = 'checkbox_' . md5( $plugin_data->Name );
+		$checkbox_id = 'checkbox_' . md5( $plugin_file );
 		?>
 	<tr>
 		<td class="check-column">
@@ -469,8 +620,18 @@
 	}
 
 	$form_action = 'update-core.php?action=do-theme-upgrade';
+
+	$themes_count = count( $themes );
 	?>
-<h2><?php _e( 'Themes' ); ?></h2>
+<h2>
+	<?php
+	printf(
+		'%s <span class="count">(%d)</span>',
+		__( 'Themes' ),
+		number_format_i18n( $themes_count )
+	);
+	?>
+</h2>
 <p><?php _e( 'The following themes have new versions available. Check the ones you want to update and then click &#8220;Update Themes&#8221;.' ); ?></p>
 <p>
 	<?php
@@ -808,7 +969,7 @@
 	)
 );
 
-$updates_howto  = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the &#8220;Update Now&#8221; button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
+$updates_howto  = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the &#8220;Update now&#8221; button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
 $updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate &#8220;Update&#8221; button</strong>. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '</p>';
 
 if ( 'en_US' !== get_locale() ) {
@@ -826,7 +987,7 @@
 $help_sidebar_autoupdates = '';
 
 if ( ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) || ( current_user_can( 'update_plugins' ) && wp_is_auto_update_enabled_for_type( 'plugin' ) ) ) {
-	$help_tab_autoupdates  = '<p>' . __( 'Auto-updates can be enabled or disabled for each individual theme or plugin. Themes or plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>';
+	$help_tab_autoupdates  = '<p>' . __( 'Auto-updates can be enabled or disabled for WordPress major versions and for each individual theme or plugin. Themes or plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>';
 	$help_tab_autoupdates .= '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>';
 
 	get_current_screen()->add_help_tab(
@@ -856,6 +1017,8 @@
 	?>
 	<div class="wrap">
 	<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
 	if ( $upgrade_error ) {
 		echo '<div class="error"><p>';
@@ -874,13 +1037,19 @@
 		$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. */
 	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 ' &nbsp; <a class="button" 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>';
 
 	if ( current_user_can( 'update_core' ) ) {
+		core_auto_updates_settings();
 		core_upgrade_preamble();
 	}
 	if ( current_user_can( 'update_plugins' ) ) {
@@ -970,10 +1139,12 @@
 	$title = __( 'Update Plugins' );
 
 	require_once ABSPATH . 'wp-admin/admin-header.php';
-	echo '<div class="wrap">';
-	echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
-	echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
-	echo '</div>';
+	?>
+	<div class="wrap">
+		<h1><?php _e( 'Update Plugins' ); ?></h1>
+		<iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
+	</div>
+	<?php
 
 	wp_localize_script(
 		'updates',
@@ -1054,6 +1225,28 @@
 
 	require_once ABSPATH . 'wp-admin/admin-footer.php';
 
+} elseif ( 'core-major-auto-updates-settings' === $action ) {
+
+	if ( ! current_user_can( 'update_core' ) ) {
+		wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
+	}
+
+	$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.