Passed
Push — master ( c1548d...55a972 )
by Brian
04:30
created
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_address(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_address(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,28 +311,28 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319
-                        'name'                 => __( 'TAX', 'invoicing' ),
319
+                        'name'                 => __('TAX', 'invoicing'),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330 330
 
331
-        if ( 0 == $invoice->get_total_tax() ) {
332
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
331
+        if (0 == $invoice->get_total_tax()) {
332
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
333 333
         }
334 334
 
335
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
335
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
336 336
 
337 337
     }
338 338
 
@@ -342,29 +342,29 @@  discard block
 block discarded – undo
342 342
      * @param stdClass $result Api response.
343 343
 	 * @param WPInv_Invoice $invoice Invoice.
344 344
 	 */
345
-	public function process_charge_response( $result, $invoice ) {
345
+	public function process_charge_response($result, $invoice) {
346 346
 
347 347
         wpinv_clear_errors();
348 348
 		$response_code = (int) $result->transactionResponse->responseCode;
349 349
 
350 350
 		// Succeeded.
351
-		if ( 1 == $response_code || 4 == $response_code ) {
351
+		if (1 == $response_code || 4 == $response_code) {
352 352
 
353 353
 			// Maybe set a transaction id.
354
-			if ( ! empty( $result->transactionResponse->transId ) ) {
355
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
354
+			if (!empty($result->transactionResponse->transId)) {
355
+				$invoice->set_transaction_id($result->transactionResponse->transId);
356 356
 			}
357 357
 
358
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
358
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
359 359
 
360
-			if ( 1 == $response_code ) {
360
+			if (1 == $response_code) {
361 361
 				return $invoice->mark_paid();
362 362
 			}
363 363
 
364
-			$invoice->set_status( 'wpi-onhold' );
364
+			$invoice->set_status('wpi-onhold');
365 365
         	$invoice->add_note(
366 366
                 sprintf(
367
-                    __( 'Held for review: %s', 'invoicing' ),
367
+                    __('Held for review: %s', 'invoicing'),
368 368
                     $result->transactionResponse->messages->message[0]->description
369 369
                 )
370 370
 			);
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
 
374 374
 		}
375 375
 
376
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
376
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
377 377
 
378
-        if ( ! empty( $result->transactionResponse->errors ) ) {
378
+        if (!empty($result->transactionResponse->errors)) {
379 379
             $errors = (object) $result->transactionResponse->errors;
380
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
380
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
381 381
         }
382 382
 
383 383
     }
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 	 * @param array $card Card details.
390 390
 	 * @return array
391 391
 	 */
392
-	public function get_payment_information( $card ) {
392
+	public function get_payment_information($card) {
393 393
         return array(
394 394
 
395
-            'creditCard'         => array (
395
+            'creditCard'         => array(
396 396
                 'cardNumber'     => $card['cc_number'],
397 397
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
398 398
                 'cardCode'       => $card['cc_cvv2'],
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param WPInv_Invoice $invoice Invoice.
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_customer_profile_meta_name( $invoice ) {
412
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
411
+	public function get_customer_profile_meta_name($invoice) {
412
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
413 413
     }
414 414
 
415 415
     /**
@@ -420,34 +420,34 @@  discard block
 block discarded – undo
420 420
      * @param WPInv_Invoice $invoice
421 421
 	 * @return WP_Error|string The payment profile id
422 422
 	 */
423
-	public function validate_submission_data( $submission_data, $invoice ) {
423
+	public function validate_submission_data($submission_data, $invoice) {
424 424
 
425 425
         // Validate authentication details.
426 426
         $auth = $this->get_auth_params();
427 427
 
428
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
429
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
428
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
429
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
430 430
         }
431 431
 
432 432
         // Validate the payment method.
433
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
434
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
433
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
434
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
435 435
         }
436 436
 
437 437
         // Are we adding a new payment method?
438
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
438
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
439 439
             return $submission_data['getpaid-authorizenet-payment-method'];
440 440
         }
441 441
 
442 442
         // Retrieve the customer profile id.
443
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
443
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
444 444
 
445 445
         // Create payment method.
446
-        if ( empty( $profile_id ) ) {
447
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
446
+        if (empty($profile_id)) {
447
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
448 448
         }
449 449
 
450
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
450
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
451 451
 
452 452
     }
453 453
 
@@ -458,16 +458,16 @@  discard block
 block discarded – undo
458 458
 	 * @param WPInv_Invoice $invoice Invoice.
459 459
 	 * @return array
460 460
 	 */
461
-	public function get_line_items( $invoice ) {
461
+	public function get_line_items($invoice) {
462 462
         $items = array();
463 463
 
464
-        foreach ( $invoice->get_items() as $item ) {
464
+        foreach ($invoice->get_items() as $item) {
465 465
 
466 466
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
467 467
             $items[] = array(
468
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
469
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
470
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
468
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
469
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
470
+                'description' => getpaid_limit_length($item->get_description(), 255),
471 471
                 'quantity'    => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
472 472
                 'unitPrice'   => (float) $amount,
473 473
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -475,15 +475,15 @@  discard block
 block discarded – undo
475 475
 
476 476
         }
477 477
 
478
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
478
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
479 479
 
480
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
480
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
481 481
 
482
-            if ( $amount > 0 ) {
482
+            if ($amount > 0) {
483 483
                 $items[] = array(
484
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
485
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
486
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
484
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
485
+                    'name'        => getpaid_limit_length($fee_name, 31),
486
+                    'description' => getpaid_limit_length($fee_name, 255),
487 487
                     'quantity'    => '1',
488 488
                     'unitPrice'   => (float) $amount,
489 489
                     'taxable'     => false,
@@ -504,36 +504,36 @@  discard block
 block discarded – undo
504 504
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505 505
 	 * @return array
506 506
 	 */
507
-	public function process_payment( $invoice, $submission_data, $submission ) {
507
+	public function process_payment($invoice, $submission_data, $submission) {
508 508
 
509 509
         // Validate the submitted data.
510
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
510
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
511 511
 
512 512
         // Do we have an error?
513
-        if ( is_wp_error( $payment_profile_id ) ) {
514
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
515
-            wpinv_send_back_to_checkout( $invoice );
513
+        if (is_wp_error($payment_profile_id)) {
514
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
515
+            wpinv_send_back_to_checkout($invoice);
516 516
         }
517 517
 
518 518
         // Save the payment method to the order.
519
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
519
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
520 520
 
521 521
         // Check if this is a subscription or not.
522
-        $subscription = getpaid_get_invoice_subscription( $invoice );
523
-        if ( ! empty( $subscription ) ) {
524
-            $this->process_subscription( $invoice, $subscription );
522
+        $subscription = getpaid_get_invoice_subscription($invoice);
523
+        if (!empty($subscription)) {
524
+            $this->process_subscription($invoice, $subscription);
525 525
         }
526 526
 
527 527
         // If it is free, send to the success page.
528
-        if ( ! $invoice->needs_payment() ) {
528
+        if (!$invoice->needs_payment()) {
529 529
             $invoice->mark_paid();
530
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
530
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
531 531
         }
532 532
 
533 533
         // Charge the payment profile.
534
-        $this->process_initial_payment( $invoice );
534
+        $this->process_initial_payment($invoice);
535 535
 
536
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
536
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
537 537
 
538 538
         exit;
539 539
 
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
 	 *
545 545
      * @param WPInv_Invoice $invoice Invoice.
546 546
 	 */
547
-	protected function process_initial_payment( $invoice ) {
547
+	protected function process_initial_payment($invoice) {
548 548
 
549
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
550
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
551
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
549
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
550
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
551
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
552 552
 
553 553
 		// Do we have an error?
554
-		if ( is_wp_error( $result ) ) {
555
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
-			wpinv_send_back_to_checkout( $invoice );
554
+		if (is_wp_error($result)) {
555
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
556
+			wpinv_send_back_to_checkout($invoice);
557 557
 		}
558 558
 
559 559
 		// Process the response.
560
-		$this->process_charge_response( $result, $invoice );
560
+		$this->process_charge_response($result, $invoice);
561 561
 
562
-		if ( wpinv_get_errors() ) {
563
-			wpinv_send_back_to_checkout( $invoice );
562
+		if (wpinv_get_errors()) {
563
+			wpinv_send_back_to_checkout($invoice);
564 564
 		}
565 565
 
566 566
 	}
@@ -571,24 +571,24 @@  discard block
 block discarded – undo
571 571
      * @param WPInv_Invoice $invoice Invoice.
572 572
      * @param WPInv_Subscription $subscription Subscription.
573 573
 	 */
574
-	public function process_subscription( $invoice, $subscription ) {
574
+	public function process_subscription($invoice, $subscription) {
575 575
 
576 576
         // Check if there is an initial amount to charge.
577
-        if ( (float) $invoice->get_total() > 0 ) {
578
-			$this->process_initial_payment( $invoice );
577
+        if ((float) $invoice->get_total() > 0) {
578
+			$this->process_initial_payment($invoice);
579 579
         }
580 580
 
581 581
         // Activate the subscription.
582
-        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
583
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
582
+        $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
583
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
584 584
 
585
-		$subscription->set_next_renewal_date( $expiry );
586
-		$subscription->set_date_created( current_time( 'mysql' ) );
587
-		$subscription->set_profile_id( $invoice->generate_key() );
585
+		$subscription->set_next_renewal_date($expiry);
586
+		$subscription->set_date_created(current_time('mysql'));
587
+		$subscription->set_profile_id($invoice->generate_key());
588 588
 		$subscription->activate();
589 589
 
590 590
 		// Redirect to the success page.
591
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
591
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
592 592
 
593 593
     }
594 594
 
@@ -599,20 +599,20 @@  discard block
 block discarded – undo
599 599
 	 * @param bool $should_expire
600 600
      * @param WPInv_Subscription $subscription
601 601
 	 */
602
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
602
+	public function maybe_renew_subscription($should_expire, $subscription) {
603 603
 
604 604
         // Ensure its our subscription && it's active.
605
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
605
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
606 606
             return $should_expire;
607 607
         }
608 608
 
609 609
         // If this is the last renewal, complete the subscription.
610
-        if ( $subscription->is_last_renewal() ) {
610
+        if ($subscription->is_last_renewal()) {
611 611
             $subscription->complete();
612 612
             return false;
613 613
         }
614 614
 
615
-        $this->renew_subscription( $subscription );
615
+        $this->renew_subscription($subscription);
616 616
 
617 617
         return false;
618 618
 
@@ -623,28 +623,28 @@  discard block
 block discarded – undo
623 623
 	 *
624 624
      * @param WPInv_Subscription $subscription
625 625
 	 */
626
-	public function renew_subscription( $subscription ) {
626
+	public function renew_subscription($subscription) {
627 627
 
628 628
 		// Generate the renewal invoice.
629 629
 		$new_invoice = $subscription->create_payment();
630 630
 		$old_invoice = $subscription->get_parent_payment();
631 631
 
632
-        if ( empty( $new_invoice ) ) {
633
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
632
+        if (empty($new_invoice)) {
633
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
634 634
             $subscription->failing();
635 635
             return;
636 636
         }
637 637
 
638 638
         // Charge the payment method.
639
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
639
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
640
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
641
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
642 642
 
643 643
 		// Do we have an error?
644
-		if ( is_wp_error( $result ) ) {
644
+		if (is_wp_error($result)) {
645 645
 
646 646
 			$old_invoice->add_note(
647
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
647
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
648 648
 				true,
649 649
 				false,
650 650
 				true
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 		}
656 656
 
657 657
 		// Process the response.
658
-		$this->process_charge_response( $result, $new_invoice );
658
+		$this->process_charge_response($result, $new_invoice);
659 659
 
660
-		if ( wpinv_get_errors() ) {
660
+		if (wpinv_get_errors()) {
661 661
 
662 662
 			$old_invoice->add_note(
663
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
663
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
664 664
 				true,
665 665
 				false,
666 666
 				true
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
         }
672 672
 
673
-        $subscription->add_payment( array(), $new_invoice );
673
+        $subscription->add_payment(array(), $new_invoice);
674 674
         $subscription->renew();
675 675
     }
676 676
 
@@ -681,34 +681,34 @@  discard block
 block discarded – undo
681 681
 	 * @param GetPaid_Form_Item[] $items
682 682
 	 * @return WPInv_Invoice
683 683
 	 */
684
-	public function process_addons( $invoice, $items ) {
684
+	public function process_addons($invoice, $items) {
685 685
 
686 686
         global $getpaid_authorize_addons;
687 687
 
688 688
         $getpaid_authorize_addons = array();
689
-        foreach ( $items as $item ) {
689
+        foreach ($items as $item) {
690 690
 
691
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
691
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
692 692
                 $getpaid_authorize_addons[] = $item;
693 693
             }
694 694
 
695 695
         }
696 696
 
697
-        if ( empty( $getpaid_authorize_addons ) ) {
697
+        if (empty($getpaid_authorize_addons)) {
698 698
             return;
699 699
         }
700 700
 
701 701
         $invoice->recalculate_total();
702 702
 
703
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
704
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
703
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
704
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
705 705
 
706
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
707
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
708
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
706
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
707
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
708
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
709 709
 
710
-        if ( is_wp_error( $result ) ) {
711
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
710
+        if (is_wp_error($result)) {
711
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
712 712
             return;
713 713
         }
714 714
 
@@ -721,19 +721,19 @@  discard block
 block discarded – undo
721 721
      * @param array $args
722 722
 	 * @return array
723 723
 	 */
724
-    public function filter_addons_request( $args ) {
724
+    public function filter_addons_request($args) {
725 725
 
726 726
         global $getpaid_authorize_addons;
727 727
         $total = 0;
728 728
 
729
-        foreach ( $getpaid_authorize_addons as $addon ) {
729
+        foreach ($getpaid_authorize_addons as $addon) {
730 730
             $total += $addon->get_sub_total();
731 731
         }
732 732
 
733 733
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
734 734
 
735
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
736
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
735
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
736
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
737 737
         }
738 738
 
739 739
         return $args;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
     public function sandbox_notice() {
747 747
 
748 748
         return sprintf(
749
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
749
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
750 750
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
751 751
             '</a>'
752 752
         );
@@ -758,42 +758,42 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @param array $admin_settings
760 760
 	 */
761
-	public function admin_settings( $admin_settings ) {
761
+	public function admin_settings($admin_settings) {
762 762
 
763 763
         $currencies = sprintf(
764
-            __( 'Supported Currencies: %s', 'invoicing' ),
765
-            implode( ', ', $this->currencies )
764
+            __('Supported Currencies: %s', 'invoicing'),
765
+            implode(', ', $this->currencies)
766 766
         );
767 767
 
768 768
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
769
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
769
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
770 770
 
771 771
         $admin_settings['authorizenet_login_id'] = array(
772 772
             'type' => 'text',
773 773
             'id'   => 'authorizenet_login_id',
774
-            'name' => __( 'API Login ID', 'invoicing' ),
775
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
774
+            'name' => __('API Login ID', 'invoicing'),
775
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
776 776
         );
777 777
 
778 778
         $admin_settings['authorizenet_transaction_key'] = array(
779 779
             'type' => 'text',
780 780
             'id'   => 'authorizenet_transaction_key',
781
-            'name' => __( 'Transaction Key', 'invoicing' ),
781
+            'name' => __('Transaction Key', 'invoicing'),
782 782
         );
783 783
 
784 784
         $admin_settings['authorizenet_signature_key'] = array(
785 785
             'type' => 'text',
786 786
             'id'   => 'authorizenet_signature_key',
787
-            'name' => __( 'Signature Key', 'invoicing' ),
788
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
787
+            'name' => __('Signature Key', 'invoicing'),
788
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
789 789
         );
790 790
 
791 791
         $admin_settings['authorizenet_ipn_url'] = array(
792 792
             'type'     => 'ipn_url',
793 793
             'id'       => 'authorizenet_ipn_url',
794
-            'name'     => __( 'Webhook URL', 'invoicing' ),
794
+            'name'     => __('Webhook URL', 'invoicing'),
795 795
             'std'      => $this->notify_url,
796
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
796
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
797 797
             'custom'   => 'authorizenet',
798 798
             'readonly' => true,
799 799
         );
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains gateway functions.
4 4
  *
5 5
  */
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Returns an array of payment gateways.
@@ -11,82 +11,82 @@  discard block
 block discarded – undo
11 11
  * @return array
12 12
  */
13 13
 function wpinv_get_payment_gateways() {
14
-    return apply_filters( 'wpinv_payment_gateways', array() );
14
+    return apply_filters('wpinv_payment_gateways', array());
15 15
 }
16 16
 
17
-function wpinv_payment_gateway_titles( $all_gateways ) {
17
+function wpinv_payment_gateway_titles($all_gateways) {
18 18
     global $wpinv_options;
19 19
 
20 20
     $gateways = array();
21
-    foreach ( $all_gateways as $key => $gateway ) {
22
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
23
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
21
+    foreach ($all_gateways as $key => $gateway) {
22
+        if (!empty($wpinv_options[$key . '_title'])) {
23
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
24 24
         }
25 25
 
26
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
26
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
27 27
     }
28 28
 
29
-    asort( $gateways );
29
+    asort($gateways);
30 30
 
31
-    foreach ( $gateways as $gateway => $key ) {
31
+    foreach ($gateways as $gateway => $key) {
32 32
         $gateways[$gateway] = $all_gateways[$gateway];
33 33
     }
34 34
 
35 35
     return $gateways;
36 36
 }
37
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
37
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
38 38
 
39
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
39
+function wpinv_get_enabled_payment_gateways($sort = false) {
40 40
     $gateways = wpinv_get_payment_gateways();
41
-    $enabled  = wpinv_get_option( 'gateways', array( 'manual' => 1 ) );
41
+    $enabled  = wpinv_get_option('gateways', array('manual' => 1));
42 42
 
43 43
     $gateway_list = array();
44 44
 
45
-    foreach ( $gateways as $key => $gateway ) {
46
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
47
-            $gateway_list[ $key ] = $gateway;
45
+    foreach ($gateways as $key => $gateway) {
46
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
47
+            $gateway_list[$key] = $gateway;
48 48
         }
49 49
     }
50 50
 
51
-    if ( true === $sort ) {
52
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
51
+    if (true === $sort) {
52
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
53 53
         
54 54
         // Reorder our gateways so the default is first
55 55
         $default_gateway_id = wpinv_get_default_gateway();
56 56
 
57
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
58
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
59
-            unset( $gateway_list[ $default_gateway_id ] );
57
+        if (wpinv_is_gateway_active($default_gateway_id)) {
58
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
59
+            unset($gateway_list[$default_gateway_id]);
60 60
 
61
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
61
+            $gateway_list = array_merge($default_gateway, $gateway_list);
62 62
         }
63 63
     }
64 64
 
65
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
65
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
66 66
 }
67 67
 
68
-function wpinv_sort_gateway_order( $a, $b ) {
68
+function wpinv_sort_gateway_order($a, $b) {
69 69
     return $a['ordering'] - $b['ordering'];
70 70
 }
71 71
 
72
-function wpinv_is_gateway_active( $gateway ) {
72
+function wpinv_is_gateway_active($gateway) {
73 73
     $gateways = wpinv_get_enabled_payment_gateways();
74 74
 
75
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
75
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
76 76
 
77
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
77
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
78 78
 }
79 79
 
80 80
 function wpinv_get_default_gateway() {
81
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
81
+    $default = wpinv_get_option('default_gateway', 'paypal');
82 82
 
83
-    if ( !wpinv_is_gateway_active( $default ) ) {
83
+    if (!wpinv_is_gateway_active($default)) {
84 84
         $gateways = wpinv_get_enabled_payment_gateways();
85
-        $gateways = array_keys( $gateways );
86
-        $default  = reset( $gateways );
85
+        $gateways = array_keys($gateways);
86
+        $default  = reset($gateways);
87 87
     }
88 88
 
89
-    return apply_filters( 'wpinv_default_gateway', $default );
89
+    return apply_filters('wpinv_default_gateway', $default);
90 90
 }
91 91
 
92 92
 /**
@@ -95,17 +95,17 @@  discard block
 block discarded – undo
95 95
  * @param string $gateway The gateway to key.
96 96
  * @return string
97 97
  */
98
-function wpinv_get_gateway_admin_label( $gateway ) {
98
+function wpinv_get_gateway_admin_label($gateway) {
99 99
 
100
-    if ( empty( $gateway ) || 'none' == $gateway ) {
101
-        return esc_html__( 'No Gateway', 'invoicing' );
100
+    if (empty($gateway) || 'none' == $gateway) {
101
+        return esc_html__('No Gateway', 'invoicing');
102 102
     }
103 103
 
104 104
     $gateways = wpinv_get_payment_gateways();
105
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
106
-    $gateway  = apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
105
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
106
+    $gateway  = apply_filters('wpinv_gateway_admin_label', $label, $gateway);
107 107
 
108
-    return wpinv_clean( $gateway );
108
+    return wpinv_clean($gateway);
109 109
 }
110 110
 
111 111
 /**
@@ -113,49 +113,49 @@  discard block
 block discarded – undo
113 113
  * 
114 114
  * @param string $gateway
115 115
  */
116
-function wpinv_get_gateway_description( $gateway ) {
116
+function wpinv_get_gateway_description($gateway) {
117 117
     global $wpinv_options;
118 118
 
119
-    $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
119
+    $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
120 120
 
121
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
121
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
122 122
 }
123 123
 
124
-function wpinv_get_gateway_button_label( $gateway ) {
125
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
124
+function wpinv_get_gateway_button_label($gateway) {
125
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
126 126
 }
127 127
 
128
-function wpinv_get_gateway_checkout_label( $gateway ) {
128
+function wpinv_get_gateway_checkout_label($gateway) {
129 129
     $gateways = wpinv_get_payment_gateways();
130
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
130
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
131 131
 
132
-    if ( $gateway == 'none' ) {
133
-        $label = __( 'None', 'invoicing' );
132
+    if ($gateway == 'none') {
133
+        $label = __('None', 'invoicing');
134 134
     }
135 135
 
136
-    return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway );
136
+    return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway);
137 137
 }
138 138
 
139
-function wpinv_settings_sections_gateways( $settings ) {
139
+function wpinv_settings_sections_gateways($settings) {
140 140
     $gateways = wpinv_get_payment_gateways();
141 141
     
142 142
     if (!empty($gateways)) {
143
-        foreach  ($gateways as $key => $gateway) {
143
+        foreach ($gateways as $key => $gateway) {
144 144
             $settings[$key] = $gateway['admin_label'];
145 145
         }
146 146
     }
147 147
     
148 148
     return $settings;    
149 149
 }
150
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
150
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
151 151
 
152 152
 /**
153 153
  * Adds GateWay settings.
154 154
  */
155
-function wpinv_settings_gateways( $settings ) {
155
+function wpinv_settings_gateways($settings) {
156 156
 
157 157
     // Loop through each gateway.
158
-    foreach  ( wpinv_get_payment_gateways() as $key => $gateway ) {
158
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
159 159
 
160 160
         $gateway_settings = array(
161 161
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             "{$key}_header" => array(
164 164
 
165 165
                 'id'     => "{$key}_gateway_header",
166
-                'name'   => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
166
+                'name'   => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
167 167
                 'custom' => $key,
168 168
                 'type'   => 'gateway_header',
169 169
 
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
             // Activate/Deactivate a gateway.
173 173
             "{$key}_active" => array(
174 174
                 'id'   => $key . '_active',
175
-                'name' => __( 'Activate', 'invoicing' ),
176
-                'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
175
+                'name' => __('Activate', 'invoicing'),
176
+                'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
177 177
                 'type' => 'checkbox',
178 178
             ),
179 179
 
180 180
             // Activate/Deactivate sandbox.
181 181
             "{$key}_sandbox" => array(
182 182
                 'id'   => $key . '_sandbox',
183
-                'name' => __( 'Sandbox', 'invoicing' ),
184
-                'desc' => __( 'Enable sandbox to test payments', 'invoicing' ),
183
+                'name' => __('Sandbox', 'invoicing'),
184
+                'desc' => __('Enable sandbox to test payments', 'invoicing'),
185 185
                 'type' => 'checkbox',
186 186
                 'std'  => '1',
187 187
             ),
@@ -189,40 +189,40 @@  discard block
 block discarded – undo
189 189
             // Checkout title.
190 190
             "{$key}_title" => array(
191 191
                 'id'   => $key . '_title',
192
-                'name' => __( 'Checkout Title', 'invoicing' ),
193
-                'std'  => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '',
192
+                'name' => __('Checkout Title', 'invoicing'),
193
+                'std'  => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '',
194 194
                 'type' => 'text',
195 195
             ),
196 196
 
197 197
             // Checkout description.
198 198
             "{$key}_desc" => array(
199 199
                 'id'   => $key . '_desc',
200
-                'name' => __( 'Checkout Description', 'invoicing' ),
201
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
200
+                'name' => __('Checkout Description', 'invoicing'),
201
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
202 202
                 'type' => 'text',
203 203
             ),
204 204
 
205 205
             // Checkout order.
206 206
             "{$key}_ordering" => array(
207 207
                 'id'   => $key . '_ordering',
208
-                'name' => __( 'Priority', 'invoicing' ),
209
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
208
+                'name' => __('Priority', 'invoicing'),
209
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
210 210
                 'type' => 'number',
211 211
                 'step' => '1',
212 212
                 'min'  => '0',
213 213
                 'max'  => '100000',
214
-                'std'  => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10',
214
+                'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
215 215
             ),
216 216
 
217 217
         );
218 218
 
219 219
         // Maybe remove the sandbox.
220
-        if ( ! apply_filters( "wpinv_{$key}_supports_sandbox", false ) ) {
221
-            unset( $gateway_settings["{$key}_sandbox"] );
220
+        if (!apply_filters("wpinv_{$key}_supports_sandbox", false)) {
221
+            unset($gateway_settings["{$key}_sandbox"]);
222 222
         }
223 223
   
224
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway );
225
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway );
224
+        $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway);
225
+        $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway);
226 226
         
227 227
         $settings[$key] = $gateway_settings;
228 228
     }
@@ -230,57 +230,57 @@  discard block
 block discarded – undo
230 230
     return $settings;
231 231
 
232 232
 }
233
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
233
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
234 234
 
235
-function wpinv_gateway_header_callback( $args ) {
236
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
235
+function wpinv_gateway_header_callback($args) {
236
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
237 237
 }
238 238
 
239
-function wpinv_get_gateway_supports( $gateway ) {
239
+function wpinv_get_gateway_supports($gateway) {
240 240
     $gateways = wpinv_get_enabled_payment_gateways();
241
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
242
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
241
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
242
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
243 243
 }
244 244
 
245
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
246
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
245
+function wpinv_get_chosen_gateway($invoice_id = 0) {
246
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
247 247
 
248 248
     $chosen = false;
249
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
249
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
250 250
         $chosen = $invoice->get_gateway();
251 251
     }
252 252
 
253
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
253
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
254 254
 
255
-	if ( false !== $chosen ) {
256
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
255
+	if (false !== $chosen) {
256
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
257 257
 	}
258 258
 
259
-	if ( ! empty ( $chosen ) ) {
260
-		$enabled_gateway = urldecode( $chosen );
261
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
259
+	if (!empty ($chosen)) {
260
+		$enabled_gateway = urldecode($chosen);
261
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
262 262
 		$enabled_gateway = 'manual';
263 263
 	} else {
264 264
 		$enabled_gateway = wpinv_get_default_gateway();
265 265
 	}
266 266
     
267
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
268
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
267
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
268
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
269 269
             $enabled_gateway = wpinv_get_default_gateway();
270
-        }else{
270
+        } else {
271 271
             $enabled_gateway = $gateways[0];
272 272
         }
273 273
 
274 274
     }
275 275
 
276
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
276
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
277 277
 }
278 278
 
279
-function wpinv_record_gateway_error( $title = '', $message = '' ) {
280
-    return wpinv_error_log( $message, $title );
279
+function wpinv_record_gateway_error($title = '', $message = '') {
280
+    return wpinv_error_log($message, $title);
281 281
 }
282 282
 
283
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
283
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
284 284
 	$ret  = 0;
285 285
 	$args = array(
286 286
 		'meta_key'    => '_wpinv_gateway',
@@ -291,48 +291,48 @@  discard block
 block discarded – undo
291 291
 		'fields'      => 'ids'
292 292
 	);
293 293
 
294
-	$payments = new WP_Query( $args );
294
+	$payments = new WP_Query($args);
295 295
 
296
-	if( $payments )
296
+	if ($payments)
297 297
 		$ret = $payments->post_count;
298 298
 	return $ret;
299 299
 }
300 300
 
301
-function wpinv_settings_update_gateways( $input ) {
301
+function wpinv_settings_update_gateways($input) {
302 302
     global $wpinv_options;
303 303
     
304
-    if ( !empty( $input['save_gateway'] ) ) {
305
-        $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) );
304
+    if (!empty($input['save_gateway'])) {
305
+        $gateways = wpinv_get_option('gateways', array('manual' => 1));
306 306
         $gateways = !empty($gateways) ? $gateways : array();
307 307
         $gateway = $input['save_gateway'];
308 308
         
309
-        if ( !empty( $input[$gateway . '_active'] ) ) {
309
+        if (!empty($input[$gateway . '_active'])) {
310 310
             $gateways[$gateway] = 1;
311 311
         } else {
312
-            if ( isset( $gateways[$gateway] ) ) {
313
-                unset( $gateways[$gateway] );
312
+            if (isset($gateways[$gateway])) {
313
+                unset($gateways[$gateway]);
314 314
             }
315 315
         }
316 316
         
317 317
         $input['gateways'] = $gateways;
318 318
     }
319 319
     
320
-    if ( !empty( $input['default_gateway'] ) ) {
320
+    if (!empty($input['default_gateway'])) {
321 321
         $gateways = wpinv_get_payment_gateways();
322 322
         
323
-        foreach ( $gateways as $key => $gateway ) {
324
-            $active   = 0;
325
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
323
+        foreach ($gateways as $key => $gateway) {
324
+            $active = 0;
325
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
326 326
                 $active = 1;
327 327
             }
328 328
             
329 329
             $input[$key . '_active'] = $active;
330 330
             
331
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
331
+            if (empty($wpinv_options[$key . '_title'])) {
332 332
                 $input[$key . '_title'] = $gateway['checkout_label'];
333 333
             }
334 334
             
335
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
335
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
336 336
                 $input[$key . '_ordering'] = $gateway['ordering'];
337 337
             }
338 338
         }
@@ -340,27 +340,27 @@  discard block
 block discarded – undo
340 340
     
341 341
     return $input;
342 342
 }
343
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
343
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
344 344
 
345 345
 // PayPal Standard settings
346
-function wpinv_gateway_settings_paypal( $setting ) {    
347
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
348
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
346
+function wpinv_gateway_settings_paypal($setting) {    
347
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
348
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
349 349
     
350 350
     $setting['paypal_sandbox'] = array(
351 351
             'type' => 'checkbox',
352 352
             'id'   => 'paypal_sandbox',
353
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
354
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
353
+            'name' => __('PayPal Sandbox', 'invoicing'),
354
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
355 355
             'std'  => 1
356 356
         );
357 357
         
358 358
     $setting['paypal_email'] = array(
359 359
             'type' => 'text',
360 360
             'id'   => 'paypal_email',
361
-            'name' => __( 'PayPal Email', 'invoicing' ),
362
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
363
-            'std' => __( '[email protected]', 'invoicing' ),
361
+            'name' => __('PayPal Email', 'invoicing'),
362
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
363
+            'std' => __('[email protected]', 'invoicing'),
364 364
         );
365 365
     /*
366 366
     $setting['paypal_ipn_url'] = array(
@@ -374,18 +374,18 @@  discard block
 block discarded – undo
374 374
         
375 375
     return $setting;
376 376
 }
377
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
377
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
378 378
 
379 379
 /**
380 380
  * Displays the ipn url field.
381 381
  */
382
-function wpinv_ipn_url_callback( $args ) {
383
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
382
+function wpinv_ipn_url_callback($args) {
383
+    $sanitize_id = wpinv_sanitize_key($args['id']);
384 384
     
385 385
     $attrs = $args['readonly'] ? ' readonly' : '';
386 386
 
387
-    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
388
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
387
+    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
388
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
389 389
 
390 390
     echo $html;
391 391
 }
@@ -397,10 +397,10 @@  discard block
 block discarded – undo
397 397
  *
398 398
  * @return bool
399 399
  */
400
-function wpinv_is_test_mode( $gateway = '' ) {
401
-    $sandbox  = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", true );
402
-    $supports = apply_filters( "wpinv_{$gateway}_supports_sandbox", false );
403
-    return apply_filters( 'wpinv_is_test_mode', $sandbox && $supports, $gateway );
400
+function wpinv_is_test_mode($gateway = '') {
401
+    $sandbox  = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", true);
402
+    $supports = apply_filters("wpinv_{$gateway}_supports_sandbox", false);
403
+    return apply_filters('wpinv_is_test_mode', $sandbox && $supports, $gateway);
404 404
 }
405 405
 
406 406
 /**
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
  * 
412 412
  * @return string
413 413
  */
414
-function wpinv_get_ipn_url( $gateway = false, $args = array() ) {
414
+function wpinv_get_ipn_url($gateway = false, $args = array()) {
415 415
     $args = wp_parse_args(
416 416
         array(
417 417
             'wpi-listener' => 'IPN',
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
         $args
421 421
     );
422 422
 
423
-    return apply_filters( 'wpinv_ipn_url', add_query_arg( $args,  home_url( 'index.php' ) ), $gateway, $args );
423
+    return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args);
424 424
 
425 425
 }
426 426
 
@@ -431,39 +431,39 @@  discard block
 block discarded – undo
431 431
  * 
432 432
  * @return string
433 433
  */
434
-function getpaid_get_non_query_string_ipn_url( $gateway ) {
435
-    $gateway = wpinv_sanitize_key( $gateway );
436
-    return home_url( "getpaid-ipn/$gateway" );
434
+function getpaid_get_non_query_string_ipn_url($gateway) {
435
+    $gateway = wpinv_sanitize_key($gateway);
436
+    return home_url("getpaid-ipn/$gateway");
437 437
 }
438 438
 
439 439
 
440 440
 /**
441 441
  * Retrieves request data with slashes removed slashes.
442 442
  */
443
-function wpinv_get_post_data( $method = 'request' ) {
443
+function wpinv_get_post_data($method = 'request') {
444 444
 
445
-    if ( $method == 'post' ) {
446
-        return wp_unslash( $_POST );
445
+    if ($method == 'post') {
446
+        return wp_unslash($_POST);
447 447
     }
448 448
 
449
-    if ( $method == 'get' ) {
450
-        return wp_unslash( $_GET );
449
+    if ($method == 'get') {
450
+        return wp_unslash($_GET);
451 451
     }
452 452
 
453
-    return wp_unslash( $_REQUEST );
453
+    return wp_unslash($_REQUEST);
454 454
   
455 455
 }
456 456
 
457 457
 /**
458 458
  * Checks if a given gateway supports subscription payments.
459 459
  */
460
-function wpinv_gateway_support_subscription( $gateway ) {
460
+function wpinv_gateway_support_subscription($gateway) {
461 461
     $supports = false;
462 462
 
463
-    if ( wpinv_is_gateway_active( $gateway ) ) {
464
-        $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports );
463
+    if (wpinv_is_gateway_active($gateway)) {
464
+        $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports);
465 465
 
466
-        $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway );
466
+        $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway);
467 467
     }
468 468
 
469 469
     return $supports;
@@ -475,14 +475,14 @@  discard block
 block discarded – undo
475 475
  * @param array $gateways an array of gateways.
476 476
  * @param GetPaid_Payment_Form $form payment form.
477 477
  */
478
-function wpinv_payment_gateways_on_cart( $gateways, $form ) {
478
+function wpinv_payment_gateways_on_cart($gateways, $form) {
479 479
 
480
-    if ( $form->is_recurring() ) {
480
+    if ($form->is_recurring()) {
481 481
 
482
-        foreach ( array_keys( $gateways ) as $gateway ) {
482
+        foreach (array_keys($gateways) as $gateway) {
483 483
 
484
-            if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
485
-                unset( $gateways[$gateway] );
484
+            if (!wpinv_gateway_support_subscription($gateway)) {
485
+                unset($gateways[$gateway]);
486 486
             }
487 487
 
488 488
         }
@@ -491,4 +491,4 @@  discard block
 block discarded – undo
491 491
 
492 492
     return $gateways;
493 493
 }
494
-add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 );
494
+add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2);
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +527 added lines, -527 removed lines patch added patch discarded remove patch
@@ -14,590 +14,590 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @param array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 * 
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @param array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     * 
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load the translation of the plugin.
158
-	 *
159
-	 * @since 1.0
160
-	 */
161
-	public function load_textdomain( $locale = NULL ) {
162
-		if ( empty( $locale ) ) {
163
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
-		}
165
-
166
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
-
168
-		unload_textdomain( 'invoicing' );
169
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
-
172
-		/**
173
-		 * Define language constants.
174
-		 */
175
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
-	}
177
-
178
-	/**
179
-	 * Include required core files used in admin and on the frontend.
180
-	 */
181
-	public function includes() {
182
-
183
-		// Start with the settings.
184
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
-
186
-		// Packages/libraries.
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
-
190
-		// Load functions.
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
-
207
-		// Register autoloader.
208
-		try {
209
-			spl_autoload_register( array( $this, 'autoload' ), true );
210
-		} catch ( Exception $e ) {
211
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
-		}
213
-
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
-
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
-			GetPaid_Post_Types_Admin::init();
238
-
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
-			// load the user class only on the users.php page
246
-			global $pagenow;
247
-			if($pagenow=='users.php'){
248
-				new WPInv_Admin_Users();
249
-			}
250
-		}
251
-
252
-		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
-		}
257
-
258
-	}
259
-
260
-	/**
261
-	 * Class autoloader
262
-	 *
263
-	 * @param       string $class_name The name of the class to load.
264
-	 * @access      public
265
-	 * @since       1.0.19
266
-	 * @return      void
267
-	 */
268
-	public function autoload( $class_name ) {
269
-
270
-		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
272
-
273
-		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
-			return;
276
-		}
277
-
278
-		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
-
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
-
284
-		// And an array of possible locations in order of importance.
285
-		$locations = array(
286
-			"$plugin_path/includes",
287
-			"$plugin_path/includes/data-stores",
288
-			"$plugin_path/includes/gateways",
289
-			"$plugin_path/includes/payments",
290
-			"$plugin_path/includes/geolocation",
291
-			"$plugin_path/includes/reports",
292
-			"$plugin_path/includes/api",
293
-			"$plugin_path/includes/admin",
294
-			"$plugin_path/includes/admin/meta-boxes",
295
-		);
296
-
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
-
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
301
-				break;
302
-			}
303
-
304
-		}
305
-
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-
313
-		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
315
-
316
-		// Maybe upgrade.
317
-		$this->maybe_upgrade_database();
318
-
319
-		// Load default gateways.
320
-		$gateways = apply_filters(
321
-			'getpaid_default_gateways',
322
-			array(
323
-				'manual'        => 'GetPaid_Manual_Gateway',
324
-				'paypal'        => 'GetPaid_Paypal_Gateway',
325
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
-			)
329
-		);
330
-
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
333
-		}
334
-
335
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
-			GetPaid_Installer::rename_gateways_label();
337
-			update_option( 'wpinv_renamed_gateways', 'yes' );
338
-		}
339
-
340
-		// Fires after getpaid inits.
341
-		do_action( 'getpaid_init', $this );
342
-
343
-	}
344
-
345
-	/**
346
-	 * Checks if this is an IPN request and processes it.
347
-	 */
348
-	public function maybe_process_ipn() {
349
-
350
-		// Ensure that this is an IPN request.
351
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
-			return;
353
-		}
354
-
355
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
356
-
357
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
358
-		do_action( "wpinv_verify_{$gateway}_ipn" );
359
-		exit;
360
-
361
-	}
362
-
363
-	public function enqueue_scripts() {
364
-
365
-		// Fires before adding scripts.
366
-		do_action( 'getpaid_enqueue_scripts' );
367
-
368
-		$localize                         = array();
369
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
371
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
372
-		$localize['UseTaxes']             = wpinv_use_taxes();
373
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
374
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
375
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
376
-
377
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
378
-
379
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
380
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
381
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
382
-	}
383
-
384
-	public function wpinv_actions() {
385
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
386
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
387
-		}
388
-	}
389
-
390
-	/**
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load the translation of the plugin.
158
+     *
159
+     * @since 1.0
160
+     */
161
+    public function load_textdomain( $locale = NULL ) {
162
+        if ( empty( $locale ) ) {
163
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
+        }
165
+
166
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
+
168
+        unload_textdomain( 'invoicing' );
169
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
+
172
+        /**
173
+         * Define language constants.
174
+         */
175
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
+    }
177
+
178
+    /**
179
+     * Include required core files used in admin and on the frontend.
180
+     */
181
+    public function includes() {
182
+
183
+        // Start with the settings.
184
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
+
186
+        // Packages/libraries.
187
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
+
190
+        // Load functions.
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
+
207
+        // Register autoloader.
208
+        try {
209
+            spl_autoload_register( array( $this, 'autoload' ), true );
210
+        } catch ( Exception $e ) {
211
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
+        }
213
+
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
+
236
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
+            GetPaid_Post_Types_Admin::init();
238
+
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
+            // load the user class only on the users.php page
246
+            global $pagenow;
247
+            if($pagenow=='users.php'){
248
+                new WPInv_Admin_Users();
249
+            }
250
+        }
251
+
252
+        // Register cli commands
253
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
+        }
257
+
258
+    }
259
+
260
+    /**
261
+     * Class autoloader
262
+     *
263
+     * @param       string $class_name The name of the class to load.
264
+     * @access      public
265
+     * @since       1.0.19
266
+     * @return      void
267
+     */
268
+    public function autoload( $class_name ) {
269
+
270
+        // Normalize the class name...
271
+        $class_name  = strtolower( $class_name );
272
+
273
+        // ... and make sure it is our class.
274
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
+            return;
276
+        }
277
+
278
+        // Next, prepare the file name from the class.
279
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
+
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
+
284
+        // And an array of possible locations in order of importance.
285
+        $locations = array(
286
+            "$plugin_path/includes",
287
+            "$plugin_path/includes/data-stores",
288
+            "$plugin_path/includes/gateways",
289
+            "$plugin_path/includes/payments",
290
+            "$plugin_path/includes/geolocation",
291
+            "$plugin_path/includes/reports",
292
+            "$plugin_path/includes/api",
293
+            "$plugin_path/includes/admin",
294
+            "$plugin_path/includes/admin/meta-boxes",
295
+        );
296
+
297
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
+
299
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
+                include trailingslashit( $location ) . $file_name;
301
+                break;
302
+            }
303
+
304
+        }
305
+
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+
313
+        // Fires before getpaid inits.
314
+        do_action( 'before_getpaid_init', $this );
315
+
316
+        // Maybe upgrade.
317
+        $this->maybe_upgrade_database();
318
+
319
+        // Load default gateways.
320
+        $gateways = apply_filters(
321
+            'getpaid_default_gateways',
322
+            array(
323
+                'manual'        => 'GetPaid_Manual_Gateway',
324
+                'paypal'        => 'GetPaid_Paypal_Gateway',
325
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
+            )
329
+        );
330
+
331
+        foreach ( $gateways as $id => $class ) {
332
+            $this->gateways[ $id ] = new $class();
333
+        }
334
+
335
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
+            GetPaid_Installer::rename_gateways_label();
337
+            update_option( 'wpinv_renamed_gateways', 'yes' );
338
+        }
339
+
340
+        // Fires after getpaid inits.
341
+        do_action( 'getpaid_init', $this );
342
+
343
+    }
344
+
345
+    /**
346
+     * Checks if this is an IPN request and processes it.
347
+     */
348
+    public function maybe_process_ipn() {
349
+
350
+        // Ensure that this is an IPN request.
351
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
+            return;
353
+        }
354
+
355
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
356
+
357
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
358
+        do_action( "wpinv_verify_{$gateway}_ipn" );
359
+        exit;
360
+
361
+    }
362
+
363
+    public function enqueue_scripts() {
364
+
365
+        // Fires before adding scripts.
366
+        do_action( 'getpaid_enqueue_scripts' );
367
+
368
+        $localize                         = array();
369
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
371
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
372
+        $localize['UseTaxes']             = wpinv_use_taxes();
373
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
374
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
375
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
376
+
377
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
378
+
379
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
380
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
381
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
382
+    }
383
+
384
+    public function wpinv_actions() {
385
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
386
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
387
+        }
388
+    }
389
+
390
+    /**
391 391
      * Fires an action after verifying that a user can fire them.
392
-	 *
393
-	 * Note: If the action is on an invoice, subscription etc, esure that the
394
-	 * current user owns the invoice/subscription.
392
+     *
393
+     * Note: If the action is on an invoice, subscription etc, esure that the
394
+     * current user owns the invoice/subscription.
395 395
      */
396 396
     public function maybe_do_authenticated_action() {
397 397
 
398
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
398
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
399
+
400
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
401
+            $data = wp_unslash( $_REQUEST );
402
+            if ( is_user_logged_in() ) {
403
+                do_action( "getpaid_authenticated_action_$key", $data );
404
+            }
405
+
406
+            do_action( "getpaid_unauthenticated_action_$key", $data );
407
+
408
+        }
399 409
 
400
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
401
-			$data = wp_unslash( $_REQUEST );
402
-			if ( is_user_logged_in() ) {
403
-				do_action( "getpaid_authenticated_action_$key", $data );
404
-			}
410
+    }
405 411
 
406
-			do_action( "getpaid_unauthenticated_action_$key", $data );
412
+    public function pre_get_posts( $wp_query ) {
407 413
 
408
-		}
414
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
415
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
416
+        }
409 417
 
418
+        return $wp_query;
410 419
     }
411 420
 
412
-	public function pre_get_posts( $wp_query ) {
413
-
414
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
415
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
416
-		}
417
-
418
-		return $wp_query;
419
-	}
420
-
421
-	/**
422
-	 * Register widgets
423
-	 *
424
-	 */
425
-	public function register_widgets() {
426
-
427
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
428
-		// So we disable our widgets when editing a page with UX Builder.
429
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
430
-			return;
431
-		}
432
-
433
-		$widgets = apply_filters(
434
-			'getpaid_widget_classes',
435
-			array(
436
-				'WPInv_Checkout_Widget',
437
-				'WPInv_History_Widget',
438
-				'WPInv_Receipt_Widget',
439
-				'WPInv_Subscriptions_Widget',
440
-				'WPInv_Buy_Item_Widget',
441
-				'WPInv_Messages_Widget',
442
-				'WPInv_GetPaid_Widget'
443
-			)
444
-		);
445
-
446
-		foreach ( $widgets as $widget ) {
447
-			register_widget( $widget );
448
-		}
421
+    /**
422
+     * Register widgets
423
+     *
424
+     */
425
+    public function register_widgets() {
426
+
427
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
428
+        // So we disable our widgets when editing a page with UX Builder.
429
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
430
+            return;
431
+        }
432
+
433
+        $widgets = apply_filters(
434
+            'getpaid_widget_classes',
435
+            array(
436
+                'WPInv_Checkout_Widget',
437
+                'WPInv_History_Widget',
438
+                'WPInv_Receipt_Widget',
439
+                'WPInv_Subscriptions_Widget',
440
+                'WPInv_Buy_Item_Widget',
441
+                'WPInv_Messages_Widget',
442
+                'WPInv_GetPaid_Widget'
443
+            )
444
+        );
445
+
446
+        foreach ( $widgets as $widget ) {
447
+            register_widget( $widget );
448
+        }
449 449
 		
450
-	}
450
+    }
451 451
 
452
-	/**
453
-	 * Upgrades the database.
454
-	 *
455
-	 * @since 2.0.2
456
-	 */
457
-	public function maybe_upgrade_database() {
452
+    /**
453
+     * Upgrades the database.
454
+     *
455
+     * @since 2.0.2
456
+     */
457
+    public function maybe_upgrade_database() {
458 458
 
459
-		$wpi_version = get_option( 'wpinv_version', 0 );
459
+        $wpi_version = get_option( 'wpinv_version', 0 );
460 460
 
461
-		if ( $wpi_version == WPINV_VERSION ) {
462
-			return;
463
-		}
461
+        if ( $wpi_version == WPINV_VERSION ) {
462
+            return;
463
+        }
464 464
 
465
-		$installer = new GetPaid_Installer();
465
+        $installer = new GetPaid_Installer();
466 466
 
467
-		if ( empty( $wpi_version ) ) {
468
-			return $installer->upgrade_db( 0 );
469
-		}
467
+        if ( empty( $wpi_version ) ) {
468
+            return $installer->upgrade_db( 0 );
469
+        }
470 470
 
471
-		$upgrades  = array(
472
-			'0.0.5' => '004',
473
-			'1.0.3' => '102',
474
-			'2.0.0' => '118',
475
-			'2.0.8' => '207',
476
-		);
471
+        $upgrades  = array(
472
+            '0.0.5' => '004',
473
+            '1.0.3' => '102',
474
+            '2.0.0' => '118',
475
+            '2.0.8' => '207',
476
+        );
477 477
 
478
-		foreach ( $upgrades as $key => $method ) {
478
+        foreach ( $upgrades as $key => $method ) {
479 479
 
480
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
481
-				return $installer->upgrade_db( $method );
482
-			}
480
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
481
+                return $installer->upgrade_db( $method );
482
+            }
483 483
 
484
-		}
484
+        }
485 485
 
486
-	}
486
+    }
487 487
 
488
-	/**
489
-	 * Flushes the permalinks if needed.
490
-	 *
491
-	 * @since 2.0.8
492
-	 */
493
-	public function maybe_flush_permalinks() {
488
+    /**
489
+     * Flushes the permalinks if needed.
490
+     *
491
+     * @since 2.0.8
492
+     */
493
+    public function maybe_flush_permalinks() {
494 494
 
495
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
495
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
496 496
 
497
-		if ( ! empty( $flush ) ) {
498
-			flush_rewrite_rules();
499
-			delete_option( 'wpinv_flush_permalinks' );
500
-		}
497
+        if ( ! empty( $flush ) ) {
498
+            flush_rewrite_rules();
499
+            delete_option( 'wpinv_flush_permalinks' );
500
+        }
501 501
 
502
-	}
502
+    }
503 503
 
504
-	/**
505
-	 * Remove our pages from yoast sitemaps.
506
-	 *
507
-	 * @since 1.0.19
508
-	 * @param int[] $excluded_posts_ids
509
-	 */
510
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
504
+    /**
505
+     * Remove our pages from yoast sitemaps.
506
+     *
507
+     * @since 1.0.19
508
+     * @param int[] $excluded_posts_ids
509
+     */
510
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
511 511
 
512
-		// Ensure that we have an array.
513
-		if ( ! is_array( $excluded_posts_ids ) ) {
514
-			$excluded_posts_ids = array();
515
-		}
512
+        // Ensure that we have an array.
513
+        if ( ! is_array( $excluded_posts_ids ) ) {
514
+            $excluded_posts_ids = array();
515
+        }
516 516
 
517
-		// Prepare our pages.
518
-		$our_pages = array();
517
+        // Prepare our pages.
518
+        $our_pages = array();
519 519
 
520
-		// Checkout page.
521
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
520
+        // Checkout page.
521
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
522 522
 
523
-		// Success page.
524
-		$our_pages[] = wpinv_get_option( 'success_page', false );
523
+        // Success page.
524
+        $our_pages[] = wpinv_get_option( 'success_page', false );
525 525
 
526
-		// Failure page.
527
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
526
+        // Failure page.
527
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
528 528
 
529
-		// History page.
530
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
529
+        // History page.
530
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
531 531
 
532
-		// Subscriptions page.
533
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
532
+        // Subscriptions page.
533
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
534 534
 
535
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
535
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
536 536
 
537
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
538
-		return array_unique( $excluded_posts_ids );
537
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
538
+        return array_unique( $excluded_posts_ids );
539 539
 
540
-	}
540
+    }
541 541
 
542
-	/**
543
-	 * Displays additional footer code.
544
-	 * 
545
-	 * @since 2.0.0
546
-	 */
547
-	public function wp_footer() {
548
-		wpinv_get_template( 'frontend-footer.php' );
549
-	}
542
+    /**
543
+     * Displays additional footer code.
544
+     * 
545
+     * @since 2.0.0
546
+     */
547
+    public function wp_footer() {
548
+        wpinv_get_template( 'frontend-footer.php' );
549
+    }
550 550
 
551
-	/**
552
-	 * Displays additional header code.
553
-	 * 
554
-	 * @since 2.0.0
555
-	 */
556
-	public function wp_head() {
557
-		wpinv_get_template( 'frontend-head.php' );
558
-	}
551
+    /**
552
+     * Displays additional header code.
553
+     * 
554
+     * @since 2.0.0
555
+     */
556
+    public function wp_head() {
557
+        wpinv_get_template( 'frontend-head.php' );
558
+    }
559 559
 
560
-	/**
561
-	 * Custom query vars.
562
-	 *
563
-	 */
564
-	public function custom_query_vars( $vars ) {
560
+    /**
561
+     * Custom query vars.
562
+     *
563
+     */
564
+    public function custom_query_vars( $vars ) {
565 565
         $vars[] = 'getpaid-ipn';
566 566
         return $vars;
567
-	}
567
+    }
568 568
 
569
-	/**
570
-	 * Add rewrite tags and rules.
571
-	 *
572
-	 */
573
-	public function add_rewrite_rule() {
569
+    /**
570
+     * Add rewrite tags and rules.
571
+     *
572
+     */
573
+    public function add_rewrite_rule() {
574 574
         $tag = 'getpaid-ipn';
575 575
         add_rewrite_tag( "%$tag%", '([^&]+)' );
576 576
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
577
-	}
577
+    }
578 578
 
579
-	/**
580
-	 * Processes non-query string ipns.
581
-	 *
582
-	 */
583
-	public function maybe_process_new_ipn( $query ) {
579
+    /**
580
+     * Processes non-query string ipns.
581
+     *
582
+     */
583
+    public function maybe_process_new_ipn( $query ) {
584 584
 
585 585
         if ( is_admin() || ! $query->is_main_query() ) {
586 586
             return;
587 587
         }
588 588
 
589
-		$gateway = get_query_var( 'getpaid-ipn' );
589
+        $gateway = get_query_var( 'getpaid-ipn' );
590 590
 
591 591
         if ( ! empty( $gateway ) ){
592 592
 
593
-			$gateway = sanitize_text_field( $gateway );
594
-			nocache_headers();
595
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
596
-			do_action( "wpinv_verify_{$gateway}_ipn" );
597
-			exit;
593
+            $gateway = sanitize_text_field( $gateway );
594
+            nocache_headers();
595
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
596
+            do_action( "wpinv_verify_{$gateway}_ipn" );
597
+            exit;
598 598
 
599 599
         }
600 600
 
601
-	}
601
+    }
602 602
 
603 603
 }
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param string $prop The prop to set.
57 57
 	 * @param mixed $value The value to retrieve.
58 58
 	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
59
+	public function set($prop, $value) {
60
+		$this->data[$prop] = $value;
61 61
 	}
62 62
 
63 63
 	/**
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param string $prop The prop to set.
67 67
 	 * @return mixed The value.
68 68
 	 */
69
-	public function get( $prop ) {
69
+	public function get($prop) {
70 70
 
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
71
+		if (isset($this->data[$prop])) {
72
+			return $this->data[$prop];
73 73
 		}
74 74
 
75 75
 		return null;
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
 	public function set_properties() {
82 82
 
83 83
 		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+		$this->set('session', new WPInv_Session_Handler());
85
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
86 86
 		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87 87
 
88 88
 		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
89
+		$this->set('session', new WPInv_Session_Handler());
90
+		$this->set('notes', new WPInv_Notes());
91
+		$this->set('api', new WPInv_API());
92
+		$this->set('post_types', new GetPaid_Post_Types());
93
+		$this->set('template', new GetPaid_Template());
94
+		$this->set('admin', new GetPaid_Admin());
95
+		$this->set('subscriptions', new WPInv_Subscriptions());
96
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
97
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
98
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
99
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
100
+		$this->set('maxmind', new GetPaid_MaxMind_Geolocation());
101 101
 
102 102
 	}
103 103
 
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	 * Define plugin constants.
106 106
 	 */
107 107
 	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
108
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
109
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
110 110
 		$this->version = WPINV_VERSION;
111 111
 	}
112 112
 
@@ -117,27 +117,27 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	protected function init_hooks() {
119 119
 		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
121 121
 
122 122
 		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135
-        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
123
+		add_action('init', array($this, 'init'), 1);
124
+		add_action('init', array($this, 'maybe_process_ipn'), 10);
125
+		add_action('init', array($this, 'wpinv_actions'));
126
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
127
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
128
+		add_action('wp_footer', array($this, 'wp_footer'));
129
+		add_action('wp_head', array($this, 'wp_head'));
130
+		add_action('widgets_init', array(&$this, 'register_widgets'));
131
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
132
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
133
+
134
+		add_filter('query_vars', array($this, 'custom_query_vars'));
135
+        add_action('init', array($this, 'add_rewrite_rule'), 10, 0);
136
+		add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1);
137 137
 
138 138
 		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
139
+		do_action('wpinv_actions', $this);
140
+		do_action('getpaid_actions', $this);
141 141
 
142 142
 	}
143 143
 
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 		/* Internationalize the text strings used. */
146 146
 		$this->load_textdomain();
147 147
 
148
-		do_action( 'wpinv_loaded' );
148
+		do_action('wpinv_loaded');
149 149
 
150 150
 		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
151
+		if (function_exists('ct_css_output')) {
152 152
 			wpinv_oxygen_fix_conflict();
153 153
 		}
154 154
 	}
@@ -158,21 +158,21 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @since 1.0
160 160
 	 */
161
-	public function load_textdomain( $locale = NULL ) {
162
-		if ( empty( $locale ) ) {
163
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
161
+	public function load_textdomain($locale = NULL) {
162
+		if (empty($locale)) {
163
+			$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
164 164
 		}
165 165
 
166
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
166
+		$locale = apply_filters('plugin_locale', $locale, 'invoicing');
167 167
 
168
-		unload_textdomain( 'invoicing' );
169
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
168
+		unload_textdomain('invoicing');
169
+		load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
170
+		load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
171 171
 
172 172
 		/**
173 173
 		 * Define language constants.
174 174
 		 */
175
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
175
+		require_once(WPINV_PLUGIN_DIR . 'language.php');
176 176
 	}
177 177
 
178 178
 	/**
@@ -181,78 +181,78 @@  discard block
 block discarded – undo
181 181
 	public function includes() {
182 182
 
183 183
 		// Start with the settings.
184
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
184
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
185 185
 
186 186
 		// Packages/libraries.
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
187
+		require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
188
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
189 189
 
190 190
 		// Load functions.
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
191
+		require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
192
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
193
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
194
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
195
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
196
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
197
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
198
+		require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
199
+		require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php');
200
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
201
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
202
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
203
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
204
+		require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php');
205
+		require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php');
206 206
 
207 207
 		// Register autoloader.
208 208
 		try {
209
-			spl_autoload_register( array( $this, 'autoload' ), true );
210
-		} catch ( Exception $e ) {
211
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
209
+			spl_autoload_register(array($this, 'autoload'), true);
210
+		} catch (Exception $e) {
211
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
212 212
 		}
213 213
 
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
-
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
214
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
215
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
216
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
217
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
218
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
219
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
220
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
221
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
222
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
223
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
224
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
225
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
226
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
227
+		require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
228
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
229
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
230
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
231
+		require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
232
+		require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
233
+		require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
234
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
235
+
236
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
237 237
 			GetPaid_Post_Types_Admin::init();
238 238
 
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
239
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
240
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
241
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
242
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
243
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
244
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
245 245
 			// load the user class only on the users.php page
246 246
 			global $pagenow;
247
-			if($pagenow=='users.php'){
247
+			if ($pagenow == 'users.php') {
248 248
 				new WPInv_Admin_Users();
249 249
 			}
250 250
 		}
251 251
 
252 252
 		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
253
+		if (defined('WP_CLI') && WP_CLI) {
254
+			require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
255
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
256 256
 		}
257 257
 
258 258
 	}
@@ -265,21 +265,21 @@  discard block
 block discarded – undo
265 265
 	 * @since       1.0.19
266 266
 	 * @return      void
267 267
 	 */
268
-	public function autoload( $class_name ) {
268
+	public function autoload($class_name) {
269 269
 
270 270
 		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
271
+		$class_name = strtolower($class_name);
272 272
 
273 273
 		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
280 280
 
281 281
 		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
283 283
 
284 284
 		// And an array of possible locations in order of importance.
285 285
 		$locations = array(
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 			"$plugin_path/includes/admin/meta-boxes",
295 295
 		);
296 296
 
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
298 298
 
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
299
+			if (file_exists(trailingslashit($location) . $file_name)) {
300
+				include trailingslashit($location) . $file_name;
301 301
 				break;
302 302
 			}
303 303
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	public function init() {
312 312
 
313 313
 		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
314
+		do_action('before_getpaid_init', $this);
315 315
 
316 316
 		// Maybe upgrade.
317 317
 		$this->maybe_upgrade_database();
@@ -328,17 +328,17 @@  discard block
 block discarded – undo
328 328
 			)
329 329
 		);
330 330
 
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
331
+		foreach ($gateways as $id => $class) {
332
+			$this->gateways[$id] = new $class();
333 333
 		}
334 334
 
335
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+		if ('yes' != get_option('wpinv_renamed_gateways')) {
336 336
 			GetPaid_Installer::rename_gateways_label();
337
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
+			update_option('wpinv_renamed_gateways', 'yes');
338 338
 		}
339 339
 
340 340
 		// Fires after getpaid inits.
341
-		do_action( 'getpaid_init', $this );
341
+		do_action('getpaid_init', $this);
342 342
 
343 343
 	}
344 344
 
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
 	public function maybe_process_ipn() {
349 349
 
350 350
 		// Ensure that this is an IPN request.
351
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
352 352
 			return;
353 353
 		}
354 354
 
355
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
355
+		$gateway = wpinv_clean($_GET['wpi-gateway']);
356 356
 
357
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
358
-		do_action( "wpinv_verify_{$gateway}_ipn" );
357
+		do_action('wpinv_verify_payment_ipn', $gateway);
358
+		do_action("wpinv_verify_{$gateway}_ipn");
359 359
 		exit;
360 360
 
361 361
 	}
@@ -363,27 +363,27 @@  discard block
 block discarded – undo
363 363
 	public function enqueue_scripts() {
364 364
 
365 365
 		// Fires before adding scripts.
366
-		do_action( 'getpaid_enqueue_scripts' );
366
+		do_action('getpaid_enqueue_scripts');
367 367
 
368 368
 		$localize                         = array();
369
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
371
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
369
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
370
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
371
+		$localize['txtComplete']          = __('Continue', 'invoicing');
372 372
 		$localize['UseTaxes']             = wpinv_use_taxes();
373
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
374
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
375
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
373
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
374
+		$localize['loading']              = __('Loading...', 'invoicing');
375
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
376 376
 
377
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
377
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
378 378
 
379
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
380
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
381
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
379
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
380
+		wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true);
381
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
382 382
 	}
383 383
 
384 384
 	public function wpinv_actions() {
385
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
386
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
385
+		if (isset($_REQUEST['wpi_action'])) {
386
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
387 387
 		}
388 388
 	}
389 389
 
@@ -395,24 +395,24 @@  discard block
 block discarded – undo
395 395
      */
396 396
     public function maybe_do_authenticated_action() {
397 397
 
398
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
398
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
399 399
 
400
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
401
-			$data = wp_unslash( $_REQUEST );
402
-			if ( is_user_logged_in() ) {
403
-				do_action( "getpaid_authenticated_action_$key", $data );
400
+			$key  = sanitize_key($_REQUEST['getpaid-action']);
401
+			$data = wp_unslash($_REQUEST);
402
+			if (is_user_logged_in()) {
403
+				do_action("getpaid_authenticated_action_$key", $data);
404 404
 			}
405 405
 
406
-			do_action( "getpaid_unauthenticated_action_$key", $data );
406
+			do_action("getpaid_unauthenticated_action_$key", $data);
407 407
 
408 408
 		}
409 409
 
410 410
     }
411 411
 
412
-	public function pre_get_posts( $wp_query ) {
412
+	public function pre_get_posts($wp_query) {
413 413
 
414
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
415
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
414
+		if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
415
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
416 416
 		}
417 417
 
418 418
 		return $wp_query;
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
 		// Currently, UX Builder does not work particulaly well with SuperDuper.
428 428
 		// So we disable our widgets when editing a page with UX Builder.
429
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
429
+		if (function_exists('ux_builder_is_active') && ux_builder_is_active()) {
430 430
 			return;
431 431
 		}
432 432
 
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 			)
444 444
 		);
445 445
 
446
-		foreach ( $widgets as $widget ) {
447
-			register_widget( $widget );
446
+		foreach ($widgets as $widget) {
447
+			register_widget($widget);
448 448
 		}
449 449
 		
450 450
 	}
@@ -456,29 +456,29 @@  discard block
 block discarded – undo
456 456
 	 */
457 457
 	public function maybe_upgrade_database() {
458 458
 
459
-		$wpi_version = get_option( 'wpinv_version', 0 );
459
+		$wpi_version = get_option('wpinv_version', 0);
460 460
 
461
-		if ( $wpi_version == WPINV_VERSION ) {
461
+		if ($wpi_version == WPINV_VERSION) {
462 462
 			return;
463 463
 		}
464 464
 
465 465
 		$installer = new GetPaid_Installer();
466 466
 
467
-		if ( empty( $wpi_version ) ) {
468
-			return $installer->upgrade_db( 0 );
467
+		if (empty($wpi_version)) {
468
+			return $installer->upgrade_db(0);
469 469
 		}
470 470
 
471
-		$upgrades  = array(
471
+		$upgrades = array(
472 472
 			'0.0.5' => '004',
473 473
 			'1.0.3' => '102',
474 474
 			'2.0.0' => '118',
475 475
 			'2.0.8' => '207',
476 476
 		);
477 477
 
478
-		foreach ( $upgrades as $key => $method ) {
478
+		foreach ($upgrades as $key => $method) {
479 479
 
480
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
481
-				return $installer->upgrade_db( $method );
480
+			if (version_compare($wpi_version, $key, '<')) {
481
+				return $installer->upgrade_db($method);
482 482
 			}
483 483
 
484 484
 		}
@@ -492,11 +492,11 @@  discard block
 block discarded – undo
492 492
 	 */
493 493
 	public function maybe_flush_permalinks() {
494 494
 
495
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
495
+		$flush = get_option('wpinv_flush_permalinks', 0);
496 496
 
497
-		if ( ! empty( $flush ) ) {
497
+		if (!empty($flush)) {
498 498
 			flush_rewrite_rules();
499
-			delete_option( 'wpinv_flush_permalinks' );
499
+			delete_option('wpinv_flush_permalinks');
500 500
 		}
501 501
 
502 502
 	}
@@ -507,10 +507,10 @@  discard block
 block discarded – undo
507 507
 	 * @since 1.0.19
508 508
 	 * @param int[] $excluded_posts_ids
509 509
 	 */
510
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
510
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
511 511
 
512 512
 		// Ensure that we have an array.
513
-		if ( ! is_array( $excluded_posts_ids ) ) {
513
+		if (!is_array($excluded_posts_ids)) {
514 514
 			$excluded_posts_ids = array();
515 515
 		}
516 516
 
@@ -518,24 +518,24 @@  discard block
 block discarded – undo
518 518
 		$our_pages = array();
519 519
 
520 520
 		// Checkout page.
521
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
521
+		$our_pages[] = wpinv_get_option('checkout_page', false);
522 522
 
523 523
 		// Success page.
524
-		$our_pages[] = wpinv_get_option( 'success_page', false );
524
+		$our_pages[] = wpinv_get_option('success_page', false);
525 525
 
526 526
 		// Failure page.
527
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
527
+		$our_pages[] = wpinv_get_option('failure_page', false);
528 528
 
529 529
 		// History page.
530
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
530
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
531 531
 
532 532
 		// Subscriptions page.
533
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
533
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
534 534
 
535
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
535
+		$our_pages   = array_map('intval', array_filter($our_pages));
536 536
 
537 537
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
538
-		return array_unique( $excluded_posts_ids );
538
+		return array_unique($excluded_posts_ids);
539 539
 
540 540
 	}
541 541
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 * @since 2.0.0
546 546
 	 */
547 547
 	public function wp_footer() {
548
-		wpinv_get_template( 'frontend-footer.php' );
548
+		wpinv_get_template('frontend-footer.php');
549 549
 	}
550 550
 
551 551
 	/**
@@ -554,14 +554,14 @@  discard block
 block discarded – undo
554 554
 	 * @since 2.0.0
555 555
 	 */
556 556
 	public function wp_head() {
557
-		wpinv_get_template( 'frontend-head.php' );
557
+		wpinv_get_template('frontend-head.php');
558 558
 	}
559 559
 
560 560
 	/**
561 561
 	 * Custom query vars.
562 562
 	 *
563 563
 	 */
564
-	public function custom_query_vars( $vars ) {
564
+	public function custom_query_vars($vars) {
565 565
         $vars[] = 'getpaid-ipn';
566 566
         return $vars;
567 567
 	}
@@ -572,28 +572,28 @@  discard block
 block discarded – undo
572 572
 	 */
573 573
 	public function add_rewrite_rule() {
574 574
         $tag = 'getpaid-ipn';
575
-        add_rewrite_tag( "%$tag%", '([^&]+)' );
576
-        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
575
+        add_rewrite_tag("%$tag%", '([^&]+)');
576
+        add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top');
577 577
 	}
578 578
 
579 579
 	/**
580 580
 	 * Processes non-query string ipns.
581 581
 	 *
582 582
 	 */
583
-	public function maybe_process_new_ipn( $query ) {
583
+	public function maybe_process_new_ipn($query) {
584 584
 
585
-        if ( is_admin() || ! $query->is_main_query() ) {
585
+        if (is_admin() || !$query->is_main_query()) {
586 586
             return;
587 587
         }
588 588
 
589
-		$gateway = get_query_var( 'getpaid-ipn' );
589
+		$gateway = get_query_var('getpaid-ipn');
590 590
 
591
-        if ( ! empty( $gateway ) ){
591
+        if (!empty($gateway)) {
592 592
 
593
-			$gateway = sanitize_text_field( $gateway );
593
+			$gateway = sanitize_text_field($gateway);
594 594
 			nocache_headers();
595
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
596
-			do_action( "wpinv_verify_{$gateway}_ipn" );
595
+			do_action('wpinv_verify_payment_ipn', $gateway);
596
+			do_action("wpinv_verify_{$gateway}_ipn");
597 597
 			exit;
598 598
 
599 599
         }
Please login to merge, or discard this patch.