• Resolved spencerfcloud

    (@spencerfcloud)


    On a WP Multisite setup that I manage, for some reason the only role available to assign to users is now “customer”. I am trying to assign an admin to a site that was just added to the network, but the only option I currently have for their role is “customer”.

    All previous user roles seem to be unaffected, so I am still a Super Admin and other admins, editors, etc are fine, but any new users or newly assigned users can only be customers on any site, new and old.

    I believe that the customer role is automatically created by WooCommerce, but so is the Shop Manager and that isn’t showing up.

    Let me know any other details you would like to know. WP Core and plugin files are all up-to-date.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    This is likely due to your theme or a plugin managing the roles visible in the new user screen. An attempt at security gone awry perhaps.

    To see all the roles that are supposed to be available, temporarily add this code to a template, such as page.php (into a HTML portion, not a PHP portion):

    <pre><?php
    print_r( wp_roles()->roles );
    ?></pre>

    View a page that uses the template. You should see shop manager et al roles listed. If you see only customer, there is a deeper problem.

    Assuming you see the other roles, deactivate all plugins. WC roles will persist even if WC is inactive. Flush your browser cache. Check the new user screen, you should see all the usual roles again. If not, your theme is managing what is visible. Restore your plugins, one at a time. When the roles available are again restricted, the last activated plugin is causing the problem.

    Thread Starter spencerfcloud

    (@spencerfcloud)

    Thanks @bcworkz.

    I did the plugin check and it looks like WooCommerce is the one causing the trouble. Oddly, it’s only when it’s activated on the main site, but it’s fine if it’s activated on the other sites in the network.

    Moderator bcworkz

    (@bcworkz)

    Well that’s unexpected! You could try seeking resolution through the dedicated WC forum.

    Plugins normally use the ‘editable_roles’ filter to intentionally alter what roles we can select on the new user screen. A place to start if you want to investigate for yourself. But if the missing roles are not intentional, it probably wouldn’t lead anywhere. More likely the global $wp_roles has been manipulated.

    @spencerfcloud

    Did you find any solution as same problem is showing in my site

    Hi all, Please check the solution below @correyjames @spencerfcloud @bcworkz

    File Path : \wp-content\plugins\woocommerce\includes\wc-user-functions.php
    Function Name: wc_modify_editable_roles

    ============================================================

    Code Before Changes:

    function wc_modify_editable_roles( $roles ) {
    	if ( ! current_user_can( 'administrator' ) ) {
    		unset( $roles['administrator'] );
    	}
    
    	if ( current_user_can( 'shop_manager' ) ) {
    		$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
    		return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
    	}
    
    	return $roles;
    }
    add_filter( 'editable_roles', 'wc_modify_editable_roles' );

    ===============================================================

    Code After Changes:

    function wc_modify_editable_roles( $roles ) {
    	if ( ! current_user_can( 'administrator' ) ) {
    		unset( $roles['administrator'] );
            
            if ( current_user_can( 'shop_manager' ) ) {
        		$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
        		return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
        	}
    	}
        	
    
    	return $roles;
    }
    add_filter( 'editable_roles', 'wc_modify_editable_roles' );
    Thread Starter spencerfcloud

    (@spencerfcloud)

    @correyjames

    Actually the most recent update of WooCommerce seems to have fixed it.

    @01radteam

    Thanks for the solution! The most recent update of WooCommerce seems to have fixed it on my site, but if I run into the issue again I’ll be sure to come back here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Can’t Assign Roles on WordPress Multisite (Except Customer)’ is closed to new replies.