Ticket #15600: 15600.3.diff
File 15600.3.diff, 6.2 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 /** … … 175 175 $tagnames = array_keys($shortcode_tags); 176 176 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 177 177 178 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes() 179 return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)'; 178 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() 179 return " 180 \\[ # Opening bracket 181 (\\[?) # 1: Optional second opening bracket for escaping shortcodes: [[tag]] 182 ( $tagregexp ) # 2: Shortcode name 183 \\b # Word boundary 184 ( # 3: Unroll the loop: Inside the opening shortcode tag 185 [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash 186 (?: 187 (?: 188 '[^']*+' # Anything in single quotes 189 | 190 \"[^\"]*+\" # Anything in double quotes 191 | 192 \\/(?!\\]) # A forward slash not followed by a closing bracket 193 ) 194 [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash 195 )*? 196 ) 197 (?: 198 \\/\\] # Self closing tag and closing bracket 199 | 200 \\] # Closing bracket 201 (?: 202 ( # 4: Unroll the loop: Optionally, anything between the opening and closing shortcode tags 203 [^\\[]*+ # Not an opening bracket 204 (?: 205 \\[(?!\\/\\2\\]) # An opening bracket not followed by the closing shortcode tag 206 [^\\[]*+ # Not an opening bracket 207 )*+ 208 ) 209 \\[\\/\\2\\] # Closing shortcode tag 210 )? 211 ) 212 (\\]?) # 5: Optional second closing brocket for escaping shortcodes: [[tag]] 213 "; 180 214 } 181 215 182 216 /** … … 194 228 global $shortcode_tags; 195 229 196 230 // allow [[foo]] syntax for escaping a tag 197 if ( $m[1] == '[' && $m[ 6] == ']' ) {231 if ( $m[1] == '[' && $m[5] == ']' ) { 198 232 return substr($m[0], 1, -1); 199 233 } 200 234 201 235 $tag = $m[2]; 202 236 $attr = shortcode_parse_atts( $m[3] ); 203 237 204 if ( isset( $m[ 5] ) ) {238 if ( isset( $m[4] ) ) { 205 239 // enclosing tag - extra parameter 206 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[ 5], $tag ) . $m[6];240 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[4], $tag ) . $m[5]; 207 241 } else { 208 242 // self-closing tag 209 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL, $tag ) . $m[ 6];243 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL, $tag ) . $m[5]; 210 244 } 211 245 } 212 246 … … 290 324 291 325 $pattern = get_shortcode_regex(); 292 326 293 return preg_replace ('/'.$pattern.'/s', '$1$6', $content);327 return preg_replace_callback( "/$pattern/sx", 'strip_shortcode_tag', $content ); 294 328 } 295 329 330 function strip_shortcode_tag( $m ) { 331 // allow [[foo]] syntax for escaping a tag 332 if ( $m[1] == '[' && $m[5] == ']' ) { 333 return substr($m[0], 1, -1); 334 } 335 336 return $m[1] . $m[5]; 337 } 338 296 339 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() 297 340 298 ?> 299 No newline at end of file 341 ?> -
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 ) # 2: Shortcode name 250 \\b # Word boundary 251 # Unroll the loop: Inside the opening shortcode tag 252 [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash 253 (?: 254 (?: 255 '[^']*+' # Anything in single quotes 256 | 257 \"[^\"]*+\" # Anything in double quotes 258 | 259 \\/(?!\\]) # A forward slash not followed by a closing bracket 260 ) 261 [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash 262 )*? 263 (?: 264 \\/\\] # Self closing tag and closing bracket 265 | 266 \\] # Closing bracket 267 (?: # Unroll the loop: Optionally, anything between the opening and closing shortcode tags 268 [^\\[]*+ # Not an opening bracket 269 (?: 270 \\[(?!\\/\\2\\]) # An opening bracket not followed by the closing shortcode tag 271 [^\\[]*+ # Not an opening bracket 272 )*+ 273 \\[\\/\\2\\] # Closing shortcode tag 274 )? 275 ) 276 ) 277 \\s*+ # optional trailing whitespace 278 <\\/p> # closing paragraph 279 /sx"; 280 281 return preg_replace( $pattern, '$1', $pee ); 245 282 } 246 283 247 284 /**