Skip to content

Instantly share code, notes, and snippets.

@paulchubatyy
Created December 1, 2010 12:10
Show Gist options
  • Save paulchubatyy/723403 to your computer and use it in GitHub Desktop.
Save paulchubatyy/723403 to your computer and use it in GitHub Desktop.
<?php
function do_shortcode($content) {
global $shortcode_tags;
if (empty($shortcode_tags) || !is_array($shortcode_tags))
return $content;
$pattern = get_shortcode_regex();
return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
}
<?php
function get_shortcode_regex() {
global $shortcode_tags;
$tagnames = array_keys($shortcode_tags);
$tagregexp = join( '|', array_map('preg_quote', $tagnames) );
// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment