Change WordPress user roles and capabilities › Forums › Bug Reports › Update 4.48 – User role only customer on Multisites
- This topic has 10 replies, 3 voices, and was last updated 6 years ago by Vladimir.
-
AuthorPosts
-
12/10/2018 at 09:08 #5184[email protected]Participant
After update 4.48 on user role editor is only shown customer as user role !?
Thanks & Regards
12/10/2018 at 10:13 #5185VladimirKeymasterVersion 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?
12/10/2018 at 10:39 #5186[email protected]Participant.. we have made the Update from 4.43 to 4.48
No other Plugin Updates
12/10/2018 at 10:59 #5187VladimirKeymasterDo 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.12/10/2018 at 16:20 #5190VladimirKeymasterNo 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.6You 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; }
12/10/2018 at 17:50 #5191[email protected]ParticipantHi Vladimir,
good news and GREAT SUPPORT !!!Thanks & Regards
13/10/2018 at 01:26 #5194VladimirKeymasterThere 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.
14/10/2018 at 03:23 #5201VladimirKeymasterThis 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 ); }
14/10/2018 at 06:27 #5202[email protected]ParticipantHi Vladimir,
yes, this works! Great support!Thanks & Regards
Dieter20/11/2018 at 19:16 #5295grandstandglasswareParticipantWill 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.
21/11/2018 at 02:44 #5296VladimirKeymasterWooCommerce 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.
-
AuthorPosts
- You must be logged in to reply to this topic.