I have a membership website where my users can create their own page. I use below snippets in function.php to remove the options of published, trash etc. of other users and only show "mine".
/**
* Remove the 'all', 'publish', 'future', 'sticky', 'draft', 'pending', 'trash'
* views for non-admins
*/
add_filter( 'views_edit-page', function( $views )
{
if( current_user_can( 'manage_options' ) )
return $views;
$remove_views = [ 'all','publish','future','sticky','draft','pending','trash' ];
foreach( (array) $remove_views as $view )
{
if( isset( $views[$view] ) )
unset( $views[$view] );
}
return $views;
} );
It is working fine. When a user create a page, it is showing only the "mine" option.
But When a new user 1st time come to create a page (they have not created any page); they still can view the "All" options where all the published page (of other users) are shown. Also when they delete his all "mine" pages, they can view the "All" option.
So how to stop users to see the "all" option when they 1st time come to create a page or delete all their pages?
pre_get_posts
action to list only current user's posts.