forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Background image: add support for relative theme path URLs in top-lev…
…el theme.json styles (WordPress#61271) * This initial commit: - removes requirement for a `source` property in theme.json as the assumption is that, for now, all paths are paths to image files, whether absolute or relative - checks for existence of "host" in URL and then tries to resolve background image url using get_theme_file_uri - Adds a new public method WP_Theme_JSON_Gutenberg::resolve_theme_file_uris to allow theme devs to optionally resolve relative paths in theme.json to a theme. * For testing purposes, resolve in get_merged_data - should it be optional? That is, done in the global themes controller and wherever a stylesheet is generated? * Rollback test of imperative method in resolver * Moves resolution of file paths back to theme_json resolver * Backend resolution of theme file URIs for global styles. * Working on revisions Backend resolution of theme file URIs for global styles revisions Ensuring links are preserved when updating global styles. * So my linter is working again * Changed the relative link to `wp:theme-file-uris` Always adding path to the link object so that it can dynamically resolved. * Added some explanatory TODOs * Adding valid link attributes to the _link object. Updated tests * Added some unit tests for utils * Switching to using file: prefix, which is an established theme.json convention for relative paths to theme assets. E.g., web fonts Adding test image to empty theme Added theme JSON schema update Unit tests for JS helper Using response methods to add links to response collection * Fix linting * Remove TODO * Update tests * dump var_dump * Check for $theme_json before resolving * be explicit about the background value file:./ * Remove unnecessary empty check * Abstracting getting any resolved URI to separate hook Updating comments * Update lib/class-wp-theme-json-resolver-gutenberg.php * Update lib/class-wp-theme-json-resolver-gutenberg.php * Revert useGlobalStyle changes - no longer required given the new hook * Bad revert * Rename wp:theme-file-uris to wp:theme-file Rename utils file --------- Co-authored-by: ramonjd <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: noisysocks <[email protected]> Co-authored-by: tellthemachines <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: TimothyBJacobs <[email protected]> Co-authored-by: creativecoder <[email protected]>
- Loading branch information
1 parent
c5f68bf
commit 692ddc7
Showing
23 changed files
with
525 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 ); | ||
if ( ! empty( $resolved_theme_uris ) ) { | ||
$links['https://api.w.org/theme-file'] = $resolved_theme_uris; | ||
} | ||
$response->add_links( $links ); | ||
|
||
return $response; | ||
} | ||
} |
This file contains 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 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 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 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.