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

Prevent adding adding AMP hooks for Infinite Scroll on legacy AMP post templates #17175

Merged
merged 2 commits into from
Sep 17, 2020
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
25 changes: 25 additions & 0 deletions modules/infinite-scroll/infinity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1721,12 +1721,37 @@ public function add_mejs_config( $scripts_data ) {
return $scripts_data;
}

/**
* Determines whether the legacy AMP Reader post templates are being used.
*
* @return bool
*/
private function is_exempted_amp_page() {
if ( is_singular( 'web-story' ) ) {
// Ensure that <amp-next-page> is not injected after <amp-story> as generated by the Web Stories plugin.
return true;
}
if ( function_exists( 'amp_is_legacy' ) ) {
// Available since AMP v2.0, this will return false if a theme like Twenty Twenty is selected as the Reader theme.
return amp_is_legacy();
}
if ( method_exists( 'AMP_Options_Manager', 'get_option' ) ) {
// In versions prior to v2.0, checking the template mode as being 'reader' is sufficient.
return 'reader' === AMP_Options_Manager::get_option( 'theme_support' );
}
return false;
}

/**
* Load AMP specific hooks.
*
* @return void
*/
public function amp_load_hooks() {
if ( $this->is_exempted_amp_page() ) {
return;
}

if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
$template = self::get_settings()->render;

Expand Down