| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations\Admin; |
| 4 |
|
| 5 |
use WPSEO_Admin_Asset_Manager; |
| 6 |
use Yoast\WP\SEO\Conditionals\Admin_Conditional; |
| 7 |
use Yoast\WP\SEO\Conditionals\News_Conditional; |
| 8 |
use Yoast\WP\SEO\Helpers\Current_Page_Helper; |
| 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 |
* Holds the current page helper. |
| 18 |
* |
| 19 |
* @var Current_Page_Helper |
| 20 |
*/ |
| 21 |
private $current_page_helper; |
| 22 |
|
| 23 |
/** |
| 24 |
* Constructs the integration. |
| 25 |
* |
| 26 |
* @param Current_Page_Helper $current_page_helper The current page helper. |
| 27 |
*/ |
| 28 |
public function __construct( Current_Page_Helper $current_page_helper ) { |
| 29 |
$this->current_page_helper = $current_page_helper; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Returns the conditionals based in which this loadable should be active. |
| 34 |
* |
| 35 |
* In this case: when on an admin page. |
| 36 |
* |
| 37 |
* @return array The conditionals. |
| 38 |
*/ |
| 39 |
public static function get_conditionals() { |
| 40 |
return [ Admin_Conditional::class, News_Conditional::class ]; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Registers an action to disable script concatenation. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function register_hooks() { |
| 49 |
global $pagenow; |
| 50 |
|
| 51 |
// Load the editor script when on an edit post or new post page. |
| 52 |
$is_post_edit_page = $pagenow === 'post.php' || $pagenow === 'post-new.php'; |
| 53 |
if ( $is_post_edit_page ) { |
| 54 |
\add_action( 'admin_enqueue_scripts', [ $this, 'add_news_script_dependency' ], 11 ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Fixes the news script dependency. |
| 60 |
* |
| 61 |
* @return void |
| 62 |
*/ |
| 63 |
public function add_news_script_dependency() { |
| 64 |
$scripts = \wp_scripts(); |
| 65 |
|
| 66 |
if ( ! isset( $scripts->registered['wpseo-news-editor'] ) ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$is_block_editor = $this->current_page_helper->is_block_editor(); |
| 71 |
$post_edit_handle = 'post-edit'; |
| 72 |
if ( ! $is_block_editor ) { |
| 73 |
$post_edit_handle = 'post-edit-classic'; |
| 74 |
} |
| 75 |
|
| 76 |
$scripts->registered['wpseo-news-editor']->deps[] = WPSEO_Admin_Asset_Manager::PREFIX . $post_edit_handle; |
| 77 |
} |
| 78 |
} |
| 79 |
|