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