function lbmn_return_font_presets_weights($remove_font_styles = true) { // Send array of Font Presets to the java script $fontPresents = array(); $actve_font_weights = array(); $actve_font_family = ''; $google_fonts = lbmn_get_goolefonts(); // Go through all Google font presents in Theme Customizer for ($i = 1; $i < 5; $i++) { $preset_no = $i; // Check if Google font is set if (get_theme_mod('lbmn_font_preset_usegooglefont_' . $preset_no) && get_theme_mod('lbmn_font_preset_googlefont_' . $preset_no, '') != '') { // get the font name for the current preset $actve_font_family = get_theme_mod('lbmn_font_preset_googlefont_' . $preset_no, ''); //check if the active font has any width variations if (isset($google_fonts[$actve_font_family]) && count($google_fonts[$actve_font_family]) > 0) { $actve_font_weights = $google_fonts[$actve_font_family]; if ($remove_font_styles) { $actve_font_weights = array_filter($actve_font_weights, "lbmn_leave_only_fontweights"); } } else { // active Google Font has no width variations $actve_font_weights = array('0' => '400'); } } else { // if not a google web font used return the full list of font weights $actve_font_weights = array('400' => '400 Regular', '100' => '100 Thin', '200' => '200 Light', '300' => '300 Book', '500' => '500 Medium', '600' => '600 DemiBold', '700' => '700 Bold', '800' => '800 ExtraBold', '900' => '900 Heavy'); } $fontPresetsWeights[$preset_no] = $actve_font_weights; } return $fontPresetsWeights; }
/** * ----------------------------------------------------------------------------- * Enqueue scripts and styles */ function lbmn_scripts() { $theme_dir = get_template_directory_uri(); // JavaScript files output (the ones we don't minify) wp_register_script('lbmn-modernizr', $theme_dir . '/javascripts/custom.modernizr.js', false, '2.6.2', false); wp_enqueue_script('lbmn-modernizr'); wp_enqueue_script('jquery'); // wp_enqueue_script( 'jquery-migrate' ); // JavaScript files output if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || LBMN_SCRIPT_DEBUG) { // Output original scripts if define( 'SCRIPT_DEBUG', true ); // is set in wp-config.php wp_enqueue_script('lbmn-custom-js', $theme_dir . '/javascripts/scripts.js', array('jquery', 'mm_menu_functions'), '20140517', true); } else { // Output minified scripts if 'SCRIPT_DEBUG' isn't set to true in config.php // define( 'SCRIPT_DEBUG', true ); wp_register_script('lbmn-js-minified', $theme_dir . '/javascripts/scripts.min.js', array('jquery', 'mm_menu_functions'), '20140604', true); wp_enqueue_script('lbmn-js-minified'); } // Custom icon font styles wp_enqueue_style('lbmn-iconfont', $theme_dir . '/iconfont/style.css'); // Theme main css style wp_enqueue_style('lbmn-style', get_stylesheet_uri(), false, '20140611-6'); if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } /** * ---------------------------------------------------------------------- * Special styles used when not all required plugins installed */ if (!is_plugin_active('ds-live-composer/ds-live-composer.php') || !get_option(LBMN_THEME_NAME . '_basic_config_done')) { wp_enqueue_style('lbmn-livecomposer-alternative-style', $theme_dir . '/design/nopluginscss/nolivecomposeractive.css', false); } if (!is_plugin_active('mega_main_menu/mega_main_menu.php') || !get_option(LBMN_THEME_NAME . '_basic_config_done')) { wp_enqueue_style('lbmn-megamainmenu-alternative-style', $theme_dir . '/design/nopluginscss/nomegamenuactive.css', false); } /** * -------------------------------------------------------------------------- * Google Web Fonts * Compose links to the Google Fonts used to be included in the <head> */ $googlefonts_toload = array(); $googlefonts_weights = lbmn_get_goolefonts(); $googlefonts_toload_prepared = ''; $first_font = true; for ($i = 1; $i < 5; $i++) { // if use google font check box is selected if (get_theme_mod('lbmn_font_preset_usegooglefont_' . $i, 1)) { // If GoogleFont name is set use it if (get_theme_mod('lbmn_font_preset_googlefont_' . $i, '')) { $prefix = ''; if (!$first_font) { $prefix = '|'; } $googlefonts_toload[$i] = $prefix . get_theme_mod('lbmn_font_preset_googlefont_' . $i, ''); // If no GoogleFont name set use the default one for this preset } else { $prefix = ''; if (!$first_font) { $prefix = '|'; } $googlefonts_toload[$i] = $prefix . get_theme_mod('lbmn_font_preset_googlefont_' . $i, constant('LBMN_FONT_PRESET_GOOGLEFONT_' . $i . '_DEFAULT')); } // If font set, attach it's weights if ($googlefonts_toload[$i]) { str_replace(' ', '+', $googlefonts_toload[$i]); $first_weight = true; foreach ($googlefonts_weights[$googlefonts_toload[$i]] as $weight) { if ($first_weight) { $googlefonts_toload[$i] .= ':'; } $googlefonts_toload[$i] .= $weight . ','; $first_weight = false; } $googlefonts_toload[$i] = substr_replace($googlefonts_toload[$i], "", -1); // remove last character ',' in a string } } } foreach ($googlefonts_toload as $google_font) { $googlefonts_toload_prepared .= $google_font . '|'; } if ($googlefonts_toload_prepared) { $googlefonts_toload_prepared = substr_replace($googlefonts_toload_prepared, "", -1); // remove last character '|' in a string $googlefonts_url = "//fonts.googleapis.com/css?family=" . $googlefonts_toload_prepared; $googlefonts_ext = '&subset=latin'; if (get_theme_mod('lbmn_font_characterset_latinextended', 0)) { $googlefonts_ext .= ',latin-ext'; } if (get_theme_mod('lbmn_font_characterset_cyrillic', 0)) { $googlefonts_ext .= ',cyrillic'; } if (get_theme_mod('lbmn_font_characterset_cyrillicextended', 0)) { $googlefonts_ext .= ',cyrillic-ext'; } if (get_theme_mod('lbmn_font_characterset_greek', 0)) { $googlefonts_ext .= ',greek'; } if (get_theme_mod('lbmn_font_characterset_greekextended', 0)) { $googlefonts_ext .= ',greek-ext'; } if (get_theme_mod('lbmn_font_characterset_vietnamese', 0)) { $googlefonts_ext .= ',vietnamese'; } wp_enqueue_style('lbmn-google-fonts', $googlefonts_url . $googlefonts_ext); } }
/** * Render Google Fonts selector */ function render_googlefonts_control($label, $section, $priority, $control_name, $default_font) { global $wp_customize; $googlefonts = lbmn_get_goolefonts(); // $fontchoices = array( '— None —' => '— None —'); $fontchoices = array(); foreach ($googlefonts as $font => $font_ext) { // Prepare font name $fontname = str_replace('+', ' ', $font); // $fontname = str_replace(':', ': ', $fontname); // $fontname = str_replace('00', '00 ', $fontname); if (count($font_ext) && $font != $font_ext) { $fontname .= ': '; $first_custom_weight = true; foreach ($font_ext as $weight) { // if ( $weight == 'regular' ) { // $weight = '400'; // } $custom_font_style = $weight; if (!stristr($weight, 'italic')) { $custom_font_weight = preg_replace("/.*(\\d{3}).*/", "\$1", $weight); $custom_font_weight = intval($custom_font_weight); if ($custom_font_weight == 0) { $custom_font_weight = '400'; } if (!$first_custom_weight) { $fontname .= ', '; } $fontname .= $custom_font_weight; } else { // $fontname .= $weight . ' '; $fontname .= '+i'; } $first_custom_weight = false; } } $fontchoices[$font] = $fontname; } if (isset($label)) { if (!isset($control_name)) { $control_name = strtolower($label); $invalid_characters = array("\$", "%", "#", "<", ">", "|", " "); $control_name = str_replace($invalid_characters, '', $control_name); $control_name = $section . '_' . $control_name; } if (!isset($priority)) { $priority = 20; } $wp_customize->add_setting($control_name, array('default' => $default_font)); $wp_customize->add_control($control_name, array('label' => $label, 'type' => 'select', 'choices' => $fontchoices, 'section' => $section, 'priority' => $priority)); } }
/** * -------------------------------------------------------------------------- * Google Web Fonts * Compose links to the Google Fonts used to be included in the <head> */ function lbmn_google_fonts($wpml_lang = '') { if ($wpml_lang != '') { $wpml_lang = '_' . $wpml_lang; } $googlefonts_toload = array(); $googlefonts_weights = lbmn_get_goolefonts(); $googlefonts_toload_prepared = ''; $first_font = true; for ($i = 1; $i < 5; $i++) { // if use google font check box is selected if (get_theme_mod('lbmn_font_preset_usegooglefont_' . $i . $wpml_lang, 1)) { // If GoogleFont name is set use it if (get_theme_mod('lbmn_font_preset_googlefont_' . $i . $wpml_lang, '')) { $prefix = ''; if (!$first_font) { $prefix = '|'; } $googlefonts_toload[$i] = $prefix . get_theme_mod('lbmn_font_preset_googlefont_' . $i . $wpml_lang, ''); // If no GoogleFont name set use the default one for this preset } else { $prefix = ''; if (!$first_font) { $prefix = '|'; } $googlefonts_toload[$i] = $prefix . get_theme_mod('lbmn_font_preset_googlefont_' . $i . $wpml_lang, constant('LBMN_FONT_PRESET_GOOGLEFONT_' . $i . '_DEFAULT')); } // If font set, attach it's weights if ($googlefonts_toload[$i]) { str_replace(' ', '+', $googlefonts_toload[$i]); $first_weight = true; foreach ($googlefonts_weights[$googlefonts_toload[$i]] as $weight) { // filter our italic fonts for speed optimization if (!stristr($weight, 'italic')) { if ($first_weight) { $googlefonts_toload[$i] .= ':'; } $googlefonts_toload[$i] .= $weight . ','; } $first_weight = false; } if (substr($googlefonts_toload[$i], -1) == ',') { $googlefonts_toload[$i] = substr_replace($googlefonts_toload[$i], "", -1); // remove last character ',' in a string } } } } foreach ($googlefonts_toload as $google_font) { if ($google_font != '') { $googlefonts_toload_prepared .= $google_font . '|'; } } if ($googlefonts_toload_prepared) { $googlefonts_toload_prepared = substr_replace($googlefonts_toload_prepared, "", -1); // remove last character '|' in a string $googlefonts_url = "//fonts.googleapis.com/css?family=" . $googlefonts_toload_prepared; $googlefonts_ext = '&subset=latin'; if (get_theme_mod('lbmn_font_characterset_latinextended', 0)) { $googlefonts_ext .= ',latin-ext'; } if (get_theme_mod('lbmn_font_characterset_cyrillic', 0)) { $googlefonts_ext .= ',cyrillic'; } if (get_theme_mod('lbmn_font_characterset_cyrillicextended', 0)) { $googlefonts_ext .= ',cyrillic-ext'; } if (get_theme_mod('lbmn_font_characterset_greek', 0)) { $googlefonts_ext .= ',greek'; } if (get_theme_mod('lbmn_font_characterset_greekextended', 0)) { $googlefonts_ext .= ',greek-ext'; } if (get_theme_mod('lbmn_font_characterset_vietnamese', 0)) { $googlefonts_ext .= ',vietnamese'; } wp_enqueue_style('lbmn-google-fonts' . $wpml_lang, $googlefonts_url . $googlefonts_ext); } }