function render_csv()
 {
     $registrations = thatcamp_registrations_get_registrations();
     $ud = wp_upload_dir();
     $csv_dir = trailingslashit($ud['basedir']) . trailingslashit('thatcamp-registrations');
     $csv_basename = 'registrations-' . date('Ymd') . '.csv';
     if (!is_dir($csv_dir)) {
         mkdir($csv_dir);
     }
     $csv_path = $csv_dir . $csv_basename;
     $fp = fopen($csv_path, 'w');
     // Build an array that will represent the proper column headers
     $cols = array(array('ukey' => 'id', 'title' => 'Registration ID #'), array('ukey' => 'date', 'title' => 'Date'), array('ukey' => 'user_id', 'title' => 'WP User ID'), array('ukey' => 'user_email', 'title' => 'Email'), array('ukey' => 'first_name', 'title' => 'First Name'), array('ukey' => 'last_name', 'title' => 'Last Name'), array('ukey' => 'user_url', 'title' => 'URL'), array('ukey' => 'description', 'title' => 'Description'), array('ukey' => 'user_title', 'title' => 'Title'), array('ukey' => 'user_organization', 'title' => 'Organization'), array('ukey' => 'user_twitter', 'title' => 'Twitter'), array('ukey' => 'discipline', 'title' => __('Discipline', 'thatcamp-registrations')), array('ukey' => 'technology_skill_level', 'title' => __('Technology Skill Level', 'thatcamp-registrations')), array('ukey' => 'tshirt_size', 'title' => __('T-shirt Size', 'thatcamp-registrations')), array('ukey' => 'days_attending', 'title' => __('Days Attending', 'thatcamp-registrations')), array('ukey' => 'application_text', 'title' => 'Application Text'), array('ukey' => 'status', 'title' => 'Status'), array('ukey' => 'children', 'title' => 'Children'), array('ukey' => 'particular_needs', 'title' => 'Particular Needs'));
     // Column headers
     $headers = wp_list_pluck($cols, 'title');
     fputcsv($fp, $headers);
     foreach ($registrations as $reg) {
         $reg_array = array();
         foreach ($reg as $rkey => $rvalue) {
             // applicant_info should be exploded out
             if ($rkey == 'applicant_info') {
                 $applicant_info = maybe_unserialize($rvalue);
                 foreach ($applicant_info as $info_key => $info_value) {
                     $reg_array[$info_key] = $info_value;
                 }
             } else {
                 $reg_array[$rkey] = $rvalue;
             }
         }
         // Create a clean array
         $reg_array_clean = array();
         foreach ($cols as $col) {
             $user_col_value = isset($reg_array[$col['ukey']]) ? $reg_array[$col['ukey']] : '';
             $reg_array_clean[$col['ukey']] = $user_col_value;
         }
         fputcsv($fp, $reg_array_clean);
     }
     fclose($fp);
     header("Content-type: application/force-download");
     header('Content-Disposition: inline; filename="' . $csv_path . '"');
     header("Content-Transfer-Encoding: Binary");
     header("Content-length: " . filesize($csv_path));
     header('Content-Type: application/excel');
     header('Content-Disposition: attachment; filename="' . $csv_basename . '"');
     readfile($csv_path);
     exit;
 }
/**
 * For a new registration, send email notifications to admins who have requested them
 */
function thatcamp_registrations_send_admin_notification($reg_id)
{
    $emails = thatcamp_registrations_option('admin_notify_emails');
    if (!empty($emails)) {
        $registration = thatcamp_registrations_get_registrations(array('id' => $reg_id));
        if (!empty($registration)) {
            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
            $subject = sprintf(__('New registration at %s', 'thatcamp-registrations'), $blogname);
            $content = sprintf(__('You have received a new registration at %1$s. To view this registration, visit %2$s', 'thatcamp-registrations'), $blogname, admin_url('?page=thatcamp-registrations&id=' . intval($reg_id)));
            foreach ($emails as $email) {
                wp_mail($email, $subject, stripslashes($content));
            }
        }
    }
}