Last active
April 21, 2021 16:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ) | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation instructions: https://gist.github.com/westonruter/6110fbc4bef0c4b8c021a112012f7e9c