Disallow a user to post in certain categories

save_post is too late. Look at the source and you can see that the post has already been saved when that hook fires. You will have to interrupt the process well before that hook if you want to prevent saving.

I think I would lean toward something like this:

add_filter(
  'post_updated_messages',
  function($messages) {
    $messages['post'][11] = 'This is my new message';
    return $messages;
  }
);
add_action(
  'load-post.php',
  function () {
    // summarily kill submission
    // and redirect back to edit page
    // purely to demonstrate the process
    $redir = admin_url('post.php?action=edit&message=11');

    if (
      isset($_POST['post_ID']) && ctype_digit($_POST['post_ID'])
    ) {
      $redir .= '&post=".(int)$_POST["post_ID'];
      //    var_dump($redir); die;
      wp_redirect($redir);
      die();
    }

  }
);

Your buc_validatePostUpdate code would run in the anonymous function with the // summarily kill submission comment and inside the if conditional.

Caution: This code is very crude. I am 100% sure that it will do things not intended. Use it as a springboard only. It is not final production code.

Leave a Comment