diff --git a/lib/experimental/class-wp-webfonts.php b/lib/experimental/class-wp-webfonts.php index 8ebbb027176b5..d4a73c77cc2d2 100644 --- a/lib/experimental/class-wp-webfonts.php +++ b/lib/experimental/class-wp-webfonts.php @@ -120,7 +120,7 @@ public function get_providers() { * * @since 6.0.0 * - * @param array $webfont The font argument. + * @param array $webfont Webfont to be registered. * @return bool True if successfully registered, else false. */ public function register_webfont( array $webfont ) { diff --git a/lib/experimental/register-webfonts-from-theme-json.php b/lib/experimental/register-webfonts-from-theme-json.php index 68d38a9042bff..3282a9eaebbc0 100644 --- a/lib/experimental/register-webfonts-from-theme-json.php +++ b/lib/experimental/register-webfonts-from-theme-json.php @@ -42,7 +42,7 @@ function gutenberg_register_webfonts_from_theme_json() { foreach ( $font_face['src'] as $src_key => $url ) { // Tweak the URL to be relative to the theme root. - if ( 0 !== strpos( $url, 'file:./' ) ) { + if ( ! str_starts_with( $url, 'file:./' ) ) { continue; } $font_face['src'][ $src_key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) ); @@ -71,7 +71,6 @@ function gutenberg_register_webfonts_from_theme_json() { * Add missing fonts data to the global styles. * * @param array $data The global styles. - * * @return array The global styles with missing fonts data. */ function gutenberg_add_registered_webfonts_to_theme_json( $data ) { @@ -85,10 +84,9 @@ function gutenberg_add_registered_webfonts_to_theme_json( $data ) { * Helper to get an array of the font-families. * * @param array $families_data The font-families data. - * * @return array The font-families array. */ - $get_families = function( $families_data ) { + $get_families = static function( $families_data ) { $families = array(); foreach ( $families_data as $family ) { $families[] = WP_Webfonts::get_font_slug( $family ); @@ -137,7 +135,7 @@ function gutenberg_add_registered_webfonts_to_theme_json( $data ) { } $data['settings']['typography']['fontFamilies'][] = array( - 'fontFamily' => false !== strpos( $family_name, ' ' ) ? "'{$family_name}'" : $family_name, + 'fontFamily' => str_contains( $family_name, ' ' ) ? "'{$family_name}'" : $family_name, 'name' => $family_name, 'slug' => $slug, 'fontFace' => $font_faces, diff --git a/lib/experimental/webfonts.php b/lib/experimental/webfonts.php index 8d4fb91534e0c..6d4c5f8dcc12b 100644 --- a/lib/experimental/webfonts.php +++ b/lib/experimental/webfonts.php @@ -60,11 +60,11 @@ function wp_webfonts() { * * @since 6.0.0 * - * @param array $webfonts Webfonts to be registered. + * @param array[] $webfonts Webfonts to be registered. * This contains an array of webfonts to be registered. * Each webfont is an array. */ - function wp_register_webfonts( array $webfonts = array() ) { + function wp_register_webfonts( array $webfonts ) { foreach ( $webfonts as $webfont ) { wp_register_webfont( $webfont ); } @@ -94,9 +94,10 @@ function wp_register_webfonts( array $webfonts = array() ) { * @since 6.0.0 * * @param array $webfont Webfont to be registered. + * @return bool True if successfully registered, else false. */ function wp_register_webfont( array $webfont ) { - wp_webfonts()->register_webfont( $webfont ); + return wp_webfonts()->register_webfont( $webfont ); } } @@ -119,7 +120,7 @@ function wp_register_webfont( array $webfont ) { * * @param string[] $webfonts Font families to be enqueued. */ - function wp_enqueue_webfonts( $webfonts ) { + function wp_enqueue_webfonts( array $webfonts ) { foreach ( $webfonts as $webfont ) { wp_enqueue_webfont( $webfont ); } @@ -140,10 +141,11 @@ function wp_enqueue_webfonts( $webfonts ) { * * @since 6.0.0 * - * @param string $webfont Font family to be enqueued. + * @param string $font_family_name The font family name to be enqueued. + * @return bool True if successfully enqueued, else false. */ - function wp_enqueue_webfont( $webfont ) { - wp_webfonts()->enqueue_webfont( $webfont ); + function wp_enqueue_webfont( $font_family_name ) { + return wp_webfonts()->enqueue_webfont( $font_family_name ); } } diff --git a/phpunit/class-wp-webfonts-test.php b/phpunit/class-wp-webfonts-test.php index 1ab14f6cd4f3b..4292747f475b2 100644 --- a/phpunit/class-wp-webfonts-test.php +++ b/phpunit/class-wp-webfonts-test.php @@ -367,7 +367,7 @@ public function test_validate_webfont() { * * @covers WP_Webfonts::generate_and_enqueue_styles */ - public function test_generate_styles() { + public function test_generate_and_enqueue_styles() { wp_register_webfonts( array( array(