I’m trying to use this function:
function add_custom_role_to_registration_form() {?>
<input type="hidden" name="custom_role" value="my_role">
<?php
}
add_action( 'register_form', 'add_custom_role_to_registration_form' );
But I cannot pass this custom_role to:
function set_custom_role_on_registration( $user_id ) {
$custom_role = isset( $_POST['custom_role'] ) ? $_POST['custom_role'] : '';
$user = get_user_by( 'ID', $user_id );
$user->remove_role( 'subscriber' );
if ( $custom_role === 'my_role' ) {
$user->add_role( 'my_role' );
}else{
$user->add_role( 'my_role_2' );
}
wp_insert_user($user);
}
add_action( 'user_register', 'set_custom_role_on_registration' );
The first part of adding the hidden field to the form is not working, I’m using the Hiveress registration form, do you know other way of passing the role on form, so when I´m registering the user I can choose which profile I will give him?
Regards