automattic / jetpack-google-fonts-provider
WordPress Webfonts 为 Google Fonts 提供商
Requires
- php: >=7.0
Requires (Dev)
- automattic/jetpack-changelogger: ^4.2.5
- brain/monkey: 2.6.1
- yoast/phpunit-polyfills: 1.1.0
Suggests
- automattic/jetpack-autoloader: Allow for better interoperability with other plugins that use this package.
README
Jetpack Google Fonts Provider 包
WordPress Webfonts 为 Google Fonts 提供商
注意
此包已被废弃。它依赖于 Gutenberg 插件在 v12.8.0 到 v16.3.0 版本之间提供的 API,该 API 从未集成到 WordPress 核心中,并且现在在 Gutenberg 中也无法使用。
如何安装 google-fonts-provider
该包在 Packagist 上发布。我们建议使用那里的最新版本。您可以使用以下命令在 composer 管理的项目中安装它:composer require automattic/jetpack-google-fonts-provider
。
您也可以使用以下方式测试最新开发版本
"require": { "automattic/jetpack-google-fonts-provider": "dev-trunk" }
使用方法
通过激活 Gutenberg 插件,WordPress Webfonts API 即可用,并计划在 WordPress 6.0 中包含。
注册提供商
此包包含提供者类,但在使用之前需要注册提供者。
wp_register_webfont_provider( 'google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' );
注册字体
注册提供者后,您可以将 Google Fonts 目录中可用的任何字体注册为可用,以便在块编辑器字体设置、全局样式和您网站的 CSS 中使用。
wp_register_webfont( array( 'font-family' => 'Lato', 'provider' => 'google-fonts', ), );
添加预连接链接
将预连接链接添加到页面 <head>
中将有助于确保字体文件尽快加载,并在显示时减少布局偏移。有关更多详细信息,请参阅 此列表中的 Webfont 最佳实践。为此,我们可以依赖 WordPress 的 wp_resource_hints
过滤器,如下所示
add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Utils::font_source_resource_hint', 10, 2 );
其他信息
有关 WordPress 中 Webfonts API 的讨论,请参阅 https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-wordpress-core/。
在您的 WordPress 插件中使用此包
如果您计划在您的 WordPress 插件中使用此包,我们建议您使用 Jetpack Autoloader 作为您的自动加载器。这将允许与其他使用此包的插件最大程度地兼容。
安全性
需要报告安全漏洞?请访问 https://automattic.com/security/ 或直接访问我们的安全漏洞赏金网站 https://hackerone.com/automattic。
许可证
Jetpack Google Fonts Provider 使用 GNU 通用公共许可证 v2(或更新版本) 许可