/** * Enqueues all the Google fonts, used in wp_enqueue_scripts * * @return void * @since 1.4 */ public function enqueueGooglefonts() { if (!count(self::$googleFontsOptions)) { return; } // Gather all the fonts that we need to load, some may be repeated so we need to // load them once after gathering them $fontsToLoad = array(); foreach (self::$googleFontsOptions as $option) { $fontValue = $option->getFramework()->getOption($option->settings['id']); if (empty($fontValue['font-family'])) { continue; } if ($fontValue['font-type'] != 'google') { continue; } // Get all the fonts that we need to load if (empty($fontsToLoad[$fontValue['font-family']])) { $fontsToLoad[$fontValue['font-family']] = array(); } // Get the weight $variant = $fontValue['font-weight']; if ($variant == 'normal') { $variant = '400,700'; } else { if ($variant == 'bold') { $variant = '500'; } else { if ($variant == 'bolder') { $variant = '800'; } else { if ($variant == 'lighter') { $variant = '100'; } else { if ($variant == '300') { $variant = '300'; } } } } } if ($fontValue['font-style'] == 'italic') { $variant .= 'italic'; } $fontsToLoad[$fontValue['font-family']][] = $variant; } // Font subsets, allow others to change this $subsets = apply_filters('tf_google_font_subsets_' . $this->getOptionNamespace(), array('latin', 'latin-ext')); // Enqueue the Google Font foreach ($fontsToLoad as $fontName => $variants) { // Always include the normal weight so that we don't error out $variants[] = '400'; $variants = array_unique($variants); $fontUrl = sprintf("//fonts.googleapis.com/css?family=%s:%s&subset=%s", str_replace(' ', '+', $fontName), implode(',', $variants), implode(',', $subsets)); wp_enqueue_style('tf-google-webfont-' . strtolower(str_replace(' ', '-', $fontName)), $fontUrl); } // Don't repeat self::$googleFontsOptions = array(); }