You are here

function _shortcode_process_tag in Shortcode 7

Same name and namespace in other branches
  1. 6 shortcode.module \_shortcode_process_tag()
  2. 7.2 shortcode.module \_shortcode_process_tag()

Regular Expression callable for do_shortcode() for calling shortcode hook.

@since 2.5 @access private @uses $shortcode_tags

Parameters

array $m Regular expression match array:

Return value

mixed False on failure.

See also

get_shortcode_regex for details of the match array contents.

1 call to _shortcode_process_tag()
_shortcode_process in ./shortcode.module
Process the shortcodes according to the text and the text format.

File

./shortcode.module, line 416

Code

function _shortcode_process_tag($m) {
  $shortcodes = _shortcode_tags();

  // allow [[foo]] syntax for escaping a tag
  if ($m[1] == '[' && $m[5] == ']') {
    return substr($m[0], 1, -1);
  }
  $tag = $m[2];
  if ($shortcodes[$tag]->enabled) {

    //dpr('_shortcode_process_tag: ' . $tag);

    // tag exists (enabled)
    $attr = _shortcode_parse_attrs($m[3]);

    //dpr($attr);

    /*
     * 0 - the full tag text?
     * 1/5 - An extra [ or ] to allow for escaping shortcodes with double [[]]
     * 2 - The shortcode name
     * 3 - The shortcode argument list
     * 4 - The content of a shortcode when it wraps some content.
     * */
    if (!is_null($m[4])) {

      //dpr('fv: ' . $shortcodes[$tag]->function);

      // enclosing tag - extra parameter
      return $m[1] . call_user_func($shortcodes[$tag]->function, $attr, $m[4], $m[2]) . $m[5];
    }
    else {

      // self-closing tag

      //dpr('fv self closing: ' . $shortcodes[$tag]->function);
      return $m[1] . call_user_func($shortcodes[$tag]->function, $attr, NULL, $m[2]) . $m[5];
    }
  }
  elseif (is_null($m[4])) {
    return $m[4];
  }
  return '';
}