Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/adminpages/orders-csv.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
//only admins can get this
3
+
if ( ! function_exists( "current_user_can" ) || ( ! current_user_can( "manage_options" ) && ! current_user_can( "pmpro_orderscsv" ) ) ) {
4
+
die( esc_html__( "You do not have permissions to perform this action.", 'paid-memberships-pro' ) );
5
+
}
6
+
7
+
if (!defined('PMPRO_BENCHMARK'))
8
+
define('PMPRO_BENCHMARK', false);
9
+
10
+
$start_memory = memory_get_usage(true);
11
+
$start_time = microtime(true);
12
+
13
+
if (true === PMPRO_BENCHMARK)
14
+
{
15
+
error_log(str_repeat('-', 10) . date_i18n('Y-m-d H:i:s') . str_repeat('-', 10));
16
+
}
17
+
18
+
/**
19
+
* Filter to set max number of order records to process at a time
20
+
* for the export (helps manage memory footprint)
21
+
*
22
+
* NOTE: Use the pmpro_before_orders_list_csv_export hook to increase memory "on-the-fly"
23
+
* Can reset with the pmpro_after_orders_list_csv_export hook
24
+
*
25
+
* @since 1.8.9
26
+
*/
27
+
//set the number of orders we'll load to try and protect ourselves from OOM errors
28
+
$max_orders_per_loop = apply_filters( 'pmpro_set_max_orders_per_export_loop', 2000 );
29
+
30
+
global $wpdb;
31
+
32
+
//get users
33
+
if ( isset( $_REQUEST['s'] ) ) {
34
+
$s = sanitize_text_field( $_REQUEST['s'] );
35
+
} else {
36
+
$s = "";
37
+
}
38
+
39
+
if ( isset( $_REQUEST['l'] ) ) {
40
+
$l = intval( $_REQUEST['l'] );
41
+
} else {
42
+
$l = false;
43
+
}
44
+
45
+
if ( isset( $_REQUEST['discount-code'] ) ) {
46
+
$discount_code = intval( $_REQUEST['discount-code'] );
47
+
} else {
48
+
$discount_code = false;
49
+
}
50
+
51
+
if ( isset( $_REQUEST['start-month'] ) ) {
52
+
$start_month = intval( $_REQUEST['start-month'] );
53
+
} else {
54
+
$start_month = "1";
55
+
}
56
+
57
+
if ( isset( $_REQUEST['start-day'] ) ) {
58
+
$start_day = intval( $_REQUEST['start-day'] );
59
+
} else {
60
+
$start_day = "1";
61
+
}
62
+
63
+
if ( isset( $_REQUEST['start-year'] ) ) {
64
+
$start_year = intval( $_REQUEST['start-year'] );
65
+
} else {
66
+
$start_year = date_i18n( "Y" );
67
+
}
68
+
69
+
if ( isset( $_REQUEST['end-month'] ) ) {
70
+
$end_month = intval( $_REQUEST['end-month'] );
71
+
} else {
72
+
$end_month = date_i18n( "n" );
73
+
}
74
+
75
+
if ( isset( $_REQUEST['end-day'] ) ) {
76
+
$end_day = intval( $_REQUEST['end-day'] );
77
+
} else {
78
+
$end_day = date_i18n( "j" );
79
+
}
80
+
81
+
if ( isset( $_REQUEST['end-year'] ) ) {
82
+
$end_year = intval( $_REQUEST['end-year'] );
83
+
} else {
84
+
$end_year = date_i18n( "Y" );
85
+
}
86
+
87
+
if ( isset( $_REQUEST['predefined-date'] ) ) {
88
+
$predefined_date = sanitize_text_field( $_REQUEST['predefined-date'] );
89
+
} else {
90
+
$predefined_date = "This Month";
91
+
}
92
+
93
+
if ( isset( $_REQUEST['status'] ) ) {
94
+
$status = sanitize_text_field( $_REQUEST['status'] );
95
+
} else {
96
+
$status = "";
97
+
}
98
+
99
+
if ( isset( $_REQUEST['filter'] ) ) {
100
+
$filter = sanitize_text_field( $_REQUEST['filter'] );
101
+
} else {
102
+
$filter = "all";
103
+
}
104
+
105
+
//some vars for the search
106
+
if ( ! empty( $_REQUEST['pn'] ) ) {
107
+
$pn = intval( $_REQUEST['pn'] );
108
+
} else {
109
+
$pn = 1;
110
+
}
111
+
112
+
if ( ! empty( $_REQUEST['limit'] ) ) {
113
+
$limit = intval( $_REQUEST['limit'] );
114
+
} else {
115
+
$limit = false;
116
+
}
117
+
118
+
if ( $limit ) {
119
+
$end = $pn * $limit;
120
+
$start = $end - $limit;
121
+
} else {
122
+
$end = null;
123
+
$start = null;
124
+
}
125
+
126
+
//filters
127
+
if ( $filter == "all" || ! $filter ) {
128
+
$condition = "1=1";
129
+
} elseif ( $filter == "within-a-date-range" ) {
130
+
$start_date = $start_year . "-" . $start_month . "-" . $start_day;
131
+
$end_date = $end_year . "-" . $end_month . "-" . $end_day;
132
+
133
+
//add times to dates and localize
134
+
$start_date = get_gmt_from_date( $start_date . ' 00:00:00' );
135
+
$end_date = get_gmt_from_date( $end_date . ' 23:59:59' );
136
+
137
+
$condition = "o.timestamp BETWEEN '" . $start_date . "' AND '" . $end_date . "'";
138
+
} elseif ( $filter == "predefined-date-range" ) {
139
+
if ( $predefined_date == "Last Month" ) {
140
+
$start_date = date_i18n( "Y-m-d", strtotime( "first day of last month", current_time( "timestamp" ) ) );
141
+
$end_date = date_i18n( "Y-m-d", strtotime( "last day of last month", current_time( "timestamp" ) ) );
142
+
} elseif ( $predefined_date == "This Month" ) {
143
+
$start_date = date_i18n( "Y-m-d", strtotime( "first day of this month", current_time( "timestamp" ) ) );
144
+
$end_date = date_i18n( "Y-m-d", strtotime( "last day of this month", current_time( "timestamp" ) ) );
145
+
} elseif ( $predefined_date == "This Year" ) {
146
+
$year = date_i18n( 'Y' );
147
+
$start_date = date_i18n( "Y-m-d", strtotime( "first day of January $year", current_time( "timestamp" ) ) );
148
+
$end_date = date_i18n( "Y-m-d", strtotime( "last day of December $year", current_time( "timestamp" ) ) );
149
+
} elseif ( $predefined_date == "Last Year" ) {
150
+
$year = date_i18n( 'Y' ) - 1;
151
+
$start_date = date_i18n( "Y-m-d", strtotime( "first day of January $year", current_time( "timestamp" ) ) );
152
+
$end_date = date_i18n( "Y-m-d", strtotime( "last day of December $year", current_time( "timestamp" ) ) );
153
+
}
154
+
155
+
//add times to dates and localize
156
+
$start_date = get_gmt_from_date( $start_date . ' 00:00:00' );
157
+
$end_date = get_gmt_from_date( $end_date . ' 23:59:59' );
158
+
159
+
$condition = "o.timestamp BETWEEN '" . esc_sql( $start_date ) . "' AND '" . esc_sql( $end_date ) . "'";
160
+
} elseif ( $filter == "within-a-level" ) {
161
+
$condition = "o.membership_id = " . (int) $l;
162
+
} elseif ( $filter == 'with-discount-code' ) {
163
+
$condition = 'dc.code_id = ' . (int) $discount_code;
164
+
} elseif ( $filter == "within-a-status" ) {
165
+
$condition = "o.status = '" . esc_sql( $status ) . "' ";
166
+
} elseif ( $filter == 'only-paid' ) {
167
+
$condition = "o.total > 0";
168
+
} elseif( $filter == 'only-free' ) {
169
+
$condition = "o.total = 0";
170
+
}
171
+
172
+
//string search
173
+
if ( ! empty( $s ) ) {
174
+
$sqlQuery = "
175
+
SELECT SQL_CALC_FOUND_ROWS o.id
176
+
FROM {$wpdb->pmpro_membership_orders} AS o
177
+
LEFT JOIN $wpdb->users u ON o.user_id = u.ID
178
+
LEFT JOIN $wpdb->pmpro_membership_levels l ON o.membership_id = l.id
179
+
";
180
+
181
+
// Join with discount codes if the filter is set to 'with-discount-code'
182
+
if ( $filter === 'with-discount-code' ) {
183
+
$sqlQuery .= "LEFT JOIN $wpdb->pmpro_discount_codes_uses dc ON o.id = dc.order_id ";
184
+
}
185
+
186
+
// Check if we are searching by a specific key or generally.
187
+
if ( strpos( $s, ':' ) !== false ) {
188
+
// Get the search key and value.
189
+
$parts = explode( ':', $s );
190
+
$search_key = array_shift( $parts );
191
+
$s = implode( ':', $parts );
192
+
193
+
$sqlQuery .= 'WHERE (1=2 ';
194
+
// If there's a colon in the search string, make the search smarter.
195
+
if ( in_array( $search_key, array( 'login', 'nicename', 'email', 'url', 'display_name' ), true ) ) {
196
+
$key_column = 'u.user_' . $search_key; // All search key options above are safe for use in a query.
197
+
$sqlQuery .= " OR $key_column LIKE '%" . esc_sql( $s ) . "%' ";
198
+
} else {
199
+
// Assume order table column.
200
+
$sqlQuery .= " OR o.$search_key LIKE '%" . esc_sql( $s ) . "%' ";
201
+
}
202
+
$sqlQuery .= ') ';
203
+
} else {
204
+
$join_with_usermeta = apply_filters( "pmpro_orders_search_usermeta", false );
205
+
206
+
if ( ! empty( $join_with_usermeta ) ) {
207
+
$sqlQuery .= "LEFT JOIN $wpdb->usermeta um ON o.user_id = um.user_id ";
208
+
}
209
+
210
+
$sqlQuery .= "WHERE (1=2 ";
211
+
212
+
$fields = array(
213
+
'o.id',
214
+
'o.code',
215
+
'o.billing_name',
216
+
'o.billing_street',
217
+
'o.billing_street2',
218
+
'o.billing_city',
219
+
'o.billing_state',
220
+
'o.billing_zip',
221
+
'o.billing_country',
222
+
'o.billing_phone',
223
+
'o.payment_type',
224
+
'o.cardtype',
225
+
'o.accountnumber',
226
+
'o.status',
227
+
'o.gateway',
228
+
'o.gateway_environment',
229
+
'o.payment_transaction_id',
230
+
'o.subscription_transaction_id',
231
+
'o.notes',
232
+
'u.user_login',
233
+
'u.user_email',
234
+
'u.display_name',
235
+
'ml.name',
236
+
);
237
+
238
+
if ( ! empty( $join_with_usermeta ) ) {
239
+
$fields[] = "um.meta_value";
240
+
}
241
+
242
+
$fields = apply_filters( "pmpro_orders_search_fields", $fields );
243
+
244
+
foreach ( $fields as $field ) {
245
+
$sqlQuery .= " OR " . esc_sql( $field ) . " LIKE '%" . esc_sql( $s ) . "%' ";
246
+
}
247
+
248
+
$sqlQuery .= ") ";
249
+
}
250
+
//Not escaping here because we escape the values in the condition statement
251
+
$sqlQuery .= "AND " . $condition . " ";
252
+
$sqlQuery .= "GROUP BY o.id ORDER BY o.id DESC, o.timestamp DESC ";
253
+
254
+
} else {
255
+
$sqlQuery = "SELECT SQL_CALC_FOUND_ROWS o.id FROM $wpdb->pmpro_membership_orders o ";
256
+
257
+
if ( $filter === 'with-discount-code' ) {
258
+
$sqlQuery .= "LEFT JOIN $wpdb->pmpro_discount_codes_uses dc ON o.id = dc.order_id ";
259
+
}
260
+
//Not escaping here because we escape the values in the condition statement
261
+
$sqlQuery .= "WHERE " . $condition . ' ORDER BY o.id DESC, o.timestamp DESC ';
262
+
}
263
+
264
+
if ( ! empty( $start ) && ! empty( $limit ) ) {
265
+
$sqlQuery .= "LIMIT " . (int) $start . "," . (int) $limit;
266
+
}
267
+
268
+
$headers = array();
269
+
$headers[] = "Content-Type: text/csv";
270
+
$headers[] = "Cache-Control: max-age=0, no-cache, no-store";
271
+
$headers[] = "Pragma: no-cache";
272
+
$headers[] = "Connection: close";
273
+
274
+
$filename = "orders.csv";
275
+
/*
276
+
Insert logic here for building filename from $filter and other values.
277
+
*/
278
+
$filename = apply_filters( 'pmpro_orders_csv_export_filename', $filename );
279
+
$headers[] = "Content-Disposition: attachment; filename={$filename};";
280
+
281
+
$csv_file_header_array = array(
282
+
"id",
283
+
"code",
284
+
"user_id",
285
+
"user_login",
286
+
"first_name",
287
+
"last_name",
288
+
"user_email",
289
+
"billing_name",
290
+
"billing_street",
291
+
"billing_city",
292
+
"billing_state",
293
+
"billing_zip",
294
+
"billing_country",
295
+
"billing_phone",
296
+
"membership_id",
297
+
"level_name",
298
+
"subtotal",
299
+
"tax",
300
+
"total",
301
+
"payment_type",
302
+
"cardtype",
303
+
"accountnumber",
304
+
"expirationmonth",
305
+
"expirationyear",
306
+
"status",
307
+
"gateway",
308
+
"gateway_environment",
309
+
"payment_transaction_id",
310
+
"subscription_transaction_id",
311
+
"discount_code_id",
312
+
"discount_code",
313
+
"timestamp"
314
+
);
315
+
316
+
//these are the meta_keys for the fields (arrays are object, property. so e.g. $theuser->ID)
317
+
$default_columns = array(
318
+
array( "order", "id" ),
319
+
array( "order", "code" ),
320
+
array( "user", "ID" ),
321
+
array( "user", "user_login" ),
322
+
array( "user", "first_name" ),
323
+
array( "user", "last_name" ),
324
+
array( "user", "user_email" ),
325
+
array( "order", "billing", "name" ),
326
+
array( "order", "billing", "street" ),
327
+
array( "order", "billing", "city" ),
328
+
array( "order", "billing", "state" ),
329
+
array( "order", "billing", "zip" ),
330
+
array( "order", "billing", "country" ),
331
+
array( "order", "billing", "phone" ),
332
+
array( "order", "membership_id" ),
333
+
array( "level", "name" ),
334
+
array( "order", "subtotal" ),
335
+
array( "order", "tax" ),
336
+
array( "order", "total" ),
337
+
array( "order", "payment_type" ),
338
+
array( "order", "cardtype" ),
339
+
array( "order", "accountnumber" ),
340
+
array( "order", "expirationmonth" ),
341
+
array( "order", "expirationyear" ),
342
+
array( "order", "status" ),
343
+
array( "order", "gateway" ),
344
+
array( "order", "gateway_environment" ),
345
+
array( "order", "payment_transaction_id" ),
346
+
array( "order", "subscription_transaction_id" ),
347
+
array( "discount_code", "id" ),
348
+
array( "discount_code", "code" )
349
+
);
350
+
351
+
$default_columns = apply_filters( "pmpro_order_list_csv_default_columns", $default_columns );
352
+
353
+
$csv_file_header_array = apply_filters( "pmpro_order_list_csv_export_header_array", $csv_file_header_array );
354
+
355
+
$dateformat = apply_filters( 'pmpro_order_list_csv_dateformat', get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
356
+
357
+
//any extra columns
358
+
$extra_columns = apply_filters( "pmpro_orders_csv_extra_columns", array() ); //the original filter
359
+
$extra_columns = apply_filters( "pmpro_order_list_csv_extra_columns", $extra_columns ); //in case anyone used the typo'd filter
360
+
361
+
if ( ! empty( $extra_columns ) ) {
362
+
foreach ( $extra_columns as $heading => $callback ) {
363
+
$csv_file_header_array[] = $heading;
364
+
}
365
+
}
366
+
367
+
$csv_file_header = implode( ',', $csv_file_header_array ) . "\n";
368
+
369
+
// Generate a temporary file to store the data in.
370
+
$tmp_dir = apply_filters( 'pmpro_order_list_csv_export_tmp_dir', sys_get_temp_dir() );
371
+
$filename = tempnam( $tmp_dir, 'pmpro_olcsv_' );
372
+
373
+
// open in append mode
374
+
$csv_fh = fopen( $filename, 'a' );
375
+
376
+
//write the CSV header to the file
377
+
fprintf( $csv_fh, '%s', $csv_file_header );
378
+
379
+
$order_ids = $wpdb->get_col( $sqlQuery );
380
+
$orders_found = count( $order_ids );
381
+
382
+
if ( empty( $order_ids ) ) {
383
+
// send data to remote browser
384
+
pmpro_transmit_order_content( $csv_fh, $filename, $headers );
385
+
}
386
+
387
+
if (PMPRO_BENCHMARK)
388
+
{
389
+
$pre_action_time = microtime(true);
390
+
$pre_action_memory = memory_get_usage(true);
391
+
}
392
+
393
+
do_action('pmpro_before_order_list_csv_export', $order_ids);
394
+
395
+
$i_start = 0;
396
+
$i_limit = 0;
397
+
$iterations = 1;
398
+
399
+
if ( $orders_found >= $max_orders_per_loop ) {
400
+
$iterations = ceil( $orders_found / $max_orders_per_loop );
401
+
$i_limit = $max_orders_per_loop;
402
+
}
403
+
404
+
$end = 0;
405
+
$time_limit = ini_get( 'max_execution_time' );
406
+
407
+
if (PMPRO_BENCHMARK)
408
+
{
409
+
error_log("PMPRO_BENCHMARK - Total records to process: {$orders_found}");
410
+
error_log("PMPRO_BENCHMARK - Will process {$iterations} iterations of max {$max_orders_per_loop} records per iteration.");
411
+
$pre_iteration_time = microtime(true);
412
+
$pre_iteration_memory = memory_get_usage(true);
413
+
}
414
+
415
+
for ( $ic = 1; $ic <= $iterations; $ic ++ ) {
416
+
417
+
if (PMPRO_BENCHMARK)
418
+
{
419
+
$start_iteration_time = microtime(true);
420
+
$start_iteration_memory = memory_get_usage(true);
421
+
}
422
+
423
+
// avoiding timeouts (modify max run-time for export)
424
+
if ( $end != 0 ) {
425
+
426
+
$iteration_diff = $end - $start;
427
+
$new_time_limit = ceil( $iteration_diff * $iterations * 1.2 );
428
+
429
+
if ( $time_limit < $new_time_limit ) {
430
+
$time_limit = $new_time_limit;
431
+
set_time_limit( $time_limit );
432
+
}
433
+
}
434
+
435
+
$start = current_time( 'timestamp' );
436
+
437
+
// get the first order id
438
+
$first_oid = $order_ids[ $i_start ];
439
+
440
+
//get last UID, will depend on which iteration we're on.
441
+
if ( $ic != $iterations ) {
442
+
$last_oid = $order_ids[ ( $i_start + ( $max_orders_per_loop - 1 ) ) ];
443
+
} else {
444
+
// Final iteration, so last UID is the last record in the users array
445
+
$last_oid = $order_ids[ ( $orders_found - 1 ) ];
446
+
}
447
+
448
+
//increment starting position
449
+
if ( $ic > 1 ) {
450
+
$i_start += $max_orders_per_loop;
451
+
}
452
+
// get the order list we should process
453
+
$order_list = array_slice( $order_ids, $i_start, $max_orders_per_loop );
454
+
455
+
if (PMPRO_BENCHMARK)
456
+
{
457
+
$pre_orderdata_time = microtime(true);
458
+
$pre_orderdata_memory = memory_get_usage(true);
459
+
}
460
+
461
+
foreach ( $order_list as $order_id ) {
462
+
$csvoutput = array();
463
+
464
+
$order = new MemberOrder();
465
+
$order->nogateway = true;
466
+
467
+
$order->getMemberOrderByID( $order_id );
468
+
469
+
$user = get_userdata( $order->user_id );
470
+
$level = $order->getMembershipLevel();
471
+
472
+
$sqlQuery = $wpdb->prepare( "
473
+
SELECT c.id, c.code
474
+
FROM {$wpdb->pmpro_discount_codes_uses} AS cu
475
+
LEFT JOIN {$wpdb->pmpro_discount_codes} AS c
476
+
ON cu.code_id = c.id
477
+
WHERE cu.order_id = %s
478
+
LIMIT 1",
479
+
$order_id
480
+
);
481
+
482
+
$discount_code = $wpdb->get_row( $sqlQuery );
483
+
484
+
//default columns
485
+
if ( ! empty( $default_columns ) ) {
486
+
$count = 0;
487
+
foreach ( $default_columns as $col ) {
488
+
489
+
//checking $object->property. note the double $$
490
+
switch ( count( $col ) ) {
491
+
case 3:
492
+
$val = isset( ${$col[0]}->{$col[1]}->{$col[2]} ) ? ${$col[0]}->{$col[1]}->{$col[2]} : null;
493
+
break;
494
+
495
+
case 2:
496
+
$val = isset( ${$col[0]}->{$col[1]} ) ? ${$col[0]}->{$col[1]} : null;
497
+
break;
498
+
499
+
default:
500
+
501
+
$val = null;
502
+
}
503
+
504
+
array_push( $csvoutput, pmpro_enclose( $val ) );
505
+
}
506
+
}
507
+
508
+
//timestamp
509
+
$ts = date_i18n( $dateformat, $order->getTimestamp() );
510
+
array_push( $csvoutput, pmpro_enclose( $ts ) );
511
+
512
+
//any extra columns
513
+
if ( ! empty( $extra_columns ) ) {
514
+
foreach ( $extra_columns as $heading => $callback ) {
515
+
$val = call_user_func( $callback, $order );
516
+
$val = ! empty( $val ) ? $val : null;
517
+
518
+
array_push( $csvoutput, pmpro_enclose( $val ) );
519
+
}
520
+
}
521
+
522
+
$line = implode( ',', $csvoutput ) . "\n";
523
+
524
+
//output
525
+
fprintf( $csv_fh, "%s", $line );
526
+
527
+
$line = null;
528
+
$csvoutput = null;
529
+
530
+
$end = current_time( 'timestamp' );
531
+
532
+
} // end of foreach orders
533
+
534
+
if (PMPRO_BENCHMARK)
535
+
{
536
+
$after_data_time = microtime(true);
537
+
$after_data_memory = memory_get_peak_usage(true);
538
+
539
+
$time_processing_data = $after_data_time - $start_time;
540
+
$memory_processing_data = $after_data_memory - $start_memory;
541
+
542
+
list($sec, $usec) = explode('.', $time_processing_data);
543
+
544
+
error_log("PMPRO_BENCHMARK - Time processing data: {$sec}.{$usec} seconds");
545
+
error_log("PMPRO_BENCHMARK - Peak memory usage: " . number_format($memory_processing_data, false, '.', ',') . " bytes");
546
+
}
547
+
$order_list = null;
548
+
wp_cache_flush();
549
+
}
550
+
pmpro_transmit_order_content( $csv_fh, $filename, $headers );
551
+
552
+
function pmpro_enclose( $s ) {
553
+
return "\"" . str_replace( "\"", "\\\"", $s ) . "\"";
554
+
}
555
+
556
+
557
+
function pmpro_transmit_order_content( $csv_fh, $filename, $headers = array() ) {
558
+
559
+
//close the temp file
560
+
fclose( $csv_fh );
561
+
562
+
if ( version_compare( phpversion(), '5.3.0', '>' ) ) {
563
+
564
+
//make sure we get the right file size
565
+
clearstatcache( true, $filename );
566
+
} else {
567
+
// for any PHP version prior to v5.3.0
568
+
clearstatcache();
569
+
}
570
+
571
+
//did we accidentally send errors/warnings to browser?
572
+
if ( headers_sent() ) {
573
+
echo esc_html( str_repeat( '-', 75 ) ) . "<br/>\n";
574
+
echo 'Please open a support case and paste in the warnings/errors you see above this text to\n ';
575
+
echo 'the <a href="http://paidmembershipspro.com/support/?utm_source=plugin&utm_medium=pmpro-orders-csv&utm_campaign=support" target="_blank">Paid Memberships Pro support forum</a><br/>\n';
576
+
echo esc_html( str_repeat( '-', 75 ) ) . "<br/>\n";
577
+
echo wp_kses_post( file_get_contents( $filename ) );
578
+
echo esc_html( str_repeat( '-', 75 ) ) . "<br/>\n";
579
+
}
580
+
581
+
//transmission
582
+
if ( ! empty( $headers ) ) {
583
+
//set the download size
584
+
$headers[] = "Content-Length: " . filesize( $filename );
585
+
586
+
//set headers
587
+
foreach ( $headers as $header ) {
588
+
header( $header . "\r\n" );
589
+
}
590
+
591
+
// disable compression for the duration of file download
592
+
if ( ini_get( 'zlib.output_compression' ) ) {
593
+
ini_set( 'zlib.output_compression', 'Off' );
594
+
}
595
+
596
+
if( function_exists( 'fpassthru' ) ) {
597
+
// use fpassthru to output the csv
598
+
$csv_fh = fopen( $filename, 'rb' );
599
+
fpassthru( $csv_fh );
600
+
fclose( $csv_fh );
601
+
} else {
602
+
// use readfile() if fpassthru() is disabled (like on Flywheel Hosted)
603
+
readfile( $filename );
604
+
}
605
+
606
+
// remove the temp file
607
+
unlink( $filename );
608
+
}
609
+
610
+
//allow user to clean up after themselves
611
+
do_action( 'pmpro_after_order_csv_export' );
612
+
exit;
613
+
}
614
+