WordPress.org

Ready to get started?Download WordPress

Forums

Import Users from CSV
[resolved] re-importing to update a user (5 posts)

  1. misterdavo
    Member
    Posted 2 years ago #

    I have a csv with a single user (a test). role= subscriber.
    He imports fine.
    Then I change the csv and make his role contributor
    Import the csv and get: "No user was successfully imported, please check the error log."
    Shouldn't I be able to re-import an existing user and have it just update the record?

    Also a side-note: When it says click to get the error log, it's always empty.

    Thanks so much.

    http://wordpress.org/extend/plugins/import-users-from-csv/

  2. Ulrich Sossou
    Member
    Plugin Author

    Posted 2 years ago #

    Are you using Multisite? If yes, here is how to correctly set the user role: http://wordpress.org/support/topic/plugin-import-users-from-csv-import-existing-users-with-multisite?replies=21.

    To update an existing user, you need to add a new column called 'ID' and add the user ID in that column.

  3. misterdavo
    Member
    Posted 2 years ago #

    Ulrich, I am not using Multisite.

    I created a new column after the existing columns, called it ID, and then just put in some random numbers because I wouldn't know what else to enter for a user's ID. There is of course no field called ID in the WordPress User Profile form, so already this sounds odd to me. The csv says it imports fine, but the user is not added at all. If the user exists already it does not update their record. I feel like I'm missing something obvious here.

    Look at my csv
    http://www.lithotechnicians.com/CustomerPickup/DL-csv1.png">

  4. misterdavo
    Member
    Posted 2 years ago #

    Update: I installed a csv exporter. Dumped out my sample user and found the first column was 'URL' It showed my admin account as '1' and the other user as '565'. So I changed the ID column in my csv to 565 and imported that user and now it imports fine and I can change the user's ID. But... how could I ever know what a User's ID is in the first place unless I do this very manual process each time? I'd be better off updating users one by one, by hand.

    My users are all stored in an external database, and ideally I'd like to SET their ID in the first place via the CSV import. OR... have the CSV importer NOT use the ID field as the key, as it seems to here, but instead use the Username field which I can be certain will never ever change.

    I hope I'm making myself clear.

  5. Ulrich Sossou
    Member
    Plugin Author

    Posted 2 years ago #

    - The ID cannot be set in the first place. The WordPress core functions don't allow that and I chose not to bypass them in the plugin code.

    - Using the ID field only for updating the users was intentional, but I added a filter so that anyone can change that behaviour is needed, with little coding. The code below should do that:

    function example_filter_import_userdata( $userdata ) {
    	if ( ! empty( $userdata['user_login'] ) ) {
    		$user = get_userdatabylogin( $userdata['user_login'] );
    		$userdata['ID'] = $user->ID;
    	}
    
    	return $userdata;
    }
    add_filter( 'is_iu_import_userdata', 'example_filter_import_userdata' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic