Ticket #10082: 10082.3.diff
File 10082.3.diff, 2.2 KB (added by , 16 years ago) |
---|
-
wp-includes/shortcodes.php
175 175 $tagnames = array_keys($shortcode_tags); 176 176 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 177 177 178 return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)'; 178 return '(\[?)' // possibly escape shortcode, part 1 179 . "\[($tagregexp)" // a valid shortcode, e.g. [foo 180 . '(?=[\s\]\/])' // Only match the shortcode if its followed by a space, a closing slash, or a closing bracket 181 . '(.*?)' // maybe attributes 182 . '(\/)?' // mark self-closing shortcode with a / 183 . '\]' 184 . '(' 185 . '?(4)' // stop if the shortcode is self-closing 186 . '|' 187 . '(?:' 188 . "((?:(?!\[(?:\\2)\b).)*?)" // look-ahead to make the shortcodes non-greedy 189 . '\[\/\2\]' // stop on [/foo] 190 . ')?' 191 . ')?' // allow for [foo] to be treated as [foo/] 192 . '(\]?)'; // possibly escape shortcode, part 2 179 193 } 180 194 181 195 /** … … 192 206 function do_shortcode_tag($m) { 193 207 global $shortcode_tags; 194 208 195 // allow [[foo]] syntax for escaping a tag 196 if ($m[1] == '[' && $m[6] == ']') { 197 return substr($m[0], 1, -1); 198 } 209 $return = array_shift($m); 210 $begin = array_shift($m); 211 $end = array_pop($m); 199 212 200 $tag = $m[2]; 201 $attr = shortcode_parse_atts($m[3]); 213 // allow [[foo]] and [[foo]bar[/foo]] syntax for escaping a tag 214 if ( $begin == '[' && $end == ']' ) 215 return substr($return, 1, -1); 202 216 203 if ( isset($m[5]) ) { 217 $tag = array_shift($m); 218 $attr = array_shift($m); 219 $content = array_pop($m); 220 221 $attr = shortcode_parse_atts($attr); 222 223 if ( $content ) { 204 224 // enclosing tag - extra parameter 205 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[5], $m[2]) . $m[6];225 $result = call_user_func($shortcode_tags[$tag], $attr, $content, $tag); 206 226 } else { 207 227 // self-closing tag 208 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[6];228 $result = call_user_func($shortcode_tags[$tag], $attr, NULL, $tag); 209 229 } 230 return do_shortcode($result); 210 231 } 211 232 212 233 /**