Membership ROLES

I’ve been hassling and researching 2 days to fix this simple problem by trying ALL possible combinations (without changing or modifying codes).

Here’s what I’m trying to do.

WITHOUT your plugin, I have created 4 roles that each has automated a coupon code attached to.

-Gold 10%

-Platinum 15%

-Diamond 30%

-Evarnia 50%

Everything works great, BUT I installed membership 2 pro for me to be able to sell these 4 roles. Now when I make 4 membership types (Gold, Platinum, Diamond and Evarnia) it doesn’t change the buyer’s role to those specific roles I put.

WHY I need this, you may ask?

Because with your plugin, the role of registered users are registered as default (Subscriber) The plugin forces me to ALLOW subscribers, because if not, it won’t be applied to any members. All I need is to give exclude subscribers. I want to sell the ROLES, not only their capabilities.

  • Kasia Swiderska
    • Support nomad

    Hello Evarnia,

    Yes, this code snippet here https://premium.wpmudev.org/forums/topic/auto-assign-wp-role-at-registration-based-on-membership-level#post-923763 is correct one.

    As you can see there is explanation how to change it depending on the memberships ID and User roles names (you will need to use slug for user role not full Name like Gold 10%).

    You can get Membership ID on memberships list

    Here is the same snippet https://gist.github.com/bappi-d-great/794bd6a18eecb59f8f27 but more readable.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    http://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Let me know of you have more questions.

    kind regards,

    Kasia

  • Kasia Swiderska
    • Support nomad

    Hello Evarnia,

    I'm afraid we do not provide support over the phone. Only forum and live chats https://premium.wpmudev.org/live-support/

    Please check Ash answer here https://premium.wpmudev.org/forums/topic/auto-assign-wp-role-at-registration-based-on-membership-level#post-923763 on what part of code snippet you need to edit so it will work on your site. Please also see this screenshot

    I hope it will make easier to edit code snippet.

    If you still having difficulties with editing that code, I can help if you give me list of your memberships ID and corresponding roles. If you are not sure how to get them would you mind allowing support access so I can check them directly on your site?

    To enable support access you can follow this guide here:

    http://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    kind regards,

    Kasia

  • Evarnia
    • WPMU DEV Initiate

    It works perfectly. Thank you very much. But there's one dangerous bug…

    I either need to remove pending option (which I don't know how to)

    Or is "pending" a sort of hidden membership ? is there an ID to it so I can put it to default by the code you sent me?

  • Kasia Swiderska
    • Support nomad

    Hello Evarnia,

    Pending is a state of membership: it means that member awaits for his subscription to be activated. Can you describe how you applied solution with default membership? You created default one, added role to it (role without access) and then you modified code snippet? Can you show me your code snippet?

    I’ve tested now solution with Default Membership and it worked – until my test member didn’t go though the payment (even paid membership was pending) it has role of default membership. But Multiple Membership add-on has to be disabled.

    kind regards,

    Kasia

  • Evarnia
    • WPMU DEV Initiate

    It still doesn’t work. Once there’s a pending membership, the user’s role is automatically changed to that pending role. (They are not added in the member list, but they have the role and the capabilities)

    I cannot send the code snippet right now. But I am positive that I did a good job because the automated roles are in function.

    I did all as said before on the other post. It worked great. With the membership ID and everything. Then I realized the little hole (pending). I then created a new defeault role and went in the PHP file to set a role for the default aswell. But I’m still having same results. Can I know the pending’s ID so I could include it in the PHP file? The same way as i did the others.

  • Kasia Swiderska
    • Support nomad

    Hello Evarnia,

    There is no pending ID – that is state of subscription, like active or expired. I was able to confirm what is happening with the pending state and roles but I was albo able to make that working with default membership and disabled add-on multiple memberships.

    That is why I’m asking for your snippet code and if possible support access so I could check that on your site if its configured the same way as on my site.

    To enable support access you can follow this guide here:

    http://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    kind regards,

    Kasia

  • Evarnia
    • WPMU DEV Initiate
    <?php

    add_action( 'ms_model_relationship_create_ms_relationship_before', 'ms_controller_member_assign_memberships_done_cb', 99, 4 );
    function ms_controller_member_assign_memberships_done_cb( $membership_id, $user_id, $gateway_id, $move_from_id ) {
    $user = new WP_User( $user_id );
    switch( $membership_id ){
    case 946:
    $user->set_role( 'gold' );
    break;

    case 947:
    $user->set_role( 'platinum' );
    break;

    case 948:
    $user->set_role( 'diamond' );
    break;

    case 949:
    $user->set_role( 'evarnia' );
    break;

    case 1015:
    $user->set_role( 'free' );
    break;

    }
    }
    function func_ms_model_relationship_cancel_membership_after( $ms_model_relationship, $generate_event ){

    $user = new WP_User( $ms_model_relationship->user_id );
    switch( $ms_model_relationship->membership_id ){
    case 1015:
    $user->set_role( 'free' );
    break;

    case 946:
    $user->set_role( 'free' );
    break;

    case 947:
    $user->set_role( 'free' );
    break;

    case 948:
    $user->set_role( 'free' );
    break;

    case 949:
    $user->set_role( 'free' );
    break;

    }
    }
    add_action('ms_model_relationship_cancel_membership_after', 'func_ms_model_relationship_cancel_membership_after', 10, 2);

    ID 1015 is the Default membership. I tried again, still the same problem. I also gave access.

  • Kasia Swiderska
    • Support nomad

    Hello Evarnia,

    Please change snippet code so it looks like that:

    <?php

    add_action( 'ms_model_relationship_create_ms_relationship_before', 'ms_controller_member_assign_memberships_done_cb', 99, 4 );
    function ms_controller_member_assign_memberships_done_cb( $membership_id, $user_id, $gateway_id, $move_from_id ) {
    $user = new WP_User( $user_id );
    switch( $membership_id ){
    case 946:
    $user->set_role( 'gold' );
    break;

    case 947:
    $user->set_role( 'platinum' );
    break;

    case 948:
    $user->set_role( 'diamond' );
    break;

    case 949:
    $user->set_role( 'evarnia' );
    break;

    case 1015:
    $user->set_role( 'free' );
    break;

    }
    }

    this is only part it should be there. Let me know when you change code and I will do more testing o your site.

    kind regards,

    Kasia

  • Evarnia
    • WPMU DEV Initiate

    It still doesn’t work. My coupons are all placed in woocommerce. Limiting certain roles to use them.

    That being said, after when I choose any plan AND NOT PAY, it becomes pending and when its pending, the user’s role changes to the plan’s role in the backend. Although, the user is not added in the member’s list (which is good). But they still get access to the coupon discount because of the role’s change in “Users”

    (And the reason why I don’t use Membership 2 pro’s coupons, is because with woocommerce coupons I can set many different limitations and have a lot more options that I NEED)

  • Kasia Swiderska
    • Support nomad

    Hello Evarnia,

    I’m sorry that your admin account get blocked.

    We are processing our thread in queue from older to newer and posting few days in row actually puts your thread lower in our queue – that can cause delays in our answers.

    I’m sorry I wasn’t able to help more – I did tested that solution on my site and it was working correctly. Because Membership 2 Pro did not have option to change user roles that quick code was developer so this is not something we can report as bug.

    kind regards,

    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.