Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure assets are also enqueued for non block editor editors. #21703

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(): void {
thijsoo marked this conversation as resolved.
Show resolved Hide resolved
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