Adding bulk amount of users to wordpress using code

  • 0

In your function.php add folowing code with all users email ids in args array as one mail id in one line. Or you can split the same using commas.

function add_user(){
$args = “sample1@sample.com
sample2@sample.com
sample3@sample.com
“;
$pieces=explode(“\n”, $args);
foreach($pieces as $piece) {
$username = $piece; //username
$password = $piece; //password
$email = $piece; //email
if ( !username_exists( $username )  && !email_exists( $email ) ) {
$user_id = wp_create_user( $username, $password, $email );
$user = new WP_User( $user_id );
$user->set_role( ‘subscriber’, ‘ ); //either of ‘administrator’, ‘subscriber’, ‘editor’, ‘author’, ‘contributor’
}
}
}
add_action(‘init’,’add_user’);

Reload the website.

Please not that if you have more than 500 users, first add 500 or less users at a time. Then replace the code with next part so on…

In your function.php add folowing code with all users email ids in args array as one mail id in one line. Or you can split the same using commas. function add_user(){ $args = “sample1@sample.com sample2@sample.com sample3@sample.com “; $pieces=explode(“\n”, $args); foreach($pieces as $piece) { $username = $piece; //username $password = $piece; //password $email = $piece; //email…

In your function.php add folowing code with all users email ids in args array as one mail id in one line. Or you can split the same using commas. function add_user(){ $args = “sample1@sample.com sample2@sample.com sample3@sample.com “; $pieces=explode(“\n”, $args); foreach($pieces as $piece) { $username = $piece; //username $password = $piece; //password $email = $piece; //email…