BuddyPress Hack to Add a Syntax Highlighter to Group Forums
Have you been wishing for an easy way to add syntax highlighting to your BuddyPress group forums? Now you can and it will only take you three minutes to hook it up. This hack was posted in the BuddyPress support forums by Rich Fuller, a prolific BuddyPress hacker and plugin developer whose blog is definitely subscription worthy. You can also see a live demo on his website.
How to Add a Syntax Highlighter to BuddyPress Group Forums
Step 1: Download SyntaxHighlighter Evolved
Install this plugin as you normally would. You’ll notice that it will only work for posts and pages. There’s just one more step to get it working with BuddyPress. Also, you need to be using BuddyPress version 22.214.171.124 or higher for this to work.
Add the Filters to syntaxhighlighter.php
add_filter( 'bp_get_the_topic_post_content', array(&$this, 'parse_shortcodes'), 7 ); add_filter( 'group_forum_post_text_before_save', array(&$this, 'encode_shortcode_contents_slashed'), 1 ); add_filter( 'group_forum_topic_text_before_save', array(&$this, 'encode_shortcode_contents_slashed'), 1 ); add_filter( 'bp_get_the_topic_text', array(&$this, 'decode_shortcode_contents'), 1 ); add_filter( 'bp_get_the_topic_post_edit_text', array(&$this, 'decode_shortcode_contents'), 1 );
You should add these statements in the file right after you see this:
add_filter( 'the_content', array(&$this, 'parse_shortcodes'), 7 );
Re-upload the file and now you’ll find that you can post code much more easily in the forums.
Now… if we could only get this added to the support forums at BuddyPress.org. ;) Here are five reasons why it’s a good idea to add a syntax highlighter at the BuddyPress forums or any other developer-centric site for that matter:
- Adding a syntax highlighter will eliminate a lot of errors people have with copying and pasting format issues.
- Developers will enjoy helping others more.
- It will significantly improve readability in the forums.
- It will make the forums more user-friendly and efficient so that people can find help faster.
- People will love it!
Feel free to add to this list in the comments below. :)