Skip to content

[Style Engine] PHP Notice: Undefined index: 'individual' #43121

Closed
@hellofromtonya

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

$style_definition = _wp_array_get( static::BLOCK_STYLE_DEFINITIONS_METADATA, $style_definition_path, null );
if ( $style_definition && isset( $style_definition['property_keys']['individual'] ) ) {
.

Questions:

  • Should WP_Style_Engine::parse_block_styles() be passing all of the static::BLOCK_STYLE_DEFINITIONS_METADATA to WP_Style_Engine::get_css_declarations() for processing?
  • If yes, what should happen in WP_Style_Engine::get_css_declarations() when a style definition's property_keys' do not define the 'individual' parameter? Should it skip that $style_value? (I assume yes.)

Step-by-step reproduction instructions

  1. Set define( 'WP_DEBUG', true ); in your local environment's wp-config.php file OR in the PHPUnit's bootstrap.php file.
  2. 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

Metadata

Labels

[Package] Style Engine/packages/style-engine[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions