admin管理员组

文章数量:1295335

I've got a site with a lot of custom user roles and capabilities, and I'm trying to allow users with a new capability 'admin_panel_access` (set up via User Role Editor) to access the admin dashboard.

No matter what I try - several different versions of access in functions.php (see below for my latest) - users with that capability cannot access /wp-admin at all.

function restrict_admin(){
    if ( ! current_user_can( 'admin_panel_access' ) ) {
        wp_die( __('You are not allowed to access this part of the site') );
    }
}
add_action( 'admin_init', 'restrict_admin', 1 );

I've narrowed it down by changing theme and disabling plugins one by one, and the culprit is WooCommerce. For some reason, when I activate WooCommerce it stops roles with custom capabilities (other than edit_posts) being able to access.

Any clues or ideas would be fantastic. 5 hours of searching and testing is enough to drive anyone to madness!

Thanks.

本文标签: woocommerce offtopicAdmin access for custom user capabilities