Example #1
0
 /**
  * Build the HTTP request URL for Google Fonts.
  *
  * The wp_enqueue_style function escapes the stylesheet URL, so no escaping is done here. If
  * this function is used in a different context, make sure the output is escaped!
  *
  * @since  1.0.0.
  *
  * @return string    The URL for including Google Fonts.
  */
 function ttfmake_get_google_font_uri()
 {
     // Grab the font choices
     $all_keys = array_keys(ttfmake_option_defaults());
     $font_keys = array();
     foreach ($all_keys as $key) {
         if (false !== strpos($key, 'font-family-')) {
             $font_keys[] = $key;
         }
     }
     $fonts = array();
     foreach ($font_keys as $key) {
         $fonts[] = get_theme_mod($key, ttfmake_get_default($key));
     }
     // De-dupe the fonts
     $fonts = array_unique($fonts);
     $allowed_fonts = ttfmake_get_google_fonts();
     $family = array();
     // Validate each font and convert to URL format
     foreach ($fonts as $font) {
         $font = trim($font);
         // Verify that the font exists
         if (array_key_exists($font, $allowed_fonts)) {
             // Build the family name and variant string (e.g., "Open+Sans:regular,italic,700")
             $family[] = urlencode($font . ':' . join(',', ttfmake_choose_google_font_variants($font, $allowed_fonts[$font]['variants'])));
         }
     }
     // Start the request
     $request = '';
     $uri_base = '//fonts.googleapis.com/css';
     // Convert from array to string
     if (!empty($family)) {
         $request = add_query_arg('family', implode('|', $family), $uri_base);
     }
     // Load the font subset
     $subset = get_theme_mod('font-subset', ttfmake_get_default('font-subset'));
     if ('all' === $subset) {
         $subsets_available = ttfmake_get_google_font_subsets();
         // Remove the all set
         unset($subsets_available['all']);
         // Build the array
         $subsets = array_keys($subsets_available);
     } else {
         $subsets = array($subset);
         if ('latin' !== $subset) {
             $subsets[] = 'latin';
         }
     }
     // Append the subset string
     if ('' !== $request && !empty($subsets)) {
         $request = add_query_arg('subset', join(',', $subsets), $request);
     }
     /**
      * Filter the Google Fonts URL.
      *
      * @since 1.2.3.
      *
      * @param string    $url    The URL to retrieve the Google Fonts.
      */
     return apply_filters('make_get_google_font_uri', $request);
 }
Example #2
0
 /**
  * Build the HTTP request URL for Google Fonts.
  *
  * @since  1.0.0.
  *
  * @return string    The URL for including Google Fonts.
  */
 function ttfmake_get_google_font_uri()
 {
     // Grab the font choices
     if (ttfmake_customizer_supports_panels()) {
         $font_keys = array('font-family-site-title', 'font-family-site-tagline', 'font-family-nav', 'font-family-subnav', 'font-family-widget', 'font-family-h1', 'font-family-h2', 'font-family-h3', 'font-family-h4', 'font-family-h5', 'font-family-h6', 'font-family-body');
     } else {
         $font_keys = array('font-site-title', 'font-header', 'font-body');
     }
     $fonts = array();
     foreach ($font_keys as $key) {
         $fonts[] = get_theme_mod($key, ttfmake_get_default($key));
     }
     // De-dupe the fonts
     $fonts = array_unique($fonts);
     $allowed_fonts = ttfmake_get_google_fonts();
     $family = array();
     // Validate each font and convert to URL format
     foreach ($fonts as $font) {
         $font = trim($font);
         // Verify that the font exists
         if (array_key_exists($font, $allowed_fonts)) {
             // Build the family name and variant string (e.g., "Open+Sans:regular,italic,700")
             $family[] = urlencode($font . ':' . join(',', ttfmake_choose_google_font_variants($font, $allowed_fonts[$font]['variants'])));
         }
     }
     // Convert from array to string
     if (empty($family)) {
         return '';
     } else {
         $request = '//fonts.googleapis.com/css?family=' . implode('|', $family);
     }
     // Load the font subset
     $subset = get_theme_mod('font-subset', ttfmake_get_default('font-subset'));
     if ('all' === $subset) {
         $subsets_available = ttfmake_get_google_font_subsets();
         // Remove the all set
         unset($subsets_available['all']);
         // Build the array
         $subsets = array_keys($subsets_available);
     } else {
         $subsets = array('latin', $subset);
     }
     // Append the subset string
     if (!empty($subsets)) {
         $request .= urlencode('&subset=' . join(',', $subsets));
     }
     /**
      * Filter the Google Fonts URL.
      *
      * @since 1.2.3.
      *
      * @param string    $url    The URL to retrieve the Google Fonts.
      */
     return apply_filters('make_get_google_font_uri', esc_url($request));
 }