Last active
December 17, 2015 07:29
-
-
Save shaynesanderson-zz/5572947 to your computer and use it in GitHub Desktop.
Add meta box to user 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
<?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
Thanks Justin! This was an old chunk of code I threw in here so as to not forget. It's been updated.