get_array(); self::$google_fonts = []; if ( is_array( $fonts ) ) { foreach ( $fonts['items'] as $font ) { self::$google_fonts[ $font['family'] ] = [ 'label' => $font['family'], 'variants' => $font['variants'], 'category' => $font['category'], ]; } } // Apply the 'kirki_fonts_google_fonts' filter. self::$google_fonts = apply_filters( 'kirki_fonts_google_fonts', self::$google_fonts ); // Save the array in cache. $cache_time = apply_filters( 'kirki_googlefonts_transient_time', HOUR_IN_SECONDS ); set_site_transient( 'kirki_googlefonts_cache', self::$google_fonts, $cache_time ); return self::$google_fonts; } /** * Return an array of all available Google Font names. * * @access public * @since 1.0.2 * @return array All Google Font names. */ public function get_google_font_names() { // Get fonts from cache. self::$google_font_names = get_site_transient( 'kirki_googlefont_names_cache' ); // If cache is populated, return cached fonts array. if ( self::$google_font_names ) { return self::$google_font_names; } // If we got this far, cache was empty so we need to get from JSON. self::$google_font_names = $this->get_names_array(); // Apply the 'kirki_fonts_google_font_names' filter. self::$google_font_names = apply_filters( 'kirki_fonts_google_font_names', self::$google_font_names ); // Save the array in cache. $cache_time = apply_filters( 'kirki_googlefont_names_transient_time', HOUR_IN_SECONDS ); set_site_transient( 'kirki_googlefont_names_cache', self::$google_font_names, $cache_time ); return self::$google_font_names; } /** * Returns an array of google-fonts matching our arguments. * * @access public * @since 1.0.0 * @param array $args The arguments. * @return array */ public function get_google_fonts_by_args( $args = [] ) { $cache_name = 'kirki_googlefonts_' . md5( wp_json_encode( $args ) ); $cache = get_site_transient( $cache_name ); if ( $cache ) { return $cache; } $args['sort'] = isset( $args['sort'] ) ? $args['sort'] : 'alpha'; $fonts = $this->get_array(); $ordered_fonts = $fonts['order'][ $args['sort'] ]; if ( isset( $args['count'] ) ) { $ordered_fonts = array_slice( $ordered_fonts, 0, $args['count'] ); set_site_transient( $cache_name, $ordered_fonts, HOUR_IN_SECONDS ); return $ordered_fonts; } set_site_transient( $cache_name, $ordered_fonts, HOUR_IN_SECONDS ); return $ordered_fonts; } }