User role assignment via PHP
-
Hi all,
Someone previously helped me with some code to assign someone a UM role based on their age when they registered on my site.
Im trying to update that code so it uses the account update hook instead. However, I can’t seem to get it to work. The only code I’ve changed is the first few lines after i found a hook on the support pages. Im not very good with PHP, so just wondering if someone was able to help me tweak it so it works?
Here’s the page I got the hook from:
https://docs.ultimatemember.com/article/1290-umuserafterupdatingprofile
Here’s the code
// Account update hook //
add_action( ‘um_user_after_updating_profile’, ‘my_user_after_updating_profile’, 10, 1 );
function my_user_after_updating_profile($this_id, $submitted ) {// code used from registration script…
$age = $submitted[‘age’];
$level = $submitted[‘player_level’];
$user = get_user_by(’email’,$submitted[‘user_email’]);
// remove um_player-sponsorship-application
$u = new WP_User( $user->ID );
// Remove role
$u->remove_role( ‘um_player-sponsorship-international’ );if($age>=16 && $level==’International’)
{
// Add role
$u->add_role( ‘um_player-sponsorship-international-16-or-over’ );
um_fetch_user($user->ID);
}else
if($age<=15 && $level==’International’)
{
// Add role
$u->add_role( ‘um_player-sponsorship-international-15-or-under’ );
um_fetch_user($user->ID);
}else
if($age<15 && $level!=’International’)
{
// Add role
$u->add_role( ‘um_player-sponsorship-level-1′ );
um_fetch_user($user->ID);}
else if($age>=15 && $age<=17 && $level!=’International’)
{$u->add_role( ‘um_player-sponsorship-level-2′ );
um_fetch_user($user->ID);}
else if($age>=18 && $age<=23 && $level!=’International’)
{$u->add_role( ‘um_player-sponsorship-level-3′ );
um_fetch_user($user->ID);}
else if($age>24 && $level!=’International’)
{
$u->add_role( ‘um_player-sponsorship-level-4’ );um_fetch_user($user->ID);
}
}`
- The topic ‘User role assignment via PHP’ is closed to new replies.