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
5 changes: 5 additions & 0 deletions admin/server-timing.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
exit; // Exit if accessed directly.
}

// Do not add any of the hooks if Server-Timing is disabled.
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return;
}

/**
* Adds the Server-Timing page to the Tools menu.
*
Expand Down
10 changes: 8 additions & 2 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ function perflab_load_active_and_valid_modules() {
* This only runs in WP Admin to not have any potential performance impact on
* the frontend.
*
* This function will short-circuit if the constant
* 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true.
* This function will short-circuit if at least one of the constants
* 'PERFLAB_DISABLE_SERVER_TIMING' or 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is
* set as true.
*
* @since 1.8.0
* @since 2.1.0 No longer attempts to use two of the drop-ins together.
Expand All @@ -327,6 +328,11 @@ function perflab_load_active_and_valid_modules() {
function perflab_maybe_set_object_cache_dropin() {
global $wp_filesystem;

// Bail if Server-Timing is disabled entirely.
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return;
}

// Bail if disabled via constant.
if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) {
return;
Expand Down
5 changes: 5 additions & 0 deletions server-timing/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
exit; // Exit if accessed directly.
}

// Do not add any of the hooks if Server-Timing is disabled.
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return;
}

/**
* Registers the default Server-Timing metrics for before rendering the template.
*
Expand Down
16 changes: 16 additions & 0 deletions server-timing/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
exit; // Exit if accessed directly.
}

// Do not add any of the hooks if Server-Timing is disabled.
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return;
}

define( 'PERFLAB_SERVER_TIMING_SETTING', 'perflab_server_timing_settings' );
define( 'PERFLAB_SERVER_TIMING_SCREEN', 'perflab-server-timing' );

Expand All @@ -27,6 +32,17 @@ function perflab_server_timing() {

if ( null === $server_timing ) {
$server_timing = new Perflab_Server_Timing();

/*
* Do not add the hook for Server-Timing header output if it is entirely disabled.
* While the constant checks on top of the file prevent this from happening by default, external code could
* still call the `perflab_server_timing()` function. It needs to be ensured that such calls do not result in
* fatal errors, but they should at least not lead to the header being output.
*/
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return $server_timing;
}

add_filter( 'template_include', array( $server_timing, 'on_template_include' ), PHP_INT_MAX );
}

Expand Down
7 changes: 6 additions & 1 deletion server-timing/object-cache.copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@
/**
* Loads the Performance Lab Server-Timing API if available.
*
* This function will short-circuit if the constant
* This function will short-circuit if at least one of the constants
* 'PERFLAB_DISABLE_SERVER_TIMING' or
* 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true.
*
* @since 1.8.0
*/
function perflab_load_server_timing_api_from_dropin() {
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return;
}

if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) {
return;
}
Expand Down