* Update Core administration panel.
* @subpackage Administration
/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
wp_enqueue_style( 'plugin-install' );
wp_enqueue_script( 'plugin-install' );
wp_enqueue_script( 'updates' );
if ( is_multisite() && ! is_network_admin() ) {
wp_redirect( network_admin_url( 'update-core.php' ) );
if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) ) {
wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
* Lists available core updates.
* @global string $wp_local_package Locale code of the package.
* @global wpdb $wpdb WordPress database abstraction object.
function list_core_update( $update ) {
global $wp_local_package, $wpdb;
static $first_pass = true;
$wp_version = wp_get_wp_version();
$version_string = sprintf( '%s–%s', $update->current, get_locale() );
if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
$version_string = $update->current;
} elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version === $update->partial_version ) {
$updates = get_core_updates();
if ( $updates && 1 === count( $updates ) ) {
// If the only available update is a partial builds, it doesn't need a language-specific version string.
$version_string = $update->current;
} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() ) {
$version_string = sprintf( '%s–%s', $update->current, $update->locale );
if ( ! isset( $update->response ) || 'latest' === $update->response ) {
$form_action = 'update-core.php?action=do-core-upgrade';
$php_version = PHP_VERSION;
$mysql_version = $wpdb->db_version();
// 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] );
/* translators: %s: WordPress version. */
$submit = sprintf( __( 'Update to version %s' ), $version_string );
if ( 'development' === $update->response ) {
$message = __( 'You can update to the latest nightly build manually:' );
/* translators: %s: WordPress version. */
$submit = sprintf( __( 'Re-install version %s' ), $version_string );
$form_action = 'update-core.php?action=do-core-reinstall';
$php_compat = version_compare( $php_version, $update->php_version, '>=' );
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
$mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
/* translators: %s: WordPress version. */
esc_url( __( 'https://wordpress.org/documentation/wordpress-version/version-%s/' ) ),
sanitize_title( $update->current )
$php_update_message = '</p><p>' . sprintf(
/* translators: %s: URL to Update PHP page. */
__( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
$annotation = wp_get_update_php_annotation();
$php_update_message .= '</p><p><em>' . $annotation . '</em>';
if ( ! $mysql_compat && ! $php_compat ) {
/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
__( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ),
} elseif ( ! $php_compat ) {
/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
__( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
} elseif ( ! $mysql_compat ) {
/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
__( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
/* 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:' ),
if ( ! $mysql_compat || ! $php_compat ) {
echo '<form method="post" action="' . esc_url( $form_action ) . '" name="upgrade" class="upgrade">';
wp_nonce_field( 'upgrade-core' );
echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden" />';
echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden" />';
submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
submit_button( $submit, '', 'upgrade', false );
if ( 'en_US' !== $update->locale ) {
if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
submit_button( __( 'Hide this update' ), '', 'dismiss', false );
submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
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 ) ) {
// Partial builds don't need language-specific warnings.
echo '<p class="hint">' . sprintf(
/* translators: %s: WordPress version. */
__( 'You are about to install WordPress %s <strong>in English (US)</strong>. There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ),
'development' !== $update->response ? $update->current : ''
* Display dismissed updates.
function dismissed_updates() {
$dismissed = get_core_updates(
$show_text = esc_js( __( 'Show hidden updates' ) );
$hide_text = esc_js( __( 'Hide hidden updates' ) );
<script type="text/javascript">
$( '#show-dismissed' ).on( 'click', function() {
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
$( this ).text( '<?php echo $show_text; ?>' ).attr( 'aria-expanded', 'false' );
$( this ).text( '<?php echo $hide_text; ?>' ).attr( 'aria-expanded', 'true' );
$( '#dismissed-updates' ).toggle( 'fast' );
echo '<p class="hide-if-no-js"><button type="button" class="button" id="show-dismissed" aria-expanded="false">' . __( 'Show hidden updates' ) . '</button></p>';
echo '<ul id="dismissed-updates" class="core-updates dismissed">';
foreach ( (array) $dismissed as $update ) {
list_core_update( $update );
* Display upgrade WordPress for downloading latest or upgrading automatically form.
function core_upgrade_preamble() {
$updates = get_core_updates();
// 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 '<h2 class="response">';
_e( 'An updated version of WordPress is available.' );
/* 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.' ),
__( 'https://developer.wordpress.org/advanced-administration/security/backup/' ),
__( 'https://wordpress.org/documentation/article/updating-wordpress/' )
'additional_classes' => array( 'inline' ),
} elseif ( $is_development_version ) {
echo '<h2 class="response">' . __( 'You are using a development version of WordPress.' ) . '</h2>';
echo '<h2 class="response">' . __( 'You have the latest version of WordPress.' ) . '</h2>';
echo '<ul class="core-updates">';
foreach ( (array) $updates as $update ) {
list_core_update( $update );
// 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>';
} elseif ( ! $updates ) {
list( $normalized_version ) = explode( '-', $wp_version );
/* translators: 1: URL to About screen, 2: WordPress version. */
__( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ),
esc_url( self_admin_url( 'about.php' ) ),
* Display WordPress auto-updates settings.
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!' );
} elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
$notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$updater = new WP_Automatic_Updater();
$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.
} elseif ( true === WP_AUTO_UPDATE_CORE
|| in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
// Only minor updates for core.
// The UI is overridden by the `WP_AUTO_UPDATE_CORE` constant.
$can_set_update_option = false;
if ( $updater->is_disabled() ) {
* 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(
'minor' => $upgrade_minor,
'major' => $upgrade_major,
$wp_version = wp_get_wp_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">
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 ) {
'<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 ) {
'<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.' )
_e( 'This site will not receive automatic updates for new versions of WordPress.' );
* Fires after the major core auto-update settings.
* @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.
function list_plugin_updates() {
$wp_version = wp_get_wp_version();
$cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugins = get_plugin_updates();
if ( empty( $plugins ) ) {
echo '<h2>' . __( 'Plugins' ) . '</h2>';
echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
$form_action = 'update-core.php?action=do-plugin-upgrade';
$core_updates = get_core_updates();
if ( ! isset( $core_updates[0]->response ) || 'latest' === $core_updates[0]->response || 'development' === $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=' ) ) {
$core_update_version = false;
$core_update_version = $core_updates[0]->current;
$plugins_count = count( $plugins );
'%s <span class="count">(%d)</span>',
number_format_i18n( $plugins_count )
<p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click “Update Plugins”.' ); ?></p>
<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
<?php wp_nonce_field( 'upgrade-core' ); ?>
<p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
<table class="widefat updates-table" id="update-plugins-table">
<td class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>