| 1 | Index: wp-includes/shortcodes.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/shortcodes.php (revision 17831) |
|---|
| 4 | +++ wp-includes/shortcodes.php (working copy) |
|---|
| 5 | @@ -148,7 +148,7 @@ |
|---|
| 6 | return $content; |
|---|
| 7 | |
|---|
| 8 | $pattern = get_shortcode_regex(); |
|---|
| 9 | - return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content); |
|---|
| 10 | + return preg_replace_callback( "/$pattern/sx", 'do_shortcode_tag', $content ); |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | @@ -175,8 +175,42 @@ |
|---|
| 15 | $tagnames = array_keys($shortcode_tags); |
|---|
| 16 | $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); |
|---|
| 17 | |
|---|
| 18 | - // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes() |
|---|
| 19 | - return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)'; |
|---|
| 20 | + // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() |
|---|
| 21 | + return " |
|---|
| 22 | + \\[ # Opening bracket |
|---|
| 23 | + (\\[?) # 1: Optional second opening bracket for escaping shortcodes: [[tag]] |
|---|
| 24 | + ( $tagregexp ) # 2: Shortcode name |
|---|
| 25 | + \\b # Word boundary |
|---|
| 26 | + ( # 3: Unroll the loop: Inside the opening shortcode tag |
|---|
| 27 | + [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash |
|---|
| 28 | + (?: |
|---|
| 29 | + (?: |
|---|
| 30 | + '[^']*+' # Anything in single quotes |
|---|
| 31 | + | |
|---|
| 32 | + \"[^\"]*+\" # Anything in double quotes |
|---|
| 33 | + | |
|---|
| 34 | + \\/(?!\\]) # A forward slash not followed by a closing bracket |
|---|
| 35 | + ) |
|---|
| 36 | + [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash |
|---|
| 37 | + )*? |
|---|
| 38 | + ) |
|---|
| 39 | + (?: |
|---|
| 40 | + \\/\\] # Self closing tag and closing bracket |
|---|
| 41 | + | |
|---|
| 42 | + \\] # Closing bracket |
|---|
| 43 | + (?: |
|---|
| 44 | + ( # 4: Unroll the loop: Optionally, anything between the opening and closing shortcode tags |
|---|
| 45 | + [^\\[]*+ # Not an opening bracket |
|---|
| 46 | + (?: |
|---|
| 47 | + \\[(?!\\/\\2\\]) # An opening bracket not followed by the closing shortcode tag |
|---|
| 48 | + [^\\[]*+ # Not an opening bracket |
|---|
| 49 | + )*+ |
|---|
| 50 | + ) |
|---|
| 51 | + \\[\\/\\2\\] # Closing shortcode tag |
|---|
| 52 | + )? |
|---|
| 53 | + ) |
|---|
| 54 | + (\\]?) # 5: Optional second closing brocket for escaping shortcodes: [[tag]] |
|---|
| 55 | + "; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | @@ -194,19 +228,19 @@ |
|---|
| 60 | global $shortcode_tags; |
|---|
| 61 | |
|---|
| 62 | // allow [[foo]] syntax for escaping a tag |
|---|
| 63 | - if ( $m[1] == '[' && $m[6] == ']' ) { |
|---|
| 64 | + if ( $m[1] == '[' && $m[5] == ']' ) { |
|---|
| 65 | return substr($m[0], 1, -1); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | $tag = $m[2]; |
|---|
| 69 | $attr = shortcode_parse_atts( $m[3] ); |
|---|
| 70 | |
|---|
| 71 | - if ( isset( $m[5] ) ) { |
|---|
| 72 | + if ( isset( $m[4] ) ) { |
|---|
| 73 | // enclosing tag - extra parameter |
|---|
| 74 | - return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6]; |
|---|
| 75 | + return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[4], $tag ) . $m[5]; |
|---|
| 76 | } else { |
|---|
| 77 | // self-closing tag |
|---|
| 78 | - return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL, $tag ) . $m[6]; |
|---|
| 79 | + return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL, $tag ) . $m[5]; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | @@ -290,9 +324,18 @@ |
|---|
| 84 | |
|---|
| 85 | $pattern = get_shortcode_regex(); |
|---|
| 86 | |
|---|
| 87 | - return preg_replace('/'.$pattern.'/s', '$1$6', $content); |
|---|
| 88 | + return preg_replace_callback( "/$pattern/sx", 'strip_shortcode_tag', $content ); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | +function strip_shortcode_tag( $m ) { |
|---|
| 92 | + // allow [[foo]] syntax for escaping a tag |
|---|
| 93 | + if ( $m[1] == '[' && $m[5] == ']' ) { |
|---|
| 94 | + return substr($m[0], 1, -1); |
|---|
| 95 | + } |
|---|
| 96 | + |
|---|
| 97 | + return $m[1] . $m[5]; |
|---|
| 98 | +} |
|---|
| 99 | + |
|---|
| 100 | add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() |
|---|
| 101 | |
|---|
| 102 | -?> |
|---|
| 103 | \ No newline at end of file |
|---|
| 104 | +?> |
|---|
| 105 | Index: wp-includes/formatting.php |
|---|
| 106 | =================================================================== |
|---|
| 107 | --- wp-includes/formatting.php (revision 17831) |
|---|
| 108 | +++ wp-includes/formatting.php (working copy) |
|---|
| 109 | @@ -232,16 +232,53 @@ |
|---|
| 110 | * @param string $pee The content. |
|---|
| 111 | * @return string The filtered content. |
|---|
| 112 | */ |
|---|
| 113 | -function shortcode_unautop($pee) { |
|---|
| 114 | +function shortcode_unautop( $pee ) { |
|---|
| 115 | global $shortcode_tags; |
|---|
| 116 | |
|---|
| 117 | - if ( !empty($shortcode_tags) && is_array($shortcode_tags) ) { |
|---|
| 118 | - $tagnames = array_keys($shortcode_tags); |
|---|
| 119 | - $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); |
|---|
| 120 | - $pee = preg_replace('/<p>\\s*?(\\[(' . $tagregexp . ')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?)\\s*<\\/p>/s', '$1', $pee); |
|---|
| 121 | + if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) { |
|---|
| 122 | + return $pee; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | - return $pee; |
|---|
| 126 | + $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); |
|---|
| 127 | + |
|---|
| 128 | + $pattern = "/ |
|---|
| 129 | + <p> # Opening paragraph |
|---|
| 130 | + \\s*+ # Optional leading whitespace |
|---|
| 131 | + ( # 1: The shortcode |
|---|
| 132 | + \\[ # Opening bracket |
|---|
| 133 | + ( $tagregexp ) # 2: Shortcode name |
|---|
| 134 | + \\b # Word boundary |
|---|
| 135 | + # Unroll the loop: Inside the opening shortcode tag |
|---|
| 136 | + [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash |
|---|
| 137 | + (?: |
|---|
| 138 | + (?: |
|---|
| 139 | + '[^']*+' # Anything in single quotes |
|---|
| 140 | + | |
|---|
| 141 | + \"[^\"]*+\" # Anything in double quotes |
|---|
| 142 | + | |
|---|
| 143 | + \\/(?!\\]) # A forward slash not followed by a closing bracket |
|---|
| 144 | + ) |
|---|
| 145 | + [^\\]'\"\\/]* # Not a closing bracket, single or double quote, or forward slash |
|---|
| 146 | + )*? |
|---|
| 147 | + (?: |
|---|
| 148 | + \\/\\] # Self closing tag and closing bracket |
|---|
| 149 | + | |
|---|
| 150 | + \\] # Closing bracket |
|---|
| 151 | + (?: # Unroll the loop: Optionally, anything between the opening and closing shortcode tags |
|---|
| 152 | + [^\\[]*+ # Not an opening bracket |
|---|
| 153 | + (?: |
|---|
| 154 | + \\[(?!\\/\\2\\]) # An opening bracket not followed by the closing shortcode tag |
|---|
| 155 | + [^\\[]*+ # Not an opening bracket |
|---|
| 156 | + )*+ |
|---|
| 157 | + \\[\\/\\2\\] # Closing shortcode tag |
|---|
| 158 | + )? |
|---|
| 159 | + ) |
|---|
| 160 | + ) |
|---|
| 161 | + \\s*+ # optional trailing whitespace |
|---|
| 162 | + <\\/p> # closing paragraph |
|---|
| 163 | + /sx"; |
|---|
| 164 | + |
|---|
| 165 | + return preg_replace( $pattern, '$1', $pee ); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | /** |
|---|