Guest User

Untitled

a guest
Jun 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /**
  2. * Search content for shortcodes and filter shortcodes through their hooks.
  3. *
  4. * If there are no shortcode tags defined, then the content will be returned
  5. * without any filtering. This might cause issues when plugins are disabled but
  6. * the shortcode will still show up in the post or content.
  7. *
  8. * @since 2.5
  9. * @uses $shortcode_tags
  10. * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.
  11. *
  12. * @param string $content Content to search for shortcodes
  13. * @return string Content with shortcodes filtered out.
  14. */
  15. function do_shortcode($content) {
  16. global $shortcode_tags;
  17.  
  18. if (empty($shortcode_tags) || !is_array($shortcode_tags))
  19. return $content;
  20.  
  21. $pattern = get_shortcode_regex();
  22. return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
  23. }
  24.  
  25. /**
  26. * Retrieve the shortcode regular expression for searching.
  27. *
  28. * The regular expression combines the shortcode tags in the regular expression
  29. * in a regex class.
  30. *
  31. * @since 2.5
  32. * @uses $shortcode_tags
  33. *
  34. * @return string The shortcode search regular expression
  35. */
  36. function get_shortcode_regex() {
  37. global $shortcode_tags;
  38. $tagnames = array_keys($shortcode_tags);
  39. $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
  40.  
  41. return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?';
  42. }
Add Comment
Please, Sign In to add comment