| 1 |
<?php |
| 2 |
/** |
| 3 |
* Module Name: Google Fonts (Beta) |
| 4 |
* Module Description: A selection of Google fonts for block enabled themes. This feature is still being developed. |
| 5 |
* Sort Order: 1 |
| 6 |
* Recommendation Order: 2 |
| 7 |
* First Introduced: 10.8.0 |
| 8 |
* Requires Connection: No |
| 9 |
* Auto Activate: No |
| 10 |
* Module Tags: Fonts, Recommended |
| 11 |
* Feature: Writing |
| 12 |
* Additional Search Queries: fonts, webfonts, typography |
| 13 |
* |
| 14 |
* @package automattic/jetpack |
| 15 |
*/ |
| 16 |
|
| 17 |
/** |
| 18 |
* Curated list of Google Fonts |
| 19 |
* See https://wp.me/p9Jlb4-22P |
| 20 |
*/ |
| 21 |
const JETPACK_GOOGLE_FONTS_LIST = array( |
| 22 |
'Arvo', |
| 23 |
'Bodoni Moda', |
| 24 |
'Cabin', |
| 25 |
'Chivo', |
| 26 |
'Courier Prime', |
| 27 |
'DM Sans', |
| 28 |
'Domine', |
| 29 |
'EB Garamond', |
| 30 |
'Fira Sans', |
| 31 |
'Inter', |
| 32 |
'Josefin Sans', |
| 33 |
'Libre Baskerville', |
| 34 |
'Libre Franklin', |
| 35 |
'Lora', |
| 36 |
'Merriweather', |
| 37 |
'Montserrat', |
| 38 |
'Nunito', |
| 39 |
'Open Sans', |
| 40 |
'Overpass', |
| 41 |
'Playfair Display', |
| 42 |
'Poppins', |
| 43 |
'Raleway', |
| 44 |
'Roboto', |
| 45 |
'Roboto Slab', |
| 46 |
'Rubik', |
| 47 |
'Source Sans Pro', |
| 48 |
'Source Serif Pro', |
| 49 |
'Space Mono', |
| 50 |
'Work Sans', |
| 51 |
); |
| 52 |
|
| 53 |
/** |
| 54 |
* Register a curated selection of Google Fonts. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
function jetpack_add_google_fonts_provider() { |
| 59 |
if ( ! function_exists( 'wp_register_webfont_provider' ) || ! function_exists( 'wp_register_webfonts' ) ) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
wp_register_webfont_provider( 'jetpack-google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' ); |
| 64 |
|
| 65 |
/** |
| 66 |
* Curated list of Google Fonts. |
| 67 |
* |
| 68 |
* @module google-fonts |
| 69 |
* |
| 70 |
* @since 10.8 |
| 71 |
* |
| 72 |
* @param array $fonts_to_register Array of Google Font names to register. |
| 73 |
*/ |
| 74 |
$fonts_to_register = apply_filters( 'jetpack_google_fonts_list', JETPACK_GOOGLE_FONTS_LIST ); |
| 75 |
|
| 76 |
foreach ( $fonts_to_register as $font_family ) { |
| 77 |
wp_register_webfonts( |
| 78 |
array( |
| 79 |
array( |
| 80 |
'font-family' => $font_family, |
| 81 |
'font-weight' => '100 900', |
| 82 |
'font-style' => 'normal', |
| 83 |
'font-display' => 'fallback', |
| 84 |
'provider' => 'jetpack-google-fonts', |
| 85 |
), |
| 86 |
array( |
| 87 |
'font-family' => $font_family, |
| 88 |
'font-weight' => '100 900', |
| 89 |
'font-style' => 'italic', |
| 90 |
'font-display' => 'fallback', |
| 91 |
'provider' => 'jetpack-google-fonts', |
| 92 |
), |
| 93 |
) |
| 94 |
); |
| 95 |
} |
| 96 |
} |
| 97 |
add_action( 'after_setup_theme', 'jetpack_add_google_fonts_provider' ); |
| 98 |
|
| 99 |
add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Utils::font_source_resource_hint', 10, 2 ); |
| 100 |
|