Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.