'Version' => $theme->get( 'Version' ),
'Author' => $theme->get( 'Author' ),
'Author URI' => $theme->get( 'AuthorURI' ),
'Template' => $theme->get_template(),
'Stylesheet' => $theme->get_stylesheet(),
$doing_cron = wp_doing_cron();
// Check for update on a different schedule, depending on the page.
switch ( current_filter() ) {
case 'upgrader_process_complete':
case 'load-update-core.php':
$timeout = MINUTE_IN_SECONDS;
$timeout = HOUR_IN_SECONDS;
$timeout = 2 * HOUR_IN_SECONDS;
$timeout = 12 * HOUR_IN_SECONDS;
$time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
if ( $time_not_changed && ! $extra_stats ) {
foreach ( $checked as $slug => $v ) {
if ( ! isset( $last_update->checked[ $slug ] ) || (string) $last_update->checked[ $slug ] !== (string) $v ) {
if ( isset( $last_update->response ) && is_array( $last_update->response ) ) {
foreach ( $last_update->response as $slug => $update_details ) {
if ( ! isset( $checked[ $slug ] ) ) {
// Bail if we've checked recently and if nothing has changed.
if ( ! $theme_changed ) {
// Update last_checked for current to prevent multiple blocking requests if request hangs.
$last_update->last_checked = time();
set_site_transient( 'update_themes', $last_update );
$request['themes'] = $themes;
$locales = array_values( get_available_languages() );
* Filters the locales requested for theme translations.
* @since 4.5.0 The default value of the `$locales` parameter changed to include all locales.
* @param array $locales Theme locales. Default is all available locales of the site.
$locales = apply_filters( 'themes_update_check_locales', $locales );
$locales = array_unique( $locales );
// Three seconds, plus one extra second for every 10 themes.
$timeout = 3 + (int) ( count( $themes ) / 10 );
'themes' => wp_json_encode( $request ),
'translations' => wp_json_encode( $translations ),
'locale' => wp_json_encode( $locales ),
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
$options['body']['update_stats'] = wp_json_encode( $extra_stats );
$url = 'http://api.wordpress.org/themes/update-check/1.1/';
$ssl = wp_http_supports( array( 'ssl' ) );
$url = set_url_scheme( $url, 'https' );
$raw_response = wp_remote_post( $url, $options );
if ( $ssl && is_wp_error( $raw_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
$raw_response = wp_remote_post( $http_url, $options );
if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) {
$new_update = new stdClass;
$new_update->last_checked = time();
$new_update->checked = $checked;
$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
if ( is_array( $response ) ) {
$new_update->response = $response['themes'];
$new_update->no_update = $response['no_update'];
$new_update->translations = $response['translations'];
set_site_transient( 'update_themes', $new_update );
* Performs WordPress automatic background updates.
* Updates WordPress core plus any plugins and themes that have automatic updates enabled.
function wp_maybe_auto_update() {
include_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater;
* Retrieves a list of all language updates available.
* @return object[] Array of translation objects that have available updates.
function wp_get_translation_updates() {
'update_plugins' => 'plugin',
'update_themes' => 'theme',
foreach ( $transients as $transient => $type ) {
$transient = get_site_transient( $transient );
if ( empty( $transient->translations ) ) {
foreach ( $transient->translations as $translation ) {
$updates[] = (object) $translation;
* Collect counts and UI strings for available updates
function wp_get_update_data() {
$plugins = current_user_can( 'update_plugins' );
$update_plugins = get_site_transient( 'update_plugins' );
if ( ! empty( $update_plugins->response ) ) {
$counts['plugins'] = count( $update_plugins->response );
$themes = current_user_can( 'update_themes' );
$update_themes = get_site_transient( 'update_themes' );
if ( ! empty( $update_themes->response ) ) {
$counts['themes'] = count( $update_themes->response );
$core = current_user_can( 'update_core' );
if ( $core && function_exists( 'get_core_updates' ) ) {
$update_wordpress = get_core_updates( array( 'dismissed' => false ) );
if ( ! empty( $update_wordpress )
&& ! in_array( $update_wordpress[0]->response, array( 'development', 'latest' ), true )
&& current_user_can( 'update_core' )
$counts['wordpress'] = 1;
if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) {
$counts['translations'] = 1;
$counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations'];
if ( $counts['wordpress'] ) {
/* translators: %d: Number of available WordPress updates. */
$titles['wordpress'] = sprintf( __( '%d WordPress Update' ), $counts['wordpress'] );
if ( $counts['plugins'] ) {
/* translators: %d: Number of available plugin updates. */
$titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] );
if ( $counts['themes'] ) {
/* translators: %d: Number of available theme updates. */
$titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] );
if ( $counts['translations'] ) {
$titles['translations'] = __( 'Translation Updates' );
$update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : '';
'title' => $update_title,
* Filters the returned array of update data for plugins, themes, and WordPress core.
* @param array $update_data {
* @type array $counts An array of counts for available plugin, theme, and WordPress updates.
* @type string $update_title Titles of available updates.
* @param array $titles An array of update counts and UI strings for available updates.
return apply_filters( 'wp_get_update_data', $update_data, $titles );
* Determines whether core should be updated.
* @global string $wp_version The WordPress version string.
function _maybe_update_core() {
// Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php';
$current = get_site_transient( 'update_core' );
if ( isset( $current->last_checked, $current->version_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
&& $current->version_checked === $wp_version
* Check the last time plugins were run before checking plugin versions.
* This might have been backported to WordPress 2.6.1 for performance reasons.
* This is used for the wp-admin to check only so often instead of every page
function _maybe_update_plugins() {
$current = get_site_transient( 'update_plugins' );
if ( isset( $current->last_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
* Check themes versions only after a duration of time.
* This is for performance reasons to make sure that on the theme version
* checker is not run on every page load.
function _maybe_update_themes() {
$current = get_site_transient( 'update_themes' );
if ( isset( $current->last_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
* Schedule core, theme, and plugin update checks.
function wp_schedule_update_checks() {
if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_version_check' );
if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' );
if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' );
* Clear existing update caches for plugins, themes, and core.
function wp_clean_update_cache() {
if ( function_exists( 'wp_clean_plugins_cache' ) ) {
wp_clean_plugins_cache();
delete_site_transient( 'update_plugins' );
delete_site_transient( 'update_core' );
if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
add_action( 'admin_init', '_maybe_update_core' );
add_action( 'wp_version_check', 'wp_version_check' );
add_action( 'load-plugins.php', 'wp_update_plugins' );
add_action( 'load-update.php', 'wp_update_plugins' );
add_action( 'load-update-core.php', 'wp_update_plugins' );
add_action( 'admin_init', '_maybe_update_plugins' );
add_action( 'wp_update_plugins', 'wp_update_plugins' );
add_action( 'load-themes.php', 'wp_update_themes' );
add_action( 'load-update.php', 'wp_update_themes' );
add_action( 'load-update-core.php', 'wp_update_themes' );
add_action( 'admin_init', '_maybe_update_themes' );
add_action( 'wp_update_themes', 'wp_update_themes' );
add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 );
add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
add_action( 'init', 'wp_schedule_update_checks' );