diff --git a/includes/class-newspack-popups-inserter.php b/includes/class-newspack-popups-inserter.php index b3dddb00..80dbd783 100644 --- a/includes/class-newspack-popups-inserter.php +++ b/includes/class-newspack-popups-inserter.php @@ -92,6 +92,10 @@ public function __construct() { * @param string $content The content of the post. */ public static function insert_popups_in_content( $content = '' ) { + if ( self::assess_amp_form_issue( $content ) ) { + return $content; + } + if ( is_admin() || ! is_singular() ) { return $content; } @@ -268,10 +272,35 @@ public static function insert_popups_amp_access( $popups ) { } } + /** + * Disable popups on non-AMP pages with a form with POST method. + * More context: https://github.com/ampproject/amphtml/issues/27638. + * + * @param string $content The content of the post. + * @return bool True if popups should be disabled for current page. + */ + public static function assess_amp_form_issue( $content = false ) { + if ( is_admin() || ! is_singular() ) { + return false; + } + if ( ! $content ) { + $content = get_the_content(); + } + $is_amp = function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); + + if ( ! $is_amp ) { + return preg_match( "/