Paulund
2014-08-18 #wordpress

Modify User Contact Fields In WordPress

With WordPress each user has their own profile records, within these profile there are multiple feeds that can be populated by the user to give you more information about them allowing you customise the site a bit for just for them. One of the fields that you can easily customise is the User content information, by default WordPress comes with a number of contact fields such as:

  • E-mail
  • Website
  • AIM
  • Yahoo IM
  • Jabber

These are all quite old and I can't remember the last time I've used them and certainly don't want the user to enter this information. We can update these contact fields with information that has a bit more up to date with communication methods. The different content fields is an array of fields which has a filter user_contactmethods that you can hook into and change the values for. All you have to do is use this filter and change the values of the array. You can use the unset() function to remove contact fields you don't need and add new elements to the array for new contact fields.

function change_user_contact_information( $fields )
{
    unset($fields['aim']);
    unset($fields['yim']);
    unset($fields['jabber']);

    $fields['twitter'] = __('Twitter');
    $fields['facebook'] = __('Facebook URL');
    $fields['googleplus'] = __('Google+ URL');
    $fields['linkedin'] = __('Linkedin');
    $fields['skype'] = __('Skype');

    return $fields;
}
add_filter('user_contactmethods', 'change_user_contact_information');

To get this contact information back out you need to use the function get_the_author_meta().


<?php get_the_author_meta( $field, $userID ); ?> 

This takes 2 parameters the field ID and the user ID, therefore if you want to get the new twitter value you need to pass in twitter as the $field parameter.


$twitterUsername = get_the_author_meta( 'twitter', $userId );
$facebookUsername = get_the_author_meta( 'facebook', $userId );
$googleplusUsername = get_the_author_meta( 'googleplus', $userId );
$linkedinUsername = get_the_author_meta( 'linkedin', $userId );
$skypeUsername = get_the_author_meta( 'skype', $userId );