From ed41f8a9b767b059863694cdaf31c7f2307488c4 Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Wed, 5 Jul 2023 15:57:36 -0600 Subject: [PATCH] fix: when comparing filtered vs post content, compare only 1st paragraph --- includes/class-newspack-popups-inserter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/class-newspack-popups-inserter.php b/includes/class-newspack-popups-inserter.php index 71bc0733..cc92bae2 100755 --- a/includes/class-newspack-popups-inserter.php +++ b/includes/class-newspack-popups-inserter.php @@ -452,6 +452,8 @@ private static function is_memberships_restricted( $post_id = null ) { * @param string $content The content of the post. */ public static function insert_popups_in_content( $content = '' ) { + $filtered_content = explode( "\n", $content ); + $post_content = explode( "\n", get_post()->post_content ); if ( // Avoid duplicate execution. true === self::$the_content_has_rendered @@ -467,7 +469,7 @@ public static function insert_popups_in_content( $content = '' ) { // It doesn't make sense with a paywall message and also causes an infinite loop. || self::is_memberships_restricted() // At filter priority 1, $content should be the same as the unfiltered post_content. This guards against inserting in other content such as featured image captions/descriptions. - || get_post()->post_content !== $content + || ( ! empty( $filtered_content ) && ! empty( $post_content ) && $filtered_content[0] !== $post_content[0] ) ) { return $content; }