PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.2.2
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.2.2
3.1.0 3.0.0 2.13.2 2.13.1 2.13.0 trunk 1.0.0 2.1.0 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.1 2.5.3 2.5.4 2.5.5 2.6.1 All 56 releases
slider-blocks / includes / classes / class-load-fonts.php

class-load-fonts.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 2.2.2, at includes/classes/class-load-fonts.php

96 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Load Google Fonts
4 * @package GutSliderBlocks
5 */
6
7 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
8
9 if( ! class_exists( 'GutSlider_Load_Fonts' ) ) {
10
11 class GutSlider_Load_Fonts {
12
13 private static $all_fonts = [];
14
15 /**
16 * Constructor
17 * return void
18 */
19 public function __construct() {
20 add_action( 'wp_enqueue_scripts', [ $this, 'fonts_loader' ] );
21 add_action( 'admin_enqueue_scripts', [ $this, 'fonts_loader' ] );
22 add_action('gutsliders_render_block', [ $this, 'font_generator' ]);
23 }
24
25 /**
26 * Font generator
27 * return void
28 */
29 public function font_generator( $block ) {
30 if ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) {
31 $attributes = $block['attrs'];
32
33 foreach ( $attributes as $key => $value ) {
34 if ( ! empty( $value ) && strpos( $key, 'gutsliders_' ) === 0 && strpos( $key, 'FontFamily' ) !== false ) {
35 self::$all_fonts[] = $value;
36 }
37 }
38 }
39 }
40
41 /**
42 * Load fonts
43 * return void
44 */
45 public function fonts_loader() {
46 if ( is_array( self::$all_fonts ) && count( self::$all_fonts ) > 0 ) {
47
48 $fonts = array_filter( array_unique( self::$all_fonts ) );
49
50 if ( ! empty( $fonts ) ) {
51
52 $system = array(
53 'Arial',
54 'Tahoma',
55 'Verdana',
56 'Helvetica',
57 'Times New Roman',
58 'Trebuchet MS',
59 'Georgia',
60 );
61
62 $gfonts = '';
63 $gfonts_attr = ':100,200,300,400,500,600,700,800,900';
64
65 foreach ($fonts as $font) {
66 if ( ! in_array( $font, $system, true) && ! empty( $font ) ) {
67 $gfonts .= str_replace( ' ', '+', trim( $font ) ) . $gfonts_attr . '|';
68 }
69 }
70
71 if ( ! empty( $gfonts ) ) {
72
73 $query_args = [ 'family' => $gfonts ];
74
75 wp_register_style(
76 'gutsliders-fonts',
77 add_query_arg( $query_args, '//fonts.googleapis.com/css' ),
78 [],
79 GUTSLIDER_VERSION,
80 'all'
81 );
82
83 wp_enqueue_style( 'gutsliders-fonts', false, [], GUTSLIDER_VERSION, 'all' );
84 }
85
86 // Reset.
87 $gfonts = '';
88 }
89 }
90 }
91
92 }
93
94 }
95
96 new GutSlider_Load_Fonts(); // Initialize the class