PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / class-asset.php

class-asset.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at admin/class-asset.php

256 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Represents a WPSEO asset
10 */
11 class WPSEO_Admin_Asset {
12
13 /**
14 * Constant used to identify file type as a JS file.
15 *
16 * @var string
17 */
18 const TYPE_JS = 'js';
19
20 /**
21 * Constant used to identify file type as a CSS file.
22 *
23 * @var string
24 */
25 const TYPE_CSS = 'css';
26
27 /**
28 * The name option identifier.
29 *
30 * @var string
31 */
32 const NAME = 'name';
33
34 /**
35 * The source option identifier.
36 *
37 * @var string
38 */
39 const SRC = 'src';
40
41 /**
42 * The dependencies option identifier.
43 *
44 * @var string
45 */
46 const DEPS = 'deps';
47
48 /**
49 * The version option identifier.
50 *
51 * @var string
52 */
53 const VERSION = 'version';
54
55 /* Style specific. */
56
57 /**
58 * The media option identifier.
59 *
60 * @var string
61 */
62 const MEDIA = 'media';
63
64 /**
65 * The rtl option identifier.
66 *
67 * @var string
68 */
69 const RTL = 'rtl';
70
71 /* Script specific. */
72
73 /**
74 * The "in footer" option identifier.
75 *
76 * @var string
77 */
78 const IN_FOOTER = 'in_footer';
79
80 /**
81 * Asset identifier.
82 *
83 * @var string
84 */
85 protected $name;
86
87 /**
88 * Path to the asset.
89 *
90 * @var string
91 */
92 protected $src;
93
94 /**
95 * Asset dependencies.
96 *
97 * @var string|array
98 */
99 protected $deps;
100
101 /**
102 * Asset version.
103 *
104 * @var string
105 */
106 protected $version;
107
108 /**
109 * For CSS Assets. The type of media for which this stylesheet has been defined.
110 *
111 * See https://www.w3.org/TR/CSS2/media.html#media-types.
112 *
113 * @var string
114 */
115 protected $media;
116
117 /**
118 * For JS Assets. Whether or not the script should be loaded in the footer.
119 *
120 * @var bool
121 */
122 protected $in_footer;
123
124 /**
125 * For CSS Assets. Whether this stylesheet is a right-to-left stylesheet.
126 *
127 * @var bool
128 */
129 protected $rtl;
130
131 /**
132 * File suffix.
133 *
134 * @var string
135 */
136 protected $suffix;
137
138 /**
139 * Default asset arguments.
140 *
141 * @var array
142 */
143 private $defaults = [
144 'deps' => [],
145 'in_footer' => true,
146 'rtl' => true,
147 'media' => 'all',
148 'version' => '',
149 'suffix' => '',
150 ];
151
152 /**
153 * Constructs an instance of the WPSEO_Admin_Asset class.
154 *
155 * @param array $args The arguments for this asset.
156 *
157 * @throws InvalidArgumentException Throws when no name or src has been provided.
158 */
159 public function __construct( array $args ) {
160 if ( ! isset( $args['name'] ) ) {
161 throw new InvalidArgumentException( 'name is a required argument' );
162 }
163
164 if ( ! isset( $args['src'] ) ) {
165 throw new InvalidArgumentException( 'src is a required argument' );
166 }
167
168 $args = array_merge( $this->defaults, $args );
169
170 $this->name = $args['name'];
171 $this->src = $args['src'];
172 $this->deps = $args['deps'];
173 $this->version = $args['version'];
174 $this->media = $args['media'];
175 $this->in_footer = $args['in_footer'];
176 $this->rtl = $args['rtl'];
177 $this->suffix = $args['suffix'];
178 }
179
180 /**
181 * Returns the asset identifier.
182 *
183 * @return string
184 */
185 public function get_name() {
186 return $this->name;
187 }
188
189 /**
190 * Returns the path to the asset.
191 *
192 * @return string
193 */
194 public function get_src() {
195 return $this->src;
196 }
197
198 /**
199 * Returns the asset dependencies.
200 *
201 * @return array|string
202 */
203 public function get_deps() {
204 return $this->deps;
205 }
206
207 /**
208 * Returns the asset version.
209 *
210 * @return string|null
211 */
212 public function get_version() {
213 if ( ! empty( $this->version ) ) {
214 return $this->version;
215 }
216
217 return null;
218 }
219
220 /**
221 * Returns the media type for CSS assets.
222 *
223 * @return string
224 */
225 public function get_media() {
226 return $this->media;
227 }
228
229 /**
230 * Returns whether a script asset should be loaded in the footer of the page.
231 *
232 * @return bool
233 */
234 public function is_in_footer() {
235 return $this->in_footer;
236 }
237
238 /**
239 * Returns whether this CSS has a RTL counterpart.
240 *
241 * @return bool
242 */
243 public function has_rtl() {
244 return $this->rtl;
245 }
246
247 /**
248 * Returns the file suffix.
249 *
250 * @return string
251 */
252 public function get_suffix() {
253 return $this->suffix;
254 }
255 }
256