最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Words must be included and restricted words in new posts

programmeradmin0浏览0评论

I am building a new website which is a specific to a certain topics and I am allowing my registered user to publish new posts. But I want to prevent the users from posting non related content to the website. If I have a list of words that the pots should contain one of them and another list for the restricted words,how can I use these lists for auto acceptance of new posts?

    function wpb_forbidden_title($title){
global $post;
$title = $post->post_title;
 
// Add restricted words or phrases separated by a semicolon
 
$restricted_words = "word1;word2;word3";
 
$restricted_words = explode(";", $restricted_words);
foreach($restricted_words as $restricted_word){
if (stristr( $title, $restricted_word))
wp_die( __('Error: You have used a forbidden word "'. $restricted_word .'" in post title') );
}
}
add_action('publish_post', 'wpb_forbidden_title', 10, 1);

I found this solution to prevent a word list from being used in the title but I need a similar solution for the post content not just the title and to have another list of words that at least one of them must be included

That you for your help

发布评论

评论列表(0)

  1. 暂无评论