Create user’s site from database in wordpress multisite

anyeong haseyo yorobun.. i wrote again.. i wanna share you about my project in wordpress multisite..

2 weeks ago, i was wondering about how to create a lot of user for wordpress multisite. in my office, there are almost 300 users and you can imagine, it will be hard to create all of them one by one..

first algorithm that i  was thought :

1. get username, password and email from database.

2. make looping for all data with function wordpress to make users and sites automatically.

here the code:

$result=mysql_query(‘SELECT * FROM dto’);

while($row = mysql_fetch_assoc($result))
{
$nama = strtolower( $row[‘nama’] );
$domain = $nama.’.blog.unas.ac.id’;
$password = $row[‘password’];
//$password = md5[$password];
$path=’/’;
$title=$nama.”‘s blog”;
$email=$row[’email’];

if ( empty( $domain ) )
wp_die( __( ‘Missing or invalid site address.’ ) );
if ( empty( $email ) )
wp_die( __( ‘Missing email address.’ ) );
if ( !is_email( $email ) )
wp_die( __( ‘Invalid email address.’ ) );

$user_id = email_exists($email);

if ( !$user_id ) {
$user_id = wpmu_create_user( $nama, $password, $email );
$id=wpmu_create_blog( $domain, $path, $title, $user_id , array( ‘public’ => 1 ), 1 );
wp_redirect( add_query_arg( array( ‘update’ => ‘added’, ‘id’ => $id ), ‘site-new-csv.php’ ) );
if ( false == $user_id )
wp_die( __( ‘There was an error creating the user.’ ) );
else
wp_new_user_notification( $user_id, $password );
}

}

i hope you understand my post.. feel free if you want to ask me.. 🙂 or you can email me at dhiekalantana@yahoo.co.id..

dhieka avrilia

everyone, i think i missed something. sorry. i wanna tell you that in my database, i only using first name such as, “hendra”, “fani”, now i want going to make with full name such as “hendra gunawan”.. im very thankfull for reading my blog

Your email address will not be published. Required fields are marked *

*