public function export_listen() { // Bail if we aren't in the admin if (!is_admin()) { return false; } if (!isset($_REQUEST['form_id']) || empty($_REQUEST['form_id'])) { return false; } if (isset($_REQUEST['export_single']) && !empty($_REQUEST['export_single'])) { Ninja_Forms()->sub(esc_html($_REQUEST['export_single']))->export(); } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'export' || isset($_REQUEST['action2']) && $_REQUEST['action2'] == 'export') { $sub_ids = WPN_Helper::esc_html($_REQUEST['post']); Ninja_Forms()->form($_REQUEST['form_id'])->export_subs($sub_ids); } if (isset($_REQUEST['download_file']) && !empty($_REQUEST['download_file'])) { // Open our download all file $filename = esc_html($_REQUEST['download_file']); $upload_dir = wp_upload_dir(); $file_path = trailingslashit($upload_dir['path']) . $filename . '.csv'; if (file_exists($file_path)) { $myfile = file_get_contents($file_path); } else { $redirect = esc_url_raw(remove_query_arg(array('download_file', 'download_all'))); wp_redirect($redirect); die; } unlink($file_path); $form_name = Ninja_Forms()->form(absint($_REQUEST['form_id']))->get_setting('title'); $form_name = sanitize_title($form_name); $today = date('Y-m-d', current_time('timestamp')); $filename = apply_filters('ninja_forms_download_all_filename', $form_name . '-all-subs-' . $today); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="' . $filename . '.csv"'); header('Pragma: no-cache'); header('Expires: 0'); echo $myfile; die; } }