Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2013 19:10
What would you like to do?
Show and save data to WordPress user profiles
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<th><label for="bgimage">Background Image</label></th>
<input type="text" name="bgimage" id="bgimage" value="<?php echo esc_attr( get_the_author_meta( 'bgimage', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Path to the background image.</span>
<?php }
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_usermeta( $user_id, 'bgimage', $_POST['bgimage'] );
Copy link

yratof commented Jun 18, 2013

Amazing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment