0

I am an newbie to wordpress php. I added a custom form field "Display name" and set as nickname value which let user to change their display name.

however below code did save and change all the user in same nickname. i understand the problem is i put nickname in everywhere but i dont know how to fix it and become normally. My goal: user able to change their nickname and all the other user showing their own nickname normally.

    /****** update nickname field with the value of display-name ******/

// New fields at the beginning of the 'Registration Data' section

add_action( 'wpjobster_before_user_profile_registration_fields_action', 'wpj_user_settings_new_fields_registration_beginning_fnc', 10, 1 );
function wpj_user_settings_new_fields_registration_beginning_fnc( $user_id ) { ?>
    <div class="field field16-class">
        <label><?php echo __( 'Display Name', 'wpjobster' ); ?></label>
        <div class="input-relative">
            <input type="text" name="nickname" value="<?php echo empty( $_POST['nickname'] ) ? stripslashes( user( $user_id, 'nickname' ) ) : stripslashes( $_POST['nickname'] ); ?>" placeholder="<?php _e( 'Display Name', 'wpjobster' ); ?>" />
                
        </div>
    </div>

<?php }


// Save fields to database
add_action( 'wpjobster_user_profile_extra_fields_update', 'wpj_user_settings_new_fields_registration_beginning_save_fnc', 10, 1 );
function wpj_user_settings_new_fields_registration_beginning_save_fnc( $user_id ) {
    update_user_meta( $user_id, 'nickname', WPJ_Form::post( 'nickname' ) );
}


/******** User display name ********/
add_filter( 'wpj_display_name_publicly_filter', 'custom_display_name_publicly_filter' );
function custom_display_name_publicly_filter( $uid ) {

$op_type = get_option( 'wpjobster_display_name_publicly' );

$nickname = get_user_meta( wp_get_current_user()->ID, 'nickname', true );

    if  ( $op_type == 'display_name' ) {
        $userdata = array(
            'ID' => $user->ID,
            'nickname' => $nickname,
            'display_name' => $nickname,
        );
    } 
    
 
    wp_update_user( $userdata );
    return $nickname ;
    
}

would somebody please give me advise and help with this problem please? thank you all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.