WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/16/2020 06:40:52 PM (11 months 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/post.php

    r47633 r47808  
    770770            $_post = sanitize_post( $post, 'raw' );
    771771            $_post = new WP_Post( $_post );
    772         } elseif ( 'raw' == $post->filter ) {
     772        } elseif ( 'raw' === $post->filter ) {
    773773            $_post = new WP_Post( $post );
    774774        } else {
     
    900900    }
    901901
    902     if ( 'attachment' == $post->post_type ) {
    903         if ( 'private' == $post->post_status ) {
     902    if ( 'attachment' === $post->post_type ) {
     903        if ( 'private' === $post->post_status ) {
    904904            return 'private';
    905905        }
    906906
    907907        // Unattached attachments are assumed to be published.
    908         if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) ) {
     908        if ( ( 'inherit' === $post->post_status ) && ( 0 == $post->post_parent ) ) {
    909909            return 'publish';
    910910        }
     
    913913        if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) {
    914914            $parent_post_status = get_post_status( $post->post_parent );
    915             if ( 'trash' == $parent_post_status ) {
     915            if ( 'trash' === $parent_post_status ) {
    916916                return get_post_meta( $post->post_parent, '_wp_trash_meta_status', true );
    917917            } else {
     
    11611161    global $wp_post_statuses;
    11621162
    1163     $field = ( 'names' == $output ) ? 'name' : false;
     1163    $field = ( 'names' === $output ) ? 'name' : false;
    11641164
    11651165    return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field );
     
    12661266    global $wp_post_types;
    12671267
    1268     $field = ( 'names' == $output ) ? 'name' : false;
     1268    $field = ( 'names' === $output ) ? 'name' : false;
    12691269
    12701270    return wp_filter_object_list( $wp_post_types, $args, $operator, $field );
     
    20282028    $parsed_args = wp_parse_args( $args, $defaults );
    20292029    if ( empty( $parsed_args['post_status'] ) ) {
    2030         $parsed_args['post_status'] = ( 'attachment' == $parsed_args['post_type'] ) ? 'inherit' : 'publish';
     2030        $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish';
    20312031    }
    20322032    if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) {
     
    23822382    }
    23832383
    2384     if ( 'raw' == $context ) {
     2384    if ( 'raw' === $context ) {
    23852385        return $value;
    23862386    }
     
    23922392    }
    23932393
    2394     if ( 'edit' == $context ) {
     2394    if ( 'edit' === $context ) {
    23952395        $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' );
    23962396
     
    24272427
    24282428        if ( in_array( $field, $format_to_edit, true ) ) {
    2429             if ( 'post_content' == $field ) {
     2429            if ( 'post_content' === $field ) {
    24302430                $value = format_to_edit( $value, user_can_richedit() );
    24312431            } else {
     
    24352435            $value = esc_attr( $value );
    24362436        }
    2437     } elseif ( 'db' == $context ) {
     2437    } elseif ( 'db' === $context ) {
    24382438        if ( $prefixed ) {
    24392439
     
    25002500        }
    25012501
    2502         if ( 'attribute' == $context ) {
     2502        if ( 'attribute' === $context ) {
    25032503            $value = esc_attr( $value );
    2504         } elseif ( 'js' == $context ) {
     2504        } elseif ( 'js' === $context ) {
    25052505            $value = esc_js( $value );
    25062506        }
     
    26032603function _count_posts_cache_key( $type = 'post', $perm = '' ) {
    26042604    $cache_key = 'posts-' . $type;
    2605     if ( 'readable' == $perm && is_user_logged_in() ) {
     2605
     2606    if ( 'readable' === $perm && is_user_logged_in() ) {
    26062607        $post_type_object = get_post_type_object( $type );
     2608
    26072609        if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
    26082610            $cache_key .= '_' . $perm . '_' . get_current_user_id();
    26092611        }
    26102612    }
     2613
    26112614    return $cache_key;
    26122615}
     
    26472650
    26482651    $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    2649     if ( 'readable' == $perm && is_user_logged_in() ) {
     2652
     2653    if ( 'readable' === $perm && is_user_logged_in() ) {
    26502654        $post_type_object = get_post_type_object( $type );
    26512655        if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
     
    26562660        }
    26572661    }
     2662
    26582663    $query .= ' GROUP BY post_status';
    26592664
     
    31153120function _reset_front_page_settings_for_post( $post_id ) {
    31163121    $post = get_post( $post_id );
    3117     if ( 'page' == $post->post_type ) {
     3122
     3123    if ( 'page' === $post->post_type ) {
    31183124        /*
    31193125         * If the page is defined in option page_on_front or post_for_posts,
     
    31283134        }
    31293135    }
     3136
    31303137    unstick_post( $post->ID );
    31313138}
     
    33823389    foreach ( $group_by_status as $status => $comments ) {
    33833390        // Sanity check. This shouldn't happen.
    3384         if ( 'post-trashed' == $status ) {
     3391        if ( 'post-trashed' === $status ) {
    33853392            $status = '0';
    33863393        }
     
    37053712    if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) {
    37063713        // 'post' requires at least one category.
    3707         if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
     3714        if ( 'post' === $post_type && 'auto-draft' !== $post_status ) {
    37083715            $post_category = array( get_option( 'default_category' ) );
    37093716        } else {
     
    37493756     * is not 'draft' or 'pending', set date to now.
    37503757     */
    3751     if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' == $postarr['post_date'] ) {
    3752         if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
     3758    if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' === $postarr['post_date'] ) {
     3759        if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
    37533760            $post_date = current_time( 'mysql' );
    37543761        } else {
     
    37723779    }
    37733780
    3774     if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
     3781    if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
    37753782        if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) {
    37763783            $post_date_gmt = get_gmt_from_date( $post_date );
     
    37823789    }
    37833790
    3784     if ( $update || '0000-00-00 00:00:00' == $post_date ) {
     3791    if ( $update || '0000-00-00 00:00:00' === $post_date ) {
    37853792        $post_modified     = current_time( 'mysql' );
    37863793        $post_modified_gmt = current_time( 'mysql', 1 );
     
    38343841
    38353842    $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
    3836     if ( 'private' == $post_status ) {
     3843    if ( 'private' === $post_status ) {
    38373844        $post_password = '';
    38383845    }
     
    40284035
    40294036    // Set GUID.
    4030     if ( ! $update && '' == $current_guid ) {
     4037    if ( ! $update && '' === $current_guid ) {
    40314038        $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where );
    40324039    }
     
    40704077        $post->page_template = $postarr['page_template'];
    40714078        $page_templates      = wp_get_theme()->get_page_templates( $post );
    4072         if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
     4079        if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
    40734080            if ( $wp_error ) {
    40744081                return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
     
    42404247    if ( isset( $post['post_status'] )
    42414248        && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ), true )
    4242         && empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' == $post['post_date_gmt'] )
     4249        && empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' === $post['post_date_gmt'] )
    42434250    ) {
    42444251        $clear_date = true;
     
    42934300    }
    42944301
    4295     if ( 'publish' == $post->post_status ) {
     4302    if ( 'publish' === $post->post_status ) {
    42964303        return;
    42974304    }
     
    43384345    }
    43394346
    4340     if ( 'future' != $post->post_status ) {
     4347    if ( 'future' !== $post->post_status ) {
    43414348        return;
    43424349    }
     
    43724379function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
    43734380    if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true )
    4374         || ( 'inherit' == $post_status && 'revision' == $post_type ) || 'user_request' === $post_type
     4381        || ( 'inherit' === $post_status && 'revision' === $post_type ) || 'user_request' === $post_type
    43754382    ) {
    43764383        return $slug;
     
    44064413    }
    44074414
    4408     if ( 'attachment' == $post_type ) {
     4415    if ( 'attachment' === $post_type ) {
    44094416        // Attachment slugs must be unique across all types.
    44104417        $check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
     
    44344441        }
    44354442    } elseif ( is_post_type_hierarchical( $post_type ) ) {
    4436         if ( 'nav_menu_item' == $post_type ) {
     4443        if ( 'nav_menu_item' === $post_type ) {
    44374444            return $slug;
    44384445        }
     
    46724679    $post_categories = (array) $post_categories;
    46734680    if ( empty( $post_categories ) ) {
    4674         if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
     4681        if ( 'post' === $post_type && 'auto-draft' !== $post_status ) {
    46754682            $post_categories = array( get_option( 'default_category' ) );
    46764683            $append          = false;
     
    46784685            $post_categories = array();
    46794686        }
    4680     } elseif ( 1 == count( $post_categories ) && '' == reset( $post_categories ) ) {
     4687    } elseif ( 1 == count( $post_categories ) && '' === reset( $post_categories ) ) {
    46814688        return true;
    46824689    }
     
    48174824
    48184825    foreach ( $custom_fields as $key => $val ) {
    4819         if ( 'enclosure' != $key || ! is_array( $val ) ) {
     4826        if ( 'enclosure' !== $key || ! is_array( $val ) ) {
    48204827            continue;
    48214828        }
     
    53965403                }
    53975404
    5398                 if ( '' == $author_query ) {
     5405                if ( '' === $author_query ) {
    53995406                    $author_query = $wpdb->prepare( ' post_author = %d ', $post_author );
    54005407                } else {
     
    54025409                }
    54035410            }
    5404             if ( '' != $author_query ) {
     5411            if ( '' !== $author_query ) {
    54055412                $author_query = " AND ($author_query)";
    54065413            }
     
    55945601    if ( $id ) {
    55955602        $post = get_post( $id );
    5596         if ( 'attachment' == $post->post_type ) {
     5603        if ( 'attachment' === $post->post_type ) {
    55975604            return true;
    55985605        }
     
    59265933    }
    59275934
    5928     if ( 'attachment' != $post->post_type ) {
     5935    if ( 'attachment' !== $post->post_type ) {
    59295936        return false;
    59305937    }
     
    62406247                    while ( false !== $file = readdir( $dh ) ) {
    62416248                        $file = wp_basename( $file );
    6242                         if ( substr( $file, 0, 1 ) == '.' ) {
     6249                        if ( '.' === substr( $file, 0, 1 ) ) {
    62436250                            continue;
    62446251                        }
     
    67026709    do_action( 'clean_post_cache', $post->ID, $post );
    67036710
    6704     if ( 'page' == $post->post_type ) {
     6711    if ( 'page' === $post->post_type ) {
    67056712        wp_cache_delete( 'all_page_ids', 'posts' );
    67066713
     
    67486755        if ( is_array( $post_type ) ) {
    67496756            $ptypes = $post_type;
    6750         } elseif ( 'any' == $post_type ) {
     6757        } elseif ( 'any' === $post_type ) {
    67516758            $ptypes = array();
    67526759            // Just use the post_types in the supplied posts.
     
    68486855    if ( 'publish' !== $old_status && 'publish' === $new_status ) {
    68496856        // Reset GUID if transitioning to publish and it is empty.
    6850         if ( '' == get_the_guid( $post->ID ) ) {
     6857        if ( '' === get_the_guid( $post->ID ) ) {
    68516858            $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );
    68526859        }
     
    68646871
    68656872    // If published posts changed clear the lastpostmodified cache.
    6866     if ( 'publish' == $new_status || 'publish' == $old_status ) {
     6873    if ( 'publish' === $new_status || 'publish' === $old_status ) {
    68676874        foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
    68686875            wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
Note: See TracChangeset for help on using the changeset viewer.