Paid Memberships Pro - Version 1.9.4.4

Version Description

  • BUG FIX: Updated the filters to extend membership levels to use the new pmpro_getSpecificMembershipLevelForUser() function to avoid bugs when MMPU is enabled.
  • BUG FIX: Fixed cases where certain email templates were resulting in the body of the email being duplicated.
  • BUG FIX: Fixed conflict with pmpro-email-templates when emails were disabled (the pmpro_email filter returns false). (Thanks, Mathieu Hays)
  • BUG FIX: Now updating status on related subscription orders BEFORE canceling at gateway to avoid cases where the webhook sent by the gateway after canceling the subscription triggers further cancellation attempts.
  • BUG FIX: No longer showing the "Stripe Publishable Key appears incorrect" error message if the key field is blank.
  • ENHANCEMENT: Added the pmpro_getSpecificMembershipLevelForUser( $user_id, $level_id ) function for cases where MMPU is enabled and you want data about a specific membership level a user might have.
  • ENHANCEMENT: Changed labels on the reCAPTCHA settings to match their current terminology: Site Key and Secret Key.
Download this release

Release Info

Developer strangerstudios
Plugin Icon 128x128 Paid Memberships Pro
Version 1.9.4.4
Comparing to
See all releases

Code changes from version 1.9.4.3 to 1.9.4.4

adminpages/advancedsettings.php CHANGED
@@ -245,11 +245,11 @@ if(pmpro_displayAds())
245
<tr id="recaptcha_tr" <?php if(!$recaptcha) { ?>style="display: none;"<?php } ?>>
246
<th scope="row" valign="top">&nbsp;</th>
247
<td>
248
- <label for="recaptcha_publickey"><?php _e('reCAPTCHA Public Key', 'paid-memberships-pro' );?>:</label>
249
- <input type="text" name="recaptcha_publickey" size="60" value="<?php echo esc_attr($recaptcha_publickey);?>" />
250
<br /><br />
251
- <label for="recaptcha_privatekey"><?php _e('reCAPTCHA Private Key', 'paid-memberships-pro' );?>:</label>
252
- <input type="text" name="recaptcha_privatekey" size="60" value="<?php echo esc_attr($recaptcha_privatekey);?>" />
253
</td>
254
</tr>
255
<tr>
245
<tr id="recaptcha_tr" <?php if(!$recaptcha) { ?>style="display: none;"<?php } ?>>
246
<th scope="row" valign="top">&nbsp;</th>
247
<td>
248
+ <label for="recaptcha_publickey"><?php _e('reCAPTCHA Site Key', 'paid-memberships-pro' );?>:</label>
249
+ <input type="text" id="recaptcha_publickey" name="recaptcha_publickey" size="60" value="<?php echo esc_attr($recaptcha_publickey);?>" />
250
<br /><br />
251
+ <label for="recaptcha_privatekey"><?php _e('reCAPTCHA Secret Key', 'paid-memberships-pro' );?>:</label>
252
+ <input type="text" id="recaptcha_privatekey" name="recaptcha_privatekey" size="60" value="<?php echo esc_attr($recaptcha_privatekey);?>" />
253
</td>
254
</tr>
255
<tr>
adminpages/orders.php CHANGED
@@ -1,15 +1,15 @@
1
<?php
2
- //only admins can get this
3
- if ( ! function_exists( "current_user_can" ) || ( ! current_user_can( "manage_options" ) && ! current_user_can( "pmpro_orders" ) ) ) {
4
- die( __( "You do not have permissions to perform this action.", 'paid-memberships-pro' ) );
5
}
6
7
- //vars
8
global $wpdb;
9
if ( isset( $_REQUEST['s'] ) ) {
10
$s = sanitize_text_field( trim( $_REQUEST['s'] ) );
11
} else {
12
- $s = "";
13
}
14
15
if ( isset( $_REQUEST['l'] ) ) {
@@ -21,58 +21,58 @@ if ( isset( $_REQUEST['l'] ) ) {
21
if ( isset( $_REQUEST['start-month'] ) ) {
22
$start_month = intval( $_REQUEST['start-month'] );
23
} else {
24
- $start_month = "1";
25
}
26
27
if ( isset( $_REQUEST['start-day'] ) ) {
28
$start_day = intval( $_REQUEST['start-day'] );
29
} else {
30
- $start_day = "1";
31
}
32
33
if ( isset( $_REQUEST['start-year'] ) ) {
34
$start_year = intval( $_REQUEST['start-year'] );
35
} else {
36
- $start_year = date_i18n( "Y" );
37
}
38
39
if ( isset( $_REQUEST['end-month'] ) ) {
40
$end_month = intval( $_REQUEST['end-month'] );
41
} else {
42
- $end_month = date_i18n( "n" );
43
}
44
45
if ( isset( $_REQUEST['end-day'] ) ) {
46
$end_day = intval( $_REQUEST['end-day'] );
47
} else {
48
- $end_day = date_i18n( "j" );
49
}
50
51
if ( isset( $_REQUEST['end-year'] ) ) {
52
$end_year = intval( $_REQUEST['end-year'] );
53
} else {
54
- $end_year = date_i18n( "Y" );
55
}
56
57
if ( isset( $_REQUEST['predefined-date'] ) ) {
58
$predefined_date = sanitize_text_field( $_REQUEST['predefined-date'] );
59
} else {
60
- $predefined_date = "This Month";
61
}
62
63
if ( isset( $_REQUEST['status'] ) ) {
64
$status = sanitize_text_field( $_REQUEST['status'] );
65
} else {
66
- $status = "";
67
}
68
69
if ( isset( $_REQUEST['filter'] ) ) {
70
$filter = sanitize_text_field( $_REQUEST['filter'] );
71
} else {
72
- $filter = "all";
73
}
74
75
- //some vars for the search
76
if ( isset( $_REQUEST['pn'] ) ) {
77
$pn = intval( $_REQUEST['pn'] );
78
} else {
@@ -96,94 +96,96 @@ if ( isset( $_REQUEST['limit'] ) ) {
96
$end = $pn * $limit;
97
$start = $end - $limit;
98
99
- //filters
100
- if ( empty( $filter ) || $filter === "all" ) {
101
- $condition = "1=1";
102
- $filter = "all";
103
- } elseif ( $filter == "within-a-date-range" ) {
104
- $start_date = $start_year . "-" . $start_month . "-" . $start_day;
105
- $end_date = $end_year . "-" . $end_month . "-" . $end_day;
106
107
- //add times to dates
108
- $start_date = $start_date . " 00:00:00";
109
- $end_date = $end_date . " 23:59:59";
110
111
$condition = "timestamp BETWEEN '" . esc_sql( $start_date ) . "' AND '" . esc_sql( $end_date ) . "'";
112
- } elseif ( $filter == "predefined-date-range" ) {
113
- if ( $predefined_date == "Last Month" ) {
114
- $start_date = date_i18n( "Y-m-d", strtotime( "first day of last month", current_time( "timestamp" ) ) );
115
- $end_date = date_i18n( "Y-m-d", strtotime( "last day of last month", current_time( "timestamp" ) ) );
116
- } elseif ( $predefined_date == "This Month" ) {
117
- $start_date = date_i18n( "Y-m-d", strtotime( "first day of this month", current_time( "timestamp" ) ) );
118
- $end_date = date_i18n( "Y-m-d", strtotime( "last day of this month", current_time( "timestamp" ) ) );
119
- } elseif ( $predefined_date == "This Year" ) {
120
$year = date_i18n( 'Y' );
121
- $start_date = date_i18n( "Y-m-d", strtotime( "first day of January $year", current_time( "timestamp" ) ) );
122
- $end_date = date_i18n( "Y-m-d", strtotime( "last day of December $year", current_time( "timestamp" ) ) );
123
- } elseif ( $predefined_date == "Last Year" ) {
124
$year = date_i18n( 'Y' ) - 1;
125
- $start_date = date_i18n( "Y-m-d", strtotime( "first day of January $year", current_time( "timestamp" ) ) );
126
- $end_date = date_i18n( "Y-m-d", strtotime( "last day of December $year", current_time( "timestamp" ) ) );
127
}
128
129
- //add times to dates
130
- $start_date = $start_date . " 00:00:00";
131
- $end_date = $end_date . " 23:59:59";
132
133
$condition = "timestamp BETWEEN '" . esc_sql( $start_date ) . "' AND '" . esc_sql( $end_date ) . "'";
134
- } elseif ( $filter == "within-a-level" ) {
135
- $condition = "membership_id = " . esc_sql( $l );
136
- } elseif ( $filter == "within-a-status" ) {
137
$condition = "status = '" . esc_sql( $status ) . "' ";
138
}
139
140
- //emailing?
141
if ( ! empty( $_REQUEST['email'] ) && ! empty( $_REQUEST['order'] ) ) {
142
$email = new PMProEmail();
143
- $user = get_user_by( 'email', sanitize_email($_REQUEST['email']) );
144
$order = new MemberOrder( $_REQUEST['order'] );
145
if ( $email->sendBillableInvoiceEmail( $user, $order ) ) {
146
- $pmpro_msg = __( "Invoice emailed successfully.", 'paid-memberships-pro' );
147
- $pmpro_msgt = "success";
148
} else {
149
- $pmpro_msg = __( "Error emailing invoice.", 'paid-memberships-pro' );
150
- $pmpro_msgt = "error";
151
}
152
153
- //clean up so we stay on the orders list view
154
unset( $_REQUEST['order'] );
155
$order = null;
156
}
157
158
- //deleting?
159
if ( ! empty( $_REQUEST['delete'] ) ) {
160
$dorder = new MemberOrder( intval( $_REQUEST['delete'] ) );
161
if ( $dorder->deleteMe() ) {
162
- $pmpro_msg = __( "Order deleted successfully.", 'paid-memberships-pro' );
163
- $pmpro_msgt = "success";
164
} else {
165
- $pmpro_msg = __( "Error deleting order.", 'paid-memberships-pro' );
166
- $pmpro_msgt = "error";
167
}
168
}
169
170
- $thisyear = date_i18n( "Y" );
171
172
- //this array stores fields that should be read only
173
- $read_only_fields = apply_filters( "pmpro_orders_read_only_fields", array(
174
- "code",
175
- "payment_transaction_id",
176
- "subscription_transaction_id"
177
- ) );
178
179
- //if this is a new order or copy of one, let's make all fields editable
180
- if( ! empty( $_REQUEST['order'] ) && $_REQUEST['order'] < 0 ) {
181
$read_only_fields = array();
182
}
183
184
- //saving?
185
if ( ! empty( $_REQUEST['save'] ) ) {
186
- //start with old order if applicable
187
$order_id = intval( $_REQUEST['order'] );
188
if ( $order_id > 0 ) {
189
$order = new MemberOrder( $order_id );
@@ -192,118 +194,118 @@ if ( ! empty( $_REQUEST['save'] ) ) {
192
$order->billing = new stdClass();
193
}
194
195
- //update values
196
- if ( ! in_array( "code", $read_only_fields ) && isset( $_POST['code'] ) ) {
197
$order->code = sanitize_text_field( $_POST['code'] );
198
}
199
- if ( ! in_array( "user_id", $read_only_fields ) && isset( $_POST['user_id'] ) ) {
200
$order->user_id = intval( $_POST['user_id'] );
201
}
202
- if ( ! in_array( "membership_id", $read_only_fields ) && isset( $_POST['membership_id'] ) ) {
203
$order->membership_id = intval( $_POST['membership_id'] );
204
}
205
- if ( ! in_array( "billing_name", $read_only_fields ) && isset( $_POST['billing_name'] ) ) {
206
- $order->billing->name = sanitize_text_field(wp_unslash( $_POST['billing_name'] ));
207
}
208
- if ( ! in_array( "billing_street", $read_only_fields ) && isset( $_POST['billing_street'] ) ) {
209
- $order->billing->street = sanitize_text_field(wp_unslash( $_POST['billing_street'] ));
210
}
211
- if ( ! in_array( "billing_city", $read_only_fields ) && isset( $_POST['billing_city'] ) ) {
212
- $order->billing->city = sanitize_text_field(wp_unslash( $_POST['billing_city'] ));
213
}
214
- if ( ! in_array( "billing_state", $read_only_fields ) && isset( $_POST['billing_state'] ) ) {
215
- $order->billing->state = sanitize_text_field(wp_unslash( $_POST['billing_state'] ));
216
}
217
- if ( ! in_array( "billing_zip", $read_only_fields ) && isset( $_POST['billing_zip'] ) ) {
218
$order->billing->zip = sanitize_text_field( $_POST['billing_zip'] );
219
}
220
- if ( ! in_array( "billing_country", $read_only_fields ) && isset( $_POST['billing_country'] ) ) {
221
- $order->billing->country = sanitize_text_field(wp_unslash( $_POST['billing_country'] ));
222
}
223
- if ( ! in_array( "billing_phone", $read_only_fields ) && isset( $_POST['billing_phone'] ) ) {
224
$order->billing->phone = sanitize_text_field( $_POST['billing_phone'] );
225
}
226
- if ( ! in_array( "subtotal", $read_only_fields ) && isset( $_POST['subtotal'] ) ) {
227
$order->subtotal = sanitize_text_field( $_POST['subtotal'] );
228
}
229
- if ( ! in_array( "tax", $read_only_fields ) && isset( $_POST['tax'] ) ) {
230
$order->tax = sanitize_text_field( $_POST['tax'] );
231
}
232
- if ( ! in_array( "couponamount", $read_only_fields ) && isset( $_POST['couponamount'] ) ) {
233
$order->couponamount = sanitize_text_field( $_POST['couponamount'] );
234
}
235
- if ( ! in_array( "total", $read_only_fields ) && isset( $_POST['total'] ) ) {
236
$order->total = sanitize_text_field( $_POST['total'] );
237
}
238
- if ( ! in_array( "payment_type", $read_only_fields ) && isset( $_POST['payment_type'] ) ) {
239
$order->payment_type = sanitize_text_field( $_POST['payment_type'] );
240
}
241
- if ( ! in_array( "cardtype", $read_only_fields ) && isset( $_POST['cardtype'] ) ) {
242
$order->cardtype = sanitize_text_field( $_POST['cardtype'] );
243
}
244
- if ( ! in_array( "accountnumber", $read_only_fields ) && isset( $_POST['accountnumber'] ) ) {
245
$order->accountnumber = sanitize_text_field( $_POST['accountnumber'] );
246
}
247
- if ( ! in_array( "expirationmonth", $read_only_fields ) && isset( $_POST['expirationmonth'] ) ) {
248
$order->expirationmonth = sanitize_text_field( $_POST['expirationmonth'] );
249
}
250
- if ( ! in_array( "expirationyear", $read_only_fields ) && isset( $_POST['expirationyear'] ) ) {
251
$order->expirationyear = sanitize_text_field( $_POST['expirationyear'] );
252
}
253
-
254
- if ( ! in_array( "status", $read_only_fields ) && isset( $_POST['status'] ) ) {
255
$order->status = pmpro_sanitize_with_safelist( $_POST['status'], pmpro_getOrderStatuses() );
256
}
257
- if ( ! in_array( "gateway", $read_only_fields ) && isset( $_POST['gateway'] ) ) {
258
$order->gateway = sanitize_text_field( $_POST['gateway'] );
259
}
260
- if ( ! in_array( "gateway_environment", $read_only_fields ) && isset( $_POST['gateway_environment'] ) ) {
261
$order->gateway_environment = sanitize_text_field( $_POST['gateway_environment'] );
262
}
263
- if ( ! in_array( "payment_transaction_id", $read_only_fields ) && isset( $_POST['payment_transaction_id'] ) ) {
264
$order->payment_transaction_id = sanitize_text_field( $_POST['payment_transaction_id'] );
265
}
266
- if ( ! in_array( "subscription_transaction_id", $read_only_fields ) && isset( $_POST['subscription_transaction_id'] ) ) {
267
$order->subscription_transaction_id = sanitize_text_field( $_POST['subscription_transaction_id'] );
268
}
269
- if ( ! in_array( "notes", $read_only_fields ) && isset( $_POST['notes'] ) ) {
270
global $allowedposttags;
271
- $order->notes = wp_kses(wp_unslash($_REQUEST['notes']), $allowedposttags);
272
}
273
274
- //affiliate stuff
275
- $affiliates = apply_filters( "pmpro_orders_show_affiliate_ids", false );
276
if ( ! empty( $affiliates ) ) {
277
- if ( ! in_array( "affiliate_id", $read_only_fields ) ) {
278
$order->affiliate_id = sanitize_text_field( $_POST['affiliate_id'] );
279
}
280
- if ( ! in_array( "affiliate_subid", $read_only_fields ) ) {
281
$order->affiliate_subid = sanitize_text_field( $_POST['affiliate_subid'] );
282
}
283
}
284
285
- //check nonce for saving
286
$nonceokay = true;
287
- if (empty($_REQUEST['pmpro_orders_nonce']) || !check_admin_referer('save', 'pmpro_orders_nonce')) {
288
$nonceokay = false;
289
}
290
-
291
- //save
292
- if ( $order->saveOrder() !== false && $nonceokay) {
293
- //handle timestamp
294
- if ( $order->updateTimestamp( intval($_POST['ts_year']), intval($_POST['ts_month']), intval($_POST['ts_day']) ) !== false ) {
295
- $pmpro_msg = __( "Order saved successfully.", 'paid-memberships-pro' );
296
- $pmpro_msgt = "success";
297
} else {
298
- $pmpro_msg = __( "Error updating order timestamp.", 'paid-memberships-pro' );
299
- $pmpro_msgt = "error";
300
}
301
} else {
302
- $pmpro_msg = __( "Error saving order.", 'paid-memberships-pro' );
303
- $pmpro_msgt = "error";
304
}
305
} else {
306
- //order passed?
307
if ( ! empty( $_REQUEST['order'] ) ) {
308
$order_id = intval( $_REQUEST['order'] );
309
if ( $order_id > 0 ) {
@@ -311,90 +313,100 @@ if ( ! empty( $_REQUEST['save'] ) ) {
311
} elseif ( ! empty( $_REQUEST['copy'] ) ) {
312
$order = new MemberOrder( intval( $_REQUEST['copy'] ) );
313
314
- //new id
315
$order->id = null;
316
317
- //new code
318
$order->code = $order->getRandomCode();
319
} else {
320
- $order = new MemberOrder(); //new order
321
322
- //defaults
323
$order->code = $order->getRandomCode();
324
- $order->user_id = "";
325
- $order->membership_id = "";
326
$order->billing = new stdClass();
327
- $order->billing->name = "";
328
- $order->billing->street = "";
329
- $order->billing->city = "";
330
- $order->billing->state = "";
331
- $order->billing->zip = "";
332
- $order->billing->country = "";
333
- $order->billing->phone = "";
334
- $order->subtotal = "";
335
- $order->tax = "";
336
- $order->couponamount = "";
337
- $order->total = "";
338
- $order->payment_type = "";
339
- $order->cardtype = "";
340
- $order->accountnumber = "";
341
- $order->expirationmonth = "";
342
- $order->expirationyear = "";
343
- $order->status = "success";
344
- $order->gateway = pmpro_getOption("gateway");
345
- $order->gateway_environment = pmpro_getOption("gateway_environment");
346
- $order->payment_transaction_id = "";
347
- $order->subscription_transaction_id = "";
348
- $order->affiliate_id = "";
349
- $order->affiliate_subid = "";
350
- $order->notes = "";
351
}
352
}
353
}
354
355
- require_once( dirname( __FILE__ ) . "/admin_header.php" );
356
?>
357
358
<?php if ( ! empty( $order ) ) { ?>
359
360
<h2>
361
<?php if ( ! empty( $order->id ) ) { ?>
362
- <?php _e( 'Order', 'paid-memberships-pro' ); ?> #<?php echo $order->id ?>: <?php echo $order->code ?>
363
<?php } else { ?>
364
<?php _e( 'New Order', 'paid-memberships-pro' ); ?>
365
<?php } ?>
366
</h2>
367
368
<?php if ( ! empty( $pmpro_msg ) ) { ?>
369
- <div id="message" class="<?php if ( $pmpro_msgt == "success" ) {
370
- echo "updated fade";
371
} else {
372
- echo "error";
373
- } ?>"><p><?php echo $pmpro_msg ?></p></div>
374
<?php } ?>
375
376
<form method="post" action="">
377
- <?php wp_nonce_field('save', 'pmpro_orders_nonce');?>
378
379
<table class="form-table">
380
<tbody>
381
<tr>
382
<th scope="row" valign="top"><label>ID:</label></th>
383
- <td><?php if ( ! empty( $order->id ) ) {
384
echo $order->id;
385
- } else {
386
- echo __( "This will be generated when you save.", 'paid-memberships-pro' );
387
- } ?></td>
388
</tr>
389
390
<tr>
391
<th scope="row" valign="top"><label for="code"><?php _e( 'Code', 'paid-memberships-pro' ); ?>:</label></th>
392
<td>
393
- <?php if ( in_array( "code", $read_only_fields ) ) {
394
echo $order->code;
395
- } else { ?>
396
- <input id="code" name="code" type="text" size="50"
397
- value="<?php echo esc_attr( $order->code ); ?>"/>
398
<?php } ?>
399
<?php if ( $order_id < 0 ) { ?>
400
<small
@@ -405,11 +417,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
405
<tr>
406
<th scope="row" valign="top"><label for="user_id"><?php _e( 'User ID', 'paid-memberships-pro' ); ?>:</label></th>
407
<td>
408
- <?php if ( in_array( "user_id", $read_only_fields ) && $order_id > 0 ) {
409
echo $order->user_id;
410
- } else { ?>
411
- <input id="user_id" name="user_id" type="text" size="50"
412
- value="<?php echo esc_attr( $order->user_id ); ?>"/>
413
<?php } ?>
414
</td>
415
</tr>
@@ -418,11 +432,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
418
<th scope="row" valign="top"><label for="membership_id"><?php _e( 'Membership Level ID', 'paid-memberships-pro' ); ?>
419
:</label></th>
420
<td>
421
- <?php if ( in_array( "membership_id", $read_only_fields ) && $order_id > 0 ) {
422
echo $order->membership_id;
423
- } else { ?>
424
- <input id="membership_id" name="membership_id" type="text" size="50"
425
- value="<?php echo esc_attr( $order->membership_id ); ?>"/>
426
<?php } ?>
427
</td>
428
</tr>
@@ -431,11 +447,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
431
<th scope="row" valign="top"><label for="billing_name"><?php _e( 'Billing Name', 'paid-memberships-pro' ); ?>:</label>
432
</th>
433
<td>
434
- <?php if ( in_array( "billing_name", $read_only_fields ) && $order_id > 0 ) {
435
echo $order->billing_name;
436
- } else { ?>
437
- <input id="billing_name" name="billing_name" type="text" size="50"
438
- value="<?php echo esc_attr( $order->billing->name ); ?>"/>
439
<?php } ?>
440
</td>
441
</tr>
@@ -443,55 +461,65 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
443
<th scope="row" valign="top"><label for="billing_street"><?php _e( 'Billing Street', 'paid-memberships-pro' ); ?>
444
:</label></th>
445
<td>
446
- <?php if ( in_array( "billing_street", $read_only_fields ) && $order_id > 0 ) {
447
echo $order->billing_street;
448
- } else { ?>
449
- <input id="billing_street" name="billing_street" type="text" size="50"
450
- value="<?php echo esc_attr( $order->billing->street ); ?>"/></td>
451
- <?php } ?>
452
</tr>
453
<tr>
454
<th scope="row" valign="top"><label for="billing_city"><?php _e( 'Billing City', 'paid-memberships-pro' ); ?>:</label>
455
</th>
456
<td>
457
- <?php if ( in_array( "billing_city", $read_only_fields ) && $order_id > 0 ) {
458
echo $order->billing_city;
459
- } else { ?>
460
- <input id="billing_city" name="billing_city" type="text" size="50"
461
- value="<?php echo esc_attr( $order->billing->city ); ?>"/></td>
462
- <?php } ?>
463
</tr>
464
<tr>
465
<th scope="row" valign="top"><label for="billing_state"><?php _e( 'Billing State', 'paid-memberships-pro' ); ?>
466
:</label></th>
467
<td>
468
- <?php if ( in_array( "billing_state", $read_only_fields ) && $order_id > 0 ) {
469
echo $order->billing_state;
470
- } else { ?>
471
- <input id="billing_state" name="billing_state" type="text" size="50"
472
- value="<?php echo esc_attr( $order->billing->state ); ?>"/></td>
473
- <?php } ?>
474
</tr>
475
<tr>
476
<th scope="row" valign="top"><label for="billing_zip"><?php _e( 'Billing Postal Code', 'paid-memberships-pro' ); ?>
477
:</label></th>
478
<td>
479
- <?php if ( in_array( "billing_zip", $read_only_fields ) && $order_id > 0 ) {
480
echo $order->billing_zip;
481
- } else { ?>
482
- <input id="billing_zip" name="billing_zip" type="text" size="50"
483
- value="<?php echo esc_attr( $order->billing->zip ); ?>"/></td>
484
- <?php } ?>
485
</tr>
486
<tr>
487
<th scope="row" valign="top"><label for="billing_country"><?php _e( 'Billing Country', 'paid-memberships-pro' ); ?>
488
:</label></th>
489
<td>
490
- <?php if ( in_array( "billing_country", $read_only_fields ) && $order_id > 0 ) {
491
echo $order->billing_country;
492
- } else { ?>
493
- <input id="billing_country" name="billing_country" type="text" size="50"
494
- value="<?php echo esc_attr( $order->billing->country ); ?>"/>
495
<?php } ?>
496
</td>
497
</tr>
@@ -499,11 +527,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
499
<th scope="row" valign="top"><label for="billing_phone"><?php _e( 'Billing Phone', 'paid-memberships-pro' ); ?>
500
:</label></th>
501
<td>
502
- <?php if ( in_array( "billing_phone", $read_only_fields ) && $order_id > 0 ) {
503
echo $order->billing_phone;
504
- } else { ?>
505
- <input id="billing_phone" name="billing_phone" type="text" size="50"
506
- value="<?php echo esc_attr( $order->billing->phone ); ?>"/>
507
<?php } ?>
508
</td>
509
</tr>
@@ -511,22 +541,26 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
511
<tr>
512
<th scope="row" valign="top"><label for="subtotal"><?php _e( 'Sub Total', 'paid-memberships-pro' ); ?>:</label></th>
513
<td>
514
- <?php if ( in_array( "subtotal", $read_only_fields ) && $order_id > 0 ) {
515
echo $order->subtotal;
516
- } else { ?>
517
- <input id="subtotal" name="subtotal" type="text" size="10"
518
- value="<?php echo esc_attr( $order->subtotal ); ?>"/>
519
<?php } ?>
520
</td>
521
</tr>
522
<tr>
523
<th scope="row" valign="top"><label for="tax"><?php _e( 'Tax', 'paid-memberships-pro' ); ?>:</label></th>
524
<td>
525
- <?php if ( in_array( "tax", $read_only_fields ) && $order_id > 0 ) {
526
echo $order->tax;
527
- } else { ?>
528
- <input id="tax" name="tax" type="text" size="10"
529
- value="<?php echo esc_attr( $order->tax ); ?>"/>
530
<?php } ?>
531
</td>
532
</tr>
@@ -534,22 +568,26 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
534
<th scope="row" valign="top"><label for="couponamount"><?php _e( 'Coupon Amount', 'paid-memberships-pro' ); ?>:</label>
535
</th>
536
<td>
537
- <?php if ( in_array( "couponamount", $read_only_fields ) && $order_id > 0 ) {
538
echo $order->couponamount;
539
- } else { ?>
540
- <input id="couponamount" name="couponamount" type="text" size="10"
541
- value="<?php echo esc_attr( $order->couponamount ); ?>"/>
542
<?php } ?>
543
</td>
544
</tr>
545
<tr>
546
<th scope="row" valign="top"><label for="total"><?php _e( 'Total', 'paid-memberships-pro' ); ?>:</label></th>
547
<td>
548
- <?php if ( in_array( "total", $read_only_fields ) && $order_id > 0 ) {
549
echo $order->total;
550
- } else { ?>
551
- <input id="total" name="total" type="text" size="10"
552
- value="<?php echo esc_attr( $order->total ); ?>"/>
553
<?php } ?>
554
<small
555
class="pmpro_lite"><?php _e( 'Should be subtotal + tax - couponamount.', 'paid-memberships-pro' ); ?></small>
@@ -560,11 +598,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
560
<th scope="row" valign="top"><label for="payment_type"><?php _e( 'Payment Type', 'paid-memberships-pro' ); ?>:</label>
561
</th>
562
<td>
563
- <?php if ( in_array( "payment_type", $read_only_fields ) && $order_id > 0 ) {
564
echo $order->payment_type;
565
- } else { ?>
566
- <input id="payment_type" name="payment_type" type="text" size="50"
567
- value="<?php echo esc_attr( $order->payment_type ); ?>"/>
568
<?php } ?>
569
<small
570
class="pmpro_lite"><?php _e( 'e.g. PayPal Express, PayPal Standard, Credit Card.', 'paid-memberships-pro' ); ?></small>
@@ -573,11 +613,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
573
<tr>
574
<th scope="row" valign="top"><label for="cardtype"><?php _e( 'Card Type', 'paid-memberships-pro' ); ?></label></th>
575
<td>
576
- <?php if ( in_array( "cardtype", $read_only_fields ) && $order_id > 0 ) {
577
echo $order->cardtype;
578
- } else { ?>
579
- <input id="cardtype" name="cardtype" type="text" size="50"
580
- value="<?php echo esc_attr( $order->cardtype ); ?>"/>
581
<?php } ?>
582
<small class="pmpro_lite"><?php _e( 'e.g. Visa, MasterCard, AMEX, etc', 'paid-memberships-pro' ); ?></small>
583
</td>
@@ -586,33 +628,37 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
586
<th scope="row" valign="top"><label for="accountnumber"><?php _e( 'Account Number', 'paid-memberships-pro' ); ?>
587
:</label></th>
588
<td>
589
- <?php if ( in_array( "accountnumber", $read_only_fields ) && $order_id > 0 ) {
590
echo $order->accountnumber;
591
- } else { ?>
592
- <input id="accountnumber" name="accountnumber" type="text" size="50"
593
- value="<?php echo esc_attr( $order->accountnumber ); ?>"/>
594
<?php } ?>
595
<small class="pmpro_lite"><?php _e( 'Obscure all but last 4 digits.', 'paid-memberships-pro' ); ?></small>
596
</td>
597
</tr>
598
- <?php if ( in_array( "ExpirationDate", $read_only_fields ) && $order_id > 0 ) {
599
echo $order->ExpirationDate;
600
- } else { ?>
601
- <tr>
602
- <th scope="row" valign="top"><label
603
for="expirationmonth"><?php _e( 'Expiration Month', 'paid-memberships-pro' ); ?>:</label></th>
604
<td>
605
<input id="expirationmonth" name="expirationmonth" type="text" size="10"
606
- value="<?php echo esc_attr( $order->expirationmonth ); ?>"/>
607
<small class="pmpro_lite">MM</small>
608
</td>
609
</tr>
610
<tr>
611
<th scope="row" valign="top"><label for="expirationyear"><?php _e( 'Expiration Year', 'paid-memberships-pro' ); ?>
612
- :</label></th>
613
<td>
614
<input id="expirationyear" name="expirationyear" type="text" size="10"
615
- value="<?php echo esc_attr( $order->expirationyear ); ?>"/>
616
<small class="pmpro_lite">YYYY</small>
617
</td>
618
</tr>
@@ -620,28 +666,30 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
620
<tr>
621
<th scope="row" valign="top"><label for="status"><?php _e( 'Status', 'paid-memberships-pro' ); ?>:</label></th>
622
<td>
623
- <?php if ( in_array( "status", $read_only_fields ) && $order_id > 0 ) {
624
echo $order->status;
625
- } else { ?>
626
- <?php
627
- $statuses = array();
628
- $default_statuses = array(
629
- "",
630
- "success",
631
- "cancelled",
632
- "review",
633
- "token",
634
- "refunded",
635
- "pending",
636
- "error",
637
- );
638
- $used_statuses = $wpdb->get_col( "SELECT DISTINCT(status) FROM $wpdb->pmpro_membership_orders" );
639
- $statuses = array_unique( array_merge( $default_statuses, $used_statuses ) );
640
- asort( $statuses );
641
- $statuses = apply_filters( "pmpro_order_statuses", $statuses );
642
?>
643
<select id="status" name="status">
644
- <?php foreach ( $statuses as $status ) { ?>
645
<option
646
value="<?php echo esc_attr( $status ); ?>" <?php selected( $order->status, $status ); ?>><?php echo $status; ?></option>
647
<?php } ?>
@@ -653,35 +701,45 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
653
<tr>
654
<th scope="row" valign="top"><label for="gateway"><?php _e( 'Gateway', 'paid-memberships-pro' ); ?>:</label></th>
655
<td>
656
- <?php if ( in_array( "gateway", $read_only_fields ) && $order_id > 0 ) {
657
echo $order->gateway;
658
- } else { ?>
659
- <select id="gateway" name="gateway" onchange="pmpro_changeGateway(jQuery(this).val());">
660
- <?php
661
- $pmpro_gateways = pmpro_gateways();
662
- foreach ( $pmpro_gateways as $pmpro_gateway_name => $pmpro_gateway_label ) {
663
- ?>
664
- <option
665
- value="<?php echo esc_attr( $pmpro_gateway_name ); ?>" <?php selected( $order->gateway, $pmpro_gateway_name ); ?>><?php echo $pmpro_gateway_label; ?></option>
666
<?php
667
- }
668
- ?>
669
- </select>
670
- <?php } ?>
671
</td>
672
</tr>
673
<tr>
674
<th scope="row" valign="top"><label
675
for="gateway_environment"><?php _e( 'Gateway Environment', 'paid-memberships-pro' ); ?>:</label></th>
676
<td>
677
- <?php if ( in_array( "gateway_environment", $read_only_fields ) && $order_id > 0 ) {
678
echo $order->gateway_environment;
679
- } else { ?>
680
- <select name="gateway_environment">
681
- <option value="sandbox"
682
- <?php if ( $order->gateway_environment == "sandbox" ) { ?>selected="selected"<?php } ?>><?php _e( 'Sandbox/Testing', 'paid-memberships-pro' ); ?></option>
683
<option value="live"
684
- <?php if ( $order->gateway_environment == "live" ) { ?>selected="selected"<?php } ?>><?php _e( 'Live/Production', 'paid-memberships-pro' ); ?></option>
685
</select>
686
<?php } ?>
687
</td>
@@ -691,11 +749,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
691
<th scope="row" valign="top"><label
692
for="payment_transaction_id"><?php _e( 'Payment Transaction ID', 'paid-memberships-pro' ); ?>:</label></th>
693
<td>
694
- <?php if ( in_array( "payment_transaction_id", $read_only_fields ) && $order_id > 0 ) {
695
echo $order->payment_transaction_id;
696
- } else { ?>
697
- <input id="payment_transaction_id" name="payment_transaction_id" type="text" size="50"
698
- value="<?php echo esc_attr( $order->payment_transaction_id ); ?>"/>
699
<?php } ?>
700
<small
701
class="pmpro_lite"><?php _e( 'Generated by the gateway. Useful to cross reference orders.', 'paid-memberships-pro' ); ?></small>
@@ -706,11 +766,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
706
for="subscription_transaction_id"><?php _e( 'Subscription Transaction ID', 'paid-memberships-pro' ); ?>
707
:</label></th>
708
<td>
709
- <?php if ( in_array( "subscription_transaction_id", $read_only_fields ) && $order_id > 0 ) {
710
echo $order->subscription_transaction_id;
711
- } else { ?>
712
- <input id="subscription_transaction_id" name="subscription_transaction_id" type="text" size="50"
713
- value="<?php echo esc_attr( $order->subscription_transaction_id ); ?>"/>
714
<?php } ?>
715
<small
716
class="pmpro_lite"><?php _e( 'Generated by the gateway. Useful to cross reference subscriptions.', 'paid-memberships-pro' ); ?></small>
@@ -720,26 +782,31 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
720
<tr>
721
<th scope="row" valign="top"><label for="ts_month"><?php _e( 'Date', 'paid-memberships-pro' ); ?>:</label></th>
722
<td>
723
- <?php if ( in_array( "timestamp", $read_only_fields ) && $order_id > 0 ) {
724
- echo date_i18n( get_option( 'date_format' ) . " " . get_option( 'time_format' ), $order->timestamp );
725
- } else { ?>
726
- <?php
727
- //set up date vars
728
- if ( ! empty( $order->timestamp ) ) {
729
- $timestamp = $order->timestamp;
730
- } else {
731
- $timestamp = current_time( 'timestamp' );
732
- }
733
- $year = date_i18n( "Y", $timestamp );
734
- $month = date_i18n( "n", $timestamp );
735
- $day = date_i18n( "j", $timestamp );
736
- ?>
737
- <select id="ts_month" name="ts_month">
738
<?php
739
for ( $i = 1; $i < 13; $i ++ ) {
740
?>
741
- <option value="<?php echo $i ?>"
742
- <?php if ( $i == $month ) { ?>selected="selected"<?php } ?>><?php echo date_i18n( "M", strtotime( $i . "/1/" . $year, current_time( "timestamp" ) ) ) ?></option>
743
<?php
744
}
745
?>
@@ -751,18 +818,20 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
751
</tr>
752
753
<?php
754
- $affiliates = apply_filters( "pmpro_orders_show_affiliate_ids", false );
755
if ( ! empty( $affiliates ) ) {
756
?>
757
<tr>
758
<th scope="row" valign="top"><label for="affiliate_id"><?php _e( 'Affiliate ID', 'paid-memberships-pro' ); ?>
759
:</label></th>
760
<td>
761
- <?php if ( in_array( "affiliate_id", $read_only_fields ) && $order_id > 0 ) {
762
echo $order->affiliate_id;
763
- } else { ?>
764
- <input id="affiliate_id" name="affiliate_id" type="text" size="50"
765
- value="<?php echo esc_attr( $order->affiliate_id ); ?>"/>
766
<?php } ?>
767
</td>
768
</tr>
@@ -770,11 +839,13 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
770
<th scope="row" valign="top"><label for="affiliate_subid"><?php _e( 'Affiliate SubID', 'paid-memberships-pro' ); ?>
771
:</label></th>
772
<td>
773
- <?php if ( in_array( "affiliate_subid", $read_only_fields ) && $order_id > 0 ) {
774
echo $order->affiliate_subid;
775
- } else { ?>
776
- <input id="affiliate_subid" name="affiliate_subid" type="text" size="50"
777
- value="<?php echo esc_attr( $order->affiliate_subid ); ?>"/>
778
<?php } ?>
779
</td>
780
</tr>
@@ -783,29 +854,35 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
783
<tr>
784
<th scope="row" valign="top"><label for="notes"><?php _e( 'Notes', 'paid-memberships-pro' ); ?>:</label></th>
785
<td>
786
- <?php if ( in_array( "notes", $read_only_fields ) && $order_id > 0 ) {
787
echo $order->notes;
788
- } else { ?>
789
- <textarea id="notes" name="notes" rows="5"
790
- cols="80"><?php echo esc_textarea( $order->notes ); ?></textarea>
791
<?php } ?>
792
</td>
793
</tr>
794
795
- <?php do_action( "pmpro_after_order_settings", $order ); ?>
796
797
</tbody>
798
</table>
799
800
<p class="submit topborder">
801
- <input name="order" type="hidden" value="<?php if ( ! empty( $order->id ) ) {
802
echo $order->id;
803
} else {
804
echo $order_id;
805
- } ?>"/>
806
<input name="save" type="submit" class="button-primary" value="<?php _e( 'Save Order', 'paid-memberships-pro' ); ?>"/>
807
<input name="cancel" type="button" class="cancel button-secondary" value="<?php _e( 'Cancel', 'paid-memberships-pro' ); ?>"
808
- onclick="location.href='<?php echo get_admin_url( null, '/admin.php?page=pmpro-orders' ) ?>';"/>
809
</p>
810
811
</form>
@@ -854,20 +931,20 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
854
class="add-new-h2">+ <?php _e( 'Add New Order', 'paid-memberships-pro' ); ?></a>
855
856
<?php
857
- //build the export URL
858
$export_url = admin_url( 'admin-ajax.php?action=orders_csv' );
859
$url_params = array(
860
- "filter" => $filter,
861
- "s" => $s,
862
- "l" => $l,
863
- "start-month" => $start_month,
864
- "start-day" => $start_day,
865
- "start-year" => $start_year,
866
- "end-month" => $end_month,
867
- "end-day" => $end_day,
868
- "end-year" => $end_year,
869
- "predefined-date" => $predefined_date,
870
- "status" => $status
871
);
872
$export_url = add_query_arg( $url_params, $export_url );
873
?>
@@ -877,50 +954,54 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
877
878
879
<?php if ( ! empty( $pmpro_msg ) ) { ?>
880
- <div id="message" class="<?php if ( $pmpro_msgt == "success" ) {
881
- echo "updated fade";
882
} else {
883
- echo "error";
884
- } ?>"><p><?php echo $pmpro_msg ?></p></div>
885
<?php } ?>
886
887
888
<ul class="subsubsub">
889
<li>
890
- <?php _e( 'Show', 'paid-memberships-pro' ) ?>
891
<select id="filter" name="filter">
892
- <option value="all" <?php selected( $filter, "all" ); ?>><?php _e( 'All', 'paid-memberships-pro' ); ?></option>
893
<option
894
- value="within-a-date-range" <?php selected( $filter, "within-a-date-range" ); ?>><?php _e( 'Within a Date Range', 'paid-memberships-pro' ); ?></option>
895
<option
896
- value="predefined-date-range" <?php selected( $filter, "predefined-date-range" ); ?>><?php _e( 'Predefined Date Range', 'paid-memberships-pro' ); ?></option>
897
<option
898
- value="within-a-level" <?php selected( $filter, "within-a-level" ); ?>><?php _e( 'Within a Level', 'paid-memberships-pro' ); ?></option>
899
<option
900
- value="within-a-status" <?php selected( $filter, "within-a-status" ); ?>><?php _e( 'Within a Status', 'paid-memberships-pro' ); ?></option>
901
</select>
902
903
- <span id="from"><?php _e( 'From', 'paid-memberships-pro' ) ?></span>
904
905
<select id="start-month" name="start-month">
906
<?php for ( $i = 1; $i < 13; $i ++ ) { ?>
907
<option
908
- value="<?php echo $i; ?>" <?php selected( $start_month, $i ); ?>><?php echo date_i18n( "F", mktime( 0, 0, 0, $i, 2 ) ); ?></option>
909
<?php } ?>
910
</select>
911
912
<input id='start-day' name="start-day" type="text" size="2"
913
- value="<?php echo esc_attr( $start_day ); ?>"/>
914
<input id='start-year' name="start-year" type="text" size="4"
915
- value="<?php echo esc_attr( $start_year ); ?>"/>
916
917
918
- <span id="to"><?php _e( 'To', 'paid-memberships-pro' ) ?></span>
919
920
<select id="end-month" name="end-month">
921
<?php for ( $i = 1; $i < 13; $i ++ ) { ?>
922
<option
923
- value="<?php echo $i; ?>" <?php selected( $end_month, $i ); ?>><?php echo date_i18n( "F", mktime( 0, 0, 0, $i, 2 ) ); ?></option>
924
<?php } ?>
925
</select>
926
@@ -928,23 +1009,23 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
928
<input id='end-day' name="end-day" type="text" size="2" value="<?php echo esc_attr( $end_day ); ?>"/>
929
<input id='end-year' name="end-year" type="text" size="4" value="<?php echo esc_attr( $end_year ); ?>"/>
930
931
- <span id="filterby"><?php _e( 'filter by ', 'paid-memberships-pro' ) ?></span>
932
933
<select id="predefined-date" name="predefined-date">
934
935
<option
936
- value="<?php echo "This Month"; ?>" <?php selected( $predefined_date, "This Month" ); ?>><?php echo "This Month"; ?></option>
937
<option
938
- value="<?php echo "Last Month"; ?>" <?php selected( $predefined_date, "Last Month" ); ?>><?php echo "Last Month"; ?></option>
939
<option
940
- value="<?php echo "This Year"; ?>" <?php selected( $predefined_date, "This Year" ); ?>><?php echo "This Year"; ?></option>
941
<option
942
- value="<?php echo "Last Year"; ?>" <?php selected( $predefined_date, "Last Year" ); ?>><?php echo "Last Year"; ?></option>
943
944
</select>
945
946
<?php
947
- //Note: only orders belonging to current levels can be filtered. There is no option for orders belonging to deleted levels
948
$levels = pmpro_getAllLevels( true, true );
949
?>
950
<select id="l" name="l">
@@ -955,7 +1036,7 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
955
956
</select>
957
958
- <?php
959
$statuses = pmpro_getOrderStatuses();
960
?>
961
<select id="status" name="status">
@@ -1070,67 +1151,67 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1070
</p>
1071
1072
<?php
1073
- //string search
1074
if ( $s ) {
1075
$sqlQuery = "SELECT SQL_CALC_FOUND_ROWS o.id FROM $wpdb->pmpro_membership_orders o LEFT JOIN $wpdb->users u ON o.user_id = u.ID LEFT JOIN $wpdb->pmpro_membership_levels l ON o.membership_id = l.id ";
1076
1077
- $join_with_usermeta = apply_filters( "pmpro_orders_search_usermeta", false );
1078
if ( $join_with_usermeta ) {
1079
$sqlQuery .= "LEFT JOIN $wpdb->usermeta um ON o.user_id = um.user_id ";
1080
}
1081
1082
- $sqlQuery .= "WHERE (1=2 ";
1083
1084
$fields = array(
1085
- "o.id",
1086
- "o.code",
1087
- "o.billing_name",
1088
- "o.billing_street",
1089
- "o.billing_city",
1090
- "o.billing_state",
1091
- "o.billing_zip",
1092
- "o.billing_phone",
1093
- "o.payment_type",
1094
- "o.cardtype",
1095
- "o.accountnumber",
1096
- "o.status",
1097
- "o.gateway",
1098
- "o.gateway_environment",
1099
- "o.payment_transaction_id",
1100
- "o.subscription_transaction_id",
1101
- "u.user_login",
1102
- "u.user_email",
1103
- "u.display_name",
1104
- "l.name"
1105
);
1106
1107
if ( $join_with_usermeta ) {
1108
- $fields[] = "um.meta_value";
1109
}
1110
1111
- $fields = apply_filters( "pmpro_orders_search_fields", $fields );
1112
1113
foreach ( $fields as $field ) {
1114
- $sqlQuery .= " OR " . $field . " LIKE '%" . esc_sql( $s ) . "%' ";
1115
}
1116
- $sqlQuery .= ") ";
1117
1118
- $sqlQuery .= "AND " . $condition . " ";
1119
1120
- $sqlQuery .= "GROUP BY o.id ORDER BY o.id DESC, o.timestamp DESC ";
1121
} else {
1122
- $sqlQuery = "SELECT SQL_CALC_FOUND_ROWS id FROM $wpdb->pmpro_membership_orders WHERE " . $condition . " ORDER BY id DESC, timestamp DESC ";
1123
}
1124
1125
$sqlQuery .= "LIMIT $start, $limit";
1126
1127
$order_ids = $wpdb->get_col( $sqlQuery );
1128
1129
- $totalrows = $wpdb->get_var( "SELECT FOUND_ROWS() as found_rows" );
1130
1131
if ( $order_ids ) {
1132
?>
1133
- <p class="clear"><?php printf( __( "%d orders found.", 'paid-memberships-pro' ), $totalrows ); ?></span></p>
1134
<?php
1135
}
1136
?>
@@ -1140,7 +1221,7 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1140
<th><?php _e( 'ID', 'paid-memberships-pro' ); ?></th>
1141
<th><?php _e( 'Code', 'paid-memberships-pro' ); ?></th>
1142
<th><?php _e( 'User', 'paid-memberships-pro' ); ?></th>
1143
- <?php do_action( "pmpro_orders_extra_cols_header", $order_ids ); ?>
1144
<th><?php _e( 'Membership Level', 'paid-memberships-pro' ); ?></th>
1145
<th><?php _e( 'Total', 'paid-memberships-pro' ); ?></th>
1146
<th><?php _e( 'Payment', 'paid-memberships-pro' ); ?></th>
@@ -1163,19 +1244,25 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1163
$order->nogateway = true;
1164
$order->getMemberOrderByID( $order_id );
1165
?>
1166
- <tr <?php if ( $count ++ % 2 == 0 ) { ?>class="alternate"<?php } ?>>
1167
<td>
1168
- <a href="admin.php?page=pmpro-orders&order=<?php echo $order->id ?>"><?php echo $order->id; ?></a>
1169
</td>
1170
<td>
1171
- <a href="admin.php?page=pmpro-orders&order=<?php echo $order->id ?>"><?php echo $order->code; ?></a>
1172
</td>
1173
<td class="username column-username">
1174
<?php $order->getUser(); ?>
1175
<?php if ( ! empty( $order->user ) ) { ?>
1176
- <a href="user-edit.php?user_id=<?php echo $order->user->ID ?>"><?php echo $order->user->user_login ?></a>
1177
- <?php } else { ?>
1178
[<?php _e( 'deleted', 'paid-memberships-pro' ); ?>]
1179
<?php } ?>
1180
<br/>
1181
<?php
@@ -1195,13 +1282,15 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1195
}
1196
?>
1197
</td>
1198
- <?php do_action( "pmpro_orders_extra_cols_body", $order ); ?>
1199
<td><?php echo $order->membership_id; ?></td>
1200
<td><?php echo pmpro_formatPrice( $order->total ); ?></td>
1201
<td>
1202
- <?php if ( ! empty( $order->payment_type ) ) {
1203
- echo $order->payment_type . "<br />";
1204
- } ?>
1205
<?php if ( ! empty( $order->accountnumber ) ) { ?>
1206
<?php echo $order->cardtype; ?>: x<?php echo last4( $order->accountnumber ); ?><br/>
1207
<?php } ?>
@@ -1211,30 +1300,46 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1211
<?php if ( ! empty( $order->billing->street ) ) { ?>
1212
<?php echo $order->billing->street; ?><br/>
1213
<?php if ( $order->billing->city && $order->billing->state ) { ?>
1214
- <?php echo $order->billing->city ?>, <?php echo $order->billing->state ?><?php echo $order->billing->zip ?><?php if ( ! empty( $order->billing->country ) )
1215
- echo $order->billing->country ?><br/>
1216
<?php } ?>
1217
<?php } ?>
1218
- <?php if ( ! empty( $order->billing->phone ) ) {
1219
echo formatPhone( $order->billing->phone );
1220
- } ?>
1221
</td>
1222
- <td><?php echo $order->gateway; ?><?php if ( $order->gateway_environment == "test" ) {
1223
- echo "(test)";
1224
- } ?></td>
1225
<td>
1226
- <?php _e( 'Payment', 'paid-memberships-pro' ); ?>: <?php if ( ! empty( $order->payment_transaction_id ) ) {
1227
- echo $order->payment_transaction_id;
1228
- } else {
1229
- echo "N/A";
1230
- } ?>
1231
<br/>
1232
<?php _e( 'Subscription', 'paid-memberships-pro' ); ?>
1233
- : <?php if ( ! empty( $order->subscription_transaction_id ) ) {
1234
echo $order->subscription_transaction_id;
1235
} else {
1236
- echo "N/A";
1237
- } ?>
1238
</td>
1239
<td><?php echo $order->status; ?></td>
1240
<td>
@@ -1248,7 +1353,7 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1248
<a href="admin.php?page=pmpro-orders&order=-1&copy=<?php echo $order->id; ?>"><?php _e( 'copy', 'paid-memberships-pro' ); ?></a>
1249
</td>
1250
<td align="center">
1251
- <a href="javascript:askfirst('<?php echo str_replace( "'", "\'", sprintf( __( "Deleting orders is permanent and can affect active users. Are you sure you want to delete order %s?", 'paid-memberships-pro' ), str_replace( "'", "", $order->code ) ) ); ?>', 'admin.php?page=pmpro-orders&delete=<?php echo $order->id; ?>'); void(0);"><?php _e( 'delete', 'paid-memberships-pro' ); ?></a>
1252
</td>
1253
<td align="center">
1254
<a href="admin-ajax.php?action=pmpro_orders_print_view&order=<?php echo $order->id; ?>"
@@ -1274,12 +1379,11 @@ require_once( dirname( __FILE__ ) . "/admin_header.php" );
1274
</table>
1275
</form>
1276
<?php
1277
- //add normal args
1278
- $pagination_url = add_query_arg( $url_params, get_admin_url( null, "/admin.php?page=pmpro-orders" ) );
1279
echo pmpro_getPaginationString( $pn, $totalrows, $limit, 1, $pagination_url, "&limit=$limit&pn=" );
1280
?>
1281
1282
<?php } ?>
1283
<?php
1284
- require_once( dirname( __FILE__ ) . "/admin_footer.php" );
1285
- ?>
1
<?php
2
+ // only admins can get this
3
+ if ( ! function_exists( 'current_user_can' ) || ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'pmpro_orders' ) ) ) {
4
+ die( __( 'You do not have permissions to perform this action.', 'paid-memberships-pro' ) );
5
}
6
7
+ // vars
8
global $wpdb;
9
if ( isset( $_REQUEST['s'] ) ) {
10
$s = sanitize_text_field( trim( $_REQUEST['s'] ) );
11
} else {
12
+ $s = '';
13
}
14
15
if ( isset( $_REQUEST['l'] ) ) {
21
if ( isset( $_REQUEST['start-month'] ) ) {
22
$start_month = intval( $_REQUEST['start-month'] );
23
} else {
24
+ $start_month = '1';
25
}
26
27
if ( isset( $_REQUEST['start-day'] ) ) {
28
$start_day = intval( $_REQUEST['start-day'] );
29
} else {
30
+ $start_day = '1';
31
}
32
33
if ( isset( $_REQUEST['start-year'] ) ) {
34
$start_year = intval( $_REQUEST['start-year'] );
35
} else {
36
+ $start_year = date_i18n( 'Y' );
37
}
38
39
if ( isset( $_REQUEST['end-month'] ) ) {
40
$end_month = intval( $_REQUEST['end-month'] );
41
} else {
42
+ $end_month = date_i18n( 'n' );
43
}
44
45
if ( isset( $_REQUEST['end-day'] ) ) {
46
$end_day = intval( $_REQUEST['end-day'] );
47
} else {
48
+ $end_day = date_i18n( 'j' );
49
}
50
51
if ( isset( $_REQUEST['end-year'] ) ) {
52
$end_year = intval( $_REQUEST['end-year'] );
53
} else {
54
+ $end_year = date_i18n( 'Y' );
55
}
56
57
if ( isset( $_REQUEST['predefined-date'] ) ) {
58
$predefined_date = sanitize_text_field( $_REQUEST['predefined-date'] );
59
} else {
60
+ $predefined_date = 'This Month';
61
}
62
63
if ( isset( $_REQUEST['status'] ) ) {
64
$status = sanitize_text_field( $_REQUEST['status'] );
65
} else {
66
+ $status = '';
67
}
68
69
if ( isset( $_REQUEST['filter'] ) ) {
70
$filter = sanitize_text_field( $_REQUEST['filter'] );
71
} else {
72
+ $filter = 'all';
73
}
74
75
+ // some vars for the search
76
if ( isset( $_REQUEST['pn'] ) ) {
77
$pn = intval( $_REQUEST['pn'] );
78
} else {
96
$end = $pn * $limit;
97
$start = $end - $limit;
98
99
+ // filters
100
+ if ( empty( $filter ) || $filter === 'all' ) {
101
+ $condition = '1=1';
102
+ $filter = 'all';
103
+ } elseif ( $filter == 'within-a-date-range' ) {
104
+ $start_date = $start_year . '-' . $start_month . '-' . $start_day;
105
+ $end_date = $end_year . '-' . $end_month . '-' . $end_day;
106
107
+ // add times to dates
108
+ $start_date = $start_date . ' 00:00:00';
109
+ $end_date = $end_date . ' 23:59:59';
110
111
$condition = "timestamp BETWEEN '" . esc_sql( $start_date ) . "' AND '" . esc_sql( $end_date ) . "'";
112
+ } elseif ( $filter == 'predefined-date-range' ) {
113
+ if ( $predefined_date == 'Last Month' ) {
114
+ $start_date = date_i18n( 'Y-m-d', strtotime( 'first day of last month', current_time( 'timestamp' ) ) );
115
+ $end_date = date_i18n( 'Y-m-d', strtotime( 'last day of last month', current_time( 'timestamp' ) ) );
116
+ } elseif ( $predefined_date == 'This Month' ) {
117
+ $start_date = date_i18n( 'Y-m-d', strtotime( 'first day of this month', current_time( 'timestamp' ) ) );
118
+ $end_date = date_i18n( 'Y-m-d', strtotime( 'last day of this month', current_time( 'timestamp' ) ) );
119
+ } elseif ( $predefined_date == 'This Year' ) {
120
$year = date_i18n( 'Y' );
121
+ $start_date = date_i18n( 'Y-m-d', strtotime( "first day of January $year", current_time( 'timestamp' ) ) );
122
+ $end_date = date_i18n( 'Y-m-d', strtotime( "last day of December $year", current_time( 'timestamp' ) ) );
123
+ } elseif ( $predefined_date == 'Last Year' ) {
124
$year = date_i18n( 'Y' ) - 1;
125
+ $start_date = date_i18n( 'Y-m-d', strtotime( "first day of January $year", current_time( 'timestamp' ) ) );
126
+ $end_date = date_i18n( 'Y-m-d', strtotime( "last day of December $year", current_time( 'timestamp' ) ) );
127
}
128
129
+ // add times to dates
130
+ $start_date = $start_date . ' 00:00:00';
131
+ $end_date = $end_date . ' 23:59:59';
132
133
$condition = "timestamp BETWEEN '" . esc_sql( $start_date ) . "' AND '" . esc_sql( $end_date ) . "'";
134
+ } elseif ( $filter == 'within-a-level' ) {
135
+ $condition = 'membership_id = ' . esc_sql( $l );
136
+ } elseif ( $filter == 'within-a-status' ) {
137
$condition = "status = '" . esc_sql( $status ) . "' ";
138
}
139
140
+ // emailing?
141
if ( ! empty( $_REQUEST['email'] ) && ! empty( $_REQUEST['order'] ) ) {
142
$email = new PMProEmail();
143
+ $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
144
$order = new MemberOrder( $_REQUEST['order'] );
145
if ( $email->sendBillableInvoiceEmail( $user, $order ) ) {
146
+ $pmpro_msg = __( 'Invoice emailed successfully.', 'paid-memberships-pro' );
147
+ $pmpro_msgt = 'success';
148
} else {
149
+ $pmpro_msg = __( 'Error emailing invoice.', 'paid-memberships-pro' );
150
+ $pmpro_msgt = 'error';
151
}
152
153
+ // clean up so we stay on the orders list view
154
unset( $_REQUEST['order'] );
155
$order = null;
156
}
157
158
+ // deleting?
159
if ( ! empty( $_REQUEST['delete'] ) ) {
160
$dorder = new MemberOrder( intval( $_REQUEST['delete'] ) );
161
if ( $dorder->deleteMe() ) {
162
+ $pmpro_msg = __( 'Order deleted successfully.', 'paid-memberships-pro' );
163
+ $pmpro_msgt = 'success';
164
} else {
165
+ $pmpro_msg = __( 'Error deleting order.', 'paid-memberships-pro' );
166
+ $pmpro_msgt = 'error';
167
}
168
}
169
170
+ $thisyear = date_i18n( 'Y' );
171
172
+ // this array stores fields that should be read only
173
+ $read_only_fields = apply_filters(
174
+ 'pmpro_orders_read_only_fields', array(
175
+ 'code',
176
+ 'payment_transaction_id',
177
+ 'subscription_transaction_id',
178
+ )
179
+ );
180
181
+ // if this is a new order or copy of one, let's make all fields editable
182
+ if ( ! empty( $_REQUEST['order'] ) && $_REQUEST['order'] < 0 ) {
183
$read_only_fields = array();
184
}
185
186
+ // saving?
187
if ( ! empty( $_REQUEST['save'] ) ) {
188
+ // start with old order if applicable
189
$order_id = intval( $_REQUEST['order'] );
190
if ( $order_id > 0 ) {
191
$order = new MemberOrder( $order_id );
194
$order->billing = new stdClass();
195
}
196
197
+ // update values
198
+ if ( ! in_array( 'code', $read_only_fields ) && isset( $_POST['code'] ) ) {
199
$order->code = sanitize_text_field( $_POST['code'] );
200
}
201
+ if ( ! in_array( 'user_id', $read_only_fields ) && isset( $_POST['user_id'] ) ) {
202
$order->user_id = intval( $_POST['user_id'] );
203
}
204
+ if ( ! in_array( 'membership_id', $read_only_fields ) && isset( $_POST['membership_id'] ) ) {
205
$order->membership_id = intval( $_POST['membership_id'] );
206
}
207
+ if ( ! in_array( 'billing_name', $read_only_fields ) && isset( $_POST['billing_name'] ) ) {
208
+ $order->billing->name = sanitize_text_field( wp_unslash( $_POST['billing_name'] ) );
209
}
210
+ if ( ! in_array( 'billing_street', $read_only_fields ) && isset( $_POST['billing_street'] ) ) {
211
+ $order->billing->street = sanitize_text_field( wp_unslash( $_POST['billing_street'] ) );
212
}
213
+ if ( ! in_array( 'billing_city', $read_only_fields ) && isset( $_POST['billing_city'] ) ) {
214
+ $order->billing->city = sanitize_text_field( wp_unslash( $_POST['billing_city'] ) );
215
}
216
+ if ( ! in_array( 'billing_state', $read_only_fields ) && isset( $_POST['billing_state'] ) ) {
217
+ $order->billing->state = sanitize_text_field( wp_unslash( $_POST['billing_state'] ) );
218
}
219
+ if ( ! in_array( 'billing_zip', $read_only_fields ) && isset( $_POST['billing_zip'] ) ) {
220
$order->billing->zip = sanitize_text_field( $_POST['billing_zip'] );
221
}
222
+ if ( ! in_array( 'billing_country', $read_only_fields ) && isset( $_POST['billing_country'] ) ) {
223
+ $order->billing->country = sanitize_text_field( wp_unslash( $_POST['billing_country'] ) );
224
}
225
+ if ( ! in_array( 'billing_phone', $read_only_fields ) && isset( $_POST['billing_phone'] ) ) {
226
$order->billing->phone = sanitize_text_field( $_POST['billing_phone'] );
227
}
228
+ if ( ! in_array( 'subtotal', $read_only_fields ) && isset( $_POST['subtotal'] ) ) {
229
$order->subtotal = sanitize_text_field( $_POST['subtotal'] );
230
}
231
+ if ( ! in_array( 'tax', $read_only_fields ) && isset( $_POST['tax'] ) ) {
232
$order->tax = sanitize_text_field( $_POST['tax'] );
233
}
234
+ if ( ! in_array( 'couponamount', $read_only_fields ) && isset( $_POST['couponamount'] ) ) {
235
$order->couponamount = sanitize_text_field( $_POST['couponamount'] );
236
}
237
+ if ( ! in_array( 'total', $read_only_fields ) && isset( $_POST['total'] ) ) {
238
$order->total = sanitize_text_field( $_POST['total'] );
239
}
240
+ if ( ! in_array( 'payment_type', $read_only_fields ) && isset( $_POST['payment_type'] ) ) {
241
$order->payment_type = sanitize_text_field( $_POST['payment_type'] );
242
}
243
+ if ( ! in_array( 'cardtype', $read_only_fields ) && isset( $_POST['cardtype'] ) ) {
244
$order->cardtype = sanitize_text_field( $_POST['cardtype'] );
245
}
246
+ if ( ! in_array( 'accountnumber', $read_only_fields ) && isset( $_POST['accountnumber'] ) ) {
247
$order->accountnumber = sanitize_text_field( $_POST['accountnumber'] );
248
}
249
+ if ( ! in_array( 'expirationmonth', $read_only_fields ) && isset( $_POST['expirationmonth'] ) ) {
250
$order->expirationmonth = sanitize_text_field( $_POST['expirationmonth'] );
251
}
252
+ if ( ! in_array( 'expirationyear', $read_only_fields ) && isset( $_POST['expirationyear'] ) ) {
253
$order->expirationyear = sanitize_text_field( $_POST['expirationyear'] );
254
}
255
+
256
+ if ( ! in_array( 'status', $read_only_fields ) && isset( $_POST['status'] ) ) {
257
$order->status = pmpro_sanitize_with_safelist( $_POST['status'], pmpro_getOrderStatuses() );
258
}
259
+ if ( ! in_array( 'gateway', $read_only_fields ) && isset( $_POST['gateway'] ) ) {
260
$order->gateway = sanitize_text_field( $_POST['gateway'] );
261
}
262
+ if ( ! in_array( 'gateway_environment', $read_only_fields ) && isset( $_POST['gateway_environment'] ) ) {
263
$order->gateway_environment = sanitize_text_field( $_POST['gateway_environment'] );
264
}
265
+ if ( ! in_array( 'payment_transaction_id', $read_only_fields ) && isset( $_POST['payment_transaction_id'] ) ) {
266
$order->payment_transaction_id = sanitize_text_field( $_POST['payment_transaction_id'] );
267
}
268
+ if ( ! in_array( 'subscription_transaction_id', $read_only_fields ) && isset( $_POST['subscription_transaction_id'] ) ) {
269
$order->subscription_transaction_id = sanitize_text_field( $_POST['subscription_transaction_id'] );
270
}
271
+ if ( ! in_array( 'notes', $read_only_fields ) && isset( $_POST['notes'] ) ) {
272
global $allowedposttags;
273
+ $order->notes = wp_kses( wp_unslash( $_REQUEST['notes'] ), $allowedposttags );
274
}
275
276
+ // affiliate stuff
277
+ $affiliates = apply_filters( 'pmpro_orders_show_affiliate_ids', false );
278
if ( ! empty( $affiliates ) ) {
279
+ if ( ! in_array( 'affiliate_id', $read_only_fields ) ) {
280
$order->affiliate_id = sanitize_text_field( $_POST['affiliate_id'] );
281
}
282
+ if ( ! in_array( 'affiliate_subid', $read_only_fields ) ) {
283
$order->affiliate_subid = sanitize_text_field( $_POST['affiliate_subid'] );
284
}
285
}
286
287
+ // check nonce for saving
288
$nonceokay = true;
289
+ if ( empty( $_REQUEST['pmpro_orders_nonce'] ) || ! check_admin_referer( 'save', 'pmpro_orders_nonce' ) ) {
290
$nonceokay = false;
291
}
292
+
293
+ // save
294
+ if ( $order->saveOrder() !== false && $nonceokay ) {
295
+ // handle timestamp
296
+ if ( $order->updateTimestamp( intval( $_POST['ts_year'] ), intval( $_POST['ts_month'] ), intval( $_POST['ts_day'] ) ) !== false ) {
297
+ $pmpro_msg = __( 'Order saved successfully.', 'paid-memberships-pro' );
298
+ $pmpro_msgt = 'success';
299
} else {
300
+ $pmpro_msg = __( 'Error updating order timestamp.', 'paid-memberships-pro' );
301
+ $pmpro_msgt = 'error';
302
}
303
} else {
304
+ $pmpro_msg = __( 'Error saving order.', 'paid-memberships-pro' );
305
+ $pmpro_msgt = 'error';
306
}
307
} else {
308
+ // order passed?
309
if ( ! empty( $_REQUEST['order'] ) ) {
310
$order_id = intval( $_REQUEST['order'] );
311
if ( $order_id > 0 ) {
313
} elseif ( ! empty( $_REQUEST['copy'] ) ) {
314
$order = new MemberOrder( intval( $_REQUEST['copy'] ) );
315
316
+ // new id
317
$order->id = null;
318
319
+ // new code
320
$order->code = $order->getRandomCode();
321
} else {
322
+ $order = new MemberOrder(); // new order
323
324
+ // defaults
325
$order->code = $order->getRandomCode();
326
+ $order->user_id = '';
327
+ $order->membership_id = '';
328
$order->billing = new stdClass();
329
+ $order->billing->name = '';
330
+ $order->billing->street = '';
331
+ $order->billing->city = '';
332
+ $order->billing->state = '';
333
+ $order->billing->zip = '';
334
+ $order->billing->country = '';
335
+ $order->billing->phone = '';
336
+ $order->subtotal = '';
337
+ $order->tax = '';
338
+ $order->couponamount = '';
339
+ $order->total = '';
340
+ $order->payment_type = '';
341
+ $order->cardtype = '';
342
+ $order->accountnumber = '';
343
+ $order->expirationmonth = '';
344
+ $order->expirationyear = '';
345
+ $order->status = 'success';
346
+ $order->gateway = pmpro_getOption( 'gateway' );
347
+ $order->gateway_environment = pmpro_getOption( 'gateway_environment' );
348
+ $order->payment_transaction_id = '';
349
+ $order->subscription_transaction_id = '';
350
+ $order->affiliate_id = '';
351
+ $order->affiliate_subid = '';
352
+ $order->notes = '';
353
}
354
}
355
}
356
357
+ require_once( dirname( __FILE__ ) . '/admin_header.php' );
358
?>
359
360
<?php if ( ! empty( $order ) ) { ?>
361
362
<h2>
363
<?php if ( ! empty( $order->id ) ) { ?>
364
+ <?php _e( 'Order', 'paid-memberships-pro' ); ?> #<?php echo $order->id; ?>: <?php echo $order->code; ?>
365
<?php } else { ?>
366
<?php _e( 'New Order', 'paid-memberships-pro' ); ?>
367
<?php } ?>
368
</h2>
369
370
<?php if ( ! empty( $pmpro_msg ) ) { ?>
371
+ <div id="message" class="
372
+ <?php
373
+ if ( $pmpro_msgt == 'success' ) {
374
+ echo 'updated fade';
375
} else {
376
+ echo 'error';
377
+ }
378
+ ?>
379
+ "><p><?php echo $pmpro_msg; ?></p></div>
380
<?php } ?>
381
382
<form method="post" action="">
383
+ <?php wp_nonce_field( 'save', 'pmpro_orders_nonce' ); ?>
384
385
<table class="form-table">
386
<tbody>
387
<tr>
388
<th scope="row" valign="top"><label>ID:</label></th>
389
+ <td>
390
+ <?php
391
+ if ( ! empty( $order->id ) ) {
392
echo $order->id;
393
+ } else {
394
+ echo __( 'This will be generated when you save.', 'paid-memberships-pro' );
395
+ }
396
+ ?>
397
+ </td>
398
</tr>
399
400
<tr>
401
<th scope="row" valign="top"><label for="code"><?php _e( 'Code', 'paid-memberships-pro' ); ?>:</label></th>
402
<td>
403
+ <?php
404
+ if ( in_array( 'code', $read_only_fields ) ) {
405
echo $order->code;
406
+ } else {
407
+ ?>
408
+ <input id="code" name="code" type="text" size="50"
409
+ value="<?php echo esc_attr( $order->code ); ?>"/>
410
<?php } ?>
411
<?php if ( $order_id < 0 ) { ?>
412
<small
417
<tr>
418
<th scope="row" valign="top"><label for="user_id"><?php _e( 'User ID', 'paid-memberships-pro' ); ?>:</label></th>
419
<td>
420
+ <?php
421
+ if ( in_array( 'user_id', $read_only_fields ) && $order_id > 0 ) {
422
echo $order->user_id;
423
+ } else {
424
+ ?>
425
+ <input id="user_id" name="user_id" type="text" size="50"
426
+ value="<?php echo esc_attr( $order->user_id ); ?>"/>
427
<?php } ?>
428
</td>
429
</tr>
432
<th scope="row" valign="top"><label for="membership_id"><?php _e( 'Membership Level ID', 'paid-memberships-pro' ); ?>
433
:</label></th>
434
<td>
435
+ <?php
436
+ if ( in_array( 'membership_id', $read_only_fields ) && $order_id > 0 ) {
437
echo $order->membership_id;
438
+ } else {
439
+ ?>
440
+ <input id="membership_id" name="membership_id" type="text" size="50"
441
+ value="<?php echo esc_attr( $order->membership_id ); ?>"/>
442
<?php } ?>
443
</td>
444
</tr>
447
<th scope="row" valign="top"><label for="billing_name"><?php _e( 'Billing Name', 'paid-memberships-pro' ); ?>:</label>
448
</th>
449
<td>
450
+ <?php
451
+ if ( in_array( 'billing_name', $read_only_fields ) && $order_id > 0 ) {
452
echo $order->billing_name;
453
+ } else {
454
+ ?>
455
+ <input id="billing_name" name="billing_name" type="text" size="50"
456
+ value="<?php echo esc_attr( $order->billing->name ); ?>"/>
457
<?php } ?>
458
</td>
459
</tr>
461
<th scope="row" valign="top"><label for="billing_street"><?php _e( 'Billing Street', 'paid-memberships-pro' ); ?>
462
:</label></th>
463
<td>
464
+ <?php
465
+ if ( in_array( 'billing_street', $read_only_fields ) && $order_id > 0 ) {
466
echo $order->billing_street;
467
+ } else {
468
+ ?>
469
+ <input id="billing_street" name="billing_street" type="text" size="50"
470
+ value="<?php echo esc_attr( $order->billing->street ); ?>"/></td>
471
+ <?php } ?>
472
</tr>
473
<tr>
474
<th scope="row" valign="top"><label for="billing_city"><?php _e( 'Billing City', 'paid-memberships-pro' ); ?>:</label>
475
</th>
476
<td>
477
+ <?php
478
+ if ( in_array( 'billing_city', $read_only_fields ) && $order_id > 0 ) {
479
echo $order->billing_city;
480
+ } else {
481
+ ?>
482
+ <input id="billing_city" name="billing_city" type="text" size="50"
483
+ value="<?php echo esc_attr( $order->billing->city ); ?>"/></td>
484
+ <?php } ?>
485
</tr>
486
<tr>
487
<th scope="row" valign="top"><label for="billing_state"><?php _e( 'Billing State', 'paid-memberships-pro' ); ?>
488
:</label></th>
489
<td>
490
+ <?php
491
+ if ( in_array( 'billing_state', $read_only_fields ) && $order_id > 0 ) {
492
echo $order->billing_state;
493
+ } else {
494
+ ?>
495
+ <input id="billing_state" name="billing_state" type="text" size="50"
496
+ value="<?php echo esc_attr( $order->billing->state ); ?>"/></td>
497
+ <?php } ?>
498
</tr>
499
<tr>
500
<th scope="row" valign="top"><label for="billing_zip"><?php _e( 'Billing Postal Code', 'paid-memberships-pro' ); ?>
501
:</label></th>
502
<td>
503
+ <?php
504
+ if ( in_array( 'billing_zip', $read_only_fields ) && $order_id > 0 ) {
505
echo $order->billing_zip;
506
+ } else {
507
+ ?>
508
+ <input id="billing_zip" name="billing_zip" type="text" size="50"
509
+ value="<?php echo esc_attr( $order->billing->zip ); ?>"/></td>
510
+ <?php } ?>
511
</tr>
512
<tr>
513
<th scope="row" valign="top"><label for="billing_country"><?php _e( 'Billing Country', 'paid-memberships-pro' ); ?>
514
:</label></th>
515
<td>
516
+ <?php
517
+ if ( in_array( 'billing_country', $read_only_fields ) && $order_id > 0 ) {
518
echo $order->billing_country;
519
+ } else {
520
+ ?>
521
+ <input id="billing_country" name="billing_country" type="text" size="50"
522
+ value="<?php echo esc_attr( $order->billing->country ); ?>"/>
523
<?php } ?>
524
</td>
525
</tr>
527
<th scope="row" valign="top"><label for="billing_phone"><?php _e( 'Billing Phone', 'paid-memberships-pro' ); ?>
528
:</label></th>
529
<td>
530
+ <?php
531
+ if ( in_array( 'billing_phone', $read_only_fields ) && $order_id > 0 ) {
532
echo $order->billing_phone;
533
+ } else {
534
+ ?>
535
+ <input id="billing_phone" name="billing_phone" type="text" size="50"
536
+ value="<?php echo esc_attr( $order->billing->phone ); ?>"/>
537
<?php } ?>
538
</td>
539
</tr>
541
<tr>
542
<th scope="row" valign="top"><label for="subtotal"><?php _e( 'Sub Total', 'paid-memberships-pro' ); ?>:</label></th>
543
<td>
544
+ <?php
545
+ if ( in_array( 'subtotal', $read_only_fields ) && $order_id > 0 ) {
546
echo $order->subtotal;
547
+ } else {
548
+ ?>
549
+ <input id="subtotal" name="subtotal" type="text" size="10"
550
+ value="<?php echo esc_attr( $order->subtotal ); ?>"/>
551
<?php } ?>
552
</td>
553
</tr>
554
<tr>
555
<th scope="row" valign="top"><label for="tax"><?php _e( 'Tax', 'paid-memberships-pro' ); ?>:</label></th>
556
<td>
557
+ <?php
558
+ if ( in_array( 'tax', $read_only_fields ) && $order_id > 0 ) {
559
echo $order->tax;
560
+ } else {
561
+ ?>
562
+ <input id="tax" name="tax" type="text" size="10"
563
+ value="<?php echo esc_attr( $order->tax ); ?>"/>
564
<?php } ?>
565
</td>
566
</tr>
568
<th scope="row" valign="top"><label for="couponamount"><?php _e( 'Coupon Amount', 'paid-memberships-pro' ); ?>:</label>
569
</th>
570
<td>
571
+ <?php
572
+ if ( in_array( 'couponamount', $read_only_fields ) && $order_id > 0 ) {
573
echo $order->couponamount;
574
+ } else {
575
+ ?>
576
+ <input id="couponamount" name="couponamount" type="text" size="10"
577
+ value="<?php echo esc_attr( $order->couponamount ); ?>"/>
578
<?php } ?>
579
</td>
580
</tr>
581
<tr>
582
<th scope="row" valign="top"><label for="total"><?php _e( 'Total', 'paid-memberships-pro' ); ?>:</label></th>
583
<td>
584
+ <?php
585
+ if ( in_array( 'total', $read_only_fields ) && $order_id > 0 ) {
586
echo $order->total;
587
+ } else {
588
+ ?>
589
+ <input id="total" name="total" type="text" size="10"
590
+ value="<?php echo esc_attr( $order->total ); ?>"/>
591
<?php } ?>
592
<small
593
class="pmpro_lite"><?php _e( 'Should be subtotal + tax - couponamount.', 'paid-memberships-pro' ); ?></small>
598
<th scope="row" valign="top"><label for="payment_type"><?php _e( 'Payment Type', 'paid-memberships-pro' ); ?>:</label>
599
</th>
600
<td>
601
+ <?php
602
+ if ( in_array( 'payment_type', $read_only_fields ) && $order_id > 0 ) {
603
echo $order->payment_type;
604
+ } else {
605
+ ?>
606
+ <input id="payment_type" name="payment_type" type="text" size="50"
607
+ value="<?php echo esc_attr( $order->payment_type ); ?>"/>
608
<?php } ?>
609
<small
610
class="pmpro_lite"><?php _e( 'e.g. PayPal Express, PayPal Standard, Credit Card.', 'paid-memberships-pro' ); ?></small>
613
<tr>
614
<th scope="row" valign="top"><label for="cardtype"><?php _e( 'Card Type', 'paid-memberships-pro' ); ?></label></th>
615
<td>
616
+ <?php
617
+ if ( in_array( 'cardtype', $read_only_fields ) && $order_id > 0 ) {
618
echo $order->cardtype;
619
+ } else {
620
+ ?>
621
+ <input id="cardtype" name="cardtype" type="text" size="50"
622
+ value="<?php echo esc_attr( $order->cardtype ); ?>"/>
623
<?php } ?>
624
<small class="pmpro_lite"><?php _e( 'e.g. Visa, MasterCard, AMEX, etc', 'paid-memberships-pro' ); ?></small>
625
</td>
628
<th scope="row" valign="top"><label for="accountnumber"><?php _e( 'Account Number', 'paid-memberships-pro' ); ?>
629
:</label></th>
630
<td>
631
+ <?php
632
+ if ( in_array( 'accountnumber', $read_only_fields ) && $order_id > 0 ) {
633
echo $order->accountnumber;
634
+ } else {
635
+ ?>
636
+ <input id="accountnumber" name="accountnumber" type="text" size="50"
637
+ value="<?php echo esc_attr( $order->accountnumber ); ?>"/>
638
<?php } ?>
639
<small class="pmpro_lite"><?php _e( 'Obscure all but last 4 digits.', 'paid-memberships-pro' ); ?></small>
640
</td>
641
</tr>
642
+ <?php
643
+ if ( in_array( 'ExpirationDate', $read_only_fields ) && $order_id > 0 ) {
644
echo $order->ExpirationDate;
645
+ } else {
646
+ ?>
647
+ <tr>
648
+ <th scope="row" valign="top"><label
649
for="expirationmonth"><?php _e( 'Expiration Month', 'paid-memberships-pro' ); ?>:</label></th>
650
<td>
651
<input id="expirationmonth" name="expirationmonth" type="text" size="10"
652
+ value="<?php echo esc_attr( $order->expirationmonth ); ?>"/>
653
<small class="pmpro_lite">MM</small>
654
</td>
655
</tr>
656
<tr>
657
<th scope="row" valign="top"><label for="expirationyear"><?php _e( 'Expiration Year', 'paid-memberships-pro' ); ?>
658
+ :</label></th>
659
<td>
660
<input id="expirationyear" name="expirationyear" type="text" size="10"
661
+ value="<?php echo esc_attr( $order->expirationyear ); ?>"/>
662
<small class="pmpro_lite">YYYY</small>
663
</td>
664
</tr>
666
<tr>
667
<th scope="row" valign="top"><label for="status"><?php _e( 'Status', 'paid-memberships-pro' ); ?>:</label></th>
668
<td>
669
+ <?php
670
+ if ( in_array( 'status', $read_only_fields ) && $order_id > 0 ) {
671
echo $order->status;
672
+ } else {
673
+ ?>
674
+ <?php
675
+ $statuses = array();
676
+ $default_statuses = array(
677
+ '',
678
+ 'success',
679
+ 'cancelled',
680
+ 'review',
681
+ 'token',
682
+ 'refunded',
683
+ 'pending',
684
+ 'error',
685
+ );
686
+ $used_statuses = $wpdb->get_col( "SELECT DISTINCT(status) FROM $wpdb->pmpro_membership_orders" );
687
+ $statuses = array_unique( array_merge( $default_statuses, $used_statuses ) );
688
+ asort( $statuses );
689
+ $statuses = apply_filters( 'pmpro_order_statuses', $statuses );
690
?>
691
<select id="status" name="status">
692
+ <?php foreach ( $statuses as $status ) { ?>
693
<option
694
value="<?php echo esc_attr( $status ); ?>" <?php selected( $order->status, $status ); ?>><?php echo $status; ?></option>
695
<?php } ?>
701
<tr>
702
<th scope="row" valign="top"><label for="gateway"><?php _e( 'Gateway', 'paid-memberships-pro' ); ?>:</label></th>
703
<td>
704
+ <?php
705
+ if ( in_array( 'gateway', $read_only_fields ) && $order_id > 0 ) {
706
echo $order->gateway;
707
+ } else {
708
+ ?>
709
+ <select id="gateway" name="gateway" onchange="pmpro_changeGateway(jQuery(this).val());">
710
+ <?php
711
+ $pmpro_gateways = pmpro_gateways();
712
+ foreach ( $pmpro_gateways as $pmpro_gateway_name => $pmpro_gateway_label ) {
713
+ ?>
714
+ <option
715
+ value="<?php echo esc_attr( $pmpro_gateway_name ); ?>" <?php selected( $order->gateway, $pmpro_gateway_name ); ?>><?php echo $pmpro_gateway_label; ?></option>
716
<?php
717
+ }
718
+ ?>
719
+ </select>
720
+ <?php } ?>
721
</td>
722
</tr>
723
<tr>
724
<th scope="row" valign="top"><label
725
for="gateway_environment"><?php _e( 'Gateway Environment', 'paid-memberships-pro' ); ?>:</label></th>
726
<td>
727
+ <?php
728
+ if ( in_array( 'gateway_environment', $read_only_fields ) && $order_id > 0 ) {
729
echo $order->gateway_environment;
730
+ } else {
731
+ ?>
732
+ <select name="gateway_environment">
733
+ <option value="sandbox"
734
+ <?php
735
+ if ( $order->gateway_environment == 'sandbox' ) {
736
+ ?>
737
+ selected="selected"<?php } ?>><?php _e( 'Sandbox/Testing', 'paid-memberships-pro' ); ?></option>
738
<option value="live"
739
+ <?php
740
+ if ( $order->gateway_environment == 'live' ) {
741
+ ?>
742
+ selected="selected"<?php } ?>><?php _e( 'Live/Production', 'paid-memberships-pro' ); ?></option>
743
</select>
744
<?php } ?>
745
</td>
749
<th scope="row" valign="top"><label
750
for="payment_transaction_id"><?php _e( 'Payment Transaction ID', 'paid-memberships-pro' ); ?>:</label></th>
751
<td>
752
+ <?php
753
+ if ( in_array( 'payment_transaction_id', $read_only_fields ) && $order_id > 0 ) {
754
echo $order->payment_transaction_id;
755
+ } else {
756
+ ?>
757
+ <input id="payment_transaction_id" name="payment_transaction_id" type="text" size="50"
758
+ value="<?php echo esc_attr( $order->payment_transaction_id ); ?>"/>
759
<?php } ?>
760
<small
761
class="pmpro_lite"><?php _e( 'Generated by the gateway. Useful to cross reference orders.', 'paid-memberships-pro' ); ?></small>
766
for="subscription_transaction_id"><?php _e( 'Subscription Transaction ID', 'paid-memberships-pro' ); ?>
767
:</label></th>
768
<td>
769
+ <?php
770
+ if ( in_array( 'subscription_transaction_id', $read_only_fields ) && $order_id > 0 ) {
771
echo $order->subscription_transaction_id;
772
+ } else {
773
+ ?>
774
+ <input id="subscription_transaction_id" name="subscription_transaction_id" type="text" size="50"
775
+ value="<?php echo esc_attr( $order->subscription_transaction_id ); ?>"/>
776
<?php } ?>
777
<small
778
class="pmpro_lite"><?php _e( 'Generated by the gateway. Useful to cross reference subscriptions.', 'paid-memberships-pro' ); ?></small>
782
<tr>
783
<th scope="row" valign="top"><label for="ts_month"><?php _e( 'Date', 'paid-memberships-pro' ); ?>:</label></th>
784
<td>
785
+ <?php
786
+ if ( in_array( 'timestamp', $read_only_fields ) && $order_id > 0 ) {
787
+ echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $order->timestamp );
788
+ } else {
789
+ ?>
790
+ <?php
791
+ // set up date vars
792
+ if ( ! empty( $order->timestamp ) ) {
793
+ $timestamp = $order->timestamp;
794
+ } else {
795
+ $timestamp = current_time( 'timestamp' );
796
+ }
797
+ $year = date_i18n( 'Y', $timestamp );
798
+ $month = date_i18n( 'n', $timestamp );
799
+ $day = date_i18n( 'j', $timestamp );
800
+ ?>
801
+ <select id="ts_month" name="ts_month">
802
<?php
803
for ( $i = 1; $i < 13; $i ++ ) {
804
?>
805
+ <option value="<?php echo $i; ?>"
806
+ <?php
807
+ if ( $i == $month ) {
808
+ ?>
809
+ selected="selected"<?php } ?>><?php echo date_i18n( 'M', strtotime( $i . '/1/' . $year, current_time( 'timestamp' ) ) ); ?></option>
810
<?php
811
}
812
?>
818
</tr>
819
820
<?php
821
+ $affiliates = apply_filters( 'pmpro_orders_show_affiliate_ids', false );
822
if ( ! empty( $affiliates ) ) {
823
?>
824
<tr>
825
<th scope="row" valign="top"><label for="affiliate_id"><?php _e( 'Affiliate ID', 'paid-memberships-pro' ); ?>
826
:</label></th>
827
<td>
828
+ <?php
829
+ if ( in_array( 'affiliate_id', $read_only_fields ) && $order_id > 0 ) {
830
echo $order->affiliate_id;
831
+ } else {
832
+ ?>
833
+ <input id="affiliate_id" name="affiliate_id" type="text" size="50"
834
+ value="<?php echo esc_attr( $order->affiliate_id ); ?>"/>
835
<?php } ?>
836
</td>
837
</tr>
839
<th scope="row" valign="top"><label for="affiliate_subid"><?php _e( 'Affiliate SubID', 'paid-memberships-pro' ); ?>
840
:</label></th>
841
<td>
842
+ <?php
843
+ if ( in_array( 'affiliate_subid', $read_only_fields ) && $order_id > 0 ) {
844
echo $order->affiliate_subid;
845
+ } else {
846
+ ?>
847
+ <input id="affiliate_subid" name="affiliate_subid" type="text" size="50"
848
+ value="<?php echo esc_attr( $order->affiliate_subid ); ?>"/>
849
<?php } ?>
850
</td>
851
</tr>
854
<tr>
855
<th scope="row" valign="top"><label for="notes"><?php _e( 'Notes', 'paid-memberships-pro' ); ?>:</label></th>
856
<td>
857
+ <?php
858
+ if ( in_array( 'notes', $read_only_fields ) && $order_id > 0 ) {
859
echo $order->notes;
860
+ } else {
861
+ ?>
862
+ <textarea id="notes" name="notes" rows="5"
863
+ cols="80"><?php echo esc_textarea( $order->notes ); ?></textarea>
864
<?php } ?>
865
</td>
866
</tr>
867
868
+ <?php do_action( 'pmpro_after_order_settings', $order ); ?>
869
870
</tbody>
871
</table>
872
873
<p class="submit topborder">
874
+ <input name="order" type="hidden" value="
875
+ <?php
876
+ if ( ! empty( $order->id ) ) {
877
echo $order->id;
878
} else {
879
echo $order_id;
880
+ }
881
+ ?>
882
+ "/>
883
<input name="save" type="submit" class="button-primary" value="<?php _e( 'Save Order', 'paid-memberships-pro' ); ?>"/>
884
<input name="cancel" type="button" class="cancel button-secondary" value="<?php _e( 'Cancel', 'paid-memberships-pro' ); ?>"
885
+ onclick="location.href='<?php echo get_admin_url( null, '/admin.php?page=pmpro-orders' ); ?>';"/>
886
</p>
887
888
</form>
931
class="add-new-h2">+ <?php _e( 'Add New Order', 'paid-memberships-pro' ); ?></a>
932
933
<?php
934
+ // build the export URL
935
$export_url = admin_url( 'admin-ajax.php?action=orders_csv' );
936
$url_params = array(
937
+ 'filter' => $filter,
938
+ 's' => $s,
939
+ 'l' => $l,
940
+ 'start-month' => $start_month,
941
+ 'start-day' => $start_day,
942
+ 'start-year' => $start_year,
943
+ 'end-month' => $end_month,
944
+ 'end-day' => $end_day,
945
+ 'end-year' => $end_year,
946
+ 'predefined-date' => $predefined_date,
947
+ 'status' => $status,
948
);
949
$export_url = add_query_arg( $url_params, $export_url );
950
?>
954
955
956
<?php if ( ! empty( $pmpro_msg ) ) { ?>
957
+ <div id="message" class="
958
+ <?php
959
+ if ( $pmpro_msgt == 'success' ) {
960
+ echo 'updated fade';
961
} else {
962
+ echo 'error';
963
+ }
964
+ ?>
965
+ "><p><?php echo $pmpro_msg; ?></p></div>
966
<?php } ?>
967
968
969
<ul class="subsubsub">
970
<li>
971
+ <?php _e( 'Show', 'paid-memberships-pro' ); ?>
972
<select id="filter" name="filter">
973
+ <option value="all" <?php selected( $filter, 'all' ); ?>><?php _e( 'All', 'paid-memberships-pro' ); ?></option>
974
<option
975
+ value="within-a-date-range" <?php selected( $filter, 'within-a-date-range' ); ?>><?php _e( 'Within a Date Range', 'paid-memberships-pro' ); ?></option>
976
<option
977
+ value="predefined-date-range" <?php selected( $filter, 'predefined-date-range' ); ?>><?php _e( 'Predefined Date Range', 'paid-memberships-pro' ); ?></option>
978
<option
979
+ value="within-a-level" <?php selected( $filter, 'within-a-level' ); ?>><?php _e( 'Within a Level', 'paid-memberships-pro' ); ?></option>
980
<option
981
+ value="within-a-status" <?php selected( $filter, 'within-a-status' ); ?>><?php _e( 'Within a Status', 'paid-memberships-pro' ); ?></option>
982
</select>
983
984
+ <span id="from"><?php _e( 'From', 'paid-memberships-pro' ); ?></span>
985
986
<select id="start-month" name="start-month">
987
<?php for ( $i = 1; $i < 13; $i ++ ) { ?>
988
<option
989
+ value="<?php echo $i; ?>" <?php selected( $start_month, $i ); ?>><?php echo date_i18n( 'F', mktime( 0, 0, 0, $i, 2 ) ); ?></option>
990
<?php } ?>
991
</select>
992
993
<input id='start-day' name="start-day" type="text" size="2"
994
+ value="<?php echo esc_attr( $start_day ); ?>"/>
995
<input id='start-year' name="start-year" type="text" size="4"
996
+ value="<?php echo esc_attr( $start_year ); ?>"/>
997
998
999
+ <span id="to"><?php _e( 'To', 'paid-memberships-pro' ); ?></span>
1000
1001
<select id="end-month" name="end-month">
1002
<?php for ( $i = 1; $i < 13; $i ++ ) { ?>
1003
<option
1004
+ value="<?php echo $i; ?>" <?php selected( $end_month, $i ); ?>><?php echo date_i18n( 'F', mktime( 0, 0, 0, $i, 2 ) ); ?></option>
1005
<?php } ?>
1006
</select>
1007
1009
<input id='end-day' name="end-day" type="text" size="2" value="<?php echo esc_attr( $end_day ); ?>"/>
1010
<input id='end-year' name="end-year" type="text" size="4" value="<?php echo esc_attr( $end_year ); ?>"/>
1011
1012
+ <span id="filterby"><?php _e( 'filter by ', 'paid-memberships-pro' ); ?></span>
1013
1014
<select id="predefined-date" name="predefined-date">
1015
1016
<option
1017
+ value="<?php echo 'This Month'; ?>" <?php selected( $predefined_date, 'This Month' ); ?>><?php echo 'This Month'; ?></option>
1018
<option
1019
+ value="<?php echo 'Last Month'; ?>" <?php selected( $predefined_date, 'Last Month' ); ?>><?php echo 'Last Month'; ?></option>
1020
<option
1021
+ value="<?php echo 'This Year'; ?>" <?php selected( $predefined_date, 'This Year' ); ?>><?php echo 'This Year'; ?></option>
1022
<option
1023
+ value="<?php echo 'Last Year'; ?>" <?php selected( $predefined_date, 'Last Year' ); ?>><?php echo 'Last Year'; ?></option>
1024
1025
</select>
1026
1027
<?php
1028
+ // Note: only orders belonging to current levels can be filtered. There is no option for orders belonging to deleted levels
1029
$levels = pmpro_getAllLevels( true, true );
1030
?>
1031
<select id="l" name="l">
1036
1037
</select>
1038
1039
+ <?php
1040
$statuses = pmpro_getOrderStatuses();
1041
?>
1042
<select id="status" name="status">
1151
</p>
1152
1153
<?php
1154
+ // string search
1155
if ( $s ) {
1156
$sqlQuery = "SELECT SQL_CALC_FOUND_ROWS o.id FROM $wpdb->pmpro_membership_orders o LEFT JOIN $wpdb->users u ON o.user_id = u.ID LEFT JOIN $wpdb->pmpro_membership_levels l ON o.membership_id = l.id ";
1157
1158
+ $join_with_usermeta = apply_filters( 'pmpro_orders_search_usermeta', false );
1159
if ( $join_with_usermeta ) {
1160
$sqlQuery .= "LEFT JOIN $wpdb->usermeta um ON o.user_id = um.user_id ";
1161
}
1162
1163
+ $sqlQuery .= 'WHERE (1=2 ';
1164
1165
$fields = array(
1166
+ 'o.id',
1167
+ 'o.code',
1168
+ 'o.billing_name',
1169
+ 'o.billing_street',
1170
+ 'o.billing_city',
1171
+ 'o.billing_state',
1172
+ 'o.billing_zip',
1173
+ 'o.billing_phone',
1174
+ 'o.payment_type',
1175
+ 'o.cardtype',
1176
+ 'o.accountnumber',
1177
+ 'o.status',
1178
+ 'o.gateway',
1179
+ 'o.gateway_environment',
1180
+ 'o.payment_transaction_id',
1181
+ 'o.subscription_transaction_id',
1182
+ 'u.user_login',
1183
+ 'u.user_email',
1184
+ 'u.display_name',
1185
+ 'l.name',
1186
);
1187
1188
if ( $join_with_usermeta ) {
1189
+ $fields[] = 'um.meta_value';
1190
}
1191
1192
+ $fields = apply_filters( 'pmpro_orders_search_fields', $fields );
1193
1194
foreach ( $fields as $field ) {
1195
+ $sqlQuery .= ' OR ' . $field . " LIKE '%" . esc_sql( $s ) . "%' ";
1196
}
1197
+ $sqlQuery .= ') ';
1198
1199
+ $sqlQuery .= 'AND ' . $condition . ' ';
1200
1201
+ $sqlQuery .= 'GROUP BY o.id ORDER BY o.id DESC, o.timestamp DESC ';
1202
} else {
1203
+ $sqlQuery = "SELECT SQL_CALC_FOUND_ROWS id FROM $wpdb->pmpro_membership_orders WHERE " . $condition . ' ORDER BY id DESC, timestamp DESC ';
1204
}
1205
1206
$sqlQuery .= "LIMIT $start, $limit";
1207
1208
$order_ids = $wpdb->get_col( $sqlQuery );
1209
1210
+ $totalrows = $wpdb->get_var( 'SELECT FOUND_ROWS() as found_rows' );
1211
1212
if ( $order_ids ) {
1213
?>
1214
+ <p class="clear"><?php printf( __( '%d orders found.', 'paid-memberships-pro' ), $totalrows ); ?></span></p>
1215
<?php
1216
}
1217
?>
1221
<th><?php _e( 'ID', 'paid-memberships-pro' ); ?></th>
1222
<th><?php _e( 'Code', 'paid-memberships-pro' ); ?></th>
1223
<th><?php _e( 'User', 'paid-memberships-pro' ); ?></th>
1224
+ <?php do_action( 'pmpro_orders_extra_cols_header', $order_ids ); ?>
1225
<th><?php _e( 'Membership Level', 'paid-memberships-pro' ); ?></th>
1226
<th><?php _e( 'Total', 'paid-memberships-pro' ); ?></th>
1227
<th><?php _e( 'Payment', 'paid-memberships-pro' ); ?></th>
1244
$order->nogateway = true;
1245
$order->getMemberOrderByID( $order_id );
1246
?>
1247
+ <tr
1248
+ <?php
1249
+ if ( $count ++ % 2 == 0 ) {
1250
+ ?>
1251
+ class="alternate"<?php } ?>>
1252
<td>
1253
+ <a href="admin.php?page=pmpro-orders&order=<?php echo $order->id; ?>"><?php echo $order->id; ?></a>
1254
</td>
1255
<td>
1256
+ <a href="admin.php?page=pmpro-orders&order=<?php echo $order->id; ?>"><?php echo $order->code; ?></a>
1257
</td>
1258
<td class="username column-username">
1259
<?php $order->getUser(); ?>
1260
<?php if ( ! empty( $order->user ) ) { ?>
1261
+ <a href="user-edit.php?user_id=<?php echo $order->user->ID; ?>"><?php echo $order->user->user_login; ?></a>
1262
+ <?php } elseif ( $order->user_id > 0 ) { ?>
1263
[<?php _e( 'deleted', 'paid-memberships-pro' ); ?>]
1264
+ <?php } else { ?>
1265
+ [<?php _e( 'none', 'paid-memberships-pro' ); ?>]
1266
<?php } ?>
1267
<br/>
1268
<?php
1282
}
1283
?>
1284
</td>
1285
+ <?php do_action( 'pmpro_orders_extra_cols_body', $order ); ?>
1286
<td><?php echo $order->membership_id; ?></td>
1287
<td><?php echo pmpro_formatPrice( $order->total ); ?></td>
1288
<td>
1289
+ <?php
1290
+ if ( ! empty( $order->payment_type ) ) {
1291
+ echo $order->payment_type . '<br />';
1292
+ }
1293
+ ?>
1294
<?php if ( ! empty( $order->accountnumber ) ) { ?>
1295
<?php echo $order->cardtype; ?>: x<?php echo last4( $order->accountnumber ); ?><br/>
1296
<?php } ?>
1300
<?php if ( ! empty( $order->billing->street ) ) { ?>
1301
<?php echo $order->billing->street; ?><br/>
1302
<?php if ( $order->billing->city && $order->billing->state ) { ?>
1303
+ <?php echo $order->billing->city; ?>, <?php echo $order->billing->state; ?><?php echo $order->billing->zip; ?>
1304
+ <?php
1305
+ if ( ! empty( $order->billing->country ) ) {
1306
+ echo $order->billing->country; }
1307
+ ?>
1308
+ <br/>
1309
<?php } ?>
1310
<?php } ?>
1311
+ <?php
1312
+ if ( ! empty( $order->billing->phone ) ) {
1313
echo formatPhone( $order->billing->phone );
1314
+ }
1315
+ ?>
1316
</td>
1317
+ <td><?php echo $order->gateway; ?>
1318
+ <?php
1319
+ if ( $order->gateway_environment == 'test' ) {
1320
+ echo '(test)';
1321
+ }
1322
+ ?>
1323
+ </td>
1324
<td>
1325
+ <?php _e( 'Payment', 'paid-memberships-pro' ); ?>:
1326
+ <?php
1327
+ if ( ! empty( $order->payment_transaction_id ) ) {
1328
+ echo $order->payment_transaction_id;
1329
+ } else {
1330
+ _e( 'N/A', 'paid-memberships-pro' );
1331
+ }
1332
+ ?>
1333
<br/>
1334
<?php _e( 'Subscription', 'paid-memberships-pro' ); ?>
1335
+ :
1336
+ <?php
1337
+ if ( ! empty( $order->subscription_transaction_id ) ) {
1338
echo $order->subscription_transaction_id;
1339
} else {
1340
+ _e( 'N/A', 'paid-memberships-pro' );
1341
+ }
1342
+ ?>
1343
</td>
1344
<td><?php echo $order->status; ?></td>
1345
<td>
1353
<a href="admin.php?page=pmpro-orders&order=-1&copy=<?php echo $order->id; ?>"><?php _e( 'copy', 'paid-memberships-pro' ); ?></a>
1354
</td>
1355
<td align="center">
1356
+ <a href="javascript:askfirst('<?php echo str_replace( "'", "\'", sprintf( __( 'Deleting orders is permanent and can affect active users. Are you sure you want to delete order %s?', 'paid-memberships-pro' ), str_replace( "'", '', $order->code ) ) ); ?>', 'admin.php?page=pmpro-orders&delete=<?php echo $order->id; ?>'); void(0);"><?php _e( 'delete', 'paid-memberships-pro' ); ?></a>
1357
</td>
1358
<td align="center">
1359
<a href="admin-ajax.php?action=pmpro_orders_print_view&order=<?php echo $order->id; ?>"
1379
</table>
1380
</form>
1381
<?php
1382
+ // add normal args
1383
+ $pagination_url = add_query_arg( $url_params, get_admin_url( null, '/admin.php?page=pmpro-orders' ) );
1384
echo pmpro_getPaginationString( $pn, $totalrows, $limit, 1, $pagination_url, "&limit=$limit&pn=" );
1385
?>
1386
1387
<?php } ?>
1388
<?php
1389
+ require_once( dirname( __FILE__ ) . '/admin_footer.php' );
classes/class.memberorder.php CHANGED
@@ -723,6 +723,26 @@
723
//get some data
724
$order_user = get_userdata($this->user_id);
725
726
//cancel the gateway subscription first
727
if (is_object($this->Gateway)) {
728
$result = $this->Gateway->cancel( $this );
@@ -752,23 +772,7 @@
752
$wpdb->query($sqlQuery);
753
}
754
755
- //cancel orders for the same subscription
756
- $sqlQuery = $wpdb->prepare(
757
- "UPDATE $wpdb->pmpro_membership_orders
758
- SET `status` = 'cancelled'
759
- WHERE user_id = %d
760
- AND membership_id = %d
761
- AND gateway = %s
762
- AND gateway_environment = %s
763
- AND subscription_transaction_id = %s
764
- AND `status` IN('success', '') ",
765
- $this->user_id,
766
- $this->membership_id,
767
- $this->gateway,
768
- $this->gateway_environment,
769
- $this->subscription_transaction_id
770
- );
771
- $wpdb->query($sqlQuery);
772
773
return $result;
774
}
723
//get some data
724
$order_user = get_userdata($this->user_id);
725
726
+ //cancel orders for the same subscription
727
+ //Note: We do this early to avoid race conditions if and when the
728
+ //gateway send the cancel webhook after cancelling the subscription.
729
+ $sqlQuery = $wpdb->prepare(
730
+ "UPDATE $wpdb->pmpro_membership_orders
731
+ SET `status` = 'cancelled'
732
+ WHERE user_id = %d
733
+ AND membership_id = %d
734
+ AND gateway = %s
735
+ AND gateway_environment = %s
736
+ AND subscription_transaction_id = %s
737
+ AND `status` IN('success', '') ",
738
+ $this->user_id,
739
+ $this->membership_id,
740
+ $this->gateway,
741
+ $this->gateway_environment,
742
+ $this->subscription_transaction_id
743
+ );
744
+ $wpdb->query($sqlQuery);
745
+
746
//cancel the gateway subscription first
747
if (is_object($this->Gateway)) {
748
$result = $this->Gateway->cancel( $this );
772
$wpdb->query($sqlQuery);
773
}
774
775
+
776
777
return $result;
778
}
classes/class.pmproemail.php CHANGED
@@ -98,12 +98,19 @@
98
{
99
foreach($this->data as $key => $value)
100
{
101
- $this->body = str_replace("!!" . $key . "!!", $value, $this->body);
102
}
103
}
104
105
//filters
106
$temail = apply_filters("pmpro_email_filter", $this); //allows filtering entire email at once
107
$this->email = apply_filters("pmpro_email_recipient", $temail->email, $this);
108
$this->from = apply_filters("pmpro_email_sender", $temail->from, $this);
109
$this->fromname = apply_filters("pmpro_email_sender_name", $temail->fromname, $this);
98
{
99
foreach($this->data as $key => $value)
100
{
101
+ if ( 'body' != $key ) {
102
+ $this->body = str_replace("!!" . $key . "!!", $value, $this->body);
103
+ }
104
}
105
}
106
107
//filters
108
$temail = apply_filters("pmpro_email_filter", $this); //allows filtering entire email at once
109
+
110
+ if ( empty( $temail ) ) {
111
+ return false;
112
+ }
113
+
114
$this->email = apply_filters("pmpro_email_recipient", $temail->email, $this);
115
$this->from = apply_filters("pmpro_email_sender", $temail->from, $this);
116
$this->fromname = apply_filters("pmpro_email_sender_name", $temail->fromname, $this);
classes/gateways/class.pmprogateway_stripe.php CHANGED
@@ -264,7 +264,7 @@
264
<input type="text" id="stripe_publishablekey" name="stripe_publishablekey" size="60" value="<?php echo esc_attr($values['stripe_publishablekey'])?>" />
265
<?php
266
$public_key_prefix = substr($values['stripe_publishablekey'] , 0, 3);
267
- if($public_key_prefix != 'pk_') {
268
?>
269
<br /><small class="pmpro_message pmpro_error"><?php _e('Your Publishable Key appears incorrect.', 'paid-memberships-pro');?></small>
270
<?php
@@ -278,15 +278,6 @@
278
</th>
279
<td>
280
<input type="text" id="stripe_secretkey" name="stripe_secretkey" size="60" value="<?php echo esc_attr($values['stripe_secretkey'])?>" />
281
- <?php
282
- $secret_key_prefix = substr($values['stripe_secretkey'] , 0, 3);
283
- //note the false here to disable this for now until we figure out a better check
284
- if(false && $secret_key_prefix != 'sk_') {
285
- ?>
286
- <br /><small class="pmpro_message pmpro_error"><?php _e('Your Secret Key appears incorrect.', 'paid-memberships-pro');?></small>
287
- <?php
288
- }
289
- ?>
290
</td>
291
</tr>
292
<tr class="gateway gateway_stripe" <?php if($gateway != "stripe") { ?>style="display: none;"<?php } ?>>
264
<input type="text" id="stripe_publishablekey" name="stripe_publishablekey" size="60" value="<?php echo esc_attr($values['stripe_publishablekey'])?>" />
265
<?php
266
$public_key_prefix = substr($values['stripe_publishablekey'] , 0, 3);
267
+ if(!empty($values['stripe_publishablekey']) && $public_key_prefix != 'pk_') {
268
?>
269
<br /><small class="pmpro_message pmpro_error"><?php _e('Your Publishable Key appears incorrect.', 'paid-memberships-pro');?></small>
270
<?php
278
</th>
279
<td>
280
<input type="text" id="stripe_secretkey" name="stripe_secretkey" size="60" value="<?php echo esc_attr($values['stripe_secretkey'])?>" />
281
</td>
282
</tr>
283
<tr class="gateway gateway_stripe" <?php if($gateway != "stripe") { ?>style="display: none;"<?php } ?>>
includes/filters.php CHANGED
@@ -7,224 +7,231 @@
7
If checking out for the same level, add remaining days to the enddate.
8
Pulled in from: https://gist.github.com/3678054
9
*/
10
- function pmpro_checkout_level_extend_memberships($level)
11
- {
12
global $pmpro_msg, $pmpro_msgt;
13
14
- //does this level expire? are they an existing user of this level?
15
- if(!empty($level) && !empty($level->expiration_number) && pmpro_hasMembershipLevel($level->id))
16
- {
17
- //get the current enddate of their membership
18
global $current_user;
19
- $expiration_date = $current_user->membership_level->enddate;
20
21
- //calculate days left
22
- $todays_date = current_time('timestamp');
23
$time_left = $expiration_date - $todays_date;
24
25
- //time left?
26
- if($time_left > 0)
27
- {
28
- //convert to days and add to the expiration date (assumes expiration was 1 year)
29
- $days_left = floor($time_left/(60*60*24));
30
31
- //figure out days based on period
32
- if($level->expiration_period == "Day")
33
$total_days = $days_left + $level->expiration_number;
34
- elseif($level->expiration_period == "Week")
35
$total_days = $days_left + $level->expiration_number * 7;
36
- elseif($level->expiration_period == "Month")
37
$total_days = $days_left + $level->expiration_number * 30;
38
- elseif($level->expiration_period == "Year")
39
$total_days = $days_left + $level->expiration_number * 365;
40
41
- //update number and period
42
$level->expiration_number = $total_days;
43
- $level->expiration_period = "Day";
44
}
45
}
46
47
return $level;
48
}
49
- add_filter("pmpro_checkout_level", "pmpro_checkout_level_extend_memberships");
50
/*
51
Same thing as above but when processed by the ipnhandler for PayPal standard.
52
*/
53
- function pmpro_ipnhandler_level_extend_memberships($level, $user_id)
54
- {
55
global $pmpro_msg, $pmpro_msgt;
56
57
- //does this level expire? are they an existing user of this level?
58
- if(!empty($level) && !empty($level->expiration_number) && pmpro_hasMembershipLevel($level->id, $user_id))
59
- {
60
- //get the current enddate of their membership
61
- $user_level = pmpro_getMembershipLevelForUser($user_id);
62
- $expiration_date = $user_level->enddate;
63
64
- //calculate days left
65
- $todays_date = current_time('timestamp');
66
$time_left = $expiration_date - $todays_date;
67
68
- //time left?
69
- if($time_left > 0)
70
- {
71
- //convert to days and add to the expiration date (assumes expiration was 1 year)
72
- $days_left = floor($time_left/(60*60*24));
73
74
- //figure out days based on period
75
- if($level->expiration_period == "Day")
76
$total_days = $days_left + $level->expiration_number;
77
- elseif($level->expiration_period == "Week")
78
$total_days = $days_left + $level->expiration_number * 7;
79
- elseif($level->expiration_period == "Month")
80
$total_days = $days_left + $level->expiration_number * 30;
81
- elseif($level->expiration_period == "Year")
82
$total_days = $days_left + $level->expiration_number * 365;
83
84
- //update number and period
85
$level->expiration_number = $total_days;
86
- $level->expiration_period = "Day";
87
}
88
}
89
90
return $level;
91
}
92
- add_filter("pmpro_ipnhandler_level", "pmpro_ipnhandler_level_extend_memberships", 10, 2);
93
94
/*
95
If checking out for the same level, keep your old startdate.
96
Added with 1.5.5
97
*/
98
- function pmpro_checkout_start_date_keep_startdate($startdate, $user_id, $level)
99
- {
100
- if(pmpro_hasMembershipLevel($level->id, $user_id))
101
- {
102
global $wpdb;
103
- $sqlQuery = "SELECT startdate FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . esc_sql($user_id) . "' AND membership_id = '" . esc_sql($level->id) . "' AND status = 'active' ORDER BY id DESC LIMIT 1";
104
- $old_startdate = $wpdb->get_var($sqlQuery);
105
-
106
- if(!empty($old_startdate))
107
$startdate = "'" . $old_startdate . "'";
108
}
109
-
110
return $startdate;
111
}
112
- add_filter("pmpro_checkout_start_date", "pmpro_checkout_start_date_keep_startdate", 10, 3);
113
114
/*
115
Stripe Lite Pulled into Core Plugin
116
*/
117
- //Stripe Lite, Set the Globals/etc
118
- $stripe_billingaddress = pmpro_getOption("stripe_billingaddress");
119
- if(empty($stripe_billingaddress))
120
- {
121
global $pmpro_stripe_lite;
122
$pmpro_stripe_lite = true;
123
- add_filter("pmpro_stripe_lite", "__return_true");
124
- add_filter("pmpro_required_billing_fields", "pmpro_required_billing_fields_stripe_lite");
125
}
126
127
- //Stripe Lite, Don't Require Billing Fields
128
- function pmpro_required_billing_fields_stripe_lite($fields)
129
- {
130
global $gateway;
131
-
132
- //ignore if not using stripe
133
- if($gateway != "stripe")
134
return $fields;
135
-
136
- //some fields to remove
137
- $remove = array('bfirstname', 'blastname', 'baddress1', 'bcity', 'bstate', 'bzipcode', 'bphone', 'bcountry', 'CardType');
138
-
139
- //if a user is logged in, don't require bemail either
140
global $current_user;
141
- if(!empty($current_user->user_email))
142
$remove[] = 'bemail';
143
-
144
- //remove the fields
145
- foreach($remove as $field)
146
- unset($fields[$field]);
147
-
148
- //ship it!
149
return $fields;
150
}
151
152
- //copy other discount code to discount code if latter is not set
153
- if(empty($_REQUEST['discount_code']) && !empty($_REQUEST['other_discount_code']))
154
- {
155
$_REQUEST['discount_code'] = $_REQUEST['other_discount_code'];
156
$_POST['discount_code'] = $_POST['other_discount_code'];
157
$_GET['discount_code'] = $_GET['other_discount_code'];
158
}
159
160
- //apply all the_content filters to confirmation messages for levels
161
- function pmpro_pmpro_confirmation_message($message) {
162
- return apply_filters('the_content', $message);
163
}
164
- add_filter('pmpro_confirmation_message', 'pmpro_pmpro_confirmation_message');
165
166
- //apply all the_content filters to level descriptions
167
- function pmpro_pmpro_level_description($description) {
168
- return apply_filters('the_content', $description);
169
}
170
- add_filter('pmpro_level_description', 'pmpro_pmpro_level_description');
171
172
/*
173
PayPal doesn't allow start dates > 1 year out.
174
So if we detect that, let's try to squeeze some of
175
that time into a trial.
176
-
177
Otherwise, let's cap at 1 year out.
178
-
179
Note that this affects PayPal Standard as well, but the fix
180
for that flavor of PayPal is different and may be included in future
181
updates.
182
*/
183
- function pmpro_pmpro_subscribe_order_startdate_limit($order, $gateway) {
184
- $affected_gateways = array('paypalexpress', 'paypal');
185
-
186
- if(in_array($gateway->gateway, $affected_gateways)) {
187
- $original_start_date = strtotime($order->ProfileStartDate, current_time('timestamp'));
188
- $one_year_out = strtotime('+1 Year', current_time('timestamp'));
189
- $two_years_out = strtotime('+2 Year', current_time('timestamp'));
190
- $one_year_out_date = date_i18n('Y-m-d', $one_year_out) . 'T0:0:0';
191
- if(!empty($order->ProfileStartDate) && $order->ProfileStartDate > $one_year_out_date) {
192
- //try to squeeze into the trial
193
- if(empty($order->TrialBillingPeriod)) {
194
- //update the order
195
$order->TrialAmount = 0;
196
$order->TrialBillingPeriod = 'Day';
197
- $order->TrialBillingFrequency = min(365, strtotime($order->ProfileStartDate, current_time('timestamp')));
198
$order->TrialBillingCycles = 1;
199
}
200
-
201
- //max out at 1 year out no matter what
202
$order->ProfileStartDate = $one_year_out_date;
203
-
204
- //if we were going to try to push it more than 2 years out, let's notify the admin
205
- if(!empty($order->TrialBillilngPeriod) || $original_start_date > $two_years_out) {
206
- //setup user data
207
global $current_user;
208
- if(empty($order->user_id))
209
$order->user_id = $current_user->ID;
210
$order->getUser();
211
-
212
- //get level data
213
- $level = pmpro_getLevel($order->membership_id);
214
-
215
- //create email
216
$pmproemail = new PMProEmail();
217
- $body = '<p>' . __("There was a potential issue while setting the 'Profile Start Date' for a user's subscription at checkout. PayPal does not allow one to set a Profile Start Date further than 1 year out. Typically, this is not an issue, but sometimes a combination of custom code or add ons for PMPro (e.g. the Prorating or Auto-renewal Checkbox add ons) will try to set a Profile Start Date out past 1 year in order to respect an existing user's original expiration date before they checked out. The user's information is below. PMPro has allowed the checkout and simply restricted the Profile Start Date to 1 year out with a possible additional free Trial of up to 1 year. You should double check this information to determine if maybe the user has overpaid or otherwise needs to be addressed. If you get many of these emails, you should consider adjusting your custom code to avoid these situations.", 'paid-memberships-pro') . '</p>';
218
- $body .= '<p>' . sprintf(__("User: %s<br />Email: %s<br />Membership Level: %s<br />Order #: %s<br />Original Profile Start Date: %s<br />Adjusted Profile Start Date: %s<br />Trial Period: %s<br />Trial Frequency: %s<br />", 'paid-memberships-pro'), $order->user->user_nicename, $order->user->user_email, $level->name, $order->code, date('c', $original_start_date), $one_year_out_date, $order->TrialBillingPeriod, $order->TrialBillingFrequency) . '</p>';
219
$pmproemail->template = 'profile_start_date_limit_check';
220
- $pmproemail->subject = sprintf(__('Profile Start Date Issue Detected and Fixed at %s', 'paid-memberships-pro'), get_bloginfo('name'));
221
- $pmproemail->data = array('body'=>$body);
222
- $pmproemail->sendEmail(get_bloginfo("admin_email"));
223
}
224
}
225
}
226
-
227
return $order;
228
}
229
- add_filter('pmpro_subscribe_order', 'pmpro_pmpro_subscribe_order_startdate_limit', 99, 2);
230
7
If checking out for the same level, add remaining days to the enddate.
8
Pulled in from: https://gist.github.com/3678054
9
*/
10
+ function pmpro_checkout_level_extend_memberships( $level ) {
11
global $pmpro_msg, $pmpro_msgt;
12
13
+ // does this level expire? are they an existing user of this level?
14
+ if ( ! empty( $level ) && ! empty( $level->expiration_number ) && pmpro_hasMembershipLevel( $level->id ) ) {
15
+ // get the current enddate of their membership
16
global $current_user;
17
+ $user_level = pmpro_getSpecificMembershipLevelForUser( $current_user->ID, $level->id );
18
19
+ // bail if their existing level doesn't have an end date
20
+ if ( empty( $user_level ) || empty( $user_level->enddate ) ) {
21
+ return $level;
22
+ }
23
+
24
+ // calculate days left
25
+ $todays_date = current_time( 'timestamp' );
26
+ $expiration_date = $user_level->enddate;
27
$time_left = $expiration_date - $todays_date;
28
29
+ // time left?
30
+ if ( $time_left > 0 ) {
31
+ // convert to days and add to the expiration date (assumes expiration was 1 year)
32
+ $days_left = floor( $time_left / ( 60 * 60 * 24 ) );
33
34
+ // figure out days based on period
35
+ if ( $level->expiration_period == 'Day' ) {
36
$total_days = $days_left + $level->expiration_number;
37
+ } elseif ( $level->expiration_period == 'Week' ) {
38
$total_days = $days_left + $level->expiration_number * 7;
39
+ } elseif ( $level->expiration_period == 'Month' ) {
40
$total_days = $days_left + $level->expiration_number * 30;
41
+ } elseif ( $level->expiration_period == 'Year' ) {
42
$total_days = $days_left + $level->expiration_number * 365;
43
+ }
44
45
+ // update number and period
46
$level->expiration_number = $total_days;
47
+ $level->expiration_period = 'Day';
48
}
49
}
50
51
return $level;
52
}
53
+ add_filter( 'pmpro_checkout_level', 'pmpro_checkout_level_extend_memberships' );
54
/*
55
Same thing as above but when processed by the ipnhandler for PayPal standard.
56
*/
57
+ function pmpro_ipnhandler_level_extend_memberships( $level, $user_id ) {
58
global $pmpro_msg, $pmpro_msgt;
59
60
+ // does this level expire? are they an existing user of this level?
61
+ if ( ! empty( $level ) && ! empty( $level->expiration_number ) && pmpro_hasMembershipLevel( $level->id, $user_id ) ) {
62
+ // get the current enddate of their membership
63
+ $user_level = pmpro_getSpecificMembershipLevelForUser( $current_user->ID, $level->id );
64
+
65
+ // bail if their existing level doesn't have an end date
66
+ if ( empty( $user_level ) || empty( $user_level->enddate ) ) {
67
+ return $level;
68
+ }
69
70
+ // calculate days left
71
+ $todays_date = current_time( 'timestamp' );
72
+ $expiration_date = $user_level->enddate;
73
$time_left = $expiration_date - $todays_date;
74
75
+ // time left?
76
+ if ( $time_left > 0 ) {
77
+ // convert to days and add to the expiration date (assumes expiration was 1 year)
78
+ $days_left = floor( $time_left / ( 60 * 60 * 24 ) );
79
80
+ // figure out days based on period
81
+ if ( $level->expiration_period == 'Day' ) {
82
$total_days = $days_left + $level->expiration_number;
83
+ } elseif ( $level->expiration_period == 'Week' ) {
84
$total_days = $days_left + $level->expiration_number * 7;
85
+ } elseif ( $level->expiration_period == 'Month' ) {
86
$total_days = $days_left + $level->expiration_number * 30;
87
+ } elseif ( $level->expiration_period == 'Year' ) {
88
$total_days = $days_left + $level->expiration_number * 365;
89
+ }
90
91
+ // update number and period
92
$level->expiration_number = $total_days;
93
+ $level->expiration_period = 'Day';
94
}
95
}
96
97
return $level;
98
}
99
+ add_filter( 'pmpro_ipnhandler_level', 'pmpro_ipnhandler_level_extend_memberships', 10, 2 );
100
101
/*
102
If checking out for the same level, keep your old startdate.
103
Added with 1.5.5
104
*/
105
+ function pmpro_checkout_start_date_keep_startdate( $startdate, $user_id, $level ) {
106
+ if ( pmpro_hasMembershipLevel( $level->id, $user_id ) ) {
107
global $wpdb;
108
+ $sqlQuery = "SELECT startdate FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . esc_sql( $user_id ) . "' AND membership_id = '" . esc_sql( $level->id ) . "' AND status = 'active' ORDER BY id DESC LIMIT 1";
109
+ $old_startdate = $wpdb->get_var( $sqlQuery );
110
+
111
+ if ( ! empty( $old_startdate ) ) {
112
$startdate = "'" . $old_startdate . "'";
113
+ }
114
}
115
+
116
return $startdate;
117
}
118
+ add_filter( 'pmpro_checkout_start_date', 'pmpro_checkout_start_date_keep_startdate', 10, 3 );
119
120
/*
121
Stripe Lite Pulled into Core Plugin
122
*/
123
+ // Stripe Lite, Set the Globals/etc
124
+ $stripe_billingaddress = pmpro_getOption( 'stripe_billingaddress' );
125
+ if ( empty( $stripe_billingaddress ) ) {
126
global $pmpro_stripe_lite;
127
$pmpro_stripe_lite = true;
128
+ add_filter( 'pmpro_stripe_lite', '__return_true' );
129
+ add_filter( 'pmpro_required_billing_fields', 'pmpro_required_billing_fields_stripe_lite' );
130
}
131
132
+ // Stripe Lite, Don't Require Billing Fields
133
+ function pmpro_required_billing_fields_stripe_lite( $fields ) {
134
global $gateway;
135
+
136
+ // ignore if not using stripe
137
+ if ( $gateway != 'stripe' ) {
138
return $fields;
139
+ }
140
+
141
+ // some fields to remove
142
+ $remove = array( 'bfirstname', 'blastname', 'baddress1', 'bcity', 'bstate', 'bzipcode', 'bphone', 'bcountry', 'CardType' );
143
+
144
+ // if a user is logged in, don't require bemail either
145
global $current_user;
146
+ if ( ! empty( $current_user->user_email ) ) {
147
$remove[] = 'bemail';
148
+ }
149
+
150
+ // remove the fields
151
+ foreach ( $remove as $field ) {
152
+ unset( $fields[ $field ] );
153
+ }
154
+
155
+ // ship it!
156
return $fields;
157
}
158
159
+ // copy other discount code to discount code if latter is not set
160
+ if ( empty( $_REQUEST['discount_code'] ) && ! empty( $_REQUEST['other_discount_code'] ) ) {
161
$_REQUEST['discount_code'] = $_REQUEST['other_discount_code'];
162
$_POST['discount_code'] = $_POST['other_discount_code'];
163
$_GET['discount_code'] = $_GET['other_discount_code'];
164
}
165
166
+ // apply all the_content filters to confirmation messages for levels
167
+ function pmpro_pmpro_confirmation_message( $message ) {
168
+ return apply_filters( 'the_content', $message );
169
}
170
+ add_filter( 'pmpro_confirmation_message', 'pmpro_pmpro_confirmation_message' );
171
172
+ // apply all the_content filters to level descriptions
173
+ function pmpro_pmpro_level_description( $description ) {
174
+ return apply_filters( 'the_content', $description );
175
}
176
+ add_filter( 'pmpro_level_description', 'pmpro_pmpro_level_description' );
177
178
/*
179
PayPal doesn't allow start dates > 1 year out.
180
So if we detect that, let's try to squeeze some of
181
that time into a trial.
182
+
183
Otherwise, let's cap at 1 year out.
184
+
185
Note that this affects PayPal Standard as well, but the fix
186
for that flavor of PayPal is different and may be included in future
187
updates.
188
*/
189
+ function pmpro_pmpro_subscribe_order_startdate_limit( $order, $gateway ) {
190
+ $affected_gateways = array( 'paypalexpress', 'paypal' );
191
+
192
+ if ( in_array( $gateway->gateway, $affected_gateways ) ) {
193
+ $original_start_date = strtotime( $order->ProfileStartDate, current_time( 'timestamp' ) );
194
+ $one_year_out = strtotime( '+1 Year', current_time( 'timestamp' ) );
195
+ $two_years_out = strtotime( '+2 Year', current_time( 'timestamp' ) );
196
+ $one_year_out_date = date_i18n( 'Y-m-d', $one_year_out ) . 'T0:0:0';
197
+ if ( ! empty( $order->ProfileStartDate ) && $order->ProfileStartDate > $one_year_out_date ) {
198
+ // try to squeeze into the trial
199
+ if ( empty( $order->TrialBillingPeriod ) ) {
200
+ // update the order
201
$order->TrialAmount = 0;
202
$order->TrialBillingPeriod = 'Day';
203
+ $order->TrialBillingFrequency = min( 365, strtotime( $order->ProfileStartDate, current_time( 'timestamp' ) ) );
204
$order->TrialBillingCycles = 1;
205
}
206
+
207
+ // max out at 1 year out no matter what
208
$order->ProfileStartDate = $one_year_out_date;
209
+
210
+ // if we were going to try to push it more than 2 years out, let's notify the admin
211