Skip to content

Commit

Permalink
Simplify assets enqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Sep 14, 2023
1 parent 12560aa commit 1b8726d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
8 changes: 0 additions & 8 deletions classes/CommonPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ public function __construct() {
$this->title = esc_html__( 'ElasticPress', 'debug-bar-elasticpress' );
}

/**
* Enqueue assets
*/
public function enqueue_assets() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
}

/**
* Return the panel title
*
Expand Down
2 changes: 1 addition & 1 deletion classes/EP_Debug_Bar_ElasticPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function init() {
$this->title( esc_html__( 'ElasticPress', 'debug-bar-elasticpress' ) );

$this->common_panel = \DebugBarElasticPress\get_common_panel();
$this->common_panel->enqueue_assets();
$this->common_panel->enqueue_scripts_styles();
}

/**
Expand Down
27 changes: 25 additions & 2 deletions classes/QueryLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function setup() {
add_action( 'ep_remote_request', array( $this, 'log_query' ), 10, 2 );
add_action( 'admin_init', array( $this, 'action_admin_init' ) );
add_action( 'admin_init', array( $this, 'maybe_clear_log' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );

/**
* Handle query storage as JSON strings.
Expand Down Expand Up @@ -86,11 +87,18 @@ public function maybe_clear_log() {
/**
* Add options page
*
* @since 1.3
* @since 1.3
* @return void
*/
public function action_admin_menu() {
add_submenu_page( 'elasticpress', esc_html__( 'Query Log', 'debug-bar-elasticpress' ), esc_html__( 'Query Log', 'debug-bar-elasticpress' ), 'manage_options', 'ep-query-log', array( $this, 'screen_options' ) );
add_submenu_page(
'elasticpress',
esc_html__( 'Query Log', 'debug-bar-elasticpress' ),
esc_html__( 'Query Log', 'debug-bar-elasticpress' ),
'manage_options',
'ep-query-log',
array( $this, 'screen_options' )
);
}

/**
Expand Down Expand Up @@ -394,6 +402,21 @@ public function maybe_add_request_query_type( array $request_args, string $path,
return $request_args;
}

/**
* Enqueue assets if we are in the correct admin screen
*
* @since 3.1.0
*/
public function admin_enqueue_scripts() {
$current_screen = get_current_screen();

if ( ! isset( $current_screen->id ) || 'elasticpress_page_ep-query-log' !== $current_screen->id ) {
return;
}

get_common_panel()->enqueue_scripts_styles();
}

/**
* Conditionally add the request type to the request args (for query requests)
*
Expand Down
2 changes: 1 addition & 1 deletion debug-bar-elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function setup() {
if ( class_exists( '\QM_Collectors' ) ) {
\QM_Collectors::add( new QueryMonitorCollector() );
add_filter( 'qm/outputter/html', $n( 'register_qm_output' ) );
add_action( 'qm/output/enqueued-assets', [ get_common_panel(), 'enqueue_assets' ] );
add_action( 'qm/output/enqueued-assets', [ get_common_panel(), 'enqueue_scripts_styles' ] );
} else {
add_filter( 'debug_bar_panels', $n( 'add_debug_bar_panel' ) );
add_filter( 'debug_bar_statuses', $n( 'add_debug_bar_stati' ) );
Expand Down

0 comments on commit 1b8726d

Please sign in to comment.