Skip to content

Commit eb88149

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@62699 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6d91e38 commit eb88149

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/wp-admin/nav-menus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ function wp_nav_menu_max_depth( $classes ) {
11791179

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 {
11851185
$auto_add = false;

src/wp-includes/kses.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) {
18631863
* has one of the given values.
18641864
*/
18651865

1866-
if ( false === array_search( strtolower( $value ), $checkvalue, true ) ) {
1866+
if ( ! in_array( strtolower( $value ), $checkvalue, true ) ) {
18671867
$ok = false;
18681868
}
18691869
break;

src/wp-includes/post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3736,7 +3736,7 @@ function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
37363736
foreach ( $patterns as $type => $pattern ) {
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;
37423742
}

tests/phpunit/includes/object-cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ public function buildKey( $key, $group = 'default' ) {
21712171
$group = 'default';
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 {
21772177
$prefix = $this->blog_prefix;

0 commit comments

Comments
 (0)