PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
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 / src / integrations / admin / fix-news-dependencies-integration.php

fix-news-dependencies-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at src/integrations/admin/fix-news-dependencies-integration.php

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Admin;
4
5 use WP_Screen;
6 use WPSEO_Admin_Asset_Manager;
7 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
8 use Yoast\WP\SEO\Conditionals\News_Conditional;
9 use Yoast\WP\SEO\Integrations\Integration_Interface;
10
11 /**
12 * Fix_News_Dependencies_Integration class.
13 */
14 class Fix_News_Dependencies_Integration implements Integration_Interface {
15
16 /**
17 * Returns the conditionals based in which this loadable should be active.
18 *
19 * In this case: when on an admin page.
20 *
21 * @return array The conditionals.
22 */
23 public static function get_conditionals() {
24 return [ Admin_Conditional::class, News_Conditional::class ];
25 }
26
27 /**
28 * Registers an action to disable script concatenation.
29 *
30 * @return void
31 */
32 public function register_hooks() {
33 global $pagenow;
34
35 // Load the editor script when on an edit post or new post page.
36 $is_post_edit_page = $pagenow === 'post.php' || $pagenow === 'post-new.php';
37 if ( $is_post_edit_page ) {
38 \add_action( 'admin_enqueue_scripts', [ $this, 'add_news_script_dependency' ], 11 );
39 }
40 }
41
42 /**
43 * Fixes the news script dependency.
44 *
45 * @return void
46 */
47 public function add_news_script_dependency() {
48 $scripts = \wp_scripts();
49
50 if ( ! isset( $scripts->registered['wpseo-news-editor'] ) ) {
51 return;
52 }
53
54 $is_block_editor = WP_Screen::get()->is_block_editor();
55 $post_edit_handle = 'post-edit';
56 if ( ! $is_block_editor ) {
57 $post_edit_handle = 'post-edit-classic';
58 }
59
60 $scripts->registered['wpseo-news-editor']->deps[] = WPSEO_Admin_Asset_Manager::PREFIX . $post_edit_handle;
61 }
62 }
63