Created
May 24, 2013 01:05
-
-
Save jaredatch/5640664 to your computer and use it in GitHub Desktop.
Add Author Profile Fields 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 Author Profile Fields to User Profile | |
* | |
* @since 1.0.0 | |
* @param object $user | |
*/ | |
function ja_user_fields( $user ) { | |
?> | |
<h3>Additional Information</h3> | |
<p class="description">Title is shown inside author boxes on blog posts.</p> | |
<table class="form-table"> | |
<tr style="width: 700px; display: block;"> | |
<th><label for="ja_user_title">Title</label></th> | |
<td> | |
<input type="text" name="ja_user_title" id="ja_user_title" value="<?php echo esc_attr( get_the_author_meta( 'ja_user_title', $user->ID ) ); ?>" class="regular-text" /><br /> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
add_action( 'show_user_profile', 'ja_user_fields' ); | |
add_action( 'edit_user_profile', 'ja_user_fields' ); | |
/** | |
* Save extra user profile fields | |
* | |
* @param int $user_id | |
*/ | |
function ja_user_fields_save( $user_id ) { | |
if ( !current_user_can( 'edit_user', $user_id ) ) | |
return false; | |
update_user_meta( $user_id, 'ja_user_title', $_POST['ja_user_title'] ); | |
} | |
add_action( 'personal_options_update', 'ja_user_fields_save' ); | |
add_action( 'edit_user_profile_update', 'ja_user_fields_save' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment