Ejemplo n.º 1
0
function enlightenment_web_fonts_style($args = null)
{
    $defaults = array('variants' => current_theme_supports('enlightenment-web-fonts', 'variants'), 'subsets' => current_theme_supports('enlightenment-web-fonts', 'subsets'));
    $defaults = apply_filters('enlightenment_web_fonts_style_args', $defaults);
    $args = wp_parse_args($args, $defaults);
    $fonts = enlightenment_fonts_to_load();
    if (!empty($fonts)) {
        global $enlightenment_web_fonts_errors;
        if (!isset($enlightenment_web_fonts_errors)) {
            $enlightenment_web_fonts_errors = array();
        }
        $stylesheet = 'http' . (is_ssl() ? 's' : '') . '://fonts.googleapis.com/css?family=';
        foreach ($fonts as $font => $styles) {
            if (empty($styles)) {
                $styles = $args['variants'];
            }
            $atts = enlightenment_get_font_atts($font);
            /* Backwards compatibility code, to be removed in a future version */
            foreach ($atts['variants'] as $key => $variant) {
                $variant = str_replace('light', '300', $variant);
                $variant = str_replace('normal', '400', $variant);
                $variant = str_replace('medium', '700', $variant);
                $variant = str_replace('semibold', '600', $variant);
                $variant = str_replace('bold', '700', $variant);
                $atts['variants'][$key] = $variant;
            }
            foreach ($styles as $key => $style) {
                if (!in_array($style, $atts['variants'], true)) {
                    unset($styles[$key]);
                }
            }
            $styles = array_values($styles);
            foreach ($args['subsets'] as $key => $subset) {
                if (!in_array($subset, $atts['subsets'])) {
                    $enlightenment_web_fonts_errors[] = sprintf(__('The font "%1$s" does not support your selected subset <code>%2$s</code>.', 'enlightenment'), $font, $subset);
                }
            }
            $fonts[$font] = array_values($styles);
        }
        $i = 0;
        $c = count($fonts);
        foreach ($fonts as $font => $styles) {
            $i++;
            $font = str_replace(' ', '+', $font);
            $stylesheet .= $font;
            if (!empty($styles) && array('400') != $styles) {
                $stylesheet .= ':';
                $tmpstyles = $styles;
                $laststyle = array_pop($tmpstyles);
                unset($tmpstyles);
                foreach ($styles as $style) {
                    $stylesheet .= $style;
                    if ($style != $laststyle) {
                        $stylesheet .= ',';
                    }
                }
            }
            if ($i != $c) {
                $stylesheet .= '|';
            }
        }
        $stylesheet .= '&subset=';
        foreach ($args['subsets'] as $subset) {
            $stylesheet .= $subset;
            if ($subset != end($args['subsets'])) {
                $stylesheet .= ',';
            }
        }
        return esc_url($stylesheet);
    }
    return false;
}
Ejemplo n.º 2
0
function enlightenment_web_fonts_style($args = null)
{
    $defaults = array('variants' => current_theme_supports('enlightenment-web-fonts', 'variants'), 'subsets' => current_theme_supports('enlightenment-web-fonts', 'subsets'));
    $defaults = apply_filters('enlightenment_web_fonts_style_args', $defaults);
    $args = wp_parse_args($args, $defaults);
    $fonts = enlightenment_fonts_to_load();
    if (!empty($fonts)) {
        global $enlightenment_web_fonts_errors;
        if (!isset($enlightenment_web_fonts_errors)) {
            $enlightenment_web_fonts_errors = array();
        }
        $stylesheet = 'http' . (is_ssl() ? 's' : '') . '://fonts.googleapis.com/css?family=';
        foreach ($fonts as $font => $styles) {
            if (empty($styles)) {
                $styles = $args['variants'];
            }
            $atts = enlightenment_get_font_atts($font);
            foreach ($styles as $key => $style) {
                if (!in_array($style, $atts['variants'])) {
                    unset($styles[$key]);
                }
            }
            foreach ($args['subsets'] as $key => $subset) {
                if (!in_array($subset, $atts['subsets'])) {
                    $enlightenment_web_fonts_errors[] = sprintf(__('The font "%1$s" does not support your selected subset <code>%2$s</code>.', 'enlightenment'), $font, $subset);
                }
            }
            $fonts[$font] = array_values($styles);
        }
        $i = 0;
        $c = count($fonts);
        foreach ($fonts as $font => $styles) {
            $i++;
            $font = str_replace(' ', '+', $font);
            $stylesheet .= $font;
            if (array('normal') != $styles) {
                $stylesheet .= ':';
                foreach ($styles as $style) {
                    $stylesheet .= $style;
                    if ($style != end($styles)) {
                        $stylesheet .= ',';
                    }
                }
            }
            if ($i != $c) {
                $stylesheet .= '|';
            }
        }
        $stylesheet .= '&subset=';
        foreach ($args['subsets'] as $subset) {
            $stylesheet .= $subset;
            if ($subset != end($args['subsets'])) {
                $stylesheet .= ',';
            }
        }
        return esc_url($stylesheet);
    }
    return false;
}