Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict type check for in_array() and array_search() where strings are involved.

This reduces the number of WordPress.PHP.StrictInArray.MissingTrueStrict issues from 486 to 50.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r47472 r47550  
    162162            $post_counts = (array) wp_count_posts( $post_type, 'readable' );
    163163
    164             if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati ) ) {
     164            if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) {
    165165                $total_items = $post_counts[ $_REQUEST['post_status'] ];
    166166            } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
     
    347347            $status_name = $status->name;
    348348
    349             if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
     349            if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
    350350                continue;
    351351            }
     
    392392
    393393            // Sticky comes after Publish, or if not listed, after All.
    394             $split        = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
     394            $split        = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ), true );
    395395            $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
    396396        }
     
    647647
    648648        $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
    649         if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) {
     649        if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) ) {
    650650            $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
    651651        }
     
    13851385
    13861386        if ( is_post_type_viewable( $post_type_object ) ) {
    1387             if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
     1387            if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
    13881388                if ( $can_edit_post ) {
    13891389                    $preview_link    = get_preview_post_link( $post );
Note: See TracChangeset for help on using the changeset viewer.