Make WordPress Core

Changeset 45639


Ignore:
Timestamp:
07/15/2019 06:24:08 AM (7 years 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.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r45494 r45639  
    50995099                                        'section'       => 'title_tagline',
    51005100                                        'priority'      => 8,
    5101                                         'height'        => $custom_logo_args[0]['height'],
    5102                                         'width'         => $custom_logo_args[0]['width'],
    5103                                         'flex_height'   => $custom_logo_args[0]['flex-height'],
    5104                                         'flex_width'    => $custom_logo_args[0]['flex-width'],
     5101                                        'height'        => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null,
     5102                                        'width'         => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null,
     5103                                        'flex_height'   => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null,
     5104                                        'flex_width'    => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null,
    51055105                                        'button_labels' => array(
    51065106                                                'select'       => __( 'Select logo' ),
  • trunk/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    r45427 r45639  
    478478        public function filter_wp_get_nav_menu_items( $items, $menu, $args ) {
    479479                $this_item                = $this->value();
    480                 $current_nav_menu_term_id = $this_item['nav_menu_term_id'];
    481                 unset( $this_item['nav_menu_term_id'] );
     480                $current_nav_menu_term_id = null;
     481                if ( isset( $this_item['nav_menu_term_id'] ) ) {
     482                        $current_nav_menu_term_id = $this_item['nav_menu_term_id'];
     483                        unset( $this_item['nav_menu_term_id'] );
     484                }
    482485
    483486                $should_filter = (
     
    494497                        false === $this_item
    495498                        ||
    496                         true === $this_item['_invalid']
     499                        ( isset( $this_item['_invalid'] ) && true === $this_item['_invalid'] )
    497500                        ||
    498501                        (
  • trunk/src/wp-includes/meta.php

    r45590 r45639  
    524524        if ( ! $meta_cache ) {
    525525                $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
    526                 $meta_cache = $meta_cache[ $object_id ];
     526                if ( isset( $meta_cache[ $object_id ] ) ) {
     527                        $meta_cache = $meta_cache[ $object_id ];
     528                } else {
     529                        $meta_cache = null;
     530                }
    527531        }
    528532
  • trunk/src/wp-includes/rest-api/class-wp-rest-request.php

    r45304 r45639  
    295295         * @since 4.4.0
    296296         *
    297          * @return array Map containing 'value' and 'parameters' keys.
     297         * @return array|null Map containing 'value' and 'parameters' keys
     298         *                    or null when no valid content-type header was
     299         *                    available.
    298300         */
    299301        public function get_content_type() {
     
    335337
    336338                $content_type = $this->get_content_type();
    337                 if ( $content_type['value'] === 'application/json' ) {
     339                if ( isset( $content_type['value'] ) && 'application/json' === $content_type['value'] ) {
    338340                        $order[] = 'JSON';
    339341                }
  • 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                        }
  • trunk/src/wp-includes/user.php

    r45590 r45639  
    20892089                        /** This filter is documented in wp-includes/pluggable.php */
    20902090                        $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false );
    2091                         $remember            = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life );
     2091                        $remember            = false;
     2092                        if ( false !== $logged_in_cookie && ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ) {
     2093                                $remember = true;
     2094                        }
    20922095
    20932096                        wp_set_auth_cookie( $ID, $remember );
  • trunk/src/wp-includes/wp-db.php

    r45635 r45639  
    31143114                                if ( ! empty( $value['db'] ) ) {
    31153115                                        // We're going to need to truncate by characters or bytes, depending on the length value we have.
    3116                                         if ( 'byte' === $value['length']['type'] ) {
     3116                                        if ( isset( $value['length']['type'] ) && 'byte' === $value['length']['type'] ) {
    31173117                                                // Using binary causes LEFT() to truncate by bytes.
    31183118                                                $charset = 'binary';
  • trunk/tests/phpunit/tests/query/generatePostdata.php

    r44941 r45639  
    2525
    2626                // Fails because there's no post with this ID.
    27                 $this->assertNotSame( $fake->ID, $data['id'] );
     27                $this->assertFalse( $data );
    2828        }
    2929
  • trunk/tests/phpunit/tests/term/termExists.php

    r43571 r45639  
    151151                _unregister_taxonomy( 'foo' );
    152152
    153                 $this->assertSame( null, $found['term_id'] );
     153                $this->assertSame( null, $found );
    154154        }
    155155
Note: See TracChangeset for help on using the changeset viewer.