is_action('import')) { $mode = $controls->data['mode']; // TODO: to be removed, it's not safe @set_time_limit(0); $results = ''; if (is_uploaded_file($_FILES['csv_file']['tmp_name'])) { $lines = file($_FILES['csv_file']['tmp_name']); } else { $csv = stripslashes($controls->data['csv']); $lines = explode("\n", $csv); } // Set the selected preferences inside the if (!isset($controls->data['preferences']) || !is_array($controls->data['preferences'])) $controls->data['preferences'] = array(); // if ($options['followup'] == 'activate') { // $subscriber['followup'] = 1; // } $error_count = 0; $added_count = 0; $updated_count = 0; $skipped_count = 0; foreach ($lines as &$line) { // Parse the CSV line $line = trim($line); if ($line == '') { continue; } if ($line[0] == '#' || $line[0] == ';') { continue; } $separator = $controls->data['separator']; if ($separator == 'tab') { $separator = "\t"; } $data = explode($separator, $line); // Builds a subscriber data structure $email = $newsletter->normalize_email($data[0]); if (empty($email)) { continue; } if (!$newsletter->is_email($email)) { $results .= '[INVALID EMAIL] ' . $line . "\n"; $error_count++; continue; } $subscriber = $module->get_user($email, ARRAY_A); if ($subscriber == null) { $subscriber = array(); $subscriber['email'] = $email; if (isset($data[1])) { $subscriber['name'] = $module->normalize_name($data[1]); } if (isset($data[2])) { $subscriber['surname'] = $module->normalize_name($data[2]); } if (isset($data[3])) { $subscriber['sex'] = $module->normalize_sex($data[3]); } $subscriber['status'] = $controls->data['import_as']; foreach ($controls->data['preferences'] as $i) { $subscriber['list_' . $i] = 1; } $module->save_user($subscriber); $results .= '[ADDED] ' . $line . "\n"; $added_count++; } else { if ($mode == 'skip') { $results .= '[SKIPPED] ' . $line . "\n"; $skipped_count++; continue; } if ($mode == 'overwrite') { if (isset($data[1])) { $subscriber['name'] = $module->normalize_name($data[1]); } if (isset($data[2])) { $subscriber['surname'] = $module->normalize_name($data[2]); } if (isset($data[3])) { $subscriber['sex'] = $module->normalize_sex($data[3]); } if (isset($controls->data['override_status'])) { $subscriber['status'] = $controls->data['import_as']; } // Prepare the preference to zero for ($i = 1; $i < NEWSLETTER_LIST_MAX; $i++) { $subscriber['list_' . $i] = 0; } foreach ($controls->data['preferences'] as $i) { $subscriber['list_' . $i] = 1; } } if ($mode == 'update') { $subscriber['name'] = $module->normalize_name($data[1]); $subscriber['surname'] = $module->normalize_name($data[2]); if (isset($data[3])) { $subscriber['sex'] = $module->normalize_sex($data[3]); } if (isset($controls->data['override_status'])) { $subscriber['status'] = $controls->data['import_as']; } foreach ($controls->data['preferences'] as $i) { $subscriber['list_' . $i] = 1; } } NewsletterUsers::instance()->save_user($subscriber); $results .= '[UPDATED] ' . $line . "\n"; $updated_count++; } } if ($error_count) { $controls->errors = "Import completed but with errors."; } $controls->messages = "Import completed: $error_count errors, $added_count added, $updated_count updated, $skipped_count skipped."; } ?>

The import and export functions ARE NOT for backup. If you want to backup you should consider to backup the wp_newsletter* tables. Please, read on bottom of this page the data format to use and other important notes.

Results

init(); ?>
select('import_as', array('C' => __('Confirmed', 'newsletter'), 'S' => __('Not confirmed', 'newsletter'))); ?>
checkbox('override_status', __('Override status of existing users', 'newsletter')) ?>
select('mode', array('update' => 'Update', 'overwrite' => 'Overwrite', 'skip' => 'Skip')); ?> if email is already present

Update:
Overwrite:
Skip:

preferences_group('preferences', true); ?>
Every new imported or updated subscriber will be associate with selected preferences above.
select('separator', array(';' => 'Semicolon', ',' => 'Comma', 'tab' => 'Tabulation')); ?>
Tip Upload a CSV file, see format description below.
CSV text
Tip Simply paste CSV text here.
 button('import', 'Import'); ?>
Data format
and other notes
Tip Consider to split up your input list if you get errors, blank pages or partially imported lists: it can be a time/resource limit of your provider. It's safe to import the same list a second time, no duplications will occur.

Import list format is:

email[separator]first name[separator]last name[separator]gender[new line]

Example:

email1@example.com;first name 1;last name 1;m
email2@example.com;first name 2;last name 2;f

where [separator] must be selected from the available ones. Empty lines and lines starting with "#" will be skipped. There is no separator escaping mechanism, so be sure that field values do not contain the selected separator. The only required field is the email all other fields are options. Gender must be "m" or "f".