Make WordPress Core


Ignore:
Timestamp:
05/16/2020 06:40:52 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison where static strings are involved.

This reduces the number of WordPress.PHP.StrictComparisons.LooseComparison issues in half, from 1897 to 890.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r47635 r47808  
    805805        $qv['attachment_id'] = absint( $qv['attachment_id'] );
    806806
    807         if ( ( '' != $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {
     807        if ( ( '' !== $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {
    808808            $this->is_single     = true;
    809809            $this->is_attachment = true;
    810         } elseif ( '' != $qv['name'] ) {
     810        } elseif ( '' !== $qv['name'] ) {
    811811            $this->is_single = true;
    812812        } elseif ( $qv['p'] ) {
    813813            $this->is_single = true;
    814         } elseif ( '' != $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
     814        } elseif ( '' !== $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
    815815            $this->is_page   = true;
    816816            $this->is_single = false;
     
    880880            }
    881881
    882             if ( '' != $qv['w'] ) {
     882            if ( $qv['w'] ) {
    883883                $this->is_date = true;
    884884            }
     
    892892                }
    893893
    894                 if ( isset( $tax_query['operator'] ) && 'NOT IN' != $tax_query['operator'] ) {
     894                if ( isset( $tax_query['operator'] ) && 'NOT IN' !== $tax_query['operator'] ) {
    895895                    switch ( $tax_query['taxonomy'] ) {
    896896                        case 'category':
     
    913913            }
    914914
    915             if ( '' != $qv['author_name'] ) {
     915            if ( '' !== $qv['author_name'] ) {
    916916                $this->is_author = true;
    917917            }
     
    972972
    973973        // Correct `is_*` for 'page_on_front' and 'page_for_posts'.
    974         if ( $this->is_home && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
     974        if ( $this->is_home && 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
    975975            $_query = wp_parse_args( $this->query );
    976976            // 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'.
    977             if ( isset( $_query['pagename'] ) && '' == $_query['pagename'] ) {
     977            if ( isset( $_query['pagename'] ) && '' === $_query['pagename'] ) {
    978978                unset( $_query['pagename'] );
    979979            }
     
    993993        }
    994994
    995         if ( '' != $qv['pagename'] ) {
     995        if ( '' !== $qv['pagename'] ) {
    996996            $this->queried_object = get_page_by_path( $qv['pagename'] );
    997997
    998             if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) {
     998            if ( $this->queried_object && 'attachment' === $this->queried_object->post_type ) {
    999999                if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) {
    10001000                    // See if we also have a post with the same slug.
     
    11041104
    11051105        foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) {
    1106             if ( 'post_tag' == $taxonomy ) {
     1106            if ( 'post_tag' === $taxonomy ) {
    11071107                continue; // Handled further down in the $q['tag'] block.
    11081108            }
     
    12361236        // Tag stuff.
    12371237
    1238         if ( '' != $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
     1238        if ( '' !== $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
    12391239            if ( strpos( $q['tag'], ',' ) !== false ) {
    12401240                $tags = preg_split( '/[,\r\n\t ]+/', $q['tag'] );
     
    19941994
    19951995        // If we've got a post_type AND it's not "any" post_type.
    1996         if ( ! empty( $q['post_type'] ) && 'any' != $q['post_type'] ) {
     1996        if ( ! empty( $q['post_type'] ) && 'any' !== $q['post_type'] ) {
    19971997            foreach ( (array) $q['post_type'] as $_post_type ) {
    19981998                $ptype_obj = get_post_type_object( $_post_type );
     
    20212021
    20222022        // Parameters related to 'post_name'.
    2023         if ( '' != $q['name'] ) {
     2023        if ( '' !== $q['name'] ) {
    20242024            $q['name'] = sanitize_title_for_query( $q['name'] );
    20252025            $where    .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";
    2026         } elseif ( '' != $q['pagename'] ) {
     2026        } elseif ( '' !== $q['pagename'] ) {
    20272027            if ( isset( $this->queried_object_id ) ) {
    20282028                $reqpage = $this->queried_object_id;
    20292029            } else {
    2030                 if ( 'page' != $q['post_type'] ) {
     2030                if ( 'page' !== $q['post_type'] ) {
    20312031                    foreach ( (array) $q['post_type'] as $_post_type ) {
    20322032                        $ptype_obj = get_post_type_object( $_post_type );
     
    20522052
    20532053            $page_for_posts = get_option( 'page_for_posts' );
    2054             if ( ( 'page' != get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) {
     2054            if ( ( 'page' !== get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) {
    20552055                $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) );
    20562056                $q['name']     = $q['pagename'];
    20572057                $where        .= " AND ({$wpdb->posts}.ID = '$reqpage')";
    20582058                $reqpage_obj   = get_post( $reqpage );
    2059                 if ( is_object( $reqpage_obj ) && 'attachment' == $reqpage_obj->post_type ) {
     2059                if ( is_object( $reqpage_obj ) && 'attachment' === $reqpage_obj->post_type ) {
    20602060                    $this->is_attachment = true;
    20612061                    $post_type           = 'attachment';
     
    20652065                }
    20662066            }
    2067         } elseif ( '' != $q['attachment'] ) {
     2067        } elseif ( '' !== $q['attachment'] ) {
    20682068            $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) );
    20692069            $q['name']       = $q['attachment'];
     
    22402240        // Author stuff for nice URLs.
    22412241
    2242         if ( '' != $q['author_name'] ) {
     2242        if ( '' !== $q['author_name'] ) {
    22432243            if ( strpos( $q['author_name'], '/' ) !== false ) {
    22442244                $q['author_name'] = explode( '/', $q['author_name'] );
     
    22862286        // MIME-Type stuff for attachment browsing.
    22872287
    2288         if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) {
     2288        if ( isset( $q['post_mime_type'] ) && '' !== $q['post_mime_type'] ) {
    22892289            $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts );
    22902290        }
     
    23212321                $orderby = "{$wpdb->posts}.post_date " . $q['order'];
    23222322            }
    2323         } elseif ( 'none' == $q['orderby'] ) {
     2323        } elseif ( 'none' === $q['orderby'] ) {
    23242324            $orderby = '';
    23252325        } else {
     
    24142414        }
    24152415
    2416         if ( 'any' == $post_type ) {
     2416        if ( 'any' === $post_type ) {
    24172417            $in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
    24182418            if ( empty( $in_search_post_types ) ) {
     
    24692469                foreach ( get_post_stati() as $status ) {
    24702470                    if ( in_array( $status, $q_status, true ) ) {
    2471                         if ( 'private' == $status ) {
     2471                        if ( 'private' === $status ) {
    24722472                            $p_status[] = "{$wpdb->posts}.post_status = '$status'";
    24732473                        } else {
     
    24782478            }
    24792479
    2480             if ( empty( $q['perm'] ) || 'readable' != $q['perm'] ) {
     2480            if ( empty( $q['perm'] ) || 'readable' !== $q['perm'] ) {
    24812481                $r_status = array_merge( $r_status, $p_status );
    24822482                unset( $p_status );
     
    24872487            }
    24882488            if ( ! empty( $r_status ) ) {
    2489                 if ( ! empty( $q['perm'] ) && 'editable' == $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
     2489                if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
    24902490                    $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $r_status ) . '))';
    24912491                } else {
     
    24942494            }
    24952495            if ( ! empty( $p_status ) ) {
    2496                 if ( ! empty( $q['perm'] ) && 'readable' == $q['perm'] && ! current_user_can( $read_private_cap ) ) {
     2496                if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) {
    24972497                    $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $p_status ) . '))';
    24982498                } else {
     
    25162516            $public_states = get_post_stati( array( 'public' => true ) );
    25172517            foreach ( (array) $public_states as $state ) {
    2518                 if ( 'publish' == $state ) { // Publish is hard-coded above.
     2518                if ( 'publish' === $state ) { // Publish is hard-coded above.
    25192519                    continue;
    25202520                }
     
    29492949        $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );
    29502950
    2951         if ( 'ids' == $q['fields'] ) {
     2951        if ( 'ids' === $q['fields'] ) {
    29522952            if ( null === $this->posts ) {
    29532953                $this->posts = $wpdb->get_col( $this->request );
     
    29612961        }
    29622962
    2963         if ( 'id=>parent' == $q['fields'] ) {
     2963        if ( 'id=>parent' === $q['fields'] ) {
    29642964            if ( null === $this->posts ) {
    29652965                $this->posts = $wpdb->get_results( $this->request );
     
    29812981
    29822982        if ( null === $this->posts ) {
    2983             $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
     2983            $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
    29842984
    29852985            /**
     
    30943094                            } else {
    30953095                                $this->is_preview = true;
    3096                                 if ( 'future' != $status ) {
     3096                                if ( 'future' !== $status ) {
    30973097                                    $this->posts[0]->post_date = current_time( 'mysql' );
    30983098                                }
     
    34823482
    34833483                    if ( ! empty( $query['terms'] ) ) {
    3484                         if ( 'term_id' == $query['field'] ) {
     3484                        if ( 'term_id' === $query['field'] ) {
    34853485                            $term = get_term( reset( $query['terms'] ), $matched_taxonomy );
    34863486                        } else {
     
    38773877        }
    38783878        $qv = $this->get( 'feed' );
    3879         if ( 'feed' == $qv ) {
     3879        if ( 'feed' === $qv ) {
    38803880            $qv = get_default_feed();
    38813881        }
     
    39123912    public function is_front_page() {
    39133913        // Most likely case.
    3914         if ( 'posts' == get_option( 'show_on_front' ) && $this->is_home() ) {
     3914        if ( 'posts' === get_option( 'show_on_front' ) && $this->is_home() ) {
    39153915            return true;
    3916         } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) {
     3916        } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' )
     3917            && $this->is_page( get_option( 'page_on_front' ) )
     3918        ) {
    39173919            return true;
    39183920        } else {
     
    39553957     */
    39563958    public function is_privacy_policy() {
    3957         if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) {
     3959        if ( get_option( 'wp_page_for_privacy_policy' )
     3960            && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) )
     3961        ) {
    39583962            return true;
    39593963        } else {
Note: See TracChangeset for help on using the changeset viewer.