WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.3k stars 4.11k forks source link

WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_wp_global_styles() doesn't return the post that it creates. #63722

Open joemcgill opened 1 month ago

joemcgill commented 1 month ago

Description

While attempting to write a unit test to confirm that caching added to wp_add_global_styles_for_blocks() would get cleared if user data changed (as reported in https://github.com/WordPress/gutenberg/issues/63467), I noticed that when a wp_global_styles Post is created directly by the WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_wp_global_styles() method, subsequent calls to the same method would not return the post that was created:

$theme = wp_get_theme();
// First call.
WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_wp_global_styles( $theme, true );

// Second call.
WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_wp_global_styles( $theme );

I would have expected the second call to return the post that was created by the first, but instead an empty array is returned because the internal tax query causes the post to not be returned.

Is this behaving as expected?

Step-by-step reproduction instructions

I've opened https://github.com/WordPress/gutenberg/pull/63721 which adds a PHPUnit test that demonstrates the bug.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

aaronrobertshaw commented 1 month ago

I was able to replicate this issue when the current user doesn't have the capabilities to assign terms. More info in https://github.com/WordPress/gutenberg/pull/63721#pullrequestreview-2190561893