• Resolved Jose

    (@giuse)


    Hello,

    it looks like the plugin doesn’t really add any user role, does it?

    I’ve checked the code, and I see that you provide the filter ‘b2bking_use_wp_roles’ for really adding the user roles, but even returning true from that filter I don’t see any added user roles.
    Do you manage the roles with user post meta or in other non-standard ways?

    When I say user role I mean the standard WordPress user role added using the function add_role.

    Why don’t you manage the roles with the standard WordPress roles?

    In my case, I need to deactivate specific plugins by user role with Freesoul Deactivate Plugins PRO, so FDP needs to know the user role added by your plugin, but I suppose in many other cases other plugins may need to detect the user role.
    If you confirm that you don’t manage the user role using the standard WP roles, I strongly suggest you do it, in another case you will have a lot of conflicts with other plugins.
    If you have no other possibilities, please let me know how you are managing the roles.

    Many thanks in advance.
    Best regards

    Jose

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WebWizards

    (@webwizardsdev)

    Hi Jose,
    Thank you for using our plugin,

    1) Indeed, instead of WP roles, we are using the plugin’s own ‘Groups’ (which you can find in the backend in B2BKing -> Groups – you can add, edit, or delete groups here).

    These groups are a custom post type and we reference a group by its post ID. Groups are stored in the user meta key ‘b2bking_customergroup’.

    So for example, if you want to get the group ID of a specific user, you can use:
    $group_id = get_user_meta($user_id,'b2bking_customergroup', true);
    To get the name of the group:
    $group_name = get_the_title($group_id);

    2) Why we are doing this instead of WP roles is because in WooCommerce it’s best for a customer to have the ‘Customer’ role. We could add multiple roles, but WordPress UI shows only 1 role by default, so that could be confusing and create issues.

    3) You can return true for this filter: b2bking_use_wp_roles
    Then deactivate and reactivate the B2BKing plugin. Now after reactivating it, you will see the plugin has created a WP role for each group.

    Initially the roles are not synced for users, but after you save a user profile, it should then sync automatically for that user (and for future users).

    The purpose of this filter is just compatibility with other plugins, like in your example,

    Kind regards,
    Stefan

    Thread Starter Jose

    (@giuse)

    Hi Stefan,

    thank you very much for your fast reply.

    I’ve already tried to deactivate and re-activate again the plugin, but the same it didn’t work.

    I understand that you need to give the possibility to have also the standard role “customer”, but I’m afraid if you don’t use the standard roles you will have issues with some plugins. For example, those plugins for customization by user role.
    I think it’s possible to assign multiple roles to the same user.
    Have a look at the answer that was given here: https://stackoverflow.com/questions/33537603/how-to-assign-multiple-roles-to-a-single-user-in-wordpress
    I didn’t test it, but I think it should work.

    In any case, I will also try to find a different solution to make detect the role by user meta.

    Thank you very much for providing the name of the user meta.

    I wish you all the best with your plugin.

    Have a great day!

    Jose

    Plugin Author WebWizards

    (@webwizardsdev)

    Hi Jose,

    That filter only exists in the Pro version of the plugin (no reason really, just didn’t get around to adding it to the Core version yet), so unless you’re using the Pro plugin, that would be why it doesn’t work. If it helps you with development, I can send you a copy of the Pro one, let me know.

    It does work to use $user->add_role to add multiple roles, but it creates a lot of confusion for customers (because WP shows only 1 role in the user profile), and also other plugins mess with roles, so it’s just simpler to keep this entirely separate as user meta – helps avoid a lot of conflicts and support tickets.

    Good luck, have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘User role not really added’ is closed to new replies.