diff --git a/src/wp-admin/font-library.php b/src/wp-admin/font-library.php
index abc2ea4f4da70..8e2b78b9b8630 100644
--- a/src/wp-admin/font-library.php
+++ b/src/wp-admin/font-library.php
@@ -10,6 +10,14 @@
/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
+if ( ! wp_is_font_library_enabled() ) {
+ wp_die(
+ '
' . __( 'Font Library is not available.' ) . '
' .
+ '' . __( 'The Font Library has been disabled on this site.' ) . '
',
+ 403
+ );
+}
+
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die(
'' . __( 'You need a higher level of permission.' ) . '
' .
diff --git a/src/wp-admin/menu.php b/src/wp-admin/menu.php
index 57d94c75e26f2..b5d5ad5a56f34 100644
--- a/src/wp-admin/menu.php
+++ b/src/wp-admin/menu.php
@@ -237,7 +237,9 @@
}
// Font Library menu item.
-$submenu['themes.php'][9] = array( __( 'Fonts' ), 'edit_theme_options', 'font-library.php' );
+if ( wp_is_font_library_enabled() ) {
+ $submenu['themes.php'][9] = array( __( 'Fonts' ), 'edit_theme_options', 'font-library.php' );
+}
$customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
diff --git a/src/wp-includes/fonts.php b/src/wp-includes/fonts.php
index 198fc21d61c74..700a246cab723 100644
--- a/src/wp-includes/fonts.php
+++ b/src/wp-includes/fonts.php
@@ -109,6 +109,30 @@ function wp_unregister_font_collection( string $slug ) {
return WP_Font_Library::get_instance()->unregister_font_collection( $slug );
}
+/**
+ * Determines whether the Font Library is enabled.
+ *
+ * The Font Library lets users with the `edit_theme_options` capability install
+ * and manage fonts from the admin interface. Returning false from the
+ * {@see 'wp_is_font_library_enabled'} filter removes the Font Library admin
+ * menu item and screen, which is useful for sites where fonts are managed by
+ * the theme and the feature is not needed in the interface.
+ *
+ * @since 7.1.0
+ *
+ * @return bool True if the Font Library is enabled, false otherwise.
+ */
+function wp_is_font_library_enabled() {
+ /**
+ * Filters whether the Font Library is enabled.
+ *
+ * @since 7.1.0
+ *
+ * @param bool $enabled Whether the Font Library is enabled. Default true.
+ */
+ return (bool) apply_filters( 'wp_is_font_library_enabled', true );
+}
+
/**
* Retrieves font uploads directory information.
*
diff --git a/tests/phpunit/tests/fonts/font-library/wpIsFontLibraryEnabled.php b/tests/phpunit/tests/fonts/font-library/wpIsFontLibraryEnabled.php
new file mode 100644
index 0000000000000..cd00e527eac10
--- /dev/null
+++ b/tests/phpunit/tests/fonts/font-library/wpIsFontLibraryEnabled.php
@@ -0,0 +1,39 @@
+assertTrue( wp_is_font_library_enabled() );
+ }
+
+ /**
+ * @ticket 65550
+ */
+ public function test_can_be_disabled_via_filter() {
+ add_filter( 'wp_is_font_library_enabled', '__return_false' );
+
+ $this->assertFalse( wp_is_font_library_enabled() );
+ }
+
+ /**
+ * @ticket 65550
+ */
+ public function test_filtered_value_is_cast_to_boolean() {
+ add_filter( 'wp_is_font_library_enabled', '__return_zero' );
+
+ $this->assertFalse( wp_is_font_library_enabled() );
+ }
+}