* WordPress Administration Update API
* @subpackage Administration
* Selects the first update version from the update_core option.
* @return object|array|false The response from the API on success, false on failure.
function get_preferred_from_update_core() {
$updates = get_core_updates();
if ( ! is_array( $updates ) ) {
if ( empty( $updates ) ) {
return (object) array( 'response' => 'latest' );
* Gets available core updates.
* @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
* set $options['available'] to false to skip not-dismissed updates.
* @return array|false Array of the update objects on success, false on failure.
function get_core_updates( $options = array() ) {
$dismissed = get_site_option( 'dismissed_update_core' );
if ( ! is_array( $dismissed ) ) {
$from_api = get_site_transient( 'update_core' );
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
$updates = $from_api->updates;
foreach ( $updates as $update ) {
if ( 'autoupdate' === $update->response ) {
if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
if ( $options['dismissed'] ) {
$update->dismissed = true;
if ( $options['available'] ) {
$update->dismissed = false;
* Gets the best available (and enabled) Auto-Update for WordPress core.
* If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the installation allows it, else, 1.2.3.
* @return object|false The core update offering on success, false on failure.
function find_core_auto_update() {
$updates = get_site_transient( 'update_core' );
if ( ! $updates || empty( $updates->updates ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater;
foreach ( $updates->updates as $update ) {
if ( 'autoupdate' !== $update->response ) {
if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
* Gets and caches the checksums for the given version of WordPress.
* @param string $version Version string to query.
* @param string $locale Locale to query.
* @return array|false An array of checksums on success, false on failure.
function get_core_checksums( $version, $locale ) {
$http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
$ssl = wp_http_supports( array( 'ssl' ) );
$url = set_url_scheme( $url, 'https' );
'timeout' => wp_doing_cron() ? 30 : 3,
$response = wp_remote_get( $url, $options );
if ( $ssl && is_wp_error( $response ) ) {
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/forums/' )
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
$response = wp_remote_get( $http_url, $options );
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
$body = trim( wp_remote_retrieve_body( $response ) );
$body = json_decode( $body, true );
if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
return $body['checksums'];
function dismiss_core_update( $update ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$dismissed[ $update->current . '|' . $update->locale ] = true;
return update_site_option( 'dismissed_update_core', $dismissed );
* Undismisses core update.
function undismiss_core_update( $version, $locale ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$key = $version . '|' . $locale;
if ( ! isset( $dismissed[ $key ] ) ) {
unset( $dismissed[ $key ] );
return update_site_option( 'dismissed_update_core', $dismissed );
* Finds the available update for WordPress core.
* @param string $version Version string to find the update for.
* @param string $locale Locale to find the update for.
* @return object|false The core update offering on success, false on failure.
function find_core_update( $version, $locale ) {
$from_api = get_site_transient( 'update_core' );
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
$updates = $from_api->updates;
foreach ( $updates as $update ) {
if ( $update->current == $version && $update->locale == $locale ) {
function core_update_footer( $msg = '' ) {
if ( ! current_user_can( 'update_core' ) ) {
/* translators: %s: WordPress version. */
return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
$cur = get_preferred_from_update_core();
if ( ! is_object( $cur ) ) {
if ( ! isset( $cur->current ) ) {
if ( ! isset( $cur->response ) ) {
// Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php';
$is_development_version = preg_match( '/alpha|beta|RC/', $wp_version );
if ( $is_development_version ) {
/* translators: 1: WordPress version number, 2: URL to WordPress Updates screen. */
__( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ),
get_bloginfo( 'version', 'display' ),
network_admin_url( 'update-core.php' )
switch ( $cur->response ) {
'<strong><a href="%s">%s</a></strong>',
network_admin_url( 'update-core.php' ),
/* translators: %s: WordPress version. */
sprintf( __( 'Get Version %s' ), $cur->current )
/* translators: %s: WordPress version. */
return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
* @global string $pagenow
if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
if ( 'update-core.php' === $pagenow ) {
$cur = get_preferred_from_update_core();
if ( ! isset( $cur->response ) || 'upgrade' !== $cur->response ) {
/* translators: %s: WordPress version. */
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
sanitize_title( $cur->current )
if ( current_user_can( 'update_core' ) ) {
/* translators: 1: URL to WordPress release notes, 2: New WordPress version, 3: URL to network admin, 4: Accessibility text. */
__( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
network_admin_url( 'update-core.php' ),
esc_attr__( 'Please update WordPress now' )
/* translators: 1: URL to WordPress release notes, 2: New WordPress version. */
__( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
echo "<div class='update-nag notice notice-warning inline'>$msg</div>";
* Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
function update_right_now_message() {
$theme_name = wp_get_theme();
if ( current_user_can( 'switch_themes' ) ) {
$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
if ( current_user_can( 'update_core' ) ) {
$cur = get_preferred_from_update_core();
if ( isset( $cur->response ) && 'upgrade' === $cur->response ) {
'<a href="%s" class="button" aria-describedby="wp-version">%s</a> ',
network_admin_url( 'update-core.php' ),
/* translators: %s: WordPress version number, or 'Latest' string. */
sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) )
/* translators: 1: Version number, 2: Theme name. */
$content = __( 'WordPress %1$s running %2$s theme.' );
* Filters the text displayed in the 'At a Glance' dashboard widget.
* Prior to 3.8.0, the widget was named 'Right Now'.
* @param string $content Default text.
$content = apply_filters( 'update_right_now_text', $content );
$msg .= sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
echo "<p id='wp-version-message'>$msg</p>";
function get_plugin_updates() {
$all_plugins = get_plugins();
$upgrade_plugins = array();
$current = get_site_transient( 'update_plugins' );
foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) {
$upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
function wp_plugin_update_rows() {
if ( ! current_user_can( 'update_plugins' ) ) {
$plugins = get_site_transient( 'update_plugins' );
if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
$plugins = array_keys( $plugins->response );
foreach ( $plugins as $plugin_file ) {
add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
* Displays update information for a plugin.
* @param string $file Plugin basename.
* @param array $plugin_data Plugin information.
function wp_plugin_update_row( $file, $plugin_data ) {
$current = get_site_transient( 'update_plugins' );
if ( ! isset( $current->response[ $file ] ) ) {
$response = $current->response[ $file ];
$plugins_allowedtags = array(
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
$plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '§ion=changelog&TB_iframe=true&width=600&height=800' );
/** @var WP_Plugins_List_Table $wp_list_table */
$wp_list_table = _get_list_table(
'screen' => get_current_screen(),
if ( is_network_admin() || ! is_multisite() ) {
if ( is_network_admin() ) {
$active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
$active_class = is_plugin_active( $file ) ? ' active' : '';
$requires_php = isset( $response->requires_php ) ? $response->requires_php : null;
$compatible_php = is_php_version_compatible( $requires_php );
$notice_type = $compatible_php ? 'notice-warning' : 'notice-error';
'<tr class="plugin-update-tr%s" id="%s" data-slug="%s" data-plugin="%s">' .
'<td colspan="%s" class="plugin-update colspanchange">' .
'<div class="update-message notice inline %s notice-alt"><p>',
esc_attr( $response->slug . '-update' ),
esc_attr( $response->slug ),
esc_attr( $wp_list_table->get_column_count() ),
if ( ! current_user_can( 'update_plugins' ) ) {
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: Plugin name, 2: Version number. */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
esc_attr( $response->new_version )
} elseif ( empty( $response->package ) ) {
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
'class="thickbox open-plugin-details-modal" aria-label="%s"',
/* translators: 1: Plugin name, 2: Version number. */
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
esc_attr( $response->new_version )
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */