From 3bc2b4a6df625971abbe9380c4efb32934e828ae Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Fri, 4 Oct 2024 16:24:14 -0300 Subject: [PATCH] fix: position calculation for inline popups --- includes/class-newspack-popups-inserter.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/includes/class-newspack-popups-inserter.php b/includes/class-newspack-popups-inserter.php index a5ca8fa8..595176af 100755 --- a/includes/class-newspack-popups-inserter.php +++ b/includes/class-newspack-popups-inserter.php @@ -264,6 +264,18 @@ public static function get_block_content( $block ) { return $block_content; } + /** + * Get the length of a given block. + * + * @param array $block A block. + * + * @return int + */ + private static function get_block_length( $block ) { + $block_content = self::get_block_content( $block ); + return strlen( wp_strip_all_tags( $block_content ) ); + } + /** * Insert popups in a post content. * @@ -349,8 +361,7 @@ function ( $block_groups, $block ) use ( &$block_index, $parsed_blocks, $max_ind // Give length-ignored blocks a length of 1 so that prompts at 0% can still be inserted before them. $total_length++; } else { - $block_content = self::get_block_content( $block ); - $total_length += strlen( wp_strip_all_tags( $block_content ) ); + $total_length += self::get_block_length( $block ); } } @@ -385,7 +396,7 @@ function ( $block_groups, $block ) use ( &$block_index, $parsed_blocks, $max_ind // Give length-ignored blocks a length of 1 so that prompts at 0% can still be inserted before them. $pos++; } else { - $pos += strlen( wp_strip_all_tags( $block['innerHTML'] ) ); + $pos += self::get_block_length( $block ); } }