/** * Return a particular global option default. * * @since 1.0.0. * * @param string $option The key of the option to return. * @return mixed Default value if found; false if not found. */ function ttfmake_get_default($option) { $defaults = ttfmake_option_defaults(); $default = isset($defaults[$option]) ? $defaults[$option] : false; /** * Filter the retrieved default value. * * @since 1.2.3. * * @param mixed $default The default value. * @param string $option The name of the default value. */ return apply_filters('make_get_default', $default, $option); }
/** * 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); }
/** * Return all the option keys for the specified font property. * * @since 1.3.0. * * @param string $property The font property to search for. * @return array Array of matching font option keys. */ function ttfmake_get_font_property_option_keys($property) { $all_keys = array_keys(ttfmake_option_defaults()); $font_keys = array(); foreach ($all_keys as $key) { if (preg_match('/^font-' . $property . '-/', $key)) { $font_keys[] = $key; } } return $font_keys; }