[Style Engine] PHP Notice: Undefined index: 'individual' #43121
Description
Description
A PHP notice "Undefined index: individual" is being thrown in WP_Style_Engine::get_css_declarations()
https://github.com/WordPress/gutenberg/blob/trunk/packages/style-engine/class-wp-style-engine.php#L418.
What is happening?
WP_Style_Engine::parse_block_styles()
invokes WP_Style_Engine::get_css_declarations()
passing the style definition of the group style from static::BLOCK_STYLE_DEFINITIONS_METADATA
. But not all 'property_keys'
contain an 'individual'
parameter, such as 'color'
.
Notice how WP_Style_Engine::get_individual_property_css_declarations()
provides guarding to ensure the key exists in the style definition before accessing it
gutenberg/packages/style-engine/class-wp-style-engine.php
Lines 464 to 466 in 22801cf
Questions:
- Should
WP_Style_Engine::parse_block_styles()
be passing all of thestatic::BLOCK_STYLE_DEFINITIONS_METADATA
toWP_Style_Engine::get_css_declarations()
for processing? - If yes, what should happen in
WP_Style_Engine::get_css_declarations()
when a style definition'sproperty_keys'
do not define the'individual'
parameter? Should it skip that$style_value
? (I assume yes.)
Step-by-step reproduction instructions
- Set
define( 'WP_DEBUG', true );
in your local environment'swp-config.php
file OR in the PHPUnit'sbootstrap.php
file. - When running locally, check the error logs. When running the PHP tests, notice the test error.
Screenshots, screen recording, code snippet
First found when turning on WP_DEBUG
for its PHPUnit tests https://github.com/WordPress/gutenberg/runs/7756878353?check_suite_focus=true
.............................E...... 477 / 477 (100%)
Time: 3.85 seconds, Memory: [46](https://github.com/WordPress/gutenberg/runs/7756878353?check_suite_focus=true#step:7:47).50MB
There was 1 error:
1) WP_Style_Engine_Test::test_generate_get_styles with data set "invalid_classnames_options" (array(array(array('friends'), array('tasty'))), array(), array())
Undefined index: individual
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:422
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:338
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:562
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/phpunit/class-wp-style-engine-test.php:37
phpvfscomposer:///var/www/html/wp-content/plugins/gutenberg/vendor/phpunit/phpunit/phpunit:[52](https://github.com/WordPress/gutenberg/runs/7756878353?check_suite_focus=true#step:7:53)
Environment info
- WordPress
trunk
- Gutenberg
trunk
- localhost: wp-env
- Plugins: only Gutenberg is activated
- Theme: TT2
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