-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: add global configuration variables for font directory #57044
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❔ lib/experimental/fonts/font-library/class-wp-font-library.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php |
Flaky tests detected in 8bfa658. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7206100374
|
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.
Nice one @madhusudhand!
This worked as expected under all the test conditions provided. We should be sure to document this one when the time comes.
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 don't have the full history of feedback here, but my first instinct is to treat the fonts directory more like the uploads folder, rather than the theme or plugin folders.
That is, add a filter for it (like upload_dir
) rather than add a constant for it.
Also, is there a need to define WP_FONT_DIR
and WP_FONT_URL
separately? Wouldn't the url need to be based on the dir path?
I believe we are already filtering it:
Could there be cases where the URL may differ from where it is stored in the filesystem? If we do move forward with separate constants, it's worth noting that it's necessary to define both. Or a compromise could be to base the URL on the WP_FONT_DIR constant if it's defined but the WP_FONT_URL is not. |
I mean adding an |
$defaults['basedir'] = WP_CONTENT_DIR; | ||
$defaults['baseurl'] = content_url(); | ||
$defaults['subdir'] = '/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.
Is anything lost by not setting basedir, baseurl, and subdir here? It seems like unexpected things could happen if some of the properties for upload_dir
are changed and some are not, but I haven't used this filter before.
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.
Based on the definition of wp_upload_dir, when path
is not set, basedir + subdir are used, and when url
is not set, baseurl + subdir are used. I think we are not loosing anything here.
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.
Alternatively, we could switch to basedir
+ subdir
where basedir becomes the path set by the variable WP_FONT_DIR
and subdir will be the site_id (in case of multi site) and empty for simple sites.
Please refer this
Looking more closely, I see that this is what we do for WP_CONTENT_DIR, WP_PLUGIN_DIR, and WPMU_PLUGIN_DIR, so it makes sense to match that convention. Thinking about this a little more, a filter seems quite useful here, for its flexibility. As an example I could imagine wanting to sort your font files into subdirectories by font family or by file type (similar to how media uploads can be sorted into subfolders). A filter would support adding logic to do this. Looking at how uploads works brings multisite to mind. Have we thought about this at all? Should each site have its own font folder, or should there be one shared folder? If the fonts are shared, how do we make sure one site doesn't delete another site's fonts? Multisite seems like a piece of the puzzle for how we add font directory configuration. 🤔 |
8bfa658
to
6c66774
Compare
6c66774
to
d6f0a0e
Compare
Since the path for
Similar to how uploads work, a sub directory |
I'll go ahead and close this one, since it's been incorporated into and replaced by #57697 |
What?
It adds following configuration variables for the font path.
WP_FONT_DIR
: absolute path where fonts are uploaded to and loaded from. When not set, plugin will fall back toWP_CONTENT_DIR/fonts
as default value.WP_FONT_URL
: full url to the font directory. It should be set when a custom path is set for WP_FONT_DIR. When not set, it defaults tocontent_url( 'fonts' )
Why?
It enables to set a custom directory as font directory.
Testing Instructions
Case 1:
/wp-content/fonts
and the font url should be set tosite_url/wp-content/fonts/your-font.ttf
Case 2:
wp-config.php
Also, validate the following use cases.
Screenshots or screencast
NA
Related
Related discussion is here
fixes #55063