• wholebiz

    (@wholebiz)


    The User Verification “Exclude user role” feature is awesome, but I am seeking some help to make it work with Memberpress.

    Memberpress allows me to add a role upon signup. I created two roles, Pending and Activated. I want UV to send the verification email to Pending and exclude Activated.

    Unfortunately, WordPress automatically adds a default role of Subscriber. So when Memberpress adds a new role, the outcome is either:

    Subscriber + Pending, or
    Subscriber + Activated

    I am not able to apply the “Exclude user role” feature to these cases.

    1) Can you provide a snippet to remove the Subscriber role before UV runs?
    2) Or, is there a way to set the default WordPress user role to “none”?

    Thanks!!

    • This topic was modified 3 years ago by wholebiz.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Shane_O

    (@shane_o)

    Hey @wholebiz

    Here’s some code I’ve used to remove user roles.

    remove_role(‘subscriber’);

    Add them to your functions.php or site specific plugin. It only needs to run once then can be removed or commented out.

    To change the default user role, Settings => General.

    I use MP as well so I’m happy to compare notes.

    Cheers

    Thread Starter wholebiz

    (@wholebiz)

    I’ve hacked a good enough solution. In Memberpress, I have free members and paid members. I only want to run UV on free members. I figure if someone pays cash, they’re not spammers ??

    UV has exclusions that work great, but the role has to be singular. Also, the role has to be set at the start. Memberpress can add roles, but by then it’s too late in the flow. UV does its work as soon as the User is created. Memberpress only adds data after a user is created.

    This code provides the distinction I need before the user is created. The paid membership is set to ‘active’ and free is set back to the system default. Then I use UV to exclude ‘active’. Works great. Oddly, the final user shows up as ‘subscriber’ whether free or paid but the system still works the way I wanted!

    // Hijack the option, the role will follow!
    add_filter('pre_option_default_role', function($default_role){
        
        // You can also add conditional tags here and return whatever
      	if( $_POST['mepr_product_id'] == '4811' ){
        	return 'active'; // This is changed
    	} else {
    	    return $default_role; // This allows default
    	}
    });

    Hoping the UV plugin dev can give me the best answer. I feel this one is weak, even though it works ok.

    • This reply was modified 3 years ago by wholebiz.
    Shane_O

    (@shane_o)

    Thanks for letting me know. I’m not sure what you mean by the exclusions needing to be singular. I exclude multiple roles by holding down the ctrl (cmd) key and selecting the roles to be excluded.

    Anyway, I have someone working on a way to copy the metadata (which doesn’t trigger any webhooks) to a custom field that will.

    Thread Starter wholebiz

    (@wholebiz)

    Yes, there is multiple selection in the exclusion box, but here is my issue. The default role in WordPress is Subscriber. I want UV to only exclude Paid members. If I exclude Subscriber, that would also exclude free members. My solution above removes the default role, allowing UV to exclude the singular role I assign to Paid members.

    Also, the action done by UV to exclude is made upon creation of the User which is upstream from creating the Memberpress member. The above code allows me to know the Memberpress membership type ahead of the creation of the user, and then remove the Subscriber role and assign the Active role ahead of creating the User if the customer purchased the paid membership.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Delete Default WordPress Role before running User Verification’ is closed to new replies.