-
Notifications
You must be signed in to change notification settings - Fork 798
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
Changes from 1 commit
dda40b0
567f897
8bf1c03
3346f19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ static function is_amp_request() { | |
&& | ||
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() ] ) || self::has_amp_suffix() ); | ||
|
||
/** | ||
* Returns true if the current request should return valid AMP content. | ||
|
@@ -78,6 +78,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 = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to use $request_path = strtok( $_SERVER['REQUEST_URI'], '?#' ); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return $request_path && substr_compare( $request_path, '/amp/', -4, 5, true ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wouldn't handle the case when a user has filtered return (bool) preg_match( '#/amp/?$#i', $request_path ); This will ensure that the slash is optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
static function filter_available_widgets( $widgets ) { | ||
if ( self::is_amp_request() ) { | ||
$widgets = array_filter( $widgets, array( 'Jetpack_AMP_Support', 'is_supported_widget' ) ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last part in this conditional should be wrapped in a check for
AMP__VERSION
being less than1.0
since with ampproject/amp-wp#1148 there will no longer be an/amp/
endpoint, and this will help guard against the case when a user publishes a page about guitar amps at like/guitar/amp/
, to avoid ambiguity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍