2012-07-17 65 views
0

林使WordPress的一个非常简单的内容过滤器。基本上防止了如果柱包含任何从一组阵列的话在创建后。过滤器不需要通知用户错误的帖子。只需要停止被保存在数据库中后,到目前为止,我有这样的: 功能thefilter($内容){简单的内容过滤器WordPress的

$searchfilter = array(
    '#cure-plus.org#', 
    '#porn#', 
    '#escort#', 
    '#no prescription#', 
    '#Prescription#' 
); 

$count=0; 
foreach($searchfilter as $filter){ 

    preg_match_all($filter, $content, $pics); 

    $count += count($pics[0]); 
} 

if ($count > 0) { 
    return 'This post has been deleted'; 
} 
} 

add_filter('content_save_pre','thefilter'); 

这所有的作品,我可以删除该信息,一旦它的存在,但我宁愿它从来没有那么做过。

谢谢:)

+0

提问_REAL question_,并解释为什么这是不够好。请注意,帖子ID创建的那一刻编辑屏幕被称为 - _before_任何字已被写入。 – fuxia 2012-07-18 04:03:55

回答

0

为了防止被保存后,你可以很容易杀了PHP,或重定向某处。

if ($count > 0) 
    die('You just got caught in our spam filter.'); 

return $content; 

if ($count > 0) 
    header('Location: http://disney.com'); 
    die('You just got caught in our spam filter.'); 

return $content; 

确保杀死PHP即使你重定向,以确保执行数据库写入前停止。

还记得原来的内容返回给过滤器,如果帖子是干净的。