From 54f218ae1881084eea0d73479a9c600bac4fd140 Mon Sep 17 00:00:00 2001 From: isabel_brison Date: Mon, 17 Jul 2023 01:47:26 +0000 Subject: [PATCH] Editor: trim footnote anchors from post excerpts. Adds the `excerpt_remove_footnotes` function to trim footnote anchors from post excerpts. Props: ramonopoly, costdev, mukesh27, mcsf, azaozz. Fixes #58805. Built from https://develop.svn.wordpress.org/trunk@56244 git-svn-id: http://core.svn.wordpress.org/trunk@55756 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 21 +++++++++++++++++++++ wp-includes/formatting.php | 3 +++ wp-includes/version.php | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index fd287370de..347839f09a 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -1009,6 +1009,27 @@ function excerpt_remove_blocks( $content ) { return $output; } +/** + * Parses footnotes markup out of a content string, + * and renders those appropriate for the excerpt. + * + * @since 6.3.0 + * + * @param string $content The content to parse. + * @return string The parsed and filtered content. + */ +function excerpt_remove_footnotes( $content ) { + if ( ! str_contains( $content, 'data-fn=' ) ) { + return $content; + } + + return preg_replace( + '_\s*\d+\s*_', + '', + $content + ); +} + /** * Renders inner blocks from the allowed wrapper blocks * for generating an excerpt. diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index a3e35599c0..9ce636edd5 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -3952,6 +3952,7 @@ function human_time_diff( $from, $to = 0 ) { * * @since 1.5.0 * @since 5.2.0 Added the `$post` parameter. + * @since 6.3.0 Removes footnotes markup from the excerpt content. * * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated. * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default null. @@ -3966,6 +3967,7 @@ function wp_trim_excerpt( $text = '', $post = null ) { $text = strip_shortcodes( $text ); $text = excerpt_remove_blocks( $text ); + $text = excerpt_remove_footnotes( $text ); /* * Temporarily unhook wp_filter_content_tags() since any tags @@ -4008,6 +4010,7 @@ function wp_trim_excerpt( $text = '', $post = null ) { */ $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' ); $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); + } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 42caa0b092..3adfdddbfd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-beta4-56243'; +$wp_version = '6.3-beta4-56244'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.