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/ajax-actions.php

    r47245 r47550  
    977977    check_ajax_referer( "approve-comment_$id" );
    978978
    979     if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
     979    if ( in_array( $current, array( 'unapproved', 'spam' ), true ) ) {
    980980        $result = wp_set_comment_status( $comment, 'approve', true );
    981981    } else {
     
    12721272    if ( empty( $post->post_status ) ) {
    12731273        wp_die( 1 );
    1274     } elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ) ) ) {
     1274    } elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) {
    12751275        wp_die( __( 'Error: You are replying to a comment on a draft post.' ) );
    12761276    }
     
    20582058
    20592059    // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
    2060     if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) {
     2060    if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ), true ) ) {
    20612061        $post['post_status'] = 'publish';
    20622062        $data['post_name']   = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] );
     
    25262526
    25272527    // If the context is custom header or background, make sure the uploaded file is an image.
    2528     if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
     2528    if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ), true ) ) {
    25292529        $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
    25302530
     
    28532853    $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
    28542854
    2855     if ( in_array( $pointer, $dismissed ) ) {
     2855    if ( in_array( $pointer, $dismissed, true ) ) {
    28562856        wp_die( 0 );
    28572857    }
Note: See TracChangeset for help on using the changeset viewer.