Ticket #6444: 6444.002.diff
| File 6444.002.diff, 4.1 KB (added by , 18 years ago) |
|---|
-
trunk/wp-includes/shortcodes.php
47 47 48 48 $shortcode_tags = array(); 49 49 50 function add_shortcode($tag, $func ) {50 function add_shortcode($tag, $func, $post_formatting = false) { 51 51 global $shortcode_tags; 52 52 53 if ( is_callable($func) ) 54 $shortcode_tags[$tag] = $func; 53 if ( is_callable($func) ) { 54 $shortcode_tags[($post_formatting)? 11:9][$tag] = $func; 55 } 55 56 } 56 57 57 58 function remove_shortcode($tag) { 58 59 global $shortcode_tags; 59 60 60 unset($shortcode_tags[ $tag]);61 unset($shortcode_tags[9][$tag], $shortcode_tags[11][$tag]); 61 62 } 62 63 63 64 function remove_all_shortcodes() { … … 66 67 $shortcode_tags = array(); 67 68 } 68 69 69 function do_shortcode($content) { 70 function do_shortcode_post_formatting($content) { 71 return do_shortcode($content, true); 72 } 73 function do_shortcode($content, $post_formatting = false) { 74 $pattern = get_shortcode_regex($post_formatting); 75 if (!$pattern) { 76 return $content; 77 } else { 78 $callback_func = 'do_shortcode_tag'; 79 if ($post_formatting) 80 $callback_func .= '_post_formatting'; 81 82 return preg_replace_callback('/' . $pattern . '/s', $callback_func, $content); 83 } 84 } 85 function get_shortcode_regex($post_formatting) { 70 86 global $shortcode_tags; 71 87 72 if (empty($shortcode_tags ) || !is_array($shortcode_tags))73 return $content;88 if (empty($shortcode_tags[($post_formatting)? 11:9]) || !is_array($shortcode_tags[($post_formatting)? 11:9])) 89 return false; 74 90 75 $tagnames = array_keys($shortcode_tags );91 $tagnames = array_keys($shortcode_tags[($post_formatting)? 11:9]); 76 92 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 77 93 78 $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s'; 94 return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?'; 95 } 79 96 80 return preg_replace_callback($pattern, 'do_shortcode_tag', $content); 97 function do_shortcode_tag_post_formatting($m) { 98 return do_shortcode_tag($m, true); 81 99 } 82 83 function do_shortcode_tag($m) { 100 function do_shortcode_tag($m, $post_formatting = false) { 84 101 global $shortcode_tags; 85 102 86 103 $tag = $m[1]; … … 88 105 89 106 if ( isset($m[4]) ) { 90 107 // enclosing tag - extra parameter 91 return call_user_func($shortcode_tags[ $tag], $attr, $m[4]);108 return call_user_func($shortcode_tags[($post_formatting)? 11:9][$tag], $attr, $m[4]); 92 109 } else { 93 110 // self-closing tag 94 return call_user_func($shortcode_tags[ $tag], $attr);111 return call_user_func($shortcode_tags[($post_formatting)? 11:9][$tag], $attr); 95 112 } 96 113 } 97 114 … … 129 146 return $out; 130 147 } 131 148 132 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() 149 add_filter( 'the_content', 'do_shortcode', 9 ); 150 add_filter( 'the_content', 'do_shortcode_post_formatting', 11 ); 133 151 134 152 ?> -
trunk/wp-includes/formatting.php
26 26 for ( $i = 0; $i < $stop; $i++ ) { 27 27 $curl = $textarr[$i]; 28 28 29 if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag 29 if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag or shortcode 30 30 // static strings 31 31 $curl = str_replace($static_characters, $static_replacements, $curl); 32 32 // regular expressions … … 74 74 $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates 75 75 $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end 76 76 $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 77 $pee = preg_replace('/<p>(\s*?' . get_shortcode_regex(true) . '\s*)<\/p>/s', '$1', $pee); // don't auto-p wrap post-formatting shortcodes 77 78 $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); 78 79 $pee = preg_replace( '|<p>|', "$1<p>", $pee ); 79 80 $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag