瀏覽代碼

Blockbase: replace user key with custom (#5147)

* Replace user key with custom

* Rename user to custom in functions.php

* Added stopgap so that the solution will work with both < and > Gutenberg version 12.1

Co-authored-by: Ben Dwyer <ben@scruffian.com>
Co-authored-by: Jason Crist <jcrist@pbking.com>
Sarah Norris 3 年之前
父節點
當前提交
70a175747e

+ 11 - 2
blockbase/functions.php

@@ -115,12 +115,22 @@ function blockbase_fonts_url() {
 	}
 
 	$font_families = [];
-	if ( ! empty( $theme_data['typography']['fontFamilies']['user'] ) ) {
+	if ( ! empty( $theme_data['typography']['fontFamilies']['custom'] ) ) {
+		foreach( $theme_data['typography']['fontFamilies']['custom'] as $font ) {
+			if ( ! empty( $font['google'] ) ) {
+				$font_families[] = $font['google'];
+			}
+		}
+
+	// NOTE: This should be removed once Gutenberg 12.1 lands stably in all environments
+	} else if ( ! empty( $theme_data['typography']['fontFamilies']['user'] ) ) {
 		foreach( $theme_data['typography']['fontFamilies']['user'] as $font ) {
 			if ( ! empty( $font['google'] ) ) {
 				$font_families[] = $font['google'];
 			}
 		}
+	// End Gutenberg < 12.1 compatibility patch
+
 	} else {
 		if ( ! empty( $theme_data['typography']['fontFamilies']['theme'] ) ) {
 			foreach( $theme_data['typography']['fontFamilies']['theme'] as $font ) {
@@ -181,4 +191,3 @@ require get_template_directory() . '/inc/block-styles.php';
  * Block Patterns.
  */
 require get_template_directory() . '/inc/block-patterns.php';
-

+ 8 - 2
blockbase/inc/customizer/wp-customize-colors.php

@@ -73,10 +73,16 @@ class GlobalStylesColorCustomizer {
 
 		$combined_color_palette = $theme_json['settings']['color']['palette']['theme'];
 		$user_color_palette     = null;
-		if ( isset( $theme_json['settings']['color']['palette']['user'] ) ) {
-			$user_color_palette = $theme_json['settings']['color']['palette']['user'];
+		if ( isset( $theme_json['settings']['color']['palette']['custom'] ) ) {
+			$user_color_palette = $theme_json['settings']['color']['palette']['custom'];
 		}
 
+		// NOTE: This should be removed once Gutenberg 12.1 lands stably in all environments
+		else if ( isset( $theme_json['settings']['color']['palette']['user'] ) ) {
+			$user_color_palette = $theme_json['settings']['color']['palette']['user'];
+		}
+		// End Gutenberg < 12.1 compatibility patch
+	
 		// Combine theme settings with user settings.
 		foreach ( $combined_color_palette as $key => $palette_item ) {
 			//make theme color value the default

+ 17 - 1
blockbase/inc/customizer/wp-customize-fonts.php

@@ -319,8 +319,22 @@ class GlobalStylesFontsCustomizer {
 			return;
 		}
 
-		if ( array_key_exists( 'user', $merged_json['settings']['typography']['fontFamilies'] ) ) {
+		if ( array_key_exists( 'custom', $merged_json['settings']['typography']['fontFamilies'] ) ) {
+			$merged_font_families = $merged_json['settings']['typography']['fontFamilies']['custom'];
+			$body_font_selected_array = array_filter( $merged_font_families, function( $font_family ) {
+				return $font_family['slug'] === "body-font";
+			} );
+			$body_font_selected = array_shift( $body_font_selected_array );
+
+			$heading_font_selected_array = array_filter( $merged_font_families, function( $font_family ) {
+				return $font_family['slug'] === "heading-font";
+			} );
+			$heading_font_selected = array_shift( $heading_font_selected_array );
+
+		// NOTE: This should be removed once Gutenberg 12.1 lands stably in all environments
+		} else if ( array_key_exists( 'user', $merged_json['settings']['typography']['fontFamilies'] ) ) {
 			$merged_font_families = $merged_json['settings']['typography']['fontFamilies']['user'];
+
 			$body_font_selected_array = array_filter( $merged_font_families, function( $font_family ) {
 				return $font_family['slug'] === "body-font";
 			} );
@@ -330,6 +344,8 @@ class GlobalStylesFontsCustomizer {
 				return $font_family['slug'] === "heading-font";
 			} );
 			$heading_font_selected = array_shift( $heading_font_selected_array );
+		// End Gutenberg < 12.1 compatibility patch
+	
 		} else {
 			$body_font_selected = $body_font_default;
 			$heading_font_selected = $heading_font_default;