Bladeren bron

Minor change to return rather than set font value from function (and lint)

Jason Crist 4 jaren geleden
bovenliggende
commit
319b6620cf
1 gewijzigde bestanden met toevoegingen van 15 en 13 verwijderingen
  1. 15 13
      blockbase/inc/customizer/wp-customize-fonts.php

+ 15 - 13
blockbase/inc/customizer/wp-customize-fonts.php

@@ -310,28 +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 );
+		if ( ! isset( $this->fonts[ $slug ] ) ) {
+			$this->fonts[ $slug ] = $this->build_font_from_theme_data( $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'];
+	function build_font_from_theme_data( $slug, $location, $configuration ) {
+		$new_font      = array();
+		$google_fonts  = $configuration['settings']['custom']['fontsToLoadFromGoogle'];
+		$font_families = $configuration['settings']['typography']['fontFamilies']['theme'];
+		foreach ( $font_families as $font_family ) {
+			if ( $font_family['slug'] === $slug ) {
+				$new_font['fontFamily'] = $font_family['fontFamily'];
+				$new_font['name']       = $font_family['name'];
 			}
 		}
-		foreach($google_fonts as $google_font) {
+		foreach ( $google_fonts as $google_font ) {
 			$aux = str_replace( '+', '-', $google_font );
-			if( strripos( $aux, $slug ) !== false ) $new_font['google'] = $google_font;
+			if ( strripos( $aux, $slug ) !== false ) {
+				$new_font['google'] = $google_font;
+			}
 		}
 		$new_font['slug'] = $slug;
-		$this->fonts[$slug] = $new_font;		
+		return $new_font;
 	}
 
 	function add_setting_and_control( $wp_customize, $name, $label, $default, $user_value ) {