[wp-trac] [WordPress Trac] #61297: Font Directory uploads ignore `subdir` property.

WordPress Trac noreply at wordpress.org
Mon May 27 00:27:24 UTC 2024


#61297: Font Directory uploads ignore `subdir` property.
---------------------------+------------------------------
 Reporter:  peterwilsoncc  |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Editor         |     Version:
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------
Description changed by peterwilsoncc:

Old description:

> The data structure for the font directory matches the uploads directory
> and contains the following properties:
>
> * path
> * url
> * subdir
> * basedir
> * baseurl
> * error (only used during directory creation)
>
> When uploading fonts, the sub-directory property is ignored and prevents
> the use of sub-directories by developers.
>
> This prevents developers from being able to organize the font files by
> font-family or the active theme at time of upload.
>
> {{{#!php
> add_filter( 'font_dir', function ( $font_dir ) {
>         /*
>          * Change sub-directory every 5 minutes.
>          *
>          * POC only, a more likely use is to get the `fontFamily` from
> the API
>          * request or the currently active theme and use either of those
> values
>          * to generate a unique sub-directory.
>          *
>          * The POC is simply to allow for eaiser testing by setting a new
>          * sub-directory every few minutes.
>          */
>         $font_dir['subdir'] = floor( time() / 300 );
>         return $font_dir;
> } );
> }}}
>
> The following will need to be updated to account for the sub-directory:
>
> * upload destination
> * post meta data containing the file reference
> * deletion of files in `_wp_before_delete_font_face()`

New description:

 The data structure for the font directory matches the uploads directory
 and contains the following properties:

 * path
 * url
 * subdir
 * basedir
 * baseurl
 * error (only used during directory creation)

 When uploading fonts, the sub-directory is not stored in the post meta and
 prevents the deletion of files when the font-face post objects are
 deleted.

 {{{#!php
 add_filter( 'font_dir', function ( $font_dir ) {
         /*
          * Change sub-directory every 5 minutes.
          *
          * POC only, a more likely use is to get the `fontFamily` from the
 API
          * request or the currently active theme and use either of those
 values
          * to generate a unique sub-directory.
          *
          * The POC is simply to allow for eaiser testing by setting a new
          * sub-directory every few minutes.
          */
         $subdir = '/' . (string) floor( time() / 300 );
         $font_dir['subdir'] = $subdir;
         $font_dir['path'] .= $subdir;
         $font_dir['url'] .= $subdir;
         return $font_dir;
 } );
 }}}

 The following will need to be updated to account for the sub-directory:

 * post meta data containing the file reference
 * deletion of files in `_wp_before_delete_font_face()`

 To reproduce:

 * Upload a font/sideload from Google
 * Observe the font file is stored in a sub-directory
 * Observe the font file's sub-directory is not stored in the post meta
 * Wait five minutes (using sample plugin above)
 * Delete the font via the font library
 * Observe the file is not deleted

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61297#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list