Writing a two-step filter plugin
-
I am attempting to write a filter that extracts part of the the_content and uses it in another function to return a formated string (a link).
In short, every time a user puts {{id:999}} in the post body (where 999 is any integer), I want it to return a formated link created by another function ( tnk_contact_link() ).
Here is my non-working example:
tnk_contact_filter($text); { $pattern = '\{id\:[0-9]+\}'; $stat = preg_match_all($patern, $text, $hit); foreach($hit as $contact) { $id = str_replace(array('{{id:', '}}'), '', $contact); $replacement = tnk_contact_link($id); $filtered = str_replace($contact, $replacement, $filtered); } return $filtered; } add_filter('the_content', 'tnk_contact_link');
Right now it causes the post to disappear because it is not doing the find/replace inline.
All I really need is a plugin that does something similar to look at, and I think I can figure it out from there.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Writing a two-step filter plugin’ is closed to new replies.