Site logo

Archived topic

Hide WPSP from non-admin users

5 replies · Started by Tim on May 4, 2020

Viewing posts 1–6 of 6

Hello

I noticed that non-admin users can see WPSP in the admin area.

I tried this to make it only for admins to see, but this also hid it for admins:

add_filter( 'register_post_type_args', function( $args, $post_type ) {
    if ( 'wp_show_posts' !== $post_type ) {
        return $args;
     }

    $args['capability_type'] = 'manage_options';

    return $args;
}, 10, 2 );

What is wrong here ?

Thanks

Hello Thomas

Sorry for the late response.

Bizarrely it had the opposite effect. Without the above code the plugin is visible to my admin account, but with the above code the plugin is no longer visible.

I'm hoping to manage this in code to reduce the amount of bloat attracted via additional plugins.

Thanks

Tim

Try this, instead:

add_action( 'admin_menu', function() {
    if ( ! current_user_can( 'manage_options' ) ) {
        remove_menu_page( 'edit.php?post_type=wp_show_posts' );
    }
} );

Again sorry for the massively belated response.

Yes, the suggested code appears to do the job.

Thank you

Tim

No problem :)

This archived topic is closed to new replies.