wp101plugin icon indicating copy to clipboard operation
wp101plugin copied to clipboard

Need a way to hide the admin menu from subscribers

Open jb510 opened this issue 9 years ago • 3 comments
trafficstars

There needs to be an easy way to hide the videos en mass from certain user roles, particularly subscribers on membership/e-commerce sites.

I was assuming this would work, but it doesn't so I must be doing something wrong:

/**
 * Hide WP101 Menu from Subscribers
 */
function s9_wp101_hide_from_subscribers() {
    if ( ! current_user_can( 'edit_posts' ) ) {
        remove_menu_page( 'wp101' );
    }
}
add_action( 'plugins_loaded', 's9_wp101_hide_from_subscribers' );

jb510 avatar Aug 17 '16 14:08 jb510

The plugins_loaded hook is too early. That page is added on the admin_menu hook with the default priority (10), so using a later priority should do it for you:

/**
 * Hide WP101 Menu from Subscribers
 */
function s9_wp101_hide_from_subscribers() {
    if ( ! current_user_can( 'edit_posts' ) ) {
        remove_menu_page( 'wp101' );
    }
}
add_action( 'admin_menu', 's9_wp101_hide_from_subscribers', 20 );

billerickson avatar Aug 17 '16 14:08 billerickson

Doh. Thanks Bill. I actually started with admin_menu, but that didn't work (was missing a later priority) so I blindly moved it to plugins_loaded thinking that was actually later...

the admin_menu, 20 combo is working.

Longer term... I think there ought to be a settings option to hide video from subscribers.

jb510 avatar Aug 17 '16 14:08 jb510

Within the context of version 5 of the WP101 plugin, the capability used to determine the visibility of the "Video Tutorials" page (defined in WP101\Admin\register_menu_pages()) should be filterable, defaulting to "read".

stevegrunwell avatar Apr 05 '19 19:04 stevegrunwell