Another handy little snippet for WordPress …
Have you ever had a client need help on their WordPress site, and have FTP access, but not actually give you a WordPress account to use? Just paste this snippet into their current theme’s functions.php file, or add it to a new file in their ~/wp-content/mu-plugins/ folder, and WordPress will automatically create an admin account for you to use!
Oh — and don’t forget to change the credentials that are included to your own. If there is already an account with the username or email address specified, it will fail and not do diddly squat.
function add_admin_acct(){
$login = 'myacct1';
$passw = 'mypass1';
$email = 'myacct1@mydomain.com';
if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','add_admin_acct');
Remember … with great power comes great responsibility. Don’t abuse it.
Just used this to get into my cousin’s client’s site earlier – the only piece of info we didn’t have. Very useful – thanks George!
Wow. I have needed this so many times.
Thanks for passing it on.
How about a post on the reverse. Seems I saw something once about if you have an admin WP account but no FTP, that there is a plugin to essentially fake FTP. That possible?