Skip to content

Commit 2f24014

Browse files
committed
Add test case for od_can_optimize_response filter and disabled_flags
1 parent f065ce6 commit 2f24014

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

plugins/optimization-detective/docs/hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ add_filter( 'od_can_optimize_response', function( $can_optimize, array $disabled
214214
$can_optimize = count( array_filter( $disabled_flags ) ) === 0;
215215
}
216216
return $can_optimize;
217-
} );
217+
}, 10, 2 );
218218
```
219219

220220
Note that some conditions cannot be overridden by this filter. Even if the filter returns `true`, optimization will still be disabled when:

plugins/optimization-detective/tests/test-optimization.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,27 @@ public function data_provider_test_od_maybe_add_template_output_buffer_filter():
177177
},
178178
'expected_has_filter' => true,
179179
),
180+
'search_enabled_by_filter_using_flags' => array(
181+
'set_up' => static function (): string {
182+
// This is needed because otherwise no_cache_purge_post_id will be true.
183+
self::factory()->post->create( array( 'post_title' => 'foo' ) );
184+
185+
add_filter(
186+
'od_can_optimize_response',
187+
static function ( $can_optimize, array $disabled_flags ): bool {
188+
if ( ! $can_optimize && $disabled_flags['is_search'] ) {
189+
unset( $disabled_flags['is_search'] );
190+
$can_optimize = count( array_filter( $disabled_flags ) ) === 0;
191+
}
192+
return $can_optimize;
193+
},
194+
10,
195+
2
196+
);
197+
return home_url( '/?s=foo' );
198+
},
199+
'expected_has_filter' => true,
200+
),
180201
'home_disabled_by_get_param' => array(
181202
'set_up' => static function (): string {
182203
return home_url( '/?optimization_detective_disabled=1' );

0 commit comments

Comments
 (0)