Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wp-admin/font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';

if ( ! wp_is_font_library_enabled() ) {
wp_die(
'<h1>' . __( 'Font Library is not available.' ) . '</h1>' .
'<p>' . __( 'The Font Library has been disabled on this site.' ) . '</p>',
403
);
}

if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die(
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
Expand Down
4 changes: 3 additions & 1 deletion src/wp-admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down
24 changes: 24 additions & 0 deletions src/wp-includes/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/tests/fonts/font-library/wpIsFontLibraryEnabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Test wp_is_font_library_enabled().
*
* @package WordPress
* @subpackage Font Library
*
* @group fonts
* @group font-library
*
* @covers ::wp_is_font_library_enabled
*/
class Tests_Fonts_WpIsFontLibraryEnabled extends WP_UnitTestCase {

/**
* @ticket 65550
*/
public function test_is_enabled_by_default() {
$this->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() );
}
}
Loading