Change WordPress user roles and capabilities Forums Bug Reports Update 4.48 – User role only customer on Multisites

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #5184
    [email protected]
    Participant

    After update 4.48 on user role editor is only shown customer as user role !?

    Thanks & Regards

    #5185
    Vladimir
    Keymaster

    Version 4.48 does not contain any changes related to the roles list update.
    If you still have access to the URE, then at least one additional role exists – administrator.

    Did you activate/update any other/new plugins?

    #5186
    [email protected]
    Participant

    .. we have made the Update from 4.43 to 4.48

    No other Plugin Updates

    #5187
    Vladimir
    Keymaster

    Do you have files (without wp-content/uploads folder) & database copy before update to 4.48?
    I’m ready to test this update with your files/data to isolate a problem if it will be repeated, while I don’t even imagine currently what my cause it.

    #5190
    Vladimir
    Keymaster

    No need in access to your site copy. I just re-tested WC v. 3.4.6 and reproduced the issue.
    Good news: All roles are in place and just not shown while WooCommerce is active. I investigated the issue and found a serious bug in WooCommerce code:

    Look at the line #339. current_user_can() always returns true for WP multisite superadmin user. Thus this code hides all roles except ‘customer’. This function is located inside ‘includes/wc-user-functions.php’ file.
    It’s a new behaviour. This code was added from version 3.4.6

    You have 2 variants until they fix this:

    1) rollback to prev. version of WC 3.4.5

    or

    2) comment lines 339-342 in the updated function. It looked this way at version 3.4.5:

    
    function wc_modify_editable_roles( $roles ) {
        if ( ! current_user_can( 'administrator' ) ) {
            unset( $roles['administrator'] );
        }
        return $roles;
    }
    
    #5191
    [email protected]
    Participant

    Hi Vladimir,
    good news and GREAT SUPPORT !!!

    Thanks & Regards

    #5194
    Vladimir
    Keymaster

    There is one more function at the same file, which may prevent superadmin from editing users without ‘Customer’ role:

    
    function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
    	switch ( $cap ) {
    		case 'edit_user':
    		case 'remove_user':
    		case 'promote_user':
    		case 'delete_user':
    			if ( ! isset( $args[0] ) || $args[0] === $user_id ) {
    				break;
    			} else {
    				if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) {
    					$caps[] = 'do_not_allow';
    				}
    
    				// Shop managers can only edit customer info.
    				if ( current_user_can( 'shop_manager' ) ) {
    					$userdata = get_userdata( $args[0] );
    					$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
    					if ( property_exists( $userdata, 'roles' ) && ! empty( $userdata->roles ) && ! array_intersect( $userdata->roles, $shop_manager_editable_roles ) ) {
    						$caps[] = 'do_not_allow';
    					}
    				}
    			}
    			break;
    	}
    	return $caps;
    }
    

    Workaround – remove/comment part with condition for ‘shop_manager’ or use ‘woocommerce_shop_manager_editable_roles’ custom filter to not restrict editable roles for superadmin.

    #5201
    Vladimir
    Keymaster

    This code switches off WooCommerce 3.4.6 roles changing code for WordPress multisite superadmin:

    
    add_action( 'admin_init', 'fix_for_wc_436');
    
    function fix_for_wc_436() {
    
        if ( ! is_multisite() or ! is_super_admin() ) {
            return;
        }
        
        remove_filter( 'editable_roles', 'wc_modify_editable_roles' );
        remove_filter( 'map_meta_cap', 'wc_modify_map_meta_cap', 10 );
    
    }
    
    #5202
    [email protected]
    Participant

    Hi Vladimir,
    yes, this works! Great support!

    Thanks & Regards
    Dieter

    #5295
    grandstandglassware
    Participant

    Will there be a fix coming to a new version release of this plugin so that we don’t have to roll-back WooCommerce or use a manual override to the WooCommerce includes/wc-user-functions.php?

    I paid for Pro Business Lifetime hopeful that the pro version would resolve the issues we were experiencing before finding this thread.

    #5296
    Vladimir
    Keymaster

    WooCommerce v. 3.4.6. had a bug, due to which even superadmin at WP multisite saw only ‘customer’ role. That bug was fixed by WC developers now. Only shop_manager role is limited by ‘customer’role by default. WooCommerce offers custom filter ‘woocommerce_shop_manager_editable_roles’ which allows to change this default behavior without any version rollback or any kind of a hack applied to WooCommerce source code.
    This filter is documented here and mentioned at this topic too.

    I think having this solution in the mind there is no need in any intervention to this issue from User Role Editor Pro.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.