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

Google Fonts: Integrate with new font library #33203

Merged
merged 16 commits into from
Oct 19, 2023

Conversation

arthur791004
Copy link
Contributor

@arthur791004 arthur791004 commented Sep 20, 2023

Related to Automattic/wp-calypso#81875

Proposed changes:

image

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Create a Jurassic Ninja sandbox against this PR.
  • Install the latest Gutenberg, e.g.: v16.7.0-rc.1
  • Go to /wp-admin/admin.php?page=jetpack_modules to activate the “Google Fonts (Beta)” module
  • Go to the Site Editor
  • Select Styles > Typography > Text > Font
  • Ensure you're able to see all Google Fonts in the list
  • Disable the Gutenberg plugin
  • Select Styles > Typography > Text > Font again
  • Ensure you can still see all Google Fonts in the list

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the feat/google-fonts-with-new-font-library branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack feat/google-fonts-with-new-font-library
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Package] Google Fonts Provider This package no longer exists in the monorepo. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Sep 20, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

  • Next scheduled release: November 7, 2023.
  • Scheduled code freeze: October 30, 2023.

@arthur791004 arthur791004 force-pushed the feat/google-fonts-with-new-font-library branch 3 times, most recently from 9b2459c to efbdf69 Compare September 20, 2023 11:19
@pbking
Copy link

pbking commented Sep 26, 2023

At first shake I notice:

Enabling and dis-abling this module causes the fonts introduced by this module to stick around.
Changing what fonts are in the list don't cause fonts added to be removed from the Global Styles list.
It did seem to remove them from other lists?

I didn't test a lot of scenarios though, just tinkered with it for a bit.

Ultimately this seems like a lot of logic in place for something the Font Library should be doing; I'm concerned that if this is they way Jetpack would augment the Font Library then the pipes to work with the Font Library aren't quite right yet. I would rather try to do this more simply while the Font Library is relatively malleable.

Ideally:

The module could provide a list of fonts to make available with a .json file.
These fonts point to remote locations for the assets (as outlined here)
to take advantage of publicly available CDNs OR
(I think more useful) include local references to the fonts (just like themes do).
(just as with themes) changing the collection in the .json file changes what fonts are available to the user.
Fonts that the user has used in content or Global Styles settings are automatically activated.

@arthur791004
Copy link
Contributor Author

Enabling and dis-abling this module causes the fonts introduced by this module to stick around.
Changing what fonts are in the list don't cause fonts added to be removed from the Global Styles list.
It did seem to remove them from other lists?

Yes, so I'd prefer to keep the Google Fonts invisible on the Font Library modal in the current iteration to avoid people controlling the fonts from the Jetpack. I'm not sure whether the Google Fonts module has to remove the added fonts from the Global Styles when disabling this module (and is it possible?).

The module could provide a list of fonts to make available with a .json file.
These fonts point to remote locations for the assets (as outlined here)
to take advantage of publicly available CDNs OR
(I think more useful) include local references to the fonts (just like themes do).

Yep, I just noticed we have the collection of the JSON file but my concern is the downloadFromUrl might be changed by Google. Is it correct? Or is the asset URL available forever?

Maybe keeping the font assets in the Jetpack repo makes more sense but I'm unsure whether Jetpack allows us to add those font assets 🤔

@arthur791004 arthur791004 changed the title WIP Google Fonts: Integrate with new font library Google Fonts: Integrate with new font library Oct 4, 2023
@arthur791004
Copy link
Contributor Author

@pbking I've created a JSON file of the font collection here and now this module loads the data from the remote and injects the fonts we want to the default global styles settings!

@arthur791004 arthur791004 force-pushed the feat/google-fonts-with-new-font-library branch from 33ffa44 to 7910c08 Compare October 16, 2023 03:17
@arthur791004 arthur791004 requested a review from jeherve October 16, 2023 03:17
@arthur791004 arthur791004 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Oct 16, 2023
require_once __DIR__ . '/current/load-google-fonts.php';
} elseif ( class_exists( 'WP_Fonts' ) || class_exists( 'WP_Webfonts' ) ) {
// WordPress 6.3 compat.
require_once __DIR__ . '/wordpress-6.3/load-google-fonts.php';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this "WordPress 6.3 compatible" isn't exactly correct.
It's more accurate to say that it's "Gutenberg Fonts API compatible" (since the API it leverages is available only in Gutenberg, that library MAY be available in other versions of WordPress, etc)

* @package automattic/jetpack
*/

if ( class_exists( 'WP_Font_Library' ) && class_exists( 'WP_Font_Face' ) && class_exists( 'WP_Font_Collection' ) ) {
Copy link

@pbking pbking Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Font Library won't be available in WordPress 6.4 since it's currently only available in Gutenberg. It's planned to be available in WordPress 6.5. However this technique IS available in situations other than WordPress 6.4 (or 6.5).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any changes I have to make here? I made a change to only check the WP_Font_Face class as I assume we still rely on it to generate and print font styles. WDYT?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class isn't actually used or depended on at all as the logic exists now, WP_Font_Collection WAS used but now that collection data is just loaded manually and the class isn't needed. The data provided in that file that is loaded is everything needed for the fonts to work; no extra logic needed. That allows the logic to be font library/api agnostic. Doing it like this means that it ONLY works in Gutenberg, wereas it COULD work WITHOUT Gutenberg. Considering that it HASN'T worked without Gutenberg in the past I don't know if that matters though.

So I guess the answer is "If you want this to work WITHOUT gutenberg it CAN you'll just need to change that if() logic a bit." "If you don't care for this to work without Gutenberg then it's fine and dandy as it is"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'll leave it as it is since it hasn't worked without Gutenberg in the past. I'd prefer to make it work without Gutenberg after WordPress 6.5 or above which supports the WP_Font_Face class.

jeherve
jeherve previously approved these changes Oct 18, 2023
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests well for me, and the changes make sense. I left a few nit-picks below, but nothing blocking (maybe the links, since we really try to stay away from private links in public repos in general?).

@jeherve jeherve removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Oct 18, 2023
@arthur791004
Copy link
Contributor Author

I left a few nit-picks below, but nothing blocking (maybe the links, since we really try to stay away from private links in public repos in general?).

Oh yes! We have to 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Google Fonts [Package] Google Fonts Provider This package no longer exists in the monorepo. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants