The WP_Posts_List_Table
class extends WP_List_Table
and within the WP_List_Table::views()
method we have the following dynamic views filter:
/**
* Filter the list of available list table views.
*
* The dynamic portion of the hook name, `$this->screen->id`, refers
* to the ID of the current screen, usually a string.
*
* @since 3.5.0
*
* @param array $views An array of available list table views.
*/
$views = apply_filters( "views_{$this->screen->id}", $views );
So we can use the generated views_edit-post
filter to adjust the views of the post list table.
Example:
Let's remove the all, publish, future, sticky, draft, pending and trash for non-admins (PHP 5.4+):
/**
* Remove the 'all', 'publish', 'future', 'sticky', 'draft', 'pending', 'trash'
* views for non-admins
*/
add_filter( 'views_edit-post', 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;
} );
where you can modify the $remove_views
to your needs. Another approach would be to only pick up mine and only return that view.
Then we could try to force the mine view further with:
/**
* Force the 'mine' view on the 'edit-post' screen
*/
add_action( 'pre_get_posts', function( \WP_Query $q )
{
if(
is_admin()
&& $q->is_main_query()
&& 'edit-post' === get_current_screen()->id
&& ! current_user_can( 'manage_options' )
)
$q->set( 'author', get_current_user_id() );
} );
Before:
After: