From 203ca9e84fb0f5ae73c2495dd33b4555f368ae72 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Fri, 12 Jan 2024 17:22:06 -0300 Subject: [PATCH] Font Library: disable font library UI using a PHP filter (#57818) * disable font library UI Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com> * remove php code no longer used Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com> --------- Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com> --- lib/load.php | 9 --------- .../components/global-styles/screen-typography.js | 12 +++++++++--- packages/editor/src/store/defaults.js | 2 ++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/load.php b/lib/load.php index d413334227ee73..8988a05820425d 100644 --- a/lib/load.php +++ b/lib/load.php @@ -185,15 +185,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/fonts/font-face/bc-layer/class-wp-web-fonts.php'; } elseif ( ! class_exists( 'WP_Fonts' ) ) { - // Disables the Font Library. - // @core-merge: this should not go to core. - add_action( - 'enqueue_block_editor_assets', - function () { - wp_add_inline_script( 'wp-block-editor', 'window.__experimentalDisableFontLibrary = true', 'before' ); - } - ); - // Turns off Font Face hooks in Core. // @since 6.4.0. remove_action( 'wp_head', 'wp_print_font_faces', 50 ); diff --git a/packages/edit-site/src/components/global-styles/screen-typography.js b/packages/edit-site/src/components/global-styles/screen-typography.js index 2a895b68fa717f..f76dc6fb381004 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography.js +++ b/packages/edit-site/src/components/global-styles/screen-typography.js @@ -3,6 +3,8 @@ */ import { __ } from '@wordpress/i18n'; import { __experimentalVStack as VStack } from '@wordpress/components'; +import { store as editorStore } from '@wordpress/editor'; +import { useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -12,6 +14,12 @@ import FontFamilies from './font-families'; import ScreenHeader from './header'; function ScreenTypography() { + const fontLibraryEnabled = useSelect( + ( select ) => + select( editorStore ).getEditorSettings().fontLibraryEnabled, + [] + ); + return ( <>
- { ! window.__experimentalDisableFontLibrary && ( - - ) } + { fontLibraryEnabled && }
diff --git a/packages/editor/src/store/defaults.js b/packages/editor/src/store/defaults.js index 686888f91de3d5..485b65d24d3ad3 100644 --- a/packages/editor/src/store/defaults.js +++ b/packages/editor/src/store/defaults.js @@ -10,6 +10,7 @@ import { SETTINGS_DEFAULTS } from '@wordpress/block-editor'; * @property {boolean} richEditingEnabled Whether rich editing is enabled or not * @property {boolean} codeEditingEnabled Whether code editing is enabled or not * @property {boolean} enableCustomFields Whether the WordPress custom fields are enabled or not. + * @property {boolean} fontLibraryEnabled Whether the font library is enabled or not. * true = the user has opted to show the Custom Fields panel at the bottom of the editor. * false = the user has opted to hide the Custom Fields panel at the bottom of the editor. * undefined = the current environment does not support Custom Fields, so the option toggle in Preferences -> Panels to enable the Custom Fields panel is not displayed. @@ -27,5 +28,6 @@ export const EDITOR_SETTINGS_DEFAULTS = { richEditingEnabled: true, codeEditingEnabled: true, enableCustomFields: undefined, + fontLibraryEnabled: true, defaultRenderingMode: 'post-only', };