EDIT -
I have come so far but I can't get the last part to work. I have the adding of a new user fixed.
The foreach loops through the csv to add all users:$filepath = get_bloginfo('template_directory')."/import_test.csv"; ini_set('auto_detect_line_endings',TRUE); $file = fopen($filepath, "r") or die("Error opening file"); $i = 0; while(($line = fgetcsv($file, 1000, ";")) !== FALSE) { if($i == 0) { $c = 0; foreach($line as $col) { $cols[$c] = $col; $c++; } } else if($i > 0) { $c = 0; foreach($line as $col) { $data[$i][$cols[$c]] = $col; $data[$i][$cols[$c]] = $col; $c++; } } $i++;
}
foreach ($data as $gebruiker){ $c++; $username = $gebruiker['username']; if ( username_exists( }$username ) ){ } $user = get_user_by( 'login', $username); $i++; update_user_meta( $user->ID, 'meta_key', $gebruiker['email'] } ); foreach} ($data as $user) else{ $user$users = wp_insert_user( array( 'user_login' => $user['username']$gebruiker['username'], 'user_pass' => $user['password']$gebruiker['password'], 'first_name' => $user['first_name']$gebruiker['first_name'], 'last_name' => $user['last_name']$gebruiker['last_name'], 'user_email' => $user['email']$gebruiker['email'], 'display_name' => $user['first_name']$gebruiker['first_name'] . ' ' . $user['last_name']$gebruiker['last_name'], 'nickname' => $user['first_name']$gebruiker['first_name'] . '' . $user['last_name']$gebruiker['last_name'], 'role' => 'subscriber' ) ); foreach ($data as $update_user) { update_user_meta( $users, 'import_1', $update_user['first_name'] ); update_user_meta( $users, 'import_2', $update_user['last_name'] ); } } }
But no matter where I place the update_user_meta
in the loop it gives me back the following error:
Fatal error: Cannot use object of type WP_Error as array in
The error is fixed. Because the users allready existed. So need to check for that later. This does mean that the fields are added to the usermeta but empty
====== EDIT ======
The above code is final and working...