Validate each arg before setting WP_Block_Type properties #48039
Labels
[Feature] Block API
API that allows to express the block paradigm.
Needs Dev
Ready for, and needs developer efforts
[Type] Bug
An existing feature does not function as intended
[Type] Code Quality
Issues or PRs that relate to code quality
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 anarray
, but can be registered as any other data type including astring
.The code interacting with the
WP_Block_Type
expects each property to be the correct data type. If any are not, thenWarning
can happen in PHP 5.6 to 8.x.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 ofWP_Block_Type
were always in the expected and documented data type.Step-by-step reproduction instructions
WP_DEBUG
andWP_DEBUG_DISPLAY
inwp-config.php
:mu-plugins
test file and copy/paste this gist into it https://gist.github.com/hellofromtonya/8c4176c4ea87e02424cf3bfd7b954ac0.You can also
var_dump()
the block type returnedregister_block_type()
to notice the properties are not validated.Screenshots, screen recording, code snippet
https://3v4l.org/9YloM
Running the provided testing steps throws the following warning:
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
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
The text was updated successfully, but these errors were encountered: