class-admin-asset-manager.php
7.82 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
/**
* @package WPSEO\Admin
*/
/**
* This class registers all the necessary styles and scripts. Also has methods for the enqueing of scripts and styles. It automatically adds a prefix to the handle.
*/
class WPSEO_Admin_Asset_Manager {
/**
* Prefix for naming the assets.
*/
const PREFIX = 'yoast-seo-';
/**
* Enqueues scripts.
*
* @param string $script The name of the script to enqueue.
*/
public function enqueue_script( $script ) {
wp_enqueue_script( self::PREFIX . $script );
}
/**
* Enqueues styles.
*
* @param string $style The name of the style to enqueue.
*/
public function enqueue_style( $style ) {
wp_enqueue_style( self::PREFIX . $style );
}
/**
* Registers scripts based on it's parameters.
*
* @param WPSEO_Admin_Asset $script The script to register.
*/
public function register_script( WPSEO_Admin_Asset $script ) {
wp_register_script(
self::PREFIX . $script->get_name(),
$script->get_url( WPSEO_Admin_Asset::TYPE_JS, WPSEO_FILE ),
$script->get_deps(),
$script->get_version(),
$script->is_in_footer()
);
}
/**
* Registers styles based on it's parameters.
*
* @param WPSEO_Admin_Asset $style The style to register.
*/
public function register_style( WPSEO_Admin_Asset $style ) {
wp_register_style(
self::PREFIX . $style->get_name(),
$style->get_url( WPSEO_Admin_Asset::TYPE_CSS, WPSEO_FILE ),
$style->get_deps(),
$style->get_version(),
$style->get_media()
);
}
/**
* Calls the functions that register scripts and styles with the scripts and styles to be registered as arguments.
*/
public function register_assets() {
$this->register_scripts( $this->scripts_to_be_registered() );
$this->register_styles( $this->styles_to_be_registered() );
}
/**
* Registers all the scripts passed to it.
*
* @param array $scripts The scripts passed to it.
*/
public function register_scripts( $scripts ) {
foreach ( $scripts as $script ) {
$script = new WPSEO_Admin_Asset( $script );
$this->register_script( $script );
}
}
/**
* Registers all the styles it recieves.
*
* @param array $styles Styles that need to be registerd.
*/
public function register_styles( $styles ) {
foreach ( $styles as $style ) {
$style = new WPSEO_Admin_Asset( $style );
$this->register_style( $style );
}
}
/**
* A list of styles that shouldn't be registered but are needed in other locations in the plugin.
*
* @return array
*/
public function special_styles() {
return array(
'inside-editor' => new WPSEO_Admin_Asset( array(
'name' => 'inside-editor',
'src' => 'inside-editor-331',
) ),
);
}
/**
* Returns the scripts that need to be registered.
*
* @TODO data format is not self-documenting. Needs explanation inline. R.
*
* @return array scripts that need to be registered.
*/
private function scripts_to_be_registered() {
$select2_language = 'en';
$user_locale = WPSEO_Utils::get_user_locale();
$language = WPSEO_Utils::get_language( $user_locale );
if ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$user_locale}.js" ) ) {
$select2_language = $user_locale; // Chinese and some others use full locale.
}
elseif ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$language}.js" ) ) {
$select2_language = $language;
}
return array(
array(
'name' => 'admin-script',
'src' => 'wp-seo-admin-400',
'deps' => array(
'jquery',
'jquery-ui-core',
'jquery-ui-progressbar',
self::PREFIX . 'select2',
self::PREFIX . 'select2-translations',
),
),
array(
'name' => 'admin-media',
'src' => 'wp-seo-admin-media-350',
'deps' => array(
'jquery',
'jquery-ui-core',
),
),
array(
'name' => 'bulk-editor',
'src' => 'wp-seo-bulk-editor-350',
'deps' => array( 'jquery' ),
),
array(
'name' => 'dismissible',
'src' => 'wp-seo-dismissible-350',
'deps' => array( 'jquery' ),
),
array(
'name' => 'admin-global-script',
'src' => 'wp-seo-admin-global-390',
'deps' => array( 'jquery' ),
),
array(
'name' => 'metabox',
'src' => 'wp-seo-metabox-400',
'deps' => array(
'jquery',
'jquery-ui-core',
'jquery-ui-autocomplete',
self::PREFIX . 'select2',
self::PREFIX . 'select2-translations',
),
'in_footer' => false,
),
array(
'name' => 'featured-image',
'src' => 'wp-seo-featured-image-350',
'deps' => array(
'jquery'
),
),
array(
'name' => 'admin-gsc',
'src' => 'wp-seo-admin-gsc-350',
'deps' => array(),
'in_footer' => false,
),
array(
'name' => 'post-scraper',
'src' => 'wp-seo-post-scraper-402',
'deps' => array(
self::PREFIX . 'replacevar-plugin',
self::PREFIX . 'shortcode-plugin',
'wp-util',
),
),
array(
'name' => 'term-scraper',
'src' => 'wp-seo-term-scraper-402',
'deps' => array(
self::PREFIX . 'replacevar-plugin',
),
),
array(
'name' => 'replacevar-plugin',
'src' => 'wp-seo-replacevar-plugin-380',
),
array(
'name' => 'shortcode-plugin',
'src' => 'wp-seo-shortcode-plugin-402',
),
array(
'name' => 'recalculate',
'src' => 'wp-seo-recalculate-402',
'deps' => array(
'jquery',
'jquery-ui-core',
'jquery-ui-progressbar',
),
),
array(
'name' => 'primary-category',
'src' => 'wp-seo-metabox-category-380',
'deps' => array(
'jquery',
'wp-util',
),
),
array(
'name' => 'select2',
'src' => 'select2/select2',
'suffix' => '.min',
'deps' => array(
'jquery',
),
'version' => '4.0.3',
),
array(
'name' => 'select2-translations',
'src' => 'select2/i18n/' . $select2_language,
'deps' => array(
'jquery',
self::PREFIX . 'select2',
),
'version' => '4.0.3',
'suffix' => '',
),
array(
'name' => 'configuration-wizard',
'src' => 'configuration-wizard-400',
'deps' => array(
'jquery',
),
),
);
}
/**
* Returns the styles that need to be registered.
*
* @TODO data format is not self-documenting. Needs explanation inline. R.
*
* @return array styles that need to be registered.
*/
private function styles_to_be_registered() {
return array(
array(
'name' => 'admin-css',
'src' => 'yst_plugin_tools-400',
'deps' => array( self::PREFIX . 'toggle-switch' ),
),
array(
'name' => 'toggle-switch',
'src' => 'toggle-switch-390',
),
array(
'name' => 'dismissible',
'src' => 'wpseo-dismissible-350',
),
array(
'name' => 'alerts',
'src' => 'alerts-340',
),
array(
'name' => 'edit-page',
'src' => 'edit-page-330',
),
array(
'name' => 'featured-image',
'src' => 'featured-image-330',
),
array(
'name' => 'metabox-css',
'src' => 'metabox-400',
'deps' => array(
self::PREFIX . 'select2',
),
),
array(
'name' => 'wp-dashboard',
'src' => 'dashboard-360',
),
array(
'name' => 'scoring',
'src' => 'yst_seo_score-390',
),
array(
'name' => 'snippet',
'src' => 'snippet-330',
),
array(
'name' => 'adminbar',
'src' => 'adminbar-340',
),
array(
'name' => 'primary-category',
'src' => 'metabox-primary-category',
),
array(
'name' => 'select2',
'src' => 'dist/select2/select2',
'suffix' => '.min',
'version' => '4.0.1',
'rtl' => false,
),
array(
'name' => 'kb-search',
'src' => 'kb-search-350',
),
array(
'name' => 'help-center',
'src' => 'help-center-340',
),
array(
'name' => 'admin-global',
'src' => 'admin-global-370',
),
array(
'name' => 'yoast-components',
'src' => 'yoast-components-400',
),
array(
'name' => 'extensions',
'src' => 'yoast-extensions-390',
),
);
}
}