Пример #1
0
/**
 * Array of Google Font options
 *
 * @since 2.1.0
 */
function vcex_fonts_array()
{
    $array = array(esc_html__('Default', 'total') => '');
    $std_fonts = wpex_standard_fonts();
    $array = array_merge($array, $std_fonts);
    if ($google_fonts = wpex_google_fonts_array()) {
        $array = array_merge($array, $google_fonts);
    }
    return apply_filters('vcex_google_fonts_array', $array);
}
/**
 * Array of Google Font options
 *
 * @since 2.1.0
 */
function vcex_fonts_array()
{
    $array = array(__('Default', 'wpex') => '');
    $std_fonts = wpex_standard_fonts();
    $array = array_merge($array, $std_fonts);
    $google_fonts = wpex_google_fonts_array();
    $array = array_merge($array, $google_fonts);
    $array = apply_filters('vcex_google_fonts_array', $array);
    return $array;
}
Пример #3
0
/**
 * Enqueues a Google Font
 *
 * @since 2.1.0
 */
function wpex_enqueue_google_font($font)
{
    // Get list of all Google Fonts
    $google_fonts = wpex_google_fonts_array();
    // Make sure font is in our list of fonts
    if (!$google_fonts || !in_array($font, $google_fonts)) {
        return;
    }
    // Sanitize handle
    $handle = trim($font);
    $handle = strtolower($handle);
    $handle = str_replace(' ', '-', $handle);
    // Sanitize font name
    $font = trim($font);
    $font = str_replace(' ', '+', $font);
    // Subset
    $subset = wpex_get_mod('google_font_subsets', 'latin');
    $subset = $subset ? $subset : 'latin';
    $subset = '&subset=' . $subset;
    // Enqueue style
    wp_enqueue_style('wpex-google-font-' . $handle, '//fonts.googleapis.com/css?family=' . str_replace(' ', '%20', $font) . ':100italic,200italic,300italic,400italic,600italic,700italic,800italic,900italic,900,800,700,600,500,400,300,200,100' . $subset, false, false, 'all');
}
    public function render_content()
    {
        // Get current value
        $this_val = $this->value();
        ?>
	<label>
		<span class="customize-control-title"><?php 
        echo esc_html($this->label);
        ?>
</span>
			<select <?php 
        $this->link();
        ?>
 style="width:100%;">
			<option value="" <?php 
        if (!$this_val) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('Default', 'wpex');
        ?>
</option>
			<?php 
        // Add custom fonts from child themes
        if (function_exists('wpex_add_custom_fonts')) {
            $fonts = wpex_add_custom_fonts();
            if ($fonts && is_array($fonts)) {
                ?>
					<optgroup label="<?php 
                _e('Custom Fonts', 'wpex');
                ?>
">
						<?php 
                foreach ($fonts as $font) {
                    ?>
							<option value="<?php 
                    echo $font;
                    ?>
" <?php 
                    if ($font == $this_val) {
                        echo 'selected="selected"';
                    }
                    ?>
><?php 
                    echo $font;
                    ?>
</option>
						<?php 
                }
                ?>
					</optgroup>
				<?php 
            }
        }
        ?>
			<optgroup label="<?php 
        _e('Standard Fonts', 'wpex');
        ?>
">
				<?php 
        // Get standard font options
        $std_fonts = wpex_standard_fonts();
        // Loop through font options and add to select
        foreach ($std_fonts as $font) {
            ?>
					<option value="<?php 
            echo $font;
            ?>
" <?php 
            selected($font, $this_val);
            ?>
><?php 
            echo $font;
            ?>
</option>
				<?php 
        }
        ?>
			</optgroup>
			<optgroup label="<?php 
        _e('Google Fonts', 'wpex');
        ?>
">
				<?php 
        // Get font options
        $google_fonts = wpex_google_fonts_array($google_fonts);
        // Loop through font options and add to select
        foreach ($google_fonts as $font) {
            ?>
					<option value="<?php 
            echo $font;
            ?>
" <?php 
            selected($font, $this_val);
            ?>
><?php 
            echo $font;
            ?>
</option>
				<?php 
        }
        ?>
			</optgroup>
		</select>
	</label>
	<?php 
    }
Пример #5
0
 /**
  * Add loaded fonts to the sourcode in the admin so it can display in the editor
  *
  * @since 1.6.0
  */
 public function mce_scripts()
 {
     // Get Google fonts
     $google_fonts = wpex_google_fonts_array();
     // For google fonts only so return if none are defined
     if (!$google_fonts) {
         return;
     }
     // Get fonts
     $fonts = $this->loop('fonts');
     // Apply filters
     $fonts = apply_filters('wpex_mce_fonts', $fonts);
     // Check
     if (empty($fonts) || !is_array($fonts)) {
         return;
     }
     // Add Google fonts to tinymce
     foreach ($fonts as $font) {
         if (!in_array($font, $google_fonts)) {
             continue;
         }
         $subset = wpex_get_mod('google_font_subsets', 'latin');
         $subset = $subset ? $subset : 'latin';
         $subset = '&amp;subset=' . $subset;
         $font = '//fonts.googleapis.com/css?family=' . str_replace(' ', '%20', $font) . ':300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' . $subset;
         $style = str_replace(',', '%2C', $font);
         add_editor_style($style);
     }
 }
Пример #6
0
 public function loop($return = 'css')
 {
     // Get typography data cache
     $data = get_theme_mod('wpex_customizer_typography_cache', false);
     // If theme mod cache empty or is live customizer loop through elements and set output
     if (empty($data) || is_customize_preview()) {
         // Define Vars
         $css = '';
         $load_scripts = '';
         $fonts = array();
         $scripts = array();
         $scripts_output = '';
         $elements = $this->elements();
         // Loop through each elements that need typography styling applied to them
         foreach ($elements as $element => $array) {
             // Attributes to loop through
             if (!empty($array['settings'])) {
                 $attributes = $array['settings'];
             } else {
                 $attributes = array('font-family', 'font-weight', 'font-style', 'font-size', 'color', 'line-height', 'letter-spacing', 'text-transform');
             }
             $add_css = '';
             $target = isset($array['target']) ? $array['target'] : '';
             $get_mod = get_theme_mod($element . '_typography');
             foreach ($attributes as $attribute) {
                 $val = isset($get_mod[$attribute]) ? $get_mod[$attribute] : '';
                 if ($val) {
                     // Convert font-size to px
                     if ('font-size' == $attribute || 'letter-spacing' == $attribute) {
                         $val = intval($get_mod[$attribute]) . 'px';
                     }
                     // Add quotes around font-family && font family to scripts array
                     if ('font-family' == $attribute) {
                         $fonts[] = $val;
                         $val = $val;
                     }
                     // Add custom CSS
                     $add_css .= $attribute . ':' . $val . ';';
                 }
             }
             if ($add_css) {
                 $css .= $target . '{' . $add_css . '}';
             }
         }
         if ($css || $fonts) {
             // Only load 1 of each font
             if (!empty($fonts)) {
                 array_unique($fonts);
             }
             // Get Google Scripts to load on the front end
             if (!empty($fonts)) {
                 $google_fonts = wpex_google_fonts_array();
                 // Loop through fonts and create Google Font Link
                 foreach ($fonts as $font) {
                     if (in_array($font, $google_fonts)) {
                         $scripts[] = 'https://fonts.googleapis.com/css?family=' . str_replace(' ', '%20', $font) . '';
                     }
                 }
                 // If scripts need to be loaded create the link tags
                 if (!empty($scripts)) {
                     $scripts_output = '<!-- Load Google Fonts -->';
                     foreach ($scripts as $script) {
                         $scripts_output .= '<link href="' . $script . ':300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&amp;subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic" rel="stylesheet" type="text/css">';
                     }
                 }
             }
         }
     }
     // Set cache or get cache if not in customizer
     if (!is_customize_preview()) {
         // Get Cache vars
         if ($data) {
             $css = isset($data['css']) ? $data['css'] : '';
             $fonts = isset($data['fonts']) ? $data['fonts'] : '';
             $scripts = isset($data['scripts']) ? $data['scripts'] : '';
             $scripts_output = isset($data['scripts_output']) ? $data['scripts_output'] : '';
         } else {
             set_theme_mod('wpex_customizer_typography_cache', array('css' => $css, 'fonts' => $fonts, 'scripts' => $scripts, 'scripts_output' => $scripts_output));
         }
     }
     // Return CSS
     if ('css' == $return && $css) {
         $css = '<!-- Typography CSS --><style type="text/css">' . $css . '</style>';
         return $css;
     }
     // Return Fonts Array
     if ('fonts' == $return && !empty($fonts)) {
         return $fonts;
     }
     // Return Scripts Array
     if ('scripts' == $return && !empty($scripts)) {
         return $scripts;
     }
     // Return Scripts Output
     if ('scripts_output' == $return && $scripts_output) {
         return $scripts_output;
     }
 }
Пример #7
0
 /**
  * Adds fonts to the font_container param
  *
  * @since  2.1.0
  */
 public static function font_container_fonts($fonts)
 {
     // Add blank option
     $new_fonts[''] = esc_html__('Default', 'total');
     // Merge arrays
     $fonts = array_merge($new_fonts, $fonts);
     // Get Google fonts
     $google_fonts = wpex_google_fonts_array();
     $google_fonts = array_combine($google_fonts, $google_fonts);
     // Merge fonts
     $fonts = array_merge($fonts, $google_fonts);
     // Return fonts
     return $fonts;
 }