Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



bbPress - Remove an...
 
Notifications
Clear all

[Solved] bbPress - Remove annoying backtick behavior (posting shell code)

2 Posts
1 Users
0 Reactions
4,802 Views
 Hans
(@hans)
Famed Member Admin
Joined: 13 years ago
Posts: 3147
Topic starter   [#108]

In bbPress, there is this annoying little backtick behavior, which can be an issue when you try to post code, specifically when using shell statements that actually have a backtick in it.

There is no easy way to disable that behavior ... except for modifying a core file of the bbPress plugin (bbPress 2.x).

Open the file 

wp-content/plugins/bbpress/includes/common/formatting.php

Find where the function "bbp_code_trick" is defined and make the following changes:
(two slashes to comment out the two "$content = preg_replace_callback" lines)

function bbp_code_trick( $content = '' ) {
 $content = str_replace( array( "rn", "r" ), "n", $content );
 //$content = preg_replace_callback( "|(`)(.*?)`|", 'bbp_encode_callback', $content );
 //$content = preg_replace_callback( "!(^|n)`(.*?)`!s", 'bbp_encode_callback', $content );
 return $content;
}

Do the same with the function that is defined right after that:
(two slashes in front of the one line that says "$content = preg_replace_callback")

function bbp_code_trick_reverse( $content = '' ) {
 // Setup variables
 $openers = array( '<p>', '<br />' );
 //$content = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", 'bbp_decode_callback', $content );
 // Do the do
 $content = str_replace( $openers, '', $content );
 $content = str_replace( '</p>', "n", $content );
 $content = str_replace( '<coded_br />', '<br />', $content );
 $content = str_replace( '<coded_p>', '<p>', $content );
 $content = str_replace( '</coded_p>', '</p>', $content );
 return $content;
}

Backticks as of now do not work anymore.

Caution:
- This "patch" needs to be done each time you update bbPress - so don't forget doing that.
- You might need to modify some parts of the theme where it might say something like "use backticks to mark code" - just so users don't accidentally use it.
- Your editor (fancy editor for example, or your custom editor) will need to use a < PRE > or < CODE > tag to mark code.



   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 13 years ago
Posts: 3147
Topic starter  

I've just tested this patch with bbPress 2.6.0 and 2.6.1 - it still works 



   
ReplyQuote
Share: