Ticket #15600: 15600.2.diff
File 15600.2.diff, 5.1 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/sx", 'do_shortcode_tag', $content ); 152 152 } 153 153 154 154 /** … … 174 174 global $shortcode_tags; 175 175 $tagnames = array_keys($shortcode_tags); 176 176 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 177 178 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes() 179 return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)'; 177 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() 178 return " 179 \\[ # Opening bracket 180 (\\[?) # 1: Optional second opening bracket for escaping shortcodes: [[tag]] 181 ( $tagregexp ) # 2: Shortcode name 182 \\b # Word boundary 183 ( # 3: Unroll the loop: Inside the opening shortcode tag 184 [^\\]'\"]* # Not a closing bracket, single or double quote 185 (?: 186 (?:\"[^\"]*\"|'[^']*') # Anything in quotes 187 [^\\]'\"]* # Not a closing bracket, single or double quote 188 )* 189 ) 190 (\\/?) # 4: Self closing? 191 (?(4) # If self closing, then ... 192 \\] # ... Closing bracket 193 | # Else ... 194 (?: 195 (.+?) # 5: ... Anything between the opening and closing shortcode tags 196 \\[\\/\\2\\] # ... Closing shortcode tag 197 )? 198 ) 199 (.?) # 6: Trailing character 200 "; 180 201 } 181 202 182 203 /** … … 203 224 204 225 if ( isset( $m[5] ) ) { 205 226 // enclosing tag - extra parameter 206 return $m[1] .call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];227 return call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6]; 207 228 } else { 208 229 // self-closing tag 209 return $m[1] .call_user_func( $shortcode_tags[$tag], $attr, NULL, $tag ) . $m[6];230 return call_user_func( $shortcode_tags[$tag], $attr, NULL, $tag ) . $m[6]; 210 231 } 211 232 } 212 233 … … 290 311 291 312 $pattern = get_shortcode_regex(); 292 313 293 return preg_replace ('/'.$pattern.'/s', '$1$6', $content);314 return preg_replace_callback( "/$pattern/sx", 'strip_shortcode_tag', $content ); 294 315 } 295 316 317 function strip_shortcode_tag( $m ) { 318 // allow [[foo]] syntax for escaping a tag 319 if ( $m[1] == '[' && $m[6] == ']' ) { 320 return substr($m[0], 1, -1); 321 } 322 323 return $m[6]; 324 } 325 296 326 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() 297 327 298 ?> 299 No newline at end of file 328 ?> -
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 <p> # Opening paragraph 246 \\s*? # Optional leading whitespace 247 ( # 1: The shortcode 248 \\[ # Opening bracket 249 (?: $tagregexp ) # Shortcode name 250 \\b # Word boundary 251 (?: # Unroll the loop: Inside the opening shortcode tag 252 [^\\]'\"]* # Not a closing bracket, single or double quote 253 (?: 254 (?:\"[^\"]*\"|'[^']*') # Anything in quotes 255 [^\\]'\"]* # Not a closing bracket, single or double quote 256 )* 257 ) 258 (\\/?) # 2: Self closing? 259 (?(2) # If self closing, then ... 260 \\] # ... Closing bracket 261 | # Else ... 262 (?: 263 .+? # ... Anything between the opening and closing shortcode tags 264 \\[\\/\\2\\] # ... Closing shortcode tag 265 ) 266 )? 267 ) 268 \\s* # optional trailing whitespace 269 <\\/p> # closing paragraph 270 /sx"; 271 272 return preg_replace( $pattern, '$1', $pee ); 245 273 } 246 274 247 275 /**