Created
January 31, 2012 19:45
-
-
Save ramseyp/1712502 to your computer and use it in GitHub Desktop.
Add Extra Fields to WordPress user profile
This file contains 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 Extra Profile Meta fields to WordPress user profile | |
*/ | |
//Extra Author Profile Meta | |
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>Is this an active author?</h3> | |
<table class="form-table"> | |
<tr> | |
<td> | |
<?php $agree = get_the_author_meta( 'active_author', $user->ID ); ?> | |
<label for="active_author">Active Author <input value="true" name="active_author" id="active_author" <?php if ($agree == 'true' ) { ?>checked="checked"<?php }?> type="checkbox" /></label> | |
</td> | |
</tr> | |
</table> | |
<?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 'active_author' to the field ID. */ | |
update_usermeta( $user_id, 'active_author', $_POST['active_author'] ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment