-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enqueue.php
59 lines (35 loc) · 1.31 KB
/
Enqueue.php
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
<?php
/**
* Helper for registered dependencies
*
* @package ThemePlate
* @since 0.1.0
*/
namespace ThemePlate;
use ThemePlate\Enqueue\CustomData;
use ThemePlate\Enqueue\Dynamic;
class Enqueue {
private static Dynamic $dynamic;
public static int $priority = 10;
public static function init(): void {
$custom_data = new CustomData();
self::$dynamic = new Dynamic();
add_action( 'wp_enqueue_scripts', array( $custom_data, 'init' ), PHP_INT_MAX );
add_action( 'wp_enqueue_scripts', array( $custom_data, 'action' ), PHP_INT_MAX );
add_action( 'wp_enqueue_scripts', array( self::$dynamic, 'action' ), self::$priority );
}
public static function asset( string $type, string $handle ): void {
if ( ! in_array( $type, array( 'script', 'style' ), true ) ) {
_doing_it_wrong( __METHOD__, esc_attr( 'Only "script" and "style" are known types' ), '2.0.0' );
return;
}
_deprecated_function( __METHOD__, '2.0.0', esc_attr( __CLASS__ . '::' . $type ) );
self::$dynamic->$type( $handle );
}
public static function script( string $handle, string $src = '', array $data = array() ): void {
self::$dynamic->script( $handle, $src, $data );
}
public static function style( string $handle, string $src = '', array $data = array() ): void {
self::$dynamic->style( $handle, $src, $data );
}
}