Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
Last active June 23, 2019 15:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ultimatemember/d98861b4c14a1540291b to your computer and use it in GitHub Desktop.
Save ultimatemember/d98861b4c14a1540291b to your computer and use it in GitHub Desktop.
Conditionally sync UM user role based on WP role (Gravity forms)
/* This code will sync the UM role based on WP role using gravity registration */
add_action("gform_user_registered", "um_gravity_user_role_sync", 200, 4);
function um_gravity_user_role_sync($user_id, $config, $entry, $user_pass) {
$user = new WP_User( $user_id );
$wp_role = $user->roles[0];
// if WP role is subscriber, set UM role to member
if ( $wp_role == 'subscriber' ) {
update_user_meta($user_id, 'role', 'member');
}
}
@kampiamodikuesto
Copy link

This synchronization start after an online user submit GF "registration form" or only after that user is created and activated (es. after the admin reviw and/or after user email link activation?

@kampiamodikuesto
Copy link

and more important question, this code is useful to evitate to manual set same wp role for ultimate member and gravity form registration?

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