Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We need the <pre> tag to make code-in-backticks work
- function bporg_forums_allowed_tags( $component_allowedtags ) {
- $component_allowedtags['pre'] = array();
- return $component_allowedtags;
- }
- add_filter( 'bp_forums_allowed_tags', 'bporg_forums_allowed_tags' );
- add_filter( 'bp_activity_allowed_tags', 'bporg_forums_allowed_tags' );
- // Borrowed from bbPress
- function bporg_encodeit( $matches ) {
- $text = trim($matches[2]);
- $text = htmlspecialchars($text, ENT_QUOTES);
- $text = str_replace(array("\r\n", "\r"), "\n", $text);
- $text = preg_replace("|\n\n\n+|", "\n\n", $text);
- $text = str_replace('&amp;', '&', $text);
- $text = str_replace('&lt;', '<', $text);
- $text = str_replace('&gt;', '>', $text);
- $text = "<code>$text</code>";
- if ( "`" != $matches[1] )
- $text = "<pre>$text</pre>";
- return $text;
- }
- // Borrowed from bbPress
- function bporg_decodeit( $matches ) {
- $text = $matches[2];
- $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES));
- $text = strtr($text, $trans_table);
- $text = str_replace('<br />', '<coded_br />', $text);
- $text = str_replace('<p>', '<coded_p>', $text);
- $text = str_replace('</p>', '</coded_p>', $text);
- $text = str_replace(array('&','&'), '&', $text);
- $text = str_replace(''', "'", $text);
- if ( '<pre><code>' == $matches[1] )
- $text = "\n$text\n";
- return "`$text`";
- }
- // Borrowed from bbPress. Makes code in backticks work, both in forum posts and in activity updates.
- function bporg_code_trick( $text ) {
- $text = str_replace(array("\r\n", "\r"), "\n", $text);
- $text = preg_replace_callback("|(`)(.*?)`|", 'bporg_encodeit', $text);
- $text = preg_replace_callback("!(^|\n)`(.*?)`!s", 'bporg_encodeit', $text);
- return $text;
- }
- add_filter( 'bp_get_the_topic_post_content', 'bporg_code_trick', 1 );
- add_filter( 'bp_get_activity_content_body', 'bporg_code_trick', 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement