Skip to content

Conversation

@jeherve
Copy link
Member

@jeherve jeherve commented Mar 9, 2022

Follow-up from #23045
Fixes #23306

Changes proposed in this Pull Request:

Instead of manually outputting a link to the head, let's rely on a Core filter, wp_resource_hints, to take care of that for us.
Let's take that opportunity to ensure we only do that when the Webfonts API is supported on the site.

Jetpack product discussion

  • N/A

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

  • No

Testing instructions:

@jeherve jeherve added this to the jetpack/10.8 milestone Mar 9, 2022
@jeherve jeherve added [Package] Google Fonts Provider This package no longer exists in the monorepo. [Pri] Normal [Status] Needs Review This PR is ready for review. [Type] Bug When a feature is broken and / or not performing as intended labels Mar 9, 2022
@jeherve jeherve self-assigned this Mar 9, 2022
@jeherve jeherve requested a review from creativecoder March 9, 2022 09:10
@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Mar 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 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: April 5, 2022.
  • Scheduled code freeze: March 29, 2022.

Copy link
Contributor

@creativecoder creativecoder left a comment

Choose a reason for hiding this comment

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

This works great. TIL about wp_resource_hints!

Copy link
Contributor

@creativecoder creativecoder left a comment

Choose a reason for hiding this comment

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

Spoke too soon 🙂. This works great for adding the preconnect link, but we still need a check before adding the filter.


// Run on an early priority to print out the preconnect link tag near the start of the page source.
add_action( 'wp_head', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider::preconnect_font_source', 0 );
add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider::font_source_resource_hint', 10, 2 );
Copy link
Contributor

Choose a reason for hiding this comment

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

If Gutenberg is disabled, I'm seeing PHP Warning: Invalid argument supplied for foreach() in /Users/Grant/Automattic/Sites/wordpress-develop/src/wp-includes/general-template.php on line 3346, as the font_source_resource_hint method is not available to hook into.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, because the parent class of Google_Fonts_Provider isn't available. What do you think about creating a new class that won't depend on WP_Webfonts_Provider. Would that be overkill? The approach you took in the other PR works, but I'm thinking doing things with a new class, and doing the WP_Webfonts_Provider check in there, would simplify things for folks having to implement that filtering.

What do you think?

jeherve and others added 3 commits March 10, 2022 12:55
WP_Webfonts_Provider may not always be available, so we cannot call a method from a child class of `WP_Webfonts_Provider` from a WP filter. Let's introduce a new class instead, that doesn't depend on anything, and do the class check inside there. That should simplify things a bit for the folks having to implement that filtering.
@kraftbj kraftbj enabled auto-merge (squash) March 14, 2022 21:30
@kraftbj kraftbj added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Mar 14, 2022
@kraftbj kraftbj merged commit 212b4d7 into master Mar 14, 2022
@kraftbj kraftbj deleted the update/google-fonts-preconnect branch March 14, 2022 21:34
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 14, 2022
@creativecoder
Copy link
Contributor

Sorry for the delay in me getting back to this... thanks for taking care of it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Google Fonts Provider This package no longer exists in the monorepo. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal [Type] Bug When a feature is broken and / or not performing as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants