treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress create users by code

  • i am using wp 3.2v. i have to create multiple users and generate passwords and use empty email as the default email for the users(if possibe)
    i know i have to use
    <?php wp_create_user( $username, $password, $email ); ?> 

    but where exactly(in which file) should i use this code
    and also i want to handle the empty email exception with
    define ('WP_IMPORTING', true);
  • If your adding users from a loop you can probably just create a file at root of WP and include wp-blog-header.php.

    Something like this should work.

    <?php
    require 'wp-blog-header.php';

    $users = array(); // this is where you would supply all of your users

    foreach( $users as $user )
    wp_create_user($user->username, $user->password);


    You may need to create the script on a local version of WP to fix any bugs before you put it into production. And I would suggest deleting the file when your done with it.