Created
January 31, 2019 21:17
-
-
Save westonruter/20d8ef0cea36bcd27bdcd8d011570a58 to your computer and use it in GitHub Desktop.
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 Infinite Endpoint Blocker | |
* | |
* @author Weston Ruter, Google | |
* @license GPL-2.0-or-later | |
* @copyright 2019 Google Inc. | |
* | |
* @wordpress-plugin | |
* Plugin Name: AMP Infinite Endpoint Blocker | |
* Description: Block infinite URL space under amp endpoint. | |
* Version: 0.1.0 | |
* Author: Weston Ruter, Google | |
* Author URI: https://weston.ruter.net/ | |
* License: GNU General Public License v2 (or later) | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
add_action( | |
'template_redirect', | |
function() { | |
if ( ! function_exists( 'amp_get_slug' ) ) { | |
return; | |
} | |
// Abort if query var is used, since not subject to infinite endpoint sub-path problem. | |
if ( isset( $_GET[ amp_get_slug() ] ) ) { | |
return; | |
} | |
$endpoint = get_query_var( amp_get_slug(), false ); | |
if ( false !== $endpoint && '1' !== (string) $endpoint && '' !== $endpoint ) { | |
wp_die( | |
esc_html__( 'Unrecognized AMP URL.', 'amp' ), | |
esc_html__( 'Bad Request', 'amp' ), | |
array( 'response' => 400 ) | |
); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment