-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Duotone: Allow users to specify custom filters #38416
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
48 changes: 48 additions & 0 deletions
48
lib/compat/wordpress-6.0/get-global-styles-and-settings.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,48 @@ | ||
<?php | ||
/** | ||
* API to interact with global settings & styles. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
if ( ! function_exists( 'wp_get_global_styles_svg_filters' ) ) { | ||
/** | ||
* Returns a string containing the SVGs to be referenced as filters (duotone). | ||
* | ||
* @return string | ||
*/ | ||
function wp_get_global_styles_svg_filters() { | ||
// Return cached value if it can be used and exists. | ||
// It's cached by theme to make sure that theme switching clears the cache. | ||
$transient_name = 'gutenberg_global_styles_svg_filters_' . get_stylesheet(); | ||
$can_use_cached = ( | ||
( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && | ||
( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && | ||
( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && | ||
! is_admin() | ||
); | ||
if ( $can_use_cached ) { | ||
$cached = get_transient( $transient_name ); | ||
if ( $cached ) { | ||
return $cached; | ||
} | ||
} | ||
|
||
$supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); | ||
|
||
$origins = array( 'default', 'theme', 'user' ); | ||
if ( ! $supports_theme_json ) { | ||
$origins = array( 'default' ); | ||
} | ||
|
||
$tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(); | ||
$svgs = $tree->get_svg_filters( $origins ); | ||
|
||
if ( $can_use_cached ) { | ||
// Cache for a minute, same as gutenberg_get_global_stylesheet. | ||
set_transient( $transient_name, $svgs, MINUTE_IN_SECONDS ); | ||
} | ||
|
||
return $svgs; | ||
} | ||
} |
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
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.
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.
I see that the
wp_get_global_styles_svg_filters
is not present in WordPress 5.9 but still lives in thelib/compat/5.9
folder of Gutenberg. Apparently, #36236 didn't make the cut for 5.9 and is slated for the next minor release (it has the "backport to WP minor release" label).My understanding of how we use the
lib/compat
folder is that we should move the existingwp_get_global_styles_svg_filters
to alib/compat/5.9.1
folder. Once there, we can make the changes introduced by this PR directly, as it wasn't shipped in a WordPress version yet.cc @gziolo and @youknowriad for confirmation.
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.
I'm not sure if we need to be so much specific about the minor version because we remove code in batch for a major version line. The existing
lib/compat/5.9
directory should be fine.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.
So are you saying we didn't need to revert #38055 ?
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.
Ah, I see. For efficiency, I asked for further clarifications in private about what happens with PRs that need to go on a minor and this is what I've learned:
lib/compat/5.9
We did use a 5.8.1 folder in the past but it's not clear that was super useful.
There's the issue of what happens with code that was supposed to go in a minor but a minor didn't happen: it seems that we need to port that code to the folder of the next major (
lib/compat/6.0
in this case) at some point (I presume we do this review when we try to remove thecompat
folder, but I haven't been involved in this process, to be honest).So, the way forward to incorporate this feature would be:
Appreciate your patience here, @scruffian and @ajlende Sorry to have you go round in circles.