0
votes

I work with some registration panel, and when the user checked radio button "Customer" i want to change his role from "Pending Vendor" to "Customer". How user roles can be changed depending on what is checked?

Fields that i want to target are BuddyPress Xprofile fields, i don't know if that is important, just to mention

1

1 Answers

0
votes

In case of registration, the code should be something like this:

function updateUser( $user_id) {
    // print_r($_POST) just to make sure that all our data is received.
    if ( isset( $_POST['<YOUR_USER_ROLE_FIELD_NAME>']) ) {
        update_user_meta($user_id, 'role', sanitize_text_field($_POST['<YOUR_USER_ROLE_FIELD_NAME>']));
    }
}
add_action('user_register', 'updateUser', 10, 1);

If there has been an override on user registration hook because of buddypress or any other plugin that you may have installed, your user registration hook might be different,