Support » Plugin: Import and export users and customers » Prevent Blank / Invalid Email from being Imported

  • I have an issue I found that I believe is a problem with Microsoft Office 365 and how it converts a spreadsheet to CSV. The Excel template that I created for use by multisite users to import users. It has custom fields with cells formatted so that dates entered are stored in the proper format. I used the format painter to format cells for 100 rows. Even though there is no input in many of the rows, the CSV file is created with blanks for these rows. There is no user login or user email in those rows.

    When the CSV file is imported using the Import users plugin , it creates entries for users with the user name usr_xxxx where xxx is the ID generated by WordPress. The users it creates have no email address or any other information. I need to manually delete them from WordPress.

    Would it be possible to check the user email field on import and stop it from being imported into WordPress if there is no email address in the field? Possibly as simple as looking for the presence of “@” in the string.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Rhapsody348

    (@rhapsody348)

    Hello Javier,

    I just looked at the file classes/import.php on line 339 where it is:

    if( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) ){ // if email is invalid

    something like this could be used to detect the ‘@’ and prevent creating users with malformed email addresses. I didn’t go through all your code so don’t know if it is the ultimate solution, but should be on the right path.

    if( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) || !strpos($email, '@') !== false ) ){ // if email is invalid

    Thread Starter Rhapsody348

    (@rhapsody348)

    Hello Javier and Happy New Year. Just checking to see if you had a chance to look at this request?

    Thread Starter Rhapsody348

    (@rhapsody348)

    Hello Javier,

    I was able to modify the file import.php line 467 to fix the issue described in the original post. The issue is a result of Excel save as CSV – see explanation below.

    $user_id = wp_create_user( $username, $password, $email );

    becomes:

    if( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) $user_id = wp_create_user( $username, $password, $email ); // prevent insertion of blank or invalid email

    This still shows the error in the table you display, but prevents the empty email from being inserted.

    Further research shows that this is a problem using Excel Save as CSV. If a field has formatting attributes, but no data it saves a row with blank fields and the comma delimiter.

    If the CSV file is opened in Excel and saved again, all the blank rows containing commas are removed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.