WP_Font_Face::order_src
Orders src items to optimize for browser support.
Method of the class: WP_Font_Face{}
No Hooks.
Returns
Array
. Font-face with ordered src items.
Usage
// private - for code of main (parent) class only $result = $this->order_src( $font_face );
- $font_face(array) (required)
- Font face to process.
Changelog
Since 6.4.0 | Introduced. |
WP_Font_Face::order_src() WP Font Face::order src code WP 6.8.1
private function order_src( array $font_face ) { if ( ! is_array( $font_face['src'] ) ) { $font_face['src'] = (array) $font_face['src']; } $src = array(); $src_ordered = array(); foreach ( $font_face['src'] as $url ) { // Add data URIs first. if ( str_starts_with( trim( $url ), 'data:' ) ) { $src_ordered[] = array( 'url' => $url, 'format' => 'data', ); continue; } $format = pathinfo( $url, PATHINFO_EXTENSION ); $src[ $format ] = $url; } // Add woff2. if ( ! empty( $src['woff2'] ) ) { $src_ordered[] = array( 'url' => $src['woff2'], 'format' => 'woff2', ); } // Add woff. if ( ! empty( $src['woff'] ) ) { $src_ordered[] = array( 'url' => $src['woff'], 'format' => 'woff', ); } // Add ttf. if ( ! empty( $src['ttf'] ) ) { $src_ordered[] = array( 'url' => $src['ttf'], 'format' => 'truetype', ); } // Add eot. if ( ! empty( $src['eot'] ) ) { $src_ordered[] = array( 'url' => $src['eot'], 'format' => 'embedded-opentype', ); } // Add otf. if ( ! empty( $src['otf'] ) ) { $src_ordered[] = array( 'url' => $src['otf'], 'format' => 'opentype', ); } $font_face['src'] = $src_ordered; return $font_face; }