From d77120ea1bae6dfc15bf9b0deee9ee7e00b37d93 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Wed, 27 Jul 2022 16:54:55 +1000 Subject: [PATCH] Add register_theme_feature call to ensure the feature is registered so it appears in API responses --- lib/block-supports/layout.php | 30 +++++++++++++++-------------- lib/compat/wordpress-6.1/theme.php | 31 ++++++++++++++++++++++++++++++ lib/load.php | 1 + 3 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 lib/compat/wordpress-6.1/theme.php diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 838327c626f209..44418407e2a005 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -226,23 +226,25 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $class_names[] = sanitize_title( $layout_classname ); } - $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) ); - // Skip if gap value contains unsupported characters. - // Regex for CSS value borrowed from `safecss_filter_attr`, and used here - // because we only want to match against the value, not the CSS attribute. - if ( is_array( $gap_value ) ) { - foreach ( $gap_value as $key => $value ) { - $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value; + // Only generate Layout styles if the theme has not opted-out. + // Attribute-based Layout classnames are output in all cases. + if ( ! current_theme_supports( 'disable-layout-styles' ) ) { + + $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) ); + // Skip if gap value contains unsupported characters. + // Regex for CSS value borrowed from `safecss_filter_attr`, and used here + // because we only want to match against the value, not the CSS attribute. + if ( is_array( $gap_value ) ) { + foreach ( $gap_value as $key => $value ) { + $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value; + } + } else { + $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value; } - } else { - $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value; - } - $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' ); - $block_spacing = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null ); + $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' ); + $block_spacing = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null ); - // Only generate Layout styles if the theme has not opted-out. - if ( ! current_theme_supports( 'disable-layout-styles' ) ) { // If a block's block.json skips serialization for spacing or spacing.blockGap, // don't apply the user-defined value to the styles. $should_skip_gap_serialization = gutenberg_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' ); diff --git a/lib/compat/wordpress-6.1/theme.php b/lib/compat/wordpress-6.1/theme.php new file mode 100644 index 00000000000000..441fc630714369 --- /dev/null +++ b/lib/compat/wordpress-6.1/theme.php @@ -0,0 +1,31 @@ + __( 'Whether the theme disables generated layout styles.', 'gutenberg' ), + 'show_in_rest' => true, + ) + ); +} +add_action( 'setup_theme', 'gutenberg_create_initial_theme_features', 0 ); diff --git a/lib/load.php b/lib/load.php index da39596251f6db..3980e952ef939c 100644 --- a/lib/load.php +++ b/lib/load.php @@ -88,6 +88,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.1/date-settings.php'; require __DIR__ . '/compat/wordpress-6.1/block-patterns.php'; require __DIR__ . '/compat/wordpress-6.1/edit-form-blocks.php'; +require __DIR__ . '/compat/wordpress-6.1/theme.php'; // Experimental features. remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WP 6.0's stopgap handler for Webfonts API.