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

Add new filter to disable query logging: ep_disable_query_logging #217

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all 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
17 changes: 15 additions & 2 deletions includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1618,12 +1618,25 @@ public function add_elasticpress_version_to_user_agent( $user_agent ) {
* Query logging. Don't log anything to the queries property when
* WP_DEBUG is not enabled. Calls action 'ep_add_query_log' if you
* want to access the query outside of the ElasticPress plugin. This
* runs regardless of debufg settings.
* runs regardless of debug settings.
*
* @param array $query Query to log.
*/
protected function add_query_log( $query ) {
if ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG ) ) {
$wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_ep_debug = defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG;

/**
* Filter query logging. Don't log anything to the queries property when true.
*
* @hook ep_disable_query_logging
* @param {bool} Whether to log to the queries property. Defaults to false.
* @return {bool} New value
* @since 5.2.0
*/
$disable_query_logging = apply_filters( 'ep_disable_query_logging', false );

if ( ! $disable_query_logging && ( $wp_debug || $wp_ep_debug ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_wp_debug_backtrace_summary
$query['backtrace'] = wp_debug_backtrace_summary( null, 1, false ); // VIP: Search Dev Tools relies on this backtrace
$this->queries[] = $query;
Expand Down
Loading