Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Last active July 25, 2019 10:55
Show Gist options
  • Select an option

  • Save patrickposner/286d12e7ef384a1dbb9029e2b2efd603 to your computer and use it in GitHub Desktop.

Select an option

Save patrickposner/286d12e7ef384a1dbb9029e2b2efd603 to your computer and use it in GitHub Desktop.
add custom user meta fields to profile
add_action( 'show_user_profile', 'add_kdnr_field' );
add_action( 'edit_user_profile', 'add_kdnr_field' );
function add_kdnr_field( $user ) { ?>
<table class="form-table">
<tr>
<th><label for="address">Kundennummer</label></th>
<td>
<input type="text" name="kdnr" id="kdnr" value="<?php echo esc_attr( get_the_author_meta( 'kdnr', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Bitte füge deine Kundennummer ein.</span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_kdnr_field' );
add_action( 'edit_user_profile_update', 'save_kdnr_field' );
function save_kdnr_field( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta( $user_id, 'kdnr', $_POST['kdnr'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment