From 1ba8462da8bc95b35e7611b8d52eee89712bddf3 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 3 Sep 2020 09:57:35 +0100 Subject: [PATCH 1/2] Allow disabling custom font sizes using theme.json config --- lib/edit-site-page.php | 1 - lib/experimental-default-theme.json | 3 ++ lib/global-styles.php | 7 ++++ lib/navigation-page.php | 1 - lib/widgets-page.php | 1 - packages/block-editor/README.md | 1 - .../components/font-sizes/font-size-picker.js | 34 +++++++++++++------ .../components/use-editor-feature/index.js | 4 +++ packages/block-editor/src/store/defaults.js | 1 - 9 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/edit-site-page.php b/lib/edit-site-page.php index 6ff50e2dfc14af..fb2ae9cdaf9358 100644 --- a/lib/edit-site-page.php +++ b/lib/edit-site-page.php @@ -127,7 +127,6 @@ function gutenberg_edit_site_init( $hook ) { $settings = array( 'alignWide' => get_theme_support( 'align-wide' ), - 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), 'imageSizes' => $available_image_sizes, 'isRTL' => is_rtl(), 'maxUploadFileSize' => $max_upload_size, diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index 23bf29f058b9c4..b33a31bb7683d1 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -133,6 +133,9 @@ }, "gradient": { "custom": true + }, + "fontSize": { + "custom": true } } } diff --git a/lib/global-styles.php b/lib/global-styles.php index ec2062d9778bf5..2a530214c6f3e0 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -621,6 +621,12 @@ function gutenberg_experimental_global_styles_get_editor_features( $config ) { } $features['global']['gradient']['custom'] = false; } + if ( get_theme_support( 'disable-custom-font-sizes' ) ) { + if ( ! isset( $features['global']['fontSize'] ) ) { + $features['global']['fontSize'] = array(); + } + $features['global']['fontSize']['custom'] = false; + } return $features; } @@ -656,6 +662,7 @@ function gutenberg_experimental_global_styles_settings( $settings ) { // Unsetting deprecated settings defined by Core. unset( $settings['disableCustomColors'] ); unset( $settings['disableCustomGradients'] ); + unset( $settings['disableCustomFontSizes'] ); return $settings; } diff --git a/lib/navigation-page.php b/lib/navigation-page.php index d592bf9b83153f..4d91724b877149 100644 --- a/lib/navigation-page.php +++ b/lib/navigation-page.php @@ -58,7 +58,6 @@ function gutenberg_navigation_init( $hook ) { } $settings = array( - 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), 'imageSizes' => $available_image_sizes, 'isRTL' => is_rtl(), 'maxUploadFileSize' => $max_upload_size, diff --git a/lib/widgets-page.php b/lib/widgets-page.php index fb024ef019794a..0a0ead4be8ecde 100644 --- a/lib/widgets-page.php +++ b/lib/widgets-page.php @@ -80,7 +80,6 @@ function gutenberg_widgets_init( $hook ) { $settings = array_merge( array( - 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), 'imageSizes' => $available_image_sizes, 'isRTL' => is_rtl(), 'maxUploadFileSize' => $max_upload_size, diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 00e8b6fdb70057..5c6e48105bd337 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -479,7 +479,6 @@ _Properties_ - _availableLegacyWidgets_ `Array`: Array of objects representing the legacy widgets available. - _colors_ `Array`: Palette colors - _fontSizes_ `Array`: Available font sizes -- _disableCustomFontSizes_ `boolean`: Whether or not the custom font sizes are disabled - _imageEditing_ `boolean`: Image Editing settings set to false to disable. - _imageSizes_ `Array`: Available image sizes - _maxWidth_ `number`: Max width to constraint resizing diff --git a/packages/block-editor/src/components/font-sizes/font-size-picker.js b/packages/block-editor/src/components/font-sizes/font-size-picker.js index 9200924ad22be8..8ad41b432b5ffa 100644 --- a/packages/block-editor/src/components/font-sizes/font-size-picker.js +++ b/packages/block-editor/src/components/font-sizes/font-size-picker.js @@ -1,16 +1,28 @@ /** * WordPress dependencies */ -import { FontSizePicker } from '@wordpress/components'; -import { withSelect } from '@wordpress/data'; +import { FontSizePicker as BaseFontSizePicker } from '@wordpress/components'; +import { useSelect } from '@wordpress/data'; -export default withSelect( ( select ) => { - const { disableCustomFontSizes, fontSizes } = select( - 'core/block-editor' - ).getSettings(); +/** + * Internal dependencies + */ +import useEditorFeature from '../use-editor-feature'; + +function FontSizePicker( props ) { + const fontSizes = useSelect( + ( select ) => select( 'core/block-editor' ).getSettings().fontSizes, + [] + ); + const disableCustomFontSizes = ! useEditorFeature( 'fontSize.custom' ); + + return ( + + ); +} - return { - disableCustomFontSizes, - fontSizes, - }; -} )( FontSizePicker ); +export default FontSizePicker; 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 f232bed0475b8c..5716ba48a0d9fb 100644 --- a/packages/block-editor/src/components/use-editor-feature/index.js +++ b/packages/block-editor/src/components/use-editor-feature/index.js @@ -22,6 +22,10 @@ const deprecatedFlags = { settings.disableCustomGradients === undefined ? undefined : ! settings.disableCustomGradients, + 'fontSize.custom': ( settings ) => + settings.disableCustomFontSizes === undefined + ? undefined + : ! settings.disableCustomFontSizes, }; /** diff --git a/packages/block-editor/src/store/defaults.js b/packages/block-editor/src/store/defaults.js index 6b0605f2386e42..7d5ae73011342f 100644 --- a/packages/block-editor/src/store/defaults.js +++ b/packages/block-editor/src/store/defaults.js @@ -15,7 +15,6 @@ export const PREFERENCES_DEFAULTS = { * @property {Array} availableLegacyWidgets Array of objects representing the legacy widgets available. * @property {Array} colors Palette colors * @property {Array} fontSizes Available font sizes - * @property {boolean} disableCustomFontSizes Whether or not the custom font sizes are disabled * @property {boolean} imageEditing Image Editing settings set to false to disable. * @property {Array} imageSizes Available image sizes * @property {number} maxWidth Max width to constraint resizing From 7cbbd5e9e388fe457a8929db635e9e33228e6cbf Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 3 Sep 2020 10:08:04 +0100 Subject: [PATCH 2/2] fix phpcs --- lib/edit-site-page.php | 8 ++++---- lib/navigation-page.php | 8 ++++---- lib/widgets-page.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/edit-site-page.php b/lib/edit-site-page.php index fb2ae9cdaf9358..508cf5184d4187 100644 --- a/lib/edit-site-page.php +++ b/lib/edit-site-page.php @@ -126,10 +126,10 @@ function gutenberg_edit_site_init( $hook ) { } $settings = array( - 'alignWide' => get_theme_support( 'align-wide' ), - 'imageSizes' => $available_image_sizes, - 'isRTL' => is_rtl(), - 'maxUploadFileSize' => $max_upload_size, + 'alignWide' => get_theme_support( 'align-wide' ), + 'imageSizes' => $available_image_sizes, + 'isRTL' => is_rtl(), + 'maxUploadFileSize' => $max_upload_size, ); list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' ); diff --git a/lib/navigation-page.php b/lib/navigation-page.php index 4d91724b877149..919c776306be44 100644 --- a/lib/navigation-page.php +++ b/lib/navigation-page.php @@ -58,10 +58,10 @@ function gutenberg_navigation_init( $hook ) { } $settings = array( - 'imageSizes' => $available_image_sizes, - 'isRTL' => is_rtl(), - 'maxUploadFileSize' => $max_upload_size, - 'blockNavMenus' => get_theme_support( 'block-nav-menus' ), + 'imageSizes' => $available_image_sizes, + 'isRTL' => is_rtl(), + 'maxUploadFileSize' => $max_upload_size, + 'blockNavMenus' => get_theme_support( 'block-nav-menus' ), ); list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' ); diff --git a/lib/widgets-page.php b/lib/widgets-page.php index 0a0ead4be8ecde..4d7ee91f6d0002 100644 --- a/lib/widgets-page.php +++ b/lib/widgets-page.php @@ -80,9 +80,9 @@ function gutenberg_widgets_init( $hook ) { $settings = array_merge( array( - 'imageSizes' => $available_image_sizes, - 'isRTL' => is_rtl(), - 'maxUploadFileSize' => $max_upload_size, + 'imageSizes' => $available_image_sizes, + 'isRTL' => is_rtl(), + 'maxUploadFileSize' => $max_upload_size, ), gutenberg_get_legacy_widget_settings() );