-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Google Fonts: update the method used to preconnect Fonts source domai…
…n. (#23322) * Google Fonts: update method used to preconnect Fonts source domain Follow-up to #23045 Let's favor using a Core implementation with a Core filter instead of manually adding to the head. * Use filter instead of action * Only add resource hint if the site supports the Webfonts API See #23306 * Update readme with latest method name. * Introduce new class that doesn't depend on WP_Webfonts_Provider 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. Co-authored-by: Brandon Kraft <[email protected]>
- Loading branch information
Showing
10 changed files
with
97 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/packages/google-fonts-provider/changelog/update-google-fonts-preconnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: deprecated | ||
|
||
Google Fonts: update the method used to preconnect Fonts source domain. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
projects/packages/google-fonts-provider/src/class-utils.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Google Fonts package Utils class file. | ||
* | ||
* @package automattic/jetpack-google-fonts-provider | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Fonts; | ||
|
||
/** | ||
* Provides utility methods for the Google Fonts Provider package. | ||
*/ | ||
class Utils { | ||
/** | ||
* Adds a preconnect link for improving performance when downloading Google Font files. | ||
* Only do so if the site supports the Webfonts API. | ||
* | ||
* @param array $urls Array of resources and their attributes, or URLs to print for resource hints. | ||
* @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. | ||
*/ | ||
public static function font_source_resource_hint( $urls, $relation_type ) { | ||
if ( | ||
'preconnect' === $relation_type | ||
&& class_exists( 'WP_Webfonts_Provider' ) | ||
) { | ||
$urls[] = array( | ||
'href' => 'https://fonts.gstatic.com', | ||
'crossorigin', | ||
); | ||
} | ||
|
||
return $urls; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-google-fonts-preconnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
Google Fonts: update the method used to preconnect Fonts source domain. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters