• Bob

    (@prasunsen)


    Hello,

    Thank you for this great plugin. Unfortunately there is a problem with users having multiple roles and the admin links. It seems that the plugin takes the first role and bases its logic on it:

    in wp-content/plugins/white-label-cms/includes/Functions.php

    function wlcms_current_user_roles()
    {
    $roles = wp_get_current_user()->roles;
    $role = array_shift($roles);
    return $role;
    }

    Example, we have two users with these roles:

    User A:

    array(
    ‘administrator’ => true,
    ‘forum_central_office’ => true,
    ‘central_office’ => true,
    )

    User B:

    array(
    ‘central_office’ => true,
    ‘administrator’ => true,
    ‘forum_central_office’ => true,
    )

    The plugin works correctly for the second user but not for the first.
    After rearranging the roles of the first user like the second, the menus started working correctly.

    Perhaps an easy solution would be to allow a hook so we can rearrange the role priority:

    function wlcms_current_user_roles()
    {
    $user = wp_get_current_user();
    $roles = (array) $user->roles;

    $role = $roles[0] ?? '';
    
    /**
     * Allow overriding the "primary" role used by WLCMS when user has multiple roles.
     *
     * @param string   $role  Selected role (default: first role).
     * @param string[] $roles All user roles.
     * @param WP_User  $user  Current user.
     */
    return apply_filters('wlcms_primary_role', $role, $roles, $user);

    }

You must be logged in to reply to this topic.