Skip to content

Hook for disabling font library no longer covers all cases (WordPress 7.0) #79019

@justintadlock

Description

@justintadlock

When the Font Library was first introduced, developers could disable it via the block_editor_settings_all filter hook: #57818

There is also a Developer Blog tutorial published based on this hook: https://developer.wordpress.org/news/snippets/how-to-disable-the-font-library/

WordPress 7.0 introduced a new font-library.php (font-library-wp-admin in Gutenberg) screen under themes.php (Appearance) in the WordPress admin. The prior technique no longer works for disabling the font library. This means that any theme/plugin that previously disabled it, that extension's users are now seeing and accessing a screen that should not be there.

The current fix (on top of the previous code) for the new menu item:

add_action( 'admin_menu', function () {
    remove_submenu_page( 'themes.php', 'font-library.php' );
} );

add_action( 'load-appearance_page_font-library', function () {
    wp_die(
        __( 'This feature has been disabled.' ),
        __( 'Disabled' ),
        [ 'response' => 403, 'back_link' => true ]
    );
} );

And a little more if you need to disable it for both WordPress and the Gutenberg plugin because they use different admin menu slugs.

Technically, using the original hook still removes the font library from the editor, so this report is not a "bug" in that sense. However, it is a bug because it changes developer expectations.

I'd also like to propose an enhancement to the system altogether: use the theme supports system to let theme authors control this. Core could auto-opt into a font-library supports. Then, remove_theme_support('font-library') would be a simple one-liner that theme authors could employ without worrying about needing to update their code for any potential future changes.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions