{"id":34788,"date":"2010-07-02T10:00:22","date_gmt":"2010-07-02T14:00:22","guid":{"rendered":"http:\/\/wpmu.org\/?p=34788"},"modified":"2010-07-02T05:47:27","modified_gmt":"2010-07-02T09:47:27","slug":"buddypress-hack-to-add-a-syntax-highlighter-to-group-forums","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/buddypress-hack-to-add-a-syntax-highlighter-to-group-forums\/","title":{"rendered":"BuddyPress Hack to Add a Syntax Highlighter to Group Forums"},"content":{"rendered":"<p><a rel=\"lightbox[34788]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2010\/07\/highlighter_blue_01.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-34792\" title=\"highlighter_blue_01\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2010\/07\/highlighter_blue_01.png\" alt=\"Post image\" aria-hidden=\"true\" width=\"128\" height=\"128\" \/><\/a>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 <a href=\"http:\/\/buddypress.org\/community\/groups\/creating-extending\/forum\/topic\/quick-hack-enable-syntaxhighlighter-evolved-on-group-forums\/\" rel=\"noopener\" target=\"_blank\">hack<\/a> 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 <a href=\"http:\/\/etivite.com\/groups\/buddypress\/forum\/\" rel=\"noopener\" target=\"_blank\">live demo<\/a> on his website.<\/p>\n<p><a rel=\"lightbox[34788]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2010\/07\/syntaxhighlighter.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34790\" title=\"syntaxhighlighter\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2010\/07\/syntaxhighlighter.png\" alt=\"Post image\" aria-hidden=\"true\" width=\"637\" height=\"294\" \/><\/a><\/p>\n<h2>How to Add a Syntax Highlighter to BuddyPress Group Forums<\/h2>\n<h3>Step 1: Download <a href=\"http:\/\/wordpress.org\/extend\/plugins\/syntaxhighlighter\/\" rel=\"noopener\" target=\"_blank\">SyntaxHighlighter Evolved<\/a><\/h3>\n<p>Install this plugin as you normally would. You&#8217;ll notice that it will only work for posts and pages. There&#8217;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.<\/p>\n<h3>Add the Filters to syntaxhighlighter.php<\/h3>\n<pre>add_filter( 'bp_get_the_topic_post_content', array(&amp;$this, 'parse_shortcodes'), 7 );\r\nadd_filter( 'group_forum_post_text_before_save', array(&amp;$this, 'encode_shortcode_contents_slashed'), 1 );\r\nadd_filter( 'group_forum_topic_text_before_save', array(&amp;$this, 'encode_shortcode_contents_slashed'), 1 );\r\n\r\nadd_filter( 'bp_get_the_topic_text', array(&amp;$this, 'decode_shortcode_contents'), 1 );\r\nadd_filter( 'bp_get_the_topic_post_edit_text', array(&amp;$this, 'decode_shortcode_contents'), 1 );\r\n<\/pre>\n<p>You should add these statements in the file right after you see this:<\/p>\n<pre>add_filter( 'the_content', array(&amp;$this, 'parse_shortcodes'), 7 );\r\n<\/pre>\n<p>Re-upload the file and now you&#8217;ll find that you can post code much more easily in the forums.<\/p>\n<p>Now&#8230; if we could only get this added to the <a href=\"http:\/\/buddypress.org\/support\/topics\/\" rel=\"noopener\" target=\"_blank\">support forums<\/a> at BuddyPress.org. ;) Here are five reasons why it&#8217;s a good idea to add a syntax highlighter at the BuddyPress forums or any other developer-centric site for that matter:<\/p>\n<ol>\n<li>Adding a syntax highlighter will eliminate a lot of errors people have with copying and pasting format issues.<\/li>\n<li>Developers will enjoy helping others more.<\/li>\n<li>It will significantly improve readability in the forums.<\/li>\n<li>It will make the forums more user-friendly and efficient so that people can find help faster.<\/li>\n<li>People will love it!<\/li>\n<\/ol>\n<p>Feel free to add to this list in the comments below. :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":4099,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[1,557,235,263],"tags":[37],"tutorials_categories":[],"class_list":["post-34788","post","type-post","status-publish","format-standard","hentry","category-news-community","category-development","category-misc","category-tutorials","tag-forums"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/34788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/4099"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=34788"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/34788\/revisions"}],"predecessor-version":[{"id":215823,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/34788\/revisions\/215823"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=34788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=34788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=34788"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=34788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}