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

Update format used by font resolver #50499

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/experimental/fonts-api/class-wp-fonts-resolver.php
Expand Up @@ -45,8 +45,12 @@ class WP_Fonts_Resolver {
* @return array User selected font-families when exists, else empty array.
*/
public static function enqueue_user_selected_fonts() {
$global_styles = wp_get_global_styles();
$user_selected_fonts = static::get_user_selected_fonts( $global_styles );
$user_selected_fonts = array();
$user_global_styles = WP_Theme_JSON_Resolver_Gutenberg::get_user_data()->get_raw_data();
Copy link
Member

Choose a reason for hiding this comment

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

Would this avoid the cache we introduced?

Copy link
Member Author

Choose a reason for hiding this comment

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

This has the same performance impact than using wp_get_global_styles. That function has not a cache of their own: both approaches rely on the resolver cache.

if ( isset( $user_global_styles['styles'] ) ) {
$user_selected_fonts = static::get_user_selected_fonts( $user_global_styles['styles'] );
}

if ( empty( $user_selected_fonts ) ) {
return array();
}
Expand Down Expand Up @@ -92,11 +96,14 @@ private static function get_value_from_style( $style, $preset_type = 'font-famil
return '';
}

$starting_pattern = "var:preset|{$preset_type}|";
$starting_pattern = "var(--wp--preset--{$preset_type}--";
$ending_pattern = ')';
if ( ! str_starts_with( $style, $starting_pattern ) ) {
return '';
}

return substr( $style, strlen( $starting_pattern ) );
$offset = strlen( $starting_pattern );
$length = strpos( $style, $ending_pattern ) - $offset;
return substr( $style, $offset, $length );
}
}