WordPress.org

Ready to get started?Download WordPress

Forums

Paid Memberships Pro
[resolved] Is there a way to set one of the user levels to contributor? (6 posts)

  1. cornerstone123
    Member
    Posted 1 year ago #

    Is there a way to set one of the user levels to contributor rather than as subscribers?

    I'm comfortable editing the function.php file if you know the code to add this function of allowing the plugin to also set the User levels of membership. Or, am I missing something in the plugin that allows for this as is?

    Thanks for the help.

    -B

    http://wordpress.org/extend/plugins/paid-memberships-pro/

  2. woutm
    Member
    Posted 1 year ago #

    I'm not sure if this is what you mean:

    If you want you assign a certain user role (e.g. contributor, editor or subsciber), to users of a particular level, than you can add something like this to your funtion.php file:

    <?php
    /*
    	This code will make members signing up for membership level #2 premium:memeber and make them normal bbp_participant when they cancel.
    */
    function my_pmpro_after_change_membership_level($level_id, $user_id)
    {
    	if($level_id == 2)
    	{
    		//New member of level #2.
    		$wp_user_object = new WP_User($user_id);
    		$wp_user_object->set_role('contributor');
    	}
    	else
    	{
    		//Not a member of level #2
    		$wp_user_object = new WP_User($user_id);
    		$wp_user_object->set_role('subscriber');
    	}
    }
    add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 2);
    ?>

    It will assign contributor role to members of level 2, and subscriber role to member of other levels.

    I use this code to assign a certain role to members of level 2 and and a different role to the other level.
    Hope this is what you're looking for...

  3. strangerstudios
    Member
    Plugin Author

    Posted 1 year ago #

    Woutm got it right. (Thanks!)

    FWIW, here is similar code for assigning the "author" role from our website:
    http://www.paidmembershipspro.com/2011/10/give-new-members-author-role/

  4. 1Dog
    Member
    Posted 1 year ago #

    I'd like to set two membership levels to 'Contributor.' The code above works for converting one level, but I can't seem to get it to work for two.

    Appreciate the help.

  5. woutm
    Member
    Posted 1 year ago #

    I think you can simply change the IF condition.
    You should look up the level id`s of the membership levels you want to set to 'Contributor' and add them in the IF statement.
    e.g. for level id 2 and 3:
    if($level_id == 2 || $level_id == 3 )

  6. 1Dog
    Member
    Posted 1 year ago #

    Thank you.

    I'm not sure what I did wrong. Thought I had tried your solution, but obviously missed something. Now it works.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic