Sick of using the name 'admin' to login to your WP installation? Have a user with the login 'PiNkbUnNiEz!1" but want to change it without that user losing all their posts/creating a new account etc.? Tried to do it but found the field disabled in your WP admin panel?
Here is what you need to do.
-
Before you do anything, backup your database. If you don't know how to do this, ask at the WP forums or Google it - there are some plugins that will do this for you if you don't have access to things like phpMyAdmin (a MySQL tool which can be used to backup your database - Jem has a tutorial on this which may be useful)
-
Paste this into a file. Name it anything you like, as long as it has a .php extension:
<?php
$existing_username = 'admin';
$new_username = 'MY_NEW_USERNAME';// —————if (!file_exists('wp-config.php')) exit('Could not find wp-config.php, please make sure you place this file in the same directory as all your WP files.');require 'wp-config.php';$link = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) exit('Could not connect to MySQL');
mysql_select_db(DB_NAME, $link) or exit('Could not connect to MySQL');if (mysql_query('UPDATE `' . $table_prefix . "users` SET `user_login` = '" . mysql_real_escape_string($new_username, $link) . "' WHERE `user_login` = '" . mysql_real_escape_string($existing_username, $link) . "' LIMIT 1", $link)) echo 'Username updated, your username is now ' . $new_username . '.';
else echo 'Could not update your username. MySQL said: ' . mysql_error($link);mysql_close($link);
?>Change the first two lines (excluding the one that says '<?php', obviously :P ) to your existing username (probably admin) and your new desired username. Save the file, then upload it to your WordPress directory. Make sure this file is in the same place as wp-config.php.
-
Go to the file in your browser, e.g. yoursite/wordpress/the-file.php and voilà! :D
Peter Green
10/04/2008 at 21:42
Very interesting, where did you find this, or did you write the code your self?
Thanks, Peter
Melissa
11/04/2008 at 4:32
Woot! Gotta remember this for whenever I'm too lazy to click into phpMyAdmin and want to change a username. :D
Amelie
11/04/2008 at 7:39
@Peter: I wrote it myself :)
Vickie
11/04/2008 at 11:21
I'm more tempted to change people's passwords to "PiNkbUnNiEz!1" instead... :P
Ivy
12/04/2008 at 20:12
This is an interesting of changing the admin name! I'm not too great with PHP though. I've always used phpmyadmin to change my admin name. Hahaha. Thanks for sharing. :)
Holly
13/04/2008 at 9:43
*bookmarks*
Handy! :)
Rilla
16/04/2008 at 1:54
Can you not just go into phpMyAdmin and change it? *have never tried though*
Amelie
16/04/2008 at 7:44
^ Yes you can, but it requires access to PMA and knowledge of where to find everything.
Just thought this would make it a bit easier. *Shrug*
Morgan
19/04/2008 at 11:15
Interesting tutorial. I ought to bookmark this, could come in handy when someone actually tries to sing up as "PinkBunnieZ1!!!".
Cindy
24/04/2008 at 23:49
OMG! You're descended from Jonathan Swift =OOOO SWEET~
Baby bacon all the way! =D