2

Is this enough to change the user ID? I'm doing this for security purposes, where the administrator has user ID=1 and I want to keep all posts, pages and content.

UPDATE wp_posts SET post_author='1000' WHERE post_author='1';
UPDATE wp_users SET ID = '1000' WHERE ID = '1';
UPDATE wp_usermeta SET user_id = '1000' WHERE user_id = '1';

ALTER TABLE wp_users AUTO_INCREMENT = 1001;

Is there a WordPress function to do it globally?

  • How does this makes WP more secure? – user42826 Mar 18 '15 at 19:38
  • It doesn't. Some security plugins report there's a username with ID 1, and some clients are worried about this. Changing the ID will make the plugin report the site as secure. – Ciprian Mar 19 '15 at 10:33
1

Why not make a new account for this user which will generate a new database ID. Then delete the user with the ID of 1 and attribute all posts / content to the new user you created for them? Then you don't have to worry about queries or messing up your database. Also, as said before this makes absolutely no sense from a security standpoint as it's pointless. If your client doesn't trust you enough and wants to micromanage the site security they clearly know nothing about, might be time to dump that client.

  • Because I want to change it to a certain ID. I suppose your solution is the most appropriate one, and I will code a function to do this automatically. And I can't dump the client as she pays really well. – Ciprian Mar 23 '15 at 11:19
1

It should work but it doesn't add even the tiniest security to the site (if the bad guy has enough permissions to alter the password of the admin he can probably create an admin user for himself). Don't forget to backup before running the queries.

  • I want to create a small plugin to allow for the admin to change the destination ID. I looked in the database to see where user ID is used and these are the only tables I have found. Do they apply to multisite, as well? – Ciprian Mar 19 '15 at 10:35
  • yes it should . – Mark Kaplun Mar 19 '15 at 10:38
  • Do you have a source for this? As far as I know, multisite tables have a different naming structure, so wp_users wouldn't work. I want it to work, not "should" work. – Ciprian Mar 19 '15 at 16:45
  • that "Should" was added to help fill the 15 characters minimum limit for a comment, but in general all answers on WPSE are "should work" as they are rarely actually tested. As for the "citation needed", what is the point of asking an expert opinion if you need actual citation, especially in the open source world when you can simply read the code by yourself and find your own citations? If you don't trust the expert why do you ask at all? – Mark Kaplun Mar 20 '15 at 5:06
  • Usually, there are code samples and citations. I do trust the expert, although not all users are experts, and a simple "yes it should" doesn't sound that reassuring. Also, as far as I know, multisite tables have a different naming structure, so wp_users wouldn't work. – Ciprian Mar 20 '15 at 10:22
1

If you would like to also keep comments:

UPDATE wp_comments SET user_id = 1000 WHERE user_id = 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.