Skip to content

Commit

Permalink
Font Library: Store font subdirectory in post meta. (WordPress#63000)
Browse files Browse the repository at this point in the history
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 WordPress/wordpress-develop@a033cf1

Co-authored-by: creativecoder <[email protected]>
Co-authored-by: costdev <[email protected]>
  • Loading branch information
3 people authored Jun 30, 2024
1 parent b76965d commit fced091
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/' );
}

Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.5/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit fced091

Please sign in to comment.