views:

144

answers:

1

This is my first time playing with filters, so forgive me if this seems basic. I have done quiet a bit of googling and can't find anything related to my problem, from everything I have been able to find this should be working without an issue. It's my understanding that filters added manually run concurrent with any other filters wordpress is automatically running, ie: creating my own filter will run along with wordpress's default wpautop and wptexturize filters.

But for some reason my added filter is running fine, except now wpautop and wptexturize is failing to run on the_content. After removing my custom filter from functions, the default filters are triggering again. No other plugins installed that are modifying the output. Any help would be super appreciated, along with any general recommendations as to a better way to do this if you see something wrong with my statements.

function tumblr_chat_post($content) {
global $post;
$content = $post->post_content;
if ($post->post_type == 'post') {
    $postcats = wp_get_object_terms($post->ID, 'category');
    foreach ($postcats as $mycat) {
        if ($mycat->name == "chats") {
            $chatoutput = "<dl class=\"transcript\">\n";
            $split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
                foreach($split as $haystack) { 
                    if (strpos($haystack, ":")) {
                        $string = explode(":", trim($haystack), 2);
                        //list($who, $what) = explode(":", $haystack, 2);
                        $who = trim($string[0]);
                        $what = trim($string[1]);
                        $row_class = empty($row_class)? " class=\"alt\"" : "";
                        $chatoutput = $chatoutput . "<dt$row_class><b>$who:</b></dt> <dd><i>$what</i></dd>\n";
                    }
                    else {
                    // the string didn't contain a needle so we will keep it and output it later
                        $no_chatoutput = $no_chatoutput . $haystack . "\n";
                    }
                }
                // print our new formated chat post and push unformatted content to the end of the post.
                $content = $chatoutput . "</dl>\n" . $no_chatoutput;
                return $content;
        } 
        else {
        // I don't exist in the defined category, so no processing is needed
        return $content;
        }
    }
} 
else { 
    // I'm not a regular post, so no processing is needed.
    return $content;
}
}
add_filter( "the_content", "tumblr_chat_post", 20);
+1  A: 

You're not passing the already filtered $content into your filter function (and therefore you're losing any filtering done before you reach your function). It should be defined like so:

function tumblr_chat_post($content) {
   // rest of your logic m'ere
}
Pat
I see what your saying, but I guess I'm still missing something as adding $content into the function args isn't making the slightest difference. Is it because I'm pulling $content from $post->post_content within the function?
Jervis
Yes, yes it was. Pulling the post_content manually was also skipping anything the filters were doing to modify it. Good to know and thanks for the quick reply to the initial problem!
Jervis