Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active April 21, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/053f8f47c21df51f1a081fc41b47f547 to your computer and use it in GitHub Desktop.
Save westonruter/053f8f47c21df51f1a081fc41b47f547 to your computer and use it in GitHub Desktop.
[OBSOLETE] Enable the official AMP plugin to send Server-Timing response headers when WP_DEBUG is enabled or an administrator is logged-in
<?php
/**
* Plugin Name: AMP Server-Timing
* Description: As of <a href="https://wordpress.org/plugins/amp/">AMP plugin</a> v1.2, the <code>Server-Timing</code> response headers are <a href="https://github.com/ampproject/amp-wp/pull/2268">disabled by default</a>. This plugin enables them when <code>WP_DEBUG</code> is enabled or an administrator is logged-in.
* Plugin URI: https://gist.github.com/westonruter/053f8f47c21df51f1a081fc41b47f547
* Author: Weston Ruter
* Author URI: https://weston.ruter.net
* Version: 1.0
* License: GPLv2 or later
* Gist Plugin URI: https://gist.github.com/westonruter/053f8f47c21df51f1a081fc41b47f547
*
* @package AMP
*/
add_action(
'amp_init',
function () {
if ( ! class_exists( 'AMP_HTTP' ) || ! property_exists( 'AMP_HTTP', 'server_timing' ) ) {
return;
}
AMP_HTTP::$server_timing = (
( defined( 'WP_DEBUG' ) && WP_DEBUG )
||
current_user_can( 'manage_options' )
);
}
);
@westonruter
Copy link
Author

@westonruter
Copy link
Author

This is obsolete. Server timings are now sent with all responses. When the user is not logged-in, the are limited to these 4:

image

If an administrator user is logged-in and the request is made with the ?amp_verbose_server_timing=1 query parameter, then all server timings are sent:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment