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

Font Library: Font Collection backend #54098

Merged
merged 52 commits into from
Aug 31, 2023
Merged

Conversation

matiasbenedetto
Copy link
Contributor

Follow up of the previous PR: #53816

What?

Add extensibility capabilities to the Font Library.
Provides a way to provide collections of typographic fonts by code.

Why?

  • Standardize the way to add font collections to the font library.
  • Allows extenders code (plugins, for example) to register lists of fonts to let the user install the ones they want. Font foundries, for example, will be able to create a plugin to provide their fonts with just a few lines of code.

Example:

This is all the code required to create a plugin providing a font collection.

<?php
/*
Plugin Name: My Font Collection
Plugin URI: https://your-website.com/
Description: Add a font collection to your WordPress Font Library.
Version: 1.0
Author: Your Name
Author URI: https://your-website.com/
License: GPLv2 or later
Text Domain: my-font-collection
*/

$my_config = array (
    'id'             => 'my-font-collection',
    'name'           => 'My Font Collection',
    'description'    => 'Demo about how to a font collection to your WordPress Font Library.',
    'data_json_file' => path_join( __DIR__, 'my-font-collection-data.json' ),
);

if ( function_exists( 'wp_register_font_collection' ) ) {
    wp_register_font_collection ( $my_config );
}

?>

Download the plugin as zip ready to test:
my-font-collection.zip

How?

  • Implementation of a WP_Font_Collection class.
  • Implementation of the wp_register_font_collection filter.
  • Implementation of the /fonts/collections and fonts/collections/<id> endpoints.

To do

Tracking issue:

Stage 1: #52698
Stage 2: #53307

matiasbenedetto and others added 30 commits August 18, 2023 12:35
Co-authored-by: Tonya Mork <[email protected]>
Co-authored-by: Tonya Mork <[email protected]>
* Ensures each required param is of the right data type.
* Improves each param check error to include expected data type.
* Rechecking if "data_json_file" exists in the $config property shouldn't be necessary,
  as it's checked in the constructor.

* If the file does not exist, bail out immediately as there's nothing more to do.

* Adds a check and WP_Error for file_get_contents():
file_get_contents() returns false on failure.
If there's nothing in the file, an empty string is returned.
This change checks for both of these conditions and returns a WP_Error if either happens.

* Internationalizes WP_Error error message for consistency in Core.
Co-authored-by: Tonya Mork <[email protected]>
…n, remove try catch and raise the error if needed
@github-actions
Copy link

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-collection.php
❔ phpunit/tests/fonts/font-library/wpFontCollection/__construct.php
❔ phpunit/tests/fonts/font-library/wpFontCollection/getData.php
❔ phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php
❔ phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollections.php
❔ phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php
❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/base.php
❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/getFontCollection.php
❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/getFontCollections.php
❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/registerRoutes.php
❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/uninstallFonts.php
❔ lib/experimental/fonts/font-library/class-wp-font-library.php
❔ lib/experimental/fonts/font-library/class-wp-rest-font-library-controller.php
❔ lib/experimental/fonts/font-library/font-library.php
❔ lib/load.php
❔ phpunit/tests/fonts/font-library/wpFontFamily/base.php
❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/installFonts.php

@matiasbenedetto matiasbenedetto added [Feature] Typography Font and typography-related issues and PRs [Type] Feature New feature to highlight in changelogs. labels Aug 31, 2023
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.

Coping my code review from PR #53816:

The source code LGTM 👍

The tests are good enough. I'll follow-up with a test improvement PR.

@hellofromtonya hellofromtonya enabled auto-merge (squash) August 31, 2023 20:38
@hellofromtonya hellofromtonya merged commit 607ef90 into trunk Aug 31, 2023
98 of 101 checks passed
@hellofromtonya hellofromtonya deleted the try/font-collections branch August 31, 2023 21:12
@github-actions github-actions bot added this to the Gutenberg 16.7 milestone Aug 31, 2023
@mikachan mikachan added the Needs PHP backport Needs PHP backport to Core label Sep 5, 2023
@youknowriad youknowriad added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Needs PHP backport Needs PHP backport to Core labels Feb 9, 2024
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 [Feature] Typography Font and typography-related issues and PRs [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants