Skip to content

Commit

Permalink
Search: Deprecate and use filter instead. Also decouples query monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Oct 24, 2023
1 parent 746f135 commit 0448c54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions search/includes/classes/class-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ protected function setup_constants() {
* This is separate from setup_hooks because some parts of setup_hooks require ElasticPress.
*/
protected function maybe_enable_ep_query_logging() {
add_action( 'plugins_loaded', [ $this, 'enable_ep_query_logging_if_query_monitor_enabled' ] );
add_action( 'plugins_loaded', [ $this, 'enable_ep_query_logging_if_debug_or_has_cap' ] );
add_action( 'plugins_loaded', [ $this, 'load_ep_get_query_log_function' ] );
}

Expand All @@ -507,15 +507,15 @@ public function load_ep_get_query_log_function() {
}

/**
* Check if query monitor or debug bar are enabled. Also check for the debug mode being enabled.
* Check if debug mode is enabled or has search dev tools cap.
* If so, define WP_EP_DEBUG as true so ElasticPress enables query logging.
*/
public function enable_ep_query_logging_if_query_monitor_enabled() {
public function enable_ep_query_logging_if_debug_or_has_cap() {
if ( defined( 'WP_EP_DEBUG' ) ) {
return;
}

if ( apply_filters( 'wpcom_vip_qm_enable', false ) || ( function_exists( 'is_debug_mode_enabled' ) && is_debug_mode_enabled() ) ) {
if ( current_user_can( apply_filters( 'vip_search_dev_tools_cap', 'manage_options' ) ) || ( function_exists( 'is_debug_mode_enabled' ) && is_debug_mode_enabled() ) ) {
define( 'WP_EP_DEBUG', true );
}
}
Expand Down
5 changes: 2 additions & 3 deletions search/search-dev-tools/search-dev-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

use Automattic\VIP\Search\Search;

define( 'SEARCH_DEV_TOOLS_CAP', 'manage_options' );

add_action( 'rest_api_init', __NAMESPACE__ . '\register_rest_routes' );
add_action( 'admin_bar_menu', __NAMESPACE__ . '\admin_bar_node', PHP_INT_MAX );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets', 11 );
Expand Down Expand Up @@ -100,7 +98,8 @@ function rest_callback( \WP_REST_Request $request ) {
* @return boolean
*/
function should_enable_search_dev_tools(): bool {
return ( current_user_can( SEARCH_DEV_TOOLS_CAP ) || is_debug_mode_enabled() ) && function_exists( 'ep_get_query_log' );
$cap = apply_filters( 'vip_search_dev_tools_cap', 'manage_options' );
return ( current_user_can( $cap ) || is_debug_mode_enabled() ) && function_exists( 'ep_get_query_log' );
}

/**
Expand Down

0 comments on commit 0448c54

Please sign in to comment.