PluginProbe
Gutenberg / 23.2.0
Gutenberg v23.2.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 12.6.0 All 403 releases
gutenberg / lib / compat / plugin / fonts.php
lib/compat/plugin
edit-site-routes-backwards-compat.php 1.7 KB 3 years ago fonts.php 1.2 KB 2 years ago

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

44 lines 1.2 KB Raw Download Zip
1 <?php
2 /**
3 * A special compat layer for legacy font files upload directory.
4 *
5 * @see 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