Opened 2 years ago
Last modified 2 years ago
#55586 new defect (bug)
`get_block_wrapper_attributes` generates PHP notices.
Reported by: | jmichaelward | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.6 |
Component: | Editor | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
To replicate this issue:
- Set both
WP_DEBUG
andWP_DEBUG_LOG
in wp-config.php totrue
so that errors will be logged towp-content/debug.log
. - Using WP-CLI, run
wp shell
. - Call
get_block_wrapper_attributes();
in the terminal. - Note the errors and call stack output in
wp-content/debug.log
. It will look something like this:
[18-Apr-2022 16:05:27 UTC] PHP Notice: Trying to access array offset on value of type null in wp-includes/class-wp-block-supports.php on line 94
[18-Apr-2022 16:05:27 UTC] PHP Notice: Trying to access array offset on value of type null in wp-includes/class-wp-block-supports.php on line 96
get_block_wrapper_attributes()
makes a singleton call to retrieve the WP_Block_Supports
object, which in turn calls apply_block_supports
on that object. The apply_block_supports
method presumes that there is an editor block already assigned to the object, and attempts to retrieve the block type by using the blockName
set on in the array of the $block_to_render
property. Since the default value on the WP_Block_Supports
object is null
, this generates the error.
It seems that the easiest solution here is to return an empty array from apply_block_supports
if $block_to_render
is not set. Since get_block_wrapper_attributes
is a public function that does not accept a block, it can be called outside of a sequence where WP_Block_Supports
might already have set properties on the object.
Hi @jmichaelward, thanks for opening this ticket!
I can confirm that this issue occurs going back to WordPress 5.6 when
get_block_wrapper_attributes()
was introduced.Adding
dev-feedback
to get other opinions on the path forward.