-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathStyleAsset.php
94 lines (84 loc) · 2.62 KB
/
StyleAsset.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Assets;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidAsset;
/**
* Class StyleAsset
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Assets
*/
class StyleAsset extends BaseAsset {
/**
* The media for which this stylesheet has been defined.
*
* @var string
*/
protected $media;
/**
* StyleAsset constructor.
*
* @param string $handle The asset handle.
* @param string $uri The URI for the asset.
* @param array $dependencies (Optional) Any dependencies the asset has.
* @param string $version (Optional) A version string for the asset. Will default to the plugin version
* if not set.
* @param callable|null $enqueue_condition_callback (Optional) The asset is always enqueued if this callback
* returns true or isn't set.
* @param string $media Optional. The media for which this stylesheet has been defined.
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media
* queries like '(orientation: portrait)' and '(max-width: 640px)'.
*/
public function __construct(
string $handle,
string $uri,
array $dependencies = [],
string $version = '',
callable $enqueue_condition_callback = null,
string $media = 'all'
) {
$this->media = $media;
parent::__construct( 'css', $handle, $uri, $dependencies, $version, $enqueue_condition_callback );
}
/**
* Get the register callback to use.
*
* @return callable
*/
protected function get_register_callback(): callable {
return function () {
if ( wp_style_is( $this->handle, 'registered' ) ) {
return;
}
wp_register_style(
$this->handle,
$this->uri,
$this->dependencies,
$this->version,
$this->media
);
};
}
/**
* Get the enqueue callback to use.
*
* @return callable
*/
protected function get_enqueue_callback(): callable {
return function () {
if ( ! wp_style_is( $this->handle, 'registered' ) ) {
throw InvalidAsset::asset_not_registered( $this->handle );
}
wp_enqueue_style( $this->handle );
};
}
/**
* Get the dequeue callback to use.
*
* @return callable
*/
protected function get_dequeue_callback(): callable {
return function () {
wp_dequeue_style( $this->handle );
};
}
}