PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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
← All changes | admin/class-admin-asset-manager.php +201 -125 18.0 → trunk View file →
@@ -17,9 +17,9 @@
17 17 * Prefix for naming the assets.
18 18 *
19 19 * @var string
20 20 */
21 - const PREFIX = 'yoast-seo-';
21 + public const PREFIX = 'yoast-seo-';
22 22
23 23 /**
24 24 * Class that manages the assets' location.
25 25 *
@@ -39,12 +39,10 @@
39 39 *
40 40 * @param WPSEO_Admin_Asset_Location|null $asset_location The provider of the asset location.
41 41 * @param string $prefix The prefix for naming assets.
42 42 */
43 - public function __construct( WPSEO_Admin_Asset_Location $asset_location = null, $prefix = self::PREFIX ) {
44 - if ( $asset_location === null ) {
45 - $asset_location = self::create_default_location();
46 - }
43 + public function __construct( ?WPSEO_Admin_Asset_Location $asset_location = null, $prefix = self::PREFIX ) {
44 + $asset_location ??= self::create_default_location();
47 45
48 46 $this->asset_location = $asset_location;
49 47 $this->prefix = $prefix;
50 48 }
@@ -52,8 +50,10 @@
52 50 /**
53 51 * Enqueues scripts.
54 52 *
55 53 * @param string $script The name of the script to enqueue.
54 + *
55 + * @return void
56 56 */
57 57 public function enqueue_script( $script ) {
58 58 wp_enqueue_script( $this->prefix . $script );
59 59 }
@@ -61,8 +61,10 @@
61 61 /**
62 62 * Enqueues styles.
63 63 *
64 64 * @param string $style The name of the style to enqueue.
65 + *
66 + * @return void
65 67 */
66 68 public function enqueue_style( $style ) {
67 69 wp_enqueue_style( $this->prefix . $style );
68 70 }
@@ -68,8 +70,10 @@
68 70 }
69 71
70 72 /**
71 73 * Enqueues the appropriate language for the user.
74 + *
75 + * @return void
72 76 */
73 77 public function enqueue_user_language_script() {
74 78 $this->enqueue_script( 'language-' . YoastSEO()->helpers->language->get_researcher_language() );
75 79 }
@@ -77,19 +81,32 @@
77 81 /**
78 82 * Registers scripts based on it's parameters.
79 83 *
80 84 * @param WPSEO_Admin_Asset $script The script to register.
85 + *
86 + * @return void
81 87 */
82 88 public function register_script( WPSEO_Admin_Asset $script ) {
83 - $url = $script->get_src() ? $this->get_url( $script, WPSEO_Admin_Asset::TYPE_JS ) : false;
89 + $url = $script->get_src() ? $this->get_url( $script, WPSEO_Admin_Asset::TYPE_JS ) : false;
90 + $args = [
91 + 'in_footer' => $script->is_in_footer(),
92 + ];
84 93
94 + if ( $script->get_strategy() !== '' ) {
95 + $args['strategy'] = $script->get_strategy();
96 + }
97 +
85 98 wp_register_script(
86 99 $this->prefix . $script->get_name(),
87 100 $url,
88 101 $script->get_deps(),
89 102 $script->get_version(),
90 - $script->is_in_footer()
103 + $args,
91 104 );
105 +
106 + if ( in_array( 'wp-i18n', $script->get_deps(), true ) ) {
107 + wp_set_script_translations( $this->prefix . $script->get_name(), 'wordpress-seo' );
108 + }
92 109 }
93 110
94 111 /**
95 112 * Registers styles based on it's parameters.
@@ -94,8 +111,10 @@
94 111 /**
95 112 * Registers styles based on it's parameters.
96 113 *
97 114 * @param WPSEO_Admin_Asset $style The style to register.
115 + *
116 + * @return void
98 117 */
99 118 public function register_style( WPSEO_Admin_Asset $style ) {
100 119 wp_register_style(
101 120 $this->prefix . $style->get_name(),
@@ -101,14 +120,16 @@
101 120 $this->prefix . $style->get_name(),
102 121 $this->get_url( $style, WPSEO_Admin_Asset::TYPE_CSS ),
103 122 $style->get_deps(),
104 123 $style->get_version(),
105 - $style->get_media()
124 + $style->get_media(),
106 125 );
107 126 }
108 127
109 128 /**
110 129 * Calls the functions that register scripts and styles with the scripts and styles to be registered as arguments.
130 + *
131 + * @return void
111 132 */
112 133 public function register_assets() {
113 134 $this->register_scripts( $this->scripts_to_be_registered() );
114 135 $this->register_styles( $this->styles_to_be_registered() );
@@ -117,8 +138,10 @@
117 138 /**
118 139 * Registers all the scripts passed to it.
119 140 *
120 141 * @param array $scripts The scripts passed to it.
142 + *
143 + * @return void
121 144 */
122 145 public function register_scripts( $scripts ) {
123 146 foreach ( $scripts as $script ) {
124 147 $script = new WPSEO_Admin_Asset( $script );
@@ -129,8 +152,10 @@
129 152 /**
130 153 * Registers all the styles it receives.
131 154 *
132 155 * @param array $styles Styles that need to be registered.
156 + *
157 + * @return void
133 158 */
134 159 public function register_styles( $styles ) {
135 160 foreach ( $styles as $style ) {
136 161 $style = new WPSEO_Admin_Asset( $style );
@@ -143,11 +168,13 @@
143 168 *
144 169 * @param string $handle The script handle.
145 170 * @param string $object_name The object name.
146 171 * @param array $data The l10n data.
172 + *
173 + * @return void
147 174 */
148 175 public function localize_script( $handle, $object_name, $data ) {
149 - \wp_localize_script( $this->prefix . $handle, $object_name, $data );
176 + wp_localize_script( $this->prefix . $handle, $object_name, $data );
150 177 }
151 178
152 179 /**
153 180 * Adds an inline script.
@@ -154,11 +181,13 @@
154 181 *
155 182 * @param string $handle The script handle.
156 183 * @param string $data The l10n data.
157 184 * @param string $position Optional. Whether to add the inline script before the handle or after.
185 + *
186 + * @return void
158 187 */
159 188 public function add_inline_script( $handle, $data, $position = 'after' ) {
160 - \wp_add_inline_script( $this->prefix . $handle, $data, $position );
189 + wp_add_inline_script( $this->prefix . $handle, $data, $position );
161 190 }
162 191
163 192 /**
164 193 * A list of styles that shouldn't be registered but are needed in other locations in the plugin.
@@ -214,12 +243,33 @@
214 243 *
215 244 * @return bool True when the script is enqueued.
216 245 */
217 246 public function is_script_enqueued( $script ) {
218 - return \wp_script_is( $this->prefix . $script );
247 + return wp_script_is( $this->prefix . $script );
219 248 }
220 249
221 250 /**
251 + * Gets the list of Elementor dependencies.
252 + *
253 + * @return array<string> The array of elementor dependencies.
254 + */
255 + protected function get_elementor_dependencies() {
256 + $dependencies = [
257 + 'backbone-marionette',
258 + 'elementor-common-modules',
259 + self::PREFIX . 'api-client',
260 + self::PREFIX . 'externals-components',
261 + self::PREFIX . 'externals-contexts',
262 + self::PREFIX . 'externals-redux',
263 + ];
264 + // Conditionally add Elementor v2 dependency if available.
265 + if ( wp_script_is( 'elementor-v2-editor-app-bar', 'registered' ) ) {
266 + $dependencies[] = 'elementor-v2-editor-app-bar';
267 + }
268 + return $dependencies;
269 + }
270 +
271 + /**
222 272 * Returns the scripts that need to be registered.
223 273 *
224 274 * @todo Data format is not self-documenting. Needs explanation inline. R.
225 275 *
@@ -231,49 +281,65 @@
231 281 'block-editor',
232 282 'classic-editor',
233 283 'post-edit',
234 284 'help-scout-beacon',
285 + 'redirect-old-features-tab',
235 286 ];
287 + $elementor_dependencies = $this->get_elementor_dependencies();
236 288 $additional_dependencies = [
237 - 'analysis-worker' => [ self::PREFIX . 'analysis-package' ],
238 - 'api-client' => [ 'wp-api' ],
239 - 'dashboard-widget' => [ self::PREFIX . 'api-client' ],
240 - 'elementor' => [
289 + 'analysis-worker' => [ self::PREFIX . 'analysis-package' ],
290 + 'api-client' => [ 'wp-api' ],
291 + 'crawl-settings' => [ 'jquery' ],
292 + 'dashboard-widget' => [ self::PREFIX . 'api-client' ],
293 + 'wincher-dashboard-widget' => [ self::PREFIX . 'api-client' ],
294 + 'editor-modules' => [ 'jquery' ],
295 + 'elementor' => $elementor_dependencies,
296 + 'elementor-v4' => array_merge( [ self::PREFIX . 'elementor' ], $elementor_dependencies ),
297 + 'indexation' => [
298 + 'jquery-ui-core',
299 + 'jquery-ui-progressbar',
300 + ],
301 + 'first-time-configuration' => [
241 302 self::PREFIX . 'api-client',
242 303 self::PREFIX . 'externals-components',
243 304 self::PREFIX . 'externals-contexts',
244 305 self::PREFIX . 'externals-redux',
245 306 ],
246 - 'indexation' => [
247 - 'jquery-ui-core',
248 - 'jquery-ui-progressbar',
307 + 'integrations-page' => [
308 + self::PREFIX . 'api-client',
309 + self::PREFIX . 'externals-components',
310 + self::PREFIX . 'externals-contexts',
311 + self::PREFIX . 'externals-redux',
249 312 ],
250 - 'post-edit' => [
313 + 'post-edit' => [
251 314 self::PREFIX . 'api-client',
252 315 self::PREFIX . 'block-editor',
253 316 self::PREFIX . 'externals-components',
254 317 self::PREFIX . 'externals-contexts',
255 318 self::PREFIX . 'externals-redux',
256 - self::PREFIX . 'select2',
257 319 ],
258 - 'reindex-links' => [
320 + 'reindex-links' => [
259 321 'jquery-ui-core',
260 322 'jquery-ui-progressbar',
261 323 ],
262 - 'settings' => [
324 + 'settings' => [
263 325 'jquery-ui-core',
264 326 'jquery-ui-progressbar',
265 327 self::PREFIX . 'api-client',
266 - self::PREFIX . 'select2',
328 + self::PREFIX . 'externals-components',
329 + self::PREFIX . 'externals-contexts',
330 + self::PREFIX . 'externals-redux',
267 331 ],
268 - 'term-edit' => [
332 + 'term-edit' => [
269 333 self::PREFIX . 'api-client',
270 334 self::PREFIX . 'classic-editor',
271 335 self::PREFIX . 'externals-components',
272 336 self::PREFIX . 'externals-contexts',
273 337 self::PREFIX . 'externals-redux',
274 - self::PREFIX . 'select2',
275 338 ],
339 + 'general-page' => [
340 + self::PREFIX . 'api-client',
341 + ],
276 342 ];
277 343
278 344 $plugin_scripts = $this->load_generated_asset_file(
279 345 [
@@ -280,9 +346,9 @@
280 346 'asset_file' => __DIR__ . '/../src/generated/assets/plugin.php',
281 347 'ext_length' => 3,
282 348 'additional_deps' => $additional_dependencies,
283 349 'header_scripts' => $header_scripts,
284 - ]
350 + ],
285 351 );
286 352 $external_scripts = $this->load_generated_asset_file(
287 353 [
288 354 'asset_file' => __DIR__ . '/../src/generated/assets/externals.php',
@@ -290,9 +356,9 @@
290 356 'suffix' => '-package',
291 357 'base_dir' => 'externals/',
292 358 'additional_deps' => $additional_dependencies,
293 359 'header_scripts' => $header_scripts,
294 - ]
360 + ],
295 361 );
296 362 $language_scripts = $this->load_generated_asset_file(
297 363 [
298 364 'asset_file' => __DIR__ . '/../src/generated/assets/languages.php',
@@ -300,11 +366,10 @@
300 366 'suffix' => '-language',
301 367 'base_dir' => 'languages/',
302 368 'additional_deps' => $additional_dependencies,
303 369 'header_scripts' => $header_scripts,
304 - ]
370 + ],
305 371 );
306 - $select2_scripts = $this->load_select2_scripts();
307 372 $renamed_scripts = $this->load_renamed_scripts();
308 373
309 374 $scripts = array_merge(
310 375 $plugin_scripts,
@@ -309,10 +374,9 @@
309 374 $scripts = array_merge(
310 375 $plugin_scripts,
311 376 $external_scripts,
312 377 $language_scripts,
313 - $select2_scripts,
314 - $renamed_scripts
378 + $renamed_scripts,
315 379 );
316 380
317 381 $scripts['installation-success'] = [
318 382 'name' => 'installation-success',
@@ -322,9 +386,9 @@
322 386 'wp-dom-ready',
323 387 'wp-components',
324 388 'wp-element',
325 389 'wp-i18n',
326 - self::PREFIX . 'yoast-components',
390 + self::PREFIX . 'components-new-package',
327 391 self::PREFIX . 'externals-components',
328 392 ],
329 393 'version' => $scripts['installation-success']['version'],
330 394 ];
@@ -332,15 +396,15 @@
332 396 $scripts['post-edit-classic'] = [
333 397 'name' => 'post-edit-classic',
334 398 'src' => $scripts['post-edit']['src'],
335 399 'deps' => array_map(
336 - static function( $dep ) {
400 + static function ( $dep ) {
337 401 if ( $dep === self::PREFIX . 'block-editor' ) {
338 402 return self::PREFIX . 'classic-editor';
339 403 }
340 404 return $dep;
341 405 },
342 - $scripts['post-edit']['deps']
406 + $scripts['post-edit']['deps'],
343 407 ),
344 408 'in_footer' => ! in_array( 'post-edit-classic', $header_scripts, true ),
345 409 'version' => $scripts['post-edit']['version'],
346 410 ];
@@ -362,10 +426,9 @@
362 426 self::PREFIX . 'externals-components',
363 427 self::PREFIX . 'externals-contexts',
364 428 self::PREFIX . 'externals-redux',
365 429 self::PREFIX . 'analysis',
366 - self::PREFIX . 'react-select',
367 - self::PREFIX . 'yoast-components',
430 + self::PREFIX . 'components-new-package',
368 431 ],
369 432 'version' => $scripts['workouts']['version'],
370 433 ];
371 434
@@ -412,9 +475,9 @@
412 475 'suffix' => '',
413 476 'additional_deps' => [],
414 477 'base_dir' => '',
415 478 'header_scripts' => [],
416 - ]
479 + ],
417 480 );
418 481 $scripts = [];
419 482 $assets = require $args['asset_file'];
420 483 foreach ( $assets as $file => $data ) {
@@ -439,62 +502,8 @@
439 502 return $scripts;
440 503 }
441 504
442 505 /**
443 - * Loads the select2 scripts.
444 - *
445 - * @return array {
446 - * The scripts to be registered.
447 - *
448 - * @type string $name The name of the asset.
449 - * @type string $src The src of the asset.
450 - * @type string[] $deps The dependenies of the asset.
451 - * @type bool $in_footer Whether or not the asset should be in the footer.
452 - * }
453 - */
454 - protected function load_select2_scripts() {
455 - $scripts = [];
456 - $select2_language = 'en';
457 - $user_locale = \get_user_locale();
458 - $language = WPSEO_Language_Utils::get_language( $user_locale );
459 -
460 - if ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$user_locale}.js" ) ) {
461 - $select2_language = $user_locale; // Chinese and some others use full locale.
462 - }
463 - elseif ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$language}.js" ) ) {
464 - $select2_language = $language;
465 - }
466 -
467 - $scripts['select2'] = [
468 - 'name' => 'select2',
469 - 'src' => false,
470 - 'deps' => [
471 - self::PREFIX . 'select2-translations',
472 - self::PREFIX . 'select2-core',
473 - ],
474 - ];
475 - $scripts['select2-core'] = [
476 - 'name' => 'select2-core',
477 - 'src' => 'select2/select2.full.min.js',
478 - 'deps' => [
479 - 'jquery',
480 - ],
481 - 'version' => '4.1.0-rc.0',
482 - ];
483 - $scripts['select2-translations'] = [
484 - 'name' => 'select2-translations',
485 - 'src' => 'select2/i18n/' . $select2_language . '.js',
486 - 'deps' => [
487 - 'jquery',
488 - self::PREFIX . 'select2-core',
489 - ],
490 - 'version' => '4.1.0-rc.0',
491 - ];
492 -
493 - return $scripts;
494 - }
495 -
496 - /**
497 506 * Loads the scripts that should be renamed for BC.
498 507 *
499 508 * @return array {
500 509 * The scripts to be registered.
@@ -517,9 +526,9 @@
517 526 'draft-js' => 'draft-js-package',
518 527 'feature-flag' => 'feature-flag-package',
519 528 'helpers' => 'helpers-package',
520 529 'jed' => 'jed-package',
521 - 'legacy-components' => 'components-package',
530 + 'chart.js' => 'chart.js-package',
522 531 'network-admin-script' => 'network-admin',
523 532 'redux' => 'redux-package',
524 533 'replacement-variable-editor' => 'replacement-variable-editor-package',
525 534 'search-metadata-previews' => 'search-metadata-previews-package',
@@ -583,14 +592,40 @@
583 592 [
584 593 'name' => 'metabox-css',
585 594 'src' => 'metabox-' . $flat_version,
586 595 'deps' => [
587 - self::PREFIX . 'select2',
588 596 self::PREFIX . 'admin-css',
597 + self::PREFIX . 'tailwind',
589 598 'wp-components',
590 599 ],
591 600 ],
592 601 [
602 + 'name' => 'block-editor',
603 + 'src' => 'block-editor-' . $flat_version,
604 + ],
605 + [
606 + 'name' => 'ai-generator',
607 + 'src' => 'ai-generator-' . $flat_version,
608 + 'deps' => [
609 + self::PREFIX . 'ai-frontend',
610 + self::PREFIX . 'tailwind',
611 + self::PREFIX . 'introductions',
612 + ],
613 + ],
614 + [
615 + 'name' => 'ai-fix-assessments',
616 + 'src' => 'ai-fix-assessments-' . $flat_version,
617 + ],
618 + [
619 + 'name' => 'ai-frontend',
620 + 'src' => 'ai-frontend-' . $flat_version,
621 + ],
622 + [
623 + 'name' => 'introductions',
624 + 'src' => 'introductions-' . $flat_version,
625 + 'deps' => [ self::PREFIX . 'tailwind' ],
626 + ],
627 + [
593 628 'name' => 'wp-dashboard',
594 629 'src' => 'dashboard-' . $flat_version,
595 630 ],
596 631 [
@@ -608,66 +643,107 @@
608 643 'name' => 'primary-category',
609 644 'src' => 'metabox-primary-category-' . $flat_version,
610 645 ],
611 646 [
612 - 'name' => 'select2',
613 - 'src' => 'select2/select2',
614 - 'suffix' => '.min',
615 - 'version' => '4.1.0-rc.0',
616 - 'rtl' => false,
647 + 'name' => 'admin-global',
648 + 'src' => 'admin-global-' . $flat_version,
649 + 'deps' => [ self::PREFIX . 'tailwind' ],
617 650 ],
618 651 [
619 - 'name' => 'admin-global',
620 - 'src' => 'admin-global-' . $flat_version,
652 + 'name' => 'filter-explanation',
653 + 'src' => 'filter-explanation-' . $flat_version,
621 654 ],
622 655 [
623 - 'name' => 'yoast-components',
624 - 'src' => 'yoast-components-' . $flat_version,
656 + 'name' => 'monorepo',
657 + 'src' => 'monorepo-' . $flat_version,
625 658 ],
626 659 [
627 - 'name' => 'extensions',
628 - 'src' => 'yoast-extensions-' . $flat_version,
660 + 'name' => 'structured-data-blocks',
661 + 'src' => 'structured-data-blocks-' . $flat_version,
629 662 'deps' => [
630 - 'wp-components',
663 + 'dashicons',
664 + 'forms',
665 + 'wp-edit-blocks',
631 666 ],
632 667 ],
633 668 [
634 - 'name' => 'filter-explanation',
635 - 'src' => 'filter-explanation-' . $flat_version,
669 + 'name' => 'elementor',
670 + 'src' => 'elementor-' . $flat_version,
636 671 ],
637 672 [
638 - 'name' => 'search-appearance',
639 - 'src' => 'search-appearance-' . $flat_version,
640 - 'deps' => [
641 - self::PREFIX . 'monorepo',
642 - ],
673 + 'name' => 'tailwind',
674 + 'src' => 'tailwind-' . $flat_version,
675 + // Note: The RTL suffix is not added here.
676 + // Tailwind and our UI library provide styling that should be standalone compatible with RTL.
677 + // To make it easier we should use the logical properties and values when possible.
678 + // If there are exceptions, we can use the Tailwind modifier, e.g. `rtl:yst-space-x-reverse`.
679 + 'rtl' => false,
643 680 ],
644 681 [
645 - 'name' => 'monorepo',
646 - 'src' => 'monorepo-' . $flat_version,
682 + 'name' => 'new-settings',
683 + 'src' => 'new-settings-' . $flat_version,
684 + 'deps' => [ self::PREFIX . 'tailwind' ],
647 685 ],
648 686 [
649 - 'name' => 'structured-data-blocks',
650 - 'src' => 'structured-data-blocks-' . $flat_version,
651 - 'deps' => [ 'wp-edit-blocks' ],
687 + 'name' => 'redirects',
688 + 'src' => 'redirects-' . $flat_version,
689 + 'deps' => [ self::PREFIX . 'tailwind' ],
652 690 ],
653 691 [
654 - 'name' => 'schema-blocks',
655 - 'src' => 'schema-blocks-' . $flat_version,
692 + 'name' => 'black-friday-banner',
693 + 'src' => 'black-friday-banner-' . $flat_version,
694 + 'deps' => [ self::PREFIX . 'tailwind' ],
656 695 ],
657 696 [
658 - 'name' => 'elementor',
659 - 'src' => 'elementor-' . $flat_version,
697 + 'name' => 'academy',
698 + 'src' => 'academy-' . $flat_version,
699 + 'deps' => [ self::PREFIX . 'tailwind' ],
660 700 ],
661 701 [
702 + 'name' => 'bulk-editor-page',
703 + 'src' => 'bulk-editor-page-' . $flat_version,
704 + 'deps' => [ self::PREFIX . 'tailwind' ],
705 + ],
706 + [
707 + 'name' => 'general-page',
708 + 'src' => 'general-page-' . $flat_version,
709 + 'deps' => [ self::PREFIX . 'tailwind' ],
710 + ],
711 + [
712 + 'name' => 'integrations-page',
713 + 'src' => 'integrations-page-' . $flat_version,
714 + 'deps' => [ self::PREFIX . 'tailwind' ],
715 + ],
716 + [
717 + 'name' => 'installation-success',
718 + 'src' => 'installation-success-' . $flat_version,
719 + 'deps' => [ self::PREFIX . 'tailwind' ],
720 + ],
721 + [
722 + 'name' => 'support',
723 + 'src' => 'support-' . $flat_version,
724 + 'deps' => [ self::PREFIX . 'tailwind' ],
725 + ],
726 + [
662 727 'name' => 'workouts',
663 728 'src' => 'workouts-' . $flat_version,
664 - 'deps' => [ self::PREFIX . 'monorepo' ],
729 + 'deps' => [
730 + self::PREFIX . 'monorepo',
731 + ],
665 732 ],
666 733 [
667 - 'name' => 'installation-success',
668 - 'src' => 'installation-success-' . $flat_version,
669 - 'deps' => [ self::PREFIX . 'monorepo' ],
734 + 'name' => 'first-time-configuration',
735 + 'src' => 'first-time-configuration-' . $flat_version,
736 + 'deps' => [ self::PREFIX . 'tailwind' ],
737 + ],
738 + [
739 + 'name' => 'inside-editor',
740 + 'src' => 'inside-editor-' . $flat_version,
741 + ],
742 + [
743 + 'name' => 'plans',
744 + 'src' => 'plans-' . $flat_version,
745 + 'deps' => [ self::PREFIX . 'tailwind' ],
670 746 ],
671 747 ];
672 748 }
673 749