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

@@ -400,7 +400,7 @@ function populate_options( array $options = array() ) {
$offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
if ( is_numeric( $offset_or_tz ) ) {
$gmt_offset = $offset_or_tz;
} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) {
} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list(), true ) ) {
$timezone_string = $offset_or_tz;
}
@@ -563,11 +563,13 @@ function populate_options( array $options = array() ) {
$existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$insert = '';
foreach ( $options as $option => $value ) {
if ( in_array( $option, $existing_options ) ) {
if ( in_array( $option, $existing_options, true ) ) {
continue;
}
if ( in_array( $option, $fat_options ) ) {
if ( in_array( $option, $fat_options, true ) ) {
$autoload = 'no';
} else {
$autoload = 'yes';
@@ -576,9 +578,11 @@ function populate_options( array $options = array() ) {
if ( is_array( $value ) ) {
$value = serialize( $value );
}
if ( ! empty( $insert ) ) {
$insert .= ', ';
}
$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
}