ソースを参照

further attempts to get the font provider to work as expected

Jason Crist 3 年 前
コミット
42f56c2fc1

+ 9 - 7
blockbase/inc/fonts/blockbase-fonts-provider.php

@@ -26,7 +26,8 @@ class Blockbase_Fonts_Provider extends \WP_Webfonts_Provider {
 		$css = '';
 		$css = '';
 
 
 		foreach ( $this->webfonts as $webfont ) {
 		foreach ( $this->webfonts as $webfont ) {
-			$css .= $this->get_style_css( $webfont['font-family'] );
+			$font_slug = \WP_Webfonts::get_font_slug( $webfont['font-family'] );
+			$css      .= $this->get_style_css( $font_slug );
 		}
 		}
 
 
 		return $css;
 		return $css;
@@ -75,16 +76,14 @@ function provider_enqueue_block_fonts( $content, $parsed_block ) {
  * @param string $font_family_name Name of font family.
  * @param string $font_family_name Name of font family.
  * @return boolean|void Whether the font family is registered, or void if WP_Webfonts is not available.
  * @return boolean|void Whether the font family is registered, or void if WP_Webfonts is not available.
  */
  */
-function is_font_family_registered( $font_family_name ) {
-	if ( ! function_exists( 'wp_webfonts' ) || ! method_exists( 'WP_Webfonts', 'get_font_slug' ) ) {
+function is_font_family_registered( $font_slug ) {
+	if ( ! function_exists( 'wp_webfonts' ) ) {
 		return;
 		return;
 	}
 	}
 
 
 	$wp_webfonts = wp_webfonts();
 	$wp_webfonts = wp_webfonts();
 
 
-	$slug = \WP_Webfonts::get_font_slug( $font_family_name );
-
-	return isset( $wp_webfonts->get_registered_webfonts()[ $slug ] );
+	return isset( $wp_webfonts->get_registered_webfonts()[ $font_slug ] );
 }
 }
 
 
 function register_blockbase_fonts_provider() {
 function register_blockbase_fonts_provider() {
@@ -95,7 +94,10 @@ function register_blockbase_fonts_provider() {
 
 
 	$result = wp_register_webfont_provider( 'blockbase-fonts', 'Blockbase_Fonts_Provider' );
 	$result = wp_register_webfont_provider( 'blockbase-fonts', 'Blockbase_Fonts_Provider' );
 
 
-	add_filter( 'pre_render_block', 'provider_enqueue_block_fonts', 10, 2 );
+	// NOTE: As far as I can tell you can't assign a font-family at the individual block level
+	// which is what this logic is for.  This may someday be necessary but I don't believe it is now.
+	// add_filter( 'pre_render_block', 'provider_enqueue_block_fonts', 10, 2 );
+
 	add_action( 'init', 'provider_enqueue_global_styles_fonts' );
 	add_action( 'init', 'provider_enqueue_global_styles_fonts' );
 }
 }
 add_action( 'after_setup_theme', 'register_blockbase_fonts_provider' );
 add_action( 'after_setup_theme', 'register_blockbase_fonts_provider' );

+ 1 - 1
blockbase/inc/fonts/custom-font-migration.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
 // Use an early priority to migrate legacy font settings before registering fonts
 // Use an early priority to migrate legacy font settings before registering fonts
-add_action( 'after_setup_theme', 'migrate_blockbase_custom_fonts', 0 );
+add_action( 'init', 'migrate_blockbase_custom_fonts' );
 
 
 function migrate_blockbase_custom_fonts() {
 function migrate_blockbase_custom_fonts() {
 
 

+ 18 - 4
blockbase/theme.json

@@ -369,7 +369,12 @@
 					"fontFamily": "Arvo, serif",
 					"fontFamily": "Arvo, serif",
 					"slug": "arvo",
 					"slug": "arvo",
 					"name": "Arvo",
 					"name": "Arvo",
-					"provider": "blockbase-fonts"
+					"fontFace": [
+						{
+							"provider": "blockbase-fonts",
+							"fontFamily": "Arvo"
+						}
+					]
 				},
 				},
 				{
 				{
 					"fontFamily": "'Bodoni Moda', serif",
 					"fontFamily": "'Bodoni Moda', serif",
@@ -381,7 +386,12 @@
 					"fontFamily": "Cabin, sans-serif",
 					"fontFamily": "Cabin, sans-serif",
 					"slug": "cabin",
 					"slug": "cabin",
 					"name": "Cabin",
 					"name": "Cabin",
-					"provider": "blockbase-fonts"
+					"fontFace": [
+						{
+							"provider": "blockbase-fonts",
+							"fontFamily": "Cabin"
+						}
+					]
 				},
 				},
 				{
 				{
 					"fontFamily": "Chivo, sans-serif",
 					"fontFamily": "Chivo, sans-serif",
@@ -417,7 +427,12 @@
 					"fontFamily": "'Fira Sans', sans-serif",
 					"fontFamily": "'Fira Sans', sans-serif",
 					"slug": "fira-sans",
 					"slug": "fira-sans",
 					"name": "Fira Sans",
 					"name": "Fira Sans",
-					"provider": "blockbase-fonts"
+					"fontFace": [
+						{
+							"provider": "blockbase-fonts",
+							"fontFamily": "Fira Sans"
+						}
+					]
 				},
 				},
 				{
 				{
 					"fontFamily": "'IBM Plex Mono', monospace",
 					"fontFamily": "'IBM Plex Mono', monospace",
@@ -637,7 +652,6 @@
 					}
 					}
 				},
 				},
 				"typography": {
 				"typography": {
-					"fontFamily": "var(--wp--preset--font-family--heading-font)",
 					"fontSize": "var(--wp--preset--font-size--large)",
 					"fontSize": "var(--wp--preset--font-size--large)",
 					"lineHeight": "var(--wp--custom--heading--typography--line-height)"
 					"lineHeight": "var(--wp--custom--heading--typography--line-height)"
 				}
 				}