• Resolved bt_dev

    (@biotrace)


    Hello – We recently upgraded from UM 1.3.XX to UM 2 and our shop manangers can no longer see the User menu item in the WP Admin Menu. Is this by design? If so, are we able to elevate the Shop Manager role to see the Users section again?

    EDIT: It appears the Users menu item gets replaced with Profile.

    • This topic was modified 4 years ago by bt_dev.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @biotrace

    Have you tried re-saving the menu settings?

    Regards,

    Thread Starter bt_dev

    (@biotrace)

    Hi,

    This is for the WP Admin (backend) menu, not the front end. The Shop Manager role cannot see the “Users” menu item any more and it is replaced with “Profile” instead. This means our Shop Managers can no longer list, edit or delete users.

    I was able to get it to show by adding the Shop Manager role to the core files but this was just for testing rather than a permanent solution. The Shop Manager role is still unable to edit or delete users created with UM2.

    class-admin-users.php

    	/**
    		 * Restrict the edit/delete users via wp-admin screen by the UM role capabilities
    		 *
    		 * @param $allcaps
    		 * @param $cap
    		 * @param $args
    		 * @param $user
    		 *
    		 * @return mixed
    		 */
    		function map_caps_by_role( $allcaps, $cap, $args, $user ) {
    			if ( isset( $cap[0] ) && $cap[0] == 'edit_users' ) {
    				if ( ! user_can( $args[1], 'administrator' || 'shop_manager' ) && $args[0] == 'edit_user' ) {
    					if ( ! UM()->roles()->um_current_user_can( 'edit', $args[2] ) ) {
    						$allcaps[ $cap[0] ] = false;
    					}
    				}
    			} elseif ( isset( $cap[0] ) && $cap[0] == 'delete_users' ) {
    				if ( ! user_can( $args[1], 'administrator' || 'shop_manager' ) && $args[0] == 'delete_user' ) {
    					if ( ! UM()->roles()->um_current_user_can( 'delete', $args[2] ) ) {
    						$allcaps[ $cap[0] ] = false;
    					}
    				}
    			} elseif ( isset( $cap[0] ) && $cap[0] == 'list_users' ) {
    				if ( ! user_can( $args[1], 'administrator' || 'shop_manager' ) && $args[0] == 'list_users' ) {
    					if ( ! um_user( 'can_view_all' ) ) {
    						$allcaps[ $cap[0] ] = false;
    					}
    				}
    			}
    
    			return $allcaps;
    		}
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @biotrace

    Have you tried adding/editing the capabilities to view/edit users with User Role Editor plugin and see if the issue goes away?
    https://www.ads-software.com/plugins/user-role-editor/

    Regards,

    Thread Starter bt_dev

    (@biotrace)

    Hi there – I thought I’d post an update to this issue as it is now resolved and may help other users. The following code snippet will allow Shop Managers to view the users section and edit / delete users again.

    /**
     * This code snippet restores capabilities 'edit_user' and 'delete_user' if they were blocked by a third-party plugin.
     */
    
    if ( function_exists( 'UM' ) ) {
    
    	function um_map_meta_cap( $caps, $cap, $user_id, $args ) {
    		static $permissions = array();
    
    		$index = array_keys( $caps, 'do_not_allow' );
    		if ( $index ) {
    			$index = current( $index );
    			if ( empty( $permissions[$user_id] ) ) {
    				$role = UM()->roles()->get_priority_user_role( $user_id );
    				$permissions[$user_id] = UM()->roles()->role_data( $role );
    			}
    			$p = $permissions[$user_id];
    
    			switch ( $cap ) {
    				case 'edit_user':
    				case 'edit_users':
    				case 'promote_user':
    					if ( !empty( $p['can_edit_everyone'] ) ) { // role setting Can edit other member accounts?
    						if ( empty( $p['can_edit_roles'] ) ) {
    							unset( $caps[$index] );
    						} elseif ( is_array( $p['can_edit_roles'] ) && isset( $args[0] ) && is_numeric( $args[0] ) ) {
    							$urole = UM()->roles()->get_priority_user_role( $args[0] );
    							if ( in_array( $urole, $p['can_edit_roles'] ) ) {
    								unset( $caps[$index] );
    							}
    						}
    					}
    					break;
    
    				case 'delete_user':
    				case 'delete_users':
    					if ( !empty( $p['can_delete_everyone'] ) ) { // role setting Can delete other member accounts?
    						if ( empty( $p['can_delete_roles'] ) ) {
    							unset( $caps[$index] );
    						} elseif ( is_array( $p['can_delete_roles'] ) && isset( $args[0] ) && is_numeric( $args[0] ) ) {
    							$urole = UM()->roles()->get_priority_user_role( $args[0] );
    							if ( in_array( $urole, $p['can_delete_roles'] ) ) {
    								unset( $caps[$index] );
    							}
    						}
    					}
    					break;
    			}
    		}
    
    		return $caps;
    	}
    
    	add_filter( 'map_meta_cap', 'um_map_meta_cap', 99, 4 );
    }

    Bonus snippet: The following snippet will restore the ability for Woocommerce Shop Managers to change user roles when paired with the above snippet.

    /**
     * Allow Shop Managers to edit and promote users with a specified role 
     * using the 'woocommerce_shop_manager_editable_roles' filter.
     *
     * @param array $roles Array of role slugs for users Shop Managers can edit.
     * @return array
     */
    function myextension_shop_manager_role_edit_capabilities( $roles ) {
        $roles[] = 'placeholder_role1';
      	$roles[] = 'placeholder_role2';
        $roles[] = 'placeholder_role3';
        return $roles;
    }
    add_filter( 'woocommerce_shop_manager_editable_roles', 'myextension_shop_manager_role_edit_capabilities' ); 
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @biotrace

    Thanks for letting us know how you resolved the issue with code snippets!

    I’m closing this thread now.

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shop Managers cannot see Users item in WP Admin Menu since upgrading’ is closed to new replies.