From 5e6c949861a1e7932491a3236c43d68fa3b66fb6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 9 Feb 2020 16:53:06 +0000 Subject: [PATCH] Coding Standards: Use Yoda conditions in some `wp-admin` files. Props subrataemfluence, marcio-zebedeu, bookdude13, 1naveengiri, alishankhan. Fixes #44365, #48455. Built from https://develop.svn.wordpress.org/trunk@47218 git-svn-id: http://core.svn.wordpress.org/trunk@47018 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin.php | 16 ++++++++-------- wp-admin/install.php | 4 ++-- wp-admin/media-upload.php | 4 ++-- wp-admin/media.php | 2 +- wp-admin/ms-delete-site.php | 4 ++-- wp-admin/options.php | 2 +- wp-admin/post.php | 10 +++++----- wp-admin/update-core.php | 32 ++++++++++++++++---------------- wp-admin/user-new.php | 2 +- wp-includes/version.php | 2 +- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/wp-admin/admin.php b/wp-admin/admin.php index e01abfb39a..7b703caff9 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -72,7 +72,7 @@ if ( get_option( 'db_upgraded' ) ) { * If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load: * attempt to do no more than threshold value, with some +/- allowed. */ - if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) == 1 ) ) { + if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) === 1 ) ) { require_once ABSPATH . WPINC . '/http.php'; $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), @@ -181,7 +181,7 @@ if ( isset( $plugin_page ) ) { $page_hook = get_plugin_page_hook( $plugin_page, $plugin_page ); // Back-compat for plugins using add_management_page(). - if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook( $plugin_page, 'tools.php' ) ) { + if ( empty( $page_hook ) && 'edit.php' === $pagenow && '' !== get_plugin_page_hook( $plugin_page, 'tools.php' ) ) { // There could be plugin specific params on the URL, so we need the whole query string. if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { $query_string = $_SERVER['QUERY_STRING']; @@ -370,16 +370,16 @@ if ( isset( $plugin_page ) ) { * The following hooks are fired to ensure backward compatibility. * In all other cases, 'load-' . $pagenow should be used instead. */ - if ( $typenow == 'page' ) { - if ( $pagenow == 'post-new.php' ) { + if ( 'page' === $typenow ) { + if ( 'post-new.php' === $pagenow ) { do_action( 'load-page-new.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - } elseif ( $pagenow == 'post.php' ) { + } elseif ( 'post.php' === $pagenow ) { do_action( 'load-page.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } - } elseif ( $pagenow == 'edit-tags.php' ) { - if ( $taxnow == 'category' ) { + } elseif ( 'edit-tags.php' === $pagenow ) { + if ( 'category' === $taxnow ) { do_action( 'load-categories.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - } elseif ( $taxnow == 'link_category' ) { + } elseif ( 'link_category' === $taxnow ) { do_action( 'load-edit-link-categories.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } } elseif ( 'term.php' === $pagenow ) { diff --git a/wp-admin/install.php b/wp-admin/install.php index 088b88ef14..5380f8b74d 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -369,7 +369,7 @@ switch ( $step ) { // TODO: Poka-yoke. display_setup_form( __( 'Please provide a valid username.' ) ); $error = true; - } elseif ( $user_name != sanitize_user( $user_name, true ) ) { + } elseif ( sanitize_user( $user_name, true ) != $user_name ) { display_setup_form( __( 'The username you provided has invalid characters.' ) ); $error = true; } elseif ( $admin_password != $admin_password_check ) { @@ -386,7 +386,7 @@ switch ( $step ) { $error = true; } - if ( $error === false ) { + if ( false === $error ) { $wpdb->show_errors(); $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language ); ?> diff --git a/wp-admin/media-upload.php b/wp-admin/media-upload.php index f009bc162a..7035f28b88 100644 --- a/wp-admin/media-upload.php +++ b/wp-admin/media-upload.php @@ -33,7 +33,7 @@ $ID = isset( $ID ) ? (int) $ID : 0; $post_id = isset( $post_id ) ? (int) $post_id : 0; // Require an ID for the edit screen. -if ( isset( $action ) && $action == 'edit' && ! $ID ) { +if ( isset( $action ) && 'edit' == $action && ! $ID ) { wp_die( '

' . __( 'Something went wrong.' ) . '

' . '

' . __( 'Invalid item ID.' ) . '

', @@ -81,7 +81,7 @@ if ( isset( $_GET['tab'] ) ) { $body_id = 'media-upload'; // Let the action code decide how to handle the request. -if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab, media_upload_tabs() ) ) { +if ( 'type' == $tab || 'type_url' == $tab || ! array_key_exists( $tab, media_upload_tabs() ) ) { /** * Fires inside specific upload-type views in the legacy (pre-3.5.0) * media popup based on the current tab. diff --git a/wp-admin/media.php b/wp-admin/media.php index 5f0752d1ac..83b35e9448 100644 --- a/wp-admin/media.php +++ b/wp-admin/media.php @@ -69,7 +69,7 @@ switch ( $action ) { if ( 'attachment' !== $att->post_type ) { wp_die( __( 'You attempted to edit an item that isn’t an attachment. Please go back and try again.' ) ); } - if ( $att->post_status == 'trash' ) { + if ( 'trash' == $att->post_status ) { wp_die( __( 'You can’t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.' ) ); } diff --git a/wp-admin/ms-delete-site.php b/wp-admin/ms-delete-site.php index 3332f50e29..28868384c2 100644 --- a/wp-admin/ms-delete-site.php +++ b/wp-admin/ms-delete-site.php @@ -17,7 +17,7 @@ if ( ! current_user_can( 'delete_site' ) ) { wp_die( __( 'Sorry, you are not allowed to delete this site.' ) ); } -if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) { +if ( isset( $_GET['h'] ) && '' != $_GET['h'] && false != get_option( 'delete_blog_hash' ) ) { if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) { wpmu_delete_blog( get_current_blog_id() ); wp_die( @@ -42,7 +42,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php'; echo '
'; echo '

' . esc_html( $title ) . '

'; -if ( isset( $_POST['action'] ) && $_POST['action'] == 'deleteblog' && isset( $_POST['confirmdelete'] ) && $_POST['confirmdelete'] == '1' ) { +if ( isset( $_POST['action'] ) && 'deleteblog' == $_POST['action'] && isset( $_POST['confirmdelete'] ) && '1' == $_POST['confirmdelete'] ) { check_admin_referer( 'delete-blog' ); $hash = wp_generate_password( 20, false ); diff --git a/wp-admin/options.php b/wp-admin/options.php index 0672e944d4..5b3efc5fc2 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -335,7 +335,7 @@ $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_nam foreach ( (array) $options as $option ) : $disabled = false; - if ( $option->option_name == '' ) { + if ( '' == $option->option_name ) { continue; } if ( is_serialized( $option->option_value ) ) { diff --git a/wp-admin/post.php b/wp-admin/post.php index d32e52b9b9..f5693f495f 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -55,8 +55,8 @@ if ( isset( $_POST['deletepost'] ) ) { $sendback = wp_get_referer(); if ( ! $sendback || - strpos( $sendback, 'post.php' ) !== false || - strpos( $sendback, 'post-new.php' ) !== false ) { + false !== strpos( $sendback, 'post.php' ) || + false !== strpos( $sendback, 'post-new.php' ) ) { if ( 'attachment' == $post_type ) { $sendback = admin_url( 'upload.php' ); } else { @@ -160,7 +160,7 @@ switch ( $action ) { $submenu_file = 'upload.php'; $post_new_file = 'media-new.php'; } else { - if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) { + if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) { $parent_file = $post_type_object->show_in_menu; } else { $parent_file = "edit.php?post_type=$post_type"; @@ -179,7 +179,7 @@ switch ( $action ) { * @param bool $replace Whether to replace the editor. Default false. * @param WP_Post $post Post object. */ - if ( apply_filters( 'replace_editor', false, $post ) === true ) { + if ( true === apply_filters( 'replace_editor', false, $post ) ) { break; } @@ -309,7 +309,7 @@ switch ( $action ) { wp_die( __( 'Sorry, you are not allowed to delete this item.' ) ); } - if ( $post->post_type == 'attachment' ) { + if ( 'attachment' === $post->post_type ) { $force = ( ! MEDIA_TRASH ); if ( ! wp_delete_attachment( $post_id, $force ) ) { wp_die( __( 'Error in deleting.' ) ); diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index 394aebadbf..e3734bd90c 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -42,9 +42,9 @@ function list_core_update( $update ) { $wp_version = get_bloginfo( 'version' ); $version_string = sprintf( '%s–%s', $update->current, $update->locale ); - if ( 'en_US' == $update->locale && 'en_US' == get_locale() ) { + if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) { $version_string = $update->current; - } elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) { + } elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) { $updates = get_core_updates(); if ( $updates && 1 == count( $updates ) ) { // If the only available update is a partial builds, it doesn't need a language-specific version string. @@ -53,7 +53,7 @@ function list_core_update( $update ) { } $current = false; - if ( ! isset( $update->response ) || 'latest' == $update->response ) { + if ( ! isset( $update->response ) || 'latest' === $update->response ) { $current = true; } $submit = __( 'Update Now' ); @@ -61,7 +61,7 @@ function list_core_update( $update ) { $php_version = phpversion(); $mysql_version = $wpdb->db_version(); $show_buttons = true; - if ( 'development' == $update->response ) { + if ( 'development' === $update->response ) { $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' ); } else { if ( $current ) { @@ -153,7 +153,7 @@ function list_core_update( $update ) { submit_button( $submit, '', 'upgrade', false ); } } - if ( 'en_US' != $update->locale ) { + if ( 'en_US' !== $update->locale ) { if ( ! isset( $update->dismissed ) || ! $update->dismissed ) { submit_button( __( 'Hide this update' ), '', 'dismiss', false ); } else { @@ -161,14 +161,14 @@ function list_core_update( $update ) { } } echo '

'; - if ( 'en_US' != $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) { + if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) { echo '

' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '

'; - } elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) { + } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) { // Partial builds don't need language-specific warnings. echo '

' . sprintf( /* translators: %s: WordPress version. */ __( 'You are about to install WordPress %s in English (US). There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ), - $update->response != 'development' ? $update->current : '' + 'development' !== $update->response ? $update->current : '' ) . '

'; } echo ''; @@ -225,7 +225,7 @@ function core_upgrade_preamble() { $wp_version = get_bloginfo( 'version' ); $updates = get_core_updates(); - if ( ! isset( $updates[0]->response ) || 'latest' == $updates[0]->response ) { + if ( ! isset( $updates[0]->response ) || 'latest' === $updates[0]->response ) { echo '

'; _e( 'You have the latest version of WordPress.' ); @@ -256,7 +256,7 @@ function core_upgrade_preamble() { echo '

'; } - if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) { + if ( isset( $updates[0] ) && 'development' === $updates[0]->response ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new WP_Automatic_Updater; if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) { @@ -274,7 +274,7 @@ function core_upgrade_preamble() { } echo ''; // Don't show the maintenance mode notice when we are only showing a single re-install option. - if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) { + if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) { echo '

' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, your site will return to normal.' ) . '

'; } elseif ( ! $updates ) { list( $normalized_version ) = explode( '-', $wp_version ); @@ -307,7 +307,7 @@ function list_plugin_updates() { $form_action = 'update-core.php?action=do-plugin-upgrade'; $core_updates = get_core_updates(); - if ( ! isset( $core_updates[0]->response ) || 'latest' == $core_updates[0]->response || 'development' == $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=' ) ) { + if ( ! isset( $core_updates[0]->response ) || 'latest' === $core_updates[0]->response || 'development' === $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=' ) ) { $core_update_version = false; } else { $core_update_version = $core_updates[0]->current; @@ -529,7 +529,7 @@ function list_theme_updates() { function list_translation_updates() { $updates = wp_get_translation_updates(); if ( ! $updates ) { - if ( 'en_US' != get_locale() ) { + if ( 'en_US' !== get_locale() ) { echo '

' . __( 'Translations' ) . '

'; echo '

' . __( 'Your translations are all up to date.' ) . '

'; } @@ -692,7 +692,7 @@ $action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core'; $upgrade_error = false; if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) ) && ! isset( $_POST['checked'] ) ) { - $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins'; + $upgrade_error = 'do-theme-upgrade' == $action ? 'themes' : 'plugins'; $action = 'upgrade-core'; } @@ -713,7 +713,7 @@ get_current_screen()->add_help_tab( $updates_howto = '

' . __( 'WordPress — Updating your WordPress installation is a simple one-click procedure: just click on the “Update Now” button when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '

'; $updates_howto .= '

' . __( 'Themes and Plugins — To update individual themes or plugins from this screen, use the checkboxes to make your selection, then click on the appropriate “Update” button. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '

'; -if ( 'en_US' != get_locale() ) { +if ( 'en_US' !== get_locale() ) { $updates_howto .= '

' . __( 'Translations — The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can click the “Update Translations” button.' ) . '

'; } @@ -743,7 +743,7 @@ if ( 'upgrade-core' == $action ) {

'; - if ( $upgrade_error == 'themes' ) { + if ( 'themes' === $upgrade_error ) { _e( 'Please select one or more themes to update.' ); } else { _e( 'Please select one or more plugins to update.' ); diff --git a/wp-admin/user-new.php b/wp-admin/user-new.php index dff49fecf0..be4b5083bc 100644 --- a/wp-admin/user-new.php +++ b/wp-admin/user-new.php @@ -63,7 +63,7 @@ if ( isset( $_REQUEST['action'] ) && 'adduser' == $_REQUEST['action'] ) { $redirect = 'user-new.php'; $username = $user_details->user_login; $user_id = $user_details->ID; - if ( $username != null && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) { + if ( null != $username && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) { $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' ); } else { if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index c695d39aa4..b3ac54fbf4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-47217'; +$wp_version = '5.4-alpha-47218'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.