Skip to:

_ck_ Can you help me with some of your regular expression code?

  • Hi I’m currently modifying your wiki post script(source once i’ve finished it) and I’m combining looking at your bbcode plugin and I’m trying to add a simple <wiki>something</wiki> tag and I’m having a trouble getting my head around how you do it.

    Looking at this code:

    $complex1 = array('wiki' => array('a','href'),'img' => array('img','src'));

    foreach($complex1 as $bbcode=>$html){

    if($bbcode=='wiki') {


    /*$text = preg_replace('/(.+?)[/'.$bbcode.']/is','<'.$html[0].' '.$html[1].'="$1">',$text);*/


    else {$text = preg_replace('/(.+?)[/'.$bbcode.']/is','<'.$html[0].' '.$html[1].'="$1">$1</'.$html[0].'>',$text);}


    Now I was thinking removing everything after ‘wiki’ would work but nothing works. It calls var_dump at the moment but it calls it for all posts in the topic.

    Any ideas? I haven’t used regular expressions before so I’m a bit lost.

Viewing 5 replies - 1 through 5 (of 5 total)

  • _ck_


    You don’t need to tamper with the regex.

    Essentially you are adding the attibutes incorrectly.

    This is wrong: 'wiki' => array('a','href')

    That means set a new tag called “wiki” with the attributes “a” and “href”. But really only “href” is an attribute.

    I could help you more if I understood what <wiki></wiki> was supposed to do.

    Well I just want it to detect when [wiki]pagename[/wiki] is used so I can run a bit of code(I’m currently modifying your wikipost script to be more of a wiki system.) I want it to create a new post and link to that post.

    Looking at the code again I’m starting to wrap my head around what’s going on.

    $simple = array('b' => 'strong',); // cut and copied example

    Turns all instances of into the html equivalent <center></center> but I just want it to recognise all instances of [wiki]wikipagename[/wiki] and then allow me to run code. I’ve been tinkering with the code most of the day but most of the time it seems to want to run the code I’ve written for all the posts and not just one 😡



    Oh I see you want to turn any post into a wiki by wrapping the text in [wiki]. There is a huge problem with your logic as the wikipost plugin allows anyone to edit a post by assigning a generic user to the post, which is the trigger. Replacing that with bbcode as the trigger instead would be far more difficult.

    bbPress would not have any way to know to let another user edit the post until it scans the post_text for [wiki]. That’s going to be a huge problem.

    by the way is translated to <strong> not <center>



    Ah sorry I explained what I want wrong.

    I already have the wikipost section sorted out, when someone puts something in [wiki]pagename[/wiki] I wan’t it to create a new topic that will be wiki enabled. Just like in mediawiki when you use the pagename and it creates a new page.



    Well you’ll have to test to make sure a wikipost isn’t created yet on that topic (and that topic hasn’t been made yet, and they don’t edit the link to change the topic name,link, etc.).

    But adding bbcode style parsing to posts is very straightforward. You’ll need to use preg_match_all on the $post->post_text

    something like this:

    add_filter('post_text', 'make_wiki_links');  // you can also try 'pre_post' which will make it only process the text once during save and not everytime it's displayed

    function make_wiki_links($text) {
    if (preg_match_all("/[wiki](.*?)[/wiki]/sim", $text, $wiki_links)) {
    foreach ($wiki_links[0] as $wiki_link) {
    // do whatever you want to each $wiki_link here
    return $text;

    You’ve got about a dozen problems to handle with this technique, including replacing the [wiki] parts afterwards with another preg_replace, good luck.

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