PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
gutenberg / lib / compat / plugin / fonts.php

fonts.php in Gutenberg trunk, at lib/compat/plugin/fonts.php

65 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * A special compat layer for legacy font files upload directory.
4 *
5 * @link https://github.com/WordPress/gutenberg/pull/57688#issuecomment-2259037546
6 *
7 * @package gutenberg
8 */
9
10 // @core-merge: Do not merge this function, it is for deleting fonts from the wp-content/fonts directory only used in Gutenberg.
11 /**
12 * Deletes associated font files from wp-content/fonts, when a font face is deleted.
13 *
14 * @param int $post_id Post ID.
15 * @param WP_Post $post Post object.
16 */
17 function gutenberg_before_delete_font_face( $post_id, $post ) {
18 if ( 'wp_font_face' !== $post->post_type ) {
19 return;
20 }
21
22 $font_files = get_post_meta( $post_id, '_wp_font_face_file', false );
23
24 if ( empty( $font_files ) ) {
25 return;
26 }
27
28 $site_path = '';
29 if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
30 $site_path = '/sites/' . get_current_blog_id();
31 }
32
33 $font_dir = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;
34
35 foreach ( $font_files as $font_file ) {
36 $font_path = $font_dir . '/' . $font_file;
37
38 if ( file_exists( $font_path ) ) {
39 wp_delete_file( $font_path );
40 }
41 }
42 }
43 add_action( 'before_delete_post', 'gutenberg_before_delete_font_face', 10, 2 );
44
45 // Priority 11 to run after Core's menu.php sets up the fonts menu.
46 add_action( 'admin_menu', 'gutenberg_register_fonts_menu_item', 11 );
47
48 /**
49 * Registers the Fonts menu item under Appearance using the font-library page.
50 * Removes Core's fonts menu item first to prevent duplication.
51 */
52 function gutenberg_register_fonts_menu_item() {
53 // Remove Core's fonts menu item if it exists.
54 remove_submenu_page( 'themes.php', 'font-library.php' );
55
56 add_submenu_page(
57 'themes.php',
58 __( 'Fonts', 'gutenberg' ),
59 __( 'Fonts', 'gutenberg' ),
60 'edit_theme_options',
61 'font-library-wp-admin',
62 'gutenberg_font_library_wp_admin_render_page'
63 );
64 }
65