Skip to content

Instantly share code, notes, and snippets.

@mlbd
Last active March 2, 2019 10:38
Show Gist options
  • Save mlbd/3e2371f57df5d443bf149b979f111b96 to your computer and use it in GitHub Desktop.
Save mlbd/3e2371f57df5d443bf149b979f111b96 to your computer and use it in GitHub Desktop.
$fullsize_path = get_attached_file( 40 );
echo "<pre>";
$csv_stream = new CSVStream($fullsize_path, array(), array('header_rows' => 1));
for ($index=0; $index < $csv_stream->computeCount(); $index++) {
$csv_stream_data = $csv_stream->getNextRow();
if ( email_exists( $csv_stream_data->email ) ) {
$user = get_user_by( 'email', $csv_stream_data->email );
if ( isset( $user ) && !empty( $user ) && isset( $user->ID ) ) {
update_user_meta($user->ID, 'description', $csv_stream_data->urn);
}
}
}
echo "</pre>";
--------------------------------------------------------------
$fullsize_path = get_attached_file( 40 );
// Open uploaded CSV file with read-only mode
$csvFile = fopen($fullsize_path, 'r');
// // Skip the first line
$key_names = fgetcsv($csvFile);
$row = 1;
// Parse data from CSV file line by line
while(($line = fgetcsv($csvFile)) !== FALSE){
$num = count($line);
for ($c=0; $c < $num; $c++) {
// Get row data
$urn = $line[0];
$email = $line[2];
if ( email_exists( $email ) ) {
$user = get_user_by( 'email', $email );
if ( isset( $user ) && !empty( $user ) && isset( $user->ID ) ) {
update_user_meta($user->ID, 'description', $urn);
}
}
echo '<p>urn == '.$urn.'</p></br>';
echo '<p>email == '.$email.'</p></br>';
}
$row++;
}
// Close opened CSV file
fclose($csvFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment