Skip to content

Commit 93afb03

Browse files
committed
Prevent output of the Server-Timing header even if external code uses (and thus initializes) the Server-Timing API.
1 parent d10d1f4 commit 93afb03

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

server-timing/load.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ function perflab_server_timing() {
3232

3333
if ( null === $server_timing ) {
3434
$server_timing = new Perflab_Server_Timing();
35+
36+
/*
37+
* Do not add the hook for Server-Timing header output if it is entirely disabled.
38+
* While the constant checks on top of the file prevent this from happening by default, external code could
39+
* still call the `perflab_server_timing()` function. It needs to be ensured that such calls do not result in
40+
* fatal errors, but they should at least not lead to the header being output.
41+
*/
42+
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
43+
return $server_timing;
44+
}
45+
3546
add_filter( 'template_include', array( $server_timing, 'on_template_include' ), PHP_INT_MAX );
3647
}
3748

0 commit comments

Comments
 (0)