Last active
July 25, 2019 10:55
-
-
Save patrickposner/286d12e7ef384a1dbb9029e2b2efd603 to your computer and use it in GitHub Desktop.
add custom user meta fields to profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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