Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55586 new defect (bug)

`get_block_wrapper_attributes` generates PHP notices.

Reported by: jmichaelward's profile 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:

  1. Set both WP_DEBUG and WP_DEBUG_LOG in wp-config.php to true so that errors will be logged to wp-content/debug.log.
  2. Using WP-CLI, run wp shell.
  3. Call get_block_wrapper_attributes(); in the terminal.
  4. 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.

Change History (1)

#1 @costdev
2 years ago

  • Component changed from General to Editor
  • Keywords dev-feedback added
  • Version set to 5.6

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.

Note: See TracTickets for help on using tickets.