函数文档

wp_print_font_faces_from_style_variations()

💡 云策文档标注

概述

wp_print_font_font_faces_from_style_variations() 函数用于生成并打印主题样式变体中定义的字体样式。它通过解析样式变体获取字体数据,并调用 wp_print_font_faces() 输出 font-face 样式。

关键要点

  • 函数调用 WP_Font_Face_Resolver::get_fonts_from_style_variations() 从主题样式变体中获取字体数据。
  • 如果字体数据为空,函数直接返回;否则,将数据传递给 wp_print_font_faces() 进行样式生成和打印。
  • 该函数在 WordPress 6.7.0 版本中引入,主要用于支持块编辑器 iframe 中的字体加载。

代码示例

function wp_print_font_faces_from_style_variations() {
	$fonts = WP_Font_Face_Resolver::get_fonts_from_style_variations();

	if ( empty( $fonts ) ) {
		return;
	}

	wp_print_font_faces( $fonts );
}

注意事项

  • 函数依赖于 WP_Font_Face_Resolver 类和 wp_print_font_faces() 函数,确保这些组件在调用前已正确加载。
  • 主要用于 _wp_get_iframed_editor_assets() 函数中,以在块编辑器 iframe 中加载字体资源。

📄 原文内容

Generates and prints font-face styles defined the the theme style variations.

Source

function wp_print_font_faces_from_style_variations() {
	$fonts = WP_Font_Face_Resolver::get_fonts_from_style_variations();

	if ( empty( $fonts ) ) {
		return;
	}

	wp_print_font_faces( $fonts );
}

Changelog

Version Description
6.7.0 Introduced.