// We need the
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('&', '&', $text); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); $text = "$text
"; if ( "`" != $matches[1] ) $text = "$text"; 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('
', '', $text); $text = str_replace(' ', '
', '', $text); $text = str_replace(array('&','&'), '&', $text); $text = str_replace(''', "'", $text); if ( '', $text); $text = str_replace(' ' == $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 );