PluginProbe
Gutenberg / 24.0.0
Gutenberg v24.0.0
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/block-supports/custom-css.php +18 -8 23.5.2 → 24.0.0 View file →
@@ -46,9 +46,9 @@
46 46 $updated_class_name = is_string( $existing_class_name )
47 47 ? "$existing_class_name $class_name"
48 48 : $class_name;
49 49
50 - _wp_array_set( $parsed_block, array( 'attrs', 'className' ), $updated_class_name );
50 + $parsed_block['attrs']['className'] = $updated_class_name;
51 51
52 52 // Process the custom CSS using the same method as global styles.
53 53 $selector = '.' . $class_name;
54 54 $processed_css = WP_Theme_JSON_Gutenberg::process_blocks_custom_css( $custom_css, $selector );
@@ -53,15 +53,25 @@
53 53 $selector = '.' . $class_name;
54 54 $processed_css = WP_Theme_JSON_Gutenberg::process_blocks_custom_css( $custom_css, $selector );
55 55
56 56 if ( ! empty( $processed_css ) ) {
57 - /*
58 - * Register and add inline style for block custom CSS.
59 - * The style depends on global-styles to ensure custom CSS loads after
60 - * and can override global styles.
57 + /**
58 + * Reuse one handle so identical custom CSS is enqueued only once via
59 + * {@see wp_unique_id_from_values()}. Explicitly declare the `wp-block-library`
60 + * dependency so `global-styles` is guaranteed to print after it, preventing
61 + * block default styles from unintentionally overriding global styles.
61 62 */
62 - wp_register_style( 'wp-block-custom-css', false, array( 'global-styles' ) );
63 - wp_add_inline_style( 'wp-block-custom-css', $processed_css );
63 + $handle = 'wp-block-custom-css';
64 + if ( ! wp_style_is( $handle, 'registered' ) ) {
65 + wp_register_style( $handle, false, array( 'wp-block-library', 'global-styles' ) );
66 + }
67 + $after_styles = wp_styles()->get_data( $handle, 'after' );
68 + if ( ! is_array( $after_styles ) ) {
69 + $after_styles = array();
70 + }
71 + if ( ! in_array( $processed_css, $after_styles, true ) ) {
72 + wp_add_inline_style( $handle, $processed_css );
73 + }
64 74 }
65 75
66 76 return $parsed_block;
67 77 }
@@ -80,9 +90,9 @@
80 90 * and stored in block attributes. This filter adds it to the actual markup.
81 91 *
82 92 * @param string $block_content Rendered block content.
83 93 * @param array $block Block object.
84 - * @return string Filtered block content.
94 + * @return string Filtered block content.
85 95 *
86 96 * @phpstan-param array{
87 97 * attrs: array{
88 98 * className?: string,