Customize users’ capabilities to change a custom post’s post status

There’s not a good way to do this as the code for this section is pretty rigid. You can simply remove the elements via JavaScript. By removing (and not just hiding) the elements, you disable the functionality. You can customize the following to your needs I’m sure.

  1. Use CSS to hide the post actions inner box so the prohibited buttons never display to the screen. Without this, you will see the buttons for a moment and then they disappear.
  2. Removals of the elements
  3. Show the post publishing actions inner box again.

Example:

add_action('admin_head-post.php', 'remove_publishing_actions');
add_action('admin_head-post-new.php', 'remove_publishing_actions');
function remove_publishing_actions(){
    global $post;
    if($post->post_type == 'post'){
        //check user capabilities here
        echo "<style type="text/css">
                /* hide the publishing box until we remove the elements */
                #submitpost{display:none;}
            </style>";

        echo "
            <script type="text/javascript">
                jQuery(document).ready(function($){
                    //Remove whatever elements you don't want
                    $('#misc-publishing-actions, #save-action, #delete-action').remove();
                    //Show the publish actions
                    $('#submitpost').show();
                });
            </script>

        ";
    }
}

You should probably check for your custom user cap before echoing the style and script tags. Hope this helps!

Leave a Comment