-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add a databse persisted fallback for the default font folder path #6252
Add a databse persisted fallback for the default font folder path #6252
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An non-persisted alternative PR to this one: #6259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes from #6259 (review) apply here too.
$font_dir = wp_default_font_dir( true ); | ||
chmod( $font_dir['path'], 0000 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_dir
function.If
/wp-content/fonts
is writable this function should return:If
/wp-content/fonts
is 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_dir
function 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.