Skip to:
Content
Pages
Categories
Search
Top
Bottom

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

@_ck_

Participant

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.

Skip to toolbar