Skip to content

Commit d8c502e

Browse files
Coding Standards: Use strict type check for in_array() and array_search().
This addresses all the remaining `WordPress.PHP.StrictInArray.MissingTrueStrict` issues in core. Includes minor code layout fixes for better readability. Follow-up to [47550]. See #49542. git-svn-id: https://develop.svn.wordpress.org/trunk@47557 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3df79c3 commit d8c502e

28 files changed

Lines changed: 172 additions & 77 deletions

src/wp-admin/includes/class-walker-category-checklist.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public function start_el( &$output, $category, $depth = 0, $args = array(), $id
8383

8484
$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
8585

86-
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
86+
$class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
8787

8888
$args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
8989

9090
if ( ! empty( $args['list_only'] ) ) {
9191
$aria_checked = 'false';
9292
$inner_class = 'category';
9393

94-
if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
94+
if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
9595
$inner_class .= ' selected';
9696
$aria_checked = 'true';
9797
}
@@ -102,10 +102,13 @@ public function start_el( &$output, $category, $depth = 0, $args = array(), $id
102102
/** This filter is documented in wp-includes/category-template.php */
103103
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
104104
} else {
105+
$is_selected = in_array( $category->term_id, $args['selected_cats'], true );
106+
$is_disabled = ! empty( $args['disabled'] );
107+
105108
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
106109
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
107-
checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
108-
disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
110+
checked( $is_selected, true, false ) .
111+
disabled( $is_disabled, true, false ) . ' /> ' .
109112
/** This filter is documented in wp-includes/category-template.php */
110113
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
111114
}

src/wp-admin/includes/class-wp-filesystem-base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public function getnumchmodfromh( $mode ) {
401401
$attarray = preg_split( '//', $mode );
402402

403403
for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
404-
$key = array_search( $attarray[ $i ], $legal );
404+
$key = array_search( $attarray[ $i ], $legal, true );
405405
if ( $key ) {
406406
$realmode .= $legal[ $key ];
407407
}

src/wp-admin/includes/class-wp-ms-users-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ protected function handle_row_actions( $user, $column_name, $primary ) {
505505
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
506506
}
507507

508-
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
508+
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins, true ) ) {
509509
$actions['delete'] = '<a href="' . esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
510510
}
511511

src/wp-admin/includes/class-wp-terms-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$coun
300300
$my_parent = get_term( $p, $taxonomy );
301301
$my_parents[] = $my_parent;
302302
$p = $my_parent->parent;
303-
if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
303+
if ( in_array( $p, $parent_ids, true ) ) { // Prevent parent loops.
304304
break;
305305
}
306306
$parent_ids[] = $p;

src/wp-admin/includes/dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ function wp_dashboard_quick_press( $error_msg = false ) {
519519
$post = get_default_post_to_edit( 'post', true );
520520
$user_id = get_current_user_id();
521521
// Don't create an option if this is a super admin who does not belong to this site.
522-
if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
522+
if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
523523
update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
524524
}
525525
}

src/wp-admin/includes/ms.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,19 +922,23 @@ function confirm_delete_users( $users ) {
922922
'fields' => array( 'ID', 'user_login' ),
923923
)
924924
);
925+
925926
if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
926927
$user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
927928
$user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
928929
$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
929930
$user_list = '';
931+
930932
foreach ( $blog_users as $user ) {
931-
if ( ! in_array( $user->ID, $allusers ) ) {
933+
if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
932934
$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
933935
}
934936
}
937+
935938
if ( '' == $user_list ) {
936939
$user_list = $admin_out;
937940
}
941+
938942
$user_dropdown .= $user_list;
939943
$user_dropdown .= "</select>\n";
940944
?>

src/wp-admin/includes/nav-menu.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,10 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
11491149
'post_status' => 'draft,publish',
11501150
)
11511151
);
1152-
$messages = array();
1153-
$menu_items = array();
1152+
1153+
$messages = array();
1154+
$menu_items = array();
1155+
11541156
// Index menu items by DB ID.
11551157
foreach ( $unsorted_menu_items as $_item ) {
11561158
$menu_items[ $_item->db_id ] = $_item;
@@ -1173,6 +1175,7 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
11731175
);
11741176

11751177
wp_defer_term_counting( true );
1178+
11761179
// Loop through all the menu items' POST variables.
11771180
if ( ! empty( $_POST['menu-item-db-id'] ) ) {
11781181
foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
@@ -1209,19 +1212,22 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
12091212
// Store 'auto-add' pages.
12101213
$auto_add = ! empty( $_POST['auto-add-pages'] );
12111214
$nav_menu_option = (array) get_option( 'nav_menu_options' );
1215+
12121216
if ( ! isset( $nav_menu_option['auto_add'] ) ) {
12131217
$nav_menu_option['auto_add'] = array();
12141218
}
1219+
12151220
if ( $auto_add ) {
1216-
if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) {
1221+
if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) {
12171222
$nav_menu_option['auto_add'][] = $nav_menu_selected_id;
12181223
}
12191224
} else {
1220-
$key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] );
1225+
$key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true );
12211226
if ( false !== $key ) {
12221227
unset( $nav_menu_option['auto_add'][ $key ] );
12231228
}
12241229
}
1230+
12251231
// Remove non-existent/deleted menus.
12261232
$nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
12271233
update_option( 'nav_menu_options', $nav_menu_option );

src/wp-admin/includes/plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ function add_option_whitelist( $new_options, $options = '' ) {
21702170
$whitelist_options[ $page ] = array();
21712171
$whitelist_options[ $page ][] = $key;
21722172
} else {
2173-
$pos = array_search( $key, $whitelist_options[ $page ] );
2173+
$pos = array_search( $key, $whitelist_options[ $page ], true );
21742174
if ( false === $pos ) {
21752175
$whitelist_options[ $page ][] = $key;
21762176
}
@@ -2202,7 +2202,7 @@ function remove_option_whitelist( $del_options, $options = '' ) {
22022202
foreach ( $del_options as $page => $keys ) {
22032203
foreach ( $keys as $key ) {
22042204
if ( isset( $whitelist_options[ $page ] ) && is_array( $whitelist_options[ $page ] ) ) {
2205-
$pos = array_search( $key, $whitelist_options[ $page ] );
2205+
$pos = array_search( $key, $whitelist_options[ $page ], true );
22062206
if ( false !== $pos ) {
22072207
unset( $whitelist_options[ $page ][ $pos ] );
22082208
}

src/wp-admin/includes/post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ function bulk_edit_posts( $post_data = null ) {
548548
$children[] = $parent;
549549

550550
foreach ( $pages as $page ) {
551-
if ( $page->ID == $parent ) {
552-
$parent = $page->post_parent;
551+
if ( (int) $page->ID === $parent ) {
552+
$parent = (int) $page->post_parent;
553553
break;
554554
}
555555
}
@@ -568,7 +568,7 @@ function bulk_edit_posts( $post_data = null ) {
568568
$post_type_object = get_post_type_object( get_post_type( $post_ID ) );
569569

570570
if ( ! isset( $post_type_object )
571-
|| ( isset( $children ) && in_array( $post_ID, $children ) )
571+
|| ( isset( $children ) && in_array( $post_ID, $children, true ) )
572572
|| ! current_user_can( 'edit_post', $post_ID )
573573
) {
574574
$skipped[] = $post_ID;

src/wp-admin/includes/revision.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
314314
// Now, grab the initial diff.
315315
$compare_two_mode = is_numeric( $from );
316316
if ( ! $compare_two_mode ) {
317-
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
317+
$found = array_search( $selected_revision_id, array_keys( $revisions ), true );
318318
if ( $found ) {
319319
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
320320
$from = reset( $from );

0 commit comments

Comments
 (0)