Extend the User Contact Info in WordPress 2.9

WordPress-Christmas-16
Joost de Valk wrote about a month ago a really great article about his idea, to expand the user contact fields (thanks Joost!). In version 2.9 you are able to use this possibility. Here a little example, how you can use this functionality.

First you write your own function in your functions.php of your theme.

<?php
function my_new_contactmethods( $contactmethods ) {
  // Add Twitter
  $contactmethods['twitter'] = 'Twitter';
  //add Facebook
  $contactmethods['facebook'] = 'Facebook';
 
  return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
?>

This function does nothing more than expand the array $contactmethods with the fields twitter and facebook. The value behind the fields is used as a label for the input fields. You can also remove existing fields, here the field of YAHOO IM:

  // Remove Yahoo IM
  unset($contactmethods['yim']);

WordPress contact info edit screen

This fields can be displayed on the author page.

<?php
$current_author = get_userdata(get_query_var('author'));
?>
<p><a href="<?php echo esc_url($current_author->twitter);?>" title="Twitter"> Follow me on Twitter</a></p>

Alternatively you can also use the template tag the_author_meta.

the_author_meta('facebook', $current_author->ID)

That's all behind the 16ht door of our Advent Calendar. :) Have fun expanding your contact fields.

8 Comments
  1. says:

    Very usefull ! Thanks guys...

  2. sebastien says:

    wp2.9, it's for when ?

  3. Matt B says:

    Well done! I somehow managed to miss the fact that this is for 2.9, not 2.8.6. Small detail, but this looks well worth the improvement.

    Keep it up!

  4. Don says:

    This is great, I've been wondering if this was possible because I've been put in charge of the server for a clan's website, and adding more contact fields (like tag, and other things) is really nice.

    The downside of this is that I'll have to wait until 2.9 is released in final because I really don't want to upgrade them to a beta release...

  5. Dieter says:

    Thanks for this useful hint.
    As user of Twitter I´m especially interested in the enhancement with the link to the Twitter account.
    And folks: WP 2.9 is out now! :-)

  6. Jones Lee says:

    Nice feature, do you know what function to add extra userdata so I could use it with wp_insert_user to add in more fields like Country, Address, etc

  7. Really nice easy way to showcase how to extend the author contact information, I think Wordpress should include "Twitter/Facebook" by default now.

  8. Konstantin says:

    Awesome! I hated how I had to hardcode everything. I'll definitely use that in my current project.

2 Pings
  1. User Conatct Info in WordPress 2.9 erweitern - Twitter, Facebook, add_filter, Benutzerprofil - dynamicinternet
  2. 37 Cool Wordpress Hacks And Tutorials You Should Try |
Leave a Reply
WP Engineer Tags