Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions tests/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down