• Resolved teresasumisu

    (@teresasumisu)


    I added a new User Role, and the Users with that rule can’t access the backend. Error: “You are not allowed to access this page.”
    This is how I add the Role:

    global $wp_roles;
        if ( ! isset( $wp_roles ) ){
            $wp_roles = new WP_Roles();
        } 
    
        $editor = $wp_roles->get_role('editor');
    
        $wp_roles->remove_role('marketing_staff');
    
        if(class_exists('WooCommerce')) { //in my case, WC is installed, but it's no difference if i add the editor alone or shop manager only or additional.
            $shop_manager = $wp_roles->get_role('shop_manager');
            $wp_roles->add_role('marketing_staff', 'Marketing Staff', array($shop_manager->capabilities, $editor->capabilities) );
        } else {
            $wp_roles->add_role('marketing_staff', 'Marketing Staff', array($editor->capabilities) );
        }
    • This topic was modified 5 years, 5 months ago by teresasumisu.
    • This topic was modified 5 years, 5 months ago by teresasumisu.
  • The topic ‘Custom User Role can’t access backend’ is closed to new replies.