Skip to content
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

Merged
merged 174 commits into from
Aug 11, 2023
Merged

Fonts Library: Backend #52704

merged 174 commits into from
Aug 11, 2023

Conversation

matiasbenedetto
Copy link
Contributor

@matiasbenedetto matiasbenedetto commented Jul 17, 2023

What?

Backend for Fonts Library

Why?

The Font Library consists of a font manager for WordPress. The Font Library is available globally, independently of the theme activated, similar to the Media Library. This list of installed fonts and their assets are site-wide available and the users can select the fonts activated (available in the editor) for each theme.

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:

  • POST /wp-json/wp/v2/fonts. Receives font family definitions to be installed. It has 2 parameters: fontFamilies and files.
  • DELETE /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 the theme.json format.
The WP_Font_Family has 2 main capabilities:

  • install(): Creates a post of the wp_font_family type. The content of the post is the font family definition in the theme.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:

@github-actions
Copy link

github-actions bot commented Jul 17, 2023

Flaky tests detected in 82968c9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5824433675
📝 Reported issues:

@github-actions
Copy link

github-actions bot commented Jul 18, 2023

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

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.
hellofromtonya and others added 4 commits August 10, 2023 12:48
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).
Copy link
Contributor

@hellofromtonya hellofromtonya left a 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!

@hellofromtonya
Copy link
Contributor

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 wp-config.php file:

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 phpunit.xml.dist file. So in your PRs and locally, the Fonts Library code will run.

@matiasbenedetto
Copy link
Contributor Author

Thanks, everyone for the the reviews, ideas and commits. ❤️
I'm merging this. Follow-up issues and PR's are welcome!

@matiasbenedetto matiasbenedetto merged commit 69d9ca3 into trunk Aug 11, 2023
50 checks passed
@matiasbenedetto matiasbenedetto deleted the try/fonts-library-backend branch August 11, 2023 15:06
@github-actions github-actions bot added this to the Gutenberg 16.5 milestone Aug 11, 2023
Copy link
Contributor

@anton-vlasenko anton-vlasenko left a 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 .

@priethor priethor added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Aug 18, 2023
@priethor
Copy link
Contributor

This, together with #53307, will probably need a dev note when included in the next major WordPress release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Experimental Experimental feature or API.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.