Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: Store font subdirectory in post meta. #63000

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

peterwilsoncc
Copy link
Contributor

@peterwilsoncc peterwilsoncc commented Jun 30, 2024

What?

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.

Why?

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.

How?

Backports WordPress/wordpress-develop@a033cf1

Testing Instructions

  1. Configure site to run on WordPress 6.4 to ensure the font directory is using the Gutenberg settings.
  2. Add the mini-plugin below to your mu-plugins folder
  3. Upload a font/sideload from Google
  4. Observe the font file is stored in a sub-directory
  5. Observe the font file's sub-directory is not stored in the post meta
  6. Wait 30 seconds for a tick of the mu-plugin
  7. Delete the font via the font library
  8. Ensure the font file is deleted. (Edited because I initially put the reproduction step here 🤦)
  9. Remove the min-plugin from your mu-plugins to avoid confusion later.

Testing mini-plugin:

add_filter( 'font_dir', function ( $font_dir ) {
        /*
         * Change sub-directory every 30 seconds
         *
         * 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 easier testing by setting a new
         * sub-directory every 30 seconds.
         */
        $subdir = '/' . (string) floor( time() / 30 );
        $font_dir['subdir'] = $subdir;
        $font_dir['path'] .= $subdir;
        $font_dir['url'] .= $subdir;
        return $font_dir;
} );

Testing Instructions for Keyboard

N/A

Screenshots or screencast

N/A

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 <grantmkin@git.wordpress.org>
Co-authored-by: costdev <costdev@git.wordpress.org>
Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
@peterwilsoncc peterwilsoncc requested review from creativecoder and removed request for spacedmonkey June 30, 2024 22:23
Copy link

github-actions bot commented Jun 30, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: creativecoder <grantmkin@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@peterwilsoncc peterwilsoncc added the Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core label Jun 30, 2024
@peterwilsoncc peterwilsoncc self-assigned this Jun 30, 2024
Copy link
Contributor

@creativecoder creativecoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ✅ Manually verified changed code matches WordPress/wordpress-develop@a033cf1
  • ✅ Tested to make sure font files are correctly deleted even after changing the font_dir filter's subdir value

@peterwilsoncc peterwilsoncc merged commit fced091 into trunk Jun 30, 2024
66 of 69 checks passed
@peterwilsoncc peterwilsoncc deleted the do/sync-wp61297-font-subdir branch June 30, 2024 23:00
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jun 30, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
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 <grantmkin@git.wordpress.org>
Co-authored-by: costdev <costdev@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants