Skip to content

Conversation

@creativecoder
Copy link
Contributor

@creativecoder creativecoder commented Apr 14, 2022

Changes proposed in this Pull Request:

  • Updates the Google Fonts module to be compatible with the most recent version of the WP_Webfonts API.
  • Registered fonts are no longer enqueued by default, so we add hooks that enqueue Google Fonts used in block and Global Styles settings so those fonts load.
  • This prevents dozens of font-face declarations from being printed out in the HTML source for unused fonts.

Jetpack product discussion

n/a

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

No.

Testing instructions:

  • On a site with the most recent version of Gutenberg active, enable the Google Fonts module (/wp-admin/admin.php?page=jetpack_modules).
  • With a block theme enabled, to the Site editor.
  • Go to Global styles and choose a Google Font from the Font family settings for all Text.
  • Go to the Blocks settings in Global styles and choose a different Google Font for the font family setting for all blocks of that type, like Buttons (makes sure you have an instance of that block on the page).
  • Select an individual block's settings and set yet another Google font for that individual block (like a List block... not all blocks have Font family settings, it partly depends on the theme).
  • Now load the the page you were editing in the front end... make sure all of the fonts you selected are loaded. I do this by viewing the Network tab in browser tools and filtering for Fonts, or the filtering for the fonts.gstatic.com domain.

@creativecoder creativecoder self-assigned this Apr 14, 2022
@creativecoder creativecoder marked this pull request as draft April 14, 2022 22:56
@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 Apr 14, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2022

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.
  • ✅ All commits were linted before commit.
  • ✅ 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 you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: May 3, 2022.
  • Scheduled code freeze: April 25, 2022.

@creativecoder creativecoder removed the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Apr 14, 2022
@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Apr 14, 2022
@creativecoder creativecoder added [Feature] Google Fonts [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Apr 14, 2022
@zaguiini
Copy link
Contributor

Thank you! Left some comments in #23810 (comment)

@creativecoder creativecoder added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Apr 23, 2022
@creativecoder creativecoder requested review from a team and jeherve April 23, 2022 01:37
@creativecoder creativecoder marked this pull request as ready for review April 23, 2022 01:39
@coder-karen coder-karen added this to the jetpack/10.9 milestone Apr 25, 2022
Copy link
Contributor

@sdixon194 sdixon194 left a comment

Choose a reason for hiding this comment

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

Had to do some fixing up with the versions, but this works for me 👍

@sdixon194 sdixon194 enabled auto-merge (squash) April 25, 2022 16:41
@sdixon194 sdixon194 merged commit dd4f755 into master Apr 25, 2022
@sdixon194 sdixon194 deleted the update/enqueue-used-google-fonts branch April 25, 2022 16:55
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Apr 25, 2022
@jeyip jeyip restored the update/enqueue-used-google-fonts branch April 25, 2022 18:36
@jeyip
Copy link
Contributor

jeyip commented Apr 25, 2022

Testing

I tested by applying Merriweather to global styles typography, Space Mono to button block-level global styles, and Raleway to a specific instance of a site title block's font family settings.

Requirements

Block Settings

  • Font family selected from block settings applies only to specific block instance
  • Font family displays properly in editor
  • Font family displays properly in frontend
  • Font family request is visible in network tab of chrome dev tools
  • Block settings override global styles block-level settings

Global Styles Block-Level Settings

  • Font family selected from block settings applies only to the selected blocks
  • Font family displays properly in editor
  • Font family displays properly in frontend
  • Font family request is visible in network tab of chrome dev tools

Global Styles

  • Selected font family modifies all fonts for non-heading blocks
  • Font family displays properly in editor
  • Font family displays properly in frontend
  • Font family request is visible in network tab of chrome dev tools

Browsers

  • Chrome

@jeyip jeyip deleted the update/enqueue-used-google-fonts branch April 25, 2022 18:59
* @return void
*/
public static function enqueue_global_styles_fonts() {
if ( is_admin() || ! function_exists( 'wp_enqueue_webfont' ) ) {
Copy link
Contributor

@jeyip jeyip Apr 25, 2022

Choose a reason for hiding this comment

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

Non-blocking: This might be a silly question, but would you mind explaining the is_admin() condition here? I thought that we wanted to enqueue all fonts in the site editor? I'm assuming that it's already being done elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Answering now for posterity (sorry I missed this initially!): this is because the all the fonts are already enqueued in wp-admin views (at least in the editor) by Gutenberg, so there's no need to run this function in that context.

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.

7 participants