Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function flash_scripts() {

// Kirki Toolkit.
require get_template_directory() . '/inc/kirki/kirki.php';
require get_template_directory() . '/inc/kirki-local-fonts.php';

// Customizer additions.s
require get_template_directory() . '/inc/customizer.php';
Expand Down
55 changes: 55 additions & 0 deletions inc/kirki-local-fonts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

defined( 'ABSPATH' ) || exit;

function flash_kirki_local_fonts_ready( $fonts = array() ) {
$dir = WP_CONTENT_DIR . '/fonts';

if ( ! file_exists( $dir ) ) {
return wp_is_writable( WP_CONTENT_DIR );
}

if ( wp_is_writable( $dir ) ) {
return true;
}

if ( empty( $fonts ) ) {
return (bool) glob( $dir . '/*/*.*' );
}

foreach ( array_keys( $fonts ) as $family ) {
$folder = $dir . '/' . sanitize_key( strtolower( str_replace( ' ', '-', $family ) ) );
if ( ! glob( $folder . '/*.*' ) ) {
return false;
}
}

return true;
}

function flash_kirki_skip_fonts_when_unwritable( $fonts ) {
if ( is_admin() || is_customize_preview() ) {
return $fonts;
}

return flash_kirki_local_fonts_ready( $fonts ) ? $fonts : array();
}
add_filter( 'kirki_enqueue_google_fonts', 'flash_kirki_skip_fonts_when_unwritable' );

function flash_kirki_schedule_font_prewarm() {
if ( ! flash_kirki_local_fonts_ready() ) {
return;
}

if ( ! wp_next_scheduled( 'flash_kirki_prewarm_fonts' ) ) {
wp_schedule_single_event( time(), 'flash_kirki_prewarm_fonts' );
}

spawn_cron();
}
add_action( 'customize_save_after', 'flash_kirki_schedule_font_prewarm' );

function flash_kirki_prewarm_fonts() {
wp_remote_get( home_url( '/' ), array( 'timeout' => 15, 'sslverify' => false ) );
}
add_action( 'flash_kirki_prewarm_fonts', 'flash_kirki_prewarm_fonts' );
Loading