diff --git a/load.php b/load.php index 9b9cffd474..f739c084c8 100644 --- a/load.php +++ b/load.php @@ -291,6 +291,17 @@ function perflab_maybe_set_object_cache_dropin() { return; } + /** + * Filters whether the Perflab server timing drop-in should be set. + * + * @since n.e.x.t + * + * @param bool Whether the server timing drop-in should be set. + */ + if ( apply_filters( 'perflab_disable_object_cache_dropin', false ) ) { + return; + } + // Bail if already attempted before timeout has been completed. // This is present in case placing the file fails for some reason, to avoid // excessively retrying to place it on every request. diff --git a/tests/load-tests.php b/tests/load-tests.php index be977801e5..f45ee7e8f5 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -343,6 +343,23 @@ public function test_perflab_maybe_set_object_cache_dropin_with_conflict_and_ori $this->assertSame( $dummy_file_content2, $wp_filesystem->get_contents( WP_CONTENT_DIR . '/object-cache-plst-orig.php' ) ); } + public function test_perflab_object_cache_dropin_may_be_disabled_via_filter() { + global $wp_filesystem; + + $this->set_up_mock_filesystem(); + + // Ensure PL object-cache.php drop-in is not present and constant is not set. + $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); + $this->assertFalse( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ); + + // Add filter to disable drop-in. + add_filter( 'perflab_disable_object_cache_dropin', '__return_true' ); + + // Run function to place drop-in and ensure it still doesn't exist afterwards. + perflab_maybe_set_object_cache_dropin(); + $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); + } + private function set_up_mock_filesystem() { global $wp_filesystem;