INTEGRATION OF CLASSIFIEDS and DIRECTORY plugin with MEMBERSHIP 2 (user roles)

Where we are: we have Membership 2 Pro(Network activated), MarketPress (Network Activated/Non-Global Cart), Pro Sites (Network Activated) and we have Classifieds (classifieds.sxdi.org) and Directory (sponsors.sxdi.org) Plugin activated locally on their own subdomain.

Here is what we are trying to do: The Directory, Classifieds and Pro Sites documentation all said to use a standard naming convention for user roles, we are trying to figure out if Membership 2 Pro can control those user roles and if 1.that is the best way to accomplish the requirements by the plugin; as in should we create user roles within Classifieds, Directory and Pro Sites that mirror our memberships and in so doing, will that membership type become the user role. or...
2. We need to go in and use a different plugin (any recommendations?) to create and author new user roles and
3. if we do that, can we have membership 2 Pro assign a user role to a specific membership.

  • Kasia Swiderska

    Hello Jonathan,

    as in should we create user roles within Classifieds, Directory and Pro Sites that mirror our memberships and in so doing, will that membership type become the user role.

    No, that will not happen. Memberships are not related to roles and it doesn't matter if role name is the same as membership. Membership does not add or change roles of users.

    2. We need to go in and use a different plugin (any recommendations?) to create and author new user roles and

    Yes, you need additional plugin to create new roles.You can use this one https://wordpress.org/plugins/members/

    if we do that, can we have membership 2 Pro assign a user role to a specific membership.

    Not out of the box because Membership can only add capabilities with Capabilities add-on. But it is possible with this code snippet: https://gist.github.com/bappi-d-great/794bd6a18eecb59f8f27 - you need to change code so it will include name of your custom role and ID of your memberships.

    Let me know of you have more questions.

    kind regards,
    Kasia

  • Nithin

    Hi Jonathan,

    Hope you are doing good today. :slight_smile:

    One more question... Where (as in what file should I put that code snippet?)

    You can add the following code as a mu-plugins, copy the code, and save it as a php file(for eg: test.php). Using an FTP client, place this file inside the /wp-content/mu-plugins folder. This will activate the code in your website. Please check this link for more details about mu-plugins: https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Or, you could also implement the code in your themes functions.php file. Please do note to make changes to a theme using a child theme.

    I hope this helps. Please let us know if you still need any further assistance. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Nithin

    Hi Jonathan,

    Hope you are doing good today. :slight_smile:

    I'm sorry but we cannot access your server through dashboard unless a plugin is being used for such thing, also I don't see the theme editor to be enabled either, so I cannot see a way to implement these. Please advise if I'm missing out anything.

    I checked the above code in my system, and it seems to work fine. Did you change the membership id's to yours?

    <?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 899:
    			$user->set_role( 'editor' );
    			break;
    
    		case 921:
    			$user->set_role( 'author' );
    			break;
    
    	}
    }

    I just added a example code, according to your membership id. Since I don't know what all roles you want for your membership, I just gave a random one for the time being, please change it accordingly.

    Here 899 is the memberishp id for SXDI Educator, which has been assigned the user role of Editor, and Id 921would be SXDI Visitor membership with Authors role. Please test these, and check whether it's working.

    Please let us know if you still have any issues, so that we could give a closer look. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Jonathan

    First: Thank you.

    I cannot express how grateful I am for WPMUDev and the example you set in actually helping.

    I have placed the user login to server in the dashboard access on the site and granted access... Here is the code that i have installed in my WPMU Folder ... Just cant figure it out.
    `<?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 723:
    $user->set_role( ‘SXDI Student’ );
    break;

    case 724:
    $user->set_role( ‘SXDI Student’ );
    break;

    case 725:
    $user->set_role( ‘SXDI Professional’ );
    break;
    case 726:
    $user->set_role( ‘SXDI Professional’ );
    break;
    case 727:
    $user->set_role( ‘SXDI VIP’ );
    break;
    case 728:
    $user->set_role( ‘SXDI VIP’ );
    break;
    case 729:
    $user->set_role( ‘SXDI Trustee’ );
    break;
    case 854:
    $user->set_role( ‘SXDI Trustee’ );
    break;
    case 898:
    $user->set_role( ‘SXDI Recruiting’ );
    break;
    case 899:
    $user->set_role( ‘SXDI Educator’ );
    break;
    case 853:
    $user->set_role( ‘SXDI Immortal’ );
    break;
    case 922:
    $user->set_role( ‘SXDI Beta One’ );
    break;
    case 921:
    $user->set_role( ‘SXDI Visitor’ );
    break;
    case 923:
    $user->set_role( ‘SXDI Blogger’ );
    break;
    case 924:
    $user->set_role( ‘SXDI Blogger Pro’ );
    break;

    }
    }

    I am stumped!

  • Nithin

    Hi Jonathan,

    Hope you are doing good today. :slight_smile:

    I have placed the user login to server in the dashboard access on the site and granted access...

    I'm afraid, I don't see any user login in the dashboard access, am I missing something?

    Thank you for sharing the code, I have corrected the following code, the custom user roles has a prefix, you can see that under Users > Roles. I have made the following correction, and it should be working this time. Please make sure you add the code inside /mu-plugins folder as a file, if you create a new folder inside it, it'll not work.

    <?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 723:
    		case 724:
    			$user->set_role( 'sxdi_student' );
    			break;
    
    		case 725:
    		case 726:
    			$user->set_role( 'sxdi_professional' );
    			break;
    
    		case 727:
    		case 728:
    			$user->set_role( 'sxdi_vip' );
    			break;
    
    		case 729:
    		case 854:
    			$user->set_role( 'sxdi_trustee' );
    			break;
    
    		case 898:
    			$user->set_role( 'sxdi_recruiting' );
    			break;
    
    		case 899:
    			$user->set_role( 'sxdi_educator' );
    			break;
    
    		case 853:
    			$user->set_role( 'sxdi_immortal' );
    			break;
    
    		case 922:
    			$user->set_role( 'sxdi_beta_one' );
    			break;
    
    		case 921:
    			$user->set_role( 'sxdi_visitor' );
    			break;
    
    		case 923:
    			$user->set_role( 'sxdi_blogger' );
    			break;
    
    		case 924:
    			$user->set_role( 'sxdi_blogger_pro' );
    			break;
    
    	}
    }

    This code should be working, if you still have issues, you could send us your credentials by using our secure contact form: http://premium.wpmudev.org/contact/

    Select "I have a different question" for your topic.

    - To Mark to my attention, the subject line should contain only: ATTN: Nithin Ramdas
    -WordPress admin username(master, and subsite)
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password) (master, and subsite)
    -link back to this thread for reference
    -any other relevant urls

    Have a nice weekend. :slight_smile:

    Kind Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.