Conversation
|
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/fonts/font-library/font-library.php |
|
Size Change: -401 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
mikachan
left a comment
There was a problem hiding this comment.
This tests well for me 👍
- Added
add_filter( 'use_font_library_for_site_editor', '__return_false' );to a new, blank theme in its functions.php file and the Font Library UI did not render ✅ - Removing the filter allows the UI to render ✅
|
@mikachan I thought of a different approach to implement this — what if we filtered the $editor-settings that get passed when initializing the site editor, added a new property like Going to try this next. |
This sounds great! I've just been looking at things that are handled via |
|
I updated the PR so that the block editor settings in the site editor context are updated with a The filter is still named the same, so testing instructions remain unchanged. Should be ready for another review @mikachan 🙏 |
| if ( ! function_exists( 'wp_use_font_library' ) ) { | ||
| /** | ||
| * Function that determines if the font library should be activated in the site editor. | ||
| * | ||
| * @since 6.5.0 | ||
| * | ||
| * @param array $editor_settings The editor settings to be potentially filtered. | ||
| * @param WP_Block_Editor_Context $editor_context The editor context. | ||
| */ | ||
| function wp_use_font_library( $editor_settings, $editor_context ) { | ||
| /** | ||
| * Filters whether a post is able to be edited in the block editor. | ||
| * | ||
| * @since 6.5.0 | ||
| */ | ||
| $use_font_library = apply_filters( 'use_font_library_for_site_editor', true ); | ||
|
|
||
| if ( isset( $editor_context->name ) && 'core/edit-site' === $editor_context->name && ! $use_font_library ) { | ||
| $editor_settings['disableFontLibrary'] = true; | ||
| } | ||
|
|
||
| return $editor_settings; | ||
| } | ||
| add_filter( 'block_editor_settings_all', 'wp_use_font_library', 10, 2 ); | ||
| } |
There was a problem hiding this comment.
If it's already possible to filter block_editor_settings_all to turn off the font library UI, I don't think we need this wp_use_font_library functional at all. Those wanting to disable it can use this filter directly.
We should include this in the dev note.
There was a problem hiding this comment.
Great point. I removed it entirely and updated the testing instructions for this PR to use the block_editor_settings_all filter directly. We can include that bit in the dev note.
|
|
||
| const disableFontLibrary = useSelect( ( select ) => { | ||
| const { getEditorSettings } = select( editorStore ); | ||
| return getEditorSettings().disableFontLibrary; |
There was a problem hiding this comment.
I'm thinking this should be enableFontLibrary instead, as that seems more consistent with other editor settings (see
There was a problem hiding this comment.
Part of why naming it disable made sense to me was that it seems to more clearly set the expectation that the font library is inherently part of the site editor, versus explicitly having to enable it or something.
Good idea though to look at the other settings, but it doesn't look so consistent, for example disableLayoutStyles.
What do you think about naming the setting fontLibrary and defaulting true, following this convention:
gutenberg/packages/block-editor/src/store/defaults.js
Lines 142 to 143 in 0e48342
There was a problem hiding this comment.
Actually, I'm also okay with fontLibraryEnabled since it follows the settings that are specific to the site editor.
There was a problem hiding this comment.
Thanks for looking into it more deeply! To make it even more difficult we have both enable[Setting], like
enableOpenverseMediaCategoryenableCustomFields
as well as [setting]Enabled
richEditingEnabledcodeEditingEnabled
I think overall I see more of the first kind (enable[Setting]) in editor settings, but it doesn't look like there's a standard convention to follow.
There was a problem hiding this comment.
Oh good point, I think this feels conceptually closer to the enableOpenverseMediaCategory and enableCustomFields, so let's just go with that naming pattern. Thanks!
|
Closing in favor of #57818. Thanks @mikachan @creativecoder, your feedback was incorporated into that PR. |
What?
This PR adds a filter to disable the Font Library UI at the site level.
Why?
Part of the feedback in the introduction of the Font Library was to give developers more control, including disabling it if needed.
Solves #55275
How?
Adds a setting to the editor (
enableFontLibrary) and conditionally renders the Font Library UI based on this setting.Testing Instructions
Screenshots or screencast