-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Description
Part of #41236.
Found in backport of adding support for editing block style variations in the global styles. See https://core.trac.wordpress.org/ticket/57583#comment:19.
It is possible to register a block type with its properties set to the wrong data type(s). For example, the WP_Block_Type::$style
is expected to be an array
, but can be registered as any other data type including a string
.
The code interacting with the WP_Block_Type
expects each property to be the correct data type. If any are not, then
- PHP
Warning
can happen in PHP 5.6 to 8.x. - Unexpected behaviors could happen.
- Can make debugging harder to find the root cause.
As a result, data type checks are being introduced within the code that interacts with WP_Block_Type
. These data type checks could be removed if the properties of WP_Block_Type
were always in the expected and documented data type.
Step-by-step reproduction instructions
- Turn on
WP_DEBUG
andWP_DEBUG_DISPLAY
inwp-config.php
:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
- Add a
mu-plugins
test file and copy/paste this gist into it https://gist.github.com/hellofromtonya/8c4176c4ea87e02424cf3bfd7b954ac0. - Refresh the web page.
- Notice the PHP Warning.
You can also var_dump()
the block type returned register_block_type()
to notice the properties are not validated.
Screenshots, screen recording, code snippet
Running the provided testing steps throws the following warning:
Warning: Invalid argument supplied for foreach() in /var/www/src/wp-includes/class-wp-theme-json.php on line 866
Note: This warning will soon be resolved with a guard being added into Core at the error line noted above. This guard can be removed if validation is added at the point of setting the property to avoid masking the problem.
Environment info
- WordPress
trunk
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes