diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-admin/includes/update.php --- a/wp/wp-admin/includes/update.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-admin/includes/update.php Fri Sep 05 18:40:08 2025 +0200 @@ -15,12 +15,15 @@ */ function get_preferred_from_update_core() { $updates = get_core_updates(); + if ( ! is_array( $updates ) ) { return false; } + if ( empty( $updates ) ) { return (object) array( 'response' => 'latest' ); } + return $updates[0]; } @@ -34,13 +37,14 @@ * @return array|false Array of the update objects on success, false on failure. */ function get_core_updates( $options = array() ) { - $options = array_merge( + $options = array_merge( array( 'available' => true, 'dismissed' => false, ), $options ); + $dismissed = get_site_option( 'dismissed_update_core' ); if ( ! is_array( $dismissed ) ) { @@ -55,6 +59,7 @@ $updates = $from_api->updates; $result = array(); + foreach ( $updates as $update ) { if ( 'autoupdate' === $update->response ) { continue; @@ -72,6 +77,7 @@ } } } + return $result; } @@ -86,6 +92,7 @@ */ function find_core_auto_update() { $updates = get_site_transient( 'update_core' ); + if ( ! $updates || empty( $updates->updates ) ) { return false; } @@ -93,7 +100,8 @@ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $auto_update = false; - $upgrader = new WP_Automatic_Updater; + $upgrader = new WP_Automatic_Updater(); + foreach ( $updates->updates as $update ) { if ( 'autoupdate' !== $update->response ) { continue; @@ -107,6 +115,7 @@ $auto_update = $update; } } + return $auto_update; } @@ -124,6 +133,7 @@ $url = $http_url; $ssl = wp_http_supports( array( 'ssl' ) ); + if ( $ssl ) { $url = set_url_scheme( $url, 'https' ); } @@ -133,8 +143,10 @@ ); $response = wp_remote_get( $url, $options ); + if ( $ssl && is_wp_error( $response ) ) { - trigger_error( + wp_trigger_error( + __FUNCTION__, sprintf( /* 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 support forums.' ), @@ -142,10 +154,11 @@ ) . ' ' . __( '(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 ) ) { + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return false; } @@ -170,6 +183,7 @@ 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 ); } @@ -191,6 +205,7 @@ } unset( $dismissed[ $key ] ); + return update_site_option( 'dismissed_update_core', $dismissed ); } @@ -211,15 +226,19 @@ } $updates = $from_api->updates; + foreach ( $updates as $update ) { - if ( $update->current == $version && $update->locale == $locale ) { + if ( $update->current === $version && $update->locale === $locale ) { return $update; } } + return false; } /** + * Returns core update footer message. + * * @since 2.3.0 * * @param string $msg @@ -232,8 +251,9 @@ } $cur = get_preferred_from_update_core(); + if ( ! is_object( $cur ) ) { - $cur = new stdClass; + $cur = new stdClass(); } if ( ! isset( $cur->current ) ) { @@ -275,6 +295,8 @@ } /** + * Returns core update notification message. + * * @since 2.3.0 * * @global string $pagenow The filename of the current screen. @@ -299,7 +321,7 @@ $version_url = sprintf( /* translators: %s: WordPress version. */ - esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ), + esc_url( __( 'https://wordpress.org/documentation/wordpress-version/version-%s/' ) ), sanitize_title( $cur->current ) ); @@ -321,7 +343,14 @@ ); } - echo "
$msg
"; + wp_admin_notice( + $msg, + array( + 'type' => 'warning', + 'additional_classes' => array( 'update-nag', 'inline' ), + 'paragraph_wrap' => false, + ) + ); } /** @@ -331,6 +360,7 @@ */ function update_right_now_message() { $theme_name = wp_get_theme(); + if ( current_user_can( 'switch_themes' ) ) { $theme_name = sprintf( '%1$s', $theme_name ); } @@ -370,6 +400,8 @@ } /** + * Retrieves plugins with updates available. + * * @since 2.9.0 * * @return array @@ -378,6 +410,7 @@ $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; @@ -389,6 +422,8 @@ } /** + * Adds a callback to display update information for plugins with updates available. + * * @since 2.9.0 */ function wp_plugin_update_rows() { @@ -397,8 +432,10 @@ } $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 ); } @@ -416,6 +453,7 @@ */ function wp_plugin_update_row( $file, $plugin_data ) { $current = get_site_transient( 'update_plugins' ); + if ( ! isset( $current->response[ $file ] ) ) { return false; } @@ -585,6 +623,8 @@ } /** + * Retrieves themes with updates available. + * * @since 2.9.0 * * @return array @@ -597,6 +637,7 @@ } $update_themes = array(); + foreach ( $current->response as $stylesheet => $data ) { $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet ); $update_themes[ $stylesheet ]->update = $data; @@ -606,6 +647,8 @@ } /** + * Adds a callback to display update information for themes with updates available. + * * @since 3.1.0 */ function wp_theme_update_rows() { @@ -614,6 +657,7 @@ } $themes = get_site_transient( 'update_themes' ); + if ( isset( $themes->response ) && is_array( $themes->response ) ) { $themes = array_keys( $themes->response ); @@ -801,16 +845,21 @@ } /** + * Displays maintenance nag HTML message. + * * @since 2.7.0 * * @global int $upgrading + * * @return void|false */ function maintenance_nag() { // Include an unmodified $wp_version. require ABSPATH . WPINC . '/version.php'; global $upgrading; + $nag = isset( $upgrading ); + if ( ! $nag ) { $failed = get_site_option( 'auto_core_update_failed' ); /* @@ -843,12 +892,21 @@ $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' ); } - echo "
$msg
"; + wp_admin_notice( + $msg, + array( + 'type' => 'warning', + 'additional_classes' => array( 'update-nag', 'inline' ), + 'paragraph_wrap' => false, + ) + ); } /** * Prints the JavaScript templates for update admin notices. * + * @since 4.6.0 + * * Template takes one argument with four values: * * param {object} data { @@ -859,8 +917,6 @@ * @type string message The notice's message. * @type string type The type of update the notice is for. Either 'plugin' or 'theme'. * } - * - * @since 4.6.0 */ function wp_print_admin_notice_templates() { ?> @@ -868,54 +924,25 @@
id="{{ data.id }}"<# } #> class="notice {{ data.className }}">

{{{ data.message }}}