PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.4.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.4.0
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Editors / BlockEditor / FontLoader.php

FontLoader.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.4.0, at includes/Editors/BlockEditor/FontLoader.php

76 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Editors\BlockEditor;
4
5 use WPDeveloper\BetterDocs\Utils\Base;
6
7 class FontLoader extends Base {
8
9 public static $registered_blocks = [
10 'betterdocs/betterdocs-print',
11 'betterdocs/breadcrumb',
12 'betterdocs/categorybox',
13 'betterdocs/categorygrid',
14 'betterdocs/archive-doc-list',
15 'betterdocs/single-doc-content',
16 'betterdocs/date',
17 'betterdocs/doc-navigation',
18 'betterdocs/feedback-form',
19 'betterdocs/reactions',
20 'betterdocs/searchbox',
21 'betterdocs/sidebar',
22 'betterdocs/social-share',
23 'betterdocs/table-of-contents',
24 'betterdocs/multiple-kb'
25 ];
26
27 public static $retrieved_fonts = [];
28
29 public function __construct() {
30 add_filter( 'render_block', [$this, 'get_betterdocs_blocks'], 10, 2 );
31 add_action( 'wp_footer', [$this, 'enqueue_google_fonts'], 10 );
32 }
33
34 public function get_betterdocs_blocks( $block_content, $block ) {
35 if ( isset( $block['attrs'] ) ) {
36 if ( in_array( $block['blockName'], self::$registered_blocks ) ) {
37 $fonts = self::get_fonts_family( $block['attrs'] );
38 self::$retrieved_fonts = array_unique( array_merge( self::$retrieved_fonts, $fonts ) );
39 }
40 }
41
42 return $block_content;
43 }
44
45 public static function get_fonts_family( $attributes ) {
46 $keys = preg_grep( '/^(\w+)FontFamily/i', array_keys( $attributes ), 0 );
47 $google_font_family = [];
48 foreach ( $keys as $key ) {
49 $google_font_family[$attributes[$key]] = $attributes[$key];
50 }
51 return $google_font_family;
52 }
53
54 public function enqueue_google_fonts() {
55 if( ! empty( self::$retrieved_fonts ) ) {
56 $google_fonts = '';
57 $google_fonts_attr = ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic';
58 foreach ( self::$retrieved_fonts as $font ) {
59 $google_fonts .= str_replace( ' ', '+', trim( $font ) ) . $google_fonts_attr . '|';
60 }
61 if ( ! empty( $google_fonts ) ) {
62 $query_args = [
63 'family' => $google_fonts
64 ];
65 wp_register_style(
66 'betterdocs-goggle-fonts',
67 add_query_arg( $query_args, '//fonts.googleapis.com/css' ),
68 [],
69 betterdocs()->version
70 );
71 wp_enqueue_style( 'betterdocs-goggle-fonts' );
72 }
73 }
74 }
75 }
76