:["regular"]},{"family":"Bonbon","category":"handwriting","variants":["regular"]},{"family":"Stalinist One","category":"display","variants":["regular"]},{"family":"Mr Bedfort","category":"handwriting","variants":["regular"]},{"family":"Eater","category":"display","variants":["regular"]},{"family":"Fasthand","category":"serif","variants":["regular"]},{"family":"Mogra","category":"display","variants":["regular"]},{"family":"Padauk","category":"sans-serif","variants":["regular","700"]},{"family":"Preahvihear","category":"display","variants":["regular"]},{"family":"Flavors","category":"display","variants":["regular"]},{"family":"Ruge Boogie","category":"handwriting","variants":["regular"]},{"family":"Tenali Ramakrishna","category":"sans-serif","variants":["regular"]},{"family":"Unlock","category":"display","variants":["regular"]},{"family":"Butcherman","category":"display","variants":["regular"]},{"family":"Baloo Da","category":"display","variants":["regular"]},{"family":"Lakki Reddy","category":"handwriting","variants":["regular"]},{"family":"Cormorant Unicase","category":"serif","variants":["300","regular","500","600","700"]},{"family":"Katibeh","category":"display","variants":["regular"]},{"family":"Asar","category":"serif","variants":["regular"]},{"family":"Emblema One","category":"display","variants":["regular"]},{"family":"Moulpali","category":"display","variants":["regular"]},{"family":"Meera Inimai","category":"sans-serif","variants":["regular"]},{"family":"Kantumruy","category":"sans-serif","variants":["300","regular","700"]},{"family":"Suravaram","category":"serif","variants":["regular"]},{"family":"Bungee Hairline","category":"display","variants":["regular"]},{"family":"Overpass Mono","category":"monospace","variants":["300","regular","600","700"]},{"family":"Peddana","category":"serif","variants":["regular"]},{"family":"Bahiana","category":"display","variants":["regular"]},{"family":"Kumar One Outline","category":"display","variants":["regular"]},{"family":"Hanalei Fill","category":"display","variants":["regular"]},{"family":"Dhurjati","category":"sans-serif","variants":["regular"]},{"family":"Hanalei","category":"display","variants":["regular"]},{"family":"Kavivanar","category":"handwriting","variants":["regular"]},{"family":"Bungee Outline","category":"display","variants":["regular"]},{"family":"BioRhyme Expanded","category":"serif","variants":["200","300","regular","700","800"]}]' ); // Loop through them and put what we need into our fonts array. $fonts = array(); foreach ( $content as $item ) { // Grab what we need from our big list. $atts = array( 'name' => $item->family, 'category' => $item->category, 'variants' => $item->variants, ); // Create an ID using our font family name. $id = strtolower( str_replace( ' ', '_', $item->family ) ); // Add our attributes to our new array. $fonts[ $id ] = $atts; } if ( 'all' !== $amount ) { $fonts = array_slice( $fonts, 0, $amount ); } if ( apply_filters( 'generate_alphabetize_google_fonts', true ) ) { asort( $fonts ); } return apply_filters( 'generate_google_fonts_array', $fonts ); } } if ( ! function_exists( 'generate_get_all_google_fonts_ajax' ) ) { add_action( 'wp_ajax_generate_get_all_google_fonts_ajax', 'generate_get_all_google_fonts_ajax' ); /** * Return an array of all of our Google Fonts. * * @since 1.3.0 */ function generate_get_all_google_fonts_ajax() { if ( generate_is_using_dynamic_typography() ) { wp_die(); } if ( ! isset( $_POST['gp_customize_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['gp_customize_nonce'] ), 'gp_customize_nonce' ) ) { wp_die(); } check_ajax_referer( 'gp_customize_nonce', 'gp_customize_nonce' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die(); } $fonts = generate_get_all_google_fonts(); echo wp_json_encode( $fonts ); die(); } } if ( ! function_exists( 'generate_get_google_font_variants' ) ) { /** * Wrapper function to find variants for chosen Google Fonts * Example: generate_get_google_font_variation( 'Open Sans' ) * * @since 1.3.0 * * @param string $font The font to look up. * @param string $key The option to look up. */ function generate_get_google_font_variants( $font, $key = '' ) { // Don't need variants 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 . '_variants' ) ) { return get_theme_mod( $key . '_variants' ); } $defaults = generate_get_default_fonts(); if ( $defaults[ $key ] === $font ) { return $defaults[ $key . '_variants' ]; } // Grab 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; } // Grab all 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 * * @param string $font The name of our font. * @param string $key The ID of the font setting. * @return string The category of our font. */ function generate_get_google_font_category( $font, $key = '' ) { // 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' ); } $defaults = generate_get_default_fonts(); // If our default font is selected and the category isn't saved, we already know the category. if ( $defaults[ $key ] === $font ) { return ', ' . $defaults[ $key . '_category' ]; } // Grab 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 $category; } } if ( ! function_exists( 'generate_get_font_family_css' ) ) { /** * Wrapper function to create font-family value for CSS. * * @since 1.3.0 * * @param string $font The name of our font. * @param string $settings The ID of the settings we're looking up. * @param array $default The defaults for our $settings. * @return string The CSS value for our font family. */ 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"' ), ); $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 ); } $output = ( 'inherit' === $font_family ) ? '' : $wrapper_start . $font_family . $wrapper_end; return $output; } } if ( ! function_exists( 'generate_add_to_font_customizer_list' ) ) { add_filter( 'generate_typography_customize_list', 'generate_add_to_font_customizer_list' ); /** * This function makes sure your selected typography option exists in the Customizer list * Why wouldn't it? Originally, all 800+ fonts were in each list. This has been reduced to 200. * This functions makes sure that if you were using a font that is now not included in the 200, you won't lose it. * * @since 1.3.40 * * @param array $fonts The existing fonts. */ function generate_add_to_font_customizer_list( $fonts ) { // Bail if we don't have our defaults. if ( ! function_exists( 'generate_get_default_fonts' ) ) { return; } $generate_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_default_fonts() ); $font_settings = array( 'font_body', 'font_top_bar', 'font_site_title', 'font_site_tagline', 'font_navigation', 'font_widget_title', 'font_heading_1', 'font_heading_2', 'font_heading_3', ); $all_fonts = generate_get_all_google_fonts(); $select_fonts = generate_get_all_google_fonts( apply_filters( 'generate_number_of_fonts', 200 ) ); foreach ( $font_settings as $setting ) { // If we don't have a setting, keep going. if ( ! isset( $generate_settings[ $setting ] ) ) { continue; } $id = strtolower( str_replace( ' ', '_', $generate_settings[ $setting ] ) ); if ( array_key_exists( $id, $select_fonts ) || in_array( $generate_settings[ $setting ], generate_typography_default_fonts() ) ) { continue; } $fonts[ strtolower( str_replace( ' ', '_', $generate_settings[ $setting ] ) ) ] = array( 'name' => $generate_settings[ $setting ], 'variants' => array_key_exists( $id, $all_fonts ) ? $all_fonts[ $id ]['variants'] : array(), 'category' => array_key_exists( $id, $all_fonts ) ? $all_fonts[ $id ]['category'] : 'sans-serif', ); } if ( function_exists( 'generate_secondary_nav_get_defaults' ) ) { $secondary_nav_settings = wp_parse_args( get_option( 'generate_secondary_nav_settings', array() ), generate_secondary_nav_get_defaults() ); $secondary_nav_id = strtolower( str_replace( ' ', '_', $secondary_nav_settings['font_secondary_navigation'] ) ); if ( ! array_key_exists( $secondary_nav_id, $select_fonts ) && ! in_array( $secondary_nav_settings['font_secondary_navigation'], generate_typography_default_fonts() ) ) { $fonts[ strtolower( str_replace( ' ', '_', $secondary_nav_settings['font_secondary_navigation'] ) ) ] = array( 'name' => $secondary_nav_settings['font_secondary_navigation'], 'variants' => array_key_exists( $secondary_nav_id, $all_fonts ) ? $all_fonts[ $secondary_nav_id ]['variants'] : array(), 'category' => array_key_exists( $secondary_nav_id, $all_fonts ) ? $all_fonts[ $secondary_nav_id ]['category'] : 'sans-serif', ); } } return $fonts; } } if ( ! function_exists( 'generate_typography_set_font_data' ) ) { add_action( 'admin_init', 'generate_typography_set_font_data' ); /** * This function will check to see if your category and variants are saved * If not, it will set them for you * Generally, set_theme_mod isn't best practice, but this is here for migration purposes for a set amount of time only * Any time a user saves a font in the Customizer from now on, the category and variants are saved as theme_mods, so this function won't be necessary. * * @since 1.3.40 */ function generate_typography_set_font_data() { if ( generate_is_using_dynamic_typography() ) { return; } // Get our defaults. $defaults = generate_get_default_fonts(); // Get our settings. $generate_settings = wp_parse_args( get_option( 'generate_settings', array() ), $defaults ); // We don't need to do this if we're using the default font, as these values have defaults already. if ( $defaults['font_body'] == $generate_settings['font_body'] ) { // phpcs:ignore return; } // Don't need to continue if we're using a system font or our default font. if ( in_array( $generate_settings['font_body'], generate_typography_default_fonts() ) ) { return; } // Don't continue if our category and variants are already set. if ( get_theme_mod( 'font_body_category' ) && get_theme_mod( 'font_body_variants' ) ) { return; } // Get all of our fonts. $fonts = generate_get_all_google_fonts(); // Get the ID from our font. $id = strtolower( str_replace( ' ', '_', $generate_settings['font_body'] ) ); // 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'] : ''; // Grab all of the variants associated with our font. $variants = $fonts[ $id ]['variants']; // Loop through our variants and put them into an array, then turn them into a comma separated list. $output = array(); if ( $variants ) { foreach ( $variants as $variant ) { $output[] = $variant; } $variants = implode( ',', $output ); } // Set our theme mods with our new settings. if ( '' !== $category ) { set_theme_mod( 'font_body_category', $category ); } if ( '' !== $variants ) { set_theme_mod( 'font_body_variants', $variants ); } } }