WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/15/2019 06:24:08 AM (19 months ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r45628 r45639  
    23722372             * for post thumbnails.
    23732373             */
    2374             if ( is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) {
     2374            if ( isset( $args[0] ) && is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) {
    23752375                $args[0] = array_unique( array_merge( $_wp_theme_features['post-thumbnails'][0], $args[0] ) );
    23762376            }
     
    23792379
    23802380        case 'post-formats':
    2381             if ( is_array( $args[0] ) ) {
     2381            if ( isset( $args[0] ) && is_array( $args[0] ) ) {
    23822382                $post_formats = get_post_format_slugs();
    23832383                unset( $post_formats['standard'] );
     
    23922392                // Build an array of types for back-compat.
    23932393                $args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
    2394             } elseif ( ! is_array( $args[0] ) ) {
     2394            } elseif ( ! isset( $args[0] ) || ! is_array( $args[0] ) ) {
    23952395                _doing_it_wrong( "add_theme_support( 'html5' )", __( 'You need to pass an array of types.' ), '3.6.1' );
    23962396                return false;
     
    24042404
    24052405        case 'custom-logo':
    2406             if ( ! is_array( $args ) ) {
     2406            if ( true === $args ) {
    24072407                $args = array( 0 => array() );
    24082408            }
     
    24272427
    24282428        case 'custom-header':
    2429             if ( ! is_array( $args ) ) {
     2429            if ( true === $args ) {
    24302430                $args = array( 0 => array() );
    24312431            }
     
    25172517
    25182518        case 'custom-background':
    2519             if ( ! is_array( $args ) ) {
     2519            if ( true === $args ) {
    25202520                $args = array( 0 => array() );
    25212521            }
Note: See TracChangeset for help on using the changeset viewer.