I am writing a plugin that will disallow user to post in certain categories. I am trying to display an error message to the user when he tries to post in the restricted category and also want WP should not post the same to Database. I am trying to do this using the save_post hook. However, I am stuck on how to tell WordPress not to save this post.
function buc_validatePostUpdate($post_id) {
global $wpdb, $user_ID;
$buc_values = get_user_meta($user_ID,'buc_user_cat');
$buc_final = explode(',', $buc_values[0]);
$post_cat = get_the_category($post_id);
foreach($post_cat as $cat) {
if(in_array( $cat->term_id, $buc_final ) !== FALSE) {
}
else {
//At this place, I need to tell WordPress not to update the post and return back.
add_action( 'admin_notices', 'custom_error_notice' );
return false;
}
}
}
add_action( 'save_post', 'buc_validatePostUpdate' );
function custom_error_notice(){
echo '<div class="error"><p>Error!!!!</p></div>';
remove_action( 'admin_notices', 'custom_error_notice' );
}
EDIT 1
While searching further, I got this link at WA. I am not sure if I need to implement something similar to as mentioned in this question.
Any advice would be greatly appreciated. Thanks in advance.