Php 自定义内容筛选器正在删除其他筛选器,即:wpcautop

Php 自定义内容筛选器正在删除其他筛选器,即:wpcautop,php,wordpress,filter,hook,Php,Wordpress,Filter,Hook,这是我第一次玩过滤器,所以请原谅我,如果这似乎是基本的。我用谷歌搜索了一下,找不到任何与我的问题相关的东西,从我所能找到的一切来看,这应该可以正常工作。据我所知,手动添加的过滤器与wordpress自动运行的任何其他过滤器同时运行,即:创建我自己的过滤器将与wordpress的默认wpautop和wptexturize过滤器一起运行 但出于某种原因,我添加的过滤器运行良好,除了现在wpautop和WPTextureSize无法在内容上运行。从函数中删除自定义筛选器后,将再次触发默认筛选器。没有安

这是我第一次玩过滤器,所以请原谅我,如果这似乎是基本的。我用谷歌搜索了一下,找不到任何与我的问题相关的东西,从我所能找到的一切来看,这应该可以正常工作。据我所知,手动添加的过滤器与wordpress自动运行的任何其他过滤器同时运行,即:创建我自己的过滤器将与wordpress的默认wpautop和wptexturize过滤器一起运行

但出于某种原因,我添加的过滤器运行良好,除了现在wpautop和WPTextureSize无法在内容上运行。从函数中删除自定义筛选器后,将再次触发默认筛选器。没有安装其他正在修改输出的插件。如果您发现我的陈述有问题,我们将非常感谢您提供的任何帮助,以及关于如何更好地完成此任务的一般性建议

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);
函数tumblr\u chat\u post($content){
全球$员额;
$content=$post->post\u内容;
如果($post->post\u type=='post'){
$postcats=wp_get_object_terms($post->ID,'category');
foreach(邮政编码为$mycat){
如果($mycat->name==“聊天”){
$chatoutput=“\n”;
$split=preg_split(“/(\r?\n)+|(\s*)+/”,$content);
foreach($haystack){
if(strpos($haystack,“:”)){
$string=explode(“:”,trim($haystack),2);
//列表($who,$what)=爆炸(“:”,$haystack,2);
$who=trim($string[0]);
$what=trim($string[1]);
$row\U class=空($row\U class)?“class=\”alt\:“”;
$chatoutput=$chatoutput.“$who:$what\n”;
}
否则{
//字符串中没有针,因此我们将保留它,稍后再输出
$no\u chatoutput=$no\u chatoutput.$haystack.“\n”;
}
}
//打印新格式化的聊天帖子,并将未格式化的内容推送到帖子末尾。
$content=$chatoutput.“\n”。$no\u chatoutput;
返回$content;
} 
否则{
//我不在定义的类别中,因此不需要处理
返回$content;
}
}
} 
否则{
//我不是一个普通的职位,所以不需要处理。
返回$content;
}
}
添加过滤器(“内容”、“tumblr\u聊天帖子”,20);

您没有将已过滤的
$content
传递到您的筛选函数中(因此,您将丢失在到达函数之前完成的任何筛选)。应该这样定义:

function tumblr_chat_post($content) {
   // rest of your logic m'ere
}

您没有将已过滤的
$content
传递到筛选函数中(因此,您将丢失在到达函数之前完成的任何筛选)。应该这样定义:

function tumblr_chat_post($content) {
   // rest of your logic m'ere
}

我明白你的意思,但我想我还是遗漏了一些东西,因为在函数args中添加$content并没有产生丝毫的影响。是因为我从函数中的$post->post_内容中提取$content吗?是的,是的。手动拉取post_内容也会跳过过滤器为修改内容所做的任何操作。很高兴知道,感谢您对初始问题的快速回复!我明白你的意思,但我想我还是遗漏了一些东西,因为在函数args中添加$content并没有产生丝毫的影响。是因为我从函数中的$post->post_内容中提取$content吗?是的,是的。手动拉取post_内容也会跳过过滤器为修改内容所做的任何操作。很高兴知道,感谢您对初始问题的快速回复!