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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47808 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-05-16 18:40:52 +00:00
parent 36e4db6b01
commit 6742d0d7a6
160 changed files with 1143 additions and 1007 deletions
+41 -37
View File
@@ -804,14 +804,14 @@ class WP_Query {
$qv['attachment_id'] = absint( $qv['attachment_id'] );
if ( ( '' != $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {
if ( ( '' !== $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {
$this->is_single = true;
$this->is_attachment = true;
} elseif ( '' != $qv['name'] ) {
} elseif ( '' !== $qv['name'] ) {
$this->is_single = true;
} elseif ( $qv['p'] ) {
$this->is_single = true;
} elseif ( '' != $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
} elseif ( '' !== $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
$this->is_page = true;
$this->is_single = false;
} else {
@@ -879,7 +879,7 @@ class WP_Query {
}
}
if ( '' != $qv['w'] ) {
if ( $qv['w'] ) {
$this->is_date = true;
}
@@ -891,7 +891,7 @@ class WP_Query {
continue;
}
if ( isset( $tax_query['operator'] ) && 'NOT IN' != $tax_query['operator'] ) {
if ( isset( $tax_query['operator'] ) && 'NOT IN' !== $tax_query['operator'] ) {
switch ( $tax_query['taxonomy'] ) {
case 'category':
$this->is_category = true;
@@ -912,7 +912,7 @@ class WP_Query {
$this->is_author = true;
}
if ( '' != $qv['author_name'] ) {
if ( '' !== $qv['author_name'] ) {
$this->is_author = true;
}
@@ -971,10 +971,10 @@ class WP_Query {
}
// Correct `is_*` for 'page_on_front' and 'page_for_posts'.
if ( $this->is_home && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
if ( $this->is_home && 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
$_query = wp_parse_args( $this->query );
// 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'.
if ( isset( $_query['pagename'] ) && '' == $_query['pagename'] ) {
if ( isset( $_query['pagename'] ) && '' === $_query['pagename'] ) {
unset( $_query['pagename'] );
}
@@ -992,10 +992,10 @@ class WP_Query {
}
}
if ( '' != $qv['pagename'] ) {
if ( '' !== $qv['pagename'] ) {
$this->queried_object = get_page_by_path( $qv['pagename'] );
if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) {
if ( $this->queried_object && 'attachment' === $this->queried_object->post_type ) {
if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) {
// See if we also have a post with the same slug.
$post = get_page_by_path( $qv['pagename'], OBJECT, 'post' );
@@ -1103,7 +1103,7 @@ class WP_Query {
}
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) {
if ( 'post_tag' == $taxonomy ) {
if ( 'post_tag' === $taxonomy ) {
continue; // Handled further down in the $q['tag'] block.
}
@@ -1235,7 +1235,7 @@ class WP_Query {
// Tag stuff.
if ( '' != $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
if ( '' !== $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
if ( strpos( $q['tag'], ',' ) !== false ) {
$tags = preg_split( '/[,\r\n\t ]+/', $q['tag'] );
foreach ( (array) $tags as $tag ) {
@@ -1993,7 +1993,7 @@ class WP_Query {
}
// If we've got a post_type AND it's not "any" post_type.
if ( ! empty( $q['post_type'] ) && 'any' != $q['post_type'] ) {
if ( ! empty( $q['post_type'] ) && 'any' !== $q['post_type'] ) {
foreach ( (array) $q['post_type'] as $_post_type ) {
$ptype_obj = get_post_type_object( $_post_type );
if ( ! $ptype_obj || ! $ptype_obj->query_var || empty( $q[ $ptype_obj->query_var ] ) ) {
@@ -2020,14 +2020,14 @@ class WP_Query {
}
// Parameters related to 'post_name'.
if ( '' != $q['name'] ) {
if ( '' !== $q['name'] ) {
$q['name'] = sanitize_title_for_query( $q['name'] );
$where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";
} elseif ( '' != $q['pagename'] ) {
} elseif ( '' !== $q['pagename'] ) {
if ( isset( $this->queried_object_id ) ) {
$reqpage = $this->queried_object_id;
} else {
if ( 'page' != $q['post_type'] ) {
if ( 'page' !== $q['post_type'] ) {
foreach ( (array) $q['post_type'] as $_post_type ) {
$ptype_obj = get_post_type_object( $_post_type );
if ( ! $ptype_obj || ! $ptype_obj->hierarchical ) {
@@ -2051,12 +2051,12 @@ class WP_Query {
}
$page_for_posts = get_option( 'page_for_posts' );
if ( ( 'page' != get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) {
if ( ( 'page' !== get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) {
$q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) );
$q['name'] = $q['pagename'];
$where .= " AND ({$wpdb->posts}.ID = '$reqpage')";
$reqpage_obj = get_post( $reqpage );
if ( is_object( $reqpage_obj ) && 'attachment' == $reqpage_obj->post_type ) {
if ( is_object( $reqpage_obj ) && 'attachment' === $reqpage_obj->post_type ) {
$this->is_attachment = true;
$post_type = 'attachment';
$q['post_type'] = 'attachment';
@@ -2064,7 +2064,7 @@ class WP_Query {
$q['attachment_id'] = $reqpage;
}
}
} elseif ( '' != $q['attachment'] ) {
} elseif ( '' !== $q['attachment'] ) {
$q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) );
$q['name'] = $q['attachment'];
$where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'";
@@ -2239,7 +2239,7 @@ class WP_Query {
// Author stuff for nice URLs.
if ( '' != $q['author_name'] ) {
if ( '' !== $q['author_name'] ) {
if ( strpos( $q['author_name'], '/' ) !== false ) {
$q['author_name'] = explode( '/', $q['author_name'] );
if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) {
@@ -2285,7 +2285,7 @@ class WP_Query {
// MIME-Type stuff for attachment browsing.
if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) {
if ( isset( $q['post_mime_type'] ) && '' !== $q['post_mime_type'] ) {
$whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts );
}
$where .= $search . $whichauthor . $whichmimetype;
@@ -2320,7 +2320,7 @@ class WP_Query {
} else {
$orderby = "{$wpdb->posts}.post_date " . $q['order'];
}
} elseif ( 'none' == $q['orderby'] ) {
} elseif ( 'none' === $q['orderby'] ) {
$orderby = '';
} else {
$orderby_array = array();
@@ -2413,7 +2413,7 @@ class WP_Query {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] );
}
if ( 'any' == $post_type ) {
if ( 'any' === $post_type ) {
$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
if ( empty( $in_search_post_types ) ) {
$where .= ' AND 1=0 ';
@@ -2468,7 +2468,7 @@ class WP_Query {
} else {
foreach ( get_post_stati() as $status ) {
if ( in_array( $status, $q_status, true ) ) {
if ( 'private' == $status ) {
if ( 'private' === $status ) {
$p_status[] = "{$wpdb->posts}.post_status = '$status'";
} else {
$r_status[] = "{$wpdb->posts}.post_status = '$status'";
@@ -2477,7 +2477,7 @@ class WP_Query {
}
}
if ( empty( $q['perm'] ) || 'readable' != $q['perm'] ) {
if ( empty( $q['perm'] ) || 'readable' !== $q['perm'] ) {
$r_status = array_merge( $r_status, $p_status );
unset( $p_status );
}
@@ -2486,14 +2486,14 @@ class WP_Query {
$statuswheres[] = '(' . join( ' AND ', $e_status ) . ')';
}
if ( ! empty( $r_status ) ) {
if ( ! empty( $q['perm'] ) && 'editable' == $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $r_status ) . '))';
} else {
$statuswheres[] = '(' . join( ' OR ', $r_status ) . ')';
}
}
if ( ! empty( $p_status ) ) {
if ( ! empty( $q['perm'] ) && 'readable' == $q['perm'] && ! current_user_can( $read_private_cap ) ) {
if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) {
$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $p_status ) . '))';
} else {
$statuswheres[] = '(' . join( ' OR ', $p_status ) . ')';
@@ -2515,7 +2515,7 @@ class WP_Query {
// Add public states.
$public_states = get_post_stati( array( 'public' => true ) );
foreach ( (array) $public_states as $state ) {
if ( 'publish' == $state ) { // Publish is hard-coded above.
if ( 'publish' === $state ) { // Publish is hard-coded above.
continue;
}
$where .= " OR {$wpdb->posts}.post_status = '$state'";
@@ -2948,7 +2948,7 @@ class WP_Query {
*/
$this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );
if ( 'ids' == $q['fields'] ) {
if ( 'ids' === $q['fields'] ) {
if ( null === $this->posts ) {
$this->posts = $wpdb->get_col( $this->request );
}
@@ -2960,7 +2960,7 @@ class WP_Query {
return $this->posts;
}
if ( 'id=>parent' == $q['fields'] ) {
if ( 'id=>parent' === $q['fields'] ) {
if ( null === $this->posts ) {
$this->posts = $wpdb->get_results( $this->request );
}
@@ -2980,7 +2980,7 @@ class WP_Query {
}
if ( null === $this->posts ) {
$split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
$split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
/**
* Filters whether to split the query.
@@ -3093,7 +3093,7 @@ class WP_Query {
$this->posts = array();
} else {
$this->is_preview = true;
if ( 'future' != $status ) {
if ( 'future' !== $status ) {
$this->posts[0]->post_date = current_time( 'mysql' );
}
}
@@ -3481,7 +3481,7 @@ class WP_Query {
$query = $this->tax_query->queried_terms[ $matched_taxonomy ];
if ( ! empty( $query['terms'] ) ) {
if ( 'term_id' == $query['field'] ) {
if ( 'term_id' === $query['field'] ) {
$term = get_term( reset( $query['terms'] ), $matched_taxonomy );
} else {
$term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );
@@ -3876,7 +3876,7 @@ class WP_Query {
return (bool) $this->is_feed;
}
$qv = $this->get( 'feed' );
if ( 'feed' == $qv ) {
if ( 'feed' === $qv ) {
$qv = get_default_feed();
}
return in_array( $qv, (array) $feeds, true );
@@ -3911,9 +3911,11 @@ class WP_Query {
*/
public function is_front_page() {
// Most likely case.
if ( 'posts' == get_option( 'show_on_front' ) && $this->is_home() ) {
if ( 'posts' === get_option( 'show_on_front' ) && $this->is_home() ) {
return true;
} elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) {
} elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' )
&& $this->is_page( get_option( 'page_on_front' ) )
) {
return true;
} else {
return false;
@@ -3954,7 +3956,9 @@ class WP_Query {
* @return bool True, if Privacy Policy page.
*/
public function is_privacy_policy() {
if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) {
if ( get_option( 'wp_page_for_privacy_policy' )
&& $this->is_page( get_option( 'wp_page_for_privacy_policy' ) )
) {
return true;
} else {
return false;