Move building to separate function

This commit is contained in:
Tetrakern 2024-02-07 02:43:01 +01:00
parent aac9f5a2b9
commit ddfd61cb34
2 changed files with 31 additions and 22 deletions

View File

@ -1067,31 +1067,12 @@ if ( ! function_exists( 'fictioneer_output_head_meta' ) ) {
// Custom fonts // Custom fonts
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css'; $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 // Create file if it does not exist
if ( ! file_exists( $bundled_fonts ) ) { if ( ! file_exists( $bundled_fonts ) ) {
// Prepare fictioneer_build_bundled_fonts();
$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 );
} }
if ( file_exists( dirname( $bundled_fonts ) ) ) { if ( file_exists( $bundled_fonts ) ) {
$custom_fonts_href = get_template_directory_uri() . '/cache/bundled-fonts.css'; $custom_fonts_href = get_template_directory_uri() . '/cache/bundled-fonts.css';
// Start HTML ---> ?> // Start HTML ---> ?>

View File

@ -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; 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 );
}
?> ?>