Skip to content
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

Global styles variations PHP changes #47075

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open

Conversation

ribaricplusplus
Copy link
Member

@ribaricplusplus ribaricplusplus commented Jan 11, 2023

This PR contains the PHP changes needed to add save and delete functionality for Global Styles. It's one part of the main PR: #46952

Description of changes

Terminology (thanks @oandregal)

  • user styles for the data that is merged with core, blocks, and theme styles to generate the global stylesheet (I refer to this as CUGS in this PR)
  • user style variations: for the different set of styles already preconfigured
  • associated style variation: the user style variation that is associated with user styles (my terminology addition, I refer to it as AS in this PR)

I will try to write about the changes here as the review is ongoing.

This PR adds endpoints for global styles so that they can be used with the entities functionality from @wordpress/core-data.

It is assumed that the first wp_global_styles posts that is created for a theme represents user styles (I refer to them as CUGS in this PR). Then all of the other posts represent variations that were saved later.

CUGS has an associated_user_variation meta key. Other wp_global_styles posts don't. This key represents which saved global style is associated with the CUGS (if any, let's call it AS) so that changes can be kept in sync in JavaScript code.

AS does not necessarily need to be the same as CUGS, but when changes are made in JavaScript the user will have the option to sync them up.

Changes in REST API endpoints for the global styles controller (credits @oandregal comment below)

Route Before After
global-styles/themes/<stylesheet>/variations/ READABLE. Lists the variations of the active theme. Same.
global-styles/themes/<stylesheet>/ READABLE. Lists the theme.json of the active theme. Same.
global-styles/<cpt_id>/ READABLE+EDITABLE. Lists and updates the user styles. READABLE+EDITABLE+DELETABLE. List, updates, and deletes user styles.
global-styles/ - READABLE+CREATABLE. Lists and creates user style variations.

@ribaricplusplus ribaricplusplus added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Jan 11, 2023
@github-actions
Copy link

github-actions bot commented Jan 11, 2023

Flaky tests detected in d9ed682.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3975033935
📝 Reported issues:

* @param WP_Theme $theme Theme data.
* @return array Links for the given block type.
*/
protected function prepare_links( $theme ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@ribaricplusplus ribaricplusplus Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, because the regular WP_Theme_JSON_Resolver fetches wp_global_styles posts in descending order. The new functionality assumes that the "current user global styles" are always the first wp_global_styles post that is made (per theme), so it has to be in ascending order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So. I've been educating myself about how this currently works and the changes here. Also checked the issue and original PR for context. Let me know if I should check any other things.

Would this be a fair representation of how this works?

  • The way this PR adds support for user style variations is by storing them as new wp_global_styles CPTs.
  • Before this PR, there was only a single wp_global_styles CPT per theme. We took those user styles to merge them with the others and generate the global stylesheet.
  • Now, there can be multiple wp_global_styles CPT: as many as user style variations + user styles if no style variation is selected.

Once we store everything under the same CPT, how do tell apart the "user styles" from the "user style variations"?

This PR proposes the "user styles" to be the older CPT. Can this be problematic? For example, if the post date changes in uncontrolled situations (exporting/importing the data to a different site?). I am not certain which specific example would break this, though I'd be more comfortable if we can tell apart "user styles" CPT by something explicit, that cannot change based on external factors.

Are there alternatives to using post_date? For example, what would you think of using the post_status field? Perhaps the "user styles" can have post_status=publish while the "user style variations" use the post_status=draft.

Copy link
Member Author

@ribaricplusplus ribaricplusplus Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be using the terminology established in the main comment of this issue (I made some edits). CUGS is different from custom styles by being the oldest and by having an associated_user_variation meta key. I think being the oldest is sufficient for all use cases. Even if export / import happens, the post date should be maintained. And if the export / import is done in a way that post_date is not maintained, who is to say that post_status will be?

I'm in favor of keeping complexity lower if possible. If there is ever a scenario discovered in some weird edge case that this approach fails, we could easily do something like add an option cugs_id_{$stylesheet} to wp_options that specifies which post exactly is CUGS. This would make it 100% resilient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slept on the use of post_date as an identifier for the user styles, and I'm still unconvinced it's safe. By depending on an external factor (the clock in a computer) the code is not deterministic: if the clock of any computer that creates global styles goes out of sync, this code will certainly introduce errors. At the scale of WordPress, that's bound to happen at some point, somewhere. This is a "fun" bug that happened because of clocks! That's what I want to avoid.

I'm not sure about what's the best alternative, though, so happy to explore any. This is something we need to figure it out before deploying this. It's not something we can fix after. Once there's user data in the database, it's a lot harder to fix (if at all possible).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty. How about we go for the approach to add cugs_id_{$stylesheet} to wp_options?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: terminology. I'd appreciate if we can stick to the existing nomenclature:

  • user styles for the data that is merged with core, blocks, and theme styles to generate the global stylesheet
  • user style variations: for the different set of styles already preconfigured

The WordPress styles sub-system is already a quite loaded domain and a there has been a few people working on it for a while. Changing/Updating established terminology is bound to be confusing.

Copy link
Member Author

@ribaricplusplus ribaricplusplus Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the main PR comment with these terminology definitions so things are clearer, I will use that terminology going forward but I won't edit all of my other comments.

In that case, the options key would be called user_styles_id_{$stylesheet} in the database. Should we do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty. How about we go for the approach to add cugs_id_{$stylesheet} to wp_options?

Do we have alternatives that involve extracting that information from the data we already have instead of querying/linking options? I mean, I don't think it'd be a big deal, though it'd be nice/simpler if we don't have to.

In light of this other conversation, do you think it'd be enough to use the post_name?

  • The user styles CPT would be stored as wp-global-styles-${stylesheet}.
  • The style variations CPTs would be stored as wp-global-styles-${stylesheet}-variation-${variation-identifier}.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oandregal I made this change. Now the user styles CPT is stored as wp-global-styles-${stylesheet} whereas custom style variations get a different name. Also, when user styles CPT is queried, it checks the post name, so now it no longer depends only on the post date but also on the post name.

@oandregal
Copy link
Member

oandregal commented Jan 13, 2023

Hey @ribaricplusplus Thanks for splitting your work in smaller steps :) I'm taking a look at this and educating myself about the changes here. Would you be able to provide some description of the changes done here as well as testing steps?

@ribaricplusplus
Copy link
Member Author

ribaricplusplus commented Jan 13, 2023

Hey @ribaricplusplus Thanks for splitting your work in smaller steps :) I'm taking a look at this and educating myself about the changes here. Would you be able to provide some description of the changes done here as well as testing steps?

Thank you for taking a look into this!

It's a little hard to provide testing instructions for these PHP changes. I added a few PHPUnit tests that cover some of the functionality, but there is not really a way to test the PHP changes unless you do curl requests to the REST API or something. I guess I could write how to do that, and I will definitely write a description of the changes and how things work. I will ping you when I write those.

Testing can only really be done manually in a feasible way when both PHP and JS changes are done. Then you can test the functionality by performing the actions that I showed in the screencasts of the main PR #46952.

I will try to think about how to test this PHP stuff though

@@ -16,7 +16,288 @@ class Gutenberg_REST_Global_Styles_Controller_6_2 extends WP_REST_Global_Styles_
* @return void
*/
public function register_routes() {
parent::register_routes();
register_rest_route(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in the routes:

Route Before After
global-styles/themes/<stylesheet>/variations/ READABLE. Lists the variations of the active theme. Same.
global-styles/themes/<stylesheet>/ READABLE. Lists the theme.json of the active theme. Same.
global-styles/<cpt_id>/ READABLE+EDITABLE. Lists and updates the user styles. READABLE+EDITABLE+DELETABLE. List, updates, and deletes user styles.
global-styles/ - READABLE+CREATABLE. Lists and creates user style variations.

return false;
}

$prev_id = get_post_meta( $current_gs_id, 'associated_user_variation', true );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the "user styles" to be linked to a "style variation" this way?

Copy link
Member Author

@ribaricplusplus ribaricplusplus Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in JS later to keep the changes that are made to custom styles in sync with the saved and associated custom style. Then when the user clicks the "Save" button in Gutenberg, they have the option to untick the checkbox that also pushes the changes to the associated style variation. If you look at the main issue comment, you will see that there are plans to add an indication that the saved style has some changes (with the little blue dot), so clearly the intent is to keep the CUGS in sync with AS, with the possibility to discard changes to AS and keep them only in CUGS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋🏻 what is AS and what is CUGS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AS = Associated User Style Variation
CUGS = Current User Global Styles

I've explained this terminology in the initial PR "comment", it's bad, we've decided to switch terminology but I don't want to edit all comments now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't want to edit all comments now.

why not? if you're convinced that it's bad one commit will stop these questions repeating 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm referring to my comments here in GitHub, if there are problems in code comments or code itself that's a different thing but I don't think that's the case, I didn't refer to CUGS / AS in code comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood 👍🏻 🙇🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace the if and the get post meta call with get_associated_user_variation_id which I see defined later?

*
* @return array
*/
public static function get_user_style_variations() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is the one used by the REST endpoint, and it returns the user style variations to be shown in the UI. I see it returns all wp_global_styles CPT: the "user styles" and the "user style variations". Should the "user styles" be listed in the "custom style variations" UI?

Copy link
Member Author

@ribaricplusplus ribaricplusplus Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only place where this method is used currently, so in that sense, no, we shouldn't return CUGS from this method. It actually causes more JS work later (which I've done) because CUGS needs to be filtered out. To be clear, because I filter it out in JS, the CUGS is not shown in the Custom Style Variations UI.

But when I was writing this method, I was thinking of it as something that might be used in general to get all user global styles, without worrying about the arguments that need to be passed to WP_Query. Perhaps it will be used by plugins or other WP core places.

I'm not sure what the right answer is here. When I first wrote this method I didn't include CUGS, later I reverted because I was like... Well, the REST endpoint to get all global styles should actually get all global styles. That's how it works for posts and other objects. So, I'm not sure. If you think I should exclude CUGS, let me know and I'll do it. But then there is an inconsistency where you can use the REST API endpoint to fetch CUGS, but if you query the endpoint to get all global styles CUGS is not included.

Maybe the method should have an $include_cugs argument, which is set to true in the REST API? But then we're adding functionality that is not currently used and we're not sure if it will ever be used.

@oandregal
Copy link
Member

Hey @ribaricplusplus this is not a small change and has some ramifications, thanks for working on it!

The overall direction sounds good to me. I've left some questions in comments, mainly for me to learn how this area works and for grabbing your thoughts on potential use cases that could be problematic.

I also want to share that I'm going to be out of work for 10 days or so, so I don't know about my availability to do reviews during that time. @youknowriad and @jorgefilipecosta should be able to provide thoughts on this topic, as they implemented this if my memory doesn't fail me. I'll resume my review when I'm back if nobody else has picked this up.

@annezazu annezazu mentioned this pull request Jan 16, 2023
57 tasks
'post_status' => 'publish',
'post_title' => $args['title'],
'post_type' => 'wp_global_styles',
'post_name' => sprintf( 'wp-global-styles-%s', urlencode( $args['stylesheet'] ) ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can posts of the same type (wp_global_styles) share the same post_name? Thinking we could use something along the lines of wp-global-styles-stylesheet-variation-urlencode(title). I presume two variations of the same theme shouldn't have the same title. We should check for that (also in the client).

@github-actions
Copy link

github-actions bot commented Jan 21, 2023

Size Change: -19.6 kB (-1%)

Total Size: 1.31 MB

Filename Size Change
build/block-editor/content-rtl.css 3.62 kB -30 B (-1%)
build/block-editor/content.css 3.62 kB -31 B (-1%)
build/block-editor/index.min.js 192 kB +1.69 kB (+1%)
build/block-editor/style-rtl.css 14.3 kB +121 B (+1%)
build/block-editor/style.css 14.3 kB +121 B (+1%)
build/block-library/blocks/video/editor-rtl.css 552 B -139 B (-20%) 🎉
build/block-library/blocks/video/editor.css 555 B -139 B (-20%) 🎉
build/block-library/editor-rtl.css 11.5 kB -111 B (-1%)
build/block-library/editor.css 11.5 kB -109 B (-1%)
build/block-library/index.min.js 199 kB +596 B (0%)
build/components/index.min.js 203 kB +101 B (0%)
build/compose/index.min.js 12.3 kB +36 B (0%)
build/core-data/index.min.js 15.9 kB -36 B (0%)
build/customize-widgets/index.min.js 11.8 kB +160 B (+1%)
build/data/index.min.js 8.06 kB +106 B (+1%)
build/edit-navigation/index.min.js 0 B -16.2 kB (removed) 🏆
build/edit-navigation/style-rtl.css 0 B -4.14 kB (removed) 🏆
build/edit-navigation/style.css 0 B -4.15 kB (removed) 🏆
build/edit-post/index.min.js 34.5 kB +143 B (0%)
build/edit-site/index.min.js 63 kB +1.43 kB (+2%)
build/edit-site/style-rtl.css 9.33 kB -59 B (-1%)
build/edit-site/style.css 9.33 kB -49 B (-1%)
build/edit-widgets/index.min.js 16.9 kB +147 B (+1%)
build/editor/index.min.js 45 kB +957 B (+2%)
build/experiments/index.min.js 905 B +35 B (+4%)
build/format-library/index.min.js 7.23 kB +35 B (0%)
build/priority-queue/index.min.js 1.52 kB -68 B (-4%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.78 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 483 B
build/block-directory/index.min.js 7.16 kB
build/block-directory/style-rtl.css 1.04 kB
build/block-directory/style.css 1.04 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 B
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 138 B
build/block-library/blocks/audio/theme.css 138 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 84 B
build/block-library/blocks/avatar/style.css 84 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 485 B
build/block-library/blocks/button/editor.css 485 B
build/block-library/blocks/button/style-rtl.css 532 B
build/block-library/blocks/button/style.css 532 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 100 B
build/block-library/blocks/categories/style.css 100 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 612 B
build/block-library/blocks/cover/editor.css 613 B
build/block-library/blocks/cover/style-rtl.css 1.57 kB
build/block-library/blocks/cover/style.css 1.56 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 138 B
build/block-library/blocks/embed/theme.css 138 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 253 B
build/block-library/blocks/file/style.css 254 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 984 B
build/block-library/blocks/gallery/editor.css 988 B
build/block-library/blocks/gallery/style-rtl.css 1.55 kB
build/block-library/blocks/gallery/style.css 1.55 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 829 B
build/block-library/blocks/image/editor.css 828 B
build/block-library/blocks/image/style-rtl.css 627 B
build/block-library/blocks/image/style.css 630 B
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/latest-comments/style-rtl.css 298 B
build/block-library/blocks/latest-comments/style.css 298 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 507 B
build/block-library/blocks/media-text/style.css 505 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 716 B
build/block-library/blocks/navigation-link/editor.css 715 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation/editor-rtl.css 2.13 kB
build/block-library/blocks/navigation/editor.css 2.14 kB
build/block-library/blocks/navigation/style-rtl.css 2.22 kB
build/block-library/blocks/navigation/style.css 2.2 kB
build/block-library/blocks/navigation/view-modal.min.js 2.81 kB
build/block-library/blocks/navigation/view.min.js 447 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 376 B
build/block-library/blocks/page-list/editor.css 376 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 501 B
build/block-library/blocks/post-comments-form/style.css 501 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 586 B
build/block-library/blocks/post-featured-image/editor.css 584 B
build/block-library/blocks/post-featured-image/style-rtl.css 318 B
build/block-library/blocks/post-featured-image/style.css 318 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 282 B
build/block-library/blocks/post-template/style.css 282 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 326 B
build/block-library/blocks/pullquote/style.css 325 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 440 B
build/block-library/blocks/query/editor.css 440 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 409 B
build/block-library/blocks/search/style.css 406 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 490 B
build/block-library/blocks/site-logo/editor.css 490 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.4 kB
build/block-library/blocks/social-links/style.css 1.39 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 651 B
build/block-library/blocks/table/style.css 650 B
build/block-library/blocks/table/theme-rtl.css 157 B
build/block-library/blocks/table/theme.css 157 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 404 B
build/block-library/blocks/template-part/editor.css 404 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/style-rtl.css 179 B
build/block-library/blocks/video/style.css 179 B
build/block-library/blocks/video/theme-rtl.css 139 B
build/block-library/blocks/video/theme.css 139 B
build/block-library/classic-rtl.css 162 B
build/block-library/classic.css 162 B
build/block-library/common-rtl.css 1.05 kB
build/block-library/common.css 1.05 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 12.4 kB
build/block-library/style.css 12.4 kB
build/block-library/theme-rtl.css 698 B
build/block-library/theme.css 703 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 50.4 kB
build/components/style-rtl.css 11.6 kB
build/components/style.css 11.7 kB
build/customize-widgets/style-rtl.css 1.41 kB
build/customize-widgets/style.css 1.41 kB
build/data-controls/index.min.js 663 B
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.71 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/style-rtl.css 7.46 kB
build/edit-post/style.css 7.45 kB
build/edit-widgets/style-rtl.css 4.49 kB
build/edit-widgets/style.css 4.49 kB
build/editor/style-rtl.css 3.68 kB
build/editor/style.css 3.67 kB
build/element/index.min.js 4.93 kB
build/escape-html/index.min.js 548 B
build/format-library/style-rtl.css 598 B
build/format-library/style.css 597 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.79 kB
build/keycodes/index.min.js 1.88 kB
build/list-reusable-blocks/index.min.js 2.14 kB
build/list-reusable-blocks/style-rtl.css 865 B
build/list-reusable-blocks/style.css 865 B
build/media-utils/index.min.js 2.99 kB
build/notices/index.min.js 977 B
build/plugins/index.min.js 1.95 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.35 kB
build/primitives/index.min.js 960 B
build/react-i18n/index.min.js 702 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.75 kB
build/reusable-blocks/index.min.js 2.27 kB
build/reusable-blocks/style-rtl.css 265 B
build/reusable-blocks/style.css 265 B
build/rich-text/index.min.js 10.8 kB
build/server-side-render/index.min.js 2.09 kB
build/shortcode/index.min.js 1.52 kB
build/style-engine/index.min.js 1.53 kB
build/token-list/index.min.js 650 B
build/url/index.min.js 3.69 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.31 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

'post_type' => $post_type_filter,
'post_status' => $post_status_filter,
'post_name' => $post_name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? There should only ever be one global style post with the taxonomy term of the stylesheet slug.

Copy link
Member Author

@ribaricplusplus ribaricplusplus Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this comment: #47075 (comment)

There should only ever be one global style post with the taxonomy term of the stylesheet slug.

Not true, the point of this PR is to make it possible to make more global styles posts (custom user variations). This PR is a split of the main PR that makes this possible #46952

Comment on lines 542 to 543
public static function generate_user_style_variation_post_name( $variation_id ) {
$stylesheet = get_stylesheet();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change $stylesheet to be param to the method and pass it in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ribaricplusplus
Copy link
Member Author

@oandregal Could you let me know if this feature is something that has been entirely abandoned or is it just on hold for now?

* present here.
*/
if ( $theme->get_stylesheet() === $args['stylesheet'] && ! wp_theme_has_theme_json() ) {
return new WP_Error( __( 'Theme does not have theme.json', 'gutenberg' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to make the erorr more helpful? Maybe "Theme does not support theme.json. User style variations only work with themes that support theme.json."

@@ -474,6 +472,120 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
return $user_cpt;
}

/**
* Saves a new user variation into the database.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Saves a new user variation into the database.
* Saves a new user style variation into the database.

* @return string Post name.
*/
public static function generate_user_style_variation_post_name( $variation_id, $stylesheet ) {
return "wp-global-styles-{$stylesheet}-variation-{$variation_id}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is generate_user_style_variation_post_name called with $variation_id as null?

*
* @since 6.2
*
* @param int|null $id ID of the associated post. Null to delete the asociation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a function that deletes the association instead of this null type for the $id argument?

}

/**
* Make an association between post $id and post containing current user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Make an association between post $id and post containing current user
* Make an association between $post_id and post containing current user

$changes->ID = $request['id'];
$post = get_post( $request['id'] );
$changes = new stdClass();
if ( ! empty( $request['id'] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was wrong here before?

}

/**
* Retrieves the global styles type' schema, conforming to JSON Schema.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Retrieves the global styles type' schema, conforming to JSON Schema.
* Retrieves the global styles type schema, conforming to JSON Schema.

'type' => 'object',
'properties' => array(
'id' => array(
'description' => __( 'ID of global styles config.', 'gutenberg' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'description' => __( 'ID of global styles config.', 'gutenberg' ),
'description' => __( 'ID of global style.', 'gutenberg' ),

'context' => array( 'view', 'edit', 'embed' ),
),
'rendered' => array(
'description' => __( 'HTML title for the post, transformed for display.', 'gutenberg' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'description' => __( 'HTML title for the post, transformed for display.', 'gutenberg' ),
'description' => __( 'Title for the global styles variation, transformed for display.', 'gutenberg' ),

<Button
variant="primary"
onClick={ handleSubmit }
className="xblock-editor-link-control__search-submit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xblock-editor-link is the x a typo?

@oandregal oandregal mentioned this pull request May 5, 2023
@geriux geriux removed their request for review February 26, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants