user1765876
user1765876

Reputation:

add new column in wp_user table

Is it good to add new column in table WP_USER - Or - should I add stuff in metauser table? I was questioning this because there is a WP function

/* Get full WP_User object instance. */ 
$user = new WP_User ($user->ID);

Will that work as well after adding column in WP_USER?

Upvotes: 2

Views: 3999

Answers (2)

Matt Maynard
Matt Maynard

Reputation: 11

Ask yourself this: does the data I want to store have a 1-1 relationship with a user table entry? If so, put it in a separate table indexed by user ID (call it [prefix]_user_auxdata or something like that), and add other 1-1 data there, should the need arise again. If not, put it in usermeta as a key-value pair.

The reason to store it separately is because this future-proofs your database from changes WordPress may want to make to the users table. It avoids a potential conflict by eliminating the possibility of one in the first place.

Upvotes: 1

Farrukh Subhani
Farrukh Subhani

Reputation: 2038

If you want custom fields to be added to your user, use the usermeta or create a new table with username as primary key. This would allow you to be future proof in terms of updates.

Upvotes: 6

Related Questions