WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/24/2008 10:31:37 PM (14 years ago)
Author:
ryan
Message:

Revert [770] for 2.5 pending further discussion. see #6444

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/wp-includes/shortcodes.php

    r7768 r7811  
    4848$shortcode_tags = array();
    4949
    50 function add_shortcode($tag, $func, $after_formatting = false) {
     50function add_shortcode($tag, $func) {
    5151    global $shortcode_tags;
    5252
    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;
    5655}
    5756
     
    5958    global $shortcode_tags;
    6059
    61     unset($shortcode_tags[9][$tag], $shortcode_tags[11][$tag]);
     60    unset($shortcode_tags[$tag]);
    6261}
    6362
     
    6867}
    6968
    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) {
     69function do_shortcode($content) {
    8670    global $shortcode_tags;
    8771
    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;
    9074
    91     $tagnames = array_keys($shortcode_tags[($after_formatting)? 11:9]);
     75    $tagnames = array_keys($shortcode_tags);
    9276    $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    9377
    94     return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?';
     78    $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s';
     79
     80    return preg_replace_callback($pattern, 'do_shortcode_tag', $content);
    9581}
    9682
    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) {
     83function do_shortcode_tag($m) {
    10184    global $shortcode_tags;
    10285
     
    10689    if ( isset($m[4]) ) {
    10790        // 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]);
    10992    } else {
    11093        // 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);
    11295    }
    11396}
     
    148131}
    149132
    150 add_filter( 'the_content', 'do_shortcode', 9 );
    151 add_filter( 'the_content', 'do_shortcode_after_formatting', 11 );
     133add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
    152134
    153135?>
Note: See TracChangeset for help on using the changeset viewer.