Coding Standards: Use strict comparison in `wp-admin/includes/update.php`.

Includes minor code layout fixes for better readability.

Follow-up to [9441], [25540].

Props aristath, poena, afercia, SergeyBiryukov.
See #57839.
Built from https://develop.svn.wordpress.org/trunk@55874


git-svn-id: http://core.svn.wordpress.org/trunk@55386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-06-01 15:14:27 +00:00
parent 3d1140c898
commit eaafce587e
2 changed files with 31 additions and 4 deletions

View File

@ -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];
}
@ -41,6 +44,7 @@ function get_core_updates( $options = array() ) {
),
$options
);
$dismissed = get_site_option( 'dismissed_update_core' );
if ( ! is_array( $dismissed ) ) {
@ -55,6 +59,7 @@ function get_core_updates( $options = array() ) {
$updates = $from_api->updates;
$result = array();
foreach ( $updates as $update ) {
if ( 'autoupdate' === $update->response ) {
continue;
@ -72,6 +77,7 @@ function get_core_updates( $options = array() ) {
}
}
}
return $result;
}
@ -86,6 +92,7 @@ function get_core_updates( $options = array() ) {
*/
function find_core_auto_update() {
$updates = get_site_transient( 'update_core' );
if ( ! $updates || empty( $updates->updates ) ) {
return false;
}
@ -94,6 +101,7 @@ function find_core_auto_update() {
$auto_update = false;
$upgrader = new WP_Automatic_Updater();
foreach ( $updates->updates as $update ) {
if ( 'autoupdate' !== $update->response ) {
continue;
@ -107,6 +115,7 @@ function find_core_auto_update() {
$auto_update = $update;
}
}
return $auto_update;
}
@ -124,6 +133,7 @@ function get_core_checksums( $version, $locale ) {
$url = $http_url;
$ssl = wp_http_supports( array( 'ssl' ) );
if ( $ssl ) {
$url = set_url_scheme( $url, 'https' );
}
@ -133,6 +143,7 @@ function get_core_checksums( $version, $locale ) {
);
$response = wp_remote_get( $url, $options );
if ( $ssl && is_wp_error( $response ) ) {
trigger_error(
sprintf(
@ -142,10 +153,11 @@ function get_core_checksums( $version, $locale ) {
) . ' ' . __( '(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 +182,7 @@ function get_core_checksums( $version, $locale ) {
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 +204,7 @@ function undismiss_core_update( $version, $locale ) {
}
unset( $dismissed[ $key ] );
return update_site_option( 'dismissed_update_core', $dismissed );
}
@ -211,11 +225,13 @@ function find_core_update( $version, $locale ) {
}
$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;
}
@ -234,6 +250,7 @@ function core_update_footer( $msg = '' ) {
}
$cur = get_preferred_from_update_core();
if ( ! is_object( $cur ) ) {
$cur = new stdClass();
}
@ -335,6 +352,7 @@ function update_nag() {
*/
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 );
}
@ -384,6 +402,7 @@ 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;
@ -405,8 +424,10 @@ function wp_plugin_update_rows() {
}
$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 );
}
@ -424,6 +445,7 @@ function wp_plugin_update_rows() {
*/
function wp_plugin_update_row( $file, $plugin_data ) {
$current = get_site_transient( 'update_plugins' );
if ( ! isset( $current->response[ $file ] ) ) {
return false;
}
@ -607,6 +629,7 @@ function get_theme_updates() {
}
$update_themes = array();
foreach ( $current->response as $stylesheet => $data ) {
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
$update_themes[ $stylesheet ]->update = $data;
@ -626,6 +649,7 @@ function wp_theme_update_rows() {
}
$themes = get_site_transient( 'update_themes' );
if ( isset( $themes->response ) && is_array( $themes->response ) ) {
$themes = array_keys( $themes->response );
@ -818,13 +842,16 @@ function wp_theme_update_row( $theme_key, $theme ) {
* @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' );
/*

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55873';
$wp_version = '6.3-alpha-55874';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.