So I’ve decided to start using this blog as a place to store useful WordPress tricks and things as I come across them and learn them.
So this is a little snippet to allow you to add an Admin user to a WordPress install even if you only have FTP access. Obviously I’d rather get login details from whoever set up the install, but sometimes that person is no longer contactable, so this comes in useful.
function admin_account(){
$user = 'AccountID';
$pass = 'AccountPassword';
$email = 'email@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','admin_account');
Just copy and paste this into the functions.php file of your WordPress theme, and then login using the details you entered where it says AccountID and AccountPassword above.