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.



Built from https://develop.svn.wordpress.org/trunk@45639


git-svn-id: http://core.svn.wordpress.org/trunk@45450 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2019-07-15 06:25:57 +00:00
parent bd45c7d3b9
commit a571a7d621
8 changed files with 31 additions and 19 deletions

View File

@ -5098,10 +5098,10 @@ final class WP_Customize_Manager {
'label' => __( 'Logo' ), 'label' => __( 'Logo' ),
'section' => 'title_tagline', 'section' => 'title_tagline',
'priority' => 8, 'priority' => 8,
'height' => $custom_logo_args[0]['height'], 'height' => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null,
'width' => $custom_logo_args[0]['width'], 'width' => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null,
'flex_height' => $custom_logo_args[0]['flex-height'], 'flex_height' => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null,
'flex_width' => $custom_logo_args[0]['flex-width'], 'flex_width' => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null,
'button_labels' => array( 'button_labels' => array(
'select' => __( 'Select logo' ), 'select' => __( 'Select logo' ),
'change' => __( 'Change logo' ), 'change' => __( 'Change logo' ),

View File

@ -477,8 +477,11 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
*/ */
public function filter_wp_get_nav_menu_items( $items, $menu, $args ) { public function filter_wp_get_nav_menu_items( $items, $menu, $args ) {
$this_item = $this->value(); $this_item = $this->value();
$current_nav_menu_term_id = null;
if ( isset( $this_item['nav_menu_term_id'] ) ) {
$current_nav_menu_term_id = $this_item['nav_menu_term_id']; $current_nav_menu_term_id = $this_item['nav_menu_term_id'];
unset( $this_item['nav_menu_term_id'] ); unset( $this_item['nav_menu_term_id'] );
}
$should_filter = ( $should_filter = (
$menu->term_id === $this->original_nav_menu_term_id $menu->term_id === $this->original_nav_menu_term_id
@ -493,7 +496,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
$should_remove = ( $should_remove = (
false === $this_item false === $this_item
|| ||
true === $this_item['_invalid'] ( isset( $this_item['_invalid'] ) && true === $this_item['_invalid'] )
|| ||
( (
$this->original_nav_menu_term_id === $menu->term_id $this->original_nav_menu_term_id === $menu->term_id

View File

@ -523,7 +523,11 @@ function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false )
if ( ! $meta_cache ) { if ( ! $meta_cache ) {
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
if ( isset( $meta_cache[ $object_id ] ) ) {
$meta_cache = $meta_cache[ $object_id ]; $meta_cache = $meta_cache[ $object_id ];
} else {
$meta_cache = null;
}
} }
if ( ! $meta_key ) { if ( ! $meta_key ) {

View File

@ -294,7 +294,9 @@ class WP_REST_Request implements ArrayAccess {
* *
* @since 4.4.0 * @since 4.4.0
* *
* @return array Map containing 'value' and 'parameters' keys. * @return array|null Map containing 'value' and 'parameters' keys
* or null when no valid content-type header was
* available.
*/ */
public function get_content_type() { public function get_content_type() {
$value = $this->get_header( 'content-type' ); $value = $this->get_header( 'content-type' );
@ -334,7 +336,7 @@ class WP_REST_Request implements ArrayAccess {
$order = array(); $order = array();
$content_type = $this->get_content_type(); $content_type = $this->get_content_type();
if ( $content_type['value'] === 'application/json' ) { if ( isset( $content_type['value'] ) && 'application/json' === $content_type['value'] ) {
$order[] = 'JSON'; $order[] = 'JSON';
} }

View File

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

View File

@ -2088,7 +2088,10 @@ All at ###SITENAME###
$logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' ); $logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' );
/** This filter is documented in wp-includes/pluggable.php */ /** This filter is documented in wp-includes/pluggable.php */
$default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false ); $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false );
$remember = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ); $remember = false;
if ( false !== $logged_in_cookie && ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ) {
$remember = true;
}
wp_set_auth_cookie( $ID, $remember ); wp_set_auth_cookie( $ID, $remember );
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-45638'; $wp_version = '5.3-alpha-45639';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -3113,7 +3113,7 @@ class wpdb {
foreach ( $data as $col => $value ) { foreach ( $data as $col => $value ) {
if ( ! empty( $value['db'] ) ) { if ( ! empty( $value['db'] ) ) {
// We're going to need to truncate by characters or bytes, depending on the length value we have. // We're going to need to truncate by characters or bytes, depending on the length value we have.
if ( 'byte' === $value['length']['type'] ) { if ( isset( $value['length']['type'] ) && 'byte' === $value['length']['type'] ) {
// Using binary causes LEFT() to truncate by bytes. // Using binary causes LEFT() to truncate by bytes.
$charset = 'binary'; $charset = 'binary';
} else { } else {