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

Duotone: Allow users to specify custom filters #38416

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/compat/wordpress-6.0/get-global-styles-and-settings.php
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() {
Copy link
Member

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 the lib/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 existing wp_get_global_styles_svg_filters to a lib/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.

Copy link
Member

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.

Copy link
Contributor Author

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 ?

Copy link
Member

@oandregal oandregal Feb 2, 2022

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:

  • they should be labeled with "Backport to WP minor"
  • they go in the folder of the major version, in this case, 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 the compat 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.

// 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;
}
}
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function gutenberg_is_experiment_enabled( $name ) {
}

require __DIR__ . '/compat.php';
require __DIR__ . '/compat/wordpress-6.0/get-global-styles-and-settings.php';
require __DIR__ . '/compat/wordpress-5.9/widget-render-api-endpoint/index.php';
require __DIR__ . '/compat/wordpress-5.9/blocks.php';
require __DIR__ . '/compat/wordpress-5.9/block-patterns.php';
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/tag-cloud/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"default": false
}
},
"styles": [
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "outline", "label": "Outline" }
],
"supports": {
"html": false,
"align": true
Expand Down
9 changes: 0 additions & 9 deletions packages/block-library/src/tag-cloud/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,5 @@ function register_block_core_tag_cloud() {
'render_callback' => 'render_block_core_tag_cloud',
)
);

register_block_style(
'core/tag-cloud',
array(
'name' => 'outline',
'label' => __( 'Outline', 'gutenberg' ),
'style_handle' => 'outline',
)
);
}
add_action( 'init', 'register_block_core_tag_cloud' );