I added a custom field to the profile-page of WordPress users called "uidnumber" and it reads values from the database just fine, however it just doesn't save anything.
I'd rather save it in wp_users instead if I could because the whole table is just that much more clear, however from what I've read, WordPress updates could delete custom columns.
Here's what I got in my functions.php
:
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id )
{
update_user_meta( $user_id,'uidnumber', sanitize_text_field( $_POST['uidnumber'] ) );
}
and here's the field itself :
<p class="form-row form-row-wide">
<label for="uidnumber"><?php _e( 'UID-Nummer', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="uidnumber" id="uidnumber" value="<?php echo esc_attr( $user->uidnumber); ?>" />
</p>
I have no idea why it won't save this field, while another one I coded into the "contact_methods
", works like a charm.
edit01:
I tried what you told me, still doesn't save unless I put it in the wrong place.
<p class="form-row form-row-wide">
<label for="uidnumber"><?php _e( 'UID-Nummer', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="uidnumber" id="uidnumber" value="<?php echo get_user_meta( $user->ID, 'uidnumber', true ); ?>" />
</p>
Or did you mean to put it in my save function? (As you mentioned value I assumed otherwise)
edit02: I think my main problem is that what you specified in your "show"-function
is actually inside another file in my case: form-edit-account.php
So I can't just use your "show_extra_profile_fields" function.
Also one thing that seems to be misunderstood: I want the user (normal user on WordPress) to be able to add his own text. That's the only reason I'm doing this. Personally I can add a UID-Number in the backend just fine. However that means I have to find out the UID for each and every user myself.
edit03:
functions.php - Here only the last couple lines are actually relevant.
$user->uidnumber
set (in the<input>
's value attribute)? Tryget_user_meta( $user->ID, 'uidnumber', true )
instead...