Make WordPress Core

Changeset 62699


Ignore:
Timestamp:
07/12/2026 11:19:36 PM (2 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use in_array() instead of array_search() for existence checks.

Several places in core use array_search() purely to determine whether a value exists in an array, comparing the result against false. In these cases the returned key/position is never used, so in_array() expresses the intent more clearly and avoids computing a return value that is discarded.

This commit replaces those existence-only array_search() calls with in_array(). The strict (true) comparison flag is preserved in every case, so there is no change in behavior.

Props Soean.
See #64897.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/nav-menus.php

    r62173 r62699  
    11801180                                                                        if ( ! isset( $auto_add['auto_add'] ) ) {
    11811181                                                                                $auto_add = false;
    1182                                                                         } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
     1182                                                                        } elseif ( in_array( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
    11831183                                                                                $auto_add = true;
    11841184                                                                        } else {
  • trunk/src/wp-includes/kses.php

    r62550 r62699  
    18641864                         */
    18651865
    1866                         if ( false === array_search( strtolower( $value ), $checkvalue, true ) ) {
     1866                        if ( ! in_array( strtolower( $value ), $checkvalue, true ) ) {
    18671867                                $ok = false;
    18681868                        }
  • trunk/src/wp-includes/post.php

    r62694 r62699  
    37373737                        foreach ( (array) $real_mime_types as $real ) {
    37383738                                if ( preg_match( "#$pattern#", $real )
    3739                                         && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ], true ) )
     3739                                        && ( empty( $matches[ $type ] ) || ! in_array( $real, $matches[ $type ], true ) )
    37403740                                ) {
    37413741                                        $matches[ $type ][] = $real;
  • trunk/tests/phpunit/includes/object-cache.php

    r60270 r62699  
    21722172                }
    21732173
    2174                 if ( false !== array_search( $group, $this->global_groups, true ) ) {
     2174                if ( in_array( $group, $this->global_groups, true ) ) {
    21752175                        $prefix = $this->global_prefix;
    21762176                } else {
Note: See TracChangeset for help on using the changeset viewer.