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
This commit is contained in:
Sergey Biryukov
2020-04-05 03:00:44 +00:00
parent 2e589142eb
commit 0b4e2c4604
140 changed files with 584 additions and 484 deletions

View File

@@ -416,7 +416,7 @@ if ( isset( $_GET['updated'] ) ) {
<td>
<?php
$lang = get_site_option( 'WPLANG' );
if ( ! in_array( $lang, $languages ) ) {
if ( ! in_array( $lang, $languages, true ) ) {
$lang = '';
}

View File

@@ -52,7 +52,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-site' == $_REQUEST['action'] ) {
if ( ! is_subdomain_install() ) {
$subdirectory_reserved_names = get_subdirectory_reserved_names();
if ( in_array( $domain, $subdirectory_reserved_names ) ) {
if ( in_array( $domain, $subdirectory_reserved_names, true ) ) {
wp_die(
sprintf(
/* translators: %s: Reserved names list. */
@@ -73,7 +73,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-site' == $_REQUEST['action'] ) {
if ( isset( $_POST['WPLANG'] ) ) {
if ( '' === $_POST['WPLANG'] ) {
$meta['WPLANG'] = ''; // en_US
} elseif ( in_array( $_POST['WPLANG'], get_available_languages() ) ) {
} elseif ( in_array( $_POST['WPLANG'], get_available_languages(), true ) ) {
$meta['WPLANG'] = $_POST['WPLANG'];
} elseif ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) {
$language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
@@ -260,7 +260,7 @@ printf(
$lang = get_site_option( 'WPLANG' );
// Use English if the default isn't available.
if ( ! in_array( $lang, $languages ) ) {
if ( ! in_array( $lang, $languages, true ) ) {
$lang = '';
}

View File

@@ -43,7 +43,7 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] && is_
foreach ( (array) $_POST['option'] as $key => $val ) {
$key = wp_unslash( $key );
$val = wp_unslash( $val );
if ( 0 === $key || is_array( $val ) || in_array( $key, $skip_options ) ) {
if ( 0 === $key || is_array( $val ) || in_array( $key, $skip_options, true ) ) {
continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options.
}
update_option( $key, $val );
@@ -149,7 +149,7 @@ if ( ! empty( $messages ) ) {
?>
<tr class="form-field">
<th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo esc_html( ucwords( str_replace( '_', ' ', $option->option_name ) ) ); ?></label></th>
<?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?>
<?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ), true ) ) { ?>
<td><code><?php echo esc_html( $option->option_value ); ?></code></td>
<?php } else { ?>
<td><input class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ); ?>]" type="text" id="<?php echo esc_attr( $option->option_name ); ?>" value="<?php echo esc_attr( $option->option_value ); ?>" size="40" <?php disabled( $disabled ); ?> /></td>

View File

@@ -7,7 +7,7 @@
* @since 3.1.0
*/
if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) ) {
if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ), true ) ) {
define( 'IFRAME_REQUEST', true );
}