Font Library: filter fonts upload directory#57697
Conversation
|
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/tests/fonts/font-library/wpFontLibrary/fontsDir.php ❔ lib/experimental/fonts/font-library/class-wp-font-family.php ❔ lib/experimental/fonts/font-library/class-wp-font-library.php |
mikachan
left a comment
There was a problem hiding this comment.
Thanks for working on this!
I've tested using the testing instructions:
Case 1: Default
- Verify the font is uploaded to /wp-content/fonts and the font url is set to site_url/wp-content/fonts/your-font.ttf ✅
Case 2: Custom
- Changed the fonts directory by adding the following snippet to my active theme, and verified the font is uploaded to /custom-fonts-dir ✅
function filter_fonts_dir( $font_settings ) {
$new_sub_dir = '/custom-fonts-dir';
$font_settings['dir'] = rtrim( $font_settings['dir'], '/' ) . $new_sub_dir;
$font_settings['url'] = rtrim( $font_settings['url'], '/' ) . $new_sub_dir;
return $font_settings;
}
add_filter( 'fonts_dir', 'filter_fonts_dir' );
Case 3: Multi-site
- Verify the font is uploaded to /wp-content/fonts/your-site-id and the font url is set to site_url/wp-content/fonts/your-site-id/your-font.ttf ✅
This only worked if I switched to a site that wasn't the primary site, but I think this is the correct logic.
This all looks great to me. I've left some comments for tiny suggestions but otherwise I think this is ready to bring in 🎉
matiasbenedetto
left a comment
There was a problem hiding this comment.
I added a few commits to make the fonts_dir filter return an array shape equal to the upload_dir filter. Why? because we are using the values of fonts_dir to update upload_dir which will be used to handle the fonts uploaded.
Apart from that, I think it simplifies the code a little.
I removed the no longer needed tests and added new ones to try the filter and its removal.
|
Thanks for testing @mikachan , and nice refactor @matiasbenedetto ! As a follow up, we should add a |
What?
This PR adds a hook for developers to filter where font assets are stored.
Why?
Fixes #55063, alternative to #57044.
See related reasoning in this comment in the above PR.
How?
Adds a single hook
fonts_dirwhich is passed an associative array with keyspathandurl, to be consistent with theupload_dirfilter.This PR is based on the one started by @madhusudhand.
Testing Instructions
Case 1: Default
Case 2: Custom
Case 3: Multi-site
Screenshots or screencast