Repository navigation
Background image: add support for relative theme path URLs in top-level theme.json styles #61271
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
Merged
ramonjd
merged 25 commits into
trunk
from
add/background-images-top-level-resolved-theme-paths
May 20, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
514e7b9
This initial commit:
ramonjd fa9e75f
For testing purposes, resolve in get_merged_data - should it be optio…
ramonjd 2ba6cfd
Rollback test of imperative method in resolver
ramonjd 17048c3
Moves resolution of file paths back to theme_json resolver
ramonjd 88aac46
Backend resolution of theme file URIs for global styles.
ramonjd 4137b37
Working on revisions
ramonjd 57cd28c
So my linter is working again
ramonjd 06c2bb0
Changed the relative link to `wp:theme-file-uris`
ramonjd 3e283e0
Added some explanatory TODOs
ramonjd 1752858
Adding valid link attributes to the _link object.
ramonjd 98de1c6
Added some unit tests for utils
ramonjd 70c26ba
Switching to using file: prefix, which is an established theme.json c…
ramonjd b94a512
Fix linting
andrewserong efae7f2
Remove TODO
ramonjd eb4ab0f
Update tests
ramonjd b0fb937
dump var_dump
ramonjd 7c083bc
Check for $theme_json before resolving
ramonjd 17d51bd
be explicit about the background value file:./
ramonjd 60c8bb1
Remove unnecessary empty check
ramonjd dd07557
Abstracting getting any resolved URI to separate hook
ramonjd 26866fc
Update lib/class-wp-theme-json-resolver-gutenberg.php
noisysocks f01dcdf
Update lib/class-wp-theme-json-resolver-gutenberg.php
noisysocks 25f8754
Revert useGlobalStyle changes - no longer required given the new hook
ramonjd 7fecf34
Bad revert
ramonjd 5d3ba0b
Rename wp:theme-file-uris to wp:theme-file
ramonjd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
lib/compat/wordpress-6.6/class-gutenberg-rest-global-styles-revisions-controller-6-6.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
| /** | ||
| * REST API: Gutenberg_REST_Global_Styles_Revisions_Controller class, inspired by WP_REST_Revisions_Controller. | ||
| * | ||
| * @package WordPress | ||
| * @subpackage REST_API | ||
| * @since 6.3.0 | ||
| */ | ||
|
|
||
| /** | ||
| * Core class used to access global styles revisions via the REST API. | ||
| * | ||
| * @since 6.3.0 | ||
| * @since 6.6.0 Added custom relative theme file URIs to `_links`. | ||
| * | ||
| * @see WP_REST_Controller | ||
| */ | ||
| class Gutenberg_REST_Global_Styles_Revisions_Controller_6_6 extends Gutenberg_REST_Global_Styles_Revisions_Controller_6_5 { | ||
| /** | ||
| * Prepares the revision for the REST response. | ||
| * | ||
| * @since 6.3.0 | ||
| * @since 6.6.0 Added resolved URI links to the response. | ||
| * | ||
| * @param WP_Post $post Post revision object. | ||
| * @param WP_REST_Request $request Request object. | ||
| * @return WP_REST_Response|WP_Error Response object. | ||
| */ | ||
| public function prepare_item_for_response( $post, $request ) { | ||
| $parent = $this->get_parent( $request['parent'] ); | ||
| $global_styles_config = $this->get_decoded_global_styles_json( $post->post_content ); | ||
|
|
||
| if ( is_wp_error( $global_styles_config ) ) { | ||
| return $global_styles_config; | ||
| } | ||
|
|
||
| $fields = $this->get_fields_for_response( $request ); | ||
| $data = array(); | ||
| $theme_json = array(); | ||
|
|
||
| if ( ! empty( $global_styles_config['styles'] ) || ! empty( $global_styles_config['settings'] ) ) { | ||
| $theme_json = new WP_Theme_JSON_Gutenberg( $global_styles_config, 'custom' ); | ||
| $global_styles_config = ( $theme_json )->get_raw_data(); | ||
|
|
||
| if ( rest_is_field_included( 'settings', $fields ) ) { | ||
| $data['settings'] = ! empty( $global_styles_config['settings'] ) ? $global_styles_config['settings'] : new stdClass(); | ||
| } | ||
| if ( rest_is_field_included( 'styles', $fields ) ) { | ||
| $data['styles'] = ! empty( $global_styles_config['styles'] ) ? $global_styles_config['styles'] : new stdClass(); | ||
| } | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'author', $fields ) ) { | ||
| $data['author'] = (int) $post->post_author; | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'date', $fields ) ) { | ||
| $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date ); | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'date_gmt', $fields ) ) { | ||
| $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt ); | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'id', $fields ) ) { | ||
| $data['id'] = (int) $post->ID; | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'modified', $fields ) ) { | ||
| $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified ); | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'modified_gmt', $fields ) ) { | ||
| $data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt ); | ||
| } | ||
|
|
||
| if ( rest_is_field_included( 'parent', $fields ) ) { | ||
| $data['parent'] = (int) $parent->ID; | ||
| } | ||
|
|
||
| $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; | ||
| $data = $this->add_additional_fields_to_object( $data, $request ); | ||
| $data = $this->filter_response_by_context( $data, $context ); | ||
|
|
||
| $response = rest_ensure_response( $data ); | ||
|
|
||
| // Add resolved URIs to the response. | ||
| $links = array(); | ||
| $resolved_theme_uris = WP_Theme_JSON_Resolver_Gutenberg::get_resolved_theme_uris( $theme_json ); | ||
|
ramonjd marked this conversation as resolved.
Resolved
|
||
| if ( ! empty( $resolved_theme_uris ) ) { | ||
| $links['https://api.w.org/theme-file'] = $resolved_theme_uris; | ||
| } | ||
| $response->add_links( $links ); | ||
|
|
||
| return $response; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.