Code Modernisation: Fix known instances of array access on data types that can't be accessed as arrays.

PHP 7.4 addes a warning when trying access a null/bool/int/float/resource (everything but array, string and object) as if it were an array.

This change fixes all of these warnings visible in unit tests.

Props jrf.
See #47704.




git-svn-id: https://develop.svn.wordpress.org/trunk@45639 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2019-07-15 06:24:08 +00:00
parent e6c750b55c
commit 2da7f9f524
9 changed files with 32 additions and 20 deletions

View File

@@ -2371,14 +2371,14 @@ function add_theme_support( $feature, ...$args ) {
* Merge post types with any that already declared their support
* for post thumbnails.
*/
if ( is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) {
if ( isset( $args[0] ) && is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) {
$args[0] = array_unique( array_merge( $_wp_theme_features['post-thumbnails'][0], $args[0] ) );
}
break;
case 'post-formats':
if ( is_array( $args[0] ) ) {
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
$post_formats = get_post_format_slugs();
unset( $post_formats['standard'] );
@@ -2391,7 +2391,7 @@ function add_theme_support( $feature, ...$args ) {
if ( empty( $args[0] ) ) {
// Build an array of types for back-compat.
$args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
} elseif ( ! is_array( $args[0] ) ) {
} elseif ( ! isset( $args[0] ) || ! is_array( $args[0] ) ) {
_doing_it_wrong( "add_theme_support( 'html5' )", __( 'You need to pass an array of types.' ), '3.6.1' );
return false;
}
@@ -2403,7 +2403,7 @@ function add_theme_support( $feature, ...$args ) {
break;
case 'custom-logo':
if ( ! is_array( $args ) ) {
if ( true === $args ) {
$args = array( 0 => array() );
}
$defaults = array(
@@ -2426,7 +2426,7 @@ function add_theme_support( $feature, ...$args ) {
return add_theme_support( 'custom-header', array( 'uploads' => true ) );
case 'custom-header':
if ( ! is_array( $args ) ) {
if ( true === $args ) {
$args = array( 0 => array() );
}
@@ -2516,7 +2516,7 @@ function add_theme_support( $feature, ...$args ) {
break;
case 'custom-background':
if ( ! is_array( $args ) ) {
if ( true === $args ) {
$args = array( 0 => array() );
}