BuddyPress Hack to Add a Syntax Highlighter to Group Forums

July 2, 2010  | 
4 Comments

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. :)

Featured Plugin - Send beautiful html email newsletters, from WordPress!

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Featured Plugin - Every great SEO tweak you need, in one snazzy bundle

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

Featured Plugin - Open an Online Store with MarketPress

Out of all the WordPress ecommerce plugins available, this has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - Host sites, get paid, just like WordPress.com

If you've ever wondered how you could offer a paid site management and hosting service, then this is the plugin for you. Offer a freemium or paid service, for any niche you like, it's powered Edublogs.org to success already!
Find out more

Featured Plugin - WordPress + Google Maps = Perfect

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - Easily integrate your WordPress site with Facebook

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

Featured Plugin - Start Your Own Powerful Membership Site

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - Start your own Quora / StackOverflow / Yahoo Q&A site

It's now incredibly easy to start your own Q&A site using nothing more than WordPress - The Q&A plugin simply and brilliantly transforms any site, or page, into a perfect support or Q&A environment.
Find out more

Featured Plugin - Add bottom corner (or anywhere else) chat to your site

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

4 Responses to BuddyPress Hack to Add a Syntax Highlighter to Group Forums

  1. Thanks Sarah, that’s surprisingly easy!

    I’ve been playing around with BuddyPress a lot this summer, hopefully this code snippet will come in handy for a few small formatting problems I’m having.

  2. Pingback: BuddyPress Hack to Add a Syntax Highlighter to Group Forums

  3. Very Nice! And Easy!

    Thanks for the post. All the other plug-ins I tried were useless to me…

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting