Skip to content

Commit

Permalink
Updates from code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromtonya committed Apr 4, 2022
1 parent 6d66272 commit 90cc444
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/experimental/class-wp-webfonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
8 changes: 3 additions & 5 deletions lib/experimental/register-webfonts-from-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 9 additions & 7 deletions lib/experimental/webfonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );
}
}

Expand All @@ -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 );
}
Expand All @@ -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 );
}
}

Expand Down
2 changes: 1 addition & 1 deletion phpunit/class-wp-webfonts-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 90cc444

Please sign in to comment.