labsecrets
3/2/2015 - 5:15 AM

Paid Memberships Pro - Set Default WP Role to Membership Levels

Paid Memberships Pro - Set Default WP Role to Membership Levels

function assign_pmpro_level_to_role($user_id, $role, $old_roles)
{
	global $current_user;
	//checks if the user doesn't have a membership level yet			
	if(!$current_user->ID) {

		//we found a role related to pmpro level
		if($role == "customer")
		{
			pmpro_changeMembershipLevel(20, $user_id); //gives default customers the level 20 free registration membership
		}
		elseif($role == "administrator")
		{
			pmpro_changeMembershipLevel(10, $user_id); //gives admin role registrants the all access level 10 membership
		}
	}
}
 
add_action('set_user_role', 'assign_pmpro_level_to_role', 10, 3);