Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
Created June 19, 2023 16:48
Show Gist options
  • Save ofernandolopes/59581f504fe1a410369855c55d76819f to your computer and use it in GitHub Desktop.
Save ofernandolopes/59581f504fe1a410369855c55d76819f to your computer and use it in GitHub Desktop.
Remove the 'all', 'publish', 'future', 'sticky', 'draft', 'pending', 'trash' views for non-admins
//Remove the 'all', 'publish', 'future', 'sticky', 'draft', 'pending', 'trash' views for non-admins
//https://wordpress.stackexchange.com/questions/224159/how-to-disable-or-remove-all-posts-published-and-trash-in-dashboard-posts
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;
} );
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;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment