Ticket #10702: 10702.diff
File 10702.diff, 3.2 KB (added by , 12 years ago) |
---|
-
wp-includes/shortcodes.php
147 147 if (empty($shortcode_tags) || !is_array($shortcode_tags)) 148 148 return $content; 149 149 150 if ( ! strstr( $content, '[' ) ) 151 return $content; 152 150 153 $pattern = get_shortcode_regex(); 151 return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 154 $count = 1; 155 while ( $count ) 156 $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content, -1, $count ); 157 158 // Restore [[shortcode]] notation 159 $content = str_replace( array( '%escaped_shortcode_tag%', '%/escaped_shortcode_tag%' ), array( '[', ']' ), $content ); 160 return $content; 152 161 } 153 162 154 163 /** … … 178 187 179 188 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() 180 189 // Also, see shortcode_unautop() and shortcode.js. 181 return190 $pattern = 182 191 '\\[' // Opening bracket 183 192 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] 184 193 . "($tagregexp)" // 2: Shortcode name … … 193 202 . '(?:' 194 203 . '(\\/)' // 4: Self closing tag ... 195 204 . '\\]' // ... and closing bracket 205 196 206 . '|' 197 207 . '\\]' // Closing bracket 208 209 . '(?=' // Positive lookahead, match the tag only if followed by... 210 . '[^\\[]*' // A non-opening bracket 211 . '\\[\\/\\2\\]' // Followed by the tag's closing tag 212 . ')' 213 198 214 . '(?:' 199 215 . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags 200 216 . '[^\\[]*+' // Not an opening bracket … … 204 220 . ')*+' 205 221 . ')' 206 222 . '\\[\\/\\2\\]' // Closing shortcode tag 207 . ')?' 223 . ')' 224 225 . '|' 226 . '\\]' // Closing bracket 227 . '(?!.*\\[\\/\\2\\])' // Closing shortcode tag 228 208 229 . ')' 209 230 . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] 231 232 return $pattern; 210 233 } 211 234 212 235 /** … … 225 248 226 249 // allow [[foo]] syntax for escaping a tag 227 250 if ( $m[1] == '[' && $m[6] == ']' ) { 228 return substr($m[0], 1, -1);251 return '%escaped_shortcode_tag%' . substr( $m[0], 2, -2 ) . '%/escaped_shortcode_tag%'; 229 252 } 230 253 231 254 $tag = $m[2]; … … 320 343 321 344 $pattern = get_shortcode_regex(); 322 345 323 return preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 346 $count = 1; 347 while ( $count ) 348 $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content, -1, $count ); 349 350 $content = str_replace( array( '%escaped_shortcode_tag%', '%/escaped_shortcode_tag%' ), array( '[', ']' ), $content ); 351 return $content; 324 352 } 325 353 326 354 function strip_shortcode_tag( $m ) { 327 355 // allow [[foo]] syntax for escaping a tag 328 356 if ( $m[1] == '[' && $m[6] == ']' ) { 329 return substr($m[0], 1, -1);357 return '%escaped_shortcode_tag%' . substr( $m[0], 2, -2 ) . '%/escaped_shortcode_tag%'; 330 358 } 331 359 332 360 return $m[1] . $m[6];