Skip to content

Instantly share code, notes, and snippets.

@willybahuaud
Last active August 26, 2016 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willybahuaud/8347f617b2cef30acec81cbf1ebd59e9 to your computer and use it in GitHub Desktop.
Save willybahuaud/8347f617b2cef30acec81cbf1ebd59e9 to your computer and use it in GitHub Desktop.
<?php
/**
* Whiteliste shortcode
*/
add_filter( 'bbp_get_reply_content', 'strip_shortcodes_whitelist', 9 );
add_filter( 'bbp_get_topic_content', 'strip_shortcodes_whitelist', 9 );
function strip_shortcodes_whitelist( $content ) {
global $shortcode_tags;
if ( false === strpos( $content, '[' ) ) {
return $content;
}
if (empty($shortcode_tags) || !is_array($shortcode_tags))
return $content;
// AJOUT WILLY
$whitelist = array(
'pastacode',
);
$shortcode_to_remove = array_diff( array_keys( $shortcode_tags ), $whitelist );
// END
// Find all registered tag names in $content.
preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
$tagnames = array_intersect( $shortcode_to_remove, $matches[1] );
if ( empty( $tagnames ) ) {
return $content;
}
$content = do_shortcodes_in_html_tags( $content, true, $tagnames );
$pattern = get_shortcode_regex( $tagnames );
$content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content );
// Always restore square braces so we don't break things like <!--[if IE ]>
$content = unescape_invalid_shortcodes( $content );
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment