icons.php
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Loads the Font Awesome Kit
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Stackable_Icons' ) ) {
/**
* Stackable Icons
*/
class Stackable_Icons {
/**
* Initialize
*/
function __construct() {
// Enqueue our FA Kit.
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
// Add our FA Kit as a dependency to our editor script.
add_filter( 'stackable_editor_js_dependencies', array( $this, 'add_kit_dependency' ) );
// Deprecated v2 call.
add_filter( 'stackable_editor_js_dependencies_v2', array( $this, 'add_kit_dependency' ) );
}
/**
* Add our Font Awesome script as a dependency on our editor script.
*
* @param array $deps
* @return array
*/
public function add_kit_dependency( $deps ) {
$deps[] = 'ugb-font-awesome-kit';
return $deps;
}
/**
* Enqueue our Font Awesome free kit.
*
* @return void
*/
public function enqueue_block_editor_assets() {
// Load our Free Font Awesome Icons.
if ( apply_filters( 'stackable_load_font_awesome_kit', true ) ) {
wp_enqueue_script(
'ugb-font-awesome-kit',
// 'https://kit.fontawesome.com/9664e939d9.js', // This is our free kit.
'https://use.fontawesome.com/releases/v5.15.4/js/all.js',
null,
null,
true
);
// Add FA parameters to the script tag.
add_filter( 'script_loader_tag', array( $this, 'script_loader_tag' ), 10, 2 );
}
}
/**
* Added the necessary parameters to the FA Kit.
*
* @param string $html
* @param string $handle
* @return string The script that will be printed on the header.
*/
public function script_loader_tag( $html, $handle ) {
if ( $handle === 'ugb-font-awesome-kit' ) {
$html = str_replace( '></script>', ' crossorigin="anonymous" data-auto-replace-svg="false" data-auto-add-css="false" data-family-prefix="fa" data-observe-mutations="false" data-show-missing-icons="false" async></script>', $html );
}
return $html;
}
}
new Stackable_Icons();
}