Question about register

  • Author
    Posts
  • Peter John

    Hi I have a question about the register proces.

    If you would like to make account you will see a registerform with username/email and password. After this process you could see the settings of your account. How could you remove first name and last name from this form. It also show at the section settings. I only want to display the nickname for a profile.

    This also for the Google sign up, when they sync with a Google account. The account shows the name of the Google account but I would like to have the nickname shown from the person. Could you help me out with this? How can the person edit this to a nickname?

    ihordeveloper

    I guess the easiest way is hiding the last name and renaming the first name field to “nickname”. Please try using this code snippet:

    add_filter(
    	'hivepress/v1/forms/user_update',
    	function( $form ) {
    		$form['fields']['first_name']['label'] = 'Nickname';
    		$form['fields']['last_name']['type']   = 'hidden';
    
    		return $form;
    	}
    );
    Peter John

    @ihor, thank you but it didn’t work with the code that you has send me because there was already a current field in WordPress that’s required ”Nickname”. I used this code and it works.

    add_filter(
    ‘hivepress/v1/forms/user_update’,
    function( $form ) {
    $form[‘fields’][‘first_name’][‘label’] = ‘Profilename’;
    $form[‘fields’][‘last_name’][‘type’] = ‘hidden’;

    return $form;
    }
    );`

    `add_action (‘admin_head’,’make_display_name_f_name_last_name’);
    function make_display_name_f_name_last_name(){
    $users = get_users(array(‘fields’=>’all’));
    foreach($users as $user){
    $user = get_userdata($user->ID);
    $display_name = $user->first_name;
    if($display_name!=’ ‘) wp_update_user( array (‘ID’ => $user->ID, ‘display_name’ => $display_name) );
    else wp_update_user( array (‘ID’ => $user->ID, ‘display_name’ => $user->display_login) );
    if($user->display_name == ”)
    wp_update_user( array (‘ID’ => $user->ID, ‘display_name’ => $user->display_login) );
    }
    }

    I changed nickname to ”profilename” but there is only one question left about this subject. How can I changed it to mandatory instead of optional?

    ihordeveloper

    Please try using another code snippets because this one will update the user on every page refresh (“admin_head” action is loaded on every admin page), and it will not work for the front-end users. If you use HivePress API you can make a field required by setting “required” property to “true”.

    Peter John

    Okay, do you have a code snippet which I can use?

    Also I couldn’t find the settings where you could change it to true. Could you help me out?

    ihordeveloper

    I’m sorry, but customizations are not part of support. The code snippet suggested above should work fine, if you have the display name set to “first name” in HivePress/Settings/Users/Display section (in this case first name will always be set as display name for users, so you can simple rename this field to “nickname”).

    Peter John

    @Ihor I changed it and it works now! But only the last thing how could I remove optional from the form? First name (optional)

    ihordeveloper

    Please try passing 'required' => true, parameter for this field, then it will be required.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Subscribe

Sign In

Don't have an account? Register

Forgot password?

Register

Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.