From 836944c921b0cfa336f3ba92102e35714c11da99 Mon Sep 17 00:00:00 2001 From: Yogesh Sambare <91533131+yssambare12@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:42:00 +0530 Subject: [PATCH] chore:code refactor --- classes/class-bsf-custom-fonts-render.php | 40 +++++++++++++---------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/classes/class-bsf-custom-fonts-render.php b/classes/class-bsf-custom-fonts-render.php index f9908fb..dde6613 100644 --- a/classes/class-bsf-custom-fonts-render.php +++ b/classes/class-bsf-custom-fonts-render.php @@ -131,12 +131,9 @@ public function __construct() { add_filter( 'fl_theme_system_fonts', array( $this, 'bb_custom_fonts' ) ); add_filter( 'fl_builder_font_families_system', array( $this, 'bb_custom_fonts' ) ); - // Add font files style. - if ( class_exists( 'Thrive_Product_Manager' ) || class_exists( 'TVA_Const' ) ) { - add_action( 'wp_head', array( $this, 'add_style' ) ); - } else { - add_action( 'wp_enqueue_scripts', array( $this, 'preload_styles' ), 1 ); - } + // Add font file styles. + add_action( 'wp_head', array( $this, 'add_style' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'preload_styles' ), 1 ); add_action( 'init', array( $this, 'add_block_assets_style' ) ); add_filter( 'elementor/fonts/groups', array( $this, 'elementor_group' ) ); @@ -281,20 +278,24 @@ public function enque_data() { * @since 1.0.4 */ public function add_style() { - $font_styles = ''; - $query_posts = $this->get_existing_font_posts(); - if ( $query_posts ) { - foreach ( $query_posts as $key => $post_id ) { - $font_styles .= get_post_meta( $post_id, 'fonts-face', true ); + if ( class_exists( 'Thrive_Product_Manager' ) || class_exists( 'TVA_Const' ) ) { + + $font_styles = ''; + $query_posts = $this->get_existing_font_posts(); + + if ( $query_posts ) { + foreach ( $query_posts as $key => $post_id ) { + $font_styles .= get_post_meta( $post_id, 'fonts-face', true ); + } + wp_reset_postdata(); } - wp_reset_postdata(); - } - if ( ! empty( $font_styles ) ) { - wp_register_style( 'cf-frontend-style', false, array(), BSF_CUSTOM_FONTS_VER ); - wp_enqueue_style( 'cf-frontend-style' ); - wp_add_inline_style( 'cf-frontend-style', wp_strip_all_tags( $font_styles ) ); + if ( ! empty( $font_styles ) ) { + wp_register_style( 'cf-frontend-style', false, array(), BSF_CUSTOM_FONTS_VER ); + wp_enqueue_style( 'cf-frontend-style' ); + wp_add_inline_style( 'cf-frontend-style', wp_strip_all_tags( $font_styles ) ); + } } } @@ -304,6 +305,11 @@ public function add_style() { * @since x.x.x */ public function preload_styles() { + + if ( class_exists( 'Thrive_Product_Manager' ) || class_exists( 'TVA_Const' ) ) { + return; + } + $font_urls = get_option( 'bcf_font_urls', array() ); if ( true === (bool) get_option( 'bcf_preloading_fonts', false ) && ! empty( $font_urls ) ) {