Make WordPress Core

Changeset 47218


Ignore:
Timestamp:
02/09/2020 04:51:22 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use Yoda conditions in some wp-admin files.

Props subrataemfluence, marcio-zebedeu, bookdude13, 1naveengiri, alishankhan.
Fixes #44365, #48455.

Location:
trunk/src/wp-admin
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/admin.php

    r47198 r47218  
    7373         * attempt to do no more than threshold value, with some +/- allowed.
    7474         */
    75         if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) == 1 ) ) {
     75        if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) === 1 ) ) {
    7676            require_once ABSPATH . WPINC . '/http.php';
    7777            $response = wp_remote_get(
     
    182182
    183183        // Back-compat for plugins using add_management_page().
    184         if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook( $plugin_page, 'tools.php' ) ) {
     184        if ( empty( $page_hook ) && 'edit.php' === $pagenow && '' !== get_plugin_page_hook( $plugin_page, 'tools.php' ) ) {
    185185            // There could be plugin specific params on the URL, so we need the whole query string.
    186186            if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
     
    371371     * In all other cases, 'load-' . $pagenow should be used instead.
    372372     */
    373     if ( $typenow == 'page' ) {
    374         if ( $pagenow == 'post-new.php' ) {
     373    if ( 'page' === $typenow ) {
     374        if ( 'post-new.php' === $pagenow ) {
    375375            do_action( 'load-page-new.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    376         } elseif ( $pagenow == 'post.php' ) {
     376        } elseif ( 'post.php' === $pagenow ) {
    377377            do_action( 'load-page.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    378378        }
    379     } elseif ( $pagenow == 'edit-tags.php' ) {
    380         if ( $taxnow == 'category' ) {
     379    } elseif ( 'edit-tags.php' === $pagenow ) {
     380        if ( 'category' === $taxnow ) {
    381381            do_action( 'load-categories.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    382         } elseif ( $taxnow == 'link_category' ) {
     382        } elseif ( 'link_category' === $taxnow ) {
    383383            do_action( 'load-edit-link-categories.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    384384        }
  • trunk/src/wp-admin/install.php

    r47198 r47218  
    370370            display_setup_form( __( 'Please provide a valid username.' ) );
    371371            $error = true;
    372         } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
     372        } elseif ( sanitize_user( $user_name, true ) != $user_name ) {
    373373            display_setup_form( __( 'The username you provided has invalid characters.' ) );
    374374            $error = true;
     
    387387        }
    388388
    389         if ( $error === false ) {
     389        if ( false === $error ) {
    390390            $wpdb->show_errors();
    391391            $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
  • trunk/src/wp-admin/media-upload.php

    r47198 r47218  
    3434
    3535// Require an ID for the edit screen.
    36 if ( isset( $action ) && $action == 'edit' && ! $ID ) {
     36if ( isset( $action ) && 'edit' == $action && ! $ID ) {
    3737    wp_die(
    3838        '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
     
    8282
    8383// Let the action code decide how to handle the request.
    84 if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab, media_upload_tabs() ) ) {
     84if ( 'type' == $tab || 'type_url' == $tab || ! array_key_exists( $tab, media_upload_tabs() ) ) {
    8585    /**
    8686     * Fires inside specific upload-type views in the legacy (pre-3.5.0)
  • trunk/src/wp-admin/media.php

    r47198 r47218  
    7070            wp_die( __( 'You attempted to edit an item that isn&#8217;t an attachment. Please go back and try again.' ) );
    7171        }
    72         if ( $att->post_status == 'trash' ) {
     72        if ( 'trash' == $att->post_status ) {
    7373            wp_die( __( 'You can&#8217;t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.' ) );
    7474        }
  • trunk/src/wp-admin/ms-delete-site.php

    r47198 r47218  
    1818}
    1919
    20 if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) {
     20if ( isset( $_GET['h'] ) && '' != $_GET['h'] && false != get_option( 'delete_blog_hash' ) ) {
    2121    if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) {
    2222        wpmu_delete_blog( get_current_blog_id() );
     
    4343echo '<h1>' . esc_html( $title ) . '</h1>';
    4444
    45 if ( isset( $_POST['action'] ) && $_POST['action'] == 'deleteblog' && isset( $_POST['confirmdelete'] ) && $_POST['confirmdelete'] == '1' ) {
     45if ( isset( $_POST['action'] ) && 'deleteblog' == $_POST['action'] && isset( $_POST['confirmdelete'] ) && '1' == $_POST['confirmdelete'] ) {
    4646    check_admin_referer( 'delete-blog' );
    4747
  • trunk/src/wp-admin/options.php

    r47198 r47218  
    336336foreach ( (array) $options as $option ) :
    337337    $disabled = false;
    338     if ( $option->option_name == '' ) {
     338    if ( '' == $option->option_name ) {
    339339        continue;
    340340    }
  • trunk/src/wp-admin/post.php

    r47198 r47218  
    5656$sendback = wp_get_referer();
    5757if ( ! $sendback ||
    58     strpos( $sendback, 'post.php' ) !== false ||
    59     strpos( $sendback, 'post-new.php' ) !== false ) {
     58    false !== strpos( $sendback, 'post.php' ) ||
     59    false !== strpos( $sendback, 'post-new.php' ) ) {
    6060    if ( 'attachment' == $post_type ) {
    6161        $sendback = admin_url( 'upload.php' );
     
    161161            $post_new_file = 'media-new.php';
    162162        } else {
    163             if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) {
     163            if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) {
    164164                $parent_file = $post_type_object->show_in_menu;
    165165            } else {
     
    180180         * @param WP_Post $post    Post object.
    181181         */
    182         if ( apply_filters( 'replace_editor', false, $post ) === true ) {
     182        if ( true === apply_filters( 'replace_editor', false, $post ) ) {
    183183            break;
    184184        }
     
    310310        }
    311311
    312         if ( $post->post_type == 'attachment' ) {
     312        if ( 'attachment' === $post->post_type ) {
    313313            $force = ( ! MEDIA_TRASH );
    314314            if ( ! wp_delete_attachment( $post_id, $force ) ) {
  • trunk/src/wp-admin/update-core.php

    r47198 r47218  
    4343    $version_string = sprintf( '%s&ndash;<strong>%s</strong>', $update->current, $update->locale );
    4444
    45     if ( 'en_US' == $update->locale && 'en_US' == get_locale() ) {
     45    if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
    4646        $version_string = $update->current;
    47     } elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
     47    } elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
    4848        $updates = get_core_updates();
    4949        if ( $updates && 1 == count( $updates ) ) {
     
    5454
    5555    $current = false;
    56     if ( ! isset( $update->response ) || 'latest' == $update->response ) {
     56    if ( ! isset( $update->response ) || 'latest' === $update->response ) {
    5757        $current = true;
    5858    }
     
    6262    $mysql_version = $wpdb->db_version();
    6363    $show_buttons  = true;
    64     if ( 'development' == $update->response ) {
     64    if ( 'development' === $update->response ) {
    6565        $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' );
    6666    } else {
     
    154154        }
    155155    }
    156     if ( 'en_US' != $update->locale ) {
     156    if ( 'en_US' !== $update->locale ) {
    157157        if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
    158158            submit_button( __( 'Hide this update' ), '', 'dismiss', false );
     
    162162    }
    163163    echo '</p>';
    164     if ( 'en_US' != $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
     164    if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
    165165        echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
    166     } elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
     166    } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
    167167        // Partial builds don't need language-specific warnings.
    168168        echo '<p class="hint">' . sprintf(
    169169            /* translators: %s: WordPress version. */
    170170            __( 'You are about to install WordPress %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ),
    171             $update->response != 'development' ? $update->current : ''
     171            'development' !== $update->response ? $update->current : ''
    172172        ) . '</p>';
    173173    }
     
    226226    $updates    = get_core_updates();
    227227
    228     if ( ! isset( $updates[0]->response ) || 'latest' == $updates[0]->response ) {
     228    if ( ! isset( $updates[0]->response ) || 'latest' === $updates[0]->response ) {
    229229        echo '<h2>';
    230230        _e( 'You have the latest version of WordPress.' );
     
    257257    }
    258258
    259     if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
     259    if ( isset( $updates[0] ) && 'development' === $updates[0]->response ) {
    260260        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    261261        $upgrader = new WP_Automatic_Updater;
     
    275275    echo '</ul>';
    276276    // Don't show the maintenance mode notice when we are only showing a single re-install option.
    277     if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
     277    if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) {
    278278        echo '<p>' . __( '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.' ) . '</p>';
    279279    } elseif ( ! $updates ) {
     
    308308
    309309    $core_updates = get_core_updates();
    310     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, '=' ) ) {
     310    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, '=' ) ) {
    311311        $core_update_version = false;
    312312    } else {
     
    530530    $updates = wp_get_translation_updates();
    531531    if ( ! $updates ) {
    532         if ( 'en_US' != get_locale() ) {
     532        if ( 'en_US' !== get_locale() ) {
    533533            echo '<h2>' . __( 'Translations' ) . '</h2>';
    534534            echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
     
    693693if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
    694694    && ! isset( $_POST['checked'] ) ) {
    695     $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
     695    $upgrade_error = 'do-theme-upgrade' == $action ? 'themes' : 'plugins';
    696696    $action        = 'upgrade-core';
    697697}
     
    714714$updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate &#8220;Update&#8221; button</strong>. 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.' ) . '</p>';
    715715
    716 if ( 'en_US' != get_locale() ) {
     716if ( 'en_US' !== get_locale() ) {
    717717    $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; 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 <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
    718718}
     
    744744    if ( $upgrade_error ) {
    745745        echo '<div class="error"><p>';
    746         if ( $upgrade_error == 'themes' ) {
     746        if ( 'themes' === $upgrade_error ) {
    747747            _e( 'Please select one or more themes to update.' );
    748748        } else {
  • trunk/src/wp-admin/user-new.php

    r47198 r47218  
    6464    $username       = $user_details->user_login;
    6565    $user_id        = $user_details->ID;
    66     if ( $username != null && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) {
     66    if ( null != $username && array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) {
    6767        $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' );
    6868    } else {
Note: See TracChangeset for help on using the changeset viewer.