Reputation: 8786
We have a user (who had admin access) that can no longer login to wp-admin portal, as he is not in the wp_users
table. I tried to add him, but wordpress tells me that the user already exists. I was able to find a reference about him in wp_usermeta
table.
What I did was to find out the user ID from wp_usermeta
table and manually create an entry in wp_users
that matches the metadata in wp_usermeta
.
But when I go to wp-admin the user is not there, and when I list the users with wp cli, it is not listing him either.
Is there a way to recover this user manually by adding him back to the database?
If not, I would like to completely purge him from the db, and re-create his username. Would deleting the reference from wp_usermeta
be enough or there might stay residues in different tables?
Upvotes: 0
Views: 50
Reputation: 91
Let me help you troubleshoot this WordPress user issue. I'll provide a systematic approach to either recover or properly purge and recreate the user.
First, to properly recover the user, you'll need to ensure the entries in both tables are correctly synchronized. Here's what you can check:
wp_users
, make sure you've added these required fields:ID -- Must match the user_id from wp_usermeta
user_login -- The username
user_pass -- WordPress hashed password
user_nicename -- Usually lowercase version of username
user_email -- Email address
user_registered -- Registration date
display_name -- Name displayed in WordPress
wp_usermeta
, check if these essential capabilities exist:wp_capabilities
wp_user_level
If recovery isn't working, here's how to properly purge the user:
SELECT user_id FROM wp_usermeta WHERE meta_key LIKE '%capabilities%' AND meta_value LIKE '%administrator%';
wp_usermeta
:DELETE FROM wp_usermeta WHERE user_id = [THE_USER_ID];
wp_posts (post_author column)
wp_comments (user_id column)
wp_terms (term_author column if using term authors)
wp user create [username] [email] --role=administrator
If you want to use the same username as before, make sure all traces of the old user are removed first, especially from wp_users
and wp_usermeta
.
Upvotes: 0