Make WordPress Core

Opened 2 months ago

Closed 7 weeks ago

#61297 closed defect (bug) (fixed)

Font Directory uploads ignore `subdir` property.

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.5.5 Priority: normal
Severity: normal Version: 6.5
Component: Editor Keywords: has-patch has-unit-tests has-testing-info commit dev-reviewed
Focuses: Cc:

Description (last modified by peterwilsoncc)

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.

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

Change History (13)

#1 @peterwilsoncc
2 months ago

  • Description modified (diff)

#2 @peterwilsoncc
2 months ago

Edited the description to clarify the bug: the sub-directory is not stored in the post meta.

This ticket was mentioned in PR #6638 on WordPress/wordpress-develop by @peterwilsoncc.


2 months ago
#3

  • Keywords has-patch has-unit-tests added

@peterwilsoncc commented on PR #6638:


2 months ago
#4

@costdev Done, the failing tests can be seen against 134770eb5d6ba43faa1fb5475890e188ec890a77 and passing against the latest commit.

The Gutenberg tests are failing but it looks to be typescript related so I am not sure what is happening there.

#5 @peterwilsoncc
2 months ago

  • Milestone changed from Awaiting Review to 6.6

Moving this to the 6.6 milestone while a discussion takes place in Slack as to whether it ought to be included in a minor 6.5 release.

#6 @grantmkin
2 months ago

I've tested and approved the PR attached to this ticket (https://github.com/WordPress/wordpress-develop/pull/6638#pullrequestreview-2099643069). Thanks for finding and fixing this @peterwilsoncc !

#7 @peterwilsoncc
2 months ago

  • Owner set to peterwilsoncc
  • Resolution set to fixed
  • Status changed from new to closed

In 58353:

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.

#8 @peterwilsoncc
2 months ago

  • Keywords dev-feedback added
  • Milestone changed from 6.6 to 6.5.5
  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-opening and moving to the minor release milestone for backport consideration.

If it's decided not to backport, please close as fixed and move the ticket back to WP 6.6.

#10 @hellofromTonya
7 weeks ago

  • Owner changed from peterwilsoncc to hellofromTonya
  • Status changed from reopened to reviewing

Currently reviewing and testing [58353] for backport to the 6.5 branch.

#11 @hellofromTonya
7 weeks ago

  • Keywords has-testing-info added

Test Report

Patch tested:[58353]

Steps to Reproduce or Test

  1. Add mini-plugin to mu-plugins
  2. Upload/install a font from Google
  3. Wait 30 seconds or so (for a tick of the clock in the plugin above to change the directory)
  4. Delete the font from the font-library 🐞

Expected Results

When testing a patch to validate it works as expected:

  • ✅ The font file should be deleted / removed from the file system.

When reproducing a bug:

  • ❌ The font file remains on the filesystem.

Environment

  • OS: macOS
  • Web server: nginx
  • PHP: 8.3
  • WordPress: 6.5.4 and 6.6 Beta 3
  • Plugins: none
  • Theme: TT4 default

Actual Results

On 6.5.4:

Yes, I can reproduce the bug

  • ❌ The font file was not deleted from the filesystem.

When testing the bugfix patch:

  • ✅ The font file was deleted from the filesystem, while the subdirectory was not.

Also tested 6.6 Beta 3 which includes the [58353]:

  • ✅ The font file was deleted from the filesystem, while the subdirectory was not.

#12 @hellofromTonya
7 weeks ago

  • Keywords commit dev-reviewed added; dev-feedback removed
  • Version set to 6.5

Tested [58353] and confirmed it resolves the issue with 6.5.4 ✅

Marking it for backport to 6.5 branch. Will backport shortly.

#13 @hellofromTonya
7 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 58448:

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.

Reviewed by hellofromTonya.
Merges [58353] to the 6.5 branch.

Props costdev, grantmkin, peterwilsoncc.
Fixes #61297.

Note: See TracTickets for help on using tickets.