Created
December 23, 2013 07:04
-
-
Save alexpos/8092774 to your computer and use it in GitHub Desktop.
WP: Add 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 | |
function modify_contact_methods($profile_fields) { | |
// Add new fields | |
$profile_fields['twitter'] = 'Twitter Username'; | |
$profile_fields['facebook'] = 'Facebook URL'; | |
$profile_fields['gplus'] = 'Google+ URL'; | |
// Remove old fields | |
unset($profile_fields['aim']); | |
return $profile_fields; | |
} | |
add_filter('user_contactmethods', 'modify_contact_methods'); |
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_action( 'personal_options_update', 'save_custom_profile_fields' ); | |
add_action( 'edit_user_profile_update', 'save_custom_profile_fields' ); | |
function save_custom_profile_fields( $user_id ) { | |
update_user_meta( $user_id, 'phone_number', $_POST['phone_number'], get_user_meta( $user_id, 'phone_number', true ) ); | |
update_user_meta( $user_id, 'greeting', $_POST['greeting'], get_user_meta( $user_id, 'greeting', true ) ); | |
} | |
add_filter( 'user_contactmethods', 'add_contact_option', 10, 2 ); | |
function add_contact_option( $user_contactmethods, $user ) { | |
$user_contactmethods['phone_number'] = 'Phone Number'; | |
return $user_contactmethods; | |
} | |
add_action( 'personal_options', 'add_profile_options'); | |
function add_profile_options( $profileuser ) { | |
$greeting = get_user_meta($profileuser->ID, 'greeting', true); | |
?><tr> | |
<th scope="row">Greeting</th> | |
<td><input type="text" name="greeting" value="<?php echo $greeting; ?>" /></td> | |
</tr><?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment