WordPress uses wp_users
data tables to store the user's primary data, which is structured like wp_posts
a wp_comments
data table, storing user data that needs to be accessed frequently, the structure of the data table, and the relationship of the data table to other data tables as follows:
WordPress User Data table relationship (click to view larger image)
At the same time, WordPress has some additional user data saved in the other data tables, including additional user data in the following two data tables:
- Additional user attribute data is saved in the
wp_usermeta
data table.
- In the comments, the data for the user who is not logged in is saved in the
wp_comments
data table.
Next, let's look at how to access this data.
wp_users
Data Sheet
The Wp_users data table stores the core data about each user, and the fields of the data table are as follows:
Field |
Store Content |
| Precautions
ID |
User ID |
Self-increment |
user_login |
User name |
Necessary |
user_pass |
Password |
If it is not filled in, it is automatically generated |
user_nicename |
Nickname |
If it is not filled in, it is automatically generated |
user_email |
Email address |
Necessary |
user_url |
Url |
Non-essential |
user_registered |
Date and time of user registration |
Automatically generated |
user_activation_key |
User Activation Key |
Automatically generated |
user_status |
The user state, saved as a number, indicating whether the user has confirmed the registration by mail. |
Automatically generated |
display_name |
Public display as Name |
If it is not filled in, it is automatically generated |
As shown in the previous table, except for one field ( user_url
), the other fields are either required or are automatically generated.
User meta-data table
As with wp_users
the data in, some data that is not frequently accessed is stored in Wp_usermeta data tables, such as user-color roles and permissions. The data table is also used to store additional settings to improve the user experience, including the Management Interface color scheme, and whether to display settings such as administrative toolbars.
When we need to add additional data to our users through themes or plugins, we should use this data table instead of wp_users
adding fields to the data table, because the structure of the data table may change with the WordPress upgrade.
Wp_usermeta The fields that the data table contains.
- ID – Self-increment ID
- user_id– Connecting to Wp_users
- Key for the meta_key– field
- The value of the meta_value– field
If you need to create User_meta data, we can use the add_user_meta()
function:
add_user_meta( $user_id, $meta_key, $meta_value, $unique );
where the fourth parameter ($unique) is optional, indicating whether the user field is unique.
Once the User_meta data has been added, we can get_user_meta()
access and output the data through a function.
About the creation and access of user fields, involving the operation of metadata, I will write an additional article to introduce in detail, here is not much to say.
The relationship between users and other content
Users can be associated with two types of data: articles and comments. In the article, an article always has an author, and the relationship is realized by a wp_posts
field in the data table post_author
, and the value of the field is the user ID of the author of the article.
Comments are not always connected to a wp_users
data table: This relationship can only be established when the logged-in user comments, which is wp_commerts
achieved through the fields in the data table user_id
.
If the reviewer is not logged in, the reviewer information is stored in the Wp_comments data sheet, which includes: comment_author
, comment_author_email
,, comment_author_url
and comment_author_IP
fields.
Summarize
User is a WordPress site necessary data, no users, we have no way to manage the site through the dashboard, no way to publish articles.
WordPress stores the user's core data in a wp_users
data table, additional data is stored in the data table wp_usermeta
, and the data table is connected to the user wp_posts
data to the article, the Data wp_comments
table to connect user data to the comment.
Ext.: https://www.wpzhiku.com/understanding-working-user-data-wordpress/
Deep understanding of user data in WordPress database Wp_user