Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.
This repository was archived by the owner on Jun 14, 2022. It is now read-only.

PHP 7.4 error notices when using the grid block without relevant thumbnails #289

@nickcernis

Description

@nickcernis

Describe the bug
Under PHP 7.4 there are a couple of notices above the editor if the grid block is in use and the user has not regenerated thumbnails to create the ab-block-post-grid-landscape and ab-block-post-grid-square sizes:

[19-Dec-2019 19:43:30 UTC] PHP Notice:  Trying to access array offset on value of type bool in /Users/nick/Documents/sites/dev/wp-content/plugins/atomic-blocks/src/blocks/block-post-grid/index.php on line 464
[19-Dec-2019 19:43:30 UTC] PHP Notice:  Trying to access array offset on value of type bool in /Users/nick/Documents/sites/dev/wp-content/plugins/atomic-blocks/src/blocks/block-post-grid/index.php on line 480

The issue is that wp_get_attachment_image_src can return an array or boolean, but AB assumes an array and tries to access it here:

return $feat_img_array[0];

return $feat_img_array[0];

If $feat_img_array is false due to missing thumbnails, then using the array accessor throws the above notices because PHP 7.4 no longer allows us to treat non-arrays like an array:

This is a low-priority edge case that's hard to reproduce (I encountered it after running theme setup with Magazine Pro), but filing in case it comes up.

One fix would be to check for the array before accessing it for any returned values of type array|mixed:

if ( is_array( $feat_img_array ) ) {
	return $feat_img_array[0];
}

Version

  • develop
  • 2.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions