handling existing users & LDAP authentication

I'm hoping that uploading the following csv file using Batch create will do the following:
File looks like :
Site name Site Title User name User password User email User role
strategicplan Strategic Planning III stest stest@earlham.edu subscriber
strategicplan Strategic Planning III markp markp@earlham.edu administrator

1. Create new user account in Multisite system (just updated to 4.1) if it does not already exist.
2. the user password field is blank because I have LDAP authenitcation configured and users get their password authenticated with the LDAP server.
3. I'd like to configure it so that no emails are sent out.

If Batch Create cannot do this I wonder whether Members import might.

  • Tyler Postle
    • CGO

    Hey Mark,

    Hope you're doing well today. If the password is left blank then it will create a password for them and email it to them. I'm thinking we can stop the email from going out when you upload batch create(will take some customization), but will them having a randomly generated password still cause a problem here?

    Sorry, I'm not too familiar with LDAP; however, it sounds like all passwords will be authenticated through your LDAP server, so a randomly generated one through WordPress wouldn't be recognized? and wouldn't properly authenticate.

    Look forward to hearing back on this Mark!


  • markpea
    • Flash Drive

    Perhaps it would be easiest if I give some background and explain the use case I have in mind.
    At the college where I work I manage our wordpress, moodle and mahara installations. We want students & teachers to be able to login to all our web facilities with the same username and password so we use an LDAP server for authentication. For Wordpress this works really well -- when the user logs in the first time the system creates a new user account and blog site automatically and then subsequently just authenticates via the LDAP server. This also means that no passwords are stored in the WP database making it more secure.
    In Moodle I can upload a csv file with user account details & if I leave the password field blank the system just uses the default authentication mechanism, ie LDAP. In addition, if in the uploaded file a user already exists the import process will just skip that row and report the user account as not having been created.
    Now for the use case. I am creating a WordPress site which needs to be accessible by teachers only (and not students) so it has to be a 'members' only site. I figured that by uploading a list of fullnames, usernames, & email addresses (which I have in an Excel file) and adding each in subscriber role to the site this would accomplish the goal. However, some of the teachers have already logged in to Wordpress and since I don't want to have to check & then remove all the existing accounts it would be easiest if account creation were skipped on import but not the adding as subscriber to the site.
    So I'm looking for a batch uploader plugin that can import a set of user details (about 400 or so), create an account for each one (skipping if it's already been created) and add to the site as subscriber. Having the option of not sending every person an email notification would be icing on the cake.
    I hope that this makes my query more intelligible!

  • aristath
    • Recruit

    Hello there @markpea, I hope you're well today!

    Actually what you want may be accomplished with some custom code...
    You can create a new php file in your wp-content/mu-plugins folder called custom-user-import.php
    If the wp-content/mu-plugins folder does not already exist you can manually create it.
    In that file paste the following:

     * Override the default WordPress mail function.
     * Effectively disables ALL WordPress emails.
    function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
    	return true;
     * Create an array of the users we want to import.
    function custom_users_array() {
    	$users = array(
    		'username1' => 'email1@domain.com',
    		'username2' => 'email2@domain.com',
    		'username3' => 'email3@domain.com',
    	return $users;
     * Import users using a blank password
    function custom_users_import() {
    	$users = custom_users_array();
    	foreach ( $users as $user_name => $user_mail ) {
    		// Check if a user exists with the same username OR email.
    		// Only proceed if the don't exist.
    		if ( ! username_exists( $user_name ) && ! email_exists( $user_email ) ) {
    			// Create the user using a blank password
    			$user_id = wp_create_user( $user_name, '', $user_email );
    add_action( 'wp', 'custom_users_import' );

    You can then add your users in the custom_users_array() function above as in my example and they will be imported.

    The first few lines of my code above disable ALL WordPress emails.

    Once you add that code, just load your site and it should automatically run and import your users.
    You will have to delete the file once it's run so that it doesn't keep running each time your site loads and your normal WordPress emails will be restored.

    I hope that helps!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.