Created
May 10, 2016 13:08
-
-
Save nextend/05d839539f8abb5c1060ccc90a6f6f99 to your computer and use it in GitHub Desktop.
WordPress multiline shortcode with wpautop support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NextendMultiLineShortcode{ | |
static $multiline_shortcode_storage = array(); | |
static $multiline_shortcodes = array(); | |
public static function init(){ | |
add_filter('the_content', 'NextendMultiLineShortcode::do_multiline_shortcode', 9); // before wpautop() | |
add_shortcode('multiline_shortcode', 'NextendMultiLineShortcode::multiline_shortcode'); | |
} | |
public static function do_multiline_shortcode($content, $ignore_html = false) { | |
$pattern = get_shortcode_regex(self::$multiline_shortcodes); | |
return preg_replace_callback("/$pattern/", 'NextendMultiLineShortcode::replace_multiline_shortcode', $content); | |
} | |
public static function replace_multiline_shortcode($m) { | |
static $counter = 0; | |
$counter++; | |
self::$multiline_shortcode_storage[$counter] = $m[0]; | |
return '[multiline_shortcode id=' . $counter . ']'; | |
} | |
public static function multiline_shortcode($atts) { | |
return do_shortcode(self::$multiline_shortcode_storage[$atts['id']]); | |
} | |
} | |
NextendMultiLineShortcode::$multiline_shortcodes = array( | |
'pro', | |
'free', | |
'note', | |
'do', | |
'dont' | |
); | |
NextendMultiLineShortcode::init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: