fonts_loader(); } /** * Get Attributes on block render * @since 4.0.2 * @access public */ public function get_fonts_on_render_block( $block_content, $block ) { if ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) { // `blockName` is null for classic/freeform content and can be absent // on synthetic block arrays — reading it blind warns on PHP 8.0+. $block_name = isset( $block['blockName'] ) ? $block['blockName'] : ''; if ( 'essential-blocks' === self::$block_name || $block_name === self::$block_name ) { $fonts = self::get_fonts_family( $block['attrs'] ); self::$gfonts = array_unique( array_merge( self::$gfonts, $fonts ) ); } } return $block_content; } /** * Generate Font family from Attributes * @since 4.0.0 * @access public */ public static function get_fonts_family( $attributes ) { $googleFontFamily = []; if ( ! is_array( $attributes ) ) { return $googleFontFamily; } $keys = preg_grep( '/^(\w+)FontFamily/i', array_keys( $attributes ), 0 ); if ( empty( $keys ) ) { return $googleFontFamily; } foreach ( $keys as $key ) { // A non-scalar attribute value used as an array key is an // "Illegal offset type" TypeError on PHP 8.0+. if ( ! is_string( $attributes[$key] ) || '' === $attributes[$key] ) { continue; } $googleFontFamily[$attributes[$key]] = $attributes[$key]; } return $googleFontFamily; } /** * Load fonts. * @since 4.0.0 * @access public */ public function fonts_loader( $handle_name = 'eb-block-fonts' ) { $googleFont = true; if ( 'essential-blocks' === self::$block_name ) { $eb_settings = get_option( 'eb_settings', [] ); $googleFont = ! empty( $eb_settings['googleFont'] ) ? $eb_settings['googleFont'] : 'true'; } if ( 'false' !== $googleFont ) { $fonts = self::$gfonts; if ( ( $key = array_search( 'Default', $fonts, true ) ) !== false ) { unset( $fonts[$key] ); } if ( ! empty( $fonts ) ) { $gfonts = ''; $gfonts_attr = ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic'; foreach ( $fonts as $font ) { $gfonts .= str_replace( ' ', '+', trim( $font ) ) . $gfonts_attr . '|'; } if ( ! empty( $gfonts ) ) { $query_args = [ 'family' => $gfonts ]; wp_register_style( $handle_name, add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ), [] ); wp_enqueue_style( $handle_name ); } // Reset. $gfonts = ''; } } } } Accordion_Font_Loder::get_instance( 'accordion-toggle/accordion-toggle' );