Skip to content

Conversation

@simison
Copy link
Member

@simison simison commented Dec 8, 2022

What?

Solves #46398

Adds support for name attribute in wp_register_webfonts:

array(
	'name'         => 'Example (Japanese)',
	'font-family'  => 'Example',

	'font-style'   => 'normal',
	'font-weight'  => '200 900',
	'font-stretch' => 'normal',
	'src'          => 'https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2',
	'font-display' => 'fallback',
	'provider'     => 'local',
)

Why?

I'm describing use case in detail at #46398, but essentially to match how theme.json already works.

How?

Allows passing name attribute as part of font family array.

I'm not entirely happy with solution as conceptually "Name" would belong to higher up, not necessarily inside font-family definition. I also didn't see better alternative.

Testing Instructions

Add this to mu-plugins or elsewhere:

function register_example_font() {
	$font_family = "Example";
	$font_name = "Example (Japanese)";
	
	wp_register_webfonts(
		array(
			array(
				'provider'     => 'local',
				'name'         => $font_name,
				'font-family'  => $font_family,
				'font-style'   => 'normal',
				'font-weight'  => '200 900',
				'font-stretch' => 'normal',
				'src'          => 'https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2',
				'font-display' => 'fallback',
			),
			array(
				'provider'     => 'local',
				'name'         => $font_name,
				'font-family'  => $font_family,
				'font-style'   => 'italic',
				'font-weight'  => '200 900',
				'font-stretch' => 'normal',
				'src'          => 'https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2',
				'font-display' => 'fallback',
			),
		)
	);
}
add_filter( 'init', 'register_example_font' );

Open site editor and note font families:

Screenshot 2022-12-08 at 15 11 40

Testing Instructions for Keyboard

Screenshots or screencast

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.

Block this PR until the architectural redesign is completed and merged. (See my comment here #46398 (comment) for more context.) Once merged, then can revisit what changes are needed in this PR, if any.

@simison simison added the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Dec 8, 2022
@hellofromtonya hellofromtonya removed the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Jan 18, 2023
@hellofromtonya
Copy link
Contributor

This PR is now unblocked. It will need to be rebased and rebuilt to apply the enhancement to the newly designed Fonts API (which is now in trunk). Please note, the API has a brand new architecture and was renamed (including all of the files, functions, classes, tests, etc.).

@hellofromtonya
Copy link
Contributor

This PR was applied to the old API. It will not work with the new API. I think it's best to close this PR, but use it as reference for the intent. Then open a new PR to add the enhancement to the new API.

@simison simison deleted the update/name_wp_register_webfonts branch September 4, 2024 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants