From fced0917da12bb4eeb8c6f1df7cd1aa11275fd96 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:00:47 +1000 Subject: [PATCH] Font Library: Store font subdirectory in post meta. (#63000) Stores the font file sub-directory in the `wp_font_face` post meta. Similar to attachments, only the portion of the path relative to the base directory is stored. This ensures the files can be deleted alongside their post on sites using a plugin to store font files in sub-directories. Previously running such a plugin would result in the files remaining on the file system post delete. Backports https://github.com/WordPress/wordpress-develop/commit/a033cf15d23e9b32485e468110c707e0f7458e37 Co-authored-by: creativecoder Co-authored-by: costdev --- .../fonts/class-wp-rest-font-faces-controller.php | 4 ++-- lib/compat/wordpress-6.5/fonts/fonts.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php index f8e7c56c52d402..e844e7a8fe8730 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php @@ -917,8 +917,8 @@ protected function relative_fonts_path( $path ) { $new_path = $path; $fonts_dir = wp_get_font_dir(); - if ( str_starts_with( $new_path, $fonts_dir['path'] ) ) { - $new_path = str_replace( $fonts_dir, '', $new_path ); + if ( str_starts_with( $new_path, $fonts_dir['basedir'] ) ) { + $new_path = str_replace( $fonts_dir['basedir'], '', $new_path ); $new_path = ltrim( $new_path, '/' ); } diff --git a/lib/compat/wordpress-6.5/fonts/fonts.php b/lib/compat/wordpress-6.5/fonts/fonts.php index 302562298fffe1..8f61dc5750f53f 100644 --- a/lib/compat/wordpress-6.5/fonts/fonts.php +++ b/lib/compat/wordpress-6.5/fonts/fonts.php @@ -360,7 +360,7 @@ function _wp_before_delete_font_face( $post_id, $post ) { } $font_files = get_post_meta( $post_id, '_wp_font_face_file', false ); - $font_dir = wp_get_font_dir()['path']; + $font_dir = untrailingslashit( wp_get_font_dir()['basedir'] ); foreach ( $font_files as $font_file ) { wp_delete_file( $font_dir . '/' . $font_file );