Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created February 18, 2014 16:11
Show Gist options
  • Save strangerstudios/9073990 to your computer and use it in GitHub Desktop.
Save strangerstudios/9073990 to your computer and use it in GitHub Desktop.
Assign a Paid Memberships Pro level based on user role when user roles are updated.
function assign_pmpro_level_to_role($user_id, $role, $old_roles)
{
//we found a role related to pmpro level
if($role == "pmpro_level_1")
{
pmpro_changeMembershipLevel(1, $user_id);
}
elseif($role == "administrator")
{
pmpro_changeMembershipLevel(2, $user_id); //setup level 2 as an all access role or just give them level 1
}
else
{
//default to no level
pmpro_changeMembershipLevel(0, $user_id);
}
}
add_action('set_user_role', 'assign_pmpro_level_to_role', 10, 3);
@gitdavidhunter
Copy link

What file do you put this snippet in ? /pmp/includes/functions.php ?

@MCombrinck
Copy link

@gitdavidhunter, were you successful with uploading this to the pmp/includes/functions.php file?

@demeillon
Copy link

Thank you very much! Works like a charm

@FilipeOS
Copy link

FilipeOS commented Oct 29, 2018

Hi guys,

Sorry but this code is ready to be used or we need to update it to match our 3 memberships?

Also, can we add on theme functions.php?

Thank you

@darrennye
Copy link

David can I reach you via email somewhere? I have a more detailed question.

nye@nyetech.com

@Jazzykhan
Copy link

where to put this file?

@cozzie49
Copy link

This worked great, thanks so much! This works fine by putting it in your theme functions.php file --> wp-content/themes/your-theme-name/functions.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment