[wp-trac] [WordPress Trac] #55586: `get_block_wrapper_attributes` generates PHP notices.
WordPress Trac
noreply at wordpress.org
Mon Apr 18 16:12:37 UTC 2022
#55586: `get_block_wrapper_attributes` generates PHP notices.
--------------------------+-----------------------------
Reporter: jmichaelward | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55586>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list