From fa594dc4ba7269a506b756a7ac7629c1bc6fe8ed Mon Sep 17 00:00:00 2001 From: Sebastian Thulin Date: Fri, 7 Feb 2025 14:45:23 +0100 Subject: [PATCH] fix: do not include contents of some tags from source. --- source/php/Index.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/php/Index.php b/source/php/Index.php index 4dab62fe..0ff8c46f 100644 --- a/source/php/Index.php +++ b/source/php/Index.php @@ -316,7 +316,7 @@ private static function getPost($post) 'ID' => $post->ID, 'post_title' => apply_filters('the_title', $post->post_title), 'post_excerpt' => self::getTheExcerpt($post), - 'content' => strip_tags(apply_filters('the_content', $post->post_content)), + 'content' => self::stripTags(apply_filters('the_content', $post->post_content)), 'permalink' => get_permalink($post->ID), 'post_date' => strtotime($post->post_date), 'post_date_formatted' => date(get_option('date_format'), strtotime($post->post_date)), @@ -352,6 +352,21 @@ private static function getPost($post) return null; } + public static function stripTags($content) { + $removeBodyOfTags = [ + 'script', + 'style', + 'noscript' + ]; + + $content = preg_replace(sprintf( + '/<(%s)\b[^>]*>.*?<\/\1>/is', + implode('|', $removeBodyOfTags) + ), '', $content); + + return strip_tags($content); + } + public static function getTheExcerpt($post, int $numberOfWords = 55) { $excerpt = get_the_excerpt($post);