Extending User Profiles in WordPress

Friday, August 28th 2009

In this series, I'm going to show you how to display a paginated archive of all your WordPress users, as well as extend user profiles to include custom user meta on both the front end of your WordPress theme and in the Dashboard.

As it stands, there are no filters in WordPress that allow you to dramatically alter the way the user profile fields (or user meta) are displayed when you visit your Profile in the Dashboard.* The existing profile fields are more or less hard-coded into the WordPress core, and so there's no easy way to add more fields without hacking the core.

Instead, we have to turn to several plugins to get the desired functionality.

First, we need to display a list of all registered users:

Members List will display a paginated list of registered users on a page in WordPress. It lets us sort the list by Last Name, First Name, Registration Date, and Email and search users by some of the default user meta fields. And when you click individual users, it will link to the Author template so we can handle individual user profiles on the front end.

So far so good.

Now, we want to let users upload their own photos for use throughout the site. But we also want gravatars to work if users have them, and additionally we want WordPress to generate a random avatar for users if they don't have a gravatar and they haven't uploaded a photo. (Uploaded avatars should take precedence over all others.)

User Photo is the only plugin that does the job.

Finally, we need to be able to add custom user meta without hacking the core, and have these new fields appear in the Dashboard so users can fill them out.

In PJW User Meta, Peter Westwood demonstrated how we could add extra fields to the Profile and process them in a sample plugin he wrote. We can use his code as a basis for writing theme-specific plugins that add sets of custom user meta without hacking the core.

Setbacks

While the good news is that all this stuff will work up to 2.8.4, we still need to hack the plugins to meet our requirements.

  • Members List doesn't know that we're letting users upload their own photos, and so it can't show avatars conditionally like User Photo does. We'll have to give it the necessary code to behave like we want when it shows our list of registered users;
  • User Photo has a bug that requires every uploaded photo to be approved by an admin, even if you turn that feature off. We'll have fix that. We also need to make it so that the function that echoes the conditionally selected avatar can optionally return the avatar for use in a variable, in order for it to play nicely with Members List;
  • We need to write an Author template to display profiles for individual users.

With that, let's start by creating the Members List archive.

You can view the finished (albeit unstyled) product here:

http://dev.dquinn.net/guest/members/

Next up, Creating a Directory of Registered Users in WordPress »

* There are developments on the horizon as we approach WordPress 2.9 that may make this whole process easier, but for now, we'll have to rely on plugins and hiding fields with CSS as this series prescribes.

Speak Your Mind

For Scathing Rebuttals

Enclose code in <code></code> brackets.

Your Trackbacks

So Says the Blogosphere
  1. Surf the Mind » Wordpress Stuff for a Business Networking Site Friday, October 16, 2009

    [...] Extending User Profiles [...]