适配Ezoic的WordPress内容审查代码分享
WordPress内容审查自定义代码(适配Ezoic广告变现)
这款代码专为WordPress博主开发,对使用Ezoic广告变现的用户格外实用——毕竟Ezoic自带不良内容检测机制,用这个代码能提前规避违规内容风险。
我已经在自身环境测试验证过代码有效性,现在分享给大家,你们可以根据需求修改或拓展功能:
/// 内容审查代码 function censor_content($content) { // 需要审查的词汇数组 $censored_words = array('word1', 'word2', 'word3'); // 遍历每个需要审查的词汇 foreach ($censored_words as $word) { // 创建正则表达式匹配词汇(不区分大小写) $pattern = '/\b' . $word . '\b/i'; // 将匹配到的词汇替换为审查后的形式 $content = preg_replace_callback($pattern, function($matches) { $word = $matches[0]; $censored_word = substr($word, 0, 2) . str_repeat('*', strlen($word) - 3) . substr($word, -1); return $censored_word; }, $content); } // 返回审查后的内容 return $content; } // 将审查函数添加到WordPress内容过滤器 add_filter('the_content', 'censor_content');
内容的提问来源于stack exchange,提问作者Sourav Pan
相关产品推荐
相关产品推荐

