Repository navigation
Add a databse persisted fallback for the default font folder path - #6252
matiasbenedetto wants to merge 9 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| $font_dir = wp_default_font_dir( true ); | ||
| chmod( $font_dir['path'], 0000 ); |
There was a problem hiding this comment.
I haven't found a way to restrict the writing permissions in the context of unit tests. This chmod line isn't working. It is there just to show how the functionality could be tested.
There was a problem hiding this comment.
No idea how to test this either. If the option is changed to record the fallback rather than the directory structure then you migh be able to filter it using the pre_option_{$option} hook.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| */ | ||
| function wp_get_font_dir() { | ||
| function wp_default_font_dir( $refresh_cache = false ) { | ||
| $defaults = get_option( 'font_dir' ); |
There was a problem hiding this comment.
I'm not 100% sure if there are significant benefits in making this persistent. Related: WordPress/gutenberg#59699 (comment)
There was a problem hiding this comment.
Rather than store the entire font directory in the option, I'd suggest storing whether it falls back to the secondary location.
This will prevent future contributors from having to manage three scenarios:
- default
- fallback
- option set
It's already complicated enough without allowing extenders to change the path via either an option or a filter.
peterwilsoncc
left a comment
There was a problem hiding this comment.
Some notes for this option too.
| */ | ||
| function wp_get_font_dir() { | ||
| function wp_default_font_dir( $refresh_cache = false ) { | ||
| $defaults = get_option( 'font_dir' ); |
There was a problem hiding this comment.
Rather than store the entire font directory in the option, I'd suggest storing whether it falls back to the secondary location.
This will prevent future contributors from having to manage three scenarios:
- default
- fallback
- option set
It's already complicated enough without allowing extenders to change the path via either an option or a filter.
| wp_mkdir_p( $defaults['path'] ); | ||
|
|
||
| if ( ! wp_is_writable( $defaults['path'] ) ) { | ||
| $defaults = wp_upload_dir(); | ||
| $defaults['path'] = path_join( $defaults['basedir'], 'fonts' ); | ||
| $defaults['url'] = $defaults['baseurl'] . '/fonts'; | ||
| $defaults['subdir'] = ''; | ||
| $defaults['basedir'] = path_join( $defaults['basedir'], 'fonts' ); | ||
| $defaults['baseurl'] = $defaults['baseurl'] . '/fonts'; | ||
| } | ||
|
|
| $font_dir = wp_default_font_dir( true ); | ||
| chmod( $font_dir['path'], 0000 ); |
There was a problem hiding this comment.
No idea how to test this either. If the option is changed to record the fallback rather than the directory structure then you migh be able to filter it using the pre_option_{$option} hook.
|
Closing this PR off per https://make.wordpress.org/core/2024/03/21/font-library-update-storage-of-font-files/. Thanks everyone for your work on this, I appreciate it. |
What?
Add a fallback for the default font directory persisted in the database as a site option.
There's an alternative PR without database persistence: #6259
Why?
Decision from https://make.wordpress.org/core/2024/03/07/unblocking-wp6-5-font-library-and-synced-pattern-overrides/
Discussion: WordPress/gutenberg#59699
How?
Add the
wp_default_font_dirfunction.If
/wp-content/fontsis writable this function should return:If
/wp-content/fontsis not writable this function should return:The output of this function is persisted in the database as a site_option. To refresh the value persisted the
wp_default_font_dirfunction should be called like thiswp_default_font_dir( true ).Trac ticket: https://core.trac.wordpress.org/ticket/60751#ticket
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.