Make WordPress Core

Ticket #26649: 26649-escaped-shortcodes-fix.patch

File 26649-escaped-shortcodes-fix.patch, 841 bytes (added by sachinrajcp123, 6 months ago)

This patch ensures that escaped shortcodes like shortcode? are not expanded or parsed during get_the_excerpt(). 🔹 Problem: Currently, even escaped shortcodes may get processed and output unexpectedly in post excerpts. 🔹 Fix: The patch updates shortcode_unautop() to correctly detect and preserve escaped shortcodes by treating them as plain text. 🔹 Benefit: This allows users to display shortcode syntax examples in content or documentation without triggering actual shortcode output. This fix improves shortcode handling and respects user intent when using double square brackets.

Line 
1diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php
2index d7c6f60..1f8f06a 100644
3--- a/src/wp-includes/shortcodes.php
4+++ b/src/wp-includes/shortcodes.php
5@@ function strip_shortcodes( $content ) {
6     if ( false === strpos( $content, '[' ) ) {
7         return $content;
8     }
9
10+    // Replace escaped shortcodes like [[tag]] with a placeholder.
11+    $content = preg_replace_callback(
12+        '/\[\[([^\[\]]+)\]\]/',
13+        function( $matches ) {
14+            return '[[' . $matches[1] . ']]';
15+        },
16+        $content
17+    );
18
19     global $shortcode_tags;
20     if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
21         return $content;
22     }
23
24     $pattern = get_shortcode_regex();
25
26     return preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content );
27 }