WordPress Add New User Directly Into Database

Every now and then we are faced with the situation where we need to add a new user but not through the normal way. A quick and dirty way to do this (and bypass all the authentication) is to add the new user directly into the database.

Please note that there are some risks and might not work as it depends on the WordPress version as well as timings! The script assumes that there are no other users doing a user registration at the same time (or you might end up giving a super admin right to someone else!).

Assuming the username is username and password is password:

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, 
 VALUES ('username', MD5('password'), 'firstname lastname', 'email@example.com', '0');
 INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
 VALUES (NULL, (Select max(id) FROM wp_users), 
 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
 INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
 VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
This entry was posted in Blog and tagged , . Bookmark the permalink.

Comments are closed.