0

I had find the code below and it is hide the tags “all, publish, thrash, draft, pending” for authors posts BUT is also keep hiding the tags for administrator too !

function remove_edit_post_views( $views ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        unset($views['all']);       
        unset($views['publish']);       
        unset($views['trash']);
        unset($views['draft']);       
        unset($views['pending']);
        return $views;
    }
}    

add_action( 'views_edit-post', 'remove_edit_post_views' );

How can be showing those tabs for administrator?

Any help is appreciated!

Sorry for my not good english

1 Answer 1

0

You need to return the $views for admins, thats why you don't see anyting.

EDIT: IMPORTANT, you are using a action but you need to use filter

function remove_edit_post_views ($views) {
    if (!current_user_can('manage_options')) {
        unset($views['all']);
        unset($views['publish']);
        unset($views['trash']);
        unset($views['draft']);
        unset($views['pending']);

        return $views;
    }

    return $views; // this is the missing piece
}

add_filter('views_edit-post', 'remove_edit_post_views');

You can make it even shorter by doing this

function remove_edit_post_views ($views) {
    if (!current_user_can('manage_options')) return [];
    return $views;
}

add_filter('views_edit-post', 'remove_edit_post_views');
1
  • Indeed the " return $views; " was the missing piece! . Thank you for your help! ;)
    – Lefteris
    Jun 30, 2021 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.