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

I want to restrict pending posts to only certain users in the admin section, so I want to remove it from the post status options when viewing all posts (the bit highlighted in red in the image below):

WordPress post statuses submenu

However, I can’t find which hook I need to edit this. Can anyone shunt me in the right direction? I’ve scanned the filter reference but didn’t see anything appropriate.

Solutions Collecting From Web of "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="%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 );
    }

}

The filter you are looking for is views_{$this->screen->id} which is located in the WP_List_Table::views() method.

Where $this->screen->id is that of the context you are in, e.g. posts, users, etc…

File wp-admin/class-wp-list-table.php

Example usage:

function filter_posts_listable_views($views) {
    //do your thing...

    return $views;
}

add_filter( 'views_posts', 'filter_posts_list_table_views', 100);