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() { function get_preferred_from_update_core() {
$updates = get_core_updates(); $updates = get_core_updates();
if ( ! is_array( $updates ) ) { if ( ! is_array( $updates ) ) {
return false; return false;
} }
if ( empty( $updates ) ) { if ( empty( $updates ) ) {
return (object) array( 'response' => 'latest' ); return (object) array( 'response' => 'latest' );
} }
return $updates[0]; return $updates[0];
} }
@ -34,13 +37,14 @@ function get_preferred_from_update_core() {
* @return array|false Array of the update objects on success, false on failure. * @return array|false Array of the update objects on success, false on failure.
*/ */
function get_core_updates( $options = array() ) { function get_core_updates( $options = array() ) {
$options = array_merge( $options = array_merge(
array( array(
'available' => true, 'available' => true,
'dismissed' => false, 'dismissed' => false,
), ),
$options $options
); );
$dismissed = get_site_option( 'dismissed_update_core' ); $dismissed = get_site_option( 'dismissed_update_core' );
if ( ! is_array( $dismissed ) ) { if ( ! is_array( $dismissed ) ) {
@ -55,6 +59,7 @@ function get_core_updates( $options = array() ) {
$updates = $from_api->updates; $updates = $from_api->updates;
$result = array(); $result = array();
foreach ( $updates as $update ) { foreach ( $updates as $update ) {
if ( 'autoupdate' === $update->response ) { if ( 'autoupdate' === $update->response ) {
continue; continue;
@ -72,6 +77,7 @@ function get_core_updates( $options = array() ) {
} }
} }
} }
return $result; return $result;
} }
@ -86,6 +92,7 @@ function get_core_updates( $options = array() ) {
*/ */
function find_core_auto_update() { function find_core_auto_update() {
$updates = get_site_transient( 'update_core' ); $updates = get_site_transient( 'update_core' );
if ( ! $updates || empty( $updates->updates ) ) { if ( ! $updates || empty( $updates->updates ) ) {
return false; return false;
} }
@ -94,6 +101,7 @@ function find_core_auto_update() {
$auto_update = false; $auto_update = false;
$upgrader = new WP_Automatic_Updater(); $upgrader = new WP_Automatic_Updater();
foreach ( $updates->updates as $update ) { foreach ( $updates->updates as $update ) {
if ( 'autoupdate' !== $update->response ) { if ( 'autoupdate' !== $update->response ) {
continue; continue;
@ -107,6 +115,7 @@ function find_core_auto_update() {
$auto_update = $update; $auto_update = $update;
} }
} }
return $auto_update; return $auto_update;
} }
@ -124,6 +133,7 @@ function get_core_checksums( $version, $locale ) {
$url = $http_url; $url = $http_url;
$ssl = wp_http_supports( array( 'ssl' ) ); $ssl = wp_http_supports( array( 'ssl' ) );
if ( $ssl ) { if ( $ssl ) {
$url = set_url_scheme( $url, 'https' ); $url = set_url_scheme( $url, 'https' );
} }
@ -133,6 +143,7 @@ function get_core_checksums( $version, $locale ) {
); );
$response = wp_remote_get( $url, $options ); $response = wp_remote_get( $url, $options );
if ( $ssl && is_wp_error( $response ) ) { if ( $ssl && is_wp_error( $response ) ) {
trigger_error( trigger_error(
sprintf( 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.)' ), ) . ' ' . __( '(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 headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
); );
$response = wp_remote_get( $http_url, $options ); $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; return false;
} }
@ -170,6 +182,7 @@ function get_core_checksums( $version, $locale ) {
function dismiss_core_update( $update ) { function dismiss_core_update( $update ) {
$dismissed = get_site_option( 'dismissed_update_core' ); $dismissed = get_site_option( 'dismissed_update_core' );
$dismissed[ $update->current . '|' . $update->locale ] = true; $dismissed[ $update->current . '|' . $update->locale ] = true;
return update_site_option( 'dismissed_update_core', $dismissed ); return update_site_option( 'dismissed_update_core', $dismissed );
} }
@ -191,6 +204,7 @@ function undismiss_core_update( $version, $locale ) {
} }
unset( $dismissed[ $key ] ); unset( $dismissed[ $key ] );
return update_site_option( 'dismissed_update_core', $dismissed ); return update_site_option( 'dismissed_update_core', $dismissed );
} }
@ -211,11 +225,13 @@ function find_core_update( $version, $locale ) {
} }
$updates = $from_api->updates; $updates = $from_api->updates;
foreach ( $updates as $update ) { foreach ( $updates as $update ) {
if ( $update->current == $version && $update->locale == $locale ) { if ( $update->current === $version && $update->locale === $locale ) {
return $update; return $update;
} }
} }
return false; return false;
} }
@ -234,6 +250,7 @@ function core_update_footer( $msg = '' ) {
} }
$cur = get_preferred_from_update_core(); $cur = get_preferred_from_update_core();
if ( ! is_object( $cur ) ) { if ( ! is_object( $cur ) ) {
$cur = new stdClass(); $cur = new stdClass();
} }
@ -335,6 +352,7 @@ function update_nag() {
*/ */
function update_right_now_message() { function update_right_now_message() {
$theme_name = wp_get_theme(); $theme_name = wp_get_theme();
if ( current_user_can( 'switch_themes' ) ) { if ( current_user_can( 'switch_themes' ) ) {
$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name ); $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
} }
@ -384,6 +402,7 @@ function get_plugin_updates() {
$all_plugins = get_plugins(); $all_plugins = get_plugins();
$upgrade_plugins = array(); $upgrade_plugins = array();
$current = get_site_transient( 'update_plugins' ); $current = get_site_transient( 'update_plugins' );
foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) { foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) { if ( isset( $current->response[ $plugin_file ] ) ) {
$upgrade_plugins[ $plugin_file ] = (object) $plugin_data; $upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
@ -405,8 +424,10 @@ function wp_plugin_update_rows() {
} }
$plugins = get_site_transient( 'update_plugins' ); $plugins = get_site_transient( 'update_plugins' );
if ( isset( $plugins->response ) && is_array( $plugins->response ) ) { if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
$plugins = array_keys( $plugins->response ); $plugins = array_keys( $plugins->response );
foreach ( $plugins as $plugin_file ) { foreach ( $plugins as $plugin_file ) {
add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 ); 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 ) { function wp_plugin_update_row( $file, $plugin_data ) {
$current = get_site_transient( 'update_plugins' ); $current = get_site_transient( 'update_plugins' );
if ( ! isset( $current->response[ $file ] ) ) { if ( ! isset( $current->response[ $file ] ) ) {
return false; return false;
} }
@ -607,6 +629,7 @@ function get_theme_updates() {
} }
$update_themes = array(); $update_themes = array();
foreach ( $current->response as $stylesheet => $data ) { foreach ( $current->response as $stylesheet => $data ) {
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet ); $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
$update_themes[ $stylesheet ]->update = $data; $update_themes[ $stylesheet ]->update = $data;
@ -626,6 +649,7 @@ function wp_theme_update_rows() {
} }
$themes = get_site_transient( 'update_themes' ); $themes = get_site_transient( 'update_themes' );
if ( isset( $themes->response ) && is_array( $themes->response ) ) { if ( isset( $themes->response ) && is_array( $themes->response ) ) {
$themes = array_keys( $themes->response ); $themes = array_keys( $themes->response );
@ -818,13 +842,16 @@ function wp_theme_update_row( $theme_key, $theme ) {
* @since 2.7.0 * @since 2.7.0
* *
* @global int $upgrading * @global int $upgrading
*
* @return void|false * @return void|false
*/ */
function maintenance_nag() { function maintenance_nag() {
// Include an unmodified $wp_version. // Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php'; require ABSPATH . WPINC . '/version.php';
global $upgrading; global $upgrading;
$nag = isset( $upgrading ); $nag = isset( $upgrading );
if ( ! $nag ) { if ( ! $nag ) {
$failed = get_site_option( 'auto_core_update_failed' ); $failed = get_site_option( 'auto_core_update_failed' );
/* /*

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.