I don’t know how “Cimy User Extra Fields” works, but you can add fields to the user registration page with:
function extra_user_profile_fields_wpse_92164() {
echo '<label for="extra_field">',_("Extra Field").'</label>';
echo '<input type="text" name="extra_field" value="" size="25" id="extra_field" />';
}
add_action( 'register_form', 'extra_user_profile_fields_wpse_92164' );
To switch subscriber types you could pass in $_GET
parameters, which is how the default wp-login.php
forms works. So…
function extra_user_profile_fields() {
if (!isset($_GET['utype'])) return false;
echo '<input type="hidden" name="register_as" value="'.esc_attr($_GET['utype']).'" />';
if ('subscriber' == $_GET['utype']) {
echo '<label for="extra_field_sub">',_("Extra Field Subscriber").'</label>';
echo '<input type="text" name="extra_field_sub" value="" size="25" id="extra_field_sub" />';
} else {
echo '<label for="extra_field">',_("Extra Field").'</label>';
echo '<input type="text" name="extra_field" value="" size="25" id="extra_field" />';
}
}
add_action( 'register_form', 'extra_user_profile_fields' );
Now you can pass data to the form like: http://example.com/wp-login.php?action=register&utype=subscriber
You can then save the date pretty much as demonstrated in the Codex for the user_register
hook.
function myplugin_registration_save($user_id) {
if ( isset( $_POST['extra_field'] ) ) {
update_user_meta($user_id, 'extra_field', $_POST['extra_field']);
}
if ( isset( $_POST['extra_field_sub'] ) ) {
update_user_meta($user_id, 'extra_field_sub', $_POST['extra_field_sub']);
}
// alter the user Role
if ('subscriber' == $_POST['register_as'] || 'contributor' == $_POST['register_as']) {
wp_update_user(array('ID'=>$user_id,'role'=>$_POST['register_as']));
}
}
add_action('user_register', 'myplugin_registration_save');
Warning
Consider this code ‘beta’. I wrote the function to only allow role changes to ‘contributor’ or ‘subscriber’ which are low-permission roles, but the function could stand better data validation before being put into service.