Skip to content

Instantly share code, notes, and snippets.

@frozzare
Last active March 24, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozzare/47375e238597b324a955 to your computer and use it in GitHub Desktop.
Save frozzare/47375e238597b324a955 to your computer and use it in GitHub Desktop.
<?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