diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index dd8bf832174e67..9973d92078df3b 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -1043,7 +1043,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' } $blocks_metadata = static::get_blocks_metadata(); - $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata ); + $style_nodes = static::get_style_nodes( $this->theme_json ); $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); $root_style_key = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $style_nodes, 'selector' ), true ); @@ -1315,7 +1315,7 @@ protected function get_layout_styles( $block_metadata ) { continue; } - $class_name = sanitize_title( _wp_array_get( $layout_definition, array( 'className' ), false ) ); + $class_name = _wp_array_get( $layout_definition, array( 'className' ), false ); $spacing_rules = _wp_array_get( $layout_definition, array( 'spacingStyles' ), array() ); if ( @@ -1372,7 +1372,7 @@ protected function get_layout_styles( $block_metadata ) { ) { $valid_display_modes = array( 'block', 'flex', 'grid' ); foreach ( $layout_definitions as $layout_definition ) { - $class_name = sanitize_title( _wp_array_get( $layout_definition, array( 'className' ), false ) ); + $class_name = _wp_array_get( $layout_definition, array( 'className' ), false ); $base_style_rules = _wp_array_get( $layout_definition, array( 'baseStyles' ), array() ); if ( @@ -1567,6 +1567,10 @@ protected static function compute_preset_classes( $settings, $selector, $origins $stylesheet = ''; foreach ( static::PRESETS_METADATA as $preset_metadata ) { + if ( empty( $preset_metadata['classes'] ) ) { + continue; + } + $slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins ); foreach ( $preset_metadata['classes'] as $class => $property ) { foreach ( $slugs as $slug ) { @@ -1766,6 +1770,10 @@ protected static function replace_slug_in_string( $input, $slug ) { protected static function compute_preset_vars( $settings, $origins ) { $declarations = array(); foreach ( static::PRESETS_METADATA as $preset_metadata ) { + if ( ! isset( $preset_metadata['css_vars'] ) ) { + continue; + } + $values_by_slug = static::get_settings_values_by_slug( $settings, $preset_metadata, $origins ); foreach ( $values_by_slug as $slug => $value ) { $declarations[] = array( @@ -2100,10 +2108,9 @@ protected static function get_setting_nodes( $theme_json, $selectors = array() ) * @since 5.8.0 * * @param array $theme_json The tree to extract style nodes from. - * @param array $selectors List of selectors per block. * @return array An array of style nodes metadata. */ - protected static function get_style_nodes( $theme_json, $selectors = array() ) { + protected static function get_style_nodes( $theme_json ) { $nodes = array(); if ( ! isset( $theme_json['styles'] ) ) { return $nodes; @@ -2142,26 +2149,7 @@ protected static function get_style_nodes( $theme_json, $selectors = array() ) { } } - // Blocks. - if ( ! isset( $theme_json['styles']['blocks'] ) ) { - return $nodes; - } - - $block_nodes = static::get_block_nodes( $theme_json, $selectors ); - foreach ( $block_nodes as $block_node ) { - $nodes[] = $block_node; - } - - /** - * Filters the list of style nodes with metadata. - * - * This allows for things like loading block CSS independently. - * - * @since 6.1.0 - * - * @param array $nodes Style nodes with metadata. - */ - return apply_filters( 'wp_theme_json_get_style_nodes', $nodes ); + return $nodes; } /** @@ -2670,8 +2658,7 @@ public function merge( $incoming ) { * @return string SVG filters. */ public function get_svg_filters( $origins ) { - $blocks_metadata = static::get_blocks_metadata(); - $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); + $setting_nodes = static::get_setting_nodes( $this->theme_json ); $filters = ''; foreach ( $setting_nodes as $metadata ) { @@ -2861,8 +2848,10 @@ public static function remove_insecure_properties( $theme_json ) { $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names, $valid_variations ); - $blocks_metadata = static::get_blocks_metadata(); - $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata ); + $style_nodes = array_merge( + static::get_style_nodes( $theme_json ), + static::get_block_nodes( $theme_json ), + ); foreach ( $style_nodes as $metadata ) { $input = _wp_array_get( $theme_json, $metadata['path'], array() );