User-related tables

In web applications, the user table plays the same role as in a normal CMS. Therefore, we don't have to worry about changing the default functionality. Any other user-related functionalities should be associated with the wp_usermeta table. Let's recall the user activation feature we implemented in Chapter 2, Implementing Membership Roles, Permissions, and Features. We had an additional requirement for activating users before login. We made use of the new wp_usermeta field called wpwa_activate_status to build this functionality. Now, open your database explorer and take a look at the fields of the wp_users table. You will find a column called user_activation_key with no value. This field could have easily been used for the activation functionality. Table columns such as user_activation_key and user_status are used by WordPress to provide core functionality. There is every chance that other plugin developers are using these fields with a different meaning and thus creating the potential for lost data and conflicts.

It's a good rule of thumb to use metatables or custom tables for advanced functionalities with your own unique keys by using a prefix, instead of relying on the existing columns of core tables.

Therefore, we choose the wp_usermeta table to keep the activation status of all users. Other plugin developers can also implement similar functionalities with unique keys inside the wp_usermeta table. In short, the wp_usermata table can be used effectively to create advanced user-related functionalities in web applications as long as it doesn't involve one-to-many relationships. It's possible to use multiple metafields with the same name; however, most developers prefer the use of custom tables for features that require multiple data rows to be associated with a single user, because it allows additional flexibility in data filtering.