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-includes/taxonomy.php

    r47219 r47550  
    621621    }
    622622
    623     if ( ! in_array( $object_type, $wp_taxonomies[ $taxonomy ]->object_type ) ) {
     623    if ( ! in_array( $object_type, $wp_taxonomies[ $taxonomy ]->object_type, true ) ) {
    624624        $wp_taxonomies[ $taxonomy ]->object_type[] = $object_type;
    625625    }
     
    15271527function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) {
    15281528    $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' );
    1529     if ( in_array( $field, $int_fields ) ) {
     1529    if ( in_array( $field, $int_fields, true ) ) {
    15301530        $value = (int) $value;
    15311531        if ( $value < 0 ) {
     
    22372237
    22382238                $existing_term = null;
    2239                 if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) {
     2239                $sibling_names = wp_list_pluck( $siblings, 'name' );
     2240                $sibling_slugs = wp_list_pluck( $siblings, 'slug' );
     2241
     2242                if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, $sibling_names, true ) ) {
    22402243                    $existing_term = $name_match;
    2241                 } elseif ( $slug_match && in_array( $slug, wp_list_pluck( $siblings, 'slug' ) ) ) {
     2244                } elseif ( $slug_match && in_array( $slug, $sibling_slugs, true ) ) {
    22422245                    $existing_term = $slug_match;
    22432246                }
     
    37013704    $object_types = array_unique( $object_types );
    37023705
    3703     $check_attachments = array_search( 'attachment', $object_types );
     3706    $check_attachments = array_search( 'attachment', $object_types, true );
    37043707    if ( false !== $check_attachments ) {
    37053708        unset( $object_types[ $check_attachments ] );
     
    44464449    foreach ( $object_terms as $object_term ) {
    44474450        // If term is an int, check against term_ids only.
    4448         if ( $ints && in_array( $object_term->term_id, $ints ) ) {
     4451        if ( $ints && in_array( $object_term->term_id, $ints, true ) ) {
    44494452            return true;
    44504453        }
     
    44574460            }
    44584461
    4459             if ( in_array( $object_term->name, $strs ) ) {
     4462            if ( in_array( $object_term->name, $strs, true ) ) {
    44604463                return true;
    44614464            }
    4462             if ( in_array( $object_term->slug, $strs ) ) {
     4465            if ( in_array( $object_term->slug, $strs, true ) ) {
    44634466                return true;
    44644467            }
     
    44834486        return false;
    44844487    }
    4485     return in_array( $taxonomy, $taxonomies );
     4488    return in_array( $taxonomy, $taxonomies, true );
    44864489}
    44874490
Note: See TracChangeset for help on using the changeset viewer.