WP_Font_Face::generate_and_print
Generates and prints the @font-face styles for the given fonts.
Method of the class: WP_Font_Face{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WP_Font_Face = new WP_Font_Face(); $WP_Font_Face->generate_and_print( $fonts );
- $fonts(array[][]) (required)
- The font-families and their font variations. See wp_print_font_faces() for the supported fields.
Default:empty array
Changelog
| Since 6.4.0 | Introduced. |
WP_Font_Face::generate_and_print() WP Font Face::generate and print code WP 7.0
public function generate_and_print( array $fonts ) {
$fonts = $this->validate_fonts( $fonts );
// Bail out if there are no fonts are given to process.
if ( empty( $fonts ) ) {
return;
}
$css = $this->get_css( $fonts );
/*
* The font-face CSS is contained within <style> tags and can only be interpreted
* as CSS in the browser. Using wp_strip_all_tags() is sufficient escaping
* to avoid malicious attempts to close </style> and open a <script>.
*/
$css = wp_strip_all_tags( $css );
// Bail out if there is no CSS to print.
if ( empty( $css ) ) {
return;
}
$processor = new WP_HTML_Tag_Processor( '<style class="wp-fonts-local"></style>' );
$processor->next_tag();
$processor->set_modifiable_text( "\n{$css}\n" );
echo "{$processor->get_updated_html()}\n";
}