Top

BuddyPress Hack to Add a Syntax Highlighter to Group Forums

July 2, 2010

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 1.2.4.1 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:

  1. Adding a syntax highlighter will eliminate a lot of errors people have with copying and pasting format issues.
  2. Developers will enjoy helping others more.
  3. It will significantly improve readability in the forums.
  4. It will make the forums more user-friendly and efficient so that people can find help faster.
  5. People will love it!

Feel free to add to this list in the comments below. :)

Tweet This Post


Comments

Got something to say?

Bottom
Article Archive  |  This site is a historical archive of pressography.com, a WordPress plugin and theme blog that published between 2006 and 2012. It is preserved for reference and is not operated by, affiliated with, or endorsed by its original authors. Nothing here is for sale and no form on this site is active. If you are the original owner and would like this domain returned, please get in touch.