Changeset 7811 for branches/2.5/wp-includes/shortcodes.php
- Timestamp:
- 04/24/2008 10:31:37 PM (18 years ago)
- File:
-
- 1 edited
-
branches/2.5/wp-includes/shortcodes.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.5/wp-includes/shortcodes.php
r7768 r7811 48 48 $shortcode_tags = array(); 49 49 50 function add_shortcode($tag, $func , $after_formatting = false) {50 function add_shortcode($tag, $func) { 51 51 global $shortcode_tags; 52 52 53 if ( is_callable($func) ) { 54 $shortcode_tags[($after_formatting)? 11:9][$tag] = $func; 55 } 53 if ( is_callable($func) ) 54 $shortcode_tags[$tag] = $func; 56 55 } 57 56 … … 59 58 global $shortcode_tags; 60 59 61 unset($shortcode_tags[ 9][$tag], $shortcode_tags[11][$tag]);60 unset($shortcode_tags[$tag]); 62 61 } 63 62 … … 68 67 } 69 68 70 function do_shortcode_after_formatting($content) { 71 return do_shortcode($content, true); 72 } 73 function do_shortcode($content, $after_formatting = false) { 74 $pattern = get_shortcode_regex($after_formatting); 75 if (!$pattern) { 76 return $content; 77 } else { 78 $callback_func = 'do_shortcode_tag'; 79 if ($after_formatting) 80 $callback_func .= '_after_formatting'; 81 82 return preg_replace_callback('/' . $pattern . '/s', $callback_func, $content); 83 } 84 } 85 function get_shortcode_regex($after_formatting) { 69 function do_shortcode($content) { 86 70 global $shortcode_tags; 87 71 88 if (empty($shortcode_tags [($after_formatting)? 11:9]) || !is_array($shortcode_tags[($after_formatting)? 11:9]))89 return false;72 if (empty($shortcode_tags) || !is_array($shortcode_tags)) 73 return $content; 90 74 91 $tagnames = array_keys($shortcode_tags [($after_formatting)? 11:9]);75 $tagnames = array_keys($shortcode_tags); 92 76 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 93 77 94 return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?'; 78 $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s'; 79 80 return preg_replace_callback($pattern, 'do_shortcode_tag', $content); 95 81 } 96 82 97 function do_shortcode_tag_after_formatting($m) { 98 return do_shortcode_tag($m, true); 99 } 100 function do_shortcode_tag($m, $after_formatting = false) { 83 function do_shortcode_tag($m) { 101 84 global $shortcode_tags; 102 85 … … 106 89 if ( isset($m[4]) ) { 107 90 // enclosing tag - extra parameter 108 return call_user_func($shortcode_tags[ ($after_formatting)? 11:9][$tag], $attr, $m[4]);91 return call_user_func($shortcode_tags[$tag], $attr, $m[4]); 109 92 } else { 110 93 // self-closing tag 111 return call_user_func($shortcode_tags[ ($after_formatting)? 11:9][$tag], $attr);94 return call_user_func($shortcode_tags[$tag], $attr); 112 95 } 113 96 } … … 148 131 } 149 132 150 add_filter( 'the_content', 'do_shortcode', 9 ); 151 add_filter( 'the_content', 'do_shortcode_after_formatting', 11 ); 133 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() 152 134 153 135 ?>
Note: See TracChangeset
for help on using the changeset viewer.