|
<?php |
|
/** |
|
* Plugin Name: Web API Plugin Tester |
|
* Plugin URI: https://github.com/test/test |
|
* Description: Tests a plugin interacting with the API. Uses Jetpack's Google Fonts Provider package. |
|
* Requires at least: 5.9 |
|
* Requires PHP: 5.6 |
|
* Version: 1.0.0 |
|
* Author: Gutenberg Team |
|
*/ |
|
|
|
require_once __DIR__ . '/vendor/autoload.php'; |
|
|
|
/** |
|
* Checks if this plugin should register web fonts definition using the |
|
* deprecated (original) array structure. |
|
* |
|
* To enable, add `&webfonts_deprecated=1` to the site's URL and refresh the page. |
|
* |
|
* @return bool |
|
*/ |
|
function _use_deprecated_wdebfonts_structure() { |
|
return ( isset( $_REQUEST['webfonts_deprecated'] ) && $_REQUEST['webfonts_deprecated'] ); |
|
} |
|
|
|
add_action( |
|
'after_setup_theme', |
|
function() { |
|
if ( ! function_exists( 'wp_register_webfont_provider' ) ) { |
|
return; |
|
} |
|
|
|
|
|
$use_deprecated = _use_deprecated_wdebfonts_structure(); |
|
wp_register_webfont_provider( 'jetpack-google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' ); |
|
|
|
$fonts_to_register = array( |
|
'Arvo', |
|
'Lato', |
|
'Merriweather', |
|
'Playfair Display', |
|
'Roboto', |
|
); |
|
|
|
$webfonts = array(); |
|
|
|
foreach ( $fonts_to_register as $font_family ) { |
|
if ( $use_deprecated ) { |
|
// Original API > deprecated webfonts structure. |
|
$webfonts[] = array( |
|
'font-family' => $font_family, |
|
'font-weight' => '100 900', |
|
'font-style' => 'normal', |
|
'font-display' => 'fallback', |
|
'provider' => 'jetpack-google-fonts', |
|
); |
|
$webfonts[] = array( |
|
'font-family' => $font_family, |
|
'font-weight' => '100 900', |
|
'font-style' => 'italic', |
|
'font-display' => 'fallback', |
|
'provider' => 'jetpack-google-fonts', |
|
); |
|
|
|
} else { |
|
// New API. |
|
$webfonts[ $font_family ] = array( |
|
array( |
|
'font-family' => $font_family, |
|
'font-weight' => '100 900', |
|
'font-style' => 'normal', |
|
'font-display' => 'fallback', |
|
'provider' => 'jetpack-google-fonts', |
|
), |
|
array( |
|
'font-family' => $font_family, |
|
'font-weight' => '100 900', |
|
'font-style' => 'italic', |
|
'font-display' => 'fallback', |
|
'provider' => 'jetpack-google-fonts', |
|
), |
|
); |
|
} |
|
} |
|
|
|
wp_register_webfonts( $webfonts ); |
|
} |
|
); |
|
|
|
add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Utils::font_source_resource_hint', 10, 2 ); |
|
add_filter( 'pre_render_block', '\Automattic\Jetpack\Fonts\Introspectors\Blocks::enqueue_block_fonts', 10, 2 ); |
|
add_action( 'init', '\Automattic\Jetpack\Fonts\Introspectors\Global_Styles::enqueue_global_styles_fonts', 22 ); |
|
|
|
if ( ! function_exists( 'gutenberg_get_global_styles' ) ) { |
|
/** |
|
* Polyfill: Jetpack's package uses the Gutenberg function instead of |
|
* the WordPress Core function. The function was removed from Gutenberg |
|
* when `lib/compat/wordpress-6.0/` was removed. |
|
* |
|
* Function to get the styles resulting of merging core, theme, and user data. |
|
* |
|
* @param array $path Path to the specific style to retrieve. Optional. |
|
* If empty, will return all styles. |
|
* @param array $context { |
|
* Metadata to know where to retrieve the $path from. Optional. |
|
* |
|
* @type string $block_name Which block to retrieve the styles from. |
|
* If empty, it'll return the styles for the global context. |
|
* @type string $origin Which origin to take data from. |
|
* Valid values are 'all' (core, theme, and user) or 'base' (core and theme). |
|
* If empty or unknown, 'all' is used. |
|
* } |
|
* |
|
* @return array The styles to retrieve. |
|
*/ |
|
function gutenberg_get_global_styles( $path = array(), $context = array() ) { |
|
return wp_get_global_styles( $path, $context ); |
|
} |
|
} |