diff --git a/wp-includes/update.php b/wp-includes/update.php index 600091faa3..a26e15943a 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -22,11 +22,12 @@ * @param bool $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set. */ function wp_version_check( $extra_stats = array(), $force_check = false ) { + global $wpdb, $wp_local_package; + if ( wp_installing() ) { return; } - global $wpdb, $wp_local_package; // Include an unmodified $wp_version. require ABSPATH . WPINC . '/version.php'; $php_version = phpversion(); @@ -35,7 +36,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { $translations = wp_get_installed_translations( 'core' ); // Invalidate the transient when $wp_version changes. - if ( is_object( $current ) && $wp_version != $current->version_checked ) { + if ( is_object( $current ) && $wp_version !== $current->version_checked ) { $current = false; } @@ -52,6 +53,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { // Wait 1 minute between multiple version check requests. $timeout = MINUTE_IN_SECONDS; $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); + if ( ! $force_check && $time_not_changed ) { return; } @@ -135,6 +137,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { $url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' ); $http_url = $url; $ssl = wp_http_supports( array( 'ssl' ) ); + if ( $ssl ) { $url = set_url_scheme( $url, 'https' ); } @@ -152,6 +155,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { ); $response = wp_remote_post( $url, $options ); + if ( $ssl && is_wp_error( $response ) ) { trigger_error( sprintf( @@ -164,7 +168,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { $response = wp_remote_post( $http_url, $options ); } - if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return; } @@ -179,12 +183,12 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { foreach ( $offers as &$offer ) { foreach ( $offer as $offer_key => $value ) { - if ( 'packages' == $offer_key ) { + if ( 'packages' === $offer_key ) { $offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ), array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) ); - } elseif ( 'download' == $offer_key ) { + } elseif ( 'download' === $offer_key ) { $offer['download'] = esc_url( $value ); } else { $offer[ $offer_key ] = esc_html( $value ); @@ -226,6 +230,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { if ( ! empty( $body['ttl'] ) ) { $ttl = (int) $body['ttl']; + if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) { // Queue an event to re-run the update check in $ttl seconds. wp_schedule_single_event( time() + $ttl, 'wp_version_check' ); @@ -273,6 +278,7 @@ function wp_update_plugins( $extra_stats = array() ) { $active = get_option( 'active_plugins', array() ); $current = get_site_transient( 'update_plugins' ); + if ( ! is_object( $current ) ) { $current = new stdClass; } @@ -306,6 +312,7 @@ function wp_update_plugins( $extra_stats = array() ) { if ( $time_not_changed && ! $extra_stats ) { $plugin_changed = false; + foreach ( $plugins as $file => $p ) { $new_option->checked[ $file ] = $p['Version']; @@ -373,11 +380,13 @@ function wp_update_plugins( $extra_stats = array() ) { $url = 'http://api.wordpress.org/plugins/update-check/1.1/'; $http_url = $url; $ssl = wp_http_supports( array( 'ssl' ) ); + if ( $ssl ) { $url = set_url_scheme( $url, 'https' ); } $raw_response = wp_remote_post( $url, $options ); + if ( $ssl && is_wp_error( $raw_response ) ) { trigger_error( sprintf( @@ -390,24 +399,30 @@ function wp_update_plugins( $extra_stats = array() ) { $raw_response = wp_remote_post( $http_url, $options ); } - if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { + if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) { return; } $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); + foreach ( $response['plugins'] as &$plugin ) { $plugin = (object) $plugin; + if ( isset( $plugin->compatibility ) ) { $plugin->compatibility = (object) $plugin->compatibility; + foreach ( $plugin->compatibility as &$data ) { $data = (object) $data; } } } + unset( $plugin, $data ); + foreach ( $response['no_update'] as &$plugin ) { $plugin = (object) $plugin; } + unset( $plugin ); if ( is_array( $response ) ) { @@ -448,6 +463,7 @@ function wp_update_themes( $extra_stats = array() ) { $translations = wp_get_installed_translations( 'themes' ); $last_update = get_site_transient( 'update_themes' ); + if ( ! is_object( $last_update ) ) { $last_update = new stdClass; } @@ -499,6 +515,7 @@ function wp_update_themes( $extra_stats = array() ) { if ( $time_not_changed && ! $extra_stats ) { $theme_changed = false; + foreach ( $checked as $slug => $v ) { if ( ! isset( $last_update->checked[ $slug ] ) || strval( $last_update->checked[ $slug ] ) !== strval( $v ) ) { $theme_changed = true; @@ -563,11 +580,13 @@ function wp_update_themes( $extra_stats = array() ) { $url = 'http://api.wordpress.org/themes/update-check/1.1/'; $http_url = $url; $ssl = wp_http_supports( array( 'ssl' ) ); + if ( $ssl ) { $url = set_url_scheme( $url, 'https' ); } $raw_response = wp_remote_post( $url, $options ); + if ( $ssl && is_wp_error( $raw_response ) ) { trigger_error( sprintf( @@ -580,7 +599,7 @@ function wp_update_themes( $extra_stats = array() ) { $raw_response = wp_remote_post( $http_url, $options ); } - if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { + if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) { return; } @@ -625,8 +644,10 @@ 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 ) ) { continue; } @@ -635,6 +656,7 @@ function wp_get_translation_updates() { $updates[] = (object) $translation; } } + return $updates; } @@ -654,24 +676,30 @@ function wp_get_update_data() { ); $plugins = current_user_can( 'update_plugins' ); + if ( $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' ); + if ( $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' ) @@ -686,18 +714,22 @@ function wp_get_update_data() { $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; $titles = array(); + 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' ); } @@ -737,11 +769,13 @@ function _maybe_update_core() { $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 ) { + if ( isset( $current->last_checked, $current->version_checked ) + && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) + && $current->version_checked === $wp_version + ) { return; } + wp_version_check(); } /** @@ -756,9 +790,13 @@ function _maybe_update_core() { */ function _maybe_update_plugins() { $current = get_site_transient( 'update_plugins' ); - if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) { + + if ( isset( $current->last_checked ) + && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) + ) { return; } + wp_update_plugins(); } @@ -773,9 +811,13 @@ function _maybe_update_plugins() { */ function _maybe_update_themes() { $current = get_site_transient( 'update_themes' ); - if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) { + + if ( isset( $current->last_checked ) + && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) + ) { return; } + wp_update_themes(); } @@ -809,7 +851,9 @@ function wp_clean_update_cache() { } else { delete_site_transient( 'update_plugins' ); } + wp_clean_themes_cache(); + delete_site_transient( 'update_core' ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 9904157000..3bc47f2a4d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-47777'; +$wp_version = '5.5-alpha-47778'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.