소스 검색

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' );
 }
 
 /**