Skip to content

Commit

Permalink
Merge pull request #21703 from Yoast/fix-editor-assets-enqueue
Browse files Browse the repository at this point in the history
Make sure assets are also enqueued for non block editor editors.
  • Loading branch information
pls78 authored Oct 15, 2024
2 parents 17073c5 + f92a251 commit aada569
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public function __construct() {
}

add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] );
add_action( 'enqueue_block_assets', [ $this, 'enqueue' ] );
// Enqueue metabox assets for the block editor.
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue' ] );
// Enqueue metabox assets for other editors.
add_action( 'admin_enqueue_scripts', [ $this, 'maybe_enqueue_assets_non_block_editor' ] );

add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_post_overview_assets' ] );
add_action( 'wp_insert_post', [ $this, 'save_postdata' ] );
add_action( 'edit_attachment', [ $this, 'save_postdata' ] );
Expand Down Expand Up @@ -816,24 +820,35 @@ public function enqueue_post_overview_assets() {
}

/**
* Enqueues all the needed JS and CSS.
*
* @todo [JRF => whomever] Create css/metabox-mp6.css file and add it to the below allowed colors array when done.
* Checks to make sure the current editor used is not the block editor to enqueue all needed assets.
* If it is the block editor the assets are already enqueued in the `enqueue_block_assets` action.
*
* @return void
*/
public function enqueue() {
public function maybe_enqueue_assets_non_block_editor() {
global $pagenow;

$asset_manager = new WPSEO_Admin_Asset_Manager();
if ( ( self::is_post_edit( $pagenow ) === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || WP_Screen::get()->is_block_editor() ) {
return;
}

$is_editor = self::is_post_overview( $pagenow ) || self::is_post_edit( $pagenow );
$this->enqueue();
}

/* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */
if ( ( $is_editor === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || $this->display_metabox() === false ) {
/**
* Enqueues all the needed JS and CSS.
*
* @todo [JRF => whomever] Create css/metabox-mp6.css file and add it to the below allowed colors array when done.
*
* @return void
*/
public function enqueue() {
if ( $this->display_metabox() === false ) {
return;
}

$asset_manager = new WPSEO_Admin_Asset_Manager();

$post_id = get_queried_object_id();
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( empty( $post_id ) && isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) {
Expand Down

0 comments on commit aada569

Please sign in to comment.