-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove additional call to WP_Theme_JSON_Gutenberg::__construct
#61262
Remove additional call to WP_Theme_JSON_Gutenberg::__construct
#61262
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
WP_Theme_JSON_Gutenberg::__construct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See related feedback in the original wordpress-develop PR WordPress/wordpress-develop#6271
$config = $theme_json->get_data(); | ||
return new WP_Theme_JSON_Gutenberg( $config, 'custom' ); | ||
|
||
return $theme_json->get_theme_json(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit below, there's another WP_Theme_JSON_Data_Gutenberg
call but we cannot update it as we do on this one. That code is different than the core code and we need to consolidate both. That's a follow-up PR that shouldn't prevent this one from landing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can absorb $config['isGlobalStylesUserThemeJSON'] = true;
as part of WP_Theme_JSON_Data_Gutenberg
. We may want to still check that's true before returning to be extra-safe (line 553) but we wouldn't need a second transformation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oandregal I observed it but presumed that GB and Core might be doing things differently here. I'll look at how to incorporate that in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $config['isGlobalStylesUserThemeJSON']
is required for migrations that don't need to run for the custom origin in WP_Theme_JSON_Schema::migrate
(called on new WP_Theme_JSON()
). If the origin could be passed to migrate
in some other way, then it would be fine.
gutenberg/lib/class-wp-theme-json-schema-gutenberg.php
Lines 115 to 124 in cc2fcbe
/* | |
* Remaining changes do not need to be applied to the custom origin, | |
* as they should take on the value of the theme origin. | |
*/ | |
if ( | |
isset( $new['isGlobalStylesUserThemeJSON'] ) && | |
true === $new['isGlobalStylesUserThemeJSON'] | |
) { | |
return $new; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a draft PR to explain what I'm talking about #62305
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ajlende! I'll try to review this later this week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved #62305 which improves the API and should bring back this change. Thanks for the follow-up, Alex!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. I think looking at the isGlobalStylesUserThemeJSON
question can be resolved in a follow-up PR.
$config = $theme_json->get_data(); | ||
return new WP_Theme_JSON_Gutenberg( $config, 'custom' ); | ||
|
||
return $theme_json->get_theme_json(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oandregal I don't have permissions to merge this PR but am planning to commit the related Core PR this week. Can you help us get this one shipped in a GB release as well? |
Thanks @adamsilverstein! |
This change was committed to WP trunk in 58185. |
Sorry I wasn't around to help with this the past week (I was AFK) — happy I wasn't a blocker and you were able to fix it! |
What?
Introduce
WP_Theme_JSON_Data_Gutenberg::get_theme_json()
to avoid the cyclic call toWP_Theme_JSON_Gutenberg::__construct
.Trac ticket: Trac 61112
Why?
Doing similar changes in core, we got a consistent ~2.5% improvement by reducing 8 calls to the constructor reference core pr.
How?
WP_Theme_JSON_Data_Gutenberg
internally has atheme_json
private attribute which is an instance ofWP_Theme_JSON_Gutenberg
. At the moment we try to form the raw JSON data from theWP_Theme_JSON_Gutenberg
object and then again from the Object from the raw JSON data, which leads to regression. In this PR we use the existingWP_Theme_JSON_Gutenberg
object available toWP_Theme_JSON_Data_Gutenberg
instead of the cyclic way.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast