Ticket #15600: 15600.5.diff
File 15600.5.diff, 6.3 KB (added by , 12 years ago) |
---|
-
wp-includes/shortcodes.php
148 148 return $content; 149 149 150 150 $pattern = get_shortcode_regex(); 151 return preg_replace_callback( '/'.$pattern.'/s', 'do_shortcode_tag', $content);151 return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 152 152 } 153 153 154 154 /** … … 159 159 * 160 160 * The regular expression contains 6 different sub matches to help with parsing. 161 161 * 162 * 1 /6 - An extra [ or ]to allow for escaping shortcodes with double [[]]162 * 1 - An extra [ to allow for escaping shortcodes with double [[]] 163 163 * 2 - The shortcode name 164 164 * 3 - The shortcode argument list 165 165 * 4 - The self closing / 166 166 * 5 - The content of a shortcode when it wraps some content. 167 * 6 - An extra ] to allow for escaping shortcodes with double [[]] 167 168 * 168 169 * @since 2.5 169 170 * @uses $shortcode_tags … … 175 176 $tagnames = array_keys($shortcode_tags); 176 177 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 177 178 178 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes() 179 return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)'; 179 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() 180 return 181 '\\[' // Opening bracket 182 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] 183 . "($tagregexp)" // 2: Shortcode name 184 . '\\b' // Word boundary 185 . '(' // 3: Unroll the loop: Inside the opening shortcode tag 186 . '[^\\]\'"\\/]*' // Not a closing bracket, single or double quote, or forward slash 187 . '(?:' 188 . '(?:' 189 . "'[^']*+'" // Anything in single quotes 190 . '|' 191 . '"[^"]*+"' // Anything in double quotes 192 . '|' 193 . '\\/(?!\\])' // A forward slash not followed by a closing bracket 194 . ')' 195 . '[^\\]\'"\\/]*' // Not a closing bracket, single or double quote, or forward slash 196 . ')*?' 197 . ')' 198 . '(?:' 199 . '(\\/)' // 4: Self closing tag ... 200 . '\\]' // ... and closing bracket 201 . '|' 202 . '\\]' // Closing bracket 203 . '(?:' 204 . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags 205 . '[^\\[]*+' // Not an opening bracket 206 . '(?:' 207 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag 208 . '[^\\[]*+' // Not an opening bracket 209 . ')*+' 210 . ')' 211 . '\\[\\/\\2\\]' // Closing shortcode tag 212 . ')?' 213 . ')' 214 . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] 180 215 } 181 216 182 217 /** … … 290 325 291 326 $pattern = get_shortcode_regex(); 292 327 293 return preg_replace ('/'.$pattern.'/s', '$1$6', $content);328 return preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 294 329 } 295 330 331 function strip_shortcode_tag( $m ) { 332 // allow [[foo]] syntax for escaping a tag 333 if ( $m[1] == '[' && $m[6] == ']' ) { 334 return substr($m[0], 1, -1); 335 } 336 337 return $m[1] . $m[6]; 338 } 339 296 340 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() 297 341 298 ?> 299 No newline at end of file 342 ?> -
wp-includes/formatting.php
232 232 * @param string $pee The content. 233 233 * @return string The filtered content. 234 234 */ 235 function shortcode_unautop( $pee) {235 function shortcode_unautop( $pee ) { 236 236 global $shortcode_tags; 237 237 238 if ( !empty($shortcode_tags) && is_array($shortcode_tags) ) { 239 $tagnames = array_keys($shortcode_tags); 240 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 241 $pee = preg_replace('/<p>\\s*?(\\[(' . $tagregexp . ')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?)\\s*<\\/p>/s', '$1', $pee); 238 if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) { 239 return $pee; 242 240 } 243 241 244 return $pee; 242 $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); 243 244 $pattern = 245 '/' 246 . '<p>' // Opening paragraph 247 . '\\s*+' // Optional leading whitespace 248 . '(' // 1: The shortcode 249 . '\\[' // Opening bracket 250 . "($tagregexp)" // 2: Shortcode name 251 . '\\b' // Word boundary 252 // Unroll the loop: Inside the opening shortcode tag 253 . '[^\\]\'"\\/]*' // Not a closing bracket, single or double quote, or forward slash 254 . '(?:' 255 . '(?:' 256 . "'[^']*+'" // Anything in single quotes 257 . '|' 258 . '"[^"]*+"' // Anything in double quotes 259 . '|' 260 . '\\/(?!\\])' // A forward slash not followed by a closing bracket 261 . ')' 262 . '[^\\]\'"\\/]*' // Not a closing bracket, single or double quote, or forward slash 263 . ')*?' 264 . '(?:' 265 . '\\/\\]' // Self closing tag and closing bracket 266 . '|' 267 . '\\]' // Closing bracket 268 . '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags 269 . '[^\\[]*+' // Not an opening bracket 270 . '(?:' 271 . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag 272 . '[^\\[]*+' // Not an opening bracket 273 . ')*+' 274 . '\\[\\/\\2\\]' // Closing shortcode tag 275 . ')?' 276 . ')' 277 . ')' 278 . '\\s*+' // optional trailing whitespace 279 . '<\\/p>' // closing paragraph 280 . '/s'; 281 282 return preg_replace( $pattern, '$1', $pee ); 245 283 } 246 284 247 285 /**