# gutenberg/24.1.0/lib/compat/plugin/fonts.php

Gutenberg, version 24.1.0. 65 lines.

- Page: https://pluginprobe.com/plugins/gutenberg/24.1.0/code/lib/compat/plugin/fonts.php
- Raw: https://pluginprobe.com/plugins/gutenberg/24.1.0/raw/lib/compat/plugin/fonts.php
- Modified: 2026-09-30T09:29:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gutenberg/24.1.0/code/lib/compat/plugin/fonts.php#L10-L20`.

```php
<?php
/**
 * A special compat layer for legacy font files upload directory.
 *
 * @link https://github.com/WordPress/gutenberg/pull/57688#issuecomment-2259037546
 *
 * @package gutenberg
 */

// @core-merge: Do not merge this function, it is for deleting fonts from the wp-content/fonts directory only used in Gutenberg.
/**
 * Deletes associated font files from wp-content/fonts, when a font face is deleted.
 *
 * @param int     $post_id Post ID.
 * @param WP_Post $post    Post object.
 */
function gutenberg_before_delete_font_face( $post_id, $post ) {
	if ( 'wp_font_face' !== $post->post_type ) {
		return;
	}

	$font_files = get_post_meta( $post_id, '_wp_font_face_file', false );

	if ( empty( $font_files ) ) {
		return;
	}

	$site_path = '';
	if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
		$site_path = '/sites/' . get_current_blog_id();
	}

	$font_dir = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;

	foreach ( $font_files as $font_file ) {
		$font_path = $font_dir . '/' . $font_file;

		if ( file_exists( $font_path ) ) {
			wp_delete_file( $font_path );
		}
	}
}
add_action( 'before_delete_post', 'gutenberg_before_delete_font_face', 10, 2 );

// Priority 11 to run after Core's menu.php sets up the fonts menu.
add_action( 'admin_menu', 'gutenberg_register_fonts_menu_item', 11 );

/**
 * Registers the Fonts menu item under Appearance using the font-library page.
 * Removes Core's fonts menu item first to prevent duplication.
 */
function gutenberg_register_fonts_menu_item() {
	// Remove Core's fonts menu item if it exists.
	remove_submenu_page( 'themes.php', 'font-library.php' );

	add_submenu_page(
		'themes.php',
		__( 'Fonts', 'gutenberg' ),
		__( 'Fonts', 'gutenberg' ),
		'edit_theme_options',
		'font-library-wp-admin',
		'gutenberg_font_library_wp_admin_render_page'
	);
}

```
