PluginProbe
Gutenberg / 17.0.2
Gutenberg v17.0.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | lib/class-wp-duotone-gutenberg.php +82 -190 23.7.0 → 17.0.2 View file →
@@ -31,8 +31,12 @@
31 31 * @package gutenberg
32 32 * @since 6.3.0
33 33 */
34 34
35 +if ( class_exists( 'WP_Duotone_Gutenberg' ) ) {
36 + return;
37 +}
38 +
35 39 /**
36 40 * Manages duotone block supports and global styles.
37 41 *
38 42 * @access public
@@ -47,11 +51,11 @@
47 51 * 'core/featured-image' => 'blue-orange',
48 52 * …
49 53 * ]
50 54 *
51 - * @var ?array<string, string>
55 + * @var array
52 56 */
53 - private static $global_styles_block_names;
57 + private static $global_styles_block_names = array();
54 58
55 59 /**
56 60 * An array of duotone filter data from global, theme, and custom presets.
57 61 *
@@ -67,11 +71,11 @@
67 71 * ],
68 72 * …
69 73 * ]
70 74 *
71 - * @var ?array<string, array<string, string|string[]>>
75 + * @var array
72 76 */
73 - private static $global_styles_presets;
77 + private static $global_styles_presets = array();
74 78
75 79 /**
76 80 * All of the duotone filter data from presets for CSS custom properties on
77 81 * the page.
@@ -131,9 +135,9 @@
131 135 /**
132 136 * Direct port of colord's clamp function. Using min/max instead of
133 137 * nested ternaries.
134 138 *
135 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L23
139 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L23
136 140 *
137 141 * @param float $number The number to clamp.
138 142 * @param float $min The minimum value.
139 143 * @param float $max The maximum value.
@@ -145,9 +149,9 @@
145 149
146 150 /**
147 151 * Direct port of colord's clampHue function.
148 152 *
149 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L32
153 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L32
150 154 *
151 155 * @param float $degrees The hue to clamp.
152 156 * @return float The clamped hue.
153 157 */
@@ -158,9 +162,9 @@
158 162
159 163 /**
160 164 * Direct port of colord's parseHue function.
161 165 *
162 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L40
166 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L40
163 167 *
164 168 * @param float $value The hue value to parse.
165 169 * @param string $unit The unit of the hue value.
166 170 * @return float The parsed hue value.
@@ -182,9 +186,9 @@
182 186
183 187 /**
184 188 * Direct port of colord's parseHex function.
185 189 *
186 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hex.ts#L8
190 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hex.ts#L8
187 191 *
188 192 * @param string $hex The hex string to parse.
189 193 * @return array|null An array of RGBA values or null if the hex string is invalid.
190 194 */
@@ -224,9 +228,9 @@
224 228
225 229 /**
226 230 * Direct port of colord's clampRgba function.
227 231 *
228 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/rgb.ts#L5
232 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/rgb.ts#L5
229 233 *
230 234 * @param array $rgba The RGBA array to clamp.
231 235 * @return array The clamped RGBA array.
232 236 */
@@ -241,9 +245,9 @@
241 245
242 246 /**
243 247 * Direct port of colord's parseRgbaString function.
244 248 *
245 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/rgbString.ts#L18
249 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/rgbString.ts#L18
246 250 *
247 251 * @param string $input The RGBA string to parse.
248 252 * @return array|null An array of RGBA values or null if the RGB string is invalid.
249 253 */
@@ -292,9 +296,9 @@
292 296
293 297 /**
294 298 * Direct port of colord's clampHsla function.
295 299 *
296 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L6
300 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L6
297 301 *
298 302 * @param array $hsla The HSLA array to clamp.
299 303 * @return array The clamped HSLA array.
300 304 */
@@ -309,9 +313,9 @@
309 313
310 314 /**
311 315 * Direct port of colord's hsvaToRgba function.
312 316 *
313 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsv.ts#L52
317 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsv.ts#L52
314 318 *
315 319 * @param array $hsva The HSVA array to convert.
316 320 * @return array The RGBA array.
317 321 */
@@ -337,9 +341,9 @@
337 341
338 342 /**
339 343 * Direct port of colord's hslaToHsva function.
340 344 *
341 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L33
345 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L33
342 346 *
343 347 * @param array $hsla The HSLA array to convert.
344 348 * @return array The HSVA array.
345 349 */
@@ -361,9 +365,9 @@
361 365
362 366 /**
363 367 * Direct port of colord's hslaToRgba function.
364 368 *
365 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L55
369 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L55
366 370 *
367 371 * @param array $hsla The HSLA array to convert.
368 372 * @return array The RGBA array.
369 373 */
@@ -373,9 +377,9 @@
373 377
374 378 /**
375 379 * Direct port of colord's parseHslaString function.
376 380 *
377 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hslString.ts#L17
381 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hslString.ts#L17
378 382 *
379 383 * @param string $input The HSLA string to parse.
380 384 * @return array|null An array of RGBA values or null if the RGB string is invalid.
381 385 */
@@ -423,9 +427,9 @@
423 427 /**
424 428 * Direct port of colord's parse function simplified for our use case. This
425 429 * version only supports string parsing and only returns RGBA values.
426 430 *
427 - * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/parse.ts#L37
431 + * @see https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/parse.ts#L37
428 432 *
429 433 * @param string $input The string to parse.
430 434 * @return array|null An array of RGBA values or null if the string is invalid.
431 435 */
@@ -447,16 +451,12 @@
447 451 * Take the inline CSS duotone variable from a block and return the slug. Handles styles slugs like:
448 452 * var:preset|duotone|blue-orange
449 453 * var(--wp--preset--duotone--blue-orange)
450 454 *
451 - * @param string|string[] $duotone_attr The duotone attribute from a block.
452 - * @return string The slug of the duotone preset or an empty string if no slug is found (including when an array was passed).
455 + * @param string $duotone_attr The duotone attribute from a block.
456 + * @return string The slug of the duotone preset or an empty string if no slug is found.
453 457 */
454 458 private static function get_slug_from_attribute( $duotone_attr ) {
455 - if ( ! is_string( $duotone_attr ) ) {
456 - return '';
457 - }
458 -
459 459 // Uses Branch Reset Groups `(?|…)` to return one capture group.
460 460 preg_match( '/(?|var:preset\|duotone\|(\S+)|var\(--wp--preset--duotone--(\S+)\))/', $duotone_attr, $matches );
461 461
462 462 return ! empty( $matches[1] ) ? $matches[1] : '';
@@ -464,20 +464,16 @@
464 464
465 465 /**
466 466 * Check if we have a valid duotone preset.
467 467 *
468 - * @param string|string[] $duotone_attr The duotone attribute from a block.
468 + * @param string $duotone_attr The duotone attribute from a block.
469 469 * @return bool True if the duotone preset present and valid.
470 470 */
471 471 private static function is_preset( $duotone_attr ) {
472 - if ( ! is_string( $duotone_attr ) ) {
473 - return false;
474 - }
475 -
476 472 $slug = self::get_slug_from_attribute( $duotone_attr );
477 473 $filter_id = self::get_filter_id( $slug );
478 474
479 - return array_key_exists( $filter_id, self::get_all_global_styles_presets() );
475 + return array_key_exists( $filter_id, self::$global_styles_presets );
480 476 }
481 477
482 478 /**
483 479 * Get the CSS variable name for a duotone preset.
@@ -630,9 +626,9 @@
630 626 * @param array $sources The duotone presets.
631 627 * @return string The CSS for global styles.
632 628 */
633 629 private static function get_global_styles_presets( $sources ) {
634 - $css = WP_Theme_JSON_Gutenberg::ROOT_CSS_PROPERTIES_SELECTOR . '{';
630 + $css = 'body{';
635 631 foreach ( $sources as $filter_id => $filter_data ) {
636 632 $slug = $filter_data['slug'];
637 633 $colors = $filter_data['colors'];
638 634 $css_property_name = self::get_css_custom_property_name( $slug );
@@ -645,43 +641,39 @@
645 641
646 642 /**
647 643 * Get the CSS selector for a block type.
648 644 *
649 - * @param WP_Block_Type $block_type Block type to check for support.
645 + * @param string $block_name The block name.
650 646 *
651 - * @return string|null The CSS selector. Null if there is no support or the $block_type is not a WP_Block_Type.
647 + * @return string The CSS selector or null if there is no support.
652 648 */
653 - private static function get_selector( $block_type ) {
654 - if ( ! ( $block_type instanceof WP_Block_Type ) ) {
655 - return null;
656 - }
649 + private static function get_selector( $block_name ) {
650 + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
657 651
658 - /*
659 - * Backward compatibility with `supports.color.__experimentalDuotone`
660 - * is provided via the `block_type_metadata_settings` filter. If
661 - * `supports.filter.duotone` has not been set and the experimental
662 - * property has been, the experimental property value is copied into
663 - * `supports.filter.duotone`.
664 - */
665 - $duotone_support = block_has_support( $block_type, array( 'filter', 'duotone' ) );
666 - if ( ! $duotone_support ) {
667 - return null;
668 - }
652 + if ( $block_type && $block_type instanceof WP_Block_Type ) {
653 + // Backwards compatibility with `supports.color.__experimentalDuotone`
654 + // is provided via the `block_type_metadata_settings` filter. If
655 + // `supports.filter.duotone` has not been set and the experimental
656 + // property has been, the experimental property value is copied into
657 + // `supports.filter.duotone`.
658 + $duotone_support = $block_type->supports['filter']['duotone'] ?? false;
659 + if ( ! $duotone_support ) {
660 + return null;
661 + }
669 662
670 - /*
671 - * If the experimental duotone support was set, that value is to be
672 - * treated as a selector and requires scoping.
673 - */
674 - $experimental_duotone = $block_type->supports['color']['__experimentalDuotone'] ?? false;
675 - if ( $experimental_duotone ) {
676 - $root_selector = wp_get_block_css_selector( $block_type );
677 - return is_string( $experimental_duotone )
678 - ? WP_Theme_JSON::scope_selector( $root_selector, $experimental_duotone )
679 - : $root_selector;
663 + // If the experimental duotone support was set, that value is to be
664 + // treated as a selector and requires scoping.
665 + $experimental_duotone = $block_type->supports['color']['__experimentalDuotone'] ?? false;
666 + if ( $experimental_duotone ) {
667 + $root_selector = wp_get_block_css_selector( $block_type );
668 + return is_string( $experimental_duotone )
669 + ? WP_Theme_JSON_Gutenberg::scope_selector( $root_selector, $experimental_duotone )
670 + : $root_selector;
671 + }
672 +
673 + // Regular filter.duotone support uses filter.duotone selectors with fallbacks.
674 + return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
680 675 }
681 -
682 - // Regular filter.duotone support uses filter.duotone selectors with fallbacks.
683 - return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
684 676 }
685 677
686 678 /**
687 679 * Enqueue a block CSS declaration for the page.
@@ -732,10 +724,9 @@
732 724 * @param string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
733 725 * @param string $filter_value The filter CSS value. e.g. 'url(#wp-duotone-blue-orange)' or 'unset'.
734 726 */
735 727 private static function enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value ) {
736 - $global_styles_presets = self::get_all_global_styles_presets();
737 - if ( ! array_key_exists( $filter_id, $global_styles_presets ) ) {
728 + if ( ! array_key_exists( $filter_id, self::$global_styles_presets ) ) {
738 729 $error_message = sprintf(
739 730 /* translators: %s: duotone filter ID */
740 731 __( 'The duotone id "%s" is not registered in theme.json settings', 'gutenberg' ),
741 732 $filter_id
@@ -742,10 +733,10 @@
742 733 );
743 734 _doing_it_wrong( __METHOD__, $error_message, '6.3.0' );
744 735 return;
745 736 }
746 - self::$used_global_styles_presets[ $filter_id ] = $global_styles_presets[ $filter_id ];
747 - self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $global_styles_presets[ $filter_id ] );
737 + self::$used_global_styles_presets[ $filter_id ] = self::$global_styles_presets[ $filter_id ];
738 + self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, self::$global_styles_presets[ $filter_id ] );
748 739 }
749 740
750 741 /**
751 742 * Registers the style and colors block attributes for block types that support it.
@@ -754,11 +745,16 @@
754 745 *
755 746 * @param WP_Block_Type $block_type Block Type.
756 747 */
757 748 public static function register_duotone_support( $block_type ) {
758 - // Previous `color.__experimentalDuotone` support flag is migrated
759 - // to `filter.duotone` via `block_type_metadata_settings` filter.
760 - if ( block_has_support( $block_type, array( 'filter', 'duotone' ), null ) ) {
749 + $has_duotone_support = false;
750 + if ( $block_type instanceof WP_Block_Type ) {
751 + // Previous `color.__experimentalDuotone` support flag is migrated
752 + // to `filter.duotone` via `block_type_metadata_settings` filter.
753 + $has_duotone_support = $block_type->supports['filter']['duotone'] ?? null;
754 + }
755 +
756 + if ( $has_duotone_support ) {
761 757 if ( ! $block_type->attributes ) {
762 758 $block_type->attributes = array();
763 759 }
764 760
@@ -774,21 +770,14 @@
774 770 * Get all possible duotone presets from global and theme styles and store as slug => [ colors array ]
775 771 * We only want to process this one time. On block render we'll access and output only the needed presets for that page.
776 772 *
777 773 * @since 6.3.0
778 - *
779 - * @return array<string, array<string, string|string[]>> An array of global styles presets, keyed on the filter ID.
780 774 */
781 - private static function get_all_global_styles_presets() {
782 - if ( isset( self::$global_styles_presets ) ) {
783 - return self::$global_styles_presets;
784 - }
785 -
775 + public static function set_global_styles_presets() {
786 776 // Get the per block settings from the theme.json.
787 777 $tree = gutenberg_get_global_settings();
788 778 $presets_by_origin = $tree['color']['duotone'] ?? array();
789 779
790 - self::$global_styles_presets = array();
791 780 foreach ( $presets_by_origin as $presets ) {
792 781 foreach ( $presets as $preset ) {
793 782 $filter_id = self::get_filter_id( _wp_to_kebab_case( $preset['slug'] ) );
794 783
@@ -794,44 +783,21 @@
794 783
795 784 self::$global_styles_presets[ $filter_id ] = $preset;
796 785 }
797 786 }
798 -
799 - return self::$global_styles_presets;
800 787 }
801 788
802 789 /**
803 - * Ensure all possible duotone presets are ready.
804 - * This function is deprecated, as it's no longer necessary to handle this manually.
805 - * It is kept to ensure external users of this method don't break.
806 - *
807 - * @since 6.3.0
808 - * @deprecated
809 - */
810 - public static function set_global_styles_presets() {
811 - _deprecated_function( __METHOD__, 'Gutenberg 22.5.0' );
812 - self::get_all_global_styles_presets();
813 - }
814 -
815 - /**
816 790 * Scrape all block names from global styles and store in self::$global_styles_block_names
817 791 *
818 792 * @since 6.3.0
819 - *
820 - * @return null|array<string, string> An array of global style block slugs, keyed on the block name.
821 793 */
822 - private static function get_all_global_style_block_names() {
823 - if ( isset( self::$global_styles_block_names ) ) {
824 - return self::$global_styles_block_names;
825 - }
826 -
794 + public static function set_global_style_block_names() {
827 795 // Get the per block settings from the theme.json.
828 796 $tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data();
829 797 $block_nodes = $tree->get_styles_block_nodes();
830 798 $theme_json = $tree->get_raw_data();
831 799
832 - self::$global_styles_block_names = array();
833 -
834 800 foreach ( $block_nodes as $block_node ) {
835 801 // This block definition doesn't include any duotone settings. Skip it.
836 802 if ( empty( $block_node['duotone'] ) ) {
837 803 continue;
@@ -844,13 +810,8 @@
844 810 if ( empty( $duotone_attr ) ) {
845 811 continue;
846 812 }
847 813 // If it has a duotone filter preset, save the block name and the preset slug.
848 - // Only process if it's a string (preset reference), not an array (custom colors).
849 - if ( ! is_string( $duotone_attr ) ) {
850 - continue;
851 - }
852 -
853 814 $slug = self::get_slug_from_attribute( $duotone_attr );
854 815
855 816 if ( $slug && $slug !== $duotone_attr ) {
856 817 self::$global_styles_block_names[ $block_node['name'] ] = $slug;
@@ -855,52 +816,30 @@
855 816 if ( $slug && $slug !== $duotone_attr ) {
856 817 self::$global_styles_block_names[ $block_node['name'] ] = $slug;
857 818 }
858 819 }
859 -
860 - return self::$global_styles_block_names;
861 820 }
862 821
863 822 /**
864 - * Ensure all possible global style block names are ready.
865 - * This function is deprecated, as it's no longer necessary to handle this manually.
866 - * It is kept to ensure external users of this method don't break.
867 - *
868 - * @since 6.3.0
869 - * @deprecated
870 - */
871 - public static function set_global_style_block_names() {
872 - _deprecated_function( __METHOD__, 'Gutenberg 22.5.0' );
873 - self::get_all_global_style_block_names();
874 - }
875 -
876 - /**
877 823 * Render out the duotone CSS styles and SVG.
878 824 *
879 825 * @since 6.3.0
880 826 *
881 - * @param string $block_content Rendered block content.
882 - * @param array $block Block object.
883 - * @param WP_Block $wp_block The block instance.
884 - * @return string Filtered block content.
827 + * @param string $block_content Rendered block content.
828 + * @param array $block Block object.
829 + * @return string Filtered block content.
885 830 */
886 - public static function render_duotone_support( $block_content, $block, $wp_block ) {
887 - if ( ! $block['blockName'] ) {
888 - return $block_content;
889 - }
890 - $duotone_selector = self::get_selector( $wp_block->block_type );
831 + public static function render_duotone_support( $block_content, $block ) {
832 + $duotone_selector = self::get_selector( $block['blockName'] );
891 833
892 - if ( ! $duotone_selector ) {
893 - return $block_content;
894 - }
895 -
896 - $global_styles_block_names = self::get_all_global_style_block_names();
897 -
898 834 // The block should have a duotone attribute or have duotone defined in its theme.json to be processed.
899 835 $has_duotone_attribute = isset( $block['attrs']['style']['color']['duotone'] );
900 - $has_global_styles_duotone = array_key_exists( $block['blockName'], $global_styles_block_names );
836 + $has_global_styles_duotone = array_key_exists( $block['blockName'], self::$global_styles_block_names );
901 837
902 - if ( ! $has_duotone_attribute && ! $has_global_styles_duotone ) {
838 + if (
839 + ! $duotone_selector ||
840 + ( ! $has_duotone_attribute && ! $has_global_styles_duotone )
841 + ) {
903 842 return $block_content;
904 843 }
905 844
906 845 // Generate the pieces needed for rendering a duotone to the page.
@@ -943,9 +882,9 @@
943 882 // SVG filter and block CSS.
944 883 self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data );
945 884 }
946 885 } elseif ( $has_global_styles_duotone ) {
947 - $slug = $global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'.
886 + $slug = self::$global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'.
948 887 $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'.
949 888 $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'.
950 889
951 890 // CSS custom property, SVG filter, and block CSS.
@@ -953,9 +892,9 @@
953 892 }
954 893
955 894 // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper.
956 895 $tags = new WP_HTML_Tag_Processor( $block_content );
957 - if ( $tags->next_tag() && isset( $filter_id ) ) {
896 + if ( $tags->next_tag() ) {
958 897 $tags->add_class( $filter_id );
959 898 }
960 899
961 900 return $tags->get_updated_html();
@@ -961,46 +900,8 @@
961 900 return $tags->get_updated_html();
962 901 }
963 902
964 903 /**
965 - * Fixes the issue with our generated class name not being added to the block's outer container
966 - * in classic themes due to gutenberg_restore_image_outer_container from layout block supports.
967 - *
968 - * @since 6.5.0
969 - *
970 - * @param string $block_content Rendered block content.
971 - * @return string Filtered block content.
972 - */
973 - public static function restore_image_outer_container( $block_content ) {
974 - if ( wp_theme_has_theme_json() ) {
975 - return $block_content;
976 - }
977 -
978 - $tags = new WP_HTML_Tag_Processor( $block_content );
979 - $wrapper_query = array(
980 - 'tag_name' => 'div',
981 - 'class_name' => 'wp-block-image',
982 - );
983 - if ( ! $tags->next_tag( $wrapper_query ) ) {
984 - return $block_content;
985 - }
986 -
987 - $tags->set_bookmark( 'wrapper-div' );
988 - $tags->next_tag();
989 -
990 - foreach ( $tags->class_list() as $classname ) {
991 - if ( str_starts_with( $classname, 'wp-duotone' ) ) {
992 - $tags->remove_class( $classname );
993 - $tags->seek( 'wrapper-div' );
994 - $tags->add_class( $classname );
995 - break;
996 - }
997 - }
998 -
999 - return $tags->get_updated_html();
1000 - }
1001 -
1002 - /**
1003 904 * Appends the used block duotone filter declarations to the inline block supports CSS.
1004 905 *
1005 906 * @since 6.3.0
1006 907 */
@@ -1036,19 +937,11 @@
1036 937 if ( ! empty( self::$used_svg_filter_data ) ) {
1037 938 echo self::get_svg_definitions( self::$used_svg_filter_data );
1038 939 }
1039 940
1040 - // In block themes, the CSS is added in the head via wp_add_inline_style in the wp_enqueue_scripts action.
1041 - if ( ! wp_is_block_theme() ) {
1042 - $style_tag_id = 'core-block-supports-duotone';
1043 - wp_register_style( $style_tag_id, false );
1044 - if ( ! empty( self::$used_global_styles_presets ) ) {
1045 - wp_add_inline_style( $style_tag_id, self::get_global_styles_presets( self::$used_global_styles_presets ) );
1046 - }
1047 - if ( ! empty( self::$block_css_declarations ) ) {
1048 - wp_add_inline_style( $style_tag_id, gutenberg_style_engine_get_stylesheet_from_css_rules( self::$block_css_declarations ) );
1049 - }
1050 - wp_enqueue_style( $style_tag_id );
941 + // This is for classic themes - in block themes, the CSS is added in the head via wp_add_inline_style in the wp_enqueue_scripts action.
942 + if ( ! wp_is_block_theme() && ! empty( self::$used_global_styles_presets ) ) {
943 + wp_add_inline_style( 'core-block-supports', self::get_global_styles_presets( self::$used_global_styles_presets ) );
1051 944 }
1052 945 }
1053 946
1054 947 /**
@@ -1061,10 +954,9 @@
1061 954 * @param array $settings The block editor settings from the `block_editor_settings_all` filter.
1062 955 * @return array The editor settings with duotone SVGs and CSS custom properties.
1063 956 */
1064 957 public static function add_editor_settings( $settings ) {
1065 - $global_styles_presets = self::get_all_global_styles_presets();
1066 - if ( ! empty( $global_styles_presets ) ) {
958 + if ( ! empty( self::$global_styles_presets ) ) {
1067 959 if ( ! isset( $settings['styles'] ) ) {
1068 960 $settings['styles'] = array();
1069 961 }
1070 962
@@ -1069,9 +961,9 @@
1069 961 }
1070 962
1071 963 $settings['styles'][] = array(
1072 964 // For the editor we can add all of the presets by default.
1073 - 'assets' => self::get_svg_definitions( $global_styles_presets ),
965 + 'assets' => self::get_svg_definitions( self::$global_styles_presets ),
1074 966 // The 'svgs' type is new in 6.3 and requires the corresponding JS changes in the EditorStyles component to work.
1075 967 '__unstableType' => 'svgs',
1076 968 // These styles not generated by global styles, so this must be false or they will be stripped out in gutenberg_get_block_editor_settings.
1077 969 'isGlobalStyles' => false,
@@ -1078,9 +970,9 @@
1078 970 );
1079 971
1080 972 $settings['styles'][] = array(
1081 973 // For the editor we can add all of the presets by default.
1082 - 'css' => self::get_global_styles_presets( $global_styles_presets ),
974 + 'css' => self::get_global_styles_presets( self::$global_styles_presets ),
1083 975 // This must be set and must be something other than 'theme' or they will be stripped out in the post editor <Editor> component.
1084 976 '__unstableType' => 'presets',
1085 977 // These styles are no longer generated by global styles, so this must be false or they will be stripped out in gutenberg_get_block_editor_settings.
1086 978 'isGlobalStyles' => false,