Skip to content

Instantly share code, notes, and snippets.

@benfavre
Forked from shaynesanderson-zz/user-meta.php
Created April 29, 2014 04:34
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 benfavre/11390715 to your computer and use it in GitHub Desktop.
Save benfavre/11390715 to your computer and use it in GitHub Desktop.
<?php
// Add custom meta to user profile screen
add_action( 'show_user_profile', 'example_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'example_show_extra_profile_fields' );
function example_show_extra_profile_fields( $user ) { ?>
<h3>Payment information</h3>
<table class="form-table">
<tr>
<th><label for="paypal">Paypal</label></th>
<td>
<input type="text" name="paypal" id="paypal" value="<?php echo esc_attr( get_the_author_meta( 'paypal', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Paypal email address for payments to be sent.</span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'example_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'example_save_extra_profile_fields' );
function example_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 'paypal' to the field ID. */
update_user_meta( $user_id, 'paypal', $_POST['paypal'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment