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

Skip redundant registration for Fonts API-registered fonts #48341

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public function to_theme_json( $font_family_handle ) {
}

$variation_obj = $this->registered[ $variation_handle ];
$variation_properties = array( 'origin' => 'gutenberg_wp_webfonts_api' );
$variation_properties = array( 'origin' => 'gutenberg_wp_fonts_api' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there risk of this impacting extenders who may be iterating through the registered fonts?

A search of the wporg plugin directory shows only Gutenberg using it https://wpdirectory.net/search/01GSZ95M6F3772YGWKZXG9A15P.

I suspect the risk to users is minimally low.

Copy link
Member

Choose a reason for hiding this comment

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

If anything, this feature is in the experimental folder so external developers should be aware that things might break πŸ˜…

Is it worth it to include a doing_it_wrong call to announce that things changed, @hellofromtonya?

Copy link
Contributor

Choose a reason for hiding this comment

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

If anything, this feature is in the experimental folder so external developers should be aware that things might break πŸ˜…
True, though the API now includes a temporary BC Layer which is intended to keep sites running while giving time for extenders to upgrade to the new API.

Is it worth it to include a doing_it_wrong call to announce that things changed, @hellofromtonya?

Good question @zaguiini! The origin is set internally within the API itself. So I think it's okay to not add a doing_it_wrong here. But it does me think about: could it be set externally? If yes and set wrong, what happens? Hmm that's interesting as it may cause unexpected things. Thinking a new issue is needed to discuss and explore.

foreach ( $variation_obj->extra['font-properties'] as $property_name => $property_value ) {
$property_in_camelcase = lcfirst( str_replace( '-', '', ucwords( $property_name, '-' ) ) );
$variation_properties[ $property_in_camelcase ] = $property_value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function gutenberg_register_fonts_from_theme_json() {
$font_family['fontFace'] = (array) $font_family['fontFace'];

foreach ( $font_family['fontFace'] as $font_face ) {
// Skip if the webfont was registered through the Webfonts API.
if ( isset( $font_face['origin'] ) && 'gutenberg_wp_webfonts_api' === $font_face['origin'] ) {
// Skip if the font was registered through the Fonts API.
if ( isset( $font_face['origin'] ) && 'gutenberg_wp_fonts_api' === $font_face['origin'] ) {
ironprogrammer marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

Expand Down