diff --git a/includes/classes/Elasticsearch.php b/includes/classes/Elasticsearch.php index 502bea1c0..6433a2ac8 100644 --- a/includes/classes/Elasticsearch.php +++ b/includes/classes/Elasticsearch.php @@ -1730,14 +1730,14 @@ 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 ) { - $wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG; - $wp_ep_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. * diff --git a/tests/php/TestElasticsearch.php b/tests/php/TestElasticsearch.php index 67e245e79..0d329d846 100644 --- a/tests/php/TestElasticsearch.php +++ b/tests/php/TestElasticsearch.php @@ -378,4 +378,35 @@ public function testGetIndicesComparison() { ]; $this->assertEqualsCanonicalizing( $expected, \ElasticPress\Elasticsearch::factory()->get_indices_comparison() ); } + + /** + * Test the ep_disable_query_logging filter + * + * @since 5.2.0 + * @group elasticsearch + */ + public function testEpDisableQueryLoggingFilter() { + $elasticsearch = new \ElasticPress\Elasticsearch(); + + $reflection = new \ReflectionClass( $elasticsearch ); + $property = $reflection->getProperty( 'queries' ); + $property->setAccessible( true ); + $method = $reflection->getMethod( 'add_query_log' ); + $method->setAccessible( true ); + + $example_query = [ 'example_query' ]; + + add_filter( 'ep_disable_query_logging', '__return_true' ); + + $method->invokeArgs( $elasticsearch, [ $example_query ] ); + $this->assertEmpty( $property->getValue( $elasticsearch ) ); + + remove_filter( 'ep_disable_query_logging', '__return_true' ); + + $method->invokeArgs( $elasticsearch, [ $example_query ] ); + + $queries = $property->getValue( $elasticsearch ); + $this->assertCount( 1, $queries ); + $this->assertSame( $example_query, $queries[0] ); + } }