Skip to content

Commit

Permalink
Use WP_Theme_JSON_Resolver_Gutenberg::get_user_data().
Browse files Browse the repository at this point in the history
From PR #50499.
Props @oandregal.
  • Loading branch information
hellofromtonya committed May 10, 2023
1 parent 4c8b071 commit fe2bd0d
Showing 1 changed file with 11 additions and 4 deletions.
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();
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 );
}
}

0 comments on commit fe2bd0d

Please sign in to comment.