Skip to content

Commit

Permalink
Refactor assets enqueing hooks and callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pls78 committed Oct 10, 2024
1 parent 5fe591e commit dd80d2d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function __construct() {
}

add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
add_action( 'enqueue_block_assets', [ $this, 'enqueue' ] );
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' ] );
add_action( 'add_attachment', [ $this, 'save_postdata' ] );
Expand Down Expand Up @@ -798,6 +799,23 @@ public function is_meta_value_disabled( $key ) {
return false;
}

/**
* Enqueues assets for the post overview page.
*
* @return void
*/
public function enqueue_post_overview_assets() {
global $pagenow;

$asset_manager = new WPSEO_Admin_Asset_Manager();

if ( self::is_post_overview( $pagenow ) ) {
error_log( 'This is the post overview' );

Check warning on line 813 in admin/metabox/class-metabox.php

View workflow job for this annotation

GitHub Actions / Check code style

error_log() found. Debug code should not normally be used in production.

Check warning on line 813 in admin/metabox/class-metabox.php

View workflow job for this annotation

GitHub Actions / Check code style

error_log() found. Debug code should not normally be used in production.
$asset_manager->enqueue_style( 'edit-page' );
$asset_manager->enqueue_script( 'edit-page' );
}
}

/**
* Enqueues all the needed JS and CSS.
*
Expand All @@ -812,13 +830,6 @@ public function enqueue() {

$is_editor = self::is_post_overview( $pagenow ) || self::is_post_edit( $pagenow );

if ( self::is_post_overview( $pagenow ) ) {
$asset_manager->enqueue_style( 'edit-page' );
$asset_manager->enqueue_script( 'edit-page' );

return;
}

/* 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 ) {
return;
Expand Down

0 comments on commit dd80d2d

Please sign in to comment.