Data, Maps, Usability, and Performance

Managing and Displaying New Fields for WordPress Users

Last updated on July 25, 2016 in Development

how to add new attributes to wordpress users

WordPress provides a lot of different hooks that allow you to expand on user management capabilities. You can easily add a new field or attribute for any user and make it editable in the user profile. You can restrict the edit mode to only Administrators and you can visualize any of these new user data points in the main Admin Users table.

So, today, I will write a quick WP Plugin that adds a new user field called credits to all users, which can be updated by Admins in the user profile. The WordPress plugin will also display that field in the Users table along with a new read only field that captures users last login date and time.

update_user_meta is used to create and update these two new user fields and last login timestamp needs to be updated by the system so I trigger it in the wp_login hook. Credits, our new user field, are managed in the user profile page so I trigger update_user_meta in personal_options_update and edit_user_profile_update hooks. It is editable only to administrators by using a simple current_user_can(‘administrator’) conditional.

To show both of these new fields in the user profile, I use the show_user_profile and edit_user_profile WP hooks and pull the new user fields via get_the_author_meta call. Finally, to display these new user fields on the backend Users table, I use the manage_users_custom_column action and manage_users_columns filter to customize the columns and row values.

Check it out on GitHub below, it is all under 100 lines of code:

New User Field WordPress Plugin

Tags: , ,

Facebook Twitter Hacker News Reddit More...