-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fonts Library: Backend #52704
Fonts Library: Backend #52704
Conversation
Flaky tests detected in 82968c9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5824433675
|
lib/experimental/fonts-library/class-wp-rest-fonts-library-controller.php
Outdated
Show resolved
Hide resolved
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-library/class-wp-font-family-utils.php ❔ lib/experimental/fonts-library/class-wp-font-family.php ❔ lib/experimental/fonts-library/class-wp-fonts-library.php ❔ lib/experimental/fonts-library/class-wp-rest-fonts-library-controller.php ❔ lib/experimental/fonts-library/fonts-library.php ❔ phpunit/fonts-library/class-wp-font-family-test.php ❔ phpunit/fonts-library/class-wp-font-family-utils-test.php ❔ phpunit/fonts-library/class-wp-fonts-library-test.php ❔ phpunit/fonts-library/class-wp-rest-fonts-library-controller-test.php ❔ lib/load.php ❔ phpunit/multisite.xml |
… the class produces Font Family Objects
…nberg into try/fonts-library-backend
WP Core registers all post types in `create_initial_post_types()`. The code for registering will be placed within that global function. This commit removes the WP_Fonts_Library static method and moves the code into the gutenberg_init_fonts_library() function. This is done to prepare the Fonts Library for and ease work in merging into Core.
This function will only exists in Gutenberg, thus it does not the guard to protect it from the same function in Core (that is once the Fonts Library is merged into Core).
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.
Overall, I think this PR is good enough as a first iteration on the Fonts Library backend. Follow-up PRs can address any needed changes for the frontend work, security, tests, etc.
For example, I'll follow-up with a PR that breaks the tests into separate test classes for each method. But this work is not a blocker for this PR.
Great work @matiasbenedetto and everyone!
Everyone, By default the src files in this PR will not load into memory. This is on purpose as the backend for the Fonts Library isn't needed until the frontend work is merged. To run this code, you'll need to add a constant to your define( 'FONTS_LIBRARY_ENABLE', true ); This constant will load the Fonts Library and Font Face, while not loading Fonts API. Use this constant in your local testing and for follow-up PRs. The PHPUnit tests do run locally and in the GitHub CI jobs as the constant is added in the |
Thanks, everyone for the the reviews, ideas and commits. ❤️ |
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 noticed this error yesterday, but I thought it would be visible if I simply left a comment (as I didn't have time to review this yesterday). It appears that the comment is not visible unless I submit a code review :( . So, yesterday, I spotted this typo, @matiasbenedetto .
lib/experimental/fonts-library/class-wp-rest-fonts-library-controller.php
Show resolved
Hide resolved
This, together with #53307, will probably need a dev note when included in the next major WordPress release. |
What?
Backend for Fonts Library
Why?
You can see screencasts of the intended frontend in this previous PR.
How?
This PR adds the following classes:
WP_Fonts_Library
Can define the folder where the font assets should be written.
Register the
wp_font_family
custom post type.Will provide extensibility options in stage 2.
WP_Fonts_Library_Controller
Add the endpoints to interact with the Fonts Library from the frontend. These are the endpoints:
/wp-json/wp/v2/fonts
. Receives font family definitions to be installed. It has 2 parameters:fontFamilies
andfiles
./wp-json/wp/v2/fonts
. Receive the slug of the font family to be uninstalled.WP_Font_Family
This class is used to create a
WP_Font_Family
object constructed using font family data in thetheme.json
format.The
WP_Font_Family
has 2 main capabilities:install()
: Creates a post of thewp_font_family
type. The content of the post is the font family definition in thetheme.json
format. It also writes the font face assets in the
/wp-content/upload/fonts
directory.uninstall()
: Removed the post containing the font definition and all the font face assets of the family.WP_Font_Family_Utils
Set of static helper methods for the WP_Font_Family class.
More info: