Assign role based on membership

I have three paid memberships. I want to assign contributor role to my members but not when they just register but when they make the payment. The role also should be assigned when I manually add them from dashboard.

Any help is appreciated.

  • Predrag Dubajic
    • Support

    Hi Shannon,

    Apologies for the delay here.

    I'm afraid that M2 at this moment can only assign capabilities but not complete roles.
    I had a chat with one of our dev guys and they say that it should be possible to create a workaround for this but it would require some additional development so I've created a task for our second level support dev guys to check this out.

    Best regards,
    Predrag

  • Shannon Routley
    • Design Lord, Child of Thor

    Thank you very much for looking into this. I'm just being ultra paranoid. I've had a web site hacked where a ton of basic subscribers were created and then exploited and given I have a support system on this site, I don't want scripted users gaining access to the support system.

    Cheers,

  • Adam Czajczyk
    • Support Gorilla

    Hello, Shannon!

    I can understand that :slight_smile: As my colleague, Predrag has already asked our second line support team what could we do about it, we'll let you know when we get a response from them. Please note though that this might take a while.

    If you feel like doing some coding by yourself meanwhile, you could try to craft some solution based on Membership 2 Pro API and core WP functions. A "wp_update_user()" function should let you set a user role and it could be triggered by one of the M2P API functions. You'll find docs of API in the plugin on "Membership 2 -> Help -> API Docs" page.

    Best regards,
    Adam

  • Ash
    • WordPress Hacker

    Hello there

    You can try the following code:
    Assign role based on WPMU membership: https://gist.github.com/bappi-d-great/794bd6a18eecb59f8f27

    Remove role and assign subscriber role to the user or membership cancel: https://gist.github.com/bappi-d-great/cf1c337e5b7cdba77eb3

    You can use this code in your theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.