Skip to content

Commit f5f8339

Browse files
hellofromtonyazaguiini
authored andcommitted
Updates from code review.
1 parent 03a4db8 commit f5f8339

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/experimental/class-wp-webfonts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function get_providers() {
120120
*
121121
* @since 6.0.0
122122
*
123-
* @param array $webfont The font argument.
123+
* @param array $webfont Webfont to be registered.
124124
* @return bool True if successfully registered, else false.
125125
*/
126126
public function register_webfont( array $webfont ) {

lib/experimental/register-webfonts-from-theme-json.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function gutenberg_register_webfonts_from_theme_json() {
4242

4343
foreach ( $font_face['src'] as $src_key => $url ) {
4444
// Tweak the URL to be relative to the theme root.
45-
if ( 0 !== strpos( $url, 'file:./' ) ) {
45+
if ( ! str_starts_with( $url, 'file:./' ) ) {
4646
continue;
4747
}
4848
$font_face['src'][ $src_key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
@@ -71,7 +71,6 @@ function gutenberg_register_webfonts_from_theme_json() {
7171
* Add missing fonts data to the global styles.
7272
*
7373
* @param array $data The global styles.
74-
*
7574
* @return array The global styles with missing fonts data.
7675
*/
7776
function gutenberg_add_registered_webfonts_to_theme_json( $data ) {
@@ -85,10 +84,9 @@ function gutenberg_add_registered_webfonts_to_theme_json( $data ) {
8584
* Helper to get an array of the font-families.
8685
*
8786
* @param array $families_data The font-families data.
88-
*
8987
* @return array The font-families array.
9088
*/
91-
$get_families = function( $families_data ) {
89+
$get_families = static function( $families_data ) {
9290
$families = array();
9391
foreach ( $families_data as $family ) {
9492
$families[] = WP_Webfonts::get_font_slug( $family );
@@ -137,7 +135,7 @@ function gutenberg_add_registered_webfonts_to_theme_json( $data ) {
137135
}
138136

139137
$data['settings']['typography']['fontFamilies'][] = array(
140-
'fontFamily' => false !== strpos( $family_name, ' ' ) ? "'{$family_name}'" : $family_name,
138+
'fontFamily' => str_contains( $family_name, ' ' ) ? "'{$family_name}'" : $family_name,
141139
'name' => $family_name,
142140
'slug' => $slug,
143141
'fontFace' => $font_faces,

lib/experimental/webfonts.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ function wp_webfonts() {
6060
*
6161
* @since 6.0.0
6262
*
63-
* @param array $webfonts Webfonts to be registered.
63+
* @param array[] $webfonts Webfonts to be registered.
6464
* This contains an array of webfonts to be registered.
6565
* Each webfont is an array.
6666
*/
67-
function wp_register_webfonts( array $webfonts = array() ) {
67+
function wp_register_webfonts( array $webfonts ) {
6868
foreach ( $webfonts as $webfont ) {
6969
wp_register_webfont( $webfont );
7070
}
@@ -94,9 +94,10 @@ function wp_register_webfonts( array $webfonts = array() ) {
9494
* @since 6.0.0
9595
*
9696
* @param array $webfont Webfont to be registered.
97+
* @return bool True if successfully registered, else false.
9798
*/
9899
function wp_register_webfont( array $webfont ) {
99-
wp_webfonts()->register_webfont( $webfont );
100+
return wp_webfonts()->register_webfont( $webfont );
100101
}
101102
}
102103

@@ -119,7 +120,7 @@ function wp_register_webfont( array $webfont ) {
119120
*
120121
* @param string[] $webfonts Font families to be enqueued.
121122
*/
122-
function wp_enqueue_webfonts( $webfonts ) {
123+
function wp_enqueue_webfonts( array $webfonts ) {
123124
foreach ( $webfonts as $webfont ) {
124125
wp_enqueue_webfont( $webfont );
125126
}
@@ -140,10 +141,11 @@ function wp_enqueue_webfonts( $webfonts ) {
140141
*
141142
* @since 6.0.0
142143
*
143-
* @param string $webfont Font family to be enqueued.
144+
* @param string $font_family_name The font family name to be enqueued.
145+
* @return bool True if successfully enqueued, else false.
144146
*/
145-
function wp_enqueue_webfont( $webfont ) {
146-
wp_webfonts()->enqueue_webfont( $webfont );
147+
function wp_enqueue_webfont( $font_family_name ) {
148+
return wp_webfonts()->enqueue_webfont( $font_family_name );
147149
}
148150
}
149151

phpunit/class-wp-webfonts-test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function test_validate_webfont() {
367367
*
368368
* @covers WP_Webfonts::generate_and_enqueue_styles
369369
*/
370-
public function test_generate_styles() {
370+
public function test_generate_and_enqueue_styles() {
371371
wp_register_webfonts(
372372
array(
373373
array(

0 commit comments

Comments
 (0)