Skip to content

Commit 0b4e2c4

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@47550 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2e58914 commit 0b4e2c4

140 files changed

Lines changed: 584 additions & 484 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/wp-activate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
} elseif ( is_wp_error( $result ) ) {
5858
$error_code = $result->get_error_code();
5959

60-
if ( ! in_array( $error_code, $valid_error_codes ) ) {
60+
if ( ! in_array( $error_code, $valid_error_codes, true ) ) {
6161
status_header( 400 );
6262
}
6363
}
@@ -136,7 +136,7 @@ function wpmu_activate_stylesheet() {
136136

137137
<?php
138138
} else {
139-
if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes ) ) {
139+
if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes, true ) ) {
140140
$signup = $result->get_error_data();
141141
?>
142142
<h2><?php _e( 'Your account is now active!' ); ?></h2>

src/wp-admin/admin-ajax.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@
146146
$core_actions_post = array_merge( $core_actions_post, $core_actions_post_deprecated );
147147

148148
// Register core Ajax calls.
149-
if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) {
149+
if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get, true ) ) {
150150
add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
151151
}
152152

153-
if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) ) {
153+
if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post, true ) ) {
154154
add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
155155
}
156156

src/wp-admin/comment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
case 'unapprovecomment':
256256
$comment_id = absint( $_REQUEST['c'] );
257257

258-
if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
258+
if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
259259
check_admin_referer( 'approve-comment_' . $comment_id );
260260
} else {
261261
check_admin_referer( 'delete-comment_' . $comment_id );
@@ -275,7 +275,7 @@
275275
$redir = wp_get_referer();
276276
} elseif ( '' != wp_get_original_referer() && ! $noredir ) {
277277
$redir = wp_get_original_referer();
278-
} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
278+
} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
279279
$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
280280
} else {
281281
$redir = admin_url( 'edit-comments.php' );

src/wp-admin/edit-tags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
wp_die( __( 'Invalid taxonomy.' ) );
2020
}
2121

22-
if ( ! in_array( $tax->name, get_taxonomies( array( 'show_ui' => true ) ) ) ) {
22+
if ( ! in_array( $tax->name, get_taxonomies( array( 'show_ui' => true ) ), true ) ) {
2323
wp_die( __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ) );
2424
}
2525

src/wp-admin/edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
wp_die( __( 'Invalid post type.' ) );
1414
}
1515

16-
if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
16+
if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
1717
wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
1818
}
1919

src/wp-admin/includes/ajax-actions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ function wp_ajax_dim_comment() {
976976

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 {
982982
$result = wp_set_comment_status( $comment, 'hold', true );
@@ -1271,7 +1271,7 @@ function wp_ajax_replyto_comment( $action ) {
12711271

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
}
12771277

@@ -2057,7 +2057,7 @@ function wp_ajax_inline_save() {
20572057
}
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'] );
20632063
}
@@ -2525,7 +2525,7 @@ function wp_ajax_upload_attachment() {
25252525
}
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

25312531
if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
@@ -2852,7 +2852,7 @@ function wp_ajax_dismiss_wp_pointer() {
28522852

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
}
28582858

src/wp-admin/includes/class-custom-background.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public function wp_set_background_image() {
601601
);
602602

603603
$size = 'thumbnail';
604-
if ( in_array( $_POST['size'], $sizes ) ) {
604+
if ( in_array( $_POST['size'], $sizes, true ) ) {
605605
$size = esc_attr( $_POST['size'] );
606606
}
607607

src/wp-admin/includes/class-custom-image-header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ final public function set_header_image( $choice ) {
10971097
return;
10981098
}
10991099

1100-
if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ) ) ) {
1100+
if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) {
11011101
set_theme_mod( 'header_image', $choice );
11021102
remove_theme_mod( 'header_image_data' );
11031103
return;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function start_el( &$output, $category, $depth = 0, $args = array(), $id
8282
}
8383

8484
$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
85-
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
85+
86+
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
8687

8788
$args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
8889

src/wp-admin/includes/class-wp-automatic-updater.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ protected function after_core_update( $update_result ) {
577577
*/
578578
$send = true;
579579
$transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' );
580-
if ( in_array( $error_code, $transient_failures ) && ! get_site_option( 'auto_core_update_failed' ) ) {
580+
if ( in_array( $error_code, $transient_failures, true ) && ! get_site_option( 'auto_core_update_failed' ) ) {
581581
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' );
582582
$send = false;
583583
}
@@ -596,7 +596,7 @@ protected function after_core_update( $update_result ) {
596596
'error_code' => $error_code,
597597
'error_data' => $result->get_error_data(),
598598
'timestamp' => time(),
599-
'retry' => in_array( $error_code, $transient_failures ),
599+
'retry' => in_array( $error_code, $transient_failures, true ),
600600
)
601601
);
602602

0 commit comments

Comments
 (0)