• Resolved stephunique

    (@stephunique)


    Hello,

    I tested this plugin on a temporary site using TasteWP. I saw that it lets you charge a recurring fee ie a subscription, to allocate a user role to someone. This is exactly what I need, a simple subscription that allocates a user role to members of my site for a limited time period, since I will use user roles to grant permissions to do things (as opposed to granting access to posts). Unfortunately, there are two issues:

    1. The recurring subscription payment form I created is really a virtual product purchase form, not a user registration form. This means it asked for a billing address and didn’t ask for a username and login password and thus cannot login, however, they showed up in my Users dashboard as a site user. I wanted to charge people to register as a site member with a certain user role and as a member, they can log in.
    2. I registered a test user and discovered they had not two, but three user roles: the site default role, the role I gave them using the add role integration, and a Surecart customer role. For my purposes, they must have only one role, and that is the role I will give them and that they pay for. This is because I will use other plugins that grant permissions based on user roles, if a person has more than one role, there will be conflicts, eg if “subscribers” is my site’s default role (WordPress makes it compulsory to have a default role), and they do not have permission to upload, but I make it that “Premium” roles can upload, then there will be a conflict when a plugin has to grant each user role the permission to do something in a setting like “Can this user role do this Yes or No”, if they have more than one role. I would like it so that when the user buys the subscription, they get only one role (the one they are purchasing), then, after the subscription expires, the person loses the role they bought, and ideally gets a different role, or at the very least, then get the site default role.

    thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Andre Gagnon

    (@2winfactor)

    Hi There!

    Thanks so much for reaching out. Happy to help with this.

    We require all purchases to have WordPress user accounts. Otherwise we cannot assign a user role to that person. By default, it’s the SureCart customer role, which has no capabilities. It’s just used as a record for the purchase.

    It is perfectly fine for a user to have multiple roles. I believe you may just need to alter how you are checking for permissions.

    Instead of “Can this user role do this”, you should be checking “Can this user do this”. It will take into account the roles and capabilities that the user has.

    So for example, say you have a role called “Premium”. This role has the capability to upload_files.

    For users with this role, current_user_can('upload_files') will be true.
    For users without this role current_user_can('upload_files') will be false.

    https://developer.www.ads-software.com/reference/functions/user_can/
    https://developer.www.ads-software.com/reference/functions/current_user_can/

    Let me know if this makes sense.

    Thread Starter stephunique

    (@stephunique)

    Hello,

    Thank you for your answer. I understand now that customers need a role for the plugin to reference.

    Is there a way at least to prevent the user from getting the site default roles too? That way I could at least grant all sure cart members a permission that does not conflict with the site’s default role.

    Unfortunately, the methods you suggested will not work for me. I cannot check the “user” as opposed to the role. I will not be the one checking the roles – I have non-negotiable plugins that I will use (I am not a developer) and all of them assigns rules to all of the roles on the site, NOT the users (there will be too many users). In the settings, it will list all the roles of the site and you have to choose whether or not this user role will have access to some permission or not, yes or no. It is impossible to leave one of them unallocated. For example: in the “messaging others” setting, it will list all the user roles and you have to select “can this user role message others, yes or no”. If I select “no” for subscribers but “yes” for sure cart customers or premium members, there will be a conflict if a user was allocated the default subscriber role as well as the sure cart customer role when making a subscription purchase, and the premium member role.

    Also, can we send reminder emails to customers before their free trial ends, not just the end of their subscription?

    Thank you

    Plugin Author Andre Gagnon

    (@2winfactor)

    If I select “no” for subscribers but “yes” for sure cart customers or premium members, there will be a conflict if a user was allocated the default subscriber role as well as the sure cart customer role when making a subscription purchase, and the premium member role.

    What if you just didn’t select the “no” part? The thing about permissions – all roles should have no permissions to start. You shouldn’t need to explicitly exclude a capability from a role. Basically if it’s not set, it is assumed it’s a “no”.

    Doing things this way, where you select “no” for specific roles can make things very complicated too. Rather than just an opt-in system, you need to account for opt-in and opt-out, which makes the logic extremely hard to follow. Which plugin is this?

    Thread Starter stephunique

    (@stephunique)

    Thank you for your reply, but you didn’t answer my question at all, which was simply whether it was possible to avoid allocating the site’s default role when a user purchases a subscription to a user role using Sure Cart (since you already stated the Surecart role is unavoidable, meaning they will have that role, and I also want to allocate them a role for making the purchase, resulting in 2 roles), and now I have to spend time to write a lengthy response to you.

    To answer your question: I am using several different plugins that determine whether a user role can have a function (not a wordpress “capability/permission”) or not. These functions are like “can this user role see others listed in a directory or not” or “should this user role be listed in the public directory” or “should this user role be featured”. This logic is actually very easy to understand and simple, which is why I am simply looking for a way for users to “buy” a subscription to a user role that would open them to all sorts of possible actions on my site. The settings in the plugins I use require you to choose an option for each user role, which would clearly result in a conflict if one user has more than one role and the roles do not have the same permissions. If the site default role is a subscriber and their permission is “this role is not listed in the directory” and a premium role (that I sell as an upgrade) “this role is listed in the directory”, and a user gets both of these roles when they sign up through SureCart (since purchasing through SureCart will result in getting the site’s default role as well as the user role they purchase through the User Roles integration, not to mention a 3rd role which is SureCart Customer or whatever it is called exactly), clearly there will be a conflict: will this user be listed or not in the directory?

    The fact that a user role starts with “no permissions” to start with, is entirely irrelevant. Most of the plugins I use are dependent on another plugin that requires setting up, so the simplest one to demonstrate the issue “Role Based Storage Limiter”. In the settings, you must allocate storage space for each user role, either a number eg 5mb 10mb or “unlimited”. If the site’s default role, no matter what it might be, is allocated 0mb, but a premium role has 10mb, and a user buys a subscription for a premium role, they will get the site’s default role and be allowed 0mb of storage and when they try to upload anything, they will fail. Meanwhile, because they bought a premium subscription, they are supposed to have 10mb of storage, so when they upload something, they can upload 10mb of files. In this case, will they be restricted or not? This is the conflict I was talking about.

    In any case, Sure Cart is not for me, so instead of continuing this thread, I will close it now.

    Plugin Author Andre Gagnon

    (@2winfactor)

    Thanks for the lengthy reply. Apologies, I was not trying to avoid your question.

    whether it was possible to avoid allocating the site’s default role 

    This is not something we do. WordPress itself requires a default role. You can certainly remove the SureCart user role if you want. But that still won’t change default WordPress functionality. I honestly don’t know how to go about doing this, which is why I was suggesting doing things in the way WordPress expects.

    The only way I would know how is just to remove all roles, but this would require custom development to ensure only the correct ones are added again.

    function remove_default_role($user_id) {
    $user = new WP_User($user_id);
    $user->set_role(”);
    }
    add_action(‘user_register’, ‘remove_default_role’);

    But not the way WordPress was designed, so your milage may very.

    Again, my apologies, I am just trying to steer you into a direction that I thought would be best, knowing how these things work under the hood.

    • This reply was modified 2 months, 3 weeks ago by Andre Gagnon.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.