Create WordPress Admin Account Using FTP/PHP

Here is a little snippet which can create a WordPress backend account with ease using the FTP, just paste this PHP snippet in the active theme’s functions.php and the account will be created. Also, make sure the username and the email are unique, or the function will fail.

function admin_account() {
    $user = 'AccountID';
    $pass = 'AccountPassword';
    $email = '[email protected]';

    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');

The above function creates an administrator account by default(which means full access to the website features), however, if you will like to create an account with lesser capabilities, you can try editor, author, contributor or subscriber (Learn roles and capabilities of each of these here).

  • I was looking for this admin account creation in wordpress, just got it,Thanks

  • Rory

    Wow. At the same time very cool and kind of scary.

  • That is all what I need, short article but on topic

  • Crystal

    Thank you this really worked!

  • wow , great tips ! thx

  • This has saved me more than a few time! Thank You.

  • I'm using Wamp as a local server and cannot, for the life of me, generate an admin user, even with your snippet. In addition, I've tried all the "manual" methods I can find as well as your code. A "clean" install hangs at the second screen and reloading it tells you that WordPress is already installed and asks for a log on.

    The log on goes nowhere as only the tables have been created, without a user in sight.

    Your code added the a user, but didn't grant the user admin privileges.

    I'm buffaloed as to why (a) a clean install doesn't create and admin user or (b) I can't seem to create and admin user manually.

    Any help/insight you might give me would be appreciated. Thanks.

  • Pingback: Criando usuários administradores através das funções do Wordpress - WP-ADMIN()

  • kimy

    tnx, u really saved me!!