ll of the variants associated with our font $variants = $fonts[$id]['variants']; // Loop through them and put them into an array, then turn them into a comma separated list $output = array(); if ( $variants ) { foreach ( $variants as $variant ) { $output[] = $variant; } return implode(',', apply_filters( 'generate_typography_variants', $output )); } } } if ( ! function_exists( 'generate_get_google_font_category' ) ) { /** * Wrapper function to find the category for chosen Google Font * Example: generate_get_google_font_category( 'Open Sans' ) * * @since 1.3.0 */ function generate_get_google_font_category( $font, $key = '', $default = '' ) { // Bail if we don't have our defaults function if ( ! function_exists( 'generate_get_default_fonts' ) ) { return; } // Don't need a category if we're using a system font if ( in_array( $font, generate_typography_default_fonts() ) ) { return; } // Return if we have our variants saved if ( '' !== $key && get_theme_mod( $key . '_category' ) ) { return ', ' . get_theme_mod( $key . '_category' ); } // Make sure we have defaults if ( '' == $default ) { $default = generate_get_default_fonts(); } // If our default font is selected and the category isn't saved, we already know the category if ( $default[ $key ] == $font ) { return ', ' . $default[ $key . '_category' ]; } // Get all of our fonts // It's a big list, so hopefully we're not even still reading $fonts = generate_get_all_google_fonts(); // Get the ID from our font $id = strtolower( str_replace( ' ', '_', $font ) ); // If the ID doesn't exist within our fonts, we can bail if ( ! array_key_exists( $id, $fonts ) ) { return; } // Let's grab our category to go with our font $category = ! empty( $fonts[$id]['category'] ) ? ', ' . $fonts[$id]['category'] : ''; // Return it to be used by our function return $category; } } if ( ! function_exists( 'generate_get_font_family_css' ) ) { /** * Wrapper function to create font-family value for CSS. * * @since 1.3.0 */ function generate_get_font_family_css( $font, $settings, $default ) { $generate_settings = wp_parse_args( get_option( $settings, array() ), $default ); // We don't want to wrap quotes around these values $no_quotes = array( 'inherit', 'Arial, Helvetica, sans-serif', 'Georgia, Times New Roman, Times, serif', 'Helvetica', 'Impact', 'Segoe UI, Helvetica Neue, Helvetica, sans-serif', 'Tahoma, Geneva, sans-serif', 'Trebuchet MS, Helvetica, sans-serif', 'Verdana, Geneva, sans-serif', apply_filters( 'generate_typography_system_stack', '-apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"' ) ); // Get our font $font_family = $generate_settings[ $font ]; if ( 'System Stack' == $font_family ) { $font_family = apply_filters( 'generate_typography_system_stack', '-apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"' ); } // If our value is still using the old format, fix it if ( strpos( $font_family, ':' ) !== false ) { $font_family = current( explode( ':', $font_family ) ); } // Set up our wrapper if ( in_array( $font_family, $no_quotes ) ) { $wrapper_start = null; $wrapper_end = null; } else { $wrapper_start = '"'; $wrapper_end = '"' . generate_get_google_font_category( $font_family, $font, $default ); } // Output the CSS $output = ( 'inherit' == $font_family ) ? 'inherit' : $wrapper_start . $font_family . $wrapper_end; return $output; } } if ( ! function_exists( 'generate_typography_customizer_live_preview' ) ) { add_action( 'customize_preview_init', 'generate_typography_customizer_live_preview' ); /** * Add our live preview JS */ function generate_typography_customizer_live_preview() { wp_enqueue_script( 'generate-typography-customizer', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/customizer.js', array( 'jquery','customize-preview' ), GENERATE_FONT_VERSION, true ); wp_localize_script( 'generate-typography-customizer', 'gp_typography', array( 'mobile' => generate_premium_get_media_query( 'mobile' ), 'tablet' => generate_premium_get_media_query( 'tablet' ), 'desktop' => generate_premium_get_media_query( 'desktop' ), ) ); } } if ( ! function_exists( 'generate_typography_default_fonts' ) ) { /** * Get our system fonts */ function generate_typography_default_fonts() { $fonts = array( 'inherit', 'System Stack', 'Arial, Helvetica, sans-serif', 'Century Gothic', 'Comic Sans MS', 'Courier New', 'Georgia, Times New Roman, Times, serif', 'Helvetica', 'Impact', 'Lucida Console', 'Lucida Sans Unicode', 'Palatino Linotype', 'Segoe UI, Helvetica Neue, Helvetica, sans-serif', 'Tahoma, Geneva, sans-serif', 'Trebuchet MS, Helvetica, sans-serif', 'Verdana, Geneva, sans-serif' ); return apply_filters( 'generate_typography_default_fonts', $fonts ); } } if ( ! function_exists( 'generate_include_typography_defaults' ) ) { /** * Check if we should include our default.css file * @since 1.3.42 */ function generate_include_typography_defaults() { return true; } } if ( ! function_exists( 'generate_typography_premium_css_defaults' ) ) { add_filter( 'generate_font_option_defaults', 'generate_typography_premium_css_defaults' ); /** * Add premium control defaults * * @since 1.3 */ function generate_typography_premium_css_defaults( $defaults ) { $defaults['tablet_site_title_font_size'] = ''; $defaults['tablet_navigation_font_size'] = ''; $defaults['mobile_navigation_font_size'] = ''; $defaults['single_post_title_weight'] = ''; $defaults['single_post_title_transform'] = ''; $defaults['single_post_title_font_size'] = ''; $defaults['single_post_title_font_size_mobile'] = ''; $defaults['single_post_title_line_height'] = ''; $defaults['archive_post_title_weight'] = ''; $defaults['archive_post_title_transform'] = ''; $defaults['archive_post_title_font_size'] = ''; $defaults['archive_post_title_font_size_mobile'] = ''; $defaults['archive_post_title_line_height'] = ''; return $defaults; } } if ( ! function_exists( 'generate_typography_premium_css' ) ) { add_action( 'wp_enqueue_scripts', 'generate_typography_premium_css', 100 ); /** * Add premium control CSS * * @since 1.3 */ function generate_typography_premium_css() { if ( ! function_exists( 'generate_get_default_fonts' ) ) { return; } $generate_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_default_fonts() ); // Initiate our CSS class require_once GP_LIBRARY_DIRECTORY . 'class-make-css.php'; $premium_css = new GeneratePress_Pro_CSS; $site_title_family = false; if ( function_exists( 'generate_get_font_family_css' ) ) { $site_title_family = generate_get_font_family_css( 'font_site_title', 'generate_settings', generate_get_default_fonts() ); } $premium_css->set_selector( 'h1.entry-title' ); $premium_css->add_property( 'font-weight', esc_attr( $generate_settings['single_post_title_weight'] ) ); $premium_css->add_property( 'text-transform', esc_attr( $generate_settings['single_post_title_transform'] ) ); if ( '' !== $generate_settings['single_post_title_font_size'] ) { $premium_css->add_property( 'font-size', absint( $generate_settings['single_post_title_font_size'] ), false, 'px' ); } if ( '' !== $generate_settings['single_post_title_line_height'] ) { $premium_css->add_property( 'line-height', floatval( $generate_settings['single_post_title_line_height'] ), false, 'em' ); } $premium_css->set_selector( 'h2.entry-title' ); $premium_css->add_property( 'font-weight', esc_attr( $generate_settings['archive_post_title_weight'] ) ); $premium_css->add_property( 'text-transform', esc_attr( $generate_settings['archive_post_title_transform'] ) ); if ( '' !== $generate_settings['archive_post_title_font_size'] ) { $premium_css->add_property( 'font-size', absint( $generate_settings['archive_post_title_font_size'] ), false, 'px' ); } if ( '' !== $generate_settings['archive_post_title_line_height'] ) { $premium_css->add_property( 'line-height', floatval( $generate_settings['archive_post_title_line_height'] ), false, 'em' ); } $premium_css->set_selector( '.navigation-branding .main-title' ); $premium_css->add_property( 'font-weight', esc_attr( $generate_settings['site_title_font_weight'] ) ); $premium_css->add_property( 'text-transform', esc_attr( $generate_settings['site_title_font_transform'] ) ); $premium_css->add_property( 'font-size', absint( $generate_settings['site_title_font_size'] ), false, 'px' ); if ( $site_title_family ) { $premium_css->add_property( 'font-family', 'inherit' !== $generate_settings['font_site_title'] ? $site_title_family : null ); } $premium_css->start_media_query( generate_premium_get_media_query( 'tablet' ) ); if ( '' !== $generate_settings[ 'tablet_navigation_font_size' ] ) { $premium_css->set_selector( '.main-navigation:not(.slideout-navigation) a, .menu-toggle' ); $premium_css->add_property( 'font-size', absint( $generate_settings[ 'tablet_navigation_font_size' ] ), false, 'px' ); $tablet_subnav_font_size = $generate_settings['tablet_navigation_font_size'] - 1; if ( $generate_settings['tablet_navigation_font_size'] >= 17 ) { $tablet_subnav_font_size = $generate_settings['tablet_navigation_font_size'] - 3; } $premium_css->set_selector( '.main-navigation:not(.slideout-navigation) .main-nav ul ul li a' ); $premium_css->add_property( 'font-size', absint( $tablet_subnav_font_size ), false, 'px' ); } if ( '' !== $generate_settings['tablet_site_title_font_size'] ) { $premium_css->set_selector( '.main-title, .navigation-branding .main-title' ); $premium_css->add_property( 'font-size', absint( $generate_settings['tablet_site_title_font_size'] ), false, 'px' ); } $premium_css->stop_media_query(); $premium_css->start_media_query( generate_premium_get_media_query( 'mobile' ) ); $premium_css->set_selector( 'h1.entry-title' ); if ( '' !== $generate_settings['single_post_title_font_size_mobile'] ) { $premium_css->add_property( 'font-size', absint( $generate_settings['single_post_title_font_size_mobile'] ), false, 'px' ); } $premium_css->set_selector( 'h2.entry-title' ); if ( '' !== $generate_settings['archive_post_title_font_size_mobile'] ) { $premium_css->add_property( 'font-size', absint( $generate_settings['archive_post_title_font_size_mobile'] ), false, 'px' ); } $premium_css->stop_media_query(); $premium_css->start_media_query( generate_premium_get_media_query( 'mobile-menu' ) ); if ( '' !== $generate_settings[ 'mobile_navigation_font_size' ] ) { $premium_css->set_selector( '.main-navigation:not(.slideout-navigation) a, .menu-toggle' ); $premium_css->add_property( 'font-size', absint( $generate_settings[ 'mobile_navigation_font_size' ] ), false, 'px' ); $mobile_subnav_font_size = $generate_settings['mobile_navigation_font_size'] - 1; if ( $generate_settings['mobile_navigation_font_size'] >= 17 ) { $mobile_subnav_font_size = $generate_settings['mobile_navigation_font_size'] - 3; } $premium_css->set_selector( '.main-navigation:not(.slideout-navigation) .main-nav ul ul li a' ); $premium_css->add_property( 'font-size', absint( $mobile_subnav_font_size ), false, 'px' ); } if ( '' !== $generate_settings['mobile_site_title_font_size'] ) { $premium_css->set_selector( '.navigation-branding .main-title' ); $premium_css->add_property( 'font-size', absint( $generate_settings['mobile_site_title_font_size'] ), false, 'px' ); } $premium_css->stop_media_query(); wp_add_inline_style( 'generate-style', $premium_css->css_output() ); } }