Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Assign user role based on field choice
- add_action("gform_user_registered", "add_custom_user_meta", 10, 4);
- function add_custom_user_meta($user_id, $config, $entry, $user_pass) {
- //Assign the role from form entry 6 on registration
- $user_obj = new WP_User( $user_id );
- $user_obj->set_role( $entry[6] );
- }
- // Update user role based on field choice
- add_action( 'gform_user_updated', 'change_role', 10, 4 );
- function change_role( $user_id, $user_config, $entry, $user_pass ) {
- $user_obj = new WP_User( $user_id );
- if(!empty($entry[6])) {
- //Assign the role from form entry 6 on registration
- $user_obj->set_role( $entry[6] );
- } else {
- //If nothing is chosen, keep the old role
- $user_obj->set_role($user_obj->roles[0]);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement