Editor (Font Library): Store font subdirectory in post meta.

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.

Props costdev, grantmkin, peterwilsoncc.
Fixes #61297.


Built from https://develop.svn.wordpress.org/trunk@58353


git-svn-id: http://core.svn.wordpress.org/trunk@57805 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2024-06-05 23:19:17 +00:00
parent c844f3203b
commit 3b8d75611b
3 changed files with 4 additions and 4 deletions

View File

@ -230,7 +230,7 @@ function _wp_before_delete_font_face( $post_id, $post ) {
} }
$font_files = get_post_meta( $post_id, '_wp_font_face_file', false ); $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 ) { foreach ( $font_files as $font_file ) {
wp_delete_file( $font_dir . '/' . $font_file ); wp_delete_file( $font_dir . '/' . $font_file );

View File

@ -916,8 +916,8 @@ class WP_REST_Font_Faces_Controller extends WP_REST_Posts_Controller {
$new_path = $path; $new_path = $path;
$fonts_dir = wp_get_font_dir(); $fonts_dir = wp_get_font_dir();
if ( str_starts_with( $new_path, $fonts_dir['path'] ) ) { if ( str_starts_with( $new_path, $fonts_dir['basedir'] ) ) {
$new_path = str_replace( $fonts_dir, '', $new_path ); $new_path = str_replace( $fonts_dir['basedir'], '', $new_path );
$new_path = ltrim( $new_path, '/' ); $new_path = ltrim( $new_path, '/' );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-beta1-58352'; $wp_version = '6.6-beta1-58353';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.