Skip to content

Instantly share code, notes, and snippets.

@mattneal-stafflink
Created June 2, 2021 23:34
Show Gist options
  • Save mattneal-stafflink/9613dbe8d109940b600aed4e487e9461 to your computer and use it in GitHub Desktop.
Save mattneal-stafflink/9613dbe8d109940b600aed4e487e9461 to your computer and use it in GitHub Desktop.
Assigns a newly registered user to a LearnDash group. Must be registered through a gravity forms form.
<?hp
/**
* Assign the user to their selected groups. Comment out what is not used where possible.
* usage: ld_update_group_access('Id of user (found in $user_id), 'id of group:bool (enter manually after creating group', false);
* $entry[7] is the form line 7. In this case, it is a single select drop down.
*
* @since 1.0.0
*/
add_action( 'gform_user_registered', 'update_user_groups', 10, 4 );
function update_user_groups( $user_id, $feed, $entry, $user_pass ) {
switch ($entry[7]) {
case "property_manager":
ld_update_group_access( $user_id, 298, false );
break;
case "sales":
ld_update_group_access( $user_id, 299, false );
break;
case "offshore":
//ld_update_group_access( $user_id, GROUP_ID_HERE, false );
break;
case "finance":
//ld_update_group_access( $user_id, GROUP_ID_HERE, false );
break;
case "marketing":
//ld_update_group_access( $user_id, GROUP_ID_HERE, false );
break;
case "hr":
// ld_update_group_access( $user_id, GROUP_ID_HERE, false );
break;
case "administration":
// ld_update_group_access( $user_id, GROUP_ID_HERE, false );
break;
default:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment