↑ Return to Data in WordPress

Da04 User Data in WordPress


Page no: Da04

Page no: Da04

 

WordPress stores user data in the wp_users table, which is linked to the wp_postsand wp_comments tables:

WordPress also stores user data in two other tables:

  • Additional meta data on users is stored in the wp_usermeta table
  • Data on commenters who are not logged in is stored in the wp_comments table.

In this part of my series on data in WordPress, I’ll look at how WordPress stores user data and how you can access it, focusing first on the wp_users table.

The wp_users table stores all of the core information about each user. It has the following fields:

Field What it stores Notes
ID the user ID auto-generated
user_login username required
user_pass password auto-generated if not provided at signup
user_nicename nickname auto-generated if not entered manually
user_email email address required
user_url website not required
user_registered date and time the user first registered auto-generated
user_activation_key user activation key auto-generated
user_status status stored as a number – this tells WordPress whether the user has confirmed registration via email, for example. It does NOT store user roles. auto-generated
display_name publicly displayed name auto-generated if not entered manually

As you can see, all but one field (user_url) are either mandatory on signup or will be auto-generated.

As well as the data in wp_users, there is data which is created for all users but is stored in the wp_usermeta table, such as roles and capabilities. This table is also used to store additional settings to enhance the user experience such as the chosen admin color scheme and settings for the admin bar and dashboard display.

This is the table you should use when you want to create additional fields for users via your theme or plugin – you should never add fields to the main wp_users table.

Each record in the wp_usermeta table has four fields:

  • ID – the record ID
  • user_id – which is linked to wp_users
  • meta_key
  • meta_value

To create a new user meta data record, you use the add_user_meta() function:

The fourth parameter for this function ($unique) is optional and specifies whether the value in the meta_key field should be unique.

Once you’ve added user meta data, you can output it on each user’s author page using get_user_meta() or create a list of all users with a given value for a specified key.

I’ll cover this last option in more detail in a later tutorial where I examine meta data and taxonomies.

Users can be linked to two content types: posts and comments. In the case of posts, there will always be a user, who will be the author. The relationship is between thepost_author field in wp_posts and the ID field in wp_users.

Comments do not always have a link to the wp_users table: this will only be created if the commenter is a user who is logged-in. If this is the case, the link is betweenID in wp_users and user_ID in wp_comments.

If a commenter is not a user who is logged-in, then their details will be recorded directly to the wp_comments table, using the comment_author,comment_author_email, comment_author_url and comment_author_IP fields.

Users are fundamental to a WordPress installation. Without them you have no site administrator and no authors to create content.

WordPress stores core data about users in the wp_users table and also uses thewp_usermeta table for additional metadata. It also links user data to posts in thewp_posts table and to comments in the wp_comments table.

 

Entity relationship diagram for

  • Terms
  • Taxonomies (like tags or categories)
  • Posts
  • Links
  • and their relationship table wp_term_relationships

.For our plugins, there must be GUI screenshots.

Usually one row per attribute,

 

WP Users Meta Table

 

Attribute Name Format (Value) OurPlugin used..by…Plugin Functionality GUI ScreenShot
basic_user_avatar Serialized array Follow Author Pro N/A Add the functionality for uploading avatar for every author  
 donate_button  Text value  FeedWordpress  Sahifa and Graphene template  This is the custom link, which we plan to use for donating for every author. It is old functionality.  Not used currently
sn1 – About me
sn2 – My site
sn3 – Twitter
sn4 – Facebook
sn5 – Google +
sn6 – Youtube
sn7 – Vkontakte
sn8 – CFA
sn9 – Seeking Alpha
sn10 – LinkedIn
sn11 – Amazon
sn12 – WordPress.org
sn13 – GitHub
sn14 – StackOverflow
sn15 – My books
sn16 – EconomicBlogs
Text Value  Follow Author Pro N/A These are the social networks for every different user

Follow autho pro GUI - Click to enlarge

 

See more for Data in WP