PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 1.0.0
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v1.0.0
3.2.0 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 All 57 releases
slider-blocks / includes / FontsLoader / FontsLoader.php

FontsLoader.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 1.0.0, at includes/FontsLoader/FontsLoader.php

83 lines 1.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 */
5
6 namespace GutSliders\FontsLoader;
7
8 // Exit if accessed directly.
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 class FontsLoader {
14
15 private static $all_fonts = [];
16
17 /**
18 * The Constructor.
19 */
20 public function __construct() {
21 add_action( 'wp_enqueue_scripts', [ $this, 'fonts_loader' ] );
22 add_action( 'admin_enqueue_scripts', [ $this, 'fonts_loader' ] );
23 add_action('gutsliders_render_block', [ $this, 'font_generator' ]);
24 }
25
26 /**
27 * Font generator.
28 */
29 public function font_generator($block) {
30 if (isset($block['attrs']) && is_array($block['attrs'])) {
31 $attributes = $block['attrs'];
32 foreach ($attributes as $key => $value) {
33 if (!empty($value) && strpos($key, 'gutsliders_') === 0 && strpos($key, 'FontFamily') !== false) {
34 self::$all_fonts[] = $value;
35 }
36 }
37 }
38 }
39
40 /**
41 * Load fonts.
42 *
43 * @access public
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 $system = array(
52 'Arial',
53 'Tahoma',
54 'Verdana',
55 'Helvetica',
56 'Times New Roman',
57 'Trebuchet MS',
58 'Georgia',
59 );
60 $gfonts = '';
61 $gfonts_attr = ':100,200,300,400,500,600,700,800,900';
62 foreach ($fonts as $font) {
63 if (!in_array($font, $system, true) && !empty($font)) {
64 $gfonts .= str_replace(' ', '+', trim($font)) . $gfonts_attr . '|';
65 }
66 }
67 if (!empty($gfonts)) {
68 $query_args = array(
69 'family' => $gfonts,
70 );
71 wp_register_style(
72 'gutsliders-fonts',
73 add_query_arg($query_args, '//fonts.googleapis.com/css'),
74 array()
75 );
76 wp_enqueue_style('gutsliders-fonts');
77 }
78 // Reset.
79 $gfonts = '';
80 }
81 }
82 }
83 }