Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webfonts API: Return font family slug when registering a webfont #40120

Merged

Conversation

zaguiini
Copy link
Contributor

@zaguiini zaguiini commented Apr 6, 2022

What?

Return the font family slug when registering a webfont.

Why?

There are cases where you want to be aware of the font family slug. One example is https://github.com/Automattic/jetpack/pull/23810/files#diff-67965f8a19767c6775dd0d0949ed5830c22bda270ec3c1835f801649e98596c2R70.

Returning the slug removes the need to call WP_Webfonts::get_font_slug after registering a webfont.

How?

Simply returning the $slug variable from the register_webfont method is enough.

Testing Instructions

You should check that the font family slug is returned after calling wp_register_webfont and wp_register_webfonts.

@zaguiini zaguiini force-pushed the update/return-font-family-slug-when-registering-webfont branch from 608efc3 to 4d84d18 Compare April 7, 2022 00:01
@jeyip
Copy link
Contributor

jeyip commented Apr 7, 2022

Testing

Requirements

  • wp_register_webfont returns the registered slug string
  • wp_register_webfonts returns the array of registered slug strings
// I tested this PR by error logging the output of wp_register_webfont and 
// wp_register_webfonts in the functions.php file of the currently active theme
$slug = wp_register_webfont(
		array(
			'font-family'  => 'Roboto',
			'font-style'   => 'normal',
			'font-stretch' => 'normal',
			"font-weight" => "900",
			'src'          => array( 'file:./assets/fonts/Roboto-Regular.ttf' ),
		)
	);

// Outputs 'roboto'
error_log( $slug );
$slugs = wp_register_webfonts(array(
		array(
			'font-family'  => 'Roboto',
			'font-style'   => 'normal',
			'font-stretch' => 'normal',
			"font-weight" => "900",
			'src'          => array( 'file:./assets/fonts/Roboto-Regular.ttf' ),
		)
	));

// Outputs [ 'roboto' ]
error_log( $slugs );
Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@zaguiini zaguiini merged commit f26587a into trunk Apr 7, 2022
@zaguiini zaguiini deleted the update/return-font-family-slug-when-registering-webfont branch April 7, 2022 14:22
@github-actions github-actions bot added this to the Gutenberg 13.0 milestone Apr 7, 2022
@bph bph added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Dev Note Requires a developer note for a major WordPress release cycle
4 participants