Memberpress: how to add users to groups upon Sign up

Try this. I haven’t tested it, so there could be errors. It’s worth having this as a reference. Let me know if it doesn’t work.

add_filter( 'wpdc_sso_params', 'wpdc_custom_sso_params' );
function wpdc_custom_sso_params( $params ) {
    $add_groups = array();
    $remove_groups = array();

	if ( current_user_can( 'mepr-active','memberships:48259,48238' )  ) {
		$add_groups[] = 'TransformPlus';
	} else {
		$remove_groups[] = 'TransformPlus';
	}

	if ( current_user_can( 'mepr-active','memberships:47303,47305' )  ) {
		$add_groups[] = 'Transform';
	} else {
		$remove_groups[] = 'Transform';
	}

	if ( current_user_can( 'mepr-active','memberships:47299,47301' )  ) {
		$add_groups[] = 'JoinLive';
	} else {
		$remove_groups[] = 'JoinLive';
	}

	if ( current_user_can( 'mepr-active','memberships:47295,47297' )  ) {
		$add_groups[] = 'CreativeLicense';
	} else {
		$remove_groups[] = 'CreativeLicense';
	}

	if ( current_user_can( 'mepr-active','memberships:47281' )  ) {
		$add_groups[] = 'ForeverFree';
	} else {
		$remove_groups[]  = 'ForeverFree';
	}

	$params['add_groups'] = join( ',', $add_groups );
	$params['remove_groups'] = join( ',', $remove_groups );

	return $params;
}

Use backticks to create codeblocks to get syntax highlighting. See Markdown Tutorial - Code

7 Likes