What hook do I use to edit the post statuses option in admin?

You can use the filter views_edit-post (or views_edit-{custom-post-type}) to modify the available “views”:

add_filter('views_edit-post', 'cyb_remove_pending_filter' );
function cyb_remove_pending_filter( $views ) {
    if( isset( $views['pending'] ) ) {
        unset( $views['pending'] );
    }
    return $views;
}

In the above filter you need inlude the user rules you want to apply. For exmple, if you want to remove the “Pending” view only for users who can not edit others posts:

add_filter('views_edit-post', 'cyb_remove_pending_filter' );
function cyb_remove_pending_filter( $views ) {
    if( isset( $views['pending'] ) && ! current_user_can('edit_others_posts') ) {
        unset( $views['pending'] );
    }
    return $views;
}

Also, if you exclude the pending view, you need to update the “All” post count:

add_filter('views_edit-post', 'cyb_remove_pending_filter' );
function cyb_remove_pending_filter( $views ) {

    if( isset( $views['pending'] ) && ! current_user_can('edit_others_posts') ) {
        unset( $views['pending'] );

        $args = [
            // Post params here
            // Include only the desired post statues for "All"
            'post_status' => [ 'publish', 'draft', 'future', 'trash' ],
            'all_posts'   => 1,
        ];
        $result = new WP_Query($args);

        if($result->found_posts > 0) {

            $views['all'] = sprintf( 
                                '<a href="https://wordpress.stackexchange.com/questions/219959/%s">'.__('All').' <span class="count">(%d)</span></a>',
                             admin_url('edit.php?all_posts=1&post_type=".get_query_var("post_type')),
                             $result->found_posts
            );

        }
    }

    return $views;
}

This code only remove the filter in the screen but it doesn’t block the access to the post with pending status. To block the access you need to use pre_get_posts action. For example:

add_action( 'pre_get_posts', 'cyb_exclude_pending_posts' );
function cyb_exclude_pending_posts( $query ) {

    // only in admin, main query and if user can not edit others posts
    if( is_admin() && ! current_user_can('edit_others_posts') && $query->is_main_query() ) {
        // Include only the desired post statues
        $post_status_arg = [ 'publish', 'draft', 'future', 'trash' ];
        $query->set( 'post_status', $post_status_arg );
    }

}

Leave a Comment