Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom BBCodes?

  • @matrixino

    Participant

    Hello, after importing from a phpBB forum where I had custom BBCodes I have the problem that they are not changed in actual html.
    I would like to know how can I implement such custom bbcodes in my bbpress installation.

    I did some tries making a custom plugin with something like this inside (this is just an example):

    function bb_table_replace( $text ) {
    $text = preg_replace('/\[tabella\](.*?)\[\/tabella\]/ie', "<table>$1</table>", $text);
    return $text;
    }
    add_filter('bbp_get_reply_content', 'bb_table_replace');

    But I had no luck. It seems however to find my regexp pattern but its replace is wrong, it’s made after the matched pattern (adding to it, instead of replacing).

    Any help?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @lynq

    Participant

    I know this could be tedious, but how about setting up some wordpress shortcodes for the relevant BBCodes?

    This could work: https://codex.wordpress.org/Shortcode_API

    Good luck!

    @matrixino

    Participant

    Anyone?

    @netweb

    Keymaster

    This should work for you, just swap the bbcode_table with tabella in each case, and the same for your custom tr/td etc 🙂

    https://gist.github.com/ntwb/7764534

    function ntwb_custom_bbcode_table_replace( $text ) {
     
    	$text = preg_replace( '/\[bbcode_table\]/i',      htmlspecialchars_decode( '<table>'  ), $text);
    	$text = preg_replace( '/\[\/bbcode_table\]/i',    htmlspecialchars_decode( '</table>' ), $text);
    	$text = preg_replace( '/\[bbcode_table_tr\]/i',   htmlspecialchars_decode( '<tr>'     ), $text);
    	$text = preg_replace( '/\[\/bbcode_table_tr\]/i', htmlspecialchars_decode( '</tr>'    ), $text);
    	$text = preg_replace( '/\[bbcode_table_td\]/i',   htmlspecialchars_decode( '<td>'     ), $text);
    	$text = preg_replace( '/\[\/bbcode_table_td\]/i', htmlspecialchars_decode( '</td>'    ), $text);
     
    	return $text;
    	}
     
    add_filter('bbp_get_reply_content', 'ntwb_custom_bbcode_table_replace');

    @matrixino

    Participant

    The problem is I have some BBcodes with multiple vars like this:
    [table3]var1!var2!var3[table3]
    transforming in something like this:
    <table><tr><td>var1</td><td>var2</td><td>var3</td></tr></table>
    I can’t seem to achieve the same thing even if using grouping in regexp with (.*?) and then using $1, $2, $3 to get the texts in between the “!”.

    @matrixino

    Participant

    Is this possible Stephen?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar