Passed
Push — master ( 86cae5...efe1c2 )
by Brian
10:40
created
includes/wpinv-item-functions.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
62
-			'page'       => 1,
63
-			'exclude'    => array(),
64
-			'orderby'    => 'date',
65
-			'order'      => 'DESC',
66
-			'type'       => wpinv_item_types(),
67
-			'meta_query' => array(
60
+            'status'     => array( 'publish' ),
61
+            'limit'      => get_option( 'posts_per_page' ),
62
+            'page'       => 1,
63
+            'exclude'    => array(),
64
+            'orderby'    => 'date',
65
+            'order'      => 'DESC',
66
+            'type'       => wpinv_item_types(),
67
+            'meta_query' => array(
68 68
                 array(
69 69
                     'key'     => '_wpinv_one_time',
70 70
                     'compare' => 'NOT EXISTS',
71 71
                 ),
72 72
             ),
73
-			'return'     => 'objects',
74
-			'paginate'   => false,
73
+            'return'     => 'objects',
74
+            'paginate'   => false,
75 75
         )
76 76
     );
77 77
 
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 
212 212
 function wpinv_get_item_types() {
213 213
     $item_types = array(
214
-		'custom' => __( 'Standard', 'invoicing' ),
215
-		'fee'    => __( 'Fee', 'invoicing' ),
216
-	);
214
+        'custom' => __( 'Standard', 'invoicing' ),
215
+        'fee'    => __( 'Fee', 'invoicing' ),
216
+    );
217 217
     return apply_filters( 'wpinv_get_item_types', $item_types );
218 218
 }
219 219
 
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
     $args = array();
256 256
     if ( $post_ids ) {
257 257
         $args = array(
258
-			'fields' => 'ids',
259
-		);
258
+            'fields' => 'ids',
259
+        );
260 260
     }
261 261
 
262 262
     $args = array_merge(
263 263
         $args,
264 264
         array(
265 265
             'post_type'  => 'wpi_item',
266
-			'orderby'    => 'rand',
267
-			'post_count' => $num,
266
+            'orderby'    => 'rand',
267
+            'post_count' => $num,
268 268
             'meta_query' => array(
269 269
                 array(
270 270
                     'key'     => '_wpinv_one_time',
@@ -439,10 +439,10 @@  discard block
 block discarded – undo
439 439
     $bill_times_less = $bill_times - 1;
440 440
 
441 441
     if ( ! empty( $bill_times ) ) {
442
-		$bill_times = $item->get_recurring_interval() * $bill_times;
442
+        $bill_times = $item->get_recurring_interval() * $bill_times;
443 443
         $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
444
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
445
-	}
444
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
445
+    }
446 446
 
447 447
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
448 448
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
Please login to merge, or discard this patch.
invoicing.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.7.9' );
26
+    define( 'WPINV_VERSION', '2.7.9' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array(
28 28
         'subscription',
29 29
         'sandbox',
@@ -36,44 +36,44 @@  discard block
 block discarded – undo
36 36
     );
37 37
 
38 38
     /**
39
-	 * Payment method order.
40
-	 *
41
-	 * @var int
42
-	 */
39
+     * Payment method order.
40
+     *
41
+     * @var int
42
+     */
43 43
     public $order = 4;
44 44
 
45 45
     /**
46
-	 * Endpoint for requests from Authorize.net.
47
-	 *
48
-	 * @var string
49
-	 */
50
-	protected $notify_url;
51
-
52
-	/**
53
-	 * Endpoint for requests to Authorize.net.
54
-	 *
55
-	 * @var string
56
-	 */
46
+     * Endpoint for requests from Authorize.net.
47
+     *
48
+     * @var string
49
+     */
50
+    protected $notify_url;
51
+
52
+    /**
53
+     * Endpoint for requests to Authorize.net.
54
+     *
55
+     * @var string
56
+     */
57 57
     protected $endpoint;
58 58
 
59 59
     /**
60
-	 * Currencies this gateway is allowed for.
61
-	 *
62
-	 * @var array
63
-	 */
64
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
60
+     * Currencies this gateway is allowed for.
61
+     *
62
+     * @var array
63
+     */
64
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
65 65
 
66 66
     /**
67
-	 * URL to view a transaction.
68
-	 *
69
-	 * @var string
70
-	 */
67
+     * URL to view a transaction.
68
+     *
69
+     * @var string
70
+     */
71 71
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
72 72
 
73 73
     /**
74
-	 * Class constructor.
75
-	 */
76
-	public function __construct() {
74
+     * Class constructor.
75
+     */
76
+    public function __construct() {
77 77
 
78 78
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
79 79
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Displays the payment method select field.
89
-	 *
90
-	 * @param int $invoice_id 0 or invoice id.
91
-	 * @param GetPaid_Payment_Form $form Current payment form.
92
-	 */
88
+     * Displays the payment method select field.
89
+     *
90
+     * @param int $invoice_id 0 or invoice id.
91
+     * @param GetPaid_Payment_Form $form Current payment form.
92
+     */
93 93
     public function payment_fields( $invoice_id, $form ) {
94 94
 
95 95
         // Let the user select a payment method.
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
     }
101 101
 
102 102
     /**
103
-	 * Creates a customer profile.
104
-	 *
105
-	 *
106
-	 * @param WPInv_Invoice $invoice Invoice.
103
+     * Creates a customer profile.
104
+     *
105
+     *
106
+     * @param WPInv_Invoice $invoice Invoice.
107 107
      * @param array $submission_data Posted checkout fields.
108 108
      * @param bool $save Whether or not to save the payment as a token.
109 109
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
110
-	 * @return string|WP_Error Payment profile id.
111
-	 */
112
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
110
+     * @return string|WP_Error Payment profile id.
111
+     */
112
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
113 113
 
114 114
         // Remove non-digits from the number
115 115
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Retrieves a customer profile.
195
-	 *
196
-	 *
197
-	 * @param string $profile_id profile id.
198
-	 * @return string|WP_Error Profile id.
194
+     * Retrieves a customer profile.
195
+     *
196
+     *
197
+     * @param string $profile_id profile id.
198
+     * @return string|WP_Error Profile id.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
200
-	 */
201
-	public function get_customer_profile( $profile_id ) {
200
+     */
201
+    public function get_customer_profile( $profile_id ) {
202 202
 
203 203
         // Generate args.
204 204
         $args = array(
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
     }
214 214
 
215 215
     /**
216
-	 * Creates a customer profile.
217
-	 *
218
-	 *
216
+     * Creates a customer profile.
217
+     *
218
+     *
219 219
      * @param string $profile_id profile id.
220
-	 * @param WPInv_Invoice $invoice Invoice.
220
+     * @param WPInv_Invoice $invoice Invoice.
221 221
      * @param array $submission_data Posted checkout fields.
222 222
      * @param bool $save Whether or not to save the payment as a token.
223 223
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
224
-	 * @return string|WP_Error Profile id.
225
-	 */
226
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
224
+     * @return string|WP_Error Profile id.
225
+     */
226
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
227 227
 
228 228
         // Remove non-digits from the number
229 229
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
     }
312 312
 
313 313
     /**
314
-	 * Retrieves payment details from cache.
315
-	 *
316
-	 *
314
+     * Retrieves payment details from cache.
315
+     *
316
+     *
317 317
      * @param array $payment_details.
318
-	 * @return array|false Profile id.
319
-	 */
320
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
318
+     * @return array|false Profile id.
319
+     */
320
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
321 321
 
322 322
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
323 323
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
     }
343 343
 
344 344
     /**
345
-	 * Securely adds payment details to cache.
346
-	 *
347
-	 *
345
+     * Securely adds payment details to cache.
346
+     *
347
+     *
348 348
      * @param array $payment_details.
349 349
      * @param string $payment_profile_id.
350
-	 */
351
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
350
+     */
351
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
352 352
 
353 353
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
354 354
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
     }
361 361
 
362 362
     /**
363
-	 * Retrieves a customer payment profile.
364
-	 *
365
-	 *
366
-	 * @param string $customer_profile_id customer profile id.
363
+     * Retrieves a customer payment profile.
364
+     *
365
+     *
366
+     * @param string $customer_profile_id customer profile id.
367 367
      * @param string $payment_profile_id payment profile id.
368
-	 * @return string|WP_Error Profile id.
368
+     * @return string|WP_Error Profile id.
369 369
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
370
-	 */
371
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
370
+     */
371
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
372 372
 
373 373
         // Generate args.
374 374
         $args = array(
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
     }
385 385
 
386 386
     /**
387
-	 * Charges a customer payment profile.
388
-	 *
387
+     * Charges a customer payment profile.
388
+     *
389 389
      * @param string $customer_profile_id customer profile id.
390 390
      * @param string $payment_profile_id payment profile id.
391
-	 * @param WPInv_Invoice $invoice Invoice.
391
+     * @param WPInv_Invoice $invoice Invoice.
392 392
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
393
-	 * @return WP_Error|object
394
-	 */
395
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
393
+     * @return WP_Error|object
394
+     */
395
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
396 396
 
397 397
         // Generate args.
398 398
         $args = array(
@@ -438,43 +438,43 @@  discard block
 block discarded – undo
438 438
     }
439 439
 
440 440
     /**
441
-	 * Processes a customer charge.
442
-	 *
441
+     * Processes a customer charge.
442
+     *
443 443
      * @param stdClass $result Api response.
444
-	 * @param WPInv_Invoice $invoice Invoice.
445
-	 */
446
-	public function process_charge_response( $result, $invoice ) {
444
+     * @param WPInv_Invoice $invoice Invoice.
445
+     */
446
+    public function process_charge_response( $result, $invoice ) {
447 447
 
448 448
         wpinv_clear_errors();
449
-		$response_code = (int) $result->transactionResponse->responseCode;
449
+        $response_code = (int) $result->transactionResponse->responseCode;
450 450
 
451 451
         $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true );
452 452
 
453
-		// Succeeded.
454
-		if ( 1 == $response_code || 4 == $response_code ) {
453
+        // Succeeded.
454
+        if ( 1 == $response_code || 4 == $response_code ) {
455 455
 
456
-			// Maybe set a transaction id.
457
-			if ( ! empty( $result->transactionResponse->transId ) ) {
458
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
459
-			}
456
+            // Maybe set a transaction id.
457
+            if ( ! empty( $result->transactionResponse->transId ) ) {
458
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
459
+            }
460 460
 
461
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
461
+            $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
462 462
 
463
-			if ( 1 == $response_code ) {
464
-				return $invoice->mark_paid();
465
-			}
463
+            if ( 1 == $response_code ) {
464
+                return $invoice->mark_paid();
465
+            }
466 466
 
467
-			$invoice->set_status( 'wpi-onhold' );
468
-        	$invoice->add_note(
467
+            $invoice->set_status( 'wpi-onhold' );
468
+            $invoice->add_note(
469 469
                 sprintf(
470 470
                     __( 'Held for review: %s', 'invoicing' ),
471 471
                     $result->transactionResponse->messages->message[0]->description
472 472
                 )
473
-			);
473
+            );
474 474
 
475
-			return $invoice->save();
475
+            return $invoice->save();
476 476
 
477
-		}
477
+        }
478 478
 
479 479
         wpinv_set_error( 'card_declined' );
480 480
 
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
     }
487 487
 
488 488
     /**
489
-	 * Returns payment information.
490
-	 *
491
-	 *
492
-	 * @param array $card Card details.
493
-	 * @return array
494
-	 */
495
-	public function get_payment_information( $card ) {
489
+     * Returns payment information.
490
+     *
491
+     *
492
+     * @param array $card Card details.
493
+     * @return array
494
+     */
495
+    public function get_payment_information( $card ) {
496 496
         return array(
497 497
 
498 498
             'creditCard' => array(
@@ -505,25 +505,25 @@  discard block
 block discarded – undo
505 505
     }
506 506
 
507 507
     /**
508
-	 * Returns the customer profile meta name.
509
-	 *
510
-	 *
511
-	 * @param WPInv_Invoice $invoice Invoice.
512
-	 * @return string
513
-	 */
514
-	public function get_customer_profile_meta_name( $invoice ) {
508
+     * Returns the customer profile meta name.
509
+     *
510
+     *
511
+     * @param WPInv_Invoice $invoice Invoice.
512
+     * @return string
513
+     */
514
+    public function get_customer_profile_meta_name( $invoice ) {
515 515
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
516 516
     }
517 517
 
518 518
     /**
519
-	 * Validates the submitted data.
520
-	 *
521
-	 *
522
-	 * @param array $submission_data Posted checkout fields.
519
+     * Validates the submitted data.
520
+     *
521
+     *
522
+     * @param array $submission_data Posted checkout fields.
523 523
      * @param WPInv_Invoice $invoice
524
-	 * @return WP_Error|string The payment profile id
525
-	 */
526
-	public function validate_submission_data( $submission_data, $invoice ) {
524
+     * @return WP_Error|string The payment profile id
525
+     */
526
+    public function validate_submission_data( $submission_data, $invoice ) {
527 527
 
528 528
         // Validate authentication details.
529 529
         $auth = $this->get_auth_params();
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
     }
556 556
 
557 557
     /**
558
-	 * Returns invoice line items.
559
-	 *
560
-	 *
561
-	 * @param WPInv_Invoice $invoice Invoice.
562
-	 * @return array
563
-	 */
564
-	public function get_line_items( $invoice ) {
558
+     * Returns invoice line items.
559
+     *
560
+     *
561
+     * @param WPInv_Invoice $invoice Invoice.
562
+     * @return array
563
+     */
564
+    public function get_line_items( $invoice ) {
565 565
         $items = array();
566 566
 
567 567
         foreach ( $invoice->get_items() as $item ) {
@@ -598,15 +598,15 @@  discard block
 block discarded – undo
598 598
     }
599 599
 
600 600
     /**
601
-	 * Process Payment.
602
-	 *
603
-	 *
604
-	 * @param WPInv_Invoice $invoice Invoice.
605
-	 * @param array $submission_data Posted checkout fields.
606
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
-	 * @return array
608
-	 */
609
-	public function process_payment( $invoice, $submission_data, $submission ) {
601
+     * Process Payment.
602
+     *
603
+     *
604
+     * @param WPInv_Invoice $invoice Invoice.
605
+     * @param array $submission_data Posted checkout fields.
606
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
+     * @return array
608
+     */
609
+    public function process_payment( $invoice, $submission_data, $submission ) {
610 610
 
611 611
         // Validate the submitted data.
612 612
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -639,45 +639,45 @@  discard block
 block discarded – undo
639 639
 
640 640
         exit;
641 641
 
642
-	}
642
+    }
643 643
 
644
-	/**
645
-	 * Processes the initial payment.
646
-	 *
644
+    /**
645
+     * Processes the initial payment.
646
+     *
647 647
      * @param WPInv_Invoice $invoice Invoice.
648
-	 */
649
-	protected function process_initial_payment( $invoice ) {
648
+     */
649
+    protected function process_initial_payment( $invoice ) {
650 650
 
651
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
651
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
652 652
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
653
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
653
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
654 654
 
655
-		// Do we have an error?
656
-		if ( is_wp_error( $result ) ) {
657
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
-			wpinv_send_back_to_checkout( $invoice );
659
-		}
655
+        // Do we have an error?
656
+        if ( is_wp_error( $result ) ) {
657
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
+            wpinv_send_back_to_checkout( $invoice );
659
+        }
660 660
 
661
-		// Process the response.
662
-		$this->process_charge_response( $result, $invoice );
661
+        // Process the response.
662
+        $this->process_charge_response( $result, $invoice );
663 663
 
664
-		if ( wpinv_get_errors() ) {
665
-			wpinv_send_back_to_checkout( $invoice );
666
-		}
664
+        if ( wpinv_get_errors() ) {
665
+            wpinv_send_back_to_checkout( $invoice );
666
+        }
667 667
 
668
-	}
668
+    }
669 669
 
670 670
     /**
671
-	 * Processes recurring payments.
672
-	 *
671
+     * Processes recurring payments.
672
+     *
673 673
      * @param WPInv_Invoice $invoice Invoice.
674 674
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
675
-	 */
676
-	public function process_subscription( $invoice, $subscriptions ) {
675
+     */
676
+    public function process_subscription( $invoice, $subscriptions ) {
677 677
 
678 678
         // Check if there is an initial amount to charge.
679 679
         if ( (float) $invoice->get_total() > 0 ) {
680
-			$this->process_initial_payment( $invoice );
680
+            $this->process_initial_payment( $invoice );
681 681
         }
682 682
 
683 683
         // Activate the subscriptions.
@@ -695,36 +695,36 @@  discard block
 block discarded – undo
695 695
             }
696 696
         }
697 697
 
698
-		// Redirect to the success page.
698
+        // Redirect to the success page.
699 699
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
700 700
 
701 701
     }
702 702
 
703
-	/**
704
-	 * (Maybe) renews an authorize.net subscription profile.
705
-	 *
706
-	 *
703
+    /**
704
+     * (Maybe) renews an authorize.net subscription profile.
705
+     *
706
+     *
707 707
      * @param WPInv_Subscription $subscription
708
-	 */
709
-	public function maybe_renew_subscription( $subscription ) {
708
+     */
709
+    public function maybe_renew_subscription( $subscription ) {
710 710
 
711 711
         // Ensure its our subscription && it's active.
712 712
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
713 713
             $this->renew_subscription( $subscription );
714 714
         }
715 715
 
716
-	}
716
+    }
717 717
 
718 718
     /**
719
-	 * Renews a subscription.
720
-	 *
719
+     * Renews a subscription.
720
+     *
721 721
      * @param WPInv_Subscription $subscription
722
-	 */
723
-	public function renew_subscription( $subscription ) {
722
+     */
723
+    public function renew_subscription( $subscription ) {
724 724
 
725
-		// Generate the renewal invoice.
726
-		$new_invoice = $subscription->create_payment();
727
-		$old_invoice = $subscription->get_parent_payment();
725
+        // Generate the renewal invoice.
726
+        $new_invoice = $subscription->create_payment();
727
+        $old_invoice = $subscription->get_parent_payment();
728 728
 
729 729
         if ( empty( $new_invoice ) ) {
730 730
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -733,37 +733,37 @@  discard block
 block discarded – undo
733 733
         }
734 734
 
735 735
         // Charge the payment method.
736
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
-
740
-		// Do we have an error?
741
-		if ( is_wp_error( $result ) ) {
742
-
743
-			$old_invoice->add_note(
744
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
-				true,
746
-				false,
747
-				true
748
-			);
749
-			$subscription->failing();
750
-			return;
751
-
752
-		}
753
-
754
-		// Process the response.
755
-		$this->process_charge_response( $result, $new_invoice );
756
-
757
-		if ( wpinv_get_errors() ) {
758
-
759
-			$old_invoice->add_note(
760
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
-				true,
762
-				false,
763
-				true
764
-			);
765
-			$subscription->failing();
766
-			return;
736
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
+
740
+        // Do we have an error?
741
+        if ( is_wp_error( $result ) ) {
742
+
743
+            $old_invoice->add_note(
744
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
+                true,
746
+                false,
747
+                true
748
+            );
749
+            $subscription->failing();
750
+            return;
751
+
752
+        }
753
+
754
+        // Process the response.
755
+        $this->process_charge_response( $result, $new_invoice );
756
+
757
+        if ( wpinv_get_errors() ) {
758
+
759
+            $old_invoice->add_note(
760
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
+                true,
762
+                false,
763
+                true
764
+            );
765
+            $subscription->failing();
766
+            return;
767 767
 
768 768
         }
769 769
 
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
     }
777 777
 
778 778
     /**
779
-	 * Processes invoice addons.
780
-	 *
781
-	 * @param WPInv_Invoice $invoice
782
-	 * @param GetPaid_Form_Item[] $items
783
-	 * @return WPInv_Invoice
784
-	 */
785
-	public function process_addons( $invoice, $items ) {
779
+     * Processes invoice addons.
780
+     *
781
+     * @param WPInv_Invoice $invoice
782
+     * @param GetPaid_Form_Item[] $items
783
+     * @return WPInv_Invoice
784
+     */
785
+    public function process_addons( $invoice, $items ) {
786 786
 
787 787
         global $getpaid_authorize_addons;
788 788
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         $invoice->recalculate_total();
802 802
 
803 803
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
804
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
804
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
805 805
 
806 806
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
807 807
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
     }
817 817
 
818 818
     /**
819
-	 * Processes invoice addons.
820
-	 *
819
+     * Processes invoice addons.
820
+     *
821 821
      * @param array $args
822
-	 * @return array
823
-	 */
822
+     * @return array
823
+     */
824 824
     public function filter_addons_request( $args ) {
825 825
 
826 826
         global $getpaid_authorize_addons;
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
     }
855 855
 
856 856
     /**
857
-	 * Filters the gateway settings.
858
-	 *
859
-	 * @param array $admin_settings
860
-	 */
861
-	public function admin_settings( $admin_settings ) {
857
+     * Filters the gateway settings.
858
+     *
859
+     * @param array $admin_settings
860
+     */
861
+    public function admin_settings( $admin_settings ) {
862 862
 
863 863
         $currencies = sprintf(
864 864
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             'readonly' => true,
899 899
         );
900 900
 
901
-		return $admin_settings;
902
-	}
901
+        return $admin_settings;
902
+    }
903 903
 
904 904
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Indentation   +1051 added lines, -1051 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id',
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id',
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,42 +141,42 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		$caches = array(
159
-			'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(),
160
-			'getpaid_subscription_transaction_ids_to_subscription_ids'    => $this->get_transaction_id(),
161
-			'getpaid_subscription_profile_ids_to_subscription_ids'        => $this->get_profile_id(),
162
-			'getpaid_subscriptions'                                       => $this->get_id(),
163
-		);
164
-
165
-		foreach ( $caches as $cache => $value ) {
166
-			if ( '' !== $value && false !== $value ) {
167
-				wp_cache_delete( $value, $cache );
168
-			}
169
-		}
170
-	}
171
-
172
-	/**
158
+        $caches = array(
159
+            'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(),
160
+            'getpaid_subscription_transaction_ids_to_subscription_ids'    => $this->get_transaction_id(),
161
+            'getpaid_subscription_profile_ids_to_subscription_ids'        => $this->get_profile_id(),
162
+            'getpaid_subscriptions'                                       => $this->get_id(),
163
+        );
164
+
165
+        foreach ( $caches as $cache => $value ) {
166
+            if ( '' !== $value && false !== $value ) {
167
+                wp_cache_delete( $value, $cache );
168
+            }
169
+        }
170
+    }
171
+
172
+    /**
173 173
      * Checks if a subscription key is set.
174 174
      */
175 175
     public function _isset( $key ) {
176 176
         return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
177
-	}
177
+    }
178 178
 
179
-	/*
179
+    /*
180 180
 	|--------------------------------------------------------------------------
181 181
 	| CRUD methods
182 182
 	|--------------------------------------------------------------------------
@@ -185,544 +185,544 @@  discard block
 block discarded – undo
185 185
 	|
186 186
     */
187 187
 
188
-	/*
188
+    /*
189 189
 	|--------------------------------------------------------------------------
190 190
 	| Getters
191 191
 	|--------------------------------------------------------------------------
192 192
 	*/
193 193
 
194
-	/**
195
-	 * Get customer id.
196
-	 *
197
-	 * @since 1.0.19
198
-	 * @param  string $context View or edit context.
199
-	 * @return int
200
-	 */
201
-	public function get_customer_id( $context = 'view' ) {
202
-		return (int) $this->get_prop( 'customer_id', $context );
203
-	}
204
-
205
-	/**
206
-	 * Get customer information.
207
-	 *
208
-	 * @since 1.0.19
209
-	 * @param  string $context View or edit context.
210
-	 * @return WP_User|false WP_User object on success, false on failure.
211
-	 */
212
-	public function get_customer( $context = 'view' ) {
213
-		return get_userdata( $this->get_customer_id( $context ) );
214
-	}
215
-
216
-	/**
217
-	 * Get parent invoice id.
218
-	 *
219
-	 * @since 1.0.19
220
-	 * @param  string $context View or edit context.
221
-	 * @return int
222
-	 */
223
-	public function get_parent_invoice_id( $context = 'view' ) {
224
-		return (int) $this->get_prop( 'parent_payment_id', $context );
225
-	}
226
-
227
-	/**
228
-	 * Alias for self::get_parent_invoice_id().
229
-	 *
230
-	 * @since 1.0.19
231
-	 * @param  string $context View or edit context.
232
-	 * @return int
233
-	 */
194
+    /**
195
+     * Get customer id.
196
+     *
197
+     * @since 1.0.19
198
+     * @param  string $context View or edit context.
199
+     * @return int
200
+     */
201
+    public function get_customer_id( $context = 'view' ) {
202
+        return (int) $this->get_prop( 'customer_id', $context );
203
+    }
204
+
205
+    /**
206
+     * Get customer information.
207
+     *
208
+     * @since 1.0.19
209
+     * @param  string $context View or edit context.
210
+     * @return WP_User|false WP_User object on success, false on failure.
211
+     */
212
+    public function get_customer( $context = 'view' ) {
213
+        return get_userdata( $this->get_customer_id( $context ) );
214
+    }
215
+
216
+    /**
217
+     * Get parent invoice id.
218
+     *
219
+     * @since 1.0.19
220
+     * @param  string $context View or edit context.
221
+     * @return int
222
+     */
223
+    public function get_parent_invoice_id( $context = 'view' ) {
224
+        return (int) $this->get_prop( 'parent_payment_id', $context );
225
+    }
226
+
227
+    /**
228
+     * Alias for self::get_parent_invoice_id().
229
+     *
230
+     * @since 1.0.19
231
+     * @param  string $context View or edit context.
232
+     * @return int
233
+     */
234 234
     public function get_parent_payment_id( $context = 'view' ) {
235 235
         return $this->get_parent_invoice_id( $context );
236
-	}
236
+    }
237
+
238
+    /**
239
+     * Alias for self::get_parent_invoice_id().
240
+     *
241
+     * @since  1.0.0
242
+     * @return int
243
+     */
244
+    public function get_original_payment_id( $context = 'view' ) {
245
+        return $this->get_parent_invoice_id( $context );
246
+    }
247
+
248
+    /**
249
+     * Get parent invoice.
250
+     *
251
+     * @since 1.0.19
252
+     * @param  string $context View or edit context.
253
+     * @return WPInv_Invoice
254
+     */
255
+    public function get_parent_invoice( $context = 'view' ) {
256
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
257
+    }
258
+
259
+    /**
260
+     * Alias for self::get_parent_invoice().
261
+     *
262
+     * @since 1.0.19
263
+     * @param  string $context View or edit context.
264
+     * @return WPInv_Invoice
265
+     */
266
+    public function get_parent_payment( $context = 'view' ) {
267
+        return $this->get_parent_invoice( $context );
268
+    }
269
+
270
+    /**
271
+     * Get subscription's product id.
272
+     *
273
+     * @since 1.0.19
274
+     * @param  string $context View or edit context.
275
+     * @return int
276
+     */
277
+    public function get_product_id( $context = 'view' ) {
278
+        return (int) $this->get_prop( 'product_id', $context );
279
+    }
280
+
281
+    /**
282
+     * Get the subscription product.
283
+     *
284
+     * @since 1.0.19
285
+     * @param  string $context View or edit context.
286
+     * @return WPInv_Item
287
+     */
288
+    public function get_product( $context = 'view' ) {
289
+        return new WPInv_Item( $this->get_product_id( $context ) );
290
+    }
291
+
292
+    /**
293
+     * Get parent invoice's gateway.
294
+     *
295
+     * Here for backwards compatibility.
296
+     *
297
+     * @since 1.0.19
298
+     * @param  string $context View or edit context.
299
+     * @return string
300
+     */
301
+    public function get_gateway( $context = 'view' ) {
302
+        return $this->get_parent_invoice( $context )->get_gateway();
303
+    }
304
+
305
+    /**
306
+     * Get the period of a renewal.
307
+     *
308
+     * @since 1.0.19
309
+     * @param  string $context View or edit context.
310
+     * @return string
311
+     */
312
+    public function get_period( $context = 'view' ) {
313
+        return $this->get_prop( 'period', $context );
314
+    }
315
+
316
+    /**
317
+     * Get number of periods each renewal is valid for.
318
+     *
319
+     * @since 1.0.19
320
+     * @param  string $context View or edit context.
321
+     * @return int
322
+     */
323
+    public function get_frequency( $context = 'view' ) {
324
+        return (int) $this->get_prop( 'frequency', $context );
325
+    }
326
+
327
+    /**
328
+     * Get the initial amount for the subscription.
329
+     *
330
+     * @since 1.0.19
331
+     * @param  string $context View or edit context.
332
+     * @return float
333
+     */
334
+    public function get_initial_amount( $context = 'view' ) {
335
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
336
+    }
337
+
338
+    /**
339
+     * Get the recurring amount for the subscription.
340
+     *
341
+     * @since 1.0.19
342
+     * @param  string $context View or edit context.
343
+     * @return float
344
+     */
345
+    public function get_recurring_amount( $context = 'view' ) {
346
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
347
+    }
348
+
349
+    /**
350
+     * Get number of times that this subscription can be renewed.
351
+     *
352
+     * @since 1.0.19
353
+     * @param  string $context View or edit context.
354
+     * @return int
355
+     */
356
+    public function get_bill_times( $context = 'view' ) {
357
+        return (int) $this->get_prop( 'bill_times', $context );
358
+    }
359
+
360
+    /**
361
+     * Get transaction id of this subscription's parent invoice.
362
+     *
363
+     * @since 1.0.19
364
+     * @param  string $context View or edit context.
365
+     * @return string
366
+     */
367
+    public function get_transaction_id( $context = 'view' ) {
368
+        return $this->get_prop( 'transaction_id', $context );
369
+    }
370
+
371
+    /**
372
+     * Get the date that the subscription was created.
373
+     *
374
+     * @since 1.0.19
375
+     * @param  string $context View or edit context.
376
+     * @return string
377
+     */
378
+    public function get_created( $context = 'view' ) {
379
+        return $this->get_prop( 'created', $context );
380
+    }
381
+
382
+    /**
383
+     * Alias for self::get_created().
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $context View or edit context.
387
+     * @return string
388
+     */
389
+    public function get_date_created( $context = 'view' ) {
390
+        return $this->get_created( $context );
391
+    }
392
+
393
+    /**
394
+     * Retrieves the creation date in a timestamp
395
+     *
396
+     * @since  1.0.0
397
+     * @return int
398
+     */
399
+    public function get_time_created() {
400
+        $created = $this->get_date_created();
401
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
402
+    }
403
+
404
+    /**
405
+     * Get GMT date when the subscription was created.
406
+     *
407
+     * @since 1.0.19
408
+     * @param  string $context View or edit context.
409
+     * @return string
410
+     */
411
+    public function get_date_created_gmt( $context = 'view' ) {
412
+        $date = $this->get_date_created( $context );
413
+
414
+        if ( $date ) {
415
+            $date = get_gmt_from_date( $date );
416
+        }
417
+        return $date;
418
+    }
419
+
420
+    /**
421
+     * Get the date that the subscription will renew.
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return string
426
+     */
427
+    public function get_next_renewal_date( $context = 'view' ) {
428
+        return $this->get_prop( 'expiration', $context );
429
+    }
430
+
431
+    /**
432
+     * Alias for self::get_next_renewal_date().
433
+     *
434
+     * @since 1.0.19
435
+     * @param  string $context View or edit context.
436
+     * @return string
437
+     */
438
+    public function get_expiration( $context = 'view' ) {
439
+        return $this->get_next_renewal_date( $context );
440
+    }
441
+
442
+    /**
443
+     * Retrieves the expiration date in a timestamp
444
+     *
445
+     * @since  1.0.0
446
+     * @return int
447
+     */
448
+    public function get_expiration_time() {
449
+        $expiration = $this->get_expiration();
450
+
451
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
+            return current_time( 'timestamp' );
453
+        }
454
+
455
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
457
+    }
458
+
459
+    /**
460
+     * Get GMT date when the subscription will renew.
461
+     *
462
+     * @since 1.0.19
463
+     * @param  string $context View or edit context.
464
+     * @return string
465
+     */
466
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
467
+        $date = $this->get_next_renewal_date( $context );
468
+
469
+        if ( $date ) {
470
+            $date = get_gmt_from_date( $date );
471
+        }
472
+        return $date;
473
+    }
474
+
475
+    /**
476
+     * Get the subscription's trial period.
477
+     *
478
+     * @since 1.0.19
479
+     * @param  string $context View or edit context.
480
+     * @return string
481
+     */
482
+    public function get_trial_period( $context = 'view' ) {
483
+        return $this->get_prop( 'trial_period', $context );
484
+    }
485
+
486
+    /**
487
+     * Get the subscription's status.
488
+     *
489
+     * @since 1.0.19
490
+     * @param  string $context View or edit context.
491
+     * @return string
492
+     */
493
+    public function get_status( $context = 'view' ) {
494
+        return $this->get_prop( 'status', $context );
495
+    }
496
+
497
+    /**
498
+     * Get the subscription's profile id.
499
+     *
500
+     * @since 1.0.19
501
+     * @param  string $context View or edit context.
502
+     * @return string
503
+     */
504
+    public function get_profile_id( $context = 'view' ) {
505
+        return $this->get_prop( 'profile_id', $context );
506
+    }
507
+
508
+    /*
509
+	|--------------------------------------------------------------------------
510
+	| Setters
511
+	|--------------------------------------------------------------------------
512
+	*/
513
+
514
+    /**
515
+     * Set customer id.
516
+     *
517
+     * @since 1.0.19
518
+     * @param  int $value The customer's id.
519
+     */
520
+    public function set_customer_id( $value ) {
521
+        $this->set_prop( 'customer_id', (int) $value );
522
+    }
523
+
524
+    /**
525
+     * Set parent invoice id.
526
+     *
527
+     * @since 1.0.19
528
+     * @param  int $value The parent invoice id.
529
+     */
530
+    public function set_parent_invoice_id( $value ) {
531
+        $this->set_prop( 'parent_payment_id', (int) $value );
532
+    }
533
+
534
+    /**
535
+     * Alias for self::set_parent_invoice_id().
536
+     *
537
+     * @since 1.0.19
538
+     * @param  int $value The parent invoice id.
539
+     */
540
+    public function set_parent_payment_id( $value ) {
541
+        $this->set_parent_invoice_id( $value );
542
+    }
543
+
544
+    /**
545
+     * Alias for self::set_parent_invoice_id().
546
+     *
547
+     * @since 1.0.19
548
+     * @param  int $value The parent invoice id.
549
+     */
550
+    public function set_original_payment_id( $value ) {
551
+        $this->set_parent_invoice_id( $value );
552
+    }
553
+
554
+    /**
555
+     * Set subscription's product id.
556
+     *
557
+     * @since 1.0.19
558
+     * @param  int $value The subscription product id.
559
+     */
560
+    public function set_product_id( $value ) {
561
+        $this->set_prop( 'product_id', (int) $value );
562
+    }
563
+
564
+    /**
565
+     * Set the period of a renewal.
566
+     *
567
+     * @since 1.0.19
568
+     * @param  string $value The renewal period.
569
+     */
570
+    public function set_period( $value ) {
571
+        $this->set_prop( 'period', $value );
572
+    }
573
+
574
+    /**
575
+     * Set number of periods each renewal is valid for.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  int $value The subscription frequency.
579
+     */
580
+    public function set_frequency( $value ) {
581
+        $value = empty( $value ) ? 1 : (int) $value;
582
+        $this->set_prop( 'frequency', absint( $value ) );
583
+    }
584
+
585
+    /**
586
+     * Set the initial amount for the subscription.
587
+     *
588
+     * @since 1.0.19
589
+     * @param  float $value The initial subcription amount.
590
+     */
591
+    public function set_initial_amount( $value ) {
592
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
593
+    }
594
+
595
+    /**
596
+     * Set the recurring amount for the subscription.
597
+     *
598
+     * @since 1.0.19
599
+     * @param  float $value The recurring subcription amount.
600
+     */
601
+    public function set_recurring_amount( $value ) {
602
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
603
+    }
604
+
605
+    /**
606
+     * Set number of times that this subscription can be renewed.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  int $value Bill times.
610
+     */
611
+    public function set_bill_times( $value ) {
612
+        $this->set_prop( 'bill_times', (int) $value );
613
+    }
614
+
615
+    /**
616
+     * Get transaction id of this subscription's parent invoice.
617
+     *
618
+     * @since 1.0.19
619
+     * @param string $value Bill times.
620
+     */
621
+    public function set_transaction_id( $value ) {
622
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
623
+    }
624
+
625
+    /**
626
+     * Set date when this subscription started.
627
+     *
628
+     * @since 1.0.19
629
+     * @param string $value strtotime compliant date.
630
+     */
631
+    public function set_created( $value ) {
632
+        $date = strtotime( $value );
633
+
634
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
+            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
636
+            return;
637
+        }
638
+
639
+        $this->set_prop( 'created', '' );
640
+
641
+    }
237 642
 
238
-	/**
239
-     * Alias for self::get_parent_invoice_id().
643
+    /**
644
+     * Alias for self::set_created().
240 645
      *
241
-     * @since  1.0.0
242
-     * @return int
646
+     * @since 1.0.19
647
+     * @param string $value strtotime compliant date.
243 648
      */
244
-    public function get_original_payment_id( $context = 'view' ) {
245
-        return $this->get_parent_invoice_id( $context );
649
+    public function set_date_created( $value ) {
650
+        $this->set_created( $value );
246 651
     }
247 652
 
248
-	/**
249
-	 * Get parent invoice.
250
-	 *
251
-	 * @since 1.0.19
252
-	 * @param  string $context View or edit context.
253
-	 * @return WPInv_Invoice
254
-	 */
255
-	public function get_parent_invoice( $context = 'view' ) {
256
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
257
-	}
258
-
259
-	/**
260
-	 * Alias for self::get_parent_invoice().
261
-	 *
262
-	 * @since 1.0.19
263
-	 * @param  string $context View or edit context.
264
-	 * @return WPInv_Invoice
265
-	 */
266
-    public function get_parent_payment( $context = 'view' ) {
267
-        return $this->get_parent_invoice( $context );
268
-	}
269
-
270
-	/**
271
-	 * Get subscription's product id.
272
-	 *
273
-	 * @since 1.0.19
274
-	 * @param  string $context View or edit context.
275
-	 * @return int
276
-	 */
277
-	public function get_product_id( $context = 'view' ) {
278
-		return (int) $this->get_prop( 'product_id', $context );
279
-	}
280
-
281
-	/**
282
-	 * Get the subscription product.
283
-	 *
284
-	 * @since 1.0.19
285
-	 * @param  string $context View or edit context.
286
-	 * @return WPInv_Item
287
-	 */
288
-	public function get_product( $context = 'view' ) {
289
-		return new WPInv_Item( $this->get_product_id( $context ) );
290
-	}
291
-
292
-	/**
293
-	 * Get parent invoice's gateway.
294
-	 *
295
-	 * Here for backwards compatibility.
296
-	 *
297
-	 * @since 1.0.19
298
-	 * @param  string $context View or edit context.
299
-	 * @return string
300
-	 */
301
-	public function get_gateway( $context = 'view' ) {
302
-		return $this->get_parent_invoice( $context )->get_gateway();
303
-	}
304
-
305
-	/**
306
-	 * Get the period of a renewal.
307
-	 *
308
-	 * @since 1.0.19
309
-	 * @param  string $context View or edit context.
310
-	 * @return string
311
-	 */
312
-	public function get_period( $context = 'view' ) {
313
-		return $this->get_prop( 'period', $context );
314
-	}
315
-
316
-	/**
317
-	 * Get number of periods each renewal is valid for.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @param  string $context View or edit context.
321
-	 * @return int
322
-	 */
323
-	public function get_frequency( $context = 'view' ) {
324
-		return (int) $this->get_prop( 'frequency', $context );
325
-	}
326
-
327
-	/**
328
-	 * Get the initial amount for the subscription.
329
-	 *
330
-	 * @since 1.0.19
331
-	 * @param  string $context View or edit context.
332
-	 * @return float
333
-	 */
334
-	public function get_initial_amount( $context = 'view' ) {
335
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
336
-	}
337
-
338
-	/**
339
-	 * Get the recurring amount for the subscription.
340
-	 *
341
-	 * @since 1.0.19
342
-	 * @param  string $context View or edit context.
343
-	 * @return float
344
-	 */
345
-	public function get_recurring_amount( $context = 'view' ) {
346
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
347
-	}
348
-
349
-	/**
350
-	 * Get number of times that this subscription can be renewed.
351
-	 *
352
-	 * @since 1.0.19
353
-	 * @param  string $context View or edit context.
354
-	 * @return int
355
-	 */
356
-	public function get_bill_times( $context = 'view' ) {
357
-		return (int) $this->get_prop( 'bill_times', $context );
358
-	}
359
-
360
-	/**
361
-	 * Get transaction id of this subscription's parent invoice.
362
-	 *
363
-	 * @since 1.0.19
364
-	 * @param  string $context View or edit context.
365
-	 * @return string
366
-	 */
367
-	public function get_transaction_id( $context = 'view' ) {
368
-		return $this->get_prop( 'transaction_id', $context );
369
-	}
370
-
371
-	/**
372
-	 * Get the date that the subscription was created.
373
-	 *
374
-	 * @since 1.0.19
375
-	 * @param  string $context View or edit context.
376
-	 * @return string
377
-	 */
378
-	public function get_created( $context = 'view' ) {
379
-		return $this->get_prop( 'created', $context );
380
-	}
381
-
382
-	/**
383
-	 * Alias for self::get_created().
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $context View or edit context.
387
-	 * @return string
388
-	 */
389
-	public function get_date_created( $context = 'view' ) {
390
-		return $this->get_created( $context );
391
-	}
392
-
393
-	/**
394
-	 * Retrieves the creation date in a timestamp
395
-	 *
396
-	 * @since  1.0.0
397
-	 * @return int
398
-	 */
399
-	public function get_time_created() {
400
-		$created = $this->get_date_created();
401
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
402
-	}
403
-
404
-	/**
405
-	 * Get GMT date when the subscription was created.
406
-	 *
407
-	 * @since 1.0.19
408
-	 * @param  string $context View or edit context.
409
-	 * @return string
410
-	 */
411
-	public function get_date_created_gmt( $context = 'view' ) {
412
-        $date = $this->get_date_created( $context );
653
+    /**
654
+     * Set the date that the subscription will renew.
655
+     *
656
+     * @since 1.0.19
657
+     * @param string $value strtotime compliant date.
658
+     */
659
+    public function set_next_renewal_date( $value ) {
660
+        $date = strtotime( $value );
413 661
 
414
-        if ( $date ) {
415
-            $date = get_gmt_from_date( $date );
662
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
+            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
664
+            return;
416 665
         }
417
-		return $date;
418
-	}
419
-
420
-	/**
421
-	 * Get the date that the subscription will renew.
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return string
426
-	 */
427
-	public function get_next_renewal_date( $context = 'view' ) {
428
-		return $this->get_prop( 'expiration', $context );
429
-	}
430
-
431
-	/**
432
-	 * Alias for self::get_next_renewal_date().
433
-	 *
434
-	 * @since 1.0.19
435
-	 * @param  string $context View or edit context.
436
-	 * @return string
437
-	 */
438
-	public function get_expiration( $context = 'view' ) {
439
-		return $this->get_next_renewal_date( $context );
440
-	}
441
-
442
-	/**
443
-	 * Retrieves the expiration date in a timestamp
444
-	 *
445
-	 * @since  1.0.0
446
-	 * @return int
447
-	 */
448
-	public function get_expiration_time() {
449
-		$expiration = $this->get_expiration();
450
-
451
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
-			return current_time( 'timestamp' );
453
-		}
454
-
455
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
457
-	}
458
-
459
-	/**
460
-	 * Get GMT date when the subscription will renew.
461
-	 *
462
-	 * @since 1.0.19
463
-	 * @param  string $context View or edit context.
464
-	 * @return string
465
-	 */
466
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
467
-        $date = $this->get_next_renewal_date( $context );
468 666
 
469
-        if ( $date ) {
470
-            $date = get_gmt_from_date( $date );
471
-        }
472
-		return $date;
473
-	}
474
-
475
-	/**
476
-	 * Get the subscription's trial period.
477
-	 *
478
-	 * @since 1.0.19
479
-	 * @param  string $context View or edit context.
480
-	 * @return string
481
-	 */
482
-	public function get_trial_period( $context = 'view' ) {
483
-		return $this->get_prop( 'trial_period', $context );
484
-	}
485
-
486
-	/**
487
-	 * Get the subscription's status.
488
-	 *
489
-	 * @since 1.0.19
490
-	 * @param  string $context View or edit context.
491
-	 * @return string
492
-	 */
493
-	public function get_status( $context = 'view' ) {
494
-		return $this->get_prop( 'status', $context );
495
-	}
496
-
497
-	/**
498
-	 * Get the subscription's profile id.
499
-	 *
500
-	 * @since 1.0.19
501
-	 * @param  string $context View or edit context.
502
-	 * @return string
503
-	 */
504
-	public function get_profile_id( $context = 'view' ) {
505
-		return $this->get_prop( 'profile_id', $context );
506
-	}
507
-
508
-	/*
509
-	|--------------------------------------------------------------------------
510
-	| Setters
511
-	|--------------------------------------------------------------------------
512
-	*/
667
+        $this->set_prop( 'expiration', '' );
513 668
 
514
-	/**
515
-	 * Set customer id.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param  int $value The customer's id.
519
-	 */
520
-	public function set_customer_id( $value ) {
521
-		$this->set_prop( 'customer_id', (int) $value );
522
-	}
523
-
524
-	/**
525
-	 * Set parent invoice id.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param  int $value The parent invoice id.
529
-	 */
530
-	public function set_parent_invoice_id( $value ) {
531
-		$this->set_prop( 'parent_payment_id', (int) $value );
532
-	}
533
-
534
-	/**
535
-	 * Alias for self::set_parent_invoice_id().
536
-	 *
537
-	 * @since 1.0.19
538
-	 * @param  int $value The parent invoice id.
539
-	 */
540
-    public function set_parent_payment_id( $value ) {
541
-        $this->set_parent_invoice_id( $value );
542
-	}
669
+    }
543 670
 
544
-	/**
545
-     * Alias for self::set_parent_invoice_id().
671
+    /**
672
+     * Alias for self::set_next_renewal_date().
546 673
      *
547 674
      * @since 1.0.19
548
-	 * @param  int $value The parent invoice id.
675
+     * @param string $value strtotime compliant date.
549 676
      */
550
-    public function set_original_payment_id( $value ) {
551
-        $this->set_parent_invoice_id( $value );
552
-	}
553
-
554
-	/**
555
-	 * Set subscription's product id.
556
-	 *
557
-	 * @since 1.0.19
558
-	 * @param  int $value The subscription product id.
559
-	 */
560
-	public function set_product_id( $value ) {
561
-		$this->set_prop( 'product_id', (int) $value );
562
-	}
563
-
564
-	/**
565
-	 * Set the period of a renewal.
566
-	 *
567
-	 * @since 1.0.19
568
-	 * @param  string $value The renewal period.
569
-	 */
570
-	public function set_period( $value ) {
571
-		$this->set_prop( 'period', $value );
572
-	}
573
-
574
-	/**
575
-	 * Set number of periods each renewal is valid for.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  int $value The subscription frequency.
579
-	 */
580
-	public function set_frequency( $value ) {
581
-		$value = empty( $value ) ? 1 : (int) $value;
582
-		$this->set_prop( 'frequency', absint( $value ) );
583
-	}
584
-
585
-	/**
586
-	 * Set the initial amount for the subscription.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param  float $value The initial subcription amount.
590
-	 */
591
-	public function set_initial_amount( $value ) {
592
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
593
-	}
594
-
595
-	/**
596
-	 * Set the recurring amount for the subscription.
597
-	 *
598
-	 * @since 1.0.19
599
-	 * @param  float $value The recurring subcription amount.
600
-	 */
601
-	public function set_recurring_amount( $value ) {
602
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
603
-	}
604
-
605
-	/**
606
-	 * Set number of times that this subscription can be renewed.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  int $value Bill times.
610
-	 */
611
-	public function set_bill_times( $value ) {
612
-		$this->set_prop( 'bill_times', (int) $value );
613
-	}
614
-
615
-	/**
616
-	 * Get transaction id of this subscription's parent invoice.
617
-	 *
618
-	 * @since 1.0.19
619
-	 * @param string $value Bill times.
620
-	 */
621
-	public function set_transaction_id( $value ) {
622
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
623
-	}
624
-
625
-	/**
626
-	 * Set date when this subscription started.
627
-	 *
628
-	 * @since 1.0.19
629
-	 * @param string $value strtotime compliant date.
630
-	 */
631
-	public function set_created( $value ) {
632
-        $date = strtotime( $value );
677
+    public function set_expiration( $value ) {
678
+        $this->set_next_renewal_date( $value );
679
+    }
633 680
 
634
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
-            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
681
+    /**
682
+     * Set the subscription's trial period.
683
+     *
684
+     * @since 1.0.19
685
+     * @param string $value trial period e.g 1 year.
686
+     */
687
+    public function set_trial_period( $value ) {
688
+        $this->set_prop( 'trial_period', $value );
689
+    }
690
+
691
+    /**
692
+     * Set the subscription's status.
693
+     *
694
+     * @since 1.0.19
695
+     * @param string $new_status    New subscription status.
696
+     */
697
+    public function set_status( $new_status ) {
698
+
699
+        // Abort if this is not a valid status;
700
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
636 701
             return;
637 702
         }
638 703
 
639
-		$this->set_prop( 'created', '' );
640
-
641
-	}
704
+        $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
+        if ( true === $this->object_read && $old_status !== $new_status ) {
706
+            $this->status_transition = array(
707
+                'from' => $old_status,
708
+                'to'   => $new_status,
709
+            );
710
+        }
642 711
 
643
-	/**
644
-	 * Alias for self::set_created().
645
-	 *
646
-	 * @since 1.0.19
647
-	 * @param string $value strtotime compliant date.
648
-	 */
649
-	public function set_date_created( $value ) {
650
-		$this->set_created( $value );
712
+        $this->set_prop( 'status', $new_status );
651 713
     }
652 714
 
653
-	/**
654
-	 * Set the date that the subscription will renew.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @param string $value strtotime compliant date.
658
-	 */
659
-	public function set_next_renewal_date( $value ) {
660
-		$date = strtotime( $value );
715
+    /**
716
+     * Set the subscription's (remote) profile id.
717
+     *
718
+     * @since 1.0.19
719
+     * @param  string $value the remote profile id.
720
+     */
721
+    public function set_profile_id( $value ) {
722
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
723
+    }
661 724
 
662
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
-            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
664
-            return;
665
-		}
666
-
667
-		$this->set_prop( 'expiration', '' );
668
-
669
-	}
670
-
671
-	/**
672
-	 * Alias for self::set_next_renewal_date().
673
-	 *
674
-	 * @since 1.0.19
675
-	 * @param string $value strtotime compliant date.
676
-	 */
677
-	public function set_expiration( $value ) {
678
-		$this->set_next_renewal_date( $value );
679
-    }
680
-
681
-	/**
682
-	 * Set the subscription's trial period.
683
-	 *
684
-	 * @since 1.0.19
685
-	 * @param string $value trial period e.g 1 year.
686
-	 */
687
-	public function set_trial_period( $value ) {
688
-		$this->set_prop( 'trial_period', $value );
689
-	}
690
-
691
-	/**
692
-	 * Set the subscription's status.
693
-	 *
694
-	 * @since 1.0.19
695
-	 * @param string $new_status    New subscription status.
696
-	 */
697
-	public function set_status( $new_status ) {
698
-
699
-		// Abort if this is not a valid status;
700
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
701
-			return;
702
-		}
703
-
704
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
-		if ( true === $this->object_read && $old_status !== $new_status ) {
706
-			$this->status_transition = array(
707
-				'from' => $old_status,
708
-				'to'   => $new_status,
709
-			);
710
-		}
711
-
712
-		$this->set_prop( 'status', $new_status );
713
-	}
714
-
715
-	/**
716
-	 * Set the subscription's (remote) profile id.
717
-	 *
718
-	 * @since 1.0.19
719
-	 * @param  string $value the remote profile id.
720
-	 */
721
-	public function set_profile_id( $value ) {
722
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
723
-	}
724
-
725
-	/*
725
+    /*
726 726
 	|--------------------------------------------------------------------------
727 727
 	| Boolean methods
728 728
 	|--------------------------------------------------------------------------
@@ -731,55 +731,55 @@  discard block
 block discarded – undo
731 731
 	|
732 732
 	*/
733 733
 
734
-	/**
734
+    /**
735 735
      * Checks if the subscription has a given status.
736
-	 *
737
-	 * @param string|array String or array of strings to check for.
738
-	 * @return bool
736
+     *
737
+     * @param string|array String or array of strings to check for.
738
+     * @return bool
739 739
      */
740 740
     public function has_status( $status ) {
741 741
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
742
-	}
742
+    }
743 743
 
744
-	/**
744
+    /**
745 745
      * Checks if the subscription has a trial period.
746
-	 *
747
-	 * @return bool
746
+     *
747
+     * @return bool
748 748
      */
749 749
     public function has_trial_period() {
750
-		$period = $this->get_trial_period();
750
+        $period = $this->get_trial_period();
751 751
         return ! empty( $period );
752
-	}
753
-
754
-	/**
755
-	 * Is the subscription active?
756
-	 *
757
-	 * @return bool
758
-	 */
759
-	public function is_active() {
760
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
761
-	}
762
-
763
-	/**
764
-	 * Is the subscription expired?
765
-	 *
766
-	 * @return bool
767
-	 */
768
-	public function is_expired() {
769
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
770
-	}
771
-
772
-	/**
773
-	 * Is this the last renewals?
774
-	 *
775
-	 * @return bool
776
-	 */
777
-	public function is_last_renewal() {
778
-		$max_bills = $this->get_bill_times();
779
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
780
-	}
781
-
782
-	/*
752
+    }
753
+
754
+    /**
755
+     * Is the subscription active?
756
+     *
757
+     * @return bool
758
+     */
759
+    public function is_active() {
760
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
761
+    }
762
+
763
+    /**
764
+     * Is the subscription expired?
765
+     *
766
+     * @return bool
767
+     */
768
+    public function is_expired() {
769
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
770
+    }
771
+
772
+    /**
773
+     * Is this the last renewals?
774
+     *
775
+     * @return bool
776
+     */
777
+    public function is_last_renewal() {
778
+        $max_bills = $this->get_bill_times();
779
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
780
+    }
781
+
782
+    /*
783 783
 	|--------------------------------------------------------------------------
784 784
 	| Additional methods
785 785
 	|--------------------------------------------------------------------------
@@ -788,27 +788,27 @@  discard block
 block discarded – undo
788 788
 	|
789 789
 	*/
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function create( $data = array() ) {
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function create( $data = array() ) {
795 795
 
796
-		// Set the properties.
797
-		if ( is_array( $data ) ) {
798
-			$this->set_props( $data );
799
-		}
796
+        // Set the properties.
797
+        if ( is_array( $data ) ) {
798
+            $this->set_props( $data );
799
+        }
800 800
 
801
-		// Save the item.
802
-		return $this->save();
801
+        // Save the item.
802
+        return $this->save();
803 803
 
804
-	}
804
+    }
805 805
 
806
-	/**
807
-	 * Backwards compatibilty.
808
-	 */
809
-	public function update( $args = array() ) {
810
-		return $this->create( $args );
811
-	}
806
+    /**
807
+     * Backwards compatibilty.
808
+     */
809
+    public function update( $args = array() ) {
810
+        return $this->create( $args );
811
+    }
812 812
 
813 813
     /**
814 814
      * Retrieve renewal payments for a subscription
@@ -818,22 +818,22 @@  discard block
 block discarded – undo
818 818
      */
819 819
     public function get_child_payments( $hide_pending = true ) {
820 820
 
821
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
821
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
822 822
 
823
-		if ( ! $hide_pending ) {
824
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
825
-		}
823
+        if ( ! $hide_pending ) {
824
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
825
+        }
826 826
 
827 827
         return get_posts(
828
-			array(
829
-            	'post_parent' => $this->get_parent_payment_id(),
830
-            	'numberposts' => -1,
831
-            	'post_status' => $statuses,
832
-            	'orderby'     => 'ID',
833
-            	'order'       => 'ASC',
834
-            	'post_type'   => 'wpi_invoice',
835
-			)
836
-		);
828
+            array(
829
+                'post_parent' => $this->get_parent_payment_id(),
830
+                'numberposts' => -1,
831
+                'post_status' => $statuses,
832
+                'orderby'     => 'ID',
833
+                'order'       => 'ASC',
834
+                'post_type'   => 'wpi_invoice',
835
+            )
836
+        );
837 837
     }
838 838
 
839 839
     /**
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
      * @return int
844 844
      */
845 845
     public function get_total_payments() {
846
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
846
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
847 847
     }
848 848
 
849 849
     /**
@@ -867,192 +867,192 @@  discard block
 block discarded – undo
867 867
      *
868 868
      * @since  2.4
869 869
      * @param  array $args Array of values for the payment, including amount and transaction ID
870
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
870
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873 873
     public function add_payment( $args = array(), $invoice = false ) {
874 874
 
875
-		// Process each payment once.
875
+        // Process each payment once.
876 876
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
877 877
             return false;
878 878
         }
879 879
 
880
-		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
882
-			$invoice = $this->create_payment( false );
880
+        // Are we creating a new invoice?
881
+        if ( empty( $invoice ) ) {
882
+            $invoice = $this->create_payment( false );
883 883
 
884
-			if ( empty( $invoice ) ) {
885
-				return false;
886
-			}
887
-		}
884
+            if ( empty( $invoice ) ) {
885
+                return false;
886
+            }
887
+        }
888 888
 
889
-		// Maybe set a transaction id.
890
-		if ( ! empty( $args['transaction_id'] ) ) {
891
-			$invoice->set_transaction_id( $args['transaction_id'] );
892
-		}
889
+        // Maybe set a transaction id.
890
+        if ( ! empty( $args['transaction_id'] ) ) {
891
+            $invoice->set_transaction_id( $args['transaction_id'] );
892
+        }
893 893
 
894
-		// Set the completed date.
895
-		$invoice->set_completed_date( current_time( 'mysql' ) );
894
+        // Set the completed date.
895
+        $invoice->set_completed_date( current_time( 'mysql' ) );
896 896
 
897
-		// And the gateway.
898
-		if ( ! empty( $args['gateway'] ) ) {
899
-			$invoice->set_gateway( $args['gateway'] );
900
-		}
897
+        // And the gateway.
898
+        if ( ! empty( $args['gateway'] ) ) {
899
+            $invoice->set_gateway( $args['gateway'] );
900
+        }
901 901
 
902
-		$invoice->set_status( 'wpi-renewal' );
903
-		$invoice->save();
902
+        $invoice->set_status( 'wpi-renewal' );
903
+        $invoice->save();
904 904
 
905
-		if ( ! $invoice->exists() ) {
906
-			return false;
907
-		}
905
+        if ( ! $invoice->exists() ) {
906
+            return false;
907
+        }
908 908
 
909
-		return $this->after_add_payment( $invoice );
910
-	}
909
+        return $this->after_add_payment( $invoice );
910
+    }
911 911
 
912 912
     public function after_add_payment( $invoice ) {
913 913
 
914
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
914
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
916 916
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
917 917
 
918 918
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
919 919
 
920 920
         return $invoice->get_id();
921
-	}
921
+    }
922 922
 
923
-	/**
923
+    /**
924 924
      * Creates a new invoice and returns it.
925 925
      *
926 926
      * @since  1.0.19
927
-	 * @param bool $save Whether we should save the invoice.
927
+     * @param bool $save Whether we should save the invoice.
928 928
      * @return WPInv_Invoice|bool
929 929
      */
930 930
     public function create_payment( $save = true ) {
931 931
 
932
-		$parent_invoice = $this->get_parent_payment();
933
-
934
-		if ( ! $parent_invoice->exists() ) {
935
-			return false;
936
-		}
937
-
938
-		// Duplicate the parent invoice.
939
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
940
-		$invoice->set_parent_id( $parent_invoice->get_id() );
941
-		$invoice->set_subscription_id( $this->get_id() );
942
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
943
-
944
-		// Set invoice items.
945
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
947
-		$invoice_items      = array();
948
-
949
-		foreach ( $invoice->get_items() as $item ) {
950
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
951
-				$invoice_items[] = $item;
952
-			}
953
-		}
954
-
955
-		$invoice->set_items( $invoice_items );
956
-
957
-		if ( ! empty( $subscription_group['fees'] ) ) {
958
-			$invoice->set_fees( $subscription_group['fees'] );
959
-		}
960
-
961
-		// Maybe recalculate discount (Pre-GetPaid Fix).
962
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
963
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
965
-		}
966
-
967
-		$invoice->recalculate_total();
968
-		$invoice->set_status( 'wpi-pending' );
969
-
970
-		if ( ! $save ) {
971
-			return $invoice;
972
-		}
973
-
974
-		$invoice->save();
975
-
976
-		return $invoice->exists() ? $invoice : false;
977
-    }
978
-
979
-	/**
980
-	 * Renews or completes a subscription
981
-	 *
982
-	 * @since  1.0.0
983
-	 * @return int The subscription's id
984
-	 */
985
-	public function renew( $calculate_from = null ) {
986
-
987
-		// Complete subscription if applicable
988
-		if ( $this->is_last_renewal() ) {
989
-			return $this->complete();
990
-		}
991
-
992
-		// Calculate new expiration
993
-		$frequency      = $this->get_frequency();
994
-		$period         = $this->get_period();
995
-		$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
-		$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
997
-
998
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
-		$this->set_status( 'active' );
1000
-		$this->save();
1001
-
1002
-		do_action( 'getpaid_subscription_renewed', $this );
1003
-
1004
-		return $this->get_id();
1005
-	}
1006
-
1007
-	/**
1008
-	 * Marks a subscription as completed
1009
-	 *
1010
-	 * Subscription is completed when the number of payments matches the billing_times field
1011
-	 *
1012
-	 * @since  1.0.0
1013
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
1014
-	 */
1015
-	public function complete() {
1016
-
1017
-		// Only mark a subscription as complete if it's not already cancelled.
1018
-		if ( $this->has_status( 'cancelled' ) ) {
1019
-			return false;
1020
-		}
1021
-
1022
-		$this->set_status( 'completed' );
1023
-		return $this->save();
1024
-
1025
-	}
1026
-
1027
-	/**
1028
-	 * Marks a subscription as expired
1029
-	 *
1030
-	 * @since  1.0.0
1031
-	 * @param  bool $check_expiration
1032
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033
-	 */
1034
-	public function expire( $check_expiration = false ) {
1035
-
1036
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1037
-			// Do not mark as expired since real expiration date is in the future
1038
-			return false;
1039
-		}
1040
-
1041
-		$this->set_status( 'expired' );
1042
-		return $this->save();
1043
-
1044
-	}
1045
-
1046
-	/**
1047
-	 * Marks a subscription as failing
1048
-	 *
1049
-	 * @since  2.4.2
1050
-	 * @return int Subscription id.
1051
-	 */
1052
-	public function failing() {
1053
-		$this->set_status( 'failing' );
1054
-		return $this->save();
1055
-	}
932
+        $parent_invoice = $this->get_parent_payment();
933
+
934
+        if ( ! $parent_invoice->exists() ) {
935
+            return false;
936
+        }
937
+
938
+        // Duplicate the parent invoice.
939
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
940
+        $invoice->set_parent_id( $parent_invoice->get_id() );
941
+        $invoice->set_subscription_id( $this->get_id() );
942
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
943
+
944
+        // Set invoice items.
945
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
947
+        $invoice_items      = array();
948
+
949
+        foreach ( $invoice->get_items() as $item ) {
950
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
951
+                $invoice_items[] = $item;
952
+            }
953
+        }
954
+
955
+        $invoice->set_items( $invoice_items );
956
+
957
+        if ( ! empty( $subscription_group['fees'] ) ) {
958
+            $invoice->set_fees( $subscription_group['fees'] );
959
+        }
960
+
961
+        // Maybe recalculate discount (Pre-GetPaid Fix).
962
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
963
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
965
+        }
966
+
967
+        $invoice->recalculate_total();
968
+        $invoice->set_status( 'wpi-pending' );
969
+
970
+        if ( ! $save ) {
971
+            return $invoice;
972
+        }
973
+
974
+        $invoice->save();
975
+
976
+        return $invoice->exists() ? $invoice : false;
977
+    }
978
+
979
+    /**
980
+     * Renews or completes a subscription
981
+     *
982
+     * @since  1.0.0
983
+     * @return int The subscription's id
984
+     */
985
+    public function renew( $calculate_from = null ) {
986
+
987
+        // Complete subscription if applicable
988
+        if ( $this->is_last_renewal() ) {
989
+            return $this->complete();
990
+        }
991
+
992
+        // Calculate new expiration
993
+        $frequency      = $this->get_frequency();
994
+        $period         = $this->get_period();
995
+        $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
+        $new_expiration = strtotime( "+ $frequency $period", $calculate_from );
997
+
998
+        $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
+        $this->set_status( 'active' );
1000
+        $this->save();
1001
+
1002
+        do_action( 'getpaid_subscription_renewed', $this );
1003
+
1004
+        return $this->get_id();
1005
+    }
1006
+
1007
+    /**
1008
+     * Marks a subscription as completed
1009
+     *
1010
+     * Subscription is completed when the number of payments matches the billing_times field
1011
+     *
1012
+     * @since  1.0.0
1013
+     * @return int|bool Subscription id or false if the subscription is cancelled.
1014
+     */
1015
+    public function complete() {
1016
+
1017
+        // Only mark a subscription as complete if it's not already cancelled.
1018
+        if ( $this->has_status( 'cancelled' ) ) {
1019
+            return false;
1020
+        }
1021
+
1022
+        $this->set_status( 'completed' );
1023
+        return $this->save();
1024
+
1025
+    }
1026
+
1027
+    /**
1028
+     * Marks a subscription as expired
1029
+     *
1030
+     * @since  1.0.0
1031
+     * @param  bool $check_expiration
1032
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033
+     */
1034
+    public function expire( $check_expiration = false ) {
1035
+
1036
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1037
+            // Do not mark as expired since real expiration date is in the future
1038
+            return false;
1039
+        }
1040
+
1041
+        $this->set_status( 'expired' );
1042
+        return $this->save();
1043
+
1044
+    }
1045
+
1046
+    /**
1047
+     * Marks a subscription as failing
1048
+     *
1049
+     * @since  2.4.2
1050
+     * @return int Subscription id.
1051
+     */
1052
+    public function failing() {
1053
+        $this->set_status( 'failing' );
1054
+        return $this->save();
1055
+    }
1056 1056
 
1057 1057
     /**
1058 1058
      * Marks a subscription as cancelled
@@ -1061,19 +1061,19 @@  discard block
 block discarded – undo
1061 1061
      * @return int Subscription id.
1062 1062
      */
1063 1063
     public function cancel() {
1064
-		$this->set_status( 'cancelled' );
1065
-		return $this->save();
1064
+        $this->set_status( 'cancelled' );
1065
+        return $this->save();
1066 1066
     }
1067 1067
 
1068
-	/**
1069
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1070
-	 *
1071
-	 * @since  1.0.0
1072
-	 * @return bool
1073
-	 */
1074
-	public function can_cancel() {
1075
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1076
-	}
1068
+    /**
1069
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1070
+     *
1071
+     * @since  1.0.0
1072
+     * @return bool
1073
+     */
1074
+    public function can_cancel() {
1075
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1076
+    }
1077 1077
 
1078 1078
     /**
1079 1079
      * Returns an array of subscription statuses that can be cancelled
@@ -1086,109 +1086,109 @@  discard block
 block discarded – undo
1086 1086
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1087 1087
     }
1088 1088
 
1089
-	/**
1090
-	 * Retrieves the URL to cancel subscription
1091
-	 *
1092
-	 * @since  1.0.0
1093
-	 * @return string
1094
-	 */
1095
-	public function get_cancel_url() {
1096
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1098
-	}
1099
-
1100
-	/**
1101
-	 * Retrieves the URL to view a subscription
1102
-	 *
1103
-	 * @since  1.0.19
1104
-	 * @return string
1105
-	 */
1106
-	public function get_view_url() {
1107
-
1108
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1110
-
1111
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1112
-	}
1113
-
1114
-	/**
1115
-	 * Determines if subscription can be manually renewed
1116
-	 *
1117
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1118
-	 * that can be renewed manually
1119
-	 *
1120
-	 * @since  2.5
1121
-	 * @return bool
1122
-	 */
1123
-	public function can_renew() {
1124
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1125
-	}
1126
-
1127
-	/**
1128
-	 * Retrieves the URL to renew a subscription
1129
-	 *
1130
-	 * @since  2.5
1131
-	 * @return string
1132
-	 */
1133
-	public function get_renew_url() {
1134
-		$url = wp_nonce_url(
1089
+    /**
1090
+     * Retrieves the URL to cancel subscription
1091
+     *
1092
+     * @since  1.0.0
1093
+     * @return string
1094
+     */
1095
+    public function get_cancel_url() {
1096
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1098
+    }
1099
+
1100
+    /**
1101
+     * Retrieves the URL to view a subscription
1102
+     *
1103
+     * @since  1.0.19
1104
+     * @return string
1105
+     */
1106
+    public function get_view_url() {
1107
+
1108
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1110
+
1111
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1112
+    }
1113
+
1114
+    /**
1115
+     * Determines if subscription can be manually renewed
1116
+     *
1117
+     * This method is filtered by payment gateways in order to return true on subscriptions
1118
+     * that can be renewed manually
1119
+     *
1120
+     * @since  2.5
1121
+     * @return bool
1122
+     */
1123
+    public function can_renew() {
1124
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1125
+    }
1126
+
1127
+    /**
1128
+     * Retrieves the URL to renew a subscription
1129
+     *
1130
+     * @since  2.5
1131
+     * @return string
1132
+     */
1133
+    public function get_renew_url() {
1134
+        $url = wp_nonce_url(
1135 1135
             add_query_arg(
1136 1136
                 array(
1137
-					'getpaid-action' => 'renew_subscription',
1138
-					'sub_id'         => $this->get_id,
1137
+                    'getpaid-action' => 'renew_subscription',
1138
+                    'sub_id'         => $this->get_id,
1139 1139
                 )
1140 1140
             ),
1141 1141
             'getpaid-nonce'
1142 1142
         );
1143
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1144
-	}
1145
-
1146
-	/**
1147
-	 * Determines if subscription can have their payment method updated
1148
-	 *
1149
-	 * @since  1.0.0
1150
-	 * @return bool
1151
-	 */
1152
-	public function can_update() {
1153
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1154
-	}
1155
-
1156
-	/**
1157
-	 * Retrieves the URL to update subscription
1158
-	 *
1159
-	 * @since  1.0.0
1160
-	 * @return string
1161
-	 */
1162
-	public function get_update_url() {
1163
-		$url = add_query_arg(
1143
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1144
+    }
1145
+
1146
+    /**
1147
+     * Determines if subscription can have their payment method updated
1148
+     *
1149
+     * @since  1.0.0
1150
+     * @return bool
1151
+     */
1152
+    public function can_update() {
1153
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1154
+    }
1155
+
1156
+    /**
1157
+     * Retrieves the URL to update subscription
1158
+     *
1159
+     * @since  1.0.0
1160
+     * @return string
1161
+     */
1162
+    public function get_update_url() {
1163
+        $url = add_query_arg(
1164 1164
             array(
1165
-				'action'          => 'update',
1166
-				'subscription_id' => $this->get_id(),
1165
+                'action'          => 'update',
1166
+                'subscription_id' => $this->get_id(),
1167 1167
             )
1168 1168
         );
1169
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1170
-	}
1171
-
1172
-	/**
1173
-	 * Retrieves the subscription status label
1174
-	 *
1175
-	 * @since  1.0.0
1176
-	 * @return string
1177
-	 */
1178
-	public function get_status_label() {
1179
-		return getpaid_get_subscription_status_label( $this->get_status() );
1180
-	}
1181
-
1182
-	/**
1183
-	 * Retrieves the subscription status class
1184
-	 *
1185
-	 * @since  1.0.19
1186
-	 * @return string
1187
-	 */
1188
-	public function get_status_class() {
1189
-		$statuses = getpaid_get_subscription_status_classes();
1190
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1191
-	}
1169
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1170
+    }
1171
+
1172
+    /**
1173
+     * Retrieves the subscription status label
1174
+     *
1175
+     * @since  1.0.0
1176
+     * @return string
1177
+     */
1178
+    public function get_status_label() {
1179
+        return getpaid_get_subscription_status_label( $this->get_status() );
1180
+    }
1181
+
1182
+    /**
1183
+     * Retrieves the subscription status class
1184
+     *
1185
+     * @since  1.0.19
1186
+     * @return string
1187
+     */
1188
+    public function get_status_class() {
1189
+        $statuses = getpaid_get_subscription_status_classes();
1190
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1191
+    }
1192 1192
 
1193 1193
     /**
1194 1194
      * Retrieves the subscription status label
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
      */
1199 1199
     public function get_status_label_html() {
1200 1200
 
1201
-		$status_label = sanitize_text_field( $this->get_status_label() );
1202
-		$class        = esc_attr( $this->get_status_class() );
1203
-		$status       = sanitize_html_class( $this->get_status() );
1201
+        $status_label = sanitize_text_field( $this->get_status_label() );
1202
+        $class        = esc_attr( $this->get_status_class() );
1203
+        $status       = sanitize_html_class( $this->get_status() );
1204 1204
 
1205
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1205
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1206 1206
     }
1207 1207
 
1208 1208
     /**
@@ -1213,75 +1213,75 @@  discard block
 block discarded – undo
1213 1213
      * @return bool
1214 1214
      */
1215 1215
     public function payment_exists( $txn_id = '' ) {
1216
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1216
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1217 1217
         return ! empty( $invoice_id );
1218
-	}
1219
-
1220
-	/**
1221
-	 * Handle the status transition.
1222
-	 */
1223
-	protected function status_transition() {
1224
-		$status_transition = $this->status_transition;
1225
-
1226
-		// Reset status transition variable.
1227
-		$this->status_transition = false;
1228
-
1229
-		if ( $status_transition ) {
1230
-			try {
1231
-
1232
-				// Fire a hook for the status change.
1233
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1235
-
1236
-				if ( ! empty( $status_transition['from'] ) ) {
1237
-
1238
-					/* translators: 1: old subscription status 2: new subscription status */
1239
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1240
-
1241
-					// Note the transition occurred.
1242
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1243
-
1244
-					// Fire another hook.
1245
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1247
-
1248
-				} else {
1249
-					/* translators: %s: new invoice status */
1250
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1251
-
1252
-					// Note the transition occurred.
1253
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1254
-
1255
-				}
1256
-			} catch ( Exception $e ) {
1257
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1258
-			}
1259
-		}
1260
-
1261
-	}
1262
-
1263
-	/**
1264
-	 * Save data to the database.
1265
-	 *
1266
-	 * @since 1.0.19
1267
-	 * @return int subscription ID
1268
-	 */
1269
-	public function save() {
1270
-		parent::save();
1271
-		$this->status_transition();
1272
-		return $this->get_id();
1273
-	}
1274
-
1275
-	/**
1276
-	 * Activates a subscription.
1277
-	 *
1278
-	 * @since 1.0.19
1279
-	 * @return int subscription ID
1280
-	 */
1281
-	public function activate() {
1282
-		$status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
-		$this->set_status( $status );
1284
-		return $this->save();
1285
-	}
1218
+    }
1219
+
1220
+    /**
1221
+     * Handle the status transition.
1222
+     */
1223
+    protected function status_transition() {
1224
+        $status_transition = $this->status_transition;
1225
+
1226
+        // Reset status transition variable.
1227
+        $this->status_transition = false;
1228
+
1229
+        if ( $status_transition ) {
1230
+            try {
1231
+
1232
+                // Fire a hook for the status change.
1233
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1235
+
1236
+                if ( ! empty( $status_transition['from'] ) ) {
1237
+
1238
+                    /* translators: 1: old subscription status 2: new subscription status */
1239
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1240
+
1241
+                    // Note the transition occurred.
1242
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1243
+
1244
+                    // Fire another hook.
1245
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1247
+
1248
+                } else {
1249
+                    /* translators: %s: new invoice status */
1250
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1251
+
1252
+                    // Note the transition occurred.
1253
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1254
+
1255
+                }
1256
+            } catch ( Exception $e ) {
1257
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1258
+            }
1259
+        }
1260
+
1261
+    }
1262
+
1263
+    /**
1264
+     * Save data to the database.
1265
+     *
1266
+     * @since 1.0.19
1267
+     * @return int subscription ID
1268
+     */
1269
+    public function save() {
1270
+        parent::save();
1271
+        $this->status_transition();
1272
+        return $this->get_id();
1273
+    }
1274
+
1275
+    /**
1276
+     * Activates a subscription.
1277
+     *
1278
+     * @since 1.0.19
1279
+     * @return int subscription ID
1280
+     */
1281
+    public function activate() {
1282
+        $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
+        $this->set_status( $status );
1284
+        return $this->save();
1285
+    }
1286 1286
 
1287 1287
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +604 added lines, -604 removed lines patch added patch discarded remove patch
@@ -14,93 +14,93 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
29
-
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29
+
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct() {
38
+     * Class constructor.
39
+     */
40
+    public function __construct() {
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect' ) );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
+        add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
68
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
69 69
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
75
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
76
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
77
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
78
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
79
-		do_action( 'getpaid_init_admin_hooks', $this );
80
-
81
-		// Setup/welcome
82
-		if ( ! empty( $_GET['page'] ) ) {
83
-			switch ( sanitize_text_field( $_GET['page'] ) ) {
84
-				case 'gp-setup':
85
-					include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
86
-					break;
87
-			}
88
-		}
89
-
90
-    }
91
-
92
-    /**
93
-	 * Register admin scripts
94
-	 *
95
-	 */
96
-	public function enqeue_scripts() {
70
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
71
+        add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
74
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
75
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
76
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
77
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
78
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
79
+        do_action( 'getpaid_init_admin_hooks', $this );
80
+
81
+        // Setup/welcome
82
+        if ( ! empty( $_GET['page'] ) ) {
83
+            switch ( sanitize_text_field( $_GET['page'] ) ) {
84
+                case 'gp-setup':
85
+                    include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
86
+                    break;
87
+            }
88
+        }
89
+
90
+    }
91
+
92
+    /**
93
+     * Register admin scripts
94
+     *
95
+     */
96
+    public function enqeue_scripts() {
97 97
         global $current_screen, $pagenow;
98 98
 
99
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
100
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
99
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
100
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
101 101
 
102 102
         if ( ! empty( $current_screen->post_type ) ) {
103
-			$page = $current_screen->post_type;
103
+            $page = $current_screen->post_type;
104 104
         }
105 105
 
106 106
         // General styles.
@@ -121,53 +121,53 @@  discard block
 block discarded – undo
121 121
         }
122 122
 
123 123
         // Payment form scripts.
124
-		if ( 'wpi_payment_form' == $page && $editing ) {
124
+        if ( 'wpi_payment_form' == $page && $editing ) {
125 125
             $this->load_payment_form_scripts();
126 126
         }
127 127
 
128
-		if ( $page == 'wpinv-subscriptions' ) {
129
-			wp_enqueue_script( 'postbox' );
130
-		}
128
+        if ( $page == 'wpinv-subscriptions' ) {
129
+            wp_enqueue_script( 'postbox' );
130
+        }
131 131
 
132 132
     }
133 133
 
134 134
     /**
135
-	 * Returns admin js translations.
136
-	 *
137
-	 */
138
-	protected function get_admin_i18() {
135
+     * Returns admin js translations.
136
+     *
137
+     */
138
+    protected function get_admin_i18() {
139 139
         global $post;
140 140
 
141
-		$date_range = array(
142
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
143
-		);
141
+        $date_range = array(
142
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
143
+        );
144 144
 
145
-		if ( $date_range['period'] == 'custom' ) {
145
+        if ( $date_range['period'] == 'custom' ) {
146 146
 
147
-			if ( isset( $_GET['from'] ) ) {
148
-				$date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
149
-			}
147
+            if ( isset( $_GET['from'] ) ) {
148
+                $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
149
+            }
150 150
 
151
-			if ( isset( $_GET['to'] ) ) {
152
-				$date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
153
-			}
151
+            if ( isset( $_GET['to'] ) ) {
152
+                $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
153
+            }
154 154
 }
155 155
 
156 156
         $i18n = array(
157 157
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
158 158
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
159
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
160
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
161
-			'rest_root'                 => esc_url_raw( rest_url() ),
162
-			'date_range'                => $date_range,
159
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
160
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
161
+            'rest_root'                 => esc_url_raw( rest_url() ),
162
+            'date_range'                => $date_range,
163 163
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
164 164
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
165 165
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
166 166
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
167 167
             'tax'                       => wpinv_tax_amount(),
168 168
             'discount'                  => 0,
169
-			'currency_symbol'           => wpinv_currency_symbol(),
170
-			'currency'                  => wpinv_get_currency(),
169
+            'currency_symbol'           => wpinv_currency_symbol(),
170
+            'currency'                  => wpinv_get_currency(),
171 171
             'currency_pos'              => wpinv_currency_position(),
172 172
             'thousand_sep'              => wpinv_thousands_separator(),
173 173
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -187,118 +187,118 @@  discard block
 block discarded – undo
187 187
             'item_description'          => __( 'Item Description', 'invoicing' ),
188 188
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
189 189
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
190
-			'searching'                 => __( 'Searching', 'invoicing' ),
191
-			'loading'                   => __( 'Loading...', 'invoicing' ),
192
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
193
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
194
-			'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
190
+            'searching'                 => __( 'Searching', 'invoicing' ),
191
+            'loading'                   => __( 'Loading...', 'invoicing' ),
192
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
193
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
194
+            'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
195 195
         );
196 196
 
197
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
197
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
198 198
 
199
-			$invoice              = new WPInv_Invoice( $post );
200
-			$i18n['save_invoice'] = sprintf(
201
-				__( 'Save %s', 'invoicing' ),
202
-				ucfirst( $invoice->get_invoice_quote_type() )
203
-			);
199
+            $invoice              = new WPInv_Invoice( $post );
200
+            $i18n['save_invoice'] = sprintf(
201
+                __( 'Save %s', 'invoicing' ),
202
+                ucfirst( $invoice->get_invoice_quote_type() )
203
+            );
204 204
 
205
-			$i18n['invoice_description'] = sprintf(
206
-				__( '%s Description', 'invoicing' ),
207
-				ucfirst( $invoice->get_invoice_quote_type() )
208
-			);
205
+            $i18n['invoice_description'] = sprintf(
206
+                __( '%s Description', 'invoicing' ),
207
+                ucfirst( $invoice->get_invoice_quote_type() )
208
+            );
209 209
 
210
-		}
211
-		return $i18n;
212
-	}
210
+        }
211
+        return $i18n;
212
+    }
213 213
 
214
-	/**
215
-	 * Change the admin footer text on GetPaid admin pages.
216
-	 *
217
-	 * @since  2.0.0
218
-	 * @param  string $footer_text
219
-	 * @return string
220
-	 */
221
-	public function admin_footer_text( $footer_text ) {
222
-		global $current_screen;
214
+    /**
215
+     * Change the admin footer text on GetPaid admin pages.
216
+     *
217
+     * @since  2.0.0
218
+     * @param  string $footer_text
219
+     * @return string
220
+     */
221
+    public function admin_footer_text( $footer_text ) {
222
+        global $current_screen;
223 223
 
224
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
224
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
225 225
 
226 226
         if ( ! empty( $current_screen->post_type ) ) {
227
-			$page = $current_screen->post_type;
227
+            $page = $current_screen->post_type;
228 228
         }
229 229
 
230 230
         // General styles.
231 231
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
232 232
 
233
-			// Change the footer text
234
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
233
+            // Change the footer text
234
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
235 235
 
236
-				$rating_url  = esc_url(
237
-					wp_nonce_url(
238
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
239
-						'getpaid-nonce',
240
-						'getpaid-nonce'
236
+                $rating_url  = esc_url(
237
+                    wp_nonce_url(
238
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
239
+                        'getpaid-nonce',
240
+                        'getpaid-nonce'
241 241
                     )
242
-				);
242
+                );
243 243
 
244
-				$footer_text = sprintf(
245
-					/* translators: %s: five stars */
246
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
247
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
248
-				);
244
+                $footer_text = sprintf(
245
+                    /* translators: %s: five stars */
246
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
247
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
248
+                );
249 249
 
250
-			} else {
250
+            } else {
251 251
 
252
-				$footer_text = sprintf(
253
-					/* translators: %s: GetPaid */
254
-					__( 'Thank you for using %s!', 'invoicing' ),
255
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
256
-				);
252
+                $footer_text = sprintf(
253
+                    /* translators: %s: GetPaid */
254
+                    __( 'Thank you for using %s!', 'invoicing' ),
255
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
256
+                );
257 257
 
258
-			}
258
+            }
259 259
 }
260 260
 
261
-		return $footer_text;
262
-	}
263
-
264
-	/**
265
-	 * Redirects to wp.org to rate the plugin.
266
-	 *
267
-	 * @since  2.0.0
268
-	 */
269
-	public function redirect_to_wordpress_rating_page() {
270
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
271
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
272
-		exit;
273
-	}
274
-
275
-    /**
276
-	 * Loads payment form js.
277
-	 *
278
-	 */
279
-	protected function load_payment_form_scripts() {
261
+        return $footer_text;
262
+    }
263
+
264
+    /**
265
+     * Redirects to wp.org to rate the plugin.
266
+     *
267
+     * @since  2.0.0
268
+     */
269
+    public function redirect_to_wordpress_rating_page() {
270
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
271
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
272
+        exit;
273
+    }
274
+
275
+    /**
276
+     * Loads payment form js.
277
+     *
278
+     */
279
+    protected function load_payment_form_scripts() {
280 280
         global $post;
281 281
 
282 282
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
283
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
284
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
283
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
284
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
285 285
 
286
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
287
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
286
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
287
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
288 288
 
289
-		wp_localize_script(
289
+        wp_localize_script(
290 290
             'wpinv-admin-payment-form-script',
291 291
             'wpinvPaymentFormAdmin',
292 292
             array(
293
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
294
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
295
-				'currency'      => wpinv_currency_symbol(),
296
-				'position'      => wpinv_currency_position(),
297
-				'decimals'      => (int) wpinv_decimals(),
298
-				'thousands_sep' => wpinv_thousands_separator(),
299
-				'decimals_sep'  => wpinv_decimal_separator(),
300
-				'form_items'    => gepaid_get_form_items( $post->ID ),
301
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
293
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
294
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
295
+                'currency'      => wpinv_currency_symbol(),
296
+                'position'      => wpinv_currency_position(),
297
+                'decimals'      => (int) wpinv_decimals(),
298
+                'thousands_sep' => wpinv_thousands_separator(),
299
+                'decimals_sep'  => wpinv_decimal_separator(),
300
+                'form_items'    => gepaid_get_form_items( $post->ID ),
301
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
302 302
             )
303 303
         );
304 304
 
@@ -307,19 +307,19 @@  discard block
 block discarded – undo
307 307
     }
308 308
 
309 309
     /**
310
-	 * Add our classes to admin pages.
310
+     * Add our classes to admin pages.
311 311
      *
312 312
      * @param string $classes
313 313
      * @return string
314
-	 *
315
-	 */
314
+     *
315
+     */
316 316
     public function admin_body_class( $classes ) {
317
-		global $pagenow, $post, $current_screen;
317
+        global $pagenow, $post, $current_screen;
318 318
 
319 319
         $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
320 320
 
321 321
         if ( ! empty( $current_screen->post_type ) ) {
322
-			$page = $current_screen->post_type;
322
+            $page = $current_screen->post_type;
323 323
         }
324 324
 
325 325
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -328,70 +328,70 @@  discard block
 block discarded – undo
328 328
 
329 329
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
330 330
             $classes .= ' wpinv-cpt wpinv';
331
-		}
331
+        }
332 332
 
333
-		if ( getpaid_is_invoice_post_type( $page ) ) {
333
+        if ( getpaid_is_invoice_post_type( $page ) ) {
334 334
             $classes .= ' getpaid-is-invoice-cpt';
335 335
         }
336 336
 
337
-		return $classes;
337
+        return $classes;
338 338
     }
339 339
 
340 340
     /**
341
-	 * Maybe show the AyeCode Connect Notice.
342
-	 */
343
-	public function init_ayecode_connect_helper() {
341
+     * Maybe show the AyeCode Connect Notice.
342
+     */
343
+    public function init_ayecode_connect_helper() {
344 344
 
345
-		// Register with the deactivation survey class.
346
-		AyeCode_Deactivation_Survey::instance(
345
+        // Register with the deactivation survey class.
346
+        AyeCode_Deactivation_Survey::instance(
347 347
             array(
348
-				'slug'              => 'invoicing',
349
-				'version'           => WPINV_VERSION,
350
-				'support_url'       => 'https://wpgetpaid.com/support/',
351
-				'documentation_url' => 'https://docs.wpgetpaid.com/',
352
-				'activated'         => (int) get_option( 'gepaid_installed_on' ),
348
+                'slug'              => 'invoicing',
349
+                'version'           => WPINV_VERSION,
350
+                'support_url'       => 'https://wpgetpaid.com/support/',
351
+                'documentation_url' => 'https://docs.wpgetpaid.com/',
352
+                'activated'         => (int) get_option( 'gepaid_installed_on' ),
353 353
             )
354 354
         );
355 355
 
356 356
         new AyeCode_Connect_Helper(
357 357
             array(
358
-				'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
359
-				'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
360
-				'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
361
-				'connect_button'    => __( 'Connect Site', 'invoicing' ),
362
-				'connecting_button' => __( 'Connecting...', 'invoicing' ),
363
-				'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
364
-				'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
358
+                'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
359
+                'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
360
+                'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
361
+                'connect_button'    => __( 'Connect Site', 'invoicing' ),
362
+                'connecting_button' => __( 'Connecting...', 'invoicing' ),
363
+                'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
364
+                'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
365 365
             ),
366 366
             array( 'wpi-addons' )
367 367
         );
368 368
 
369 369
     }
370 370
 
371
-	/**
372
-	 * Redirect users to settings on activation.
373
-	 *
374
-	 * @return void
375
-	 */
376
-	public function activation_redirect() {
371
+    /**
372
+     * Redirect users to settings on activation.
373
+     *
374
+     * @return void
375
+     */
376
+    public function activation_redirect() {
377 377
 
378
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
378
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
379 379
 
380
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
381
-			return;
382
-		}
380
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
381
+            return;
382
+        }
383 383
 
384
-		// Bail if activating from network, or bulk
385
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
386
-			return;
387
-		}
384
+        // Bail if activating from network, or bulk
385
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
386
+            return;
387
+        }
388 388
 
389
-	    update_option( 'wpinv_redirected_to_settings', 1 );
389
+        update_option( 'wpinv_redirected_to_settings', 1 );
390 390
 
391 391
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
392 392
         exit;
393 393
 
394
-	}
394
+    }
395 395
 
396 396
     /**
397 397
      * Fires an admin action after verifying that a user can fire them.
@@ -404,543 +404,543 @@  discard block
 block discarded – undo
404 404
         }
405 405
     }
406 406
 
407
-	/**
407
+    /**
408 408
      * Duplicate invoice.
409
-	 *
410
-	 * @param array $args
409
+     *
410
+     * @param array $args
411 411
      */
412 412
     public function duplicate_invoice( $args ) {
413 413
 
414
-		if ( empty( $args['invoice_id'] ) ) {
415
-			return;
416
-		}
414
+        if ( empty( $args['invoice_id'] ) ) {
415
+            return;
416
+        }
417 417
 
418
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
418
+        $invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
419 419
 
420
-		if ( ! $invoice->exists() ) {
421
-			return;
422
-		}
420
+        if ( ! $invoice->exists() ) {
421
+            return;
422
+        }
423 423
 
424
-		$new_invoice = getpaid_duplicate_invoice( $invoice );
425
-		$new_invoice->save();
424
+        $new_invoice = getpaid_duplicate_invoice( $invoice );
425
+        $new_invoice->save();
426 426
 
427
-		if ( $new_invoice->exists() ) {
427
+        if ( $new_invoice->exists() ) {
428 428
 
429
-			getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
429
+            getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
430 430
 
431
-			wp_safe_redirect(
432
-				add_query_arg(
433
-					array(
434
-						'action' => 'edit',
435
-						'post'   => $new_invoice->get_id(),
436
-					),
437
-					admin_url( 'post.php' )
438
-				)
439
-			);
440
-			exit;
431
+            wp_safe_redirect(
432
+                add_query_arg(
433
+                    array(
434
+                        'action' => 'edit',
435
+                        'post'   => $new_invoice->get_id(),
436
+                    ),
437
+                    admin_url( 'post.php' )
438
+                )
439
+            );
440
+            exit;
441 441
 
442
-		}
442
+        }
443 443
 
444
-		getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
444
+        getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
445 445
 
446
-	}
446
+    }
447 447
 
448
-	/**
448
+    /**
449 449
      * Sends a payment reminder to a customer.
450
-	 *
451
-	 * @param array $args
450
+     *
451
+     * @param array $args
452 452
      */
453 453
     public function duplicate_payment_form( $args ) {
454 454
 
455
-		if ( empty( $args['form_id'] ) ) {
456
-			return;
457
-		}
458
-
459
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
455
+        if ( empty( $args['form_id'] ) ) {
456
+            return;
457
+        }
460 458
 
461
-		if ( ! $form->exists() ) {
462
-			return;
463
-		}
459
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
464 460
 
465
-		$new_form = new GetPaid_Payment_Form();
466
-		$new_form->set_author( $form->get_author( 'edit' ) );
467
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
468
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
469
-		$new_form->set_items( $form->get_items( 'edit' ) );
470
-		$new_form->save();
461
+        if ( ! $form->exists() ) {
462
+            return;
463
+        }
471 464
 
472
-		if ( $new_form->exists() ) {
473
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
474
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
475
-		} else {
476
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
477
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
478
-		}
465
+        $new_form = new GetPaid_Payment_Form();
466
+        $new_form->set_author( $form->get_author( 'edit' ) );
467
+        $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
468
+        $new_form->set_elements( $form->get_elements( 'edit' ) );
469
+        $new_form->set_items( $form->get_items( 'edit' ) );
470
+        $new_form->save();
471
+
472
+        if ( $new_form->exists() ) {
473
+            $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
474
+            $url = get_edit_post_link( $new_form->get_id(), 'edit' );
475
+        } else {
476
+            $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
477
+            $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
478
+        }
479 479
 
480
-		wp_redirect( $url );
481
-		exit;
482
-	}
480
+        wp_redirect( $url );
481
+        exit;
482
+    }
483 483
 
484
-	/**
484
+    /**
485 485
      * Resets form stats.
486
-	 *
487
-	 * @param array $args
486
+     *
487
+     * @param array $args
488 488
      */
489 489
     public function reset_form_stats( $args ) {
490 490
 
491
-		if ( empty( $args['form_id'] ) ) {
492
-			return;
493
-		}
491
+        if ( empty( $args['form_id'] ) ) {
492
+            return;
493
+        }
494 494
 
495
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
495
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
496 496
 
497
-		if ( ! $form->exists() ) {
498
-			return;
499
-		}
497
+        if ( ! $form->exists() ) {
498
+            return;
499
+        }
500 500
 
501
-		$form->set_earned( 0 );
502
-		$form->set_refunded( 0 );
503
-		$form->set_cancelled( 0 );
504
-		$form->set_failed( 0 );
505
-		$form->save();
501
+        $form->set_earned( 0 );
502
+        $form->set_refunded( 0 );
503
+        $form->set_cancelled( 0 );
504
+        $form->set_failed( 0 );
505
+        $form->save();
506 506
 
507
-		$this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
507
+        $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
508 508
 
509
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
510
-		exit;
511
-	}
509
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
510
+        exit;
511
+    }
512 512
 
513
-	/**
513
+    /**
514 514
      * Sends a payment reminder to a customer.
515
-	 *
516
-	 * @param array $args
515
+     *
516
+     * @param array $args
517 517
      */
518 518
     public function send_customer_invoice( $args ) {
519
-		getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
520
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
521
-		exit;
522
-	}
519
+        getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
520
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
521
+        exit;
522
+    }
523 523
 
524
-	/**
524
+    /**
525 525
      * Sends a payment reminder to a customer.
526
-	 *
527
-	 * @param array $args
526
+     *
527
+     * @param array $args
528 528
      */
529 529
     public function send_customer_payment_reminder( $args ) {
530
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
530
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
531 531
 
532
-		if ( $sent ) {
533
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
534
-		} else {
535
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
536
-		}
532
+        if ( $sent ) {
533
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
534
+        } else {
535
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
536
+        }
537 537
 
538
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
539
-		exit;
540
-	}
538
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
539
+        exit;
540
+    }
541 541
 
542
-	/**
542
+    /**
543 543
      * Resets tax rates.
544
-	 *
544
+     *
545 545
      */
546 546
     public function admin_reset_tax_rates() {
547 547
 
548
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
549
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
550
-		exit;
548
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
549
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
550
+        exit;
551 551
 
552
-	}
552
+    }
553 553
 
554
-	/**
554
+    /**
555 555
      * Resets admin pages.
556
-	 *
556
+     *
557 557
      */
558 558
     public function admin_create_missing_pages() {
559
-		$installer = new GetPaid_Installer();
560
-		$installer->create_pages();
561
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
562
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
563
-		exit;
564
-	}
565
-
566
-	/**
567
-	 * Refreshes the permalinks.
568
-	 */
569
-	public function admin_refresh_permalinks() {
570
-		flush_rewrite_rules();
571
-		$this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
572
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
573
-		exit;
574
-	}
575
-
576
-	/**
559
+        $installer = new GetPaid_Installer();
560
+        $installer->create_pages();
561
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
562
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
563
+        exit;
564
+    }
565
+
566
+    /**
567
+     * Refreshes the permalinks.
568
+     */
569
+    public function admin_refresh_permalinks() {
570
+        flush_rewrite_rules();
571
+        $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
572
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
573
+        exit;
574
+    }
575
+
576
+    /**
577 577
      * Creates missing admin tables.
578
-	 *
578
+     *
579 579
      */
580 580
     public function admin_create_missing_tables() {
581
-		global $wpdb;
581
+        global $wpdb;
582 582
 
583
-		GetPaid_Installer::create_db_tables();
583
+        GetPaid_Installer::create_db_tables();
584 584
 
585
-		if ( '' !== $wpdb->last_error ) {
586
-			$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
587
-		} else {
588
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
589
-		}
585
+        if ( '' !== $wpdb->last_error ) {
586
+            $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
587
+        } else {
588
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
589
+        }
590 590
 
591
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
592
-		exit;
593
-	}
591
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
592
+        exit;
593
+    }
594 594
 
595
-	/**
595
+    /**
596 596
      * Migrates old invoices to the new database tables.
597
-	 *
597
+     *
598 598
      */
599 599
     public function admin_migrate_old_invoices() {
600 600
 
601
-		// Migrate the invoices.
602
-		$installer = new GetPaid_Installer();
603
-		$installer->migrate_old_invoices();
601
+        // Migrate the invoices.
602
+        $installer = new GetPaid_Installer();
603
+        $installer->migrate_old_invoices();
604 604
 
605
-		// Show an admin message.
606
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
605
+        // Show an admin message.
606
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
607 607
 
608
-		// Redirect the admin.
609
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
610
-		exit;
608
+        // Redirect the admin.
609
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
610
+        exit;
611 611
 
612
-	}
612
+    }
613 613
 
614
-	/**
614
+    /**
615 615
      * Download customers.
616
-	 *
616
+     *
617 617
      */
618 618
     public function admin_download_customers() {
619
-		global $wpdb;
620
-
621
-		$output = fopen( 'php://output', 'w' );
622
-
623
-		if ( false === $output ) {
624
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
625
-		}
619
+        global $wpdb;
626 620
 
627
-		header( 'Content-Type:text/csv' );
628
-		header( 'Content-Disposition:attachment;filename=customers.csv' );
621
+        $output = fopen( 'php://output', 'w' );
629 622
 
630
-		$post_types = '';
623
+        if ( false === $output ) {
624
+            wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
625
+        }
631 626
 
632
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
633
-			$post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
634
-		}
627
+        header( 'Content-Type:text/csv' );
628
+        header( 'Content-Disposition:attachment;filename=customers.csv' );
635 629
 
636
-		$post_types = rtrim( $post_types, ' OR' );
630
+        $post_types = '';
637 631
 
638
-		$customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" );
632
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
633
+            $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
634
+        }
639 635
 
640
-		$columns = array(
641
-			'name'       => __( 'Name', 'invoicing' ),
642
-			'email'      => __( 'Email', 'invoicing' ),
643
-			'country'    => __( 'Country', 'invoicing' ),
644
-			'state'      => __( 'State', 'invoicing' ),
645
-			'city'       => __( 'City', 'invoicing' ),
646
-			'zip'        => __( 'ZIP', 'invoicing' ),
647
-			'address'    => __( 'Address', 'invoicing' ),
648
-			'phone'      => __( 'Phone', 'invoicing' ),
649
-			'company'    => __( 'Company', 'invoicing' ),
650
-			'company_id' => __( 'Company ID', 'invoicing' ),
651
-			'invoices'   => __( 'Invoices', 'invoicing' ),
652
-			'total_raw'  => __( 'Total Spend', 'invoicing' ),
653
-			'signup'     => __( 'Date created', 'invoicing' ),
654
-		);
636
+        $post_types = rtrim( $post_types, ' OR' );
637
+
638
+        $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" );
639
+
640
+        $columns = array(
641
+            'name'       => __( 'Name', 'invoicing' ),
642
+            'email'      => __( 'Email', 'invoicing' ),
643
+            'country'    => __( 'Country', 'invoicing' ),
644
+            'state'      => __( 'State', 'invoicing' ),
645
+            'city'       => __( 'City', 'invoicing' ),
646
+            'zip'        => __( 'ZIP', 'invoicing' ),
647
+            'address'    => __( 'Address', 'invoicing' ),
648
+            'phone'      => __( 'Phone', 'invoicing' ),
649
+            'company'    => __( 'Company', 'invoicing' ),
650
+            'company_id' => __( 'Company ID', 'invoicing' ),
651
+            'invoices'   => __( 'Invoices', 'invoicing' ),
652
+            'total_raw'  => __( 'Total Spend', 'invoicing' ),
653
+            'signup'     => __( 'Date created', 'invoicing' ),
654
+        );
655 655
 
656
-		// Output the csv column headers.
657
-		fputcsv( $output, array_values( $columns ) );
656
+        // Output the csv column headers.
657
+        fputcsv( $output, array_values( $columns ) );
658 658
 
659
-		// Loop through
660
-		$table = new WPInv_Customers_Table();
661
-		foreach ( $customers as $customer_id ) {
659
+        // Loop through
660
+        $table = new WPInv_Customers_Table();
661
+        foreach ( $customers as $customer_id ) {
662 662
 
663
-			$user = get_user_by( 'id', $customer_id );
664
-			$row  = array();
665
-			if ( empty( $user ) ) {
666
-				continue;
667
-			}
663
+            $user = get_user_by( 'id', $customer_id );
664
+            $row  = array();
665
+            if ( empty( $user ) ) {
666
+                continue;
667
+            }
668 668
 
669
-			foreach ( array_keys( $columns ) as $column ) {
669
+            foreach ( array_keys( $columns ) as $column ) {
670 670
 
671
-				$method = 'column_' . $column;
671
+                $method = 'column_' . $column;
672 672
 
673
-				if ( 'name' == $column ) {
674
-					$value = esc_html( $user->display_name );
675
-				} elseif ( 'email' == $column ) {
676
-					$value = sanitize_email( $user->user_email );
677
-				} elseif ( is_callable( array( $table, $method ) ) ) {
678
-					$value = wp_strip_all_tags( $table->$method( $user ) );
679
-				}
673
+                if ( 'name' == $column ) {
674
+                    $value = esc_html( $user->display_name );
675
+                } elseif ( 'email' == $column ) {
676
+                    $value = sanitize_email( $user->user_email );
677
+                } elseif ( is_callable( array( $table, $method ) ) ) {
678
+                    $value = wp_strip_all_tags( $table->$method( $user ) );
679
+                }
680 680
 
681
-				if ( empty( $value ) ) {
682
-					$value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
683
-				}
681
+                if ( empty( $value ) ) {
682
+                    $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
683
+                }
684 684
 
685
-				$row[] = $value;
685
+                $row[] = $value;
686 686
 
687
-			}
687
+            }
688 688
 
689
-			fputcsv( $output, $row );
690
-		}
689
+            fputcsv( $output, $row );
690
+        }
691 691
 
692
-		fclose( $output );
693
-		exit;
692
+        fclose( $output );
693
+        exit;
694 694
 
695
-	}
695
+    }
696 696
 
697
-	/**
697
+    /**
698 698
      * Installs a plugin.
699
-	 *
700
-	 * @param array $data
699
+     *
700
+     * @param array $data
701 701
      */
702 702
     public function admin_install_plugin( $data ) {
703 703
 
704
-		if ( ! empty( $data['plugins'] ) ) {
705
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
706
-			wp_cache_flush();
704
+        if ( ! empty( $data['plugins'] ) ) {
705
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
706
+            wp_cache_flush();
707 707
 
708
-			foreach ( $data['plugins'] as $slug => $file ) {
709
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
710
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
711
-				$installed  = $upgrader->install( $plugin_zip );
708
+            foreach ( $data['plugins'] as $slug => $file ) {
709
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
710
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
711
+                $installed  = $upgrader->install( $plugin_zip );
712 712
 
713
-				if ( ! is_wp_error( $installed ) && $installed ) {
714
-					activate_plugin( $file, '', false, true );
715
-				} else {
716
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
717
-				}
713
+                if ( ! is_wp_error( $installed ) && $installed ) {
714
+                    activate_plugin( $file, '', false, true );
715
+                } else {
716
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
717
+                }
718 718
 }
719 719
 }
720 720
 
721
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
722
-		wp_safe_redirect( $redirect );
723
-		exit;
721
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
722
+        wp_safe_redirect( $redirect );
723
+        exit;
724 724
 
725
-	}
725
+    }
726 726
 
727
-	/**
727
+    /**
728 728
      * Connects a gateway.
729
-	 *
730
-	 * @param array $data
729
+     *
730
+     * @param array $data
731 731
      */
732 732
     public function admin_connect_gateway( $data ) {
733 733
 
734
-		if ( ! empty( $data['plugin'] ) ) {
734
+        if ( ! empty( $data['plugin'] ) ) {
735 735
 
736
-			$gateway     = sanitize_key( $data['plugin'] );
737
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
736
+            $gateway     = sanitize_key( $data['plugin'] );
737
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
738 738
 
739
-			if ( ! empty( $connect_url ) ) {
740
-				wp_redirect( $connect_url );
741
-				exit;
742
-			}
739
+            if ( ! empty( $connect_url ) ) {
740
+                wp_redirect( $connect_url );
741
+                exit;
742
+            }
743 743
 
744
-			if ( 'stripe' == $data['plugin'] ) {
745
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
746
-				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
747
-				wp_cache_flush();
744
+            if ( 'stripe' == $data['plugin'] ) {
745
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
746
+                include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
747
+                wp_cache_flush();
748 748
 
749
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
750
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
751
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
752
-					$upgrader->install( $plugin_zip );
753
-				}
749
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
750
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
751
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
752
+                    $upgrader->install( $plugin_zip );
753
+                }
754 754
 
755
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
756
-			}
755
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
756
+            }
757 757
 
758
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
759
-			if ( ! empty( $connect_url ) ) {
760
-				wp_redirect( $connect_url );
761
-				exit;
762
-			}
758
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
759
+            if ( ! empty( $connect_url ) ) {
760
+                wp_redirect( $connect_url );
761
+                exit;
762
+            }
763 763
 }
764 764
 
765
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
766
-		wp_safe_redirect( $redirect );
767
-		exit;
765
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
766
+        wp_safe_redirect( $redirect );
767
+        exit;
768 768
 
769
-	}
769
+    }
770 770
 
771
-	/**
771
+    /**
772 772
      * Recalculates discounts.
773
-	 *
773
+     *
774 774
      */
775 775
     public function admin_recalculate_discounts() {
776
-		global $wpdb;
776
+        global $wpdb;
777 777
 
778
-		// Fetch all invoices that have discount codes.
779
-		$table    = $wpdb->prefix . 'getpaid_invoices';
780
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
778
+        // Fetch all invoices that have discount codes.
779
+        $table    = $wpdb->prefix . 'getpaid_invoices';
780
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
781 781
 
782
-		foreach ( $invoices as $invoice ) {
782
+        foreach ( $invoices as $invoice ) {
783 783
 
784
-			$invoice = new WPInv_Invoice( $invoice );
784
+            $invoice = new WPInv_Invoice( $invoice );
785 785
 
786
-			if ( ! $invoice->exists() ) {
787
-				continue;
788
-			}
786
+            if ( ! $invoice->exists() ) {
787
+                continue;
788
+            }
789 789
 
790
-			// Abort if the discount does not exist or does not apply here.
791
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
792
-			if ( ! $discount->exists() ) {
793
-				continue;
794
-			}
790
+            // Abort if the discount does not exist or does not apply here.
791
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
792
+            if ( ! $discount->exists() ) {
793
+                continue;
794
+            }
795 795
 
796
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
797
-			$invoice->recalculate_total();
796
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
797
+            $invoice->recalculate_total();
798 798
 
799
-			if ( $invoice->get_total_discount() > 0 ) {
800
-				$invoice->save();
801
-			}
799
+            if ( $invoice->get_total_discount() > 0 ) {
800
+                $invoice->save();
801
+            }
802 802
 }
803 803
 
804
-		// Show an admin message.
805
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
804
+        // Show an admin message.
805
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
806 806
 
807
-		// Redirect the admin.
808
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
809
-		exit;
807
+        // Redirect the admin.
808
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
809
+        exit;
810 810
 
811
-	}
811
+    }
812 812
 
813 813
     /**
814
-	 * Returns an array of admin notices.
815
-	 *
816
-	 * @since       1.0.19
814
+     * Returns an array of admin notices.
815
+     *
816
+     * @since       1.0.19
817 817
      * @return array
818
-	 */
819
-	public function get_notices() {
820
-		$notices = get_option( 'wpinv_admin_notices' );
818
+     */
819
+    public function get_notices() {
820
+        $notices = get_option( 'wpinv_admin_notices' );
821 821
         return is_array( $notices ) ? $notices : array();
822
-	}
822
+    }
823 823
 
824
-	/**
825
-	 * Checks if we have any admin notices.
826
-	 *
827
-	 * @since       2.0.4
824
+    /**
825
+     * Checks if we have any admin notices.
826
+     *
827
+     * @since       2.0.4
828 828
      * @return array
829
-	 */
830
-	public function has_notices() {
831
-		return count( $this->get_notices() ) > 0;
832
-	}
833
-
834
-	/**
835
-	 * Clears all admin notices
836
-	 *
837
-	 * @access      public
838
-	 * @since       1.0.19
839
-	 */
840
-	public function clear_notices() {
841
-		delete_option( 'wpinv_admin_notices' );
842
-	}
843
-
844
-	/**
845
-	 * Saves a new admin notice
846
-	 *
847
-	 * @access      public
848
-	 * @since       1.0.19
849
-	 */
850
-	public function save_notice( $type, $message ) {
851
-		$notices = $this->get_notices();
852
-
853
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
854
-			$notices[ $type ] = array();
855
-		}
856
-
857
-		$notices[ $type ][] = $message;
858
-
859
-		update_option( 'wpinv_admin_notices', $notices );
860
-	}
861
-
862
-	/**
863
-	 * Displays a success notice
864
-	 *
865
-	 * @param       string $msg The message to qeue.
866
-	 * @access      public
867
-	 * @since       1.0.19
868
-	 */
869
-	public function show_success( $msg ) {
870
-		$this->save_notice( 'success', $msg );
871
-	}
872
-
873
-	/**
874
-	 * Displays a error notice
875
-	 *
876
-	 * @access      public
877
-	 * @param       string $msg The message to qeue.
878
-	 * @since       1.0.19
879
-	 */
880
-	public function show_error( $msg ) {
881
-		$this->save_notice( 'error', $msg );
882
-	}
883
-
884
-	/**
885
-	 * Displays a warning notice
886
-	 *
887
-	 * @access      public
888
-	 * @param       string $msg The message to qeue.
889
-	 * @since       1.0.19
890
-	 */
891
-	public function show_warning( $msg ) {
892
-		$this->save_notice( 'warning', $msg );
893
-	}
894
-
895
-	/**
896
-	 * Displays a info notice
897
-	 *
898
-	 * @access      public
899
-	 * @param       string $msg The message to qeue.
900
-	 * @since       1.0.19
901
-	 */
902
-	public function show_info( $msg ) {
903
-		$this->save_notice( 'info', $msg );
904
-	}
905
-
906
-	/**
907
-	 * Show notices
908
-	 *
909
-	 * @access      public
910
-	 * @since       1.0.19
911
-	 */
912
-	public function show_notices() {
829
+     */
830
+    public function has_notices() {
831
+        return count( $this->get_notices() ) > 0;
832
+    }
833
+
834
+    /**
835
+     * Clears all admin notices
836
+     *
837
+     * @access      public
838
+     * @since       1.0.19
839
+     */
840
+    public function clear_notices() {
841
+        delete_option( 'wpinv_admin_notices' );
842
+    }
843
+
844
+    /**
845
+     * Saves a new admin notice
846
+     *
847
+     * @access      public
848
+     * @since       1.0.19
849
+     */
850
+    public function save_notice( $type, $message ) {
851
+        $notices = $this->get_notices();
852
+
853
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
854
+            $notices[ $type ] = array();
855
+        }
856
+
857
+        $notices[ $type ][] = $message;
858
+
859
+        update_option( 'wpinv_admin_notices', $notices );
860
+    }
861
+
862
+    /**
863
+     * Displays a success notice
864
+     *
865
+     * @param       string $msg The message to qeue.
866
+     * @access      public
867
+     * @since       1.0.19
868
+     */
869
+    public function show_success( $msg ) {
870
+        $this->save_notice( 'success', $msg );
871
+    }
872
+
873
+    /**
874
+     * Displays a error notice
875
+     *
876
+     * @access      public
877
+     * @param       string $msg The message to qeue.
878
+     * @since       1.0.19
879
+     */
880
+    public function show_error( $msg ) {
881
+        $this->save_notice( 'error', $msg );
882
+    }
883
+
884
+    /**
885
+     * Displays a warning notice
886
+     *
887
+     * @access      public
888
+     * @param       string $msg The message to qeue.
889
+     * @since       1.0.19
890
+     */
891
+    public function show_warning( $msg ) {
892
+        $this->save_notice( 'warning', $msg );
893
+    }
894
+
895
+    /**
896
+     * Displays a info notice
897
+     *
898
+     * @access      public
899
+     * @param       string $msg The message to qeue.
900
+     * @since       1.0.19
901
+     */
902
+    public function show_info( $msg ) {
903
+        $this->save_notice( 'info', $msg );
904
+    }
905
+
906
+    /**
907
+     * Show notices
908
+     *
909
+     * @access      public
910
+     * @since       1.0.19
911
+     */
912
+    public function show_notices() {
913 913
 
914 914
         $notices = $this->get_notices();
915 915
         $this->clear_notices();
916 916
 
917
-		foreach ( $notices as $type => $messages ) {
917
+        foreach ( $notices as $type => $messages ) {
918 918
 
919
-			if ( ! is_array( $messages ) ) {
920
-				continue;
921
-			}
919
+            if ( ! is_array( $messages ) ) {
920
+                continue;
921
+            }
922 922
 
923 923
             $type  = esc_attr( $type );
924
-			foreach ( $messages as $message ) {
925
-				echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
924
+            foreach ( $messages as $message ) {
925
+                echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
926 926
             }
927 927
 }
928 928
 
929
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
930
-
931
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
932
-				$url     = wp_nonce_url(
933
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
934
-					'getpaid-nonce',
935
-					'getpaid-nonce'
936
-				);
937
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
938
-				$message2 = __( 'Generate Pages', 'invoicing' );
939
-				echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
940
-				break;
941
-			}
929
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
930
+
931
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
932
+                $url     = wp_nonce_url(
933
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
934
+                    'getpaid-nonce',
935
+                    'getpaid-nonce'
936
+                );
937
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
938
+                $message2 = __( 'Generate Pages', 'invoicing' );
939
+                echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
940
+                break;
941
+            }
942 942
 }
943 943
 
944
-	}
944
+    }
945 945
 
946 946
 }
Please login to merge, or discard this patch.
includes/user-functions.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
73 73
 
74
-	if ( current_user_can( 'manage_options' ) ) {
75
-		return 'manage_options';
76
-	};
74
+    if ( current_user_can( 'manage_options' ) ) {
75
+        return 'manage_options';
76
+    };
77 77
 
78
-	return $capalibilty;
78
+    return $capalibilty;
79 79
 }
80 80
 
81 81
 /**
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
  * @return bool Whether the current user has the given capability.
99 99
  */
100 100
 function wpinv_current_user_can( $capability, $args = array() ) {
101
-	$can = wpinv_current_user_can_manage_invoicing();
101
+    $can = wpinv_current_user_can_manage_invoicing();
102 102
 
103
-	return apply_filters( 'getpaid_current_user_can', $can, $capability, $args );
103
+    return apply_filters( 'getpaid_current_user_can', $can, $capability, $args );
104 104
 }
105 105
 
106 106
 /**
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
     // Prepare user values.
115 115
     $prefix = preg_replace( '/\s+/', '', $prefix );
116 116
     $prefix = empty( $prefix ) ? $email : $prefix;
117
-	$args   = array(
118
-		'user_login' => wpinv_generate_user_name( $prefix ),
119
-		'user_pass'  => wp_generate_password(),
120
-		'user_email' => $email,
117
+    $args   = array(
118
+        'user_login' => wpinv_generate_user_name( $prefix ),
119
+        'user_pass'  => wp_generate_password(),
120
+        'user_email' => $email,
121 121
         'role'       => 'subscriber',
122 122
     );
123 123
 
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
 function wpinv_generate_user_name( $prefix = '' ) {
135 135
 
136 136
     // If prefix is an email, retrieve the part before the email.
137
-	$prefix = strtok( $prefix, '@' );
137
+    $prefix = strtok( $prefix, '@' );
138 138
     $prefix = trim( $prefix, '.' );
139 139
 
140
-	// Sanitize the username.
141
-	$prefix = sanitize_user( $prefix, true );
140
+    // Sanitize the username.
141
+    $prefix = sanitize_user( $prefix, true );
142 142
 
143
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
144
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
145
-		$prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
146
-	}
143
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
144
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
145
+        $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
146
+    }
147 147
 
148 148
     $username = $prefix;
149 149
     $postfix  = 2;
@@ -282,43 +282,43 @@  discard block
 block discarded – undo
282 282
 
283 283
                         $value = $customer->get( $key );
284 284
 
285
-					// Display the country.
286
-					if ( 'country' == $key ) {
287
-
288
-						aui()->select(
289
-							array(
290
-								'options'     => wpinv_get_country_list(),
291
-								'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
292
-								'id'          => 'wpinv-' . sanitize_html_class( $key ),
293
-								'value'       => sanitize_text_field( $value ),
294
-								'placeholder' => $label,
295
-								'label'       => wp_kses_post( $label ),
296
-								'label_type'  => 'vertical',
297
-								'class'       => 'getpaid-address-field',
285
+                    // Display the country.
286
+                    if ( 'country' == $key ) {
287
+
288
+                        aui()->select(
289
+                            array(
290
+                                'options'     => wpinv_get_country_list(),
291
+                                'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
292
+                                'id'          => 'wpinv-' . sanitize_html_class( $key ),
293
+                                'value'       => sanitize_text_field( $value ),
294
+                                'placeholder' => $label,
295
+                                'label'       => wp_kses_post( $label ),
296
+                                'label_type'  => 'vertical',
297
+                                'class'       => 'getpaid-address-field',
298 298
                             ),
299 299
                             true
300
-						);
300
+                        );
301 301
 
302
-					}
302
+                    }
303 303
 
304
-					// Display the state.
305
-					elseif ( 'state' == $key ) {
304
+                    // Display the state.
305
+                    elseif ( 'state' == $key ) {
306 306
 
307
-						getpaid_get_states_select_markup(
307
+                        getpaid_get_states_select_markup(
308 308
                             $customer->get( 'country' ),
309
-							$value,
310
-							$label,
311
-							$label,
312
-							'',
313
-							false,
314
-							'',
315
-							'getpaid_address[' . esc_attr( $key ) . ']',
309
+                            $value,
310
+                            $label,
311
+                            $label,
312
+                            '',
313
+                            false,
314
+                            '',
315
+                            'getpaid_address[' . esc_attr( $key ) . ']',
316 316
                             true
317
-						);
317
+                        );
318 318
 
319 319
                         } else {
320 320
 
321
-						aui()->input(
321
+                        aui()->input(
322 322
                             array(
323 323
                                 'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
324 324
                                 'id'          => 'wpinv-' . sanitize_html_class( $key ),
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                                 'class'       => 'getpaid-address-field',
331 331
                             ),
332 332
                             true
333
-						);
333
+                        );
334 334
 
335 335
                         }
336 336
                     }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 function getpaid_allowed_html() {
475 475
     $allowed_html = wp_kses_allowed_html( 'post' );
476 476
 
477
-	// form fields
477
+    // form fields
478 478
     $allowed_html['form'] = array(
479 479
         'action'         => true,
480 480
         'accept'         => true,
@@ -486,12 +486,12 @@  discard block
 block discarded – undo
486 486
     );
487 487
 
488 488
     // - input
489
-	$allowed_html['input'] = array(
490
-		'class'        => array(),
491
-		'id'           => array(),
492
-		'name'         => array(),
493
-		'value'        => array(),
494
-		'type'         => array(),
489
+    $allowed_html['input'] = array(
490
+        'class'        => array(),
491
+        'id'           => array(),
492
+        'name'         => array(),
493
+        'value'        => array(),
494
+        'type'         => array(),
495 495
         'placeholder'  => array(),
496 496
         'autocomplete' => array(),
497 497
         'autofocus'    => array(),
@@ -505,33 +505,33 @@  discard block
 block discarded – undo
505 505
         'max'          => array(),
506 506
         'step'         => array(),
507 507
         'size'         => array(),
508
-	);
508
+    );
509 509
 
510 510
     // - input
511
-	$allowed_html['textarea'] = array(
512
-		'class' => array(),
513
-		'id'    => array(),
514
-		'name'  => array(),
515
-		'value' => array(),
516
-	);
517
-
518
-	// select
519
-	$allowed_html['select'] = array(
520
-		'class'        => array(),
521
-		'id'           => array(),
522
-		'name'         => array(),
511
+    $allowed_html['textarea'] = array(
512
+        'class' => array(),
513
+        'id'    => array(),
514
+        'name'  => array(),
515
+        'value' => array(),
516
+    );
517
+
518
+    // select
519
+    $allowed_html['select'] = array(
520
+        'class'        => array(),
521
+        'id'           => array(),
522
+        'name'         => array(),
523 523
         'autocomplete' => array(),
524 524
         'multiple'     => array(),
525
-	);
525
+    );
526 526
 
527
-	// select options
528
-	$allowed_html['option'] = array(
529
-		'selected' => array(),
527
+    // select options
528
+    $allowed_html['option'] = array(
529
+        'selected' => array(),
530 530
         'disabled' => array(),
531 531
         'value'    => array(),
532
-	);
532
+    );
533 533
 
534
-	return $allowed_html;
534
+    return $allowed_html;
535 535
 
536 536
 }
537 537
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-profile.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -5,110 +5,110 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit; // Exit if accessed directly
8
+    exit; // Exit if accessed directly
9 9
 }
10 10
 
11 11
 if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) :
12 12
 
13
-	/**
14
-	 * GetPaid_Admin_Profile Class.
15
-	 */
16
-	class GetPaid_Admin_Profile {
17
-
18
-		/**
19
-		 * Hook in tabs.
20
-		 */
21
-		public function __construct() {
22
-			add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
-			add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
-
25
-			add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
-			add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
-		}
28
-
29
-		/**
30
-		 * Get Address Fields for the edit user pages.
31
-		 *
32
-		 * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
-		 */
34
-		public function get_customer_meta_fields() {
35
-
36
-			$show_fields = apply_filters(
37
-				'getpaid_customer_meta_fields',
38
-				array(
39
-					'billing' => array(
40
-						'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
-						'fields' => array(
42
-							'_wpinv_first_name' => array(
43
-								'label'       => __( 'First name', 'invoicing' ),
44
-								'description' => '',
45
-							),
46
-							'_wpinv_last_name'  => array(
47
-								'label'       => __( 'Last name', 'invoicing' ),
48
-								'description' => '',
49
-							),
50
-							'_wpinv_company'    => array(
51
-								'label'       => __( 'Company', 'invoicing' ),
52
-								'description' => '',
53
-							),
54
-							'_wpinv_company_id' => array(
55
-								'label'       => __( 'Company ID', 'invoicing' ),
56
-								'description' => '',
57
-							),
58
-							'_wpinv_address'    => array(
59
-								'label'       => __( 'Address', 'invoicing' ),
60
-								'description' => '',
61
-							),
62
-							'_wpinv_city'       => array(
63
-								'label'       => __( 'City', 'invoicing' ),
64
-								'description' => '',
65
-							),
66
-							'_wpinv_zip'        => array(
67
-								'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
-								'description' => '',
69
-							),
70
-							'_wpinv_country'    => array(
71
-								'label'       => __( 'Country / Region', 'invoicing' ),
72
-								'description' => '',
73
-								'class'       => 'getpaid_js_field-country',
74
-								'type'        => 'select',
75
-								'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
-							),
77
-							'_wpinv_state'      => array(
78
-								'label'       => __( 'State / County', 'invoicing' ),
79
-								'description' => __( 'State / County or state code', 'invoicing' ),
80
-								'class'       => 'getpaid_js_field-state regular-text',
81
-							),
82
-							'_wpinv_phone'      => array(
83
-								'label'       => __( 'Phone', 'invoicing' ),
84
-								'description' => '',
85
-							),
86
-							'_wpinv_vat_number' => array(
87
-								'label'       => __( 'VAT Number', 'invoicing' ),
88
-								'description' => '',
89
-							),
90
-						),
91
-					),
92
-				)
93
-			);
94
-			return $show_fields;
95
-		}
96
-
97
-		/**
98
-		 * Show Address Fields on edit user pages.
99
-		 *
100
-		 * @param WP_User $user
101
-		 */
102
-		public function add_customer_meta_fields( $user ) {
103
-
104
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
-				return;
106
-			}
107
-
108
-			$show_fields = $this->get_customer_meta_fields();
109
-
110
-			foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
-				?>
13
+    /**
14
+     * GetPaid_Admin_Profile Class.
15
+     */
16
+    class GetPaid_Admin_Profile {
17
+
18
+        /**
19
+         * Hook in tabs.
20
+         */
21
+        public function __construct() {
22
+            add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
+            add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
+
25
+            add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
+            add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
+        }
28
+
29
+        /**
30
+         * Get Address Fields for the edit user pages.
31
+         *
32
+         * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
+         */
34
+        public function get_customer_meta_fields() {
35
+
36
+            $show_fields = apply_filters(
37
+                'getpaid_customer_meta_fields',
38
+                array(
39
+                    'billing' => array(
40
+                        'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
+                        'fields' => array(
42
+                            '_wpinv_first_name' => array(
43
+                                'label'       => __( 'First name', 'invoicing' ),
44
+                                'description' => '',
45
+                            ),
46
+                            '_wpinv_last_name'  => array(
47
+                                'label'       => __( 'Last name', 'invoicing' ),
48
+                                'description' => '',
49
+                            ),
50
+                            '_wpinv_company'    => array(
51
+                                'label'       => __( 'Company', 'invoicing' ),
52
+                                'description' => '',
53
+                            ),
54
+                            '_wpinv_company_id' => array(
55
+                                'label'       => __( 'Company ID', 'invoicing' ),
56
+                                'description' => '',
57
+                            ),
58
+                            '_wpinv_address'    => array(
59
+                                'label'       => __( 'Address', 'invoicing' ),
60
+                                'description' => '',
61
+                            ),
62
+                            '_wpinv_city'       => array(
63
+                                'label'       => __( 'City', 'invoicing' ),
64
+                                'description' => '',
65
+                            ),
66
+                            '_wpinv_zip'        => array(
67
+                                'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
+                                'description' => '',
69
+                            ),
70
+                            '_wpinv_country'    => array(
71
+                                'label'       => __( 'Country / Region', 'invoicing' ),
72
+                                'description' => '',
73
+                                'class'       => 'getpaid_js_field-country',
74
+                                'type'        => 'select',
75
+                                'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
+                            ),
77
+                            '_wpinv_state'      => array(
78
+                                'label'       => __( 'State / County', 'invoicing' ),
79
+                                'description' => __( 'State / County or state code', 'invoicing' ),
80
+                                'class'       => 'getpaid_js_field-state regular-text',
81
+                            ),
82
+                            '_wpinv_phone'      => array(
83
+                                'label'       => __( 'Phone', 'invoicing' ),
84
+                                'description' => '',
85
+                            ),
86
+                            '_wpinv_vat_number' => array(
87
+                                'label'       => __( 'VAT Number', 'invoicing' ),
88
+                                'description' => '',
89
+                            ),
90
+                        ),
91
+                    ),
92
+                )
93
+            );
94
+            return $show_fields;
95
+        }
96
+
97
+        /**
98
+         * Show Address Fields on edit user pages.
99
+         *
100
+         * @param WP_User $user
101
+         */
102
+        public function add_customer_meta_fields( $user ) {
103
+
104
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
+                return;
106
+            }
107
+
108
+            $show_fields = $this->get_customer_meta_fields();
109
+
110
+            foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
+                ?>
112 112
 				<h2><?php echo esc_html( $fieldset['title'] ); ?></h2>
113 113
 				<table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>">
114 114
 					<?php foreach ( $fieldset['fields'] as $key => $field ) : ?>
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 								<?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
121 121
 									<select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;">
122 122
 										<?php
123
-											$selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
-										foreach ( $field['options'] as $option_key => $option_value ) :
125
-											?>
123
+                                            $selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
+                                        foreach ( $field['options'] as $option_key => $option_value ) :
125
+                                            ?>
126 126
 											<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option>
127 127
 										<?php endforeach; ?>
128 128
 									</select>
@@ -137,59 +137,59 @@  discard block
 block discarded – undo
137 137
 					<?php endforeach; ?>
138 138
 				</table>
139 139
 				<?php
140
-			endforeach;
141
-		}
142
-
143
-		/**
144
-		 * Save Address Fields on edit user pages.
145
-		 *
146
-		 * @param int $user_id User ID of the user being saved
147
-		 */
148
-		public function save_customer_meta_fields( $user_id ) {
149
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
-				return;
151
-			}
152
-
153
-			$save_fields = $this->get_customer_meta_fields();
154
-
155
-			$customer = getpaid_get_customer_by_user_id( get_current_user_id() );
156
-
157
-			if ( empty( $customer ) ) {
158
-				$customer = new GetPaid_Customer( 0 );
159
-				$customer->clone_user( get_current_user_id() );
160
-			}
161
-
162
-			foreach ( $save_fields as $fieldset ) {
163
-
164
-				foreach ( $fieldset['fields'] as $key => $field ) {
165
-
166
-					if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
167
-						$customer->set( $key, ! empty( $_POST[ $key ] ) );
168
-					} elseif ( isset( $_POST[ $key ] ) ) {
169
-						$customer->set( $key, wpinv_clean( $_POST[ $key ] ) );
170
-					}
171
-				}
172
-			}
173
-		}
174
-
175
-		/**
176
-		 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
177
-		 *
178
-		 * @since 3.1.0
179
-		 * @param int    $user_id User ID of the user being edited
180
-		 * @param string $key     Key for user meta field
181
-		 * @return string
182
-		 */
183
-		protected function get_user_meta( $user_id, $key ) {
184
-			$value           = get_user_meta( $user_id, $key, true );
185
-			$existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
186
-			if ( ! $value && in_array( $key, $existing_fields ) ) {
187
-				$value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
188
-			}
189
-
190
-			return $value;
191
-		}
192
-	}
140
+            endforeach;
141
+        }
142
+
143
+        /**
144
+         * Save Address Fields on edit user pages.
145
+         *
146
+         * @param int $user_id User ID of the user being saved
147
+         */
148
+        public function save_customer_meta_fields( $user_id ) {
149
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
+                return;
151
+            }
152
+
153
+            $save_fields = $this->get_customer_meta_fields();
154
+
155
+            $customer = getpaid_get_customer_by_user_id( get_current_user_id() );
156
+
157
+            if ( empty( $customer ) ) {
158
+                $customer = new GetPaid_Customer( 0 );
159
+                $customer->clone_user( get_current_user_id() );
160
+            }
161
+
162
+            foreach ( $save_fields as $fieldset ) {
163
+
164
+                foreach ( $fieldset['fields'] as $key => $field ) {
165
+
166
+                    if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
167
+                        $customer->set( $key, ! empty( $_POST[ $key ] ) );
168
+                    } elseif ( isset( $_POST[ $key ] ) ) {
169
+                        $customer->set( $key, wpinv_clean( $_POST[ $key ] ) );
170
+                    }
171
+                }
172
+            }
173
+        }
174
+
175
+        /**
176
+         * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
177
+         *
178
+         * @since 3.1.0
179
+         * @param int    $user_id User ID of the user being edited
180
+         * @param string $key     Key for user meta field
181
+         * @return string
182
+         */
183
+        protected function get_user_meta( $user_id, $key ) {
184
+            $value           = get_user_meta( $user_id, $key, true );
185
+            $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
186
+            if ( ! $value && in_array( $key, $existing_fields ) ) {
187
+                $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
188
+            }
189
+
190
+            return $value;
191
+        }
192
+    }
193 193
 
194 194
 endif;
195 195
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +441 added lines, -441 removed lines patch added patch discarded remove patch
@@ -20,402 +20,402 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		$installed = get_option( 'gepaid_installed_on' );
52
-
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
55
-		}
56
-
57
-		if ( method_exists( $this, $method ) ) {
58
-			$this->$method();
59
-		}
60
-
61
-	}
62
-
63
-	/**
64
-	 * Do a fresh install.
65
-	 *
66
-	 */
67
-	public function upgrade_from_0() {
68
-
69
-		// Save default tax rates.
70
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
71
-	}
72
-
73
-	/**
74
-	 * Upgrade to 0.0.5
75
-	 *
76
-	 */
77
-	public function upgrade_from_004() {
78
-		global $wpdb;
79
-
80
-		// Invoices.
81
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
82
-		if ( ! empty( $results ) ) {
83
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
84
-
85
-			// Clean post cache
86
-			foreach ( $results as $row ) {
87
-				clean_post_cache( $row->ID );
88
-			}
89
-		}
90
-
91
-		// Item meta key changes
92
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
93
-		$results = $wpdb->get_results( $query );
94
-
95
-		if ( ! empty( $results ) ) {
96
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
97
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
98
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
99
-
100
-			foreach ( $results as $row ) {
101
-				clean_post_cache( $row->post_id );
102
-			}
103
-		}
104
-
105
-		$this->upgrade_from_118();
106
-	}
107
-
108
-	/**
109
-	 * Upgrade to version 2.0.0.
110
-	 *
111
-	 */
112
-	public function upgrade_from_118() {
113
-		$this->migrate_old_invoices();
114
-		$this->upgrade_from_279();
115
-	}
116
-
117
-	/**
118
-	 * Upgrade to version 2.0.0.
119
-	 *
120
-	 */
121
-	public function upgrade_from_279() {
122
-		$this->migrate_old_customers();
123
-	}
124
-
125
-	/**
126
-	 * Give administrators the capability to manage GetPaid.
127
-	 *
128
-	 */
129
-	public function add_capabilities() {
130
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
131
-	}
132
-
133
-	/**
134
-	 * Retreives GetPaid pages.
135
-	 *
136
-	 */
137
-	public static function get_pages() {
138
-
139
-		return apply_filters(
140
-			'wpinv_create_pages',
141
-			array(
142
-
143
-				// Checkout page.
144
-				'checkout_page'             => array(
145
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
146
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
147
-					'content' => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        $installed = get_option( 'gepaid_installed_on' );
52
+
53
+        if ( empty( $installed ) ) {
54
+            update_option( 'gepaid_installed_on', time() );
55
+        }
56
+
57
+        if ( method_exists( $this, $method ) ) {
58
+            $this->$method();
59
+        }
60
+
61
+    }
62
+
63
+    /**
64
+     * Do a fresh install.
65
+     *
66
+     */
67
+    public function upgrade_from_0() {
68
+
69
+        // Save default tax rates.
70
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
71
+    }
72
+
73
+    /**
74
+     * Upgrade to 0.0.5
75
+     *
76
+     */
77
+    public function upgrade_from_004() {
78
+        global $wpdb;
79
+
80
+        // Invoices.
81
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
82
+        if ( ! empty( $results ) ) {
83
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
84
+
85
+            // Clean post cache
86
+            foreach ( $results as $row ) {
87
+                clean_post_cache( $row->ID );
88
+            }
89
+        }
90
+
91
+        // Item meta key changes
92
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
93
+        $results = $wpdb->get_results( $query );
94
+
95
+        if ( ! empty( $results ) ) {
96
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
97
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
98
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
99
+
100
+            foreach ( $results as $row ) {
101
+                clean_post_cache( $row->post_id );
102
+            }
103
+        }
104
+
105
+        $this->upgrade_from_118();
106
+    }
107
+
108
+    /**
109
+     * Upgrade to version 2.0.0.
110
+     *
111
+     */
112
+    public function upgrade_from_118() {
113
+        $this->migrate_old_invoices();
114
+        $this->upgrade_from_279();
115
+    }
116
+
117
+    /**
118
+     * Upgrade to version 2.0.0.
119
+     *
120
+     */
121
+    public function upgrade_from_279() {
122
+        $this->migrate_old_customers();
123
+    }
124
+
125
+    /**
126
+     * Give administrators the capability to manage GetPaid.
127
+     *
128
+     */
129
+    public function add_capabilities() {
130
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
131
+    }
132
+
133
+    /**
134
+     * Retreives GetPaid pages.
135
+     *
136
+     */
137
+    public static function get_pages() {
138
+
139
+        return apply_filters(
140
+            'wpinv_create_pages',
141
+            array(
142
+
143
+                // Checkout page.
144
+                'checkout_page'             => array(
145
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
146
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
147
+                    'content' => '
148 148
 						<!-- wp:shortcode -->
149 149
 						[wpinv_checkout]
150 150
 						<!-- /wp:shortcode -->
151 151
 					',
152
-					'parent'  => '',
153
-				),
154
-
155
-				// Invoice history page.
156
-				'invoice_history_page'      => array(
157
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
158
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
159
-					'content' => '
152
+                    'parent'  => '',
153
+                ),
154
+
155
+                // Invoice history page.
156
+                'invoice_history_page'      => array(
157
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
158
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
159
+                    'content' => '
160 160
 					<!-- wp:shortcode -->
161 161
 					[wpinv_history]
162 162
 					<!-- /wp:shortcode -->
163 163
 				',
164
-					'parent'  => '',
165
-				),
166
-
167
-				// Success page content.
168
-				'success_page'              => array(
169
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
170
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
171
-					'content' => '
164
+                    'parent'  => '',
165
+                ),
166
+
167
+                // Success page content.
168
+                'success_page'              => array(
169
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
170
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
171
+                    'content' => '
172 172
 					<!-- wp:shortcode -->
173 173
 					[wpinv_receipt]
174 174
 					<!-- /wp:shortcode -->
175 175
 				',
176
-					'parent'  => 'gp-checkout',
177
-				),
178
-
179
-				// Failure page content.
180
-				'failure_page'              => array(
181
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
182
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
183
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
184
-					'parent'  => 'gp-checkout',
185
-				),
186
-
187
-				// Subscriptions history page.
188
-				'invoice_subscription_page' => array(
189
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
190
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
191
-					'content' => '
176
+                    'parent'  => 'gp-checkout',
177
+                ),
178
+
179
+                // Failure page content.
180
+                'failure_page'              => array(
181
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
182
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
183
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
184
+                    'parent'  => 'gp-checkout',
185
+                ),
186
+
187
+                // Subscriptions history page.
188
+                'invoice_subscription_page' => array(
189
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
190
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
191
+                    'content' => '
192 192
 					<!-- wp:shortcode -->
193 193
 					[wpinv_subscriptions]
194 194
 					<!-- /wp:shortcode -->
195 195
 				',
196
-					'parent'  => '',
197
-				),
198
-
199
-			)
200
-		);
201
-
202
-	}
203
-
204
-	/**
205
-	 * Re-create GetPaid pages.
206
-	 *
207
-	 */
208
-	public function create_pages() {
209
-
210
-		foreach ( self::get_pages() as $key => $page ) {
211
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
212
-		}
213
-
214
-	}
215
-
216
-	/**
217
-	 * Migrates old invoices to new invoices.
218
-	 *
219
-	 */
220
-	public function migrate_old_invoices() {
221
-		global $wpdb;
222
-
223
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
224
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
225
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
226
-		$invoices            = array_unique(
227
-			get_posts(
228
-				array(
229
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
230
-					'posts_per_page' => -1,
231
-					'fields'         => 'ids',
232
-					'post_status'    => array_keys( get_post_stati() ),
233
-					'exclude'        => (array) $migrated,
234
-				)
235
-			)
236
-		);
237
-
238
-		// Abort if we do not have any invoices.
239
-		if ( empty( $invoices ) ) {
240
-			return;
241
-		}
242
-
243
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
244
-
245
-		$invoice_rows = array();
246
-		foreach ( $invoices as $invoice ) {
247
-
248
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
249
-
250
-			if ( empty( $invoice->ID ) ) {
251
-				return;
252
-			}
253
-
254
-			$fields = array(
255
-				'post_id'            => $invoice->ID,
256
-				'number'             => $invoice->get_number(),
257
-				'key'                => $invoice->get_key(),
258
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
259
-				'mode'               => $invoice->mode,
260
-				'user_ip'            => $invoice->get_ip(),
261
-				'first_name'         => $invoice->get_first_name(),
262
-				'last_name'          => $invoice->get_last_name(),
263
-				'address'            => $invoice->get_address(),
264
-				'city'               => $invoice->city,
265
-				'state'              => $invoice->state,
266
-				'country'            => $invoice->country,
267
-				'zip'                => $invoice->zip,
268
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
269
-				'gateway'            => $invoice->get_gateway(),
270
-				'transaction_id'     => $invoice->get_transaction_id(),
271
-				'currency'           => $invoice->get_currency(),
272
-				'subtotal'           => $invoice->get_subtotal(),
273
-				'tax'                => $invoice->get_tax(),
274
-				'fees_total'         => $invoice->get_fees_total(),
275
-				'total'              => $invoice->get_total(),
276
-				'discount'           => $invoice->get_discount(),
277
-				'discount_code'      => $invoice->get_discount_code(),
278
-				'disable_taxes'      => $invoice->disable_taxes,
279
-				'due_date'           => $invoice->get_due_date(),
280
-				'completed_date'     => $invoice->get_completed_date(),
281
-				'company'            => $invoice->company,
282
-				'vat_number'         => $invoice->vat_number,
283
-				'vat_rate'           => $invoice->vat_rate,
284
-				'custom_meta'        => $invoice->payment_meta,
285
-			);
286
-
287
-			foreach ( $fields as $key => $val ) {
288
-				if ( is_null( $val ) ) {
289
-					$val = '';
290
-				}
291
-				$val = maybe_serialize( $val );
292
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
293
-			}
294
-
295
-			$fields = implode( ', ', $fields );
296
-			$invoice_rows[] = "($fields)";
297
-
298
-			$item_rows    = array();
299
-			$item_columns = array();
300
-			foreach ( $invoice->get_cart_details() as $details ) {
301
-				$fields = array(
302
-					'post_id'          => $invoice->ID,
303
-					'item_id'          => $details['id'],
304
-					'item_name'        => $details['name'],
305
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
306
-					'vat_rate'         => $details['vat_rate'],
307
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
308
-					'tax'              => $details['tax'],
309
-					'item_price'       => $details['item_price'],
310
-					'custom_price'     => $details['custom_price'],
311
-					'quantity'         => $details['quantity'],
312
-					'discount'         => $details['discount'],
313
-					'subtotal'         => $details['subtotal'],
314
-					'price'            => $details['price'],
315
-					'meta'             => $details['meta'],
316
-					'fees'             => $details['fees'],
317
-				);
318
-
319
-				$item_columns = array_keys( $fields );
320
-
321
-				foreach ( $fields as $key => $val ) {
322
-					if ( is_null( $val ) ) {
323
-						$val = '';
324
-					}
325
-					$val = maybe_serialize( $val );
326
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
327
-				}
328
-
329
-				$fields = implode( ', ', $fields );
330
-				$item_rows[] = "($fields)";
331
-			}
332
-
333
-			$item_rows    = implode( ', ', $item_rows );
334
-			$item_columns = implode( ', ', $item_columns );
335
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
336
-		}
337
-
338
-		if ( empty( $invoice_rows ) ) {
339
-			return;
340
-		}
341
-
342
-		$invoice_rows = implode( ', ', $invoice_rows );
343
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
344
-
345
-	}
346
-
347
-	/**
348
-	 * Migrates old customers to new table.
349
-	 *
350
-	 */
351
-	public function migrate_old_customers() {
352
-		global $wpdb;
353
-
354
-		// Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
355
-		$invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
356
-
357
-		foreach ( $invoice_ids as $invoice_id ) {
358
-			$invoice = wpinv_get_invoice( $invoice_id );
359
-
360
-			if ( empty( $invoice ) ) {
361
-				continue;
362
-			}
363
-
364
-			// Fetch customer from the user ID.
365
-			$user_id = $invoice->get_user_id();
366
-
367
-			if ( empty( $user_id ) ) {
368
-				continue;
369
-			}
370
-
371
-			$customer = getpaid_get_customer_by_user_id( $user_id );
372
-
373
-			// Create if not exists.
374
-			if ( empty( $customer ) ) {
375
-				$customer = new GetPaid_Customer( 0 );
376
-				$customer->clone_user( $user_id );
377
-				$customer->save();
378
-			}
379
-
380
-			$invoice->set_customer_id( $customer->get_id() );
381
-			$invoice->save();
382
-		}
383
-
384
-	}
385
-
386
-	/**
387
-	 * Migrates old invoices to new invoices.
388
-	 *
389
-	 */
390
-	public static function rename_gateways_label() {
391
-		global $wpdb;
392
-
393
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
394
-
395
-			$wpdb->update(
396
-				$wpdb->prefix . 'getpaid_invoices',
397
-				array( 'gateway' => $gateway ),
398
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
399
-				'%s',
400
-				'%s'
401
-			);
402
-
403
-		}
404
-	}
405
-
406
-	/**
407
-	 * Returns the DB schema.
408
-	 *
409
-	 */
410
-	public static function get_db_schema() {
411
-		global $wpdb;
412
-
413
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
414
-
415
-		$charset_collate = $wpdb->get_charset_collate();
196
+                    'parent'  => '',
197
+                ),
198
+
199
+            )
200
+        );
201
+
202
+    }
203
+
204
+    /**
205
+     * Re-create GetPaid pages.
206
+     *
207
+     */
208
+    public function create_pages() {
209
+
210
+        foreach ( self::get_pages() as $key => $page ) {
211
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
212
+        }
213
+
214
+    }
215
+
216
+    /**
217
+     * Migrates old invoices to new invoices.
218
+     *
219
+     */
220
+    public function migrate_old_invoices() {
221
+        global $wpdb;
222
+
223
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
224
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
225
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
226
+        $invoices            = array_unique(
227
+            get_posts(
228
+                array(
229
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
230
+                    'posts_per_page' => -1,
231
+                    'fields'         => 'ids',
232
+                    'post_status'    => array_keys( get_post_stati() ),
233
+                    'exclude'        => (array) $migrated,
234
+                )
235
+            )
236
+        );
237
+
238
+        // Abort if we do not have any invoices.
239
+        if ( empty( $invoices ) ) {
240
+            return;
241
+        }
242
+
243
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
244
+
245
+        $invoice_rows = array();
246
+        foreach ( $invoices as $invoice ) {
247
+
248
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
249
+
250
+            if ( empty( $invoice->ID ) ) {
251
+                return;
252
+            }
253
+
254
+            $fields = array(
255
+                'post_id'            => $invoice->ID,
256
+                'number'             => $invoice->get_number(),
257
+                'key'                => $invoice->get_key(),
258
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
259
+                'mode'               => $invoice->mode,
260
+                'user_ip'            => $invoice->get_ip(),
261
+                'first_name'         => $invoice->get_first_name(),
262
+                'last_name'          => $invoice->get_last_name(),
263
+                'address'            => $invoice->get_address(),
264
+                'city'               => $invoice->city,
265
+                'state'              => $invoice->state,
266
+                'country'            => $invoice->country,
267
+                'zip'                => $invoice->zip,
268
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
269
+                'gateway'            => $invoice->get_gateway(),
270
+                'transaction_id'     => $invoice->get_transaction_id(),
271
+                'currency'           => $invoice->get_currency(),
272
+                'subtotal'           => $invoice->get_subtotal(),
273
+                'tax'                => $invoice->get_tax(),
274
+                'fees_total'         => $invoice->get_fees_total(),
275
+                'total'              => $invoice->get_total(),
276
+                'discount'           => $invoice->get_discount(),
277
+                'discount_code'      => $invoice->get_discount_code(),
278
+                'disable_taxes'      => $invoice->disable_taxes,
279
+                'due_date'           => $invoice->get_due_date(),
280
+                'completed_date'     => $invoice->get_completed_date(),
281
+                'company'            => $invoice->company,
282
+                'vat_number'         => $invoice->vat_number,
283
+                'vat_rate'           => $invoice->vat_rate,
284
+                'custom_meta'        => $invoice->payment_meta,
285
+            );
286
+
287
+            foreach ( $fields as $key => $val ) {
288
+                if ( is_null( $val ) ) {
289
+                    $val = '';
290
+                }
291
+                $val = maybe_serialize( $val );
292
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
293
+            }
294
+
295
+            $fields = implode( ', ', $fields );
296
+            $invoice_rows[] = "($fields)";
297
+
298
+            $item_rows    = array();
299
+            $item_columns = array();
300
+            foreach ( $invoice->get_cart_details() as $details ) {
301
+                $fields = array(
302
+                    'post_id'          => $invoice->ID,
303
+                    'item_id'          => $details['id'],
304
+                    'item_name'        => $details['name'],
305
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
306
+                    'vat_rate'         => $details['vat_rate'],
307
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
308
+                    'tax'              => $details['tax'],
309
+                    'item_price'       => $details['item_price'],
310
+                    'custom_price'     => $details['custom_price'],
311
+                    'quantity'         => $details['quantity'],
312
+                    'discount'         => $details['discount'],
313
+                    'subtotal'         => $details['subtotal'],
314
+                    'price'            => $details['price'],
315
+                    'meta'             => $details['meta'],
316
+                    'fees'             => $details['fees'],
317
+                );
318
+
319
+                $item_columns = array_keys( $fields );
320
+
321
+                foreach ( $fields as $key => $val ) {
322
+                    if ( is_null( $val ) ) {
323
+                        $val = '';
324
+                    }
325
+                    $val = maybe_serialize( $val );
326
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
327
+                }
328
+
329
+                $fields = implode( ', ', $fields );
330
+                $item_rows[] = "($fields)";
331
+            }
332
+
333
+            $item_rows    = implode( ', ', $item_rows );
334
+            $item_columns = implode( ', ', $item_columns );
335
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
336
+        }
337
+
338
+        if ( empty( $invoice_rows ) ) {
339
+            return;
340
+        }
341
+
342
+        $invoice_rows = implode( ', ', $invoice_rows );
343
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
344
+
345
+    }
346
+
347
+    /**
348
+     * Migrates old customers to new table.
349
+     *
350
+     */
351
+    public function migrate_old_customers() {
352
+        global $wpdb;
353
+
354
+        // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
355
+        $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
356
+
357
+        foreach ( $invoice_ids as $invoice_id ) {
358
+            $invoice = wpinv_get_invoice( $invoice_id );
359
+
360
+            if ( empty( $invoice ) ) {
361
+                continue;
362
+            }
363
+
364
+            // Fetch customer from the user ID.
365
+            $user_id = $invoice->get_user_id();
366
+
367
+            if ( empty( $user_id ) ) {
368
+                continue;
369
+            }
370
+
371
+            $customer = getpaid_get_customer_by_user_id( $user_id );
372
+
373
+            // Create if not exists.
374
+            if ( empty( $customer ) ) {
375
+                $customer = new GetPaid_Customer( 0 );
376
+                $customer->clone_user( $user_id );
377
+                $customer->save();
378
+            }
379
+
380
+            $invoice->set_customer_id( $customer->get_id() );
381
+            $invoice->save();
382
+        }
383
+
384
+    }
385
+
386
+    /**
387
+     * Migrates old invoices to new invoices.
388
+     *
389
+     */
390
+    public static function rename_gateways_label() {
391
+        global $wpdb;
392
+
393
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
394
+
395
+            $wpdb->update(
396
+                $wpdb->prefix . 'getpaid_invoices',
397
+                array( 'gateway' => $gateway ),
398
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
399
+                '%s',
400
+                '%s'
401
+            );
402
+
403
+        }
404
+    }
405
+
406
+    /**
407
+     * Returns the DB schema.
408
+     *
409
+     */
410
+    public static function get_db_schema() {
411
+        global $wpdb;
412
+
413
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
414
+
415
+        $charset_collate = $wpdb->get_charset_collate();
416 416
 
417
-		// Subscriptions.
418
-		$schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
417
+        // Subscriptions.
418
+        $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
419 419
 			id bigint(20) unsigned NOT NULL auto_increment,
420 420
 			customer_id bigint(20) NOT NULL,
421 421
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
 			KEY customer_and_status (customer_id, status)
439 439
 		  ) $charset_collate;";
440 440
 
441
-		// Invoices.
442
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
441
+        // Invoices.
442
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
443 443
 			post_id BIGINT(20) NOT NULL,
444 444
 			customer_id BIGINT(20) NOT NULL DEFAULT 0,
445 445
             `number` VARCHAR(100),
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
 			KEY `key` (`key`)
477 477
 		  ) $charset_collate;";
478 478
 
479
-		// Invoice items.
480
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
479
+        // Invoice items.
480
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
481 481
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
482 482
             post_id BIGINT(20) NOT NULL,
483 483
             item_id BIGINT(20) NOT NULL,
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
 			KEY post_id (post_id)
500 500
 		  ) $charset_collate;";
501 501
 
502
-		// Customers.
503
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers (
502
+        // Customers.
503
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers (
504 504
 			id BIGINT(20) NOT NULL AUTO_INCREMENT,
505 505
 			user_id BIGINT(20) NOT NULL,
506 506
 			email VARCHAR(100) NOT NULL,
@@ -510,38 +510,38 @@  discard block
 block discarded – undo
510 510
 			purchase_count BIGINT(20) NOT NULL DEFAULT 0,
511 511
 			";
512 512
 
513
-		// Add address fields.
514
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
513
+        // Add address fields.
514
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
515 515
 
516
-			// Skip id, user_id and email.
517
-			if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
518
-				continue;
519
-			}
516
+            // Skip id, user_id and email.
517
+            if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
518
+                continue;
519
+            }
520 520
 
521
-			$field   = sanitize_key( $field );
522
-			$length  = 100;
523
-			$default = '';
521
+            $field   = sanitize_key( $field );
522
+            $length  = 100;
523
+            $default = '';
524 524
 
525
-			// Country.
526
-			if ( 'country' === $field ) {
527
-				$length  = 2;
528
-				$default = wpinv_get_default_country();
529
-			}
525
+            // Country.
526
+            if ( 'country' === $field ) {
527
+                $length  = 2;
528
+                $default = wpinv_get_default_country();
529
+            }
530 530
 
531
-			// State.
532
-			if ( 'state' === $field ) {
533
-				$default = wpinv_get_default_state();
534
-			}
531
+            // State.
532
+            if ( 'state' === $field ) {
533
+                $default = wpinv_get_default_state();
534
+            }
535 535
 
536
-			// Phone, zip.
537
-			if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
538
-				$length = 20;
539
-			}
536
+            // Phone, zip.
537
+            if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
538
+                $length = 20;
539
+            }
540 540
 
541
-			$schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',";
542
-		}
541
+            $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',";
542
+        }
543 543
 
544
-		$schema .= "
544
+        $schema .= "
545 545
 			date_created DATETIME NOT NULL,
546 546
 			date_modified DATETIME NOT NULL,
547 547
 			uuid VARCHAR(100) NOT NULL,
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 			KEY email (email)
551 551
 		  ) $charset_collate;";
552 552
 
553
-		// Customer meta.
554
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
553
+        // Customer meta.
554
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
555 555
 			meta_id BIGINT(20) NOT NULL AUTO_INCREMENT,
556 556
 			customer_id BIGINT(20) NOT NULL,
557 557
 			meta_key VARCHAR(255) NOT NULL,
@@ -561,41 +561,41 @@  discard block
 block discarded – undo
561 561
 			KEY meta_key (meta_key(191))
562 562
 		  ) $charset_collate;";
563 563
 
564
-		return $schema;
565
-	}
564
+        return $schema;
565
+    }
566 566
 
567
-	/**
568
-	 * Checks if the db schema is up to date.
569
-	 *
570
-	 * @return bool
571
-	 */
572
-	public static function is_db_schema_up_to_date() {
573
-		return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' );
574
-	}
567
+    /**
568
+     * Checks if the db schema is up to date.
569
+     *
570
+     * @return bool
571
+     */
572
+    public static function is_db_schema_up_to_date() {
573
+        return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' );
574
+    }
575 575
 
576
-	/**
577
-	 * Set up the database tables which the plugin needs to function.
578
-	 */
579
-	public static function create_db_tables() {
580
-		global $wpdb;
576
+    /**
577
+     * Set up the database tables which the plugin needs to function.
578
+     */
579
+    public static function create_db_tables() {
580
+        global $wpdb;
581 581
 
582
-		$wpdb->hide_errors();
582
+        $wpdb->hide_errors();
583 583
 
584
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
584
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
585 585
 
586
-		$schema = self::get_db_schema();
586
+        $schema = self::get_db_schema();
587 587
 
588
-		dbDelta( $schema );
588
+        dbDelta( $schema );
589 589
 
590
-		update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) );
591
-	}
590
+        update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) );
591
+    }
592 592
 
593
-	/**
594
-	 * Creates tables if schema is not up to date.
595
-	 */
596
-	public static function maybe_create_db_tables() {
597
-		if ( ! self::is_db_schema_up_to_date() ) {
598
-			self::create_db_tables();
599
-		}
600
-	}
593
+    /**
594
+     * Creates tables if schema is not up to date.
595
+     */
596
+    public static function maybe_create_db_tables() {
597
+        if ( ! self::is_db_schema_up_to_date() ) {
598
+            self::create_db_tables();
599
+        }
600
+    }
601 601
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-customers-table.php 1 patch
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 // Load WP_List_Table if not loaded
13 13
 if ( ! class_exists( 'WP_List_Table' ) ) {
14
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
14
+    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
15 15
 }
16 16
 
17 17
 /**
@@ -23,323 +23,323 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class WPInv_Customers_Table extends WP_List_Table {
25 25
 
26
-	/**
27
-	 * @var int Number of items per page
28
-	 * @since 1.0.19
29
-	 */
30
-	public $per_page = 10;
31
-
32
-	/**
33
-	 * @var int Number of items
34
-	 * @since 1.0.19
35
-	 */
36
-	public $total = 0;
37
-
38
-	/**
39
-	 * Get things started
40
-	 *
41
-	 * @since 1.0.19
42
-	 * @see WP_List_Table::__construct()
43
-	 */
44
-	public function __construct() {
45
-
46
-		// Set parent defaults
47
-		parent::__construct(
26
+    /**
27
+     * @var int Number of items per page
28
+     * @since 1.0.19
29
+     */
30
+    public $per_page = 10;
31
+
32
+    /**
33
+     * @var int Number of items
34
+     * @since 1.0.19
35
+     */
36
+    public $total = 0;
37
+
38
+    /**
39
+     * Get things started
40
+     *
41
+     * @since 1.0.19
42
+     * @see WP_List_Table::__construct()
43
+     */
44
+    public function __construct() {
45
+
46
+        // Set parent defaults
47
+        parent::__construct(
48 48
             array(
49
-				'singular' => 'id',
50
-				'plural'   => 'ids',
51
-				'ajax'     => false,
49
+                'singular' => 'id',
50
+                'plural'   => 'ids',
51
+                'ajax'     => false,
52 52
             )
53 53
         );
54 54
 
55
-	}
56
-
57
-	/**
58
-	 * Gets the name of the primary column.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @access protected
62
-	 *
63
-	 * @return string Name of the primary column.
64
-	 */
65
-	protected function get_primary_column_name() {
66
-		return 'name';
67
-	}
68
-
69
-	/**
70
-	 * This function renders most of the columns in the list table.
71
-	 *
72
-	 * @since 1.0.19
73
-	 *
74
-	 * @param WP_User $item
75
-	 * @param string $column_name The name of the column
76
-	 *
77
-	 * @return string Column Name
78
-	 */
79
-	public function column_default( $item, $column_name ) {
80
-		$value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
81
-		return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
82
-	}
83
-
84
-	/**
85
-	 * Displays the country column.
86
-	 *
87
-	 * @since 1.0.19
88
-	 *
89
-	 * @param WP_User $user
90
-	 *
91
-	 * @return string Column Name
92
-	 */
93
-	public function column_country( $user ) {
94
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
95
-		if ( $country ) {
96
-			$country = wpinv_country_name( $country );
97
-		}
98
-		return esc_html( $country );
99
-	}
100
-
101
-	/**
102
-	 * Displays the state column.
103
-	 *
104
-	 * @since 1.0.19
105
-	 *
106
-	 * @param WP_User $user
107
-	 *
108
-	 * @return string Column Name
109
-	 */
110
-	public function column_state( $user ) {
111
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
112
-		$state   = $user->_wpinv_state;
113
-		if ( $state ) {
114
-			$state = wpinv_state_name( $state, $country );
115
-		}
116
-
117
-		return esc_html( $state );
118
-	}
119
-
120
-	/**
121
-	 * Displays the signup column.
122
-	 *
123
-	 * @since 1.0.19
124
-	 *
125
-	 * @param WP_User $user
126
-	 *
127
-	 * @return string Column Name
128
-	 */
129
-	public function column_signup( $user ) {
130
-		return getpaid_format_date_value( $user->user_registered );
131
-	}
132
-
133
-	/**
134
-	 * Displays the total spent column.
135
-	 *
136
-	 * @since 1.0.19
137
-	 *
138
-	 * @param WP_User $user
139
-	 *
140
-	 * @return string Column Name
141
-	 */
142
-	public function column_total( $user ) {
143
-		return wpinv_price( $this->column_total_raw( $user ) );
144
-	}
145
-
146
-	/**
147
-	 * Displays the total spent column.
148
-	 *
149
-	 * @since 1.0.19
150
-	 *
151
-	 * @param WP_User $user
152
-	 *
153
-	 * @return float
154
-	 */
155
-	public function column_total_raw( $user ) {
156
-		return getpaid_get_user_total_spend( $user->ID );
157
-	}
158
-
159
-	/**
160
-	 * Displays the total spent column.
161
-	 *
162
-	 * @since 1.0.19
163
-	 *
164
-	 * @param WP_User $user
165
-	 *
166
-	 * @return string Column Name
167
-	 */
168
-	public function column_invoices( $user ) {
169
-		$value = getpaid_count_user_invoices( $user->ID );
170
-		$url   = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) );
171
-		return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>';
172
-
173
-	}
174
-
175
-	/**
176
-	 * Generates content for a single row of the table
177
-	 * @since 1.0.19
178
-	 *
179
-	 * @param int $item The user id.
180
-	 */
181
-	public function single_row( $item ) {
182
-		$item = get_user_by( 'id', $item );
183
-
184
-		if ( empty( $item ) ) {
185
-			return;
186
-		}
187
-
188
-		echo '<tr>';
189
-		$this->single_row_columns( $item );
190
-		echo '</tr>';
191
-	}
192
-
193
-	/**
194
-	 * Displays the customers name
195
-	 *
196
-	 * @param  WP_User $customer customer.
197
-	 * @return string
198
-	 */
199
-	public function column_name( $customer ) {
200
-
201
-		// Customer view URL.
202
-		$view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
203
-		$row_actions = $this->row_actions(
204
-			array(
205
-				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
206
-			)
207
-		);
208
-
209
-		// Get user's address.
210
-		$address = wpinv_get_user_address( $customer->ID );
211
-
212
-		// Customer email address.
213
-		$email       = sanitize_email( $customer->user_email );
214
-
215
-		// Customer's avatar.
216
-		$avatar = esc_url( get_avatar_url( $email ) );
217
-		$avatar = "<img src='$avatar' height='32' width='32'/>";
218
-
219
-		// Customer's name.
220
-		$name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
221
-
222
-		if ( empty( trim( $name ) ) ) {
223
-			$name = esc_html( $address['display_name'] );
224
-		}
225
-
226
-		if ( ! empty( $name ) ) {
227
-			$name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
228
-		}
229
-
230
-		$email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
231
-
232
-		return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
233
-
234
-	}
235
-
236
-	/**
237
-	 * Retrieve the table columns
238
-	 *
239
-	 * @since 1.0.19
240
-	 * @return array $columns Array of all the list table columns
241
-	 */
242
-	public function get_columns() {
243
-
244
-		$columns = array(
245
-			'name'     => __( 'Name', 'invoicing' ),
246
-			'country'  => __( 'Country', 'invoicing' ),
247
-			'state'    => __( 'State', 'invoicing' ),
248
-			'city'     => __( 'City', 'invoicing' ),
249
-			'zip'      => __( 'ZIP', 'invoicing' ),
250
-			'address'  => __( 'Address', 'invoicing' ),
251
-			'phone'    => __( 'Phone', 'invoicing' ),
252
-			'company'  => __( 'Company', 'invoicing' ),
253
-			'invoices' => __( 'Invoices', 'invoicing' ),
254
-			'total'    => __( 'Total Spend', 'invoicing' ),
255
-			'signup'   => __( 'Date created', 'invoicing' ),
256
-		);
257
-		return apply_filters( 'wpinv_customers_table_columns', $columns );
258
-
259
-	}
260
-
261
-	/**
262
-	 * Retrieve the current page number
263
-	 *
264
-	 * @since 1.0.19
265
-	 * @return int Current page number
266
-	 */
267
-	public function get_paged() {
268
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
269
-	}
270
-
271
-	/**
272
-	 * Returns bulk actions.
273
-	 *
274
-	 * @since 1.0.19
275
-	 * @return void
276
-	 */
277
-	public function bulk_actions( $which = '' ) {
278
-		return array();
279
-	}
280
-
281
-	/**
282
-	 *  Prepares the display query
283
-	 */
284
-	public function prepare_query() {
285
-		global $wpdb;
286
-
287
-		$post_types = '';
288
-
289
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
290
-			$post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
291
-		}
292
-
293
-		$post_types = rtrim( $post_types, ' OR' );
294
-
295
-		// Maybe search.
296
-		if ( ! empty( $_POST['s'] ) ) {
297
-			$users = get_users(
298
-				array(
299
-					'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
300
-					'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
301
-					'fields'         => 'ID',
302
-				)
303
-			);
304
-
305
-			$users      = implode( ', ', $users );
306
-			$post_types = "($post_types) AND ( post_author IN ( $users ) )";
307
-		}
308
-
309
-		// Users with invoices.
310
-    	$customers = $wpdb->get_col(
311
-			$wpdb->prepare(
312
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
313
-				$this->get_paged() * 10 - 10,
314
-				$this->per_page
315
-			)
316
-		);
317
-
318
-		$this->items = $customers;
319
-		$this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
320
-
321
-	}
322
-
323
-	/**
324
-	 * Setup the final data for the table
325
-	 *
326
-	 * @since 1.0.19
327
-	 * @return void
328
-	 */
329
-	public function prepare_items() {
330
-		$columns               = $this->get_columns();
331
-		$hidden                = array(); // No hidden columns
332
-		$sortable              = $this->get_sortable_columns();
333
-		$this->_column_headers = array( $columns, $hidden, $sortable );
334
-		$this->prepare_query();
335
-
336
-		$this->set_pagination_args(
337
-			array(
338
-				'total_items' => $this->total,
339
-				'per_page'    => $this->per_page,
340
-				'total_pages' => ceil( $this->total / $this->per_page ),
341
-			)
342
-		);
343
-
344
-	}
55
+    }
56
+
57
+    /**
58
+     * Gets the name of the primary column.
59
+     *
60
+     * @since 1.0.19
61
+     * @access protected
62
+     *
63
+     * @return string Name of the primary column.
64
+     */
65
+    protected function get_primary_column_name() {
66
+        return 'name';
67
+    }
68
+
69
+    /**
70
+     * This function renders most of the columns in the list table.
71
+     *
72
+     * @since 1.0.19
73
+     *
74
+     * @param WP_User $item
75
+     * @param string $column_name The name of the column
76
+     *
77
+     * @return string Column Name
78
+     */
79
+    public function column_default( $item, $column_name ) {
80
+        $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
81
+        return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
82
+    }
83
+
84
+    /**
85
+     * Displays the country column.
86
+     *
87
+     * @since 1.0.19
88
+     *
89
+     * @param WP_User $user
90
+     *
91
+     * @return string Column Name
92
+     */
93
+    public function column_country( $user ) {
94
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
95
+        if ( $country ) {
96
+            $country = wpinv_country_name( $country );
97
+        }
98
+        return esc_html( $country );
99
+    }
100
+
101
+    /**
102
+     * Displays the state column.
103
+     *
104
+     * @since 1.0.19
105
+     *
106
+     * @param WP_User $user
107
+     *
108
+     * @return string Column Name
109
+     */
110
+    public function column_state( $user ) {
111
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
112
+        $state   = $user->_wpinv_state;
113
+        if ( $state ) {
114
+            $state = wpinv_state_name( $state, $country );
115
+        }
116
+
117
+        return esc_html( $state );
118
+    }
119
+
120
+    /**
121
+     * Displays the signup column.
122
+     *
123
+     * @since 1.0.19
124
+     *
125
+     * @param WP_User $user
126
+     *
127
+     * @return string Column Name
128
+     */
129
+    public function column_signup( $user ) {
130
+        return getpaid_format_date_value( $user->user_registered );
131
+    }
132
+
133
+    /**
134
+     * Displays the total spent column.
135
+     *
136
+     * @since 1.0.19
137
+     *
138
+     * @param WP_User $user
139
+     *
140
+     * @return string Column Name
141
+     */
142
+    public function column_total( $user ) {
143
+        return wpinv_price( $this->column_total_raw( $user ) );
144
+    }
145
+
146
+    /**
147
+     * Displays the total spent column.
148
+     *
149
+     * @since 1.0.19
150
+     *
151
+     * @param WP_User $user
152
+     *
153
+     * @return float
154
+     */
155
+    public function column_total_raw( $user ) {
156
+        return getpaid_get_user_total_spend( $user->ID );
157
+    }
158
+
159
+    /**
160
+     * Displays the total spent column.
161
+     *
162
+     * @since 1.0.19
163
+     *
164
+     * @param WP_User $user
165
+     *
166
+     * @return string Column Name
167
+     */
168
+    public function column_invoices( $user ) {
169
+        $value = getpaid_count_user_invoices( $user->ID );
170
+        $url   = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) );
171
+        return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>';
172
+
173
+    }
174
+
175
+    /**
176
+     * Generates content for a single row of the table
177
+     * @since 1.0.19
178
+     *
179
+     * @param int $item The user id.
180
+     */
181
+    public function single_row( $item ) {
182
+        $item = get_user_by( 'id', $item );
183
+
184
+        if ( empty( $item ) ) {
185
+            return;
186
+        }
187
+
188
+        echo '<tr>';
189
+        $this->single_row_columns( $item );
190
+        echo '</tr>';
191
+    }
192
+
193
+    /**
194
+     * Displays the customers name
195
+     *
196
+     * @param  WP_User $customer customer.
197
+     * @return string
198
+     */
199
+    public function column_name( $customer ) {
200
+
201
+        // Customer view URL.
202
+        $view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
203
+        $row_actions = $this->row_actions(
204
+            array(
205
+                'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
206
+            )
207
+        );
208
+
209
+        // Get user's address.
210
+        $address = wpinv_get_user_address( $customer->ID );
211
+
212
+        // Customer email address.
213
+        $email       = sanitize_email( $customer->user_email );
214
+
215
+        // Customer's avatar.
216
+        $avatar = esc_url( get_avatar_url( $email ) );
217
+        $avatar = "<img src='$avatar' height='32' width='32'/>";
218
+
219
+        // Customer's name.
220
+        $name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
221
+
222
+        if ( empty( trim( $name ) ) ) {
223
+            $name = esc_html( $address['display_name'] );
224
+        }
225
+
226
+        if ( ! empty( $name ) ) {
227
+            $name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
228
+        }
229
+
230
+        $email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
231
+
232
+        return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
233
+
234
+    }
235
+
236
+    /**
237
+     * Retrieve the table columns
238
+     *
239
+     * @since 1.0.19
240
+     * @return array $columns Array of all the list table columns
241
+     */
242
+    public function get_columns() {
243
+
244
+        $columns = array(
245
+            'name'     => __( 'Name', 'invoicing' ),
246
+            'country'  => __( 'Country', 'invoicing' ),
247
+            'state'    => __( 'State', 'invoicing' ),
248
+            'city'     => __( 'City', 'invoicing' ),
249
+            'zip'      => __( 'ZIP', 'invoicing' ),
250
+            'address'  => __( 'Address', 'invoicing' ),
251
+            'phone'    => __( 'Phone', 'invoicing' ),
252
+            'company'  => __( 'Company', 'invoicing' ),
253
+            'invoices' => __( 'Invoices', 'invoicing' ),
254
+            'total'    => __( 'Total Spend', 'invoicing' ),
255
+            'signup'   => __( 'Date created', 'invoicing' ),
256
+        );
257
+        return apply_filters( 'wpinv_customers_table_columns', $columns );
258
+
259
+    }
260
+
261
+    /**
262
+     * Retrieve the current page number
263
+     *
264
+     * @since 1.0.19
265
+     * @return int Current page number
266
+     */
267
+    public function get_paged() {
268
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
269
+    }
270
+
271
+    /**
272
+     * Returns bulk actions.
273
+     *
274
+     * @since 1.0.19
275
+     * @return void
276
+     */
277
+    public function bulk_actions( $which = '' ) {
278
+        return array();
279
+    }
280
+
281
+    /**
282
+     *  Prepares the display query
283
+     */
284
+    public function prepare_query() {
285
+        global $wpdb;
286
+
287
+        $post_types = '';
288
+
289
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
290
+            $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
291
+        }
292
+
293
+        $post_types = rtrim( $post_types, ' OR' );
294
+
295
+        // Maybe search.
296
+        if ( ! empty( $_POST['s'] ) ) {
297
+            $users = get_users(
298
+                array(
299
+                    'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
300
+                    'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
301
+                    'fields'         => 'ID',
302
+                )
303
+            );
304
+
305
+            $users      = implode( ', ', $users );
306
+            $post_types = "($post_types) AND ( post_author IN ( $users ) )";
307
+        }
308
+
309
+        // Users with invoices.
310
+        $customers = $wpdb->get_col(
311
+            $wpdb->prepare(
312
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
313
+                $this->get_paged() * 10 - 10,
314
+                $this->per_page
315
+            )
316
+        );
317
+
318
+        $this->items = $customers;
319
+        $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
320
+
321
+    }
322
+
323
+    /**
324
+     * Setup the final data for the table
325
+     *
326
+     * @since 1.0.19
327
+     * @return void
328
+     */
329
+    public function prepare_items() {
330
+        $columns               = $this->get_columns();
331
+        $hidden                = array(); // No hidden columns
332
+        $sortable              = $this->get_sortable_columns();
333
+        $this->_column_headers = array( $columns, $hidden, $sortable );
334
+        $this->prepare_query();
335
+
336
+        $this->set_pagination_args(
337
+            array(
338
+                'total_items' => $this->total,
339
+                'per_page'    => $this->per_page,
340
+                'total_pages' => ceil( $this->total / $this->per_page ),
341
+            )
342
+        );
343
+
344
+    }
345 345
 }
Please login to merge, or discard this patch.