PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.6.1
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.6.1
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.6.1, at includes/classes/class-load-fonts.php

107 lines 3.4 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' ], 9999);
21 add_action( 'admin_enqueue_scripts', [ $this, 'fonts_loader' ], 9999 );
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 $this->fonts_loader();
40 }
41 }
42
43 /**
44 * Load fonts
45 * return void
46 */
47 public function fonts_loader() {
48 if ( is_array( self::$all_fonts ) && count( self::$all_fonts ) > 0 ) {
49
50 $fonts = array_filter( array_unique( self::$all_fonts ) );
51
52 if ( ! empty( $fonts ) ) {
53
54 $system = array(
55 'Default',
56 'Arial',
57 'Tahoma',
58 'Verdana',
59 'Helvetica',
60 'Times New Roman',
61 'Trebuchet MS',
62 'Georgia',
63 );
64
65 $gfonts = '';
66 $gfonts_attr = ':100,200,300,400,500,600,700,800,900';
67
68 foreach ($fonts as $font) {
69 if ( ! in_array( $font, $system, true) && ! empty( $font ) ) {
70 $gfonts .= str_replace( ' ', '+', trim( $font ) ) . $gfonts_attr . '|';
71 }
72 }
73
74 if (!empty($gfonts)) {
75 $font_array = explode('|', $gfonts);
76
77 foreach ($font_array as $font) {
78 if (empty($font) || in_array($font, $system, true)) {
79 continue;
80 }
81
82 $query_args = ['family' => $font];
83 $font_handle = 'gutsliders-font-' . sanitize_title($font);
84
85 wp_register_style(
86 $font_handle,
87 add_query_arg($query_args, '//fonts.googleapis.com/css'),
88 [],
89 GUTSLIDER_VERSION,
90 'all'
91 );
92
93 wp_enqueue_style($font_handle);
94 }
95 }
96
97 // Reset.
98 $gfonts = '';
99 }
100 }
101 }
102
103 }
104
105 }
106
107 new GutSlider_Load_Fonts(); // Initialize the class