Last active
March 24, 2016 09:12
-
-
Save frozzare/47375e238597b324a955 to your computer and use it in GitHub Desktop.
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
<?php | |
function render_user_profile_fields( WP_User $user ) { | |
$twitter = get_user_meta( $user->ID, 'twitter', true ); | |
?> | |
<h3>Custom user info</h3> | |
<table class="form-table"> | |
<tr> | |
<th> | |
<label for="office">Twitter username</label> | |
</th> | |
<td> | |
<input type="text" value="<?php echo esc_attr( $twitter ); ?>" name="twitter" /> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
add_action( 'show_user_profile', 'render_user_profile_fields' ); | |
add_action( 'edit_user_profile', 'render_user_profile_fields' ); | |
function update_user_profile_fields( $user_id ) { | |
if ( ! current_user_can( 'edit_user', $user_id ) ) { | |
return; | |
} | |
update_user_meta( $user_id, 'twitter', sanitize_text_field( $_POST['twitter'] ) ); | |
} | |
add_action( 'personal_options_update', 'update_user_profile_fields' ); | |
add_action( 'edit_user_profile_update', 'update_user_profile_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment