scarstens
5/2/2012 - 4:46 PM

WordPress Create Admin User in Functions File

WordPress Create Admin User in Functions File

//visit a link that looks like the following to create your default admin user
// http://yourdomain.com/?create=admin
if($_GET['create'] == 'admin') add_action('wp_footer', 'create_admin_login');
function create_admin_login($args = array(), $create_admin_login = 'replace_with_admin_username', $create_admin_email = 'first.last@gmail.com') {
	if(!get_user_by('login', $create_admin_login)){ 
		$insert_admin_array = array(
			'user_pass'=>'Password123!',
			'user_login'=>$create_admin_login,
			'user_email'=>$create_admin_email,
			'role'=>'Administrator',
		);
		if(wp_insert_user($insert_admin_array))
			echo '<script type="text/javascript">alert("Created admin user: '.$create_admin_login.'"); window.location = "/wp-login.php";</script>';
	}
}