2025-07-27 19:55:19 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Helper class for font settings.
|
|
|
|
|
*
|
|
|
|
|
* @package Astra
|
|
|
|
|
* @link https://wpastra.com/
|
|
|
|
|
* @since Astra 1.0.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Exit if accessed directly.
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Font info class for System and Google fonts.
|
|
|
|
|
*/
|
|
|
|
|
if ( ! class_exists( 'Astra_Fonts_Data' ) ) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fonts Data
|
|
|
|
|
*/
|
|
|
|
|
final class Astra_Fonts_Data {
|
|
|
|
|
/**
|
|
|
|
|
* Localize Fonts
|
2025-12-12 13:14:39 +01:00
|
|
|
*
|
|
|
|
|
* @param bool $skip_google_fonts Whether to skip Google Fonts loading for initial load optimization.
|
2025-07-27 19:55:19 +02:00
|
|
|
*/
|
2025-12-12 13:14:39 +01:00
|
|
|
public static function js( $skip_google_fonts = true ) {
|
2025-07-27 19:55:19 +02:00
|
|
|
|
|
|
|
|
$system = wp_json_encode( Astra_Font_Families::get_system_fonts() );
|
|
|
|
|
$custom = wp_json_encode( Astra_Font_Families::get_custom_fonts() );
|
2025-12-12 13:14:39 +01:00
|
|
|
|
|
|
|
|
/** @psalm-suppress UndefinedVariable */
|
|
|
|
|
if ( $skip_google_fonts ) {
|
|
|
|
|
$custom = $custom ? $custom : '{}';
|
|
|
|
|
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
|
|
|
|
if ( ! empty( $custom ) && '{}' !== $custom ) {
|
|
|
|
|
return 'var AstFontFamilies = { system: ' . ( $system ?: '{}' ) . ', custom: ' . $custom . ', google: {}, googleLoaded: false };';
|
|
|
|
|
}
|
|
|
|
|
return 'var AstFontFamilies = { system: ' . ( $system ?: '{}' ) . ', google: {}, googleLoaded: false };';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$google = wp_json_encode( Astra_Font_Families::get_google_fonts() );
|
|
|
|
|
$custom = $custom ? $custom : '{}';
|
|
|
|
|
$google = $google ? $google : '{}';
|
|
|
|
|
$system = $system ? $system : '{}';
|
|
|
|
|
|
|
|
|
|
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
|
|
|
|
if ( ! empty( $custom ) && '{}' !== $custom ) {
|
|
|
|
|
return 'var AstFontFamilies = { system: ' . $system . ', custom: ' . $custom . ', google: ' . $google . ', googleLoaded: true };';
|
2025-07-27 19:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-12 13:14:39 +01:00
|
|
|
return 'var AstFontFamilies = { system: ' . $system . ', google: ' . $google . ', googleLoaded: true };';
|
2025-07-27 19:55:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|