diff --git a/lib/global-styles.php b/lib/global-styles.php index 852ce5ef3dd37a..0b9413dc4608bb 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -596,22 +596,27 @@ function gutenberg_experimental_global_styles_enqueue_assets() { * @return array Default features config for the editor. */ function gutenberg_experimental_global_styles_get_editor_features( $config ) { - if ( - empty( $config['global']['features'] ) || - ! is_array( $config['global']['features'] ) - ) { - $config['global']['features'] = array(); + $features = array(); + foreach ( array_keys( $config ) as $context ) { + if ( + empty( $config[ $context ]['features'] ) || + ! is_array( $config[ $context ]['features']) + ) { + $features[ $context ] = array(); + } else { + $features[ $context ] = $config[ $context ]['features']; + } } // Deprecated theme supports. if ( get_theme_support( 'disable-custom-colors' ) ) { - if ( ! isset( $config['global']['features']['color'] ) ) { - $config['global']['features']['color'] = array(); + if ( ! isset( $features['global']['color'] ) ) { + $features['global']['color'] = array(); } - $config['global']['features']['color']['custom'] = false; + $features['global']['color']['custom'] = false; } - return $config['global']['features']; + return $features; } /** diff --git a/packages/block-editor/src/components/use-editor-feature/index.js b/packages/block-editor/src/components/use-editor-feature/index.js index efda6385ece3c2..e1ed370ec01605 100644 --- a/packages/block-editor/src/components/use-editor-feature/index.js +++ b/packages/block-editor/src/components/use-editor-feature/index.js @@ -38,8 +38,6 @@ export default function useEditorFeature( featurePath ) { const setting = useSelect( ( select ) => { - const path = `__experimentalFeatures.${ featurePath }`; - // 1 - Use deprecated settings, if available. const settings = select( 'core/block-editor' ).getSettings(); const deprecatedSettingsValue = deprecatedFlags[ featurePath ] @@ -49,8 +47,14 @@ export default function useEditorFeature( featurePath ) { return deprecatedSettingsValue; } - // 2 - Use global __experimentalFeatures otherwise. - return get( settings, path ); + // 2 - Use __experimental features otherwise. + // We cascade to the global value if the block one is not available. + // + // TODO: make it work for blocks that define multiple selectors + // such as core/heading or core/post-title. + const globalPath = `__experimentalFeatures.global.${ featurePath }`; + const blockPath = `__experimentalFeatures.${ blockName }.${ featurePath }`; + return get( settings, blockPath ) ?? get( settings, globalPath ); }, [ blockName, featurePath ] );