woocommerce offtopic – Admin access for custom user capabilities

Question

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.

0
PenguinBegins 4 weeks 2021-04-14T14:37:04-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse