PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 +197 -125 18.428.5 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,18 +81,27 @@
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 );
92 105
93 106 if ( in_array( 'wp-i18n', $script->get_deps(), true ) ) {
94 107 wp_set_script_translations( $this->prefix . $script->get_name(), 'wordpress-seo' );
@@ -98,8 +111,10 @@
98 111 /**
99 112 * Registers styles based on it's parameters.
100 113 *
101 114 * @param WPSEO_Admin_Asset $style The style to register.
115 + *
116 + * @return void
102 117 */
103 118 public function register_style( WPSEO_Admin_Asset $style ) {
104 119 wp_register_style(
105 120 $this->prefix . $style->get_name(),
@@ -105,14 +120,16 @@
105 120 $this->prefix . $style->get_name(),
106 121 $this->get_url( $style, WPSEO_Admin_Asset::TYPE_CSS ),
107 122 $style->get_deps(),
108 123 $style->get_version(),
109 - $style->get_media()
124 + $style->get_media(),
110 125 );
111 126 }
112 127
113 128 /**
114 129 * Calls the functions that register scripts and styles with the scripts and styles to be registered as arguments.
130 + *
131 + * @return void
115 132 */
116 133 public function register_assets() {
117 134 $this->register_scripts( $this->scripts_to_be_registered() );
118 135 $this->register_styles( $this->styles_to_be_registered() );
@@ -121,8 +138,10 @@
121 138 /**
122 139 * Registers all the scripts passed to it.
123 140 *
124 141 * @param array $scripts The scripts passed to it.
142 + *
143 + * @return void
125 144 */
126 145 public function register_scripts( $scripts ) {
127 146 foreach ( $scripts as $script ) {
128 147 $script = new WPSEO_Admin_Asset( $script );
@@ -133,8 +152,10 @@
133 152 /**
134 153 * Registers all the styles it receives.
135 154 *
136 155 * @param array $styles Styles that need to be registered.
156 + *
157 + * @return void
137 158 */
138 159 public function register_styles( $styles ) {
139 160 foreach ( $styles as $style ) {
140 161 $style = new WPSEO_Admin_Asset( $style );
@@ -147,11 +168,13 @@
147 168 *
148 169 * @param string $handle The script handle.
149 170 * @param string $object_name The object name.
150 171 * @param array $data The l10n data.
172 + *
173 + * @return void
151 174 */
152 175 public function localize_script( $handle, $object_name, $data ) {
153 - \wp_localize_script( $this->prefix . $handle, $object_name, $data );
176 + wp_localize_script( $this->prefix . $handle, $object_name, $data );
154 177 }
155 178
156 179 /**
157 180 * Adds an inline script.
@@ -158,11 +181,13 @@
158 181 *
159 182 * @param string $handle The script handle.
160 183 * @param string $data The l10n data.
161 184 * @param string $position Optional. Whether to add the inline script before the handle or after.
185 + *
186 + * @return void
162 187 */
163 188 public function add_inline_script( $handle, $data, $position = 'after' ) {
164 - \wp_add_inline_script( $this->prefix . $handle, $data, $position );
189 + wp_add_inline_script( $this->prefix . $handle, $data, $position );
165 190 }
166 191
167 192 /**
168 193 * A list of styles that shouldn't be registered but are needed in other locations in the plugin.
@@ -218,12 +243,33 @@
218 243 *
219 244 * @return bool True when the script is enqueued.
220 245 */
221 246 public function is_script_enqueued( $script ) {
222 - return \wp_script_is( $this->prefix . $script );
247 + return wp_script_is( $this->prefix . $script );
223 248 }
224 249
225 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 + /**
226 272 * Returns the scripts that need to be registered.
227 273 *
228 274 * @todo Data format is not self-documenting. Needs explanation inline. R.
229 275 *
@@ -235,49 +281,65 @@
235 281 'block-editor',
236 282 'classic-editor',
237 283 'post-edit',
238 284 'help-scout-beacon',
285 + 'redirect-old-features-tab',
239 286 ];
287 + $elementor_dependencies = $this->get_elementor_dependencies();
240 288 $additional_dependencies = [
241 - 'analysis-worker' => [ self::PREFIX . 'analysis-package' ],
242 - 'api-client' => [ 'wp-api' ],
243 - 'dashboard-widget' => [ self::PREFIX . 'api-client' ],
244 - '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' => [
245 302 self::PREFIX . 'api-client',
246 303 self::PREFIX . 'externals-components',
247 304 self::PREFIX . 'externals-contexts',
248 305 self::PREFIX . 'externals-redux',
249 306 ],
250 - 'indexation' => [
251 - 'jquery-ui-core',
252 - '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',
253 312 ],
254 - 'post-edit' => [
313 + 'post-edit' => [
255 314 self::PREFIX . 'api-client',
256 315 self::PREFIX . 'block-editor',
257 316 self::PREFIX . 'externals-components',
258 317 self::PREFIX . 'externals-contexts',
259 318 self::PREFIX . 'externals-redux',
260 - self::PREFIX . 'select2',
261 319 ],
262 - 'reindex-links' => [
320 + 'reindex-links' => [
263 321 'jquery-ui-core',
264 322 'jquery-ui-progressbar',
265 323 ],
266 - 'settings' => [
324 + 'settings' => [
267 325 'jquery-ui-core',
268 326 'jquery-ui-progressbar',
269 327 self::PREFIX . 'api-client',
270 - self::PREFIX . 'select2',
328 + self::PREFIX . 'externals-components',
329 + self::PREFIX . 'externals-contexts',
330 + self::PREFIX . 'externals-redux',
271 331 ],
272 - 'term-edit' => [
332 + 'term-edit' => [
273 333 self::PREFIX . 'api-client',
274 334 self::PREFIX . 'classic-editor',
275 335 self::PREFIX . 'externals-components',
276 336 self::PREFIX . 'externals-contexts',
277 337 self::PREFIX . 'externals-redux',
278 - self::PREFIX . 'select2',
279 338 ],
339 + 'general-page' => [
340 + self::PREFIX . 'api-client',
341 + ],
280 342 ];
281 343
282 344 $plugin_scripts = $this->load_generated_asset_file(
283 345 [
@@ -284,9 +346,9 @@
284 346 'asset_file' => __DIR__ . '/../src/generated/assets/plugin.php',
285 347 'ext_length' => 3,
286 348 'additional_deps' => $additional_dependencies,
287 349 'header_scripts' => $header_scripts,
288 - ]
350 + ],
289 351 );
290 352 $external_scripts = $this->load_generated_asset_file(
291 353 [
292 354 'asset_file' => __DIR__ . '/../src/generated/assets/externals.php',
@@ -294,9 +356,9 @@
294 356 'suffix' => '-package',
295 357 'base_dir' => 'externals/',
296 358 'additional_deps' => $additional_dependencies,
297 359 'header_scripts' => $header_scripts,
298 - ]
360 + ],
299 361 );
300 362 $language_scripts = $this->load_generated_asset_file(
301 363 [
302 364 'asset_file' => __DIR__ . '/../src/generated/assets/languages.php',
@@ -304,11 +366,10 @@
304 366 'suffix' => '-language',
305 367 'base_dir' => 'languages/',
306 368 'additional_deps' => $additional_dependencies,
307 369 'header_scripts' => $header_scripts,
308 - ]
370 + ],
309 371 );
310 - $select2_scripts = $this->load_select2_scripts();
311 372 $renamed_scripts = $this->load_renamed_scripts();
312 373
313 374 $scripts = array_merge(
314 375 $plugin_scripts,
@@ -313,10 +374,9 @@
313 374 $scripts = array_merge(
314 375 $plugin_scripts,
315 376 $external_scripts,
316 377 $language_scripts,
317 - $select2_scripts,
318 - $renamed_scripts
378 + $renamed_scripts,
319 379 );
320 380
321 381 $scripts['installation-success'] = [
322 382 'name' => 'installation-success',
@@ -326,9 +386,9 @@
326 386 'wp-dom-ready',
327 387 'wp-components',
328 388 'wp-element',
329 389 'wp-i18n',
330 - self::PREFIX . 'yoast-components',
390 + self::PREFIX . 'components-new-package',
331 391 self::PREFIX . 'externals-components',
332 392 ],
333 393 'version' => $scripts['installation-success']['version'],
334 394 ];
@@ -336,15 +396,15 @@
336 396 $scripts['post-edit-classic'] = [
337 397 'name' => 'post-edit-classic',
338 398 'src' => $scripts['post-edit']['src'],
339 399 'deps' => array_map(
340 - static function( $dep ) {
400 + static function ( $dep ) {
341 401 if ( $dep === self::PREFIX . 'block-editor' ) {
342 402 return self::PREFIX . 'classic-editor';
343 403 }
344 404 return $dep;
345 405 },
346 - $scripts['post-edit']['deps']
406 + $scripts['post-edit']['deps'],
347 407 ),
348 408 'in_footer' => ! in_array( 'post-edit-classic', $header_scripts, true ),
349 409 'version' => $scripts['post-edit']['version'],
350 410 ];
@@ -366,10 +426,9 @@
366 426 self::PREFIX . 'externals-components',
367 427 self::PREFIX . 'externals-contexts',
368 428 self::PREFIX . 'externals-redux',
369 429 self::PREFIX . 'analysis',
370 - self::PREFIX . 'react-select',
371 - self::PREFIX . 'yoast-components',
430 + self::PREFIX . 'components-new-package',
372 431 ],
373 432 'version' => $scripts['workouts']['version'],
374 433 ];
375 434
@@ -416,9 +475,9 @@
416 475 'suffix' => '',
417 476 'additional_deps' => [],
418 477 'base_dir' => '',
419 478 'header_scripts' => [],
420 - ]
479 + ],
421 480 );
422 481 $scripts = [];
423 482 $assets = require $args['asset_file'];
424 483 foreach ( $assets as $file => $data ) {
@@ -443,62 +502,8 @@
443 502 return $scripts;
444 503 }
445 504
446 505 /**
447 - * Loads the select2 scripts.
448 - *
449 - * @return array {
450 - * The scripts to be registered.
451 - *
452 - * @type string $name The name of the asset.
453 - * @type string $src The src of the asset.
454 - * @type string[] $deps The dependenies of the asset.
455 - * @type bool $in_footer Whether or not the asset should be in the footer.
456 - * }
457 - */
458 - protected function load_select2_scripts() {
459 - $scripts = [];
460 - $select2_language = 'en';
461 - $user_locale = \get_user_locale();
462 - $language = WPSEO_Language_Utils::get_language( $user_locale );
463 -
464 - if ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$user_locale}.js" ) ) {
465 - $select2_language = $user_locale; // Chinese and some others use full locale.
466 - }
467 - elseif ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$language}.js" ) ) {
468 - $select2_language = $language;
469 - }
470 -
471 - $scripts['select2'] = [
472 - 'name' => 'select2',
473 - 'src' => false,
474 - 'deps' => [
475 - self::PREFIX . 'select2-translations',
476 - self::PREFIX . 'select2-core',
477 - ],
478 - ];
479 - $scripts['select2-core'] = [
480 - 'name' => 'select2-core',
481 - 'src' => 'select2/select2.full.min.js',
482 - 'deps' => [
483 - 'jquery',
484 - ],
485 - 'version' => '4.1.0-rc.0',
486 - ];
487 - $scripts['select2-translations'] = [
488 - 'name' => 'select2-translations',
489 - 'src' => 'select2/i18n/' . $select2_language . '.js',
490 - 'deps' => [
491 - 'jquery',
492 - self::PREFIX . 'select2-core',
493 - ],
494 - 'version' => '4.1.0-rc.0',
495 - ];
496 -
497 - return $scripts;
498 - }
499 -
500 - /**
501 506 * Loads the scripts that should be renamed for BC.
502 507 *
503 508 * @return array {
504 509 * The scripts to be registered.
@@ -521,9 +526,9 @@
521 526 'draft-js' => 'draft-js-package',
522 527 'feature-flag' => 'feature-flag-package',
523 528 'helpers' => 'helpers-package',
524 529 'jed' => 'jed-package',
525 - 'legacy-components' => 'components-package',
530 + 'chart.js' => 'chart.js-package',
526 531 'network-admin-script' => 'network-admin',
527 532 'redux' => 'redux-package',
528 533 'replacement-variable-editor' => 'replacement-variable-editor-package',
529 534 'search-metadata-previews' => 'search-metadata-previews-package',
@@ -587,14 +592,40 @@
587 592 [
588 593 'name' => 'metabox-css',
589 594 'src' => 'metabox-' . $flat_version,
590 595 'deps' => [
591 - self::PREFIX . 'select2',
592 596 self::PREFIX . 'admin-css',
597 + self::PREFIX . 'tailwind',
593 598 'wp-components',
594 599 ],
595 600 ],
596 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 + [
597 628 'name' => 'wp-dashboard',
598 629 'src' => 'dashboard-' . $flat_version,
599 630 ],
600 631 [
@@ -612,66 +643,107 @@
612 643 'name' => 'primary-category',
613 644 'src' => 'metabox-primary-category-' . $flat_version,
614 645 ],
615 646 [
616 - 'name' => 'select2',
617 - 'src' => 'select2/select2',
618 - 'suffix' => '.min',
619 - 'version' => '4.1.0-rc.0',
620 - 'rtl' => false,
647 + 'name' => 'admin-global',
648 + 'src' => 'admin-global-' . $flat_version,
649 + 'deps' => [ self::PREFIX . 'tailwind' ],
621 650 ],
622 651 [
623 - 'name' => 'admin-global',
624 - 'src' => 'admin-global-' . $flat_version,
652 + 'name' => 'filter-explanation',
653 + 'src' => 'filter-explanation-' . $flat_version,
625 654 ],
626 655 [
627 - 'name' => 'yoast-components',
628 - 'src' => 'yoast-components-' . $flat_version,
656 + 'name' => 'monorepo',
657 + 'src' => 'monorepo-' . $flat_version,
629 658 ],
630 659 [
631 - 'name' => 'extensions',
632 - 'src' => 'yoast-extensions-' . $flat_version,
660 + 'name' => 'structured-data-blocks',
661 + 'src' => 'structured-data-blocks-' . $flat_version,
633 662 'deps' => [
634 - 'wp-components',
663 + 'dashicons',
664 + 'forms',
665 + 'wp-edit-blocks',
635 666 ],
636 667 ],
637 668 [
638 - 'name' => 'filter-explanation',
639 - 'src' => 'filter-explanation-' . $flat_version,
669 + 'name' => 'elementor',
670 + 'src' => 'elementor-' . $flat_version,
640 671 ],
641 672 [
642 - 'name' => 'search-appearance',
643 - 'src' => 'search-appearance-' . $flat_version,
644 - 'deps' => [
645 - self::PREFIX . 'monorepo',
646 - ],
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,
647 680 ],
648 681 [
649 - 'name' => 'monorepo',
650 - 'src' => 'monorepo-' . $flat_version,
682 + 'name' => 'new-settings',
683 + 'src' => 'new-settings-' . $flat_version,
684 + 'deps' => [ self::PREFIX . 'tailwind' ],
651 685 ],
652 686 [
653 - 'name' => 'structured-data-blocks',
654 - 'src' => 'structured-data-blocks-' . $flat_version,
655 - 'deps' => [ 'wp-edit-blocks' ],
687 + 'name' => 'redirects',
688 + 'src' => 'redirects-' . $flat_version,
689 + 'deps' => [ self::PREFIX . 'tailwind' ],
656 690 ],
657 691 [
658 - 'name' => 'schema-blocks',
659 - 'src' => 'schema-blocks-' . $flat_version,
692 + 'name' => 'black-friday-banner',
693 + 'src' => 'black-friday-banner-' . $flat_version,
694 + 'deps' => [ self::PREFIX . 'tailwind' ],
660 695 ],
661 696 [
662 - 'name' => 'elementor',
663 - 'src' => 'elementor-' . $flat_version,
697 + 'name' => 'academy',
698 + 'src' => 'academy-' . $flat_version,
699 + 'deps' => [ self::PREFIX . 'tailwind' ],
664 700 ],
665 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 + [
666 727 'name' => 'workouts',
667 728 'src' => 'workouts-' . $flat_version,
668 - 'deps' => [ self::PREFIX . 'monorepo' ],
729 + 'deps' => [
730 + self::PREFIX . 'monorepo',
731 + ],
669 732 ],
670 733 [
671 - 'name' => 'installation-success',
672 - 'src' => 'installation-success-' . $flat_version,
673 - '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' ],
674 746 ],
675 747 ];
676 748 }
677 749