瀏覽代碼

include theme fonts to the list of selectable fonts if they are not available

Maggie 4 年之前
父節點
當前提交
e55d3d7fd0
共有 1 個文件被更改,包括 21 次插入0 次删除
  1. 21 0
      blockbase/inc/customizer/wp-customize-fonts.php

+ 21 - 0
blockbase/inc/customizer/wp-customize-fonts.php

@@ -310,9 +310,30 @@ class GlobalStylesFontsCustomizer {
 	function get_font_family( $location, $configuration ) {
 		$variable = $configuration['settings']['custom'][ $location ]['typography']['fontFamily'];
 		$slug     = preg_replace( '/var\(--wp--preset--font-family--(.*)\)/', '$1', $variable );
+		if( !isset($this->fonts[ $slug ])){
+			$this->set_theme_font_family( $slug, $location, $configuration );
+		}
 		return $this->fonts[ $slug ];
 	}
 
+	function set_theme_font_family( $slug, $location, $configuration ) {
+		$new_font = [];
+		$google_fonts = $configuration['settings']['custom']['fontsToLoadFromGoogle'];
+		$fontFamilies = $configuration['settings']['typography']['fontFamilies']['theme'];
+		foreach($fontFamilies as $fontFamily) {
+			if( $fontFamily['slug'] === $slug ) {
+				$new_font['fontFamily'] = $fontFamily['fontFamily'];
+				$new_font['name'] = $fontFamily['name'];
+			}
+		}
+		foreach($google_fonts as $google_font) {
+			$aux = str_replace( '+', '-', $google_font );
+			if( strripos( $aux, $slug ) !== false ) $new_font['google'] = $google_font;
+		}
+		$new_font['slug'] = $slug;
+		$this->fonts[$slug] = $new_font;		
+	}
+
 	function add_setting_and_control( $wp_customize, $name, $label, $default, $user_value ) {
 		$setting_name          = $this->section_key . $name;
 		$global_styles_setting = new WP_Customize_Global_Styles_Setting(