瀏覽代碼

Blockbase: Improve blockbase_fonts_url handling (#4489)

This change adresses multiple issues. 
It:
1. prevents the possibility of an "empty" call to fonts.googleapis.com by returning empty instead of `https://fonts.googleapis.com/css2?&display=swap`, see issue #4458
2. prevents a child theme custom Google font to ALWAYS be loaded even if it's is not selected in the user settings
3. prevents duplicate URL parameters when both user body and header fonts are set to the same value with `array_unique`
Rolf Allard van Hagen 3 年之前
父節點
當前提交
474ffbeb3c
共有 1 個文件被更改,包括 14 次插入12 次删除
  1. 14 12
      blockbase/functions.php

+ 14 - 12
blockbase/functions.php

@@ -83,26 +83,28 @@ function blockbase_fonts_url() {
 	}
 
 	$font_families = [];
-	if ( ! empty( $theme_data['typography']['fontFamilies']['theme'] ) ) {
-		foreach( $theme_data['typography']['fontFamilies']['theme'] as $font ) {
-			if ( ! empty( $font['google'] ) ) {
-				$font_families[] = $font['google'];
-			}
-		}
-	}
-
 	if ( ! empty( $theme_data['typography']['fontFamilies']['user'] ) ) {
 		foreach( $theme_data['typography']['fontFamilies']['user'] as $font ) {
 			if ( ! empty( $font['google'] ) ) {
 				$font_families[] = $font['google'];
 			}
 		}
+	} else {
+		if ( ! empty( $theme_data['typography']['fontFamilies']['theme'] ) ) {
+			foreach( $theme_data['typography']['fontFamilies']['theme'] as $font ) {
+				if ( ! empty( $font['google'] ) ) {
+					$font_families[] = $font['google'];
+				}
+			}
+		}
+	}
+	
+	if ( empty( $font_families ) ) {
+		return '';
 	}
 
-	$font_families[] = 'display=swap';
-
-	// Make a single request for the theme fonts.
-	return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', $font_families ) );
+	// Make a single request for the theme or user fonts.
+	return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', array_unique( $font_families ) ) . '&display=swap' );
 }
 
 /**