diff --git a/includes/functions/_theme_setup.php b/includes/functions/_theme_setup.php index 5e712364..0b7bc9a6 100644 --- a/includes/functions/_theme_setup.php +++ b/includes/functions/_theme_setup.php @@ -1067,31 +1067,12 @@ if ( ! function_exists( 'fictioneer_output_head_meta' ) ) { // Custom fonts $bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css'; - // Make sure directory exists - if ( ! file_exists( dirname( $bundled_fonts ) ) ) { - mkdir( dirname( $bundled_fonts ), 0755, true ); - } - // Create file if it does not exist if ( ! file_exists( $bundled_fonts ) ) { - // Prepare - $fonts = fictioneer_get_font_data(); - $combined_font_css = ''; - - // Build - foreach ( $fonts as $font ) { - if ( $font['skip'] ?? 0 ) { - continue; - } - - $combined_font_css .= file_get_contents( $font['css_file'] ); - } - - // Save - file_put_contents( $bundled_fonts, $combined_font_css ); + fictioneer_build_bundled_fonts(); } - if ( file_exists( dirname( $bundled_fonts ) ) ) { + if ( file_exists( $bundled_fonts ) ) { $custom_fonts_href = get_template_directory_uri() . '/cache/bundled-fonts.css'; // Start HTML ---> ?> diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index 888c5fb4..ca1f5cb0 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -2721,7 +2721,7 @@ function fictioneer_append_meta_fields( $post_type, $meta_key, $meta_value ) { } // ============================================================================= -// GET FONTS +// GET FONT DATA // ============================================================================= /** @@ -2768,4 +2768,32 @@ function fictioneer_get_font_data() { return $fonts; } +// ============================================================================= +// BUILD BUNDLED FONT CSS FILE +// ============================================================================= + +function fictioneer_build_bundled_fonts() { + // Setup + $bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css'; + $fonts = fictioneer_get_font_data(); + $combined_font_css = ''; + + // Make sure directory exists + if ( ! file_exists( dirname( $bundled_fonts ) ) ) { + mkdir( dirname( $bundled_fonts ), 0755, true ); + } + + // Build + foreach ( $fonts as $font ) { + if ( $font['skip'] ?? 0 ) { + continue; + } + + $combined_font_css .= file_get_contents( $font['css_file'] ); + } + + // Save + file_put_contents( $bundled_fonts, $combined_font_css ); +} + ?>