Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect /amp/ suffix when determining AMP request #9625

Merged
merged 4 commits into from
May 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions 3rd-party/class.jetpack-amp-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,20 @@ static function is_amp_request() {
// can't use is_amp_endpoint() since it's not ready early enough in init.
// is_amp_endpoint() implementation calls is_feed, which bails with a notice if plugins_loaded isn't finished
// "Conditional query tags do not work before the query is run"
$is_amp_request = ! is_admin() // this is necessary so that modules can still be enabled/disabled/configured as per normal via Jetpack admin
$is_amp_request =
defined( 'AMP__VERSION' )
&&
! is_admin() // this is necessary so that modules can still be enabled/disabled/configured as per normal via Jetpack admin
&&
function_exists( 'amp_is_canonical' ) // this is really just testing if the plugin exists
&&
( amp_is_canonical() || isset( $_GET[ amp_get_slug() ] ) );
(
amp_is_canonical()
||
isset( $_GET[ amp_get_slug() ] )
||
( version_compare( AMP__VERSION, '1.0', '<' ) && self::has_amp_suffix() ) // after AMP 1.0, the amp suffix will no longer be supported
);

/**
* Returns true if the current request should return valid AMP content.
Expand All @@ -78,6 +87,11 @@ function_exists( 'amp_is_canonical' ) // this is really just testing if the plug
return apply_filters( 'jetpack_is_amp_request', $is_amp_request );
}

static function has_amp_suffix() {
$request_path = wp_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
return $request_path && preg_match( '#/amp/?$#i', $request_path );
}

static function filter_available_widgets( $widgets ) {
if ( self::is_amp_request() ) {
$widgets = array_filter( $widgets, array( 'Jetpack_AMP_Support', 'is_supported_widget' ) );
Expand Down