Skip to content

Commit b0310ee

Browse files
authored
Merge pull request #1996 from b1ink0/add/server-timing-object-cache-dropin-opt-in
Implement opt-in `PERFLAB_PLACE_OBJECT_CACHE_DROPIN` for Server-Timing `object-cache.php` placement
2 parents 167aa3a + 922212d commit b0310ee

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

plugins/performance-lab/load.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ function perflab_get_standalone_plugin_version_constants(): array {
145145
* the frontend.
146146
*
147147
* This function will short-circuit if at least one of the constants
148-
* 'PERFLAB_DISABLE_SERVER_TIMING' or 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is
149-
* set as true.
148+
* 'PERFLAB_DISABLE_SERVER_TIMING' or
149+
* 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true or if the
150+
* 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' constant is not set to a truthy value.
150151
*
151152
* @since 1.8.0
152153
* @since 2.1.0 No longer attempts to use two of the drop-ins together.
154+
* @since n.e.x.t No longer places the drop-in on new sites by default, unless the `PERFLAB_PLACE_OBJECT_CACHE_DROPIN` constant is set to true.
153155
*
154156
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
155157
*/
@@ -161,7 +163,14 @@ function perflab_maybe_set_object_cache_dropin(): void {
161163
return;
162164
}
163165

166+
// Bail if the drop-in is not enabled.
167+
if ( ! defined( 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' ) || ! PERFLAB_PLACE_OBJECT_CACHE_DROPIN ) {
168+
return;
169+
}
170+
164171
// Bail if disabled via constant.
172+
// This constant is maintained only for backward compatibility and should not be relied upon in new implementations.
173+
// Use the 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' constant instead to control drop-in placement.
165174
if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) {
166175
return;
167176
}

plugins/performance-lab/tests/test-load.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77

88
class Test_Load extends WP_UnitTestCase {
99

10+
/**
11+
* Runs the routine before each test is executed.
12+
*/
13+
public function set_up(): void {
14+
parent::set_up();
15+
16+
/*
17+
* This constant is not set by default in production.
18+
* However, it is needed for all tests that cover placement of the object cache drop-in.
19+
*/
20+
if ( ! defined( 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' ) ) {
21+
define( 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN', true );
22+
}
23+
}
24+
1025
public function test_perflab_get_generator_content(): void {
1126
$expected = 'performance-lab ' . PERFLAB_VERSION . '; plugins: ';
1227
$content = perflab_get_generator_content();

0 commit comments

Comments
 (0)