Ticket #12760: shortcodes.2.diff
File shortcodes.2.diff, 2.5 KB (added by , 14 years ago) |
---|
-
wp-includes/shortcodes.php
133 133 * If there are no shortcode tags defined, then the content will be returned 134 134 * without any filtering. This might cause issues when plugins are disabled but 135 135 * the shortcode will still show up in the post or content. 136 * @see get_shortcode_regex for details of the pattern. 136 137 * 137 138 * @since 2.5 138 139 * @uses $shortcode_tags 139 * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.140 140 * 141 141 * @param string $content Content to search for shortcodes 142 142 * @return string Content with shortcodes filtered out. … … 147 147 if (empty($shortcode_tags) || !is_array($shortcode_tags)) 148 148 return $content; 149 149 150 $pattern = get_shortcode_regex();151 return preg_replace_callback('/'.$pattern.'/s', ' do_shortcode_tag', $content);150 $pattern = '(.?)\[(\w+?)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)'; 151 return preg_replace_callback('/'.$pattern.'/s', 'escape_shortcode', $content); 152 152 } 153 153 154 154 /** 155 * Escapes shortcodes. 156 * 157 * Because of the way 'embed' is implemented, shortcodes are escaped only during 158 * the second pass when all shortcodes are added to the shortcode_tags array. 159 * 160 * If a shortcode is not active its hook is not called. 161 * @see get_shortcode_regex for details of the match array contents. 162 * 163 * @since 3.1 164 * @uses $shortcode_tags 165 * 166 * @param array $m Regular expression match array. 167 * @return string The shortcode either escaped, unchanged or modified by its hook. 168 */ 169 function escape_shortcode($m){ 170 global $shortcode_tags; 171 172 if( '[' == $m[1] && ']' == $m[6] ){ 173 //HACK! If this is the first pass of the do_shortcode() does not escape. 174 if( ! empty( $shortcode_tags['gallery'] ) ) 175 return substr( $m[0], 1, -1 ); 176 else 177 return $m[0]; 178 } 179 180 if( ! empty( $shortcode_tags[$m[2]] ) ) 181 return do_shortcode_tag($m); 182 else 183 return $m[0]; 184 } 185 186 /** 155 187 * Retrieve the shortcode regular expression for searching. 156 188 * 157 189 * The regular expression combines the shortcode tags in the regular expression … … 193 225 function do_shortcode_tag( $m ) { 194 226 global $shortcode_tags; 195 227 196 // allow [[foo]] syntax for escaping a tag197 if ( $m[1] == '[' && $m[6] == ']' ) {198 return substr($m[0], 1, -1);199 }200 201 228 $tag = $m[2]; 202 229 $attr = shortcode_parse_atts( $m[3] ); 203 230 … … 295 322 296 323 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() 297 324 298 ?> 299 No newline at end of file 325 ?>