Passed
Push — master ( 5f1d59...f20c5b )
by Brian
05:28
created
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -12,179 +12,179 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
125
+
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
131
+
132
+        $invoice = $submission->get_invoice();
133 133
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138 138
 
139
-		return $invoice;
140
-	}
139
+        return $invoice;
140
+    }
141 141
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150 150
 
151
-		$submission = $this->payment_form_submission;
151
+        $submission = $this->payment_form_submission;
152 152
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field('wpi-gateway') );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field('wpi-gateway') );
162 162
 
163
-		$address_confirmed = $submission->get_field( 'confirm-address' );
164
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
163
+        $address_confirmed = $submission->get_field( 'confirm-address' );
164
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
165 165
 
166
-		if ( $submission->has_discount_code() ) {
166
+        if ( $submission->has_discount_code() ) {
167 167
             $invoice->set_discount_code( $submission->get_discount_code() );
168
-		}
169
-
170
-		getpaid_maybe_add_default_address( $invoice );
171
-		return $invoice;
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the submission's customer.
176
-	 *
177
-	 * @return int The customer id.
178
-	 */
179
-	protected function get_submission_customer() {
180
-		$submission = $this->payment_form_submission;
181
-
182
-		// If this is an existing invoice...
183
-		if ( $submission->has_invoice() ) {
184
-			return $submission->get_invoice()->get_user_id();
185
-		}
186
-
187
-		// (Maybe) create the user.
168
+        }
169
+
170
+        getpaid_maybe_add_default_address( $invoice );
171
+        return $invoice;
172
+    }
173
+
174
+    /**
175
+     * Retrieves the submission's customer.
176
+     *
177
+     * @return int The customer id.
178
+     */
179
+    protected function get_submission_customer() {
180
+        $submission = $this->payment_form_submission;
181
+
182
+        // If this is an existing invoice...
183
+        if ( $submission->has_invoice() ) {
184
+            return $submission->get_invoice()->get_user_id();
185
+        }
186
+
187
+        // (Maybe) create the user.
188 188
         $user = get_current_user_id();
189 189
 
190 190
         if ( empty( $user ) ) {
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
         if ( empty( $user ) ) {
195 195
             $user = wpinv_create_user( $submission->get_billing_email() );
196 196
 
197
-			// (Maybe) send new user notification.
198
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
-				wp_send_new_user_notifications( $user, 'user' );
201
-			}
197
+            // (Maybe) send new user notification.
198
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
+                wp_send_new_user_notifications( $user, 'user' );
201
+            }
202 202
 
203 203
         }
204 204
 
@@ -208,34 +208,34 @@  discard block
 block discarded – undo
208 208
 
209 209
         if ( is_numeric( $user ) ) {
210 210
             return $user;
211
-		}
211
+        }
212 212
 
213
-		return $user->ID;
213
+        return $user->ID;
214 214
 
215
-	}
215
+    }
216 216
 
217
-	/**
217
+    /**
218 218
      * Prepares submission data for saving to the database.
219 219
      *
220
-	 * @return array
220
+     * @return array
221 221
      */
222 222
     public function prepare_submission_data_for_saving() {
223 223
 
224
-		$submission = $this->payment_form_submission;
224
+        $submission = $this->payment_form_submission;
225 225
 
226
-		// Prepared submission details.
226
+        // Prepared submission details.
227 227
         $prepared = array(
228
-			'all'  => array(),
229
-			'meta' => array(),
230
-		);
228
+            'all'  => array(),
229
+            'meta' => array(),
230
+        );
231 231
 
232 232
         // Raw submission details.
233
-		$data     = $submission->get_data();
233
+        $data     = $submission->get_data();
234 234
 
235
-		// Loop through the submitted details.
235
+        // Loop through the submitted details.
236 236
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
237 237
 
238
-			// Skip premade fields.
238
+            // Skip premade fields.
239 239
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
240 240
                 continue;
241 241
             }
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
             // Handle misc fields.
249 249
             if ( isset( $data[ $field['id'] ] ) ) {
250 250
 
251
-				if ( $field['type'] == 'checkbox' ) {
252
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
253
-				} else {
254
-					$value = wp_kses_post( $data[ $field['id'] ] );
255
-				}
251
+                if ( $field['type'] == 'checkbox' ) {
252
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
253
+                } else {
254
+                    $value = wp_kses_post( $data[ $field['id'] ] );
255
+                }
256 256
 
257 257
                 $label = $field['id'];
258 258
 
@@ -260,189 +260,189 @@  discard block
 block discarded – undo
260 260
                     $label = $field['label'];
261 261
                 }
262 262
 
263
-				if ( ! empty( $field['add_meta'] ) ) {
264
-					$prepared['meta'][ wpinv_clean( $label ) ] = $value;
265
-				}
266
-				$prepared['all'][ wpinv_clean( $label ) ] = $value;
263
+                if ( ! empty( $field['add_meta'] ) ) {
264
+                    $prepared['meta'][ wpinv_clean( $label ) ] = $value;
265
+                }
266
+                $prepared['all'][ wpinv_clean( $label ) ] = $value;
267 267
 
268 268
             }
269 269
 
270
-		}
270
+        }
271 271
 
272
-		return $prepared;
272
+        return $prepared;
273 273
 
274
-	}
274
+    }
275 275
 
276
-	/**
276
+    /**
277 277
      * Retrieves address details.
278 278
      *
279
-	 * @return array
280
-	 * @param WPInv_Invoice $invoice
281
-	 * @param string $type
279
+     * @return array
280
+     * @param WPInv_Invoice $invoice
281
+     * @param string $type
282 282
      */
283 283
     public function prepare_address_details( $invoice, $type = 'billing' ) {
284 284
 
285
-		$data     = $this->payment_form_submission->get_data();
286
-		$type     = sanitize_key( $type );
287
-		$address  = array();
288
-		$prepared = array();
285
+        $data     = $this->payment_form_submission->get_data();
286
+        $type     = sanitize_key( $type );
287
+        $address  = array();
288
+        $prepared = array();
289 289
 
290
-		if ( ! empty( $data[ $type ] ) ) {
291
-			$address = $data[ $type ];
292
-		}
290
+        if ( ! empty( $data[ $type ] ) ) {
291
+            $address = $data[ $type ];
292
+        }
293 293
 
294
-		// Clean address details.
295
-		foreach ( $address as $key => $value ) {
296
-			$key             = sanitize_key( $key );
297
-			$key             = str_replace( 'wpinv_', '', $key );
298
-			$value           = wpinv_clean( $value );
299
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
300
-		}
294
+        // Clean address details.
295
+        foreach ( $address as $key => $value ) {
296
+            $key             = sanitize_key( $key );
297
+            $key             = str_replace( 'wpinv_', '', $key );
298
+            $value           = wpinv_clean( $value );
299
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
300
+        }
301 301
 
302
-		// Filter address details.
303
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
302
+        // Filter address details.
303
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
304 304
 
305
-		// Remove non-whitelisted values.
306
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
305
+        // Remove non-whitelisted values.
306
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
307 307
 
308
-	}
308
+    }
309 309
 
310
-	/**
310
+    /**
311 311
      * Prepares the billing details.
312 312
      *
313
-	 * @return array
314
-	 * @param WPInv_Invoice $invoice
313
+     * @return array
314
+     * @param WPInv_Invoice $invoice
315 315
      */
316 316
     protected function prepare_billing_info( &$invoice ) {
317 317
 
318
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
318
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
319 319
 
320
-		// Update the invoice with the billing details.
321
-		$invoice->set_props( $billing_address );
320
+        // Update the invoice with the billing details.
321
+        $invoice->set_props( $billing_address );
322 322
 
323
-	}
323
+    }
324 324
 
325
-	/**
325
+    /**
326 326
      * Prepares the shipping details.
327 327
      *
328
-	 * @return array
329
-	 * @param WPInv_Invoice $invoice
328
+     * @return array
329
+     * @param WPInv_Invoice $invoice
330 330
      */
331 331
     protected function prepare_shipping_info( $invoice ) {
332 332
 
333
-		$data = $this->payment_form_submission->get_data();
333
+        $data = $this->payment_form_submission->get_data();
334 334
 
335
-		if ( empty( $data['same-shipping-address'] ) ) {
336
-			return $this->prepare_address_details( $invoice, 'shipping' );
337
-		}
335
+        if ( empty( $data['same-shipping-address'] ) ) {
336
+            return $this->prepare_address_details( $invoice, 'shipping' );
337
+        }
338 338
 
339
-		return $this->prepare_address_details( $invoice, 'billing' );
339
+        return $this->prepare_address_details( $invoice, 'billing' );
340 340
 
341
-	}
341
+    }
342 342
 
343
-	/**
344
-	 * Confirms the submission is valid and send users to the gateway.
345
-	 *
346
-	 * @param WPInv_Invoice $invoice
347
-	 * @param array $prepared_payment_form_data
348
-	 * @param array $shipping
349
-	 */
350
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
343
+    /**
344
+     * Confirms the submission is valid and send users to the gateway.
345
+     *
346
+     * @param WPInv_Invoice $invoice
347
+     * @param array $prepared_payment_form_data
348
+     * @param array $shipping
349
+     */
350
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
351 351
 
352
-		// Ensure the invoice exists.
352
+        // Ensure the invoice exists.
353 353
         if ( ! $invoice->exists() ) {
354 354
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
355 355
         }
356 356
 
357
-		// Save payment form data.
358
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
357
+        // Save payment form data.
358
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
359 359
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
360
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
361
-		if ( ! empty( $prepared_payment_form_data ) ) {
360
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
361
+        if ( ! empty( $prepared_payment_form_data ) ) {
362 362
 
363
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
364
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
365
-			}
363
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
364
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
365
+            }
366 366
 
367
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
368
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
369
-			}
367
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
368
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
369
+            }
370 370
 
371
-		}
371
+        }
372 372
 
373
-		// Save payment form data.
373
+        // Save payment form data.
374 374
         if ( ! empty( $shipping ) ) {
375 375
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
376
-		}
376
+        }
377 377
 
378
-		// Backwards compatibility.
378
+        // Backwards compatibility.
379 379
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
380 380
 
381
-		$this->process_payment( $invoice );
381
+        $this->process_payment( $invoice );
382 382
 
383 383
         // If we are here, there was an error.
384
-		wpinv_send_back_to_checkout( $invoice );
384
+        wpinv_send_back_to_checkout( $invoice );
385 385
 
386
-	}
386
+    }
387 387
 
388
-	/**
389
-	 * Processes the actual payment.
390
-	 *
391
-	 * @param WPInv_Invoice $invoice
392
-	 */
393
-	protected function process_payment( $invoice ) {
388
+    /**
389
+     * Processes the actual payment.
390
+     *
391
+     * @param WPInv_Invoice $invoice
392
+     */
393
+    protected function process_payment( $invoice ) {
394 394
 
395
-		// Clear any checkout errors.
396
-		wpinv_clear_errors();
395
+        // Clear any checkout errors.
396
+        wpinv_clear_errors();
397 397
 
398
-		// No need to send free invoices to the gateway.
399
-		if ( $invoice->is_free() ) {
400
-			$this->process_free_payment( $invoice );
401
-		}
398
+        // No need to send free invoices to the gateway.
399
+        if ( $invoice->is_free() ) {
400
+            $this->process_free_payment( $invoice );
401
+        }
402 402
 
403
-		$submission = $this->payment_form_submission;
403
+        $submission = $this->payment_form_submission;
404 404
 
405
-		// Fires before sending to the gateway.
406
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
405
+        // Fires before sending to the gateway.
406
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
407 407
 
408
-		// Allow the sumission data to be modified before it is sent to the gateway.
409
-		$submission_data    = $submission->get_data();
410
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
411
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
408
+        // Allow the sumission data to be modified before it is sent to the gateway.
409
+        $submission_data    = $submission->get_data();
410
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
411
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
412 412
 
413
-		// Validate the currency.
414
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
415
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
416
-		}
413
+        // Validate the currency.
414
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
415
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
416
+        }
417 417
 
418
-		// Check to see if we have any errors.
419
-		if ( wpinv_get_errors() ) {
420
-			wpinv_send_back_to_checkout( $invoice );
421
-		}
418
+        // Check to see if we have any errors.
419
+        if ( wpinv_get_errors() ) {
420
+            wpinv_send_back_to_checkout( $invoice );
421
+        }
422 422
 
423
-		// Send info to the gateway for payment processing
424
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
423
+        // Send info to the gateway for payment processing
424
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
425 425
 
426
-		// Backwards compatibility.
427
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
426
+        // Backwards compatibility.
427
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
428 428
 
429
-	}
429
+    }
430 430
 
431
-	/**
432
-	 * Marks the invoice as paid in case the checkout is free.
433
-	 *
434
-	 * @param WPInv_Invoice $invoice
435
-	 */
436
-	protected function process_free_payment( $invoice ) {
431
+    /**
432
+     * Marks the invoice as paid in case the checkout is free.
433
+     *
434
+     * @param WPInv_Invoice $invoice
435
+     */
436
+    protected function process_free_payment( $invoice ) {
437 437
 
438
-		$invoice->set_gateway( 'none' );
439
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
440
-		$invoice->mark_paid();
441
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
438
+        $invoice->set_gateway( 'none' );
439
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
440
+        $invoice->mark_paid();
441
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
442 442
 
443
-	}
443
+    }
444 444
 
445
-	/**
445
+    /**
446 446
      * Sends a redrect response to payment details.
447 447
      *
448 448
      */
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 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
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,28 +146,28 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field('wpi-gateway') );
162
-
163
-		$address_confirmed = $submission->get_field( 'confirm-address' );
164
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
165
-
166
-		if ( $submission->has_discount_code() ) {
167
-            $invoice->set_discount_code( $submission->get_discount_code() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+
163
+		$address_confirmed = $submission->get_field('confirm-address');
164
+		$invoice->set_address_confirmed(!empty($address_confirmed));
165
+
166
+		if ($submission->has_discount_code()) {
167
+            $invoice->set_discount_code($submission->get_discount_code());
168 168
 		}
169 169
 
170
-		getpaid_maybe_add_default_address( $invoice );
170
+		getpaid_maybe_add_default_address($invoice);
171 171
 		return $invoice;
172 172
 	}
173 173
 
@@ -180,33 +180,33 @@  discard block
 block discarded – undo
180 180
 		$submission = $this->payment_form_submission;
181 181
 
182 182
 		// If this is an existing invoice...
183
-		if ( $submission->has_invoice() ) {
183
+		if ($submission->has_invoice()) {
184 184
 			return $submission->get_invoice()->get_user_id();
185 185
 		}
186 186
 
187 187
 		// (Maybe) create the user.
188 188
         $user = get_current_user_id();
189 189
 
190
-        if ( empty( $user ) ) {
191
-            $user = get_user_by( 'email', $submission->get_billing_email() );
190
+        if (empty($user)) {
191
+            $user = get_user_by('email', $submission->get_billing_email());
192 192
         }
193 193
 
194
-        if ( empty( $user ) ) {
195
-            $user = wpinv_create_user( $submission->get_billing_email() );
194
+        if (empty($user)) {
195
+            $user = wpinv_create_user($submission->get_billing_email());
196 196
 
197 197
 			// (Maybe) send new user notification.
198
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
-				wp_send_new_user_notifications( $user, 'user' );
198
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
199
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
200
+				wp_send_new_user_notifications($user, 'user');
201 201
 			}
202 202
 
203 203
         }
204 204
 
205
-        if ( is_wp_error( $user ) ) {
206
-            wp_send_json_error( $user->get_error_message() );
205
+        if (is_wp_error($user)) {
206
+            wp_send_json_error($user->get_error_message());
207 207
         }
208 208
 
209
-        if ( is_numeric( $user ) ) {
209
+        if (is_numeric($user)) {
210 210
             return $user;
211 211
 		}
212 212
 
@@ -230,40 +230,40 @@  discard block
 block discarded – undo
230 230
 		);
231 231
 
232 232
         // Raw submission details.
233
-		$data     = $submission->get_data();
233
+		$data = $submission->get_data();
234 234
 
235 235
 		// Loop through the submitted details.
236
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
236
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
237 237
 
238 238
 			// Skip premade fields.
239
-            if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
239
+            if (!empty($field['premade']) || $field['type'] == 'address') {
240 240
                 continue;
241 241
             }
242 242
 
243 243
             // If it is required and not set, abort.
244
-            if ( ! $submission->is_required_field_set( $field ) ) {
245
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
244
+            if (!$submission->is_required_field_set($field)) {
245
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
246 246
             }
247 247
 
248 248
             // Handle misc fields.
249
-            if ( isset( $data[ $field['id'] ] ) ) {
249
+            if (isset($data[$field['id']])) {
250 250
 
251
-				if ( $field['type'] == 'checkbox' ) {
252
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
251
+				if ($field['type'] == 'checkbox') {
252
+					$value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
253 253
 				} else {
254
-					$value = wp_kses_post( $data[ $field['id'] ] );
254
+					$value = wp_kses_post($data[$field['id']]);
255 255
 				}
256 256
 
257 257
                 $label = $field['id'];
258 258
 
259
-                if ( isset( $field['label'] ) ) {
259
+                if (isset($field['label'])) {
260 260
                     $label = $field['label'];
261 261
                 }
262 262
 
263
-				if ( ! empty( $field['add_meta'] ) ) {
264
-					$prepared['meta'][ wpinv_clean( $label ) ] = $value;
263
+				if (!empty($field['add_meta'])) {
264
+					$prepared['meta'][wpinv_clean($label)] = $value;
265 265
 				}
266
-				$prepared['all'][ wpinv_clean( $label ) ] = $value;
266
+				$prepared['all'][wpinv_clean($label)] = $value;
267 267
 
268 268
             }
269 269
 
@@ -280,30 +280,30 @@  discard block
 block discarded – undo
280 280
 	 * @param WPInv_Invoice $invoice
281 281
 	 * @param string $type
282 282
      */
283
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
283
+    public function prepare_address_details($invoice, $type = 'billing') {
284 284
 
285 285
 		$data     = $this->payment_form_submission->get_data();
286
-		$type     = sanitize_key( $type );
286
+		$type     = sanitize_key($type);
287 287
 		$address  = array();
288 288
 		$prepared = array();
289 289
 
290
-		if ( ! empty( $data[ $type ] ) ) {
291
-			$address = $data[ $type ];
290
+		if (!empty($data[$type])) {
291
+			$address = $data[$type];
292 292
 		}
293 293
 
294 294
 		// Clean address details.
295
-		foreach ( $address as $key => $value ) {
296
-			$key             = sanitize_key( $key );
297
-			$key             = str_replace( 'wpinv_', '', $key );
298
-			$value           = wpinv_clean( $value );
299
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
295
+		foreach ($address as $key => $value) {
296
+			$key             = sanitize_key($key);
297
+			$key             = str_replace('wpinv_', '', $key);
298
+			$value           = wpinv_clean($value);
299
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
300 300
 		}
301 301
 
302 302
 		// Filter address details.
303
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
303
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
304 304
 
305 305
 		// Remove non-whitelisted values.
306
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
306
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
307 307
 
308 308
 	}
309 309
 
@@ -313,12 +313,12 @@  discard block
 block discarded – undo
313 313
 	 * @return array
314 314
 	 * @param WPInv_Invoice $invoice
315 315
      */
316
-    protected function prepare_billing_info( &$invoice ) {
316
+    protected function prepare_billing_info(&$invoice) {
317 317
 
318
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
318
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
319 319
 
320 320
 		// Update the invoice with the billing details.
321
-		$invoice->set_props( $billing_address );
321
+		$invoice->set_props($billing_address);
322 322
 
323 323
 	}
324 324
 
@@ -328,15 +328,15 @@  discard block
 block discarded – undo
328 328
 	 * @return array
329 329
 	 * @param WPInv_Invoice $invoice
330 330
      */
331
-    protected function prepare_shipping_info( $invoice ) {
331
+    protected function prepare_shipping_info($invoice) {
332 332
 
333 333
 		$data = $this->payment_form_submission->get_data();
334 334
 
335
-		if ( empty( $data['same-shipping-address'] ) ) {
336
-			return $this->prepare_address_details( $invoice, 'shipping' );
335
+		if (empty($data['same-shipping-address'])) {
336
+			return $this->prepare_address_details($invoice, 'shipping');
337 337
 		}
338 338
 
339
-		return $this->prepare_address_details( $invoice, 'billing' );
339
+		return $this->prepare_address_details($invoice, 'billing');
340 340
 
341 341
 	}
342 342
 
@@ -347,41 +347,41 @@  discard block
 block discarded – undo
347 347
 	 * @param array $prepared_payment_form_data
348 348
 	 * @param array $shipping
349 349
 	 */
350
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
350
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
351 351
 
352 352
 		// Ensure the invoice exists.
353
-        if ( ! $invoice->exists() ) {
354
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
353
+        if (!$invoice->exists()) {
354
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
355 355
         }
356 356
 
357 357
 		// Save payment form data.
358
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
359
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
360
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
361
-		if ( ! empty( $prepared_payment_form_data ) ) {
358
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
359
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
360
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
361
+		if (!empty($prepared_payment_form_data)) {
362 362
 
363
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
364
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
363
+			if (!empty($prepared_payment_form_data['all'])) {
364
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
365 365
 			}
366 366
 
367
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
368
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
367
+			if (!empty($prepared_payment_form_data['meta'])) {
368
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
369 369
 			}
370 370
 
371 371
 		}
372 372
 
373 373
 		// Save payment form data.
374
-        if ( ! empty( $shipping ) ) {
375
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
374
+        if (!empty($shipping)) {
375
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
376 376
 		}
377 377
 
378 378
 		// Backwards compatibility.
379
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
379
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
380 380
 
381
-		$this->process_payment( $invoice );
381
+		$this->process_payment($invoice);
382 382
 
383 383
         // If we are here, there was an error.
384
-		wpinv_send_back_to_checkout( $invoice );
384
+		wpinv_send_back_to_checkout($invoice);
385 385
 
386 386
 	}
387 387
 
@@ -390,41 +390,41 @@  discard block
 block discarded – undo
390 390
 	 *
391 391
 	 * @param WPInv_Invoice $invoice
392 392
 	 */
393
-	protected function process_payment( $invoice ) {
393
+	protected function process_payment($invoice) {
394 394
 
395 395
 		// Clear any checkout errors.
396 396
 		wpinv_clear_errors();
397 397
 
398 398
 		// No need to send free invoices to the gateway.
399
-		if ( $invoice->is_free() ) {
400
-			$this->process_free_payment( $invoice );
399
+		if ($invoice->is_free()) {
400
+			$this->process_free_payment($invoice);
401 401
 		}
402 402
 
403 403
 		$submission = $this->payment_form_submission;
404 404
 
405 405
 		// Fires before sending to the gateway.
406
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
406
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
407 407
 
408 408
 		// Allow the sumission data to be modified before it is sent to the gateway.
409 409
 		$submission_data    = $submission->get_data();
410
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
411
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
410
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
411
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
412 412
 
413 413
 		// Validate the currency.
414
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
415
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
414
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
415
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
416 416
 		}
417 417
 
418 418
 		// Check to see if we have any errors.
419
-		if ( wpinv_get_errors() ) {
420
-			wpinv_send_back_to_checkout( $invoice );
419
+		if (wpinv_get_errors()) {
420
+			wpinv_send_back_to_checkout($invoice);
421 421
 		}
422 422
 
423 423
 		// Send info to the gateway for payment processing
424
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
424
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
425 425
 
426 426
 		// Backwards compatibility.
427
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
427
+		wpinv_send_to_gateway($submission_gateway, $invoice);
428 428
 
429 429
 	}
430 430
 
@@ -433,12 +433,12 @@  discard block
 block discarded – undo
433 433
 	 *
434 434
 	 * @param WPInv_Invoice $invoice
435 435
 	 */
436
-	protected function process_free_payment( $invoice ) {
436
+	protected function process_free_payment($invoice) {
437 437
 
438
-		$invoice->set_gateway( 'none' );
439
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
438
+		$invoice->set_gateway('none');
439
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
440 440
 		$invoice->mark_paid();
441
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
441
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
442 442
 
443 443
 	}
444 444
 
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
      * Sends a redrect response to payment details.
447 447
      *
448 448
      */
449
-    public function send_redirect_response( $url ) {
450
-        $url = urlencode( $url );
451
-        wp_send_json_success( $url );
449
+    public function send_redirect_response($url) {
450
+        $url = urlencode($url);
451
+        wp_send_json_success($url);
452 452
     }
453 453
 
454 454
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +572 added lines, -572 removed lines patch added patch discarded remove patch
@@ -14,90 +14,90 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
66
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
67 67
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
75
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
76
-		do_action( 'getpaid_init_admin_hooks', $this );
77
-
78
-		// Setup/welcome
79
-		if ( ! empty( $_GET['page'] ) ) {
80
-			switch ( $_GET['page'] ) {
81
-				case 'gp-setup' :
82
-					include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
83
-					break;
84
-			}
85
-		}
68
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
70
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
71
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
74
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
75
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
76
+        do_action( 'getpaid_init_admin_hooks', $this );
77
+
78
+        // Setup/welcome
79
+        if ( ! empty( $_GET['page'] ) ) {
80
+            switch ( $_GET['page'] ) {
81
+                case 'gp-setup' :
82
+                    include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
83
+                    break;
84
+            }
85
+        }
86 86
 
87 87
     }
88 88
 
89 89
     /**
90
-	 * Register admin scripts
91
-	 *
92
-	 */
93
-	public function enqeue_scripts() {
90
+     * Register admin scripts
91
+     *
92
+     */
93
+    public function enqeue_scripts() {
94 94
         global $current_screen, $pagenow;
95 95
 
96
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
97
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
96
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
97
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
98 98
 
99 99
         if ( ! empty( $current_screen->post_type ) ) {
100
-			$page = $current_screen->post_type;
100
+            $page = $current_screen->post_type;
101 101
         }
102 102
 
103 103
         // General styles.
@@ -118,54 +118,54 @@  discard block
 block discarded – undo
118 118
         }
119 119
 
120 120
         // Payment form scripts.
121
-		if ( 'wpi_payment_form' == $page && $editing ) {
121
+        if ( 'wpi_payment_form' == $page && $editing ) {
122 122
             $this->load_payment_form_scripts();
123 123
         }
124 124
 
125
-		if ( $page == 'wpinv-subscriptions' ) {
126
-			wp_enqueue_script( 'postbox' );
127
-		}
125
+        if ( $page == 'wpinv-subscriptions' ) {
126
+            wp_enqueue_script( 'postbox' );
127
+        }
128 128
 
129 129
     }
130 130
 
131 131
     /**
132
-	 * Returns admin js translations.
133
-	 *
134
-	 */
135
-	protected function get_admin_i18() {
132
+     * Returns admin js translations.
133
+     *
134
+     */
135
+    protected function get_admin_i18() {
136 136
         global $post;
137 137
 
138
-		$date_range = array(
139
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
140
-		);
138
+        $date_range = array(
139
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
140
+        );
141 141
 
142
-		if ( $date_range['period'] == 'custom' ) {
142
+        if ( $date_range['period'] == 'custom' ) {
143 143
 			
144
-			if ( isset( $_GET['from'] ) ) {
145
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
146
-			}
144
+            if ( isset( $_GET['from'] ) ) {
145
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
146
+            }
147 147
 
148
-			if ( isset( $_GET['to'] ) ) {
149
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
150
-			}
148
+            if ( isset( $_GET['to'] ) ) {
149
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
150
+            }
151 151
 
152
-		}
152
+        }
153 153
 
154 154
         $i18n = array(
155 155
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
156 156
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
157
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
158
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
159
-			'rest_root'                 => esc_url_raw( rest_url() ),
160
-			'date_range'                => $date_range,
157
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
158
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
159
+            'rest_root'                 => esc_url_raw( rest_url() ),
160
+            'date_range'                => $date_range,
161 161
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
162 162
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
163 163
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
164 164
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
165 165
             'tax'                       => wpinv_tax_amount(),
166 166
             'discount'                  => 0,
167
-			'currency_symbol'           => wpinv_currency_symbol(),
168
-			'currency'                  => wpinv_get_currency(),
167
+            'currency_symbol'           => wpinv_currency_symbol(),
168
+            'currency'                  => wpinv_get_currency(),
169 169
             'currency_pos'              => wpinv_currency_position(),
170 170
             'thousand_sep'              => wpinv_thousands_separator(),
171 171
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -185,118 +185,118 @@  discard block
 block discarded – undo
185 185
             'item_description'          => __( 'Item Description', 'invoicing' ),
186 186
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
187 187
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
188
-			'searching'                 => __( 'Searching', 'invoicing' ),
189
-			'loading'                   => __( 'Loading...', 'invoicing' ),
190
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
191
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
188
+            'searching'                 => __( 'Searching', 'invoicing' ),
189
+            'loading'                   => __( 'Loading...', 'invoicing' ),
190
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
191
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
192 192
         );
193 193
 
194
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
194
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
195 195
 
196
-			$invoice              = new WPInv_Invoice( $post );
197
-			$i18n['save_invoice'] = sprintf(
198
-				__( 'Save %s', 'invoicing' ),
199
-				ucfirst( $invoice->get_invoice_quote_type() )
200
-			);
196
+            $invoice              = new WPInv_Invoice( $post );
197
+            $i18n['save_invoice'] = sprintf(
198
+                __( 'Save %s', 'invoicing' ),
199
+                ucfirst( $invoice->get_invoice_quote_type() )
200
+            );
201 201
 
202
-			$i18n['invoice_description'] = sprintf(
203
-				__( '%s Description', 'invoicing' ),
204
-				ucfirst( $invoice->get_invoice_quote_type() )
205
-			);
202
+            $i18n['invoice_description'] = sprintf(
203
+                __( '%s Description', 'invoicing' ),
204
+                ucfirst( $invoice->get_invoice_quote_type() )
205
+            );
206 206
 
207
-		}
208
-		return $i18n;
209
-	}
207
+        }
208
+        return $i18n;
209
+    }
210 210
 
211
-	/**
212
-	 * Change the admin footer text on GetPaid admin pages.
213
-	 *
214
-	 * @since  2.0.0
215
-	 * @param  string $footer_text
216
-	 * @return string
217
-	 */
218
-	public function admin_footer_text( $footer_text ) {
219
-		global $current_screen;
211
+    /**
212
+     * Change the admin footer text on GetPaid admin pages.
213
+     *
214
+     * @since  2.0.0
215
+     * @param  string $footer_text
216
+     * @return string
217
+     */
218
+    public function admin_footer_text( $footer_text ) {
219
+        global $current_screen;
220 220
 
221
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
221
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
222 222
 
223 223
         if ( ! empty( $current_screen->post_type ) ) {
224
-			$page = $current_screen->post_type;
224
+            $page = $current_screen->post_type;
225 225
         }
226 226
 
227 227
         // General styles.
228 228
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
229 229
 
230
-			// Change the footer text
231
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
232
-
233
-				$rating_url  = esc_url(
234
-					wp_nonce_url(
235
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
236
-						'getpaid-nonce',
237
-						'getpaid-nonce'
238
-						)
239
-				);
240
-
241
-				$footer_text = sprintf(
242
-					/* translators: %s: five stars */
243
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
244
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
245
-				);
246
-
247
-			} else {
248
-
249
-				$footer_text = sprintf(
250
-					/* translators: %s: GetPaid */
251
-					__( 'Thank you for using %s!', 'invoicing' ),
252
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
253
-				);
254
-
255
-			}
256
-
257
-		}
258
-
259
-		return $footer_text;
260
-	}
261
-
262
-	/**
263
-	 * Redirects to wp.org to rate the plugin.
264
-	 *
265
-	 * @since  2.0.0
266
-	 */
267
-	public function redirect_to_wordpress_rating_page() {
268
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
269
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
270
-		exit;
271
-	}
272
-
273
-    /**
274
-	 * Loads payment form js.
275
-	 *
276
-	 */
277
-	protected function load_payment_form_scripts() {
230
+            // Change the footer text
231
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
232
+
233
+                $rating_url  = esc_url(
234
+                    wp_nonce_url(
235
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
236
+                        'getpaid-nonce',
237
+                        'getpaid-nonce'
238
+                        )
239
+                );
240
+
241
+                $footer_text = sprintf(
242
+                    /* translators: %s: five stars */
243
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
244
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
245
+                );
246
+
247
+            } else {
248
+
249
+                $footer_text = sprintf(
250
+                    /* translators: %s: GetPaid */
251
+                    __( 'Thank you for using %s!', 'invoicing' ),
252
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
253
+                );
254
+
255
+            }
256
+
257
+        }
258
+
259
+        return $footer_text;
260
+    }
261
+
262
+    /**
263
+     * Redirects to wp.org to rate the plugin.
264
+     *
265
+     * @since  2.0.0
266
+     */
267
+    public function redirect_to_wordpress_rating_page() {
268
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
269
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
270
+        exit;
271
+    }
272
+
273
+    /**
274
+     * Loads payment form js.
275
+     *
276
+     */
277
+    protected function load_payment_form_scripts() {
278 278
         global $post;
279 279
 
280 280
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
281
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
282
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
281
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
282
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
283 283
 
284
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
285
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
284
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
285
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
286 286
 
287
-		wp_localize_script(
287
+        wp_localize_script(
288 288
             'wpinv-admin-payment-form-script',
289 289
             'wpinvPaymentFormAdmin',
290 290
             array(
291
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
292
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
293
-				'currency'      => wpinv_currency_symbol(),
294
-				'position'      => wpinv_currency_position(),
295
-				'decimals'      => (int) wpinv_decimals(),
296
-				'thousands_sep' => wpinv_thousands_separator(),
297
-				'decimals_sep'  => wpinv_decimal_separator(),
298
-				'form_items'    => gepaid_get_form_items( $post->ID ),
299
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
291
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
292
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
293
+                'currency'      => wpinv_currency_symbol(),
294
+                'position'      => wpinv_currency_position(),
295
+                'decimals'      => (int) wpinv_decimals(),
296
+                'thousands_sep' => wpinv_thousands_separator(),
297
+                'decimals_sep'  => wpinv_decimal_separator(),
298
+                'form_items'    => gepaid_get_form_items( $post->ID ),
299
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
300 300
             )
301 301
         );
302 302
 
@@ -305,20 +305,20 @@  discard block
 block discarded – undo
305 305
     }
306 306
 
307 307
     /**
308
-	 * Add our classes to admin pages.
308
+     * Add our classes to admin pages.
309 309
      *
310 310
      * @param string $classes
311 311
      * @return string
312
-	 *
313
-	 */
312
+     *
313
+     */
314 314
     public function admin_body_class( $classes ) {
315
-		global $pagenow, $post, $current_screen;
315
+        global $pagenow, $post, $current_screen;
316 316
 
317 317
 
318 318
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
319 319
 
320 320
         if ( ! empty( $current_screen->post_type ) ) {
321
-			$page = $current_screen->post_type;
321
+            $page = $current_screen->post_type;
322 322
         }
323 323
 
324 324
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -327,68 +327,68 @@  discard block
 block discarded – undo
327 327
 
328 328
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
329 329
             $classes .= ' wpinv-cpt wpinv';
330
-		}
330
+        }
331 331
 		
332
-		if ( getpaid_is_invoice_post_type( $page ) ) {
332
+        if ( getpaid_is_invoice_post_type( $page ) ) {
333 333
             $classes .= ' getpaid-is-invoice-cpt';
334 334
         }
335 335
 
336
-		return $classes;
336
+        return $classes;
337 337
     }
338 338
 
339 339
     /**
340
-	 * Maybe show the AyeCode Connect Notice.
341
-	 */
342
-	public function init_ayecode_connect_helper(){
340
+     * Maybe show the AyeCode Connect Notice.
341
+     */
342
+    public function init_ayecode_connect_helper(){
343 343
 
344
-		// Register with the deactivation survey class.
345
-		AyeCode_Deactivation_Survey::instance(array(
346
-			'slug'		        => 'invoicing',
347
-			'version'	        => WPINV_VERSION,
348
-			'support_url'       => 'https://wpgetpaid.com/support/',
349
-			'documentation_url' => 'https://docs.wpgetpaid.com/',
350
-			'activated'         => (int) get_option( 'gepaid_installed_on' ),
351
-		));
344
+        // Register with the deactivation survey class.
345
+        AyeCode_Deactivation_Survey::instance(array(
346
+            'slug'		        => 'invoicing',
347
+            'version'	        => WPINV_VERSION,
348
+            'support_url'       => 'https://wpgetpaid.com/support/',
349
+            'documentation_url' => 'https://docs.wpgetpaid.com/',
350
+            'activated'         => (int) get_option( 'gepaid_installed_on' ),
351
+        ));
352 352
 
353 353
         new AyeCode_Connect_Helper(
354 354
             array(
355
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
356
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
357
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
358
-				'connect_button'    => __("Connect Site","invoicing"),
359
-				'connecting_button'    => __("Connecting...","invoicing"),
360
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
361
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
355
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
356
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
357
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
358
+                'connect_button'    => __("Connect Site","invoicing"),
359
+                'connecting_button'    => __("Connecting...","invoicing"),
360
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
361
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
362 362
             ),
363 363
             array( 'wpi-addons' )
364 364
         );
365 365
 
366 366
     }
367 367
 
368
-	/**
369
-	 * Redirect users to settings on activation.
370
-	 *
371
-	 * @return void
372
-	 */
373
-	public function activation_redirect() {
368
+    /**
369
+     * Redirect users to settings on activation.
370
+     *
371
+     * @return void
372
+     */
373
+    public function activation_redirect() {
374 374
 
375
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
375
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
376 376
 
377
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
378
-			return;
379
-		}
377
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
378
+            return;
379
+        }
380 380
 
381
-		// Bail if activating from network, or bulk
382
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
383
-			return;
384
-		}
381
+        // Bail if activating from network, or bulk
382
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
383
+            return;
384
+        }
385 385
 
386
-	    update_option( 'wpinv_redirected_to_settings', 1 );
386
+        update_option( 'wpinv_redirected_to_settings', 1 );
387 387
 
388 388
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
389 389
         exit;
390 390
 
391
-	}
391
+    }
392 392
 
393 393
     /**
394 394
      * Fires an admin action after verifying that a user can fire them.
@@ -402,495 +402,495 @@  discard block
 block discarded – undo
402 402
 
403 403
     }
404 404
 
405
-	/**
405
+    /**
406 406
      * Sends a payment reminder to a customer.
407
-	 * 
408
-	 * @param array $args
407
+     * 
408
+     * @param array $args
409 409
      */
410 410
     public function duplicate_payment_form( $args ) {
411 411
 
412
-		if ( empty( $args['form_id'] ) ) {
413
-			return;
414
-		}
415
-
416
-		$form = new GetPaid_Payment_Form( $args['form_id'] );
412
+        if ( empty( $args['form_id'] ) ) {
413
+            return;
414
+        }
417 415
 
418
-		if ( ! $form->exists() ) {
419
-			return;
420
-		}
416
+        $form = new GetPaid_Payment_Form( $args['form_id'] );
421 417
 
422
-		$new_form = new GetPaid_Payment_Form();
423
-		$new_form->set_author( $form->get_author( 'edit' ) );
424
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
425
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
426
-		$new_form->set_items( $form->get_items( 'edit' ) );
427
-		$new_form->save();
418
+        if ( ! $form->exists() ) {
419
+            return;
420
+        }
428 421
 
429
-		if ( $new_form->exists() ) {
430
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
431
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
432
-		} else {
433
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
434
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
435
-		}
422
+        $new_form = new GetPaid_Payment_Form();
423
+        $new_form->set_author( $form->get_author( 'edit' ) );
424
+        $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
425
+        $new_form->set_elements( $form->get_elements( 'edit' ) );
426
+        $new_form->set_items( $form->get_items( 'edit' ) );
427
+        $new_form->save();
428
+
429
+        if ( $new_form->exists() ) {
430
+            $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
431
+            $url = get_edit_post_link( $new_form->get_id(), 'edit' );
432
+        } else {
433
+            $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
434
+            $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
435
+        }
436 436
 
437
-		wp_redirect( $url );
438
-		exit;
439
-	}
437
+        wp_redirect( $url );
438
+        exit;
439
+    }
440 440
 
441
-	/**
441
+    /**
442 442
      * Sends a payment reminder to a customer.
443
-	 * 
444
-	 * @param array $args
443
+     * 
444
+     * @param array $args
445 445
      */
446 446
     public function send_customer_invoice( $args ) {
447
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
447
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
448 448
 
449
-		if ( $sent ) {
450
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
451
-		} else {
452
-			$this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
453
-		}
449
+        if ( $sent ) {
450
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
451
+        } else {
452
+            $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
453
+        }
454 454
 
455
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
456
-		exit;
457
-	}
455
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
456
+        exit;
457
+    }
458 458
 
459
-	/**
459
+    /**
460 460
      * Sends a payment reminder to a customer.
461
-	 * 
462
-	 * @param array $args
461
+     * 
462
+     * @param array $args
463 463
      */
464 464
     public function send_customer_payment_reminder( $args ) {
465
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
465
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
466 466
 
467
-		if ( $sent ) {
468
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
469
-		} else {
470
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
471
-		}
467
+        if ( $sent ) {
468
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
469
+        } else {
470
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
471
+        }
472 472
 
473
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
474
-		exit;
475
-	}
473
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
474
+        exit;
475
+    }
476 476
 
477
-	/**
477
+    /**
478 478
      * Resets tax rates.
479
-	 * 
479
+     * 
480 480
      */
481 481
     public function admin_reset_tax_rates() {
482 482
 
483
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
484
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
485
-		exit;
483
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
484
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
485
+        exit;
486 486
 
487
-	}
487
+    }
488 488
 
489
-	/**
489
+    /**
490 490
      * Resets admin pages.
491
-	 * 
491
+     * 
492 492
      */
493 493
     public function admin_create_missing_pages() {
494
-		$installer = new GetPaid_Installer();
495
-		$installer->create_pages();
496
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
497
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
498
-		exit;
499
-	}
500
-
501
-	/**
494
+        $installer = new GetPaid_Installer();
495
+        $installer->create_pages();
496
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
497
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
498
+        exit;
499
+    }
500
+
501
+    /**
502 502
      * Creates an missing admin tables.
503
-	 * 
503
+     * 
504 504
      */
505 505
     public function admin_create_missing_tables() {
506
-		global $wpdb;
507
-		$installer = new GetPaid_Installer();
506
+        global $wpdb;
507
+        $installer = new GetPaid_Installer();
508 508
 
509
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
510
-			$installer->create_subscriptions_table();
509
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
510
+            $installer->create_subscriptions_table();
511 511
 
512
-			if ( $wpdb->last_error !== '' ) {
513
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
514
-			}
515
-		}
512
+            if ( $wpdb->last_error !== '' ) {
513
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
514
+            }
515
+        }
516 516
 
517
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
518
-			$installer->create_invoices_table();
517
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
518
+            $installer->create_invoices_table();
519 519
 
520
-			if ( $wpdb->last_error !== '' ) {
521
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
522
-			}
523
-		}
520
+            if ( $wpdb->last_error !== '' ) {
521
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
522
+            }
523
+        }
524 524
 
525
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
526
-			$installer->create_invoice_items_table();
525
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
526
+            $installer->create_invoice_items_table();
527 527
 
528
-			if ( $wpdb->last_error !== '' ) {
529
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
530
-			}
531
-		}
528
+            if ( $wpdb->last_error !== '' ) {
529
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
530
+            }
531
+        }
532 532
 
533
-		if ( ! $this->has_notices() ) {
534
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
535
-		}
533
+        if ( ! $this->has_notices() ) {
534
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
535
+        }
536 536
 
537
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
538
-		exit;
539
-	}
537
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
538
+        exit;
539
+    }
540 540
 
541
-	/**
541
+    /**
542 542
      * Migrates old invoices to the new database tables.
543
-	 * 
543
+     * 
544 544
      */
545 545
     public function admin_migrate_old_invoices() {
546 546
 
547
-		// Migrate the invoices.
548
-		$installer = new GetPaid_Installer();
549
-		$installer->migrate_old_invoices();
547
+        // Migrate the invoices.
548
+        $installer = new GetPaid_Installer();
549
+        $installer->migrate_old_invoices();
550 550
 
551
-		// Show an admin message.
552
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
551
+        // Show an admin message.
552
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
553 553
 
554
-		// Redirect the admin.
555
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
556
-		exit;
554
+        // Redirect the admin.
555
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
556
+        exit;
557 557
 
558
-	}
558
+    }
559 559
 
560
-	/**
560
+    /**
561 561
      * Download customers.
562
-	 * 
562
+     * 
563 563
      */
564 564
     public function admin_download_customers() {
565
-		global $wpdb;
565
+        global $wpdb;
566 566
 
567
-		$output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
567
+        $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
568 568
 
569
-		header( "Content-Type:text/csv" );
570
-		header( "Content-Disposition:attachment;filename=customers.csv" );
569
+        header( "Content-Type:text/csv" );
570
+        header( "Content-Disposition:attachment;filename=customers.csv" );
571 571
 
572
-		$post_types = '';
572
+        $post_types = '';
573 573
 
574
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
575
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
576
-		}
574
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
575
+            $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
576
+        }
577 577
 
578
-		$post_types = rtrim( $post_types, ' OR' );
578
+        $post_types = rtrim( $post_types, ' OR' );
579 579
 
580
-		$customers = $wpdb->get_col(
581
-			$wpdb->prepare(
582
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
583
-			)
584
-		);
580
+        $customers = $wpdb->get_col(
581
+            $wpdb->prepare(
582
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
583
+            )
584
+        );
585 585
 
586
-		$columns = array(
587
-			'name'     => __( 'Name', 'invoicing' ),
588
-			'email'    => __( 'Email', 'invoicing' ),
589
-			'country'  => __( 'Country', 'invoicing' ),
590
-			'state'    => __( 'State', 'invoicing' ),
591
-			'city'     => __( 'City', 'invoicing' ),
592
-			'zip'      => __( 'ZIP', 'invoicing' ),
593
-			'address'  => __( 'Address', 'invoicing' ),
594
-			'phone'    => __( 'Phone', 'invoicing' ),
595
-			'company'  => __( 'Company', 'invoicing' ),
596
-			'company_id'  => __( 'Company ID', 'invoicing' ),
597
-			'invoices' => __( 'Invoices', 'invoicing' ),
598
-			'total_raw' => __( 'Total Spend', 'invoicing' ),
599
-			'signup'   => __( 'Date created', 'invoicing' ),
600
-		);
586
+        $columns = array(
587
+            'name'     => __( 'Name', 'invoicing' ),
588
+            'email'    => __( 'Email', 'invoicing' ),
589
+            'country'  => __( 'Country', 'invoicing' ),
590
+            'state'    => __( 'State', 'invoicing' ),
591
+            'city'     => __( 'City', 'invoicing' ),
592
+            'zip'      => __( 'ZIP', 'invoicing' ),
593
+            'address'  => __( 'Address', 'invoicing' ),
594
+            'phone'    => __( 'Phone', 'invoicing' ),
595
+            'company'  => __( 'Company', 'invoicing' ),
596
+            'company_id'  => __( 'Company ID', 'invoicing' ),
597
+            'invoices' => __( 'Invoices', 'invoicing' ),
598
+            'total_raw' => __( 'Total Spend', 'invoicing' ),
599
+            'signup'   => __( 'Date created', 'invoicing' ),
600
+        );
601 601
 
602
-		// Output the csv column headers.
603
-		fputcsv( $output, array_values( $columns ) );
602
+        // Output the csv column headers.
603
+        fputcsv( $output, array_values( $columns ) );
604 604
 
605
-		// Loop through
606
-		$table = new WPInv_Customers_Table();
607
-		foreach ( $customers as $customer_id ) {
605
+        // Loop through
606
+        $table = new WPInv_Customers_Table();
607
+        foreach ( $customers as $customer_id ) {
608 608
 
609
-			$user = get_user_by( 'id', $customer_id );
610
-			$row  = array();
611
-			if ( empty( $user ) ) {
612
-				continue;
613
-			}
609
+            $user = get_user_by( 'id', $customer_id );
610
+            $row  = array();
611
+            if ( empty( $user ) ) {
612
+                continue;
613
+            }
614 614
 
615
-			foreach ( array_keys( $columns ) as $column ) {
615
+            foreach ( array_keys( $columns ) as $column ) {
616 616
 
617
-				$method = 'column_' . $column;
617
+                $method = 'column_' . $column;
618 618
 
619
-				if ( 'name' == $column ) {
620
-					$value = sanitize_text_field( $user->display_name );
621
-				} else if( 'email' == $column ) {
622
-					$value = sanitize_email( $user->user_email );
623
-				} else if ( is_callable( array( $table, $method ) ) ) {
624
-					$value = strip_tags( $table->$method( $user ) );
625
-				}
619
+                if ( 'name' == $column ) {
620
+                    $value = sanitize_text_field( $user->display_name );
621
+                } else if( 'email' == $column ) {
622
+                    $value = sanitize_email( $user->user_email );
623
+                } else if ( is_callable( array( $table, $method ) ) ) {
624
+                    $value = strip_tags( $table->$method( $user ) );
625
+                }
626 626
 
627
-				if ( empty( $value ) ) {
628
-					$value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
629
-				}
627
+                if ( empty( $value ) ) {
628
+                    $value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
629
+                }
630 630
 
631
-				$row[] = $value;
631
+                $row[] = $value;
632 632
 
633
-			}
633
+            }
634 634
 
635
-			fputcsv( $output, $row );
636
-		}
635
+            fputcsv( $output, $row );
636
+        }
637 637
 
638
-		fclose( $output );
639
-		exit;
638
+        fclose( $output );
639
+        exit;
640 640
 
641
-	}
641
+    }
642 642
 
643
-	/**
643
+    /**
644 644
      * Installs a plugin.
645
-	 *
646
-	 * @param array $data
645
+     *
646
+     * @param array $data
647 647
      */
648 648
     public function admin_install_plugin( $data ) {
649 649
 
650
-		if ( ! empty( $data['plugins'] ) ) {
651
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
652
-			wp_cache_flush();
650
+        if ( ! empty( $data['plugins'] ) ) {
651
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
652
+            wp_cache_flush();
653 653
 
654
-			foreach ( $data['plugins'] as $slug => $file ) {
655
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
656
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
657
-				$installed  = $upgrader->install( $plugin_zip );
654
+            foreach ( $data['plugins'] as $slug => $file ) {
655
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
656
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
657
+                $installed  = $upgrader->install( $plugin_zip );
658 658
 
659
-				if ( ! is_wp_error( $installed ) && $installed ) {
660
-					activate_plugin( $file, '', false, true );
661
-				} else {
662
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
663
-				}
659
+                if ( ! is_wp_error( $installed ) && $installed ) {
660
+                    activate_plugin( $file, '', false, true );
661
+                } else {
662
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
663
+                }
664 664
 
665
-			}
665
+            }
666 666
 
667
-		}
667
+        }
668 668
 
669
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
670
-		wp_safe_redirect( $redirect );
671
-		exit;
669
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
670
+        wp_safe_redirect( $redirect );
671
+        exit;
672 672
 
673
-	}
673
+    }
674 674
 
675
-	/**
675
+    /**
676 676
      * Connects a gateway.
677
-	 *
678
-	 * @param array $data
677
+     *
678
+     * @param array $data
679 679
      */
680 680
     public function admin_connect_gateway( $data ) {
681 681
 
682
-		if ( ! empty( $data['plugin'] ) ) {
682
+        if ( ! empty( $data['plugin'] ) ) {
683 683
 
684
-			$gateway     = sanitize_key( $data['plugin'] );
685
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
684
+            $gateway     = sanitize_key( $data['plugin'] );
685
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
686 686
 
687
-			if ( ! empty( $connect_url ) ) {
688
-				wp_redirect( $connect_url );
689
-				exit;
690
-			}
687
+            if ( ! empty( $connect_url ) ) {
688
+                wp_redirect( $connect_url );
689
+                exit;
690
+            }
691 691
 
692
-			if ( 'stripe' == $data['plugin'] ) {
693
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
692
+            if ( 'stripe' == $data['plugin'] ) {
693
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
694 694
 
695
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
696
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
697
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
698
-					$upgrader->install( $plugin_zip );
699
-				}
695
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
696
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
697
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
698
+                    $upgrader->install( $plugin_zip );
699
+                }
700 700
 
701
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
702
-			}
701
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
702
+            }
703 703
 
704
-			if ( ! empty( $connect_url ) ) {
705
-				wp_redirect( $connect_url );
706
-				exit;
707
-			}
704
+            if ( ! empty( $connect_url ) ) {
705
+                wp_redirect( $connect_url );
706
+                exit;
707
+            }
708 708
 
709
-		}
709
+        }
710 710
 
711
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
712
-		wp_safe_redirect( $redirect );
713
-		exit;
711
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
712
+        wp_safe_redirect( $redirect );
713
+        exit;
714 714
 
715
-	}
715
+    }
716 716
 
717
-	/**
717
+    /**
718 718
      * Recalculates discounts.
719
-	 * 
719
+     * 
720 720
      */
721 721
     public function admin_recalculate_discounts() {
722
-		global $wpdb;
722
+        global $wpdb;
723 723
 
724
-		// Fetch all invoices that have discount codes.
725
-		$table    = $wpdb->prefix . 'getpaid_invoices';
726
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
724
+        // Fetch all invoices that have discount codes.
725
+        $table    = $wpdb->prefix . 'getpaid_invoices';
726
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
727 727
 
728
-		foreach ( $invoices as $invoice ) {
728
+        foreach ( $invoices as $invoice ) {
729 729
 
730
-			$invoice = new WPInv_Invoice( $invoice );
730
+            $invoice = new WPInv_Invoice( $invoice );
731 731
 
732
-			if ( ! $invoice->exists() ) {
733
-				continue;
734
-			}
732
+            if ( ! $invoice->exists() ) {
733
+                continue;
734
+            }
735 735
 
736
-			// Abort if the discount does not exist or does not apply here.
737
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
738
-			if ( ! $discount->exists() ) {
739
-				continue;
740
-			}
736
+            // Abort if the discount does not exist or does not apply here.
737
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
738
+            if ( ! $discount->exists() ) {
739
+                continue;
740
+            }
741 741
 
742
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
743
-			$invoice->recalculate_total();
742
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
743
+            $invoice->recalculate_total();
744 744
 
745
-			if ( $invoice->get_total_discount() > 0 ) {
746
-				$invoice->save();
747
-			}
745
+            if ( $invoice->get_total_discount() > 0 ) {
746
+                $invoice->save();
747
+            }
748 748
 
749
-		}
749
+        }
750 750
 
751
-		// Show an admin message.
752
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
751
+        // Show an admin message.
752
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
753 753
 
754
-		// Redirect the admin.
755
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
756
-		exit;
754
+        // Redirect the admin.
755
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
756
+        exit;
757 757
 
758
-	}
758
+    }
759 759
 
760 760
     /**
761
-	 * Returns an array of admin notices.
762
-	 *
763
-	 * @since       1.0.19
761
+     * Returns an array of admin notices.
762
+     *
763
+     * @since       1.0.19
764 764
      * @return array
765
-	 */
766
-	public function get_notices() {
767
-		$notices = get_option( 'wpinv_admin_notices' );
765
+     */
766
+    public function get_notices() {
767
+        $notices = get_option( 'wpinv_admin_notices' );
768 768
         return is_array( $notices ) ? $notices : array();
769
-	}
769
+    }
770 770
 
771
-	/**
772
-	 * Checks if we have any admin notices.
773
-	 *
774
-	 * @since       2.0.4
771
+    /**
772
+     * Checks if we have any admin notices.
773
+     *
774
+     * @since       2.0.4
775 775
      * @return array
776
-	 */
777
-	public function has_notices() {
778
-		return count( $this->get_notices() ) > 0;
779
-	}
780
-
781
-	/**
782
-	 * Clears all admin notices
783
-	 *
784
-	 * @access      public
785
-	 * @since       1.0.19
786
-	 */
787
-	public function clear_notices() {
788
-		delete_option( 'wpinv_admin_notices' );
789
-	}
790
-
791
-	/**
792
-	 * Saves a new admin notice
793
-	 *
794
-	 * @access      public
795
-	 * @since       1.0.19
796
-	 */
797
-	public function save_notice( $type, $message ) {
798
-		$notices = $this->get_notices();
799
-
800
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
801
-			$notices[ $type ] = array();
802
-		}
803
-
804
-		$notices[ $type ][] = $message;
805
-
806
-		update_option( 'wpinv_admin_notices', $notices );
807
-	}
808
-
809
-	/**
810
-	 * Displays a success notice
811
-	 *
812
-	 * @param       string $msg The message to qeue.
813
-	 * @access      public
814
-	 * @since       1.0.19
815
-	 */
816
-	public function show_success( $msg ) {
817
-		$this->save_notice( 'success', $msg );
818
-	}
819
-
820
-	/**
821
-	 * Displays a error notice
822
-	 *
823
-	 * @access      public
824
-	 * @param       string $msg The message to qeue.
825
-	 * @since       1.0.19
826
-	 */
827
-	public function show_error( $msg ) {
828
-		$this->save_notice( 'error', $msg );
829
-	}
830
-
831
-	/**
832
-	 * Displays a warning notice
833
-	 *
834
-	 * @access      public
835
-	 * @param       string $msg The message to qeue.
836
-	 * @since       1.0.19
837
-	 */
838
-	public function show_warning( $msg ) {
839
-		$this->save_notice( 'warning', $msg );
840
-	}
841
-
842
-	/**
843
-	 * Displays a info notice
844
-	 *
845
-	 * @access      public
846
-	 * @param       string $msg The message to qeue.
847
-	 * @since       1.0.19
848
-	 */
849
-	public function show_info( $msg ) {
850
-		$this->save_notice( 'info', $msg );
851
-	}
852
-
853
-	/**
854
-	 * Show notices
855
-	 *
856
-	 * @access      public
857
-	 * @since       1.0.19
858
-	 */
859
-	public function show_notices() {
776
+     */
777
+    public function has_notices() {
778
+        return count( $this->get_notices() ) > 0;
779
+    }
780
+
781
+    /**
782
+     * Clears all admin notices
783
+     *
784
+     * @access      public
785
+     * @since       1.0.19
786
+     */
787
+    public function clear_notices() {
788
+        delete_option( 'wpinv_admin_notices' );
789
+    }
790
+
791
+    /**
792
+     * Saves a new admin notice
793
+     *
794
+     * @access      public
795
+     * @since       1.0.19
796
+     */
797
+    public function save_notice( $type, $message ) {
798
+        $notices = $this->get_notices();
799
+
800
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
801
+            $notices[ $type ] = array();
802
+        }
803
+
804
+        $notices[ $type ][] = $message;
805
+
806
+        update_option( 'wpinv_admin_notices', $notices );
807
+    }
808
+
809
+    /**
810
+     * Displays a success notice
811
+     *
812
+     * @param       string $msg The message to qeue.
813
+     * @access      public
814
+     * @since       1.0.19
815
+     */
816
+    public function show_success( $msg ) {
817
+        $this->save_notice( 'success', $msg );
818
+    }
819
+
820
+    /**
821
+     * Displays a error notice
822
+     *
823
+     * @access      public
824
+     * @param       string $msg The message to qeue.
825
+     * @since       1.0.19
826
+     */
827
+    public function show_error( $msg ) {
828
+        $this->save_notice( 'error', $msg );
829
+    }
830
+
831
+    /**
832
+     * Displays a warning notice
833
+     *
834
+     * @access      public
835
+     * @param       string $msg The message to qeue.
836
+     * @since       1.0.19
837
+     */
838
+    public function show_warning( $msg ) {
839
+        $this->save_notice( 'warning', $msg );
840
+    }
841
+
842
+    /**
843
+     * Displays a info notice
844
+     *
845
+     * @access      public
846
+     * @param       string $msg The message to qeue.
847
+     * @since       1.0.19
848
+     */
849
+    public function show_info( $msg ) {
850
+        $this->save_notice( 'info', $msg );
851
+    }
852
+
853
+    /**
854
+     * Show notices
855
+     *
856
+     * @access      public
857
+     * @since       1.0.19
858
+     */
859
+    public function show_notices() {
860 860
 
861 861
         $notices = $this->get_notices();
862 862
         $this->clear_notices();
863 863
 
864
-		foreach ( $notices as $type => $messages ) {
864
+        foreach ( $notices as $type => $messages ) {
865 865
 
866
-			if ( ! is_array( $messages ) ) {
867
-				continue;
868
-			}
866
+            if ( ! is_array( $messages ) ) {
867
+                continue;
868
+            }
869 869
 
870 870
             $type  = sanitize_key( $type );
871
-			foreach ( $messages as $message ) {
871
+            foreach ( $messages as $message ) {
872 872
                 $message = wp_kses_post( $message );
873
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
873
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
874 874
             }
875 875
 
876 876
         }
877 877
 
878
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
879
-
880
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
881
-				$url     = wp_nonce_url(
882
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
883
-					'getpaid-nonce',
884
-					'getpaid-nonce'
885
-				);
886
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
887
-				$message2 = __( 'Generate Pages', 'invoicing' );
888
-				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
889
-				break;
890
-			}
878
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
879
+
880
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
881
+                $url     = wp_nonce_url(
882
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
883
+                    'getpaid-nonce',
884
+                    'getpaid-nonce'
885
+                );
886
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
887
+                $message2 = __( 'Generate Pages', 'invoicing' );
888
+                echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
889
+                break;
890
+            }
891 891
 
892
-		}
892
+        }
893 893
 
894
-	}
894
+    }
895 895
 
896 896
 }
Please login to merge, or discard this patch.
Spacing   +269 added lines, -269 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
  * The main admin class.
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
     /**
38 38
 	 * Class constructor.
39 39
 	 */
40
-	public function __construct(){
40
+	public function __construct() {
41 41
 
42
-        $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
42
+        $this->admin_path = plugin_dir_path(__FILE__);
43
+		$this->admin_url   = plugins_url('/', __FILE__);
44 44
 		$this->reports     = new GetPaid_Reports();
45 45
 
46
-        if ( is_admin() ) {
46
+        if (is_admin()) {
47 47
 			$this->init_admin_hooks();
48 48
         }
49 49
 
@@ -54,32 +54,32 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 */
56 56
 	private function init_admin_hooks() {
57
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
61
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
67
-        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
75
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
76
-		do_action( 'getpaid_init_admin_hooks', $this );
57
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
58
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
59
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
60
+        add_action('admin_init', array($this, 'activation_redirect'));
61
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
62
+		add_action('admin_notices', array($this, 'show_notices'));
63
+		add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page'));
64
+		add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form'));
65
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
66
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
67
+        add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates'));
68
+		add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages'));
69
+		add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables'));
70
+		add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices'));
71
+		add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers'));
72
+		add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts'));
73
+		add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin'));
74
+		add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway'));
75
+		add_filter('admin_footer_text', array($this, 'admin_footer_text'));
76
+		do_action('getpaid_init_admin_hooks', $this);
77 77
 
78 78
 		// Setup/welcome
79
-		if ( ! empty( $_GET['page'] ) ) {
80
-			switch ( $_GET['page'] ) {
79
+		if (!empty($_GET['page'])) {
80
+			switch ($_GET['page']) {
81 81
 				case 'gp-setup' :
82
-					include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
82
+					include_once(dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php');
83 83
 					break;
84 84
 			}
85 85
 		}
@@ -93,37 +93,37 @@  discard block
 block discarded – undo
93 93
 	public function enqeue_scripts() {
94 94
         global $current_screen, $pagenow;
95 95
 
96
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
96
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
97 97
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
98 98
 
99
-        if ( ! empty( $current_screen->post_type ) ) {
99
+        if (!empty($current_screen->post_type)) {
100 100
 			$page = $current_screen->post_type;
101 101
         }
102 102
 
103 103
         // General styles.
104
-        if ( false !== stripos( $page, 'wpi' ) || 'gp-setup' == $page ) {
104
+        if (false !== stripos($page, 'wpi') || 'gp-setup' == $page) {
105 105
 
106 106
             // Styles.
107
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
108
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
109
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
107
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
108
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
109
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
110 110
 
111 111
             // Scripts.
112
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
112
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
113 113
 
114
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
115
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ),  $version );
116
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
114
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
115
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version);
116
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
117 117
 
118 118
         }
119 119
 
120 120
         // Payment form scripts.
121
-		if ( 'wpi_payment_form' == $page && $editing ) {
121
+		if ('wpi_payment_form' == $page && $editing) {
122 122
             $this->load_payment_form_scripts();
123 123
         }
124 124
 
125
-		if ( $page == 'wpinv-subscriptions' ) {
126
-			wp_enqueue_script( 'postbox' );
125
+		if ($page == 'wpinv-subscriptions') {
126
+			wp_enqueue_script('postbox');
127 127
 		}
128 128
 
129 129
     }
@@ -136,32 +136,32 @@  discard block
 block discarded – undo
136 136
         global $post;
137 137
 
138 138
 		$date_range = array(
139
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
139
+			'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days'
140 140
 		);
141 141
 
142
-		if ( $date_range['period'] == 'custom' ) {
142
+		if ($date_range['period'] == 'custom') {
143 143
 			
144
-			if ( isset( $_GET['from'] ) ) {
145
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
144
+			if (isset($_GET['from'])) {
145
+				$date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS);
146 146
 			}
147 147
 
148
-			if ( isset( $_GET['to'] ) ) {
149
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
148
+			if (isset($_GET['to'])) {
149
+				$date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS);
150 150
 			}
151 151
 
152 152
 		}
153 153
 
154 154
         $i18n = array(
155
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
156
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
157
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
158
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
159
-			'rest_root'                 => esc_url_raw( rest_url() ),
155
+            'ajax_url'                  => admin_url('admin-ajax.php'),
156
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
157
+			'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
158
+			'rest_nonce'                => wp_create_nonce('wp_rest'),
159
+			'rest_root'                 => esc_url_raw(rest_url()),
160 160
 			'date_range'                => $date_range,
161
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
162
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
163
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
164
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
161
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
162
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
163
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
164
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
165 165
             'tax'                       => wpinv_tax_amount(),
166 166
             'discount'                  => 0,
167 167
 			'currency_symbol'           => wpinv_currency_symbol(),
@@ -170,38 +170,38 @@  discard block
 block discarded – undo
170 170
             'thousand_sep'              => wpinv_thousands_separator(),
171 171
             'decimal_sep'               => wpinv_decimal_separator(),
172 172
             'decimals'                  => wpinv_decimals(),
173
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
174
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
175
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
176
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
177
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
178
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
179
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
180
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
181
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
182
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
183
-            'action_edit'               => __( 'Edit', 'invoicing' ),
184
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
185
-            'item_description'          => __( 'Item Description', 'invoicing' ),
186
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
187
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
188
-			'searching'                 => __( 'Searching', 'invoicing' ),
189
-			'loading'                   => __( 'Loading...', 'invoicing' ),
190
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
191
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
173
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
174
+            'status_publish'            => wpinv_status_nicename('publish'),
175
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
176
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
177
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
178
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
179
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
180
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
181
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
182
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
183
+            'action_edit'               => __('Edit', 'invoicing'),
184
+            'action_cancel'             => __('Cancel', 'invoicing'),
185
+            'item_description'          => __('Item Description', 'invoicing'),
186
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
187
+            'discount_description'      => __('Discount Description', 'invoicing'),
188
+			'searching'                 => __('Searching', 'invoicing'),
189
+			'loading'                   => __('Loading...', 'invoicing'),
190
+			'search_customers'          => __('Enter customer name or email', 'invoicing'),
191
+			'search_items'              => __('Enter item name', 'invoicing'),
192 192
         );
193 193
 
194
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
194
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
195 195
 
196
-			$invoice              = new WPInv_Invoice( $post );
196
+			$invoice              = new WPInv_Invoice($post);
197 197
 			$i18n['save_invoice'] = sprintf(
198
-				__( 'Save %s', 'invoicing' ),
199
-				ucfirst( $invoice->get_invoice_quote_type() )
198
+				__('Save %s', 'invoicing'),
199
+				ucfirst($invoice->get_invoice_quote_type())
200 200
 			);
201 201
 
202 202
 			$i18n['invoice_description'] = sprintf(
203
-				__( '%s Description', 'invoicing' ),
204
-				ucfirst( $invoice->get_invoice_quote_type() )
203
+				__('%s Description', 'invoicing'),
204
+				ucfirst($invoice->get_invoice_quote_type())
205 205
 			);
206 206
 
207 207
 		}
@@ -215,24 +215,24 @@  discard block
 block discarded – undo
215 215
 	 * @param  string $footer_text
216 216
 	 * @return string
217 217
 	 */
218
-	public function admin_footer_text( $footer_text ) {
218
+	public function admin_footer_text($footer_text) {
219 219
 		global $current_screen;
220 220
 
221
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
221
+		$page = isset($_GET['page']) ? $_GET['page'] : '';
222 222
 
223
-        if ( ! empty( $current_screen->post_type ) ) {
223
+        if (!empty($current_screen->post_type)) {
224 224
 			$page = $current_screen->post_type;
225 225
         }
226 226
 
227 227
         // General styles.
228
-        if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
228
+        if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) {
229 229
 
230 230
 			// Change the footer text
231
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
231
+			if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) {
232 232
 
233
-				$rating_url  = esc_url(
233
+				$rating_url = esc_url(
234 234
 					wp_nonce_url(
235
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
235
+						admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'),
236 236
 						'getpaid-nonce',
237 237
 						'getpaid-nonce'
238 238
 						)
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 
241 241
 				$footer_text = sprintf(
242 242
 					/* translators: %s: five stars */
243
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
243
+					__('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'),
244 244
 					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
245 245
 				);
246 246
 
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
 				$footer_text = sprintf(
250 250
 					/* translators: %s: GetPaid */
251
-					__( 'Thank you for using %s!', 'invoicing' ),
251
+					__('Thank you for using %s!', 'invoicing'),
252 252
 					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
253 253
 				);
254 254
 
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
 	 * @since  2.0.0
266 266
 	 */
267 267
 	public function redirect_to_wordpress_rating_page() {
268
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
269
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
268
+		update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1);
269
+		wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post');
270 270
 		exit;
271 271
 	}
272 272
 
@@ -277,30 +277,30 @@  discard block
 block discarded – undo
277 277
 	protected function load_payment_form_scripts() {
278 278
         global $post;
279 279
 
280
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
281
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
282
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
280
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION);
281
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
282
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
283 283
 
284
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
285
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
284
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
285
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
286 286
 
287 287
 		wp_localize_script(
288 288
             'wpinv-admin-payment-form-script',
289 289
             'wpinvPaymentFormAdmin',
290 290
             array(
291
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
292
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
291
+				'elements'      => wpinv_get_data('payment-form-elements'),
292
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
293 293
 				'currency'      => wpinv_currency_symbol(),
294 294
 				'position'      => wpinv_currency_position(),
295 295
 				'decimals'      => (int) wpinv_decimals(),
296 296
 				'thousands_sep' => wpinv_thousands_separator(),
297 297
 				'decimals_sep'  => wpinv_decimal_separator(),
298
-				'form_items'    => gepaid_get_form_items( $post->ID ),
298
+				'form_items'    => gepaid_get_form_items($post->ID),
299 299
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
300 300
             )
301 301
         );
302 302
 
303
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
303
+        wp_enqueue_script('wpinv-admin-payment-form-script');
304 304
 
305 305
     }
306 306
 
@@ -311,25 +311,25 @@  discard block
 block discarded – undo
311 311
      * @return string
312 312
 	 *
313 313
 	 */
314
-    public function admin_body_class( $classes ) {
314
+    public function admin_body_class($classes) {
315 315
 		global $pagenow, $post, $current_screen;
316 316
 
317 317
 
318
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
318
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
319 319
 
320
-        if ( ! empty( $current_screen->post_type ) ) {
320
+        if (!empty($current_screen->post_type)) {
321 321
 			$page = $current_screen->post_type;
322 322
         }
323 323
 
324
-        if ( false !== stripos( $page, 'wpi' ) ) {
325
-            $classes .= ' wpi-' . sanitize_key( $page );
324
+        if (false !== stripos($page, 'wpi')) {
325
+            $classes .= ' wpi-' . sanitize_key($page);
326 326
         }
327 327
 
328
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
328
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
329 329
             $classes .= ' wpinv-cpt wpinv';
330 330
 		}
331 331
 		
332
-		if ( getpaid_is_invoice_post_type( $page ) ) {
332
+		if (getpaid_is_invoice_post_type($page)) {
333 333
             $classes .= ' getpaid-is-invoice-cpt';
334 334
         }
335 335
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     /**
340 340
 	 * Maybe show the AyeCode Connect Notice.
341 341
 	 */
342
-	public function init_ayecode_connect_helper(){
342
+	public function init_ayecode_connect_helper() {
343 343
 
344 344
 		// Register with the deactivation survey class.
345 345
 		AyeCode_Deactivation_Survey::instance(array(
@@ -347,20 +347,20 @@  discard block
 block discarded – undo
347 347
 			'version'	        => WPINV_VERSION,
348 348
 			'support_url'       => 'https://wpgetpaid.com/support/',
349 349
 			'documentation_url' => 'https://docs.wpgetpaid.com/',
350
-			'activated'         => (int) get_option( 'gepaid_installed_on' ),
350
+			'activated'         => (int) get_option('gepaid_installed_on'),
351 351
 		));
352 352
 
353 353
         new AyeCode_Connect_Helper(
354 354
             array(
355
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
356
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
357
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
358
-				'connect_button'    => __("Connect Site","invoicing"),
359
-				'connecting_button'    => __("Connecting...","invoicing"),
360
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
361
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
355
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
356
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
357
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
358
+				'connect_button'    => __("Connect Site", "invoicing"),
359
+				'connecting_button'    => __("Connecting...", "invoicing"),
360
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
361
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
362 362
             ),
363
-            array( 'wpi-addons' )
363
+            array('wpi-addons')
364 364
         );
365 365
 
366 366
     }
@@ -372,20 +372,20 @@  discard block
 block discarded – undo
372 372
 	 */
373 373
 	public function activation_redirect() {
374 374
 
375
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
375
+		$redirected = get_option('wpinv_redirected_to_settings');
376 376
 
377
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
377
+		if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) {
378 378
 			return;
379 379
 		}
380 380
 
381 381
 		// Bail if activating from network, or bulk
382
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
382
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
383 383
 			return;
384 384
 		}
385 385
 
386
-	    update_option( 'wpinv_redirected_to_settings', 1 );
386
+	    update_option('wpinv_redirected_to_settings', 1);
387 387
 
388
-        wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
388
+        wp_safe_redirect(admin_url('index.php?page=gp-setup'));
389 389
         exit;
390 390
 
391 391
 	}
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
      */
396 396
     public function maybe_do_admin_action() {
397 397
 
398
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
399
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
400
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
398
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
399
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
400
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
401 401
         }
402 402
 
403 403
     }
@@ -407,34 +407,34 @@  discard block
 block discarded – undo
407 407
 	 * 
408 408
 	 * @param array $args
409 409
      */
410
-    public function duplicate_payment_form( $args ) {
410
+    public function duplicate_payment_form($args) {
411 411
 
412
-		if ( empty( $args['form_id'] ) ) {
412
+		if (empty($args['form_id'])) {
413 413
 			return;
414 414
 		}
415 415
 
416
-		$form = new GetPaid_Payment_Form( $args['form_id'] );
416
+		$form = new GetPaid_Payment_Form($args['form_id']);
417 417
 
418
-		if ( ! $form->exists() ) {
418
+		if (!$form->exists()) {
419 419
 			return;
420 420
 		}
421 421
 
422 422
 		$new_form = new GetPaid_Payment_Form();
423
-		$new_form->set_author( $form->get_author( 'edit' ) );
424
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
425
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
426
-		$new_form->set_items( $form->get_items( 'edit' ) );
423
+		$new_form->set_author($form->get_author('edit'));
424
+		$new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing'));
425
+		$new_form->set_elements($form->get_elements('edit'));
426
+		$new_form->set_items($form->get_items('edit'));
427 427
 		$new_form->save();
428 428
 
429
-		if ( $new_form->exists() ) {
430
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
431
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
429
+		if ($new_form->exists()) {
430
+			$this->show_success(__('Form duplicated successfully', 'invoicing'));
431
+			$url = get_edit_post_link($new_form->get_id(), 'edit');
432 432
 		} else {
433
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
434
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
433
+			$this->show_error(__('Unable to duplicate form', 'invoicing'));
434
+			$url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce'));
435 435
 		}
436 436
 
437
-		wp_redirect( $url );
437
+		wp_redirect($url);
438 438
 		exit;
439 439
 	}
440 440
 
@@ -443,16 +443,16 @@  discard block
 block discarded – undo
443 443
 	 * 
444 444
 	 * @param array $args
445 445
      */
446
-    public function send_customer_invoice( $args ) {
447
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
446
+    public function send_customer_invoice($args) {
447
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true);
448 448
 
449
-		if ( $sent ) {
450
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
449
+		if ($sent) {
450
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
451 451
 		} else {
452
-			$this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
452
+			$this->show_error(__('Could not send the invoice to the customer', 'invoicing'));
453 453
 		}
454 454
 
455
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
455
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
456 456
 		exit;
457 457
 	}
458 458
 
@@ -461,16 +461,16 @@  discard block
 block discarded – undo
461 461
 	 * 
462 462
 	 * @param array $args
463 463
      */
464
-    public function send_customer_payment_reminder( $args ) {
465
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
464
+    public function send_customer_payment_reminder($args) {
465
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
466 466
 
467
-		if ( $sent ) {
468
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
467
+		if ($sent) {
468
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
469 469
 		} else {
470
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
470
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
471 471
 		}
472 472
 
473
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
473
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
474 474
 		exit;
475 475
 	}
476 476
 
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
      */
481 481
     public function admin_reset_tax_rates() {
482 482
 
483
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
484
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
483
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
484
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
485 485
 		exit;
486 486
 
487 487
 	}
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
     public function admin_create_missing_pages() {
494 494
 		$installer = new GetPaid_Installer();
495 495
 		$installer->create_pages();
496
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
497
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
496
+		$this->show_success(__('GetPaid pages updated.', 'invoicing'));
497
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
498 498
 		exit;
499 499
 	}
500 500
 
@@ -506,35 +506,35 @@  discard block
 block discarded – undo
506 506
 		global $wpdb;
507 507
 		$installer = new GetPaid_Installer();
508 508
 
509
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
509
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') {
510 510
 			$installer->create_subscriptions_table();
511 511
 
512
-			if ( $wpdb->last_error !== '' ) {
513
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
512
+			if ($wpdb->last_error !== '') {
513
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
514 514
 			}
515 515
 		}
516 516
 
517
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
517
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') {
518 518
 			$installer->create_invoices_table();
519 519
 
520
-			if ( $wpdb->last_error !== '' ) {
521
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
520
+			if ($wpdb->last_error !== '') {
521
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
522 522
 			}
523 523
 		}
524 524
 
525
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
525
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') {
526 526
 			$installer->create_invoice_items_table();
527 527
 
528
-			if ( $wpdb->last_error !== '' ) {
529
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
528
+			if ($wpdb->last_error !== '') {
529
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
530 530
 			}
531 531
 		}
532 532
 
533
-		if ( ! $this->has_notices() ) {
534
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
533
+		if (!$this->has_notices()) {
534
+			$this->show_success(__('Your GetPaid tables have been updated.', 'invoicing'));
535 535
 		}
536 536
 
537
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
537
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
538 538
 		exit;
539 539
 	}
540 540
 
@@ -549,10 +549,10 @@  discard block
 block discarded – undo
549 549
 		$installer->migrate_old_invoices();
550 550
 
551 551
 		// Show an admin message.
552
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
552
+		$this->show_success(__('Your invoices have been migrated.', 'invoicing'));
553 553
 
554 554
 		// Redirect the admin.
555
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
555
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
556 556
 		exit;
557 557
 
558 558
 	}
@@ -564,18 +564,18 @@  discard block
 block discarded – undo
564 564
     public function admin_download_customers() {
565 565
 		global $wpdb;
566 566
 
567
-		$output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
567
+		$output = fopen('php://output', 'w') or die(__('Unsupported server', 'invoicing'));
568 568
 
569
-		header( "Content-Type:text/csv" );
570
-		header( "Content-Disposition:attachment;filename=customers.csv" );
569
+		header("Content-Type:text/csv");
570
+		header("Content-Disposition:attachment;filename=customers.csv");
571 571
 
572 572
 		$post_types = '';
573 573
 
574
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
575
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
574
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
575
+			$post_types .= $wpdb->prepare("post_type=%s OR ", $post_type);
576 576
 		}
577 577
 
578
-		$post_types = rtrim( $post_types, ' OR' );
578
+		$post_types = rtrim($post_types, ' OR');
579 579
 
580 580
 		$customers = $wpdb->get_col(
581 581
 			$wpdb->prepare(
@@ -584,58 +584,58 @@  discard block
 block discarded – undo
584 584
 		);
585 585
 
586 586
 		$columns = array(
587
-			'name'     => __( 'Name', 'invoicing' ),
588
-			'email'    => __( 'Email', 'invoicing' ),
589
-			'country'  => __( 'Country', 'invoicing' ),
590
-			'state'    => __( 'State', 'invoicing' ),
591
-			'city'     => __( 'City', 'invoicing' ),
592
-			'zip'      => __( 'ZIP', 'invoicing' ),
593
-			'address'  => __( 'Address', 'invoicing' ),
594
-			'phone'    => __( 'Phone', 'invoicing' ),
595
-			'company'  => __( 'Company', 'invoicing' ),
596
-			'company_id'  => __( 'Company ID', 'invoicing' ),
597
-			'invoices' => __( 'Invoices', 'invoicing' ),
598
-			'total_raw' => __( 'Total Spend', 'invoicing' ),
599
-			'signup'   => __( 'Date created', 'invoicing' ),
587
+			'name'     => __('Name', 'invoicing'),
588
+			'email'    => __('Email', 'invoicing'),
589
+			'country'  => __('Country', 'invoicing'),
590
+			'state'    => __('State', 'invoicing'),
591
+			'city'     => __('City', 'invoicing'),
592
+			'zip'      => __('ZIP', 'invoicing'),
593
+			'address'  => __('Address', 'invoicing'),
594
+			'phone'    => __('Phone', 'invoicing'),
595
+			'company'  => __('Company', 'invoicing'),
596
+			'company_id'  => __('Company ID', 'invoicing'),
597
+			'invoices' => __('Invoices', 'invoicing'),
598
+			'total_raw' => __('Total Spend', 'invoicing'),
599
+			'signup'   => __('Date created', 'invoicing'),
600 600
 		);
601 601
 
602 602
 		// Output the csv column headers.
603
-		fputcsv( $output, array_values( $columns ) );
603
+		fputcsv($output, array_values($columns));
604 604
 
605 605
 		// Loop through
606 606
 		$table = new WPInv_Customers_Table();
607
-		foreach ( $customers as $customer_id ) {
607
+		foreach ($customers as $customer_id) {
608 608
 
609
-			$user = get_user_by( 'id', $customer_id );
609
+			$user = get_user_by('id', $customer_id);
610 610
 			$row  = array();
611
-			if ( empty( $user ) ) {
611
+			if (empty($user)) {
612 612
 				continue;
613 613
 			}
614 614
 
615
-			foreach ( array_keys( $columns ) as $column ) {
615
+			foreach (array_keys($columns) as $column) {
616 616
 
617 617
 				$method = 'column_' . $column;
618 618
 
619
-				if ( 'name' == $column ) {
620
-					$value = sanitize_text_field( $user->display_name );
621
-				} else if( 'email' == $column ) {
622
-					$value = sanitize_email( $user->user_email );
623
-				} else if ( is_callable( array( $table, $method ) ) ) {
624
-					$value = strip_tags( $table->$method( $user ) );
619
+				if ('name' == $column) {
620
+					$value = sanitize_text_field($user->display_name);
621
+				} else if ('email' == $column) {
622
+					$value = sanitize_email($user->user_email);
623
+				} else if (is_callable(array($table, $method))) {
624
+					$value = strip_tags($table->$method($user));
625 625
 				}
626 626
 
627
-				if ( empty( $value ) ) {
628
-					$value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
627
+				if (empty($value)) {
628
+					$value = sanitize_text_field(get_user_meta($user->ID, '_wpinv_' . $column, true));
629 629
 				}
630 630
 
631 631
 				$row[] = $value;
632 632
 
633 633
 			}
634 634
 
635
-			fputcsv( $output, $row );
635
+			fputcsv($output, $row);
636 636
 		}
637 637
 
638
-		fclose( $output );
638
+		fclose($output);
639 639
 		exit;
640 640
 
641 641
 	}
@@ -645,29 +645,29 @@  discard block
 block discarded – undo
645 645
 	 *
646 646
 	 * @param array $data
647 647
      */
648
-    public function admin_install_plugin( $data ) {
648
+    public function admin_install_plugin($data) {
649 649
 
650
-		if ( ! empty( $data['plugins'] ) ) {
650
+		if (!empty($data['plugins'])) {
651 651
 			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
652 652
 			wp_cache_flush();
653 653
 
654
-			foreach ( $data['plugins'] as $slug => $file ) {
655
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
656
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
657
-				$installed  = $upgrader->install( $plugin_zip );
654
+			foreach ($data['plugins'] as $slug => $file) {
655
+				$plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip');
656
+				$upgrader   = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
657
+				$installed  = $upgrader->install($plugin_zip);
658 658
 
659
-				if ( ! is_wp_error( $installed ) && $installed ) {
660
-					activate_plugin( $file, '', false, true );
659
+				if (!is_wp_error($installed) && $installed) {
660
+					activate_plugin($file, '', false, true);
661 661
 				} else {
662
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
662
+					wpinv_error_log($upgrader->skin->get_upgrade_messages(), false);
663 663
 				}
664 664
 
665 665
 			}
666 666
 
667 667
 		}
668 668
 
669
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
670
-		wp_safe_redirect( $redirect );
669
+		$redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php');
670
+		wp_safe_redirect($redirect);
671 671
 		exit;
672 672
 
673 673
 	}
@@ -677,39 +677,39 @@  discard block
 block discarded – undo
677 677
 	 *
678 678
 	 * @param array $data
679 679
      */
680
-    public function admin_connect_gateway( $data ) {
680
+    public function admin_connect_gateway($data) {
681 681
 
682
-		if ( ! empty( $data['plugin'] ) ) {
682
+		if (!empty($data['plugin'])) {
683 683
 
684
-			$gateway     = sanitize_key( $data['plugin'] );
685
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
684
+			$gateway     = sanitize_key($data['plugin']);
685
+			$connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data);
686 686
 
687
-			if ( ! empty( $connect_url ) ) {
688
-				wp_redirect( $connect_url );
687
+			if (!empty($connect_url)) {
688
+				wp_redirect($connect_url);
689 689
 				exit;
690 690
 			}
691 691
 
692
-			if ( 'stripe' == $data['plugin'] ) {
692
+			if ('stripe' == $data['plugin']) {
693 693
 				require_once ABSPATH . 'wp-admin/includes/plugin.php';
694 694
 
695
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
696
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
697
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
698
-					$upgrader->install( $plugin_zip );
695
+				if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) {
696
+					$plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip');
697
+					$upgrader   = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
698
+					$upgrader->install($plugin_zip);
699 699
 				}
700 700
 
701
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
701
+				activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true);
702 702
 			}
703 703
 
704
-			if ( ! empty( $connect_url ) ) {
705
-				wp_redirect( $connect_url );
704
+			if (!empty($connect_url)) {
705
+				wp_redirect($connect_url);
706 706
 				exit;
707 707
 			}
708 708
 
709 709
 		}
710 710
 
711
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
712
-		wp_safe_redirect( $redirect );
711
+		$redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways');
712
+		wp_safe_redirect($redirect);
713 713
 		exit;
714 714
 
715 715
 	}
@@ -723,36 +723,36 @@  discard block
 block discarded – undo
723 723
 
724 724
 		// Fetch all invoices that have discount codes.
725 725
 		$table    = $wpdb->prefix . 'getpaid_invoices';
726
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
726
+		$invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''");
727 727
 
728
-		foreach ( $invoices as $invoice ) {
728
+		foreach ($invoices as $invoice) {
729 729
 
730
-			$invoice = new WPInv_Invoice( $invoice );
730
+			$invoice = new WPInv_Invoice($invoice);
731 731
 
732
-			if ( ! $invoice->exists() ) {
732
+			if (!$invoice->exists()) {
733 733
 				continue;
734 734
 			}
735 735
 
736 736
 			// Abort if the discount does not exist or does not apply here.
737
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
738
-			if ( ! $discount->exists() ) {
737
+			$discount = new WPInv_Discount($invoice->get_discount_code());
738
+			if (!$discount->exists()) {
739 739
 				continue;
740 740
 			}
741 741
 
742
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
742
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
743 743
 			$invoice->recalculate_total();
744 744
 
745
-			if ( $invoice->get_total_discount() > 0 ) {
745
+			if ($invoice->get_total_discount() > 0) {
746 746
 				$invoice->save();
747 747
 			}
748 748
 
749 749
 		}
750 750
 
751 751
 		// Show an admin message.
752
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
752
+		$this->show_success(__('Discounts have been recalculated.', 'invoicing'));
753 753
 
754 754
 		// Redirect the admin.
755
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
755
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
756 756
 		exit;
757 757
 
758 758
 	}
@@ -764,8 +764,8 @@  discard block
 block discarded – undo
764 764
      * @return array
765 765
 	 */
766 766
 	public function get_notices() {
767
-		$notices = get_option( 'wpinv_admin_notices' );
768
-        return is_array( $notices ) ? $notices : array();
767
+		$notices = get_option('wpinv_admin_notices');
768
+        return is_array($notices) ? $notices : array();
769 769
 	}
770 770
 
771 771
 	/**
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      * @return array
776 776
 	 */
777 777
 	public function has_notices() {
778
-		return count( $this->get_notices() ) > 0;
778
+		return count($this->get_notices()) > 0;
779 779
 	}
780 780
 
781 781
 	/**
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 	 * @since       1.0.19
786 786
 	 */
787 787
 	public function clear_notices() {
788
-		delete_option( 'wpinv_admin_notices' );
788
+		delete_option('wpinv_admin_notices');
789 789
 	}
790 790
 
791 791
 	/**
@@ -794,16 +794,16 @@  discard block
 block discarded – undo
794 794
 	 * @access      public
795 795
 	 * @since       1.0.19
796 796
 	 */
797
-	public function save_notice( $type, $message ) {
797
+	public function save_notice($type, $message) {
798 798
 		$notices = $this->get_notices();
799 799
 
800
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
801
-			$notices[ $type ] = array();
800
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
801
+			$notices[$type] = array();
802 802
 		}
803 803
 
804
-		$notices[ $type ][] = $message;
804
+		$notices[$type][] = $message;
805 805
 
806
-		update_option( 'wpinv_admin_notices', $notices );
806
+		update_option('wpinv_admin_notices', $notices);
807 807
 	}
808 808
 
809 809
 	/**
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 	 * @access      public
814 814
 	 * @since       1.0.19
815 815
 	 */
816
-	public function show_success( $msg ) {
817
-		$this->save_notice( 'success', $msg );
816
+	public function show_success($msg) {
817
+		$this->save_notice('success', $msg);
818 818
 	}
819 819
 
820 820
 	/**
@@ -824,8 +824,8 @@  discard block
 block discarded – undo
824 824
 	 * @param       string $msg The message to qeue.
825 825
 	 * @since       1.0.19
826 826
 	 */
827
-	public function show_error( $msg ) {
828
-		$this->save_notice( 'error', $msg );
827
+	public function show_error($msg) {
828
+		$this->save_notice('error', $msg);
829 829
 	}
830 830
 
831 831
 	/**
@@ -835,8 +835,8 @@  discard block
 block discarded – undo
835 835
 	 * @param       string $msg The message to qeue.
836 836
 	 * @since       1.0.19
837 837
 	 */
838
-	public function show_warning( $msg ) {
839
-		$this->save_notice( 'warning', $msg );
838
+	public function show_warning($msg) {
839
+		$this->save_notice('warning', $msg);
840 840
 	}
841 841
 
842 842
 	/**
@@ -846,8 +846,8 @@  discard block
 block discarded – undo
846 846
 	 * @param       string $msg The message to qeue.
847 847
 	 * @since       1.0.19
848 848
 	 */
849
-	public function show_info( $msg ) {
850
-		$this->save_notice( 'info', $msg );
849
+	public function show_info($msg) {
850
+		$this->save_notice('info', $msg);
851 851
 	}
852 852
 
853 853
 	/**
@@ -861,30 +861,30 @@  discard block
 block discarded – undo
861 861
         $notices = $this->get_notices();
862 862
         $this->clear_notices();
863 863
 
864
-		foreach ( $notices as $type => $messages ) {
864
+		foreach ($notices as $type => $messages) {
865 865
 
866
-			if ( ! is_array( $messages ) ) {
866
+			if (!is_array($messages)) {
867 867
 				continue;
868 868
 			}
869 869
 
870
-            $type  = sanitize_key( $type );
871
-			foreach ( $messages as $message ) {
872
-                $message = wp_kses_post( $message );
870
+            $type = sanitize_key($type);
871
+			foreach ($messages as $message) {
872
+                $message = wp_kses_post($message);
873 873
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
874 874
             }
875 875
 
876 876
         }
877 877
 
878
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
878
+		foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) {
879 879
 
880
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
881
-				$url     = wp_nonce_url(
882
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
880
+			if (!is_numeric(wpinv_get_option($page, false))) {
881
+				$url = wp_nonce_url(
882
+					add_query_arg('getpaid-admin-action', 'create_missing_pages'),
883 883
 					'getpaid-nonce',
884 884
 					'getpaid-nonce'
885 885
 				);
886
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
887
-				$message2 = __( 'Generate Pages', 'invoicing' );
886
+				$message  = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing');
887
+				$message2 = __('Generate Pages', 'invoicing');
888 888
 				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
889 889
 				break;
890 890
 			}
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +700 added lines, -700 removed lines patch added patch discarded remove patch
@@ -13,703 +13,703 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
-
36
-		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
-
44
-		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
-
49
-		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
-
53
-		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
-
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
-	}
59
-
60
-	/**
61
-	 * Post updated messages.
62
-	 */
63
-	public static function post_updated_messages( $messages ) {
64
-		global $post;
65
-
66
-		$messages['wpi_discount'] = array(
67
-			0   => '',
68
-			1   => __( 'Discount updated.', 'invoicing' ),
69
-			2   => __( 'Custom field updated.', 'invoicing' ),
70
-			3   => __( 'Custom field deleted.', 'invoicing' ),
71
-			4   => __( 'Discount updated.', 'invoicing' ),
72
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6   => __( 'Discount updated.', 'invoicing' ),
74
-			7   => __( 'Discount saved.', 'invoicing' ),
75
-			8   => __( 'Discount submitted.', 'invoicing' ),
76
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10  => __( 'Discount draft updated.', 'invoicing' ),
78
-		);
79
-
80
-		$messages['wpi_payment_form'] = array(
81
-			0   => '',
82
-			1   => __( 'Payment Form updated.', 'invoicing' ),
83
-			2   => __( 'Custom field updated.', 'invoicing' ),
84
-			3   => __( 'Custom field deleted.', 'invoicing' ),
85
-			4   => __( 'Payment Form updated.', 'invoicing' ),
86
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6   => __( 'Payment Form updated.', 'invoicing' ),
88
-			7   => __( 'Payment Form saved.', 'invoicing' ),
89
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
92
-		);
93
-
94
-		return $messages;
95
-
96
-	}
97
-
98
-	/**
99
-	 * Post row actions.
100
-	 */
101
-	public static function post_row_actions( $actions, $post ) {
102
-
103
-		$post = get_post( $post );
104
-
105
-		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
107
-
108
-			if ( $post->ID == wpinv_get_default_payment_form() ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
111
-			}
112
-
113
-			$actions['duplicate'] =  sprintf(
114
-				'<a href="%1$s">%2$s</a>',
115
-				esc_url(
116
-					wp_nonce_url(
117
-						add_query_arg(
118
-							array(
119
-								'getpaid-admin-action' => 'duplicate_form',
120
-								'form_id'              => $post->ID
121
-							)
122
-						),
123
-						'getpaid-nonce',
124
-						'getpaid-nonce'
125
-					)
126
-				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
128
-			);
129
-
130
-		}
131
-
132
-		return $actions;
133
-	}
134
-
135
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+        add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
+        add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
+
36
+        // Items table columns.
37
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
+
44
+        // Payment forms columns.
45
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
+
49
+        // Discount table columns.
50
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
+
53
+        // Deleting posts.
54
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
+
57
+        add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
+    }
59
+
60
+    /**
61
+     * Post updated messages.
62
+     */
63
+    public static function post_updated_messages( $messages ) {
64
+        global $post;
65
+
66
+        $messages['wpi_discount'] = array(
67
+            0   => '',
68
+            1   => __( 'Discount updated.', 'invoicing' ),
69
+            2   => __( 'Custom field updated.', 'invoicing' ),
70
+            3   => __( 'Custom field deleted.', 'invoicing' ),
71
+            4   => __( 'Discount updated.', 'invoicing' ),
72
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
+            6   => __( 'Discount updated.', 'invoicing' ),
74
+            7   => __( 'Discount saved.', 'invoicing' ),
75
+            8   => __( 'Discount submitted.', 'invoicing' ),
76
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
+            10  => __( 'Discount draft updated.', 'invoicing' ),
78
+        );
79
+
80
+        $messages['wpi_payment_form'] = array(
81
+            0   => '',
82
+            1   => __( 'Payment Form updated.', 'invoicing' ),
83
+            2   => __( 'Custom field updated.', 'invoicing' ),
84
+            3   => __( 'Custom field deleted.', 'invoicing' ),
85
+            4   => __( 'Payment Form updated.', 'invoicing' ),
86
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
+            6   => __( 'Payment Form updated.', 'invoicing' ),
88
+            7   => __( 'Payment Form saved.', 'invoicing' ),
89
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
90
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
92
+        );
93
+
94
+        return $messages;
95
+
96
+    }
97
+
98
+    /**
99
+     * Post row actions.
100
+     */
101
+    public static function post_row_actions( $actions, $post ) {
102
+
103
+        $post = get_post( $post );
104
+
105
+        // We do not want to edit the default payment form.
106
+        if ( 'wpi_payment_form' == $post->post_type ) {
107
+
108
+            if ( $post->ID == wpinv_get_default_payment_form() ) {
109
+                unset( $actions['trash'] );
110
+                unset( $actions['inline hide-if-no-js'] );
111
+            }
112
+
113
+            $actions['duplicate'] =  sprintf(
114
+                '<a href="%1$s">%2$s</a>',
115
+                esc_url(
116
+                    wp_nonce_url(
117
+                        add_query_arg(
118
+                            array(
119
+                                'getpaid-admin-action' => 'duplicate_form',
120
+                                'form_id'              => $post->ID
121
+                            )
122
+                        ),
123
+                        'getpaid-nonce',
124
+                        'getpaid-nonce'
125
+                    )
126
+                ),
127
+                esc_html( __( 'Duplicate', 'invoicing' ) )
128
+            );
129
+
130
+        }
131
+
132
+        return $actions;
133
+    }
134
+
135
+    /**
136 136
      * Remove bulk edit option from admin side quote listing
137 137
      *
138 138
      * @since    1.0.0
139 139
      * @param array $actions post actions
140
-	 * @param WP_Post $post
140
+     * @param WP_Post $post
141 141
      * @return array $actions actions without edit option
142 142
      */
143 143
     public static function filter_invoice_row_actions( $actions, $post ) {
144 144
 
145 145
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
146 146
 
147
-			$actions = array();
148
-			$invoice = new WPInv_Invoice( $post );
149
-
150
-			$actions['edit'] =  sprintf(
151
-				'<a href="%1$s">%2$s</a>',
152
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
153
-				esc_html( __( 'Edit', 'invoicing' ) )
154
-			);
155
-
156
-			if ( ! $invoice->is_draft() ) {
157
-
158
-				$actions['view'] =  sprintf(
159
-					'<a href="%1$s">%2$s</a>',
160
-					esc_url( $invoice->get_view_url() ),
161
-					sprintf(
162
-						esc_html( __( 'View %s', 'invoicing' ) ),
163
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
164
-					)
165
-				);
166
-
167
-				$actions['send'] =  sprintf(
168
-					'<a href="%1$s">%2$s</a>',
169
-					esc_url(
170
-						wp_nonce_url(
171
-							add_query_arg(
172
-								array(
173
-									'getpaid-admin-action' => 'send_invoice',
174
-									'invoice_id'           => $invoice->get_id()
175
-								)
176
-							),
177
-							'getpaid-nonce',
178
-							'getpaid-nonce'
179
-						)
180
-					),
181
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
182
-				);
183
-
184
-			}
147
+            $actions = array();
148
+            $invoice = new WPInv_Invoice( $post );
149
+
150
+            $actions['edit'] =  sprintf(
151
+                '<a href="%1$s">%2$s</a>',
152
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
153
+                esc_html( __( 'Edit', 'invoicing' ) )
154
+            );
155
+
156
+            if ( ! $invoice->is_draft() ) {
157
+
158
+                $actions['view'] =  sprintf(
159
+                    '<a href="%1$s">%2$s</a>',
160
+                    esc_url( $invoice->get_view_url() ),
161
+                    sprintf(
162
+                        esc_html( __( 'View %s', 'invoicing' ) ),
163
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
164
+                    )
165
+                );
166
+
167
+                $actions['send'] =  sprintf(
168
+                    '<a href="%1$s">%2$s</a>',
169
+                    esc_url(
170
+                        wp_nonce_url(
171
+                            add_query_arg(
172
+                                array(
173
+                                    'getpaid-admin-action' => 'send_invoice',
174
+                                    'invoice_id'           => $invoice->get_id()
175
+                                )
176
+                            ),
177
+                            'getpaid-nonce',
178
+                            'getpaid-nonce'
179
+                        )
180
+                    ),
181
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
182
+                );
183
+
184
+            }
185 185
 
186 186
         }
187 187
 
188 188
         return $actions;
189
-	}
190
-
191
-	/**
192
-	 * Returns an array of invoice table columns.
193
-	 */
194
-	public static function invoice_columns( $columns ) {
195
-
196
-		$columns = array(
197
-			'cb'                => $columns['cb'],
198
-			'number'            => __( 'Invoice', 'invoicing' ),
199
-			'customer'          => __( 'Customer', 'invoicing' ),
200
-			'invoice_date'      => __( 'Created', 'invoicing' ),
201
-			'payment_date'      => __( 'Completed', 'invoicing' ),
202
-			'amount'            => __( 'Amount', 'invoicing' ),
203
-			'recurring'         => __( 'Recurring', 'invoicing' ),
204
-			'status'            => __( 'Status', 'invoicing' ),
205
-		);
206
-
207
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
208
-	}
209
-
210
-	/**
211
-	 * Displays invoice table columns.
212
-	 */
213
-	public static function display_invoice_columns( $column_name, $post_id ) {
214
-
215
-		$invoice = new WPInv_Invoice( $post_id );
216
-
217
-		switch ( $column_name ) {
218
-
219
-			case 'invoice_date' :
220
-				$date_time = esc_attr( $invoice->get_created_date() );
221
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
222
-				echo "<span title='$date_time'>$date</span>";
223
-				break;
224
-
225
-			case 'payment_date' :
226
-
227
-				if ( $invoice->is_paid() ) {
228
-					$date_time = esc_attr( $invoice->get_completed_date() );
229
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
230
-					echo "<span title='$date_time'>$date</span>";
231
-				} else {
232
-					echo "&mdash;";
233
-				}
189
+    }
190
+
191
+    /**
192
+     * Returns an array of invoice table columns.
193
+     */
194
+    public static function invoice_columns( $columns ) {
195
+
196
+        $columns = array(
197
+            'cb'                => $columns['cb'],
198
+            'number'            => __( 'Invoice', 'invoicing' ),
199
+            'customer'          => __( 'Customer', 'invoicing' ),
200
+            'invoice_date'      => __( 'Created', 'invoicing' ),
201
+            'payment_date'      => __( 'Completed', 'invoicing' ),
202
+            'amount'            => __( 'Amount', 'invoicing' ),
203
+            'recurring'         => __( 'Recurring', 'invoicing' ),
204
+            'status'            => __( 'Status', 'invoicing' ),
205
+        );
206
+
207
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
208
+    }
209
+
210
+    /**
211
+     * Displays invoice table columns.
212
+     */
213
+    public static function display_invoice_columns( $column_name, $post_id ) {
214
+
215
+        $invoice = new WPInv_Invoice( $post_id );
216
+
217
+        switch ( $column_name ) {
218
+
219
+            case 'invoice_date' :
220
+                $date_time = esc_attr( $invoice->get_created_date() );
221
+                $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
222
+                echo "<span title='$date_time'>$date</span>";
223
+                break;
224
+
225
+            case 'payment_date' :
226
+
227
+                if ( $invoice->is_paid() ) {
228
+                    $date_time = esc_attr( $invoice->get_completed_date() );
229
+                    $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
230
+                    echo "<span title='$date_time'>$date</span>";
231
+                } else {
232
+                    echo "&mdash;";
233
+                }
234 234
 				
235
-				break;
235
+                break;
236 236
 
237
-			case 'amount' :
237
+            case 'amount' :
238 238
 
239
-				$amount = $invoice->get_total();
240
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
239
+                $amount = $invoice->get_total();
240
+                $formated_amount = wpinv_price( $amount, $invoice->get_currency() );
241 241
 
242
-				if ( $invoice->is_refunded() ) {
243
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
244
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
245
-				} else {
242
+                if ( $invoice->is_refunded() ) {
243
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
244
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
245
+                } else {
246 246
 
247
-					$discount = $invoice->get_total_discount();
247
+                    $discount = $invoice->get_total_discount();
248 248
 
249
-					if ( ! empty( $discount ) ) {
250
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
251
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
252
-					} else {
253
-						echo $formated_amount;
254
-					}
249
+                    if ( ! empty( $discount ) ) {
250
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
251
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
252
+                    } else {
253
+                        echo $formated_amount;
254
+                    }
255 255
 
256
-				}
256
+                }
257 257
 
258
-				break;
258
+                break;
259 259
 
260
-			case 'status' :
261
-				$status       = sanitize_text_field( $invoice->get_status() );
262
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
260
+            case 'status' :
261
+                $status       = sanitize_text_field( $invoice->get_status() );
262
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
263 263
 
264
-				// If it is paid, show the gateway title.
265
-				if ( $invoice->is_paid() ) {
266
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
267
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
264
+                // If it is paid, show the gateway title.
265
+                if ( $invoice->is_paid() ) {
266
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
267
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
268 268
 
269
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
270
-				} else {
271
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
272
-				}
269
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
270
+                } else {
271
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
272
+                }
273 273
 
274
-				// If it is not paid, display the overdue and view status.
275
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
274
+                // If it is not paid, display the overdue and view status.
275
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
276 276
 
277
-					// Invoice view status.
278
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
279
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
280
-					} else {
281
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
282
-					}
277
+                    // Invoice view status.
278
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
279
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
280
+                    } else {
281
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
282
+                    }
283 283
 
284
-					// Display the overview status.
285
-					if ( wpinv_get_option( 'overdue_active' ) ) {
286
-						$due_date = $invoice->get_due_date();
287
-						$fomatted = getpaid_format_date( $due_date );
284
+                    // Display the overview status.
285
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
286
+                        $due_date = $invoice->get_due_date();
287
+                        $fomatted = getpaid_format_date( $due_date );
288 288
 
289
-						if ( ! empty( $fomatted ) ) {
290
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
291
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
292
-						}
293
-					}
289
+                        if ( ! empty( $fomatted ) ) {
290
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
291
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
292
+                        }
293
+                    }
294 294
 
295
-				}
295
+                }
296 296
 
297
-				break;
297
+                break;
298 298
 
299
-			case 'recurring':
299
+            case 'recurring':
300 300
 
301
-				if ( $invoice->is_recurring() ) {
302
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
303
-				} else {
304
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
305
-				}
306
-				break;
301
+                if ( $invoice->is_recurring() ) {
302
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
303
+                } else {
304
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
305
+                }
306
+                break;
307 307
 
308
-			case 'number' :
308
+            case 'number' :
309 309
 
310
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
311
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
312
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
310
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
311
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
312
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
313 313
 
314
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
314
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
315 315
 
316
-				break;
316
+                break;
317 317
 
318
-			case 'customer' :
318
+            case 'customer' :
319 319
 	
320
-				$customer_name = $invoice->get_user_full_name();
320
+                $customer_name = $invoice->get_user_full_name();
321 321
 	
322
-				if ( empty( $customer_name ) ) {
323
-					$customer_name = $invoice->get_email();
324
-				}
322
+                if ( empty( $customer_name ) ) {
323
+                    $customer_name = $invoice->get_email();
324
+                }
325 325
 	
326
-				if ( ! empty( $customer_name ) ) {
327
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
328
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
329
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
330
-				} else {
331
-					echo '<div>&mdash;</div>';
332
-				}
326
+                if ( ! empty( $customer_name ) ) {
327
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
328
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
329
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
330
+                } else {
331
+                    echo '<div>&mdash;</div>';
332
+                }
333 333
 
334
-				break;
334
+                break;
335 335
 
336
-		}
336
+        }
337 337
 
338
-	}
338
+    }
339 339
 
340
-	/**
341
-	 * Displays invoice bulk actions.
342
-	 */
343
-	public static function invoice_bulk_actions( $actions ) {
344
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
345
-		return $actions;
346
-	}
340
+    /**
341
+     * Displays invoice bulk actions.
342
+     */
343
+    public static function invoice_bulk_actions( $actions ) {
344
+        $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
345
+        return $actions;
346
+    }
347 347
 
348
-	/**
349
-	 * Processes invoice bulk actions.
350
-	 */
351
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
348
+    /**
349
+     * Processes invoice bulk actions.
350
+     */
351
+    public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
352 352
 
353
-		if ( $action == 'resend-invoice' ) {
353
+        if ( $action == 'resend-invoice' ) {
354 354
 
355
-			$success = false;
356
-			foreach ( $post_ids as $post_id ) {
357
-				$success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
358
-			}
355
+            $success = false;
356
+            foreach ( $post_ids as $post_id ) {
357
+                $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
358
+            }
359 359
 
360
-			if ( $success ) {
361
-				getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) );
362
-			} else {
363
-				getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) );
364
-			}
360
+            if ( $success ) {
361
+                getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) );
362
+            } else {
363
+                getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) );
364
+            }
365 365
 
366
-		}
366
+        }
367 367
 
368
-		return $redirect_url;
368
+        return $redirect_url;
369 369
 
370
-	}
370
+    }
371 371
 
372
-	/**
373
-	 * Returns an array of payment forms table columns.
374
-	 */
375
-	public static function payment_form_columns( $columns ) {
372
+    /**
373
+     * Returns an array of payment forms table columns.
374
+     */
375
+    public static function payment_form_columns( $columns ) {
376 376
 
377
-		$columns = array(
378
-			'cb'                => $columns['cb'],
379
-			'title'             => __( 'Name', 'invoicing' ),
380
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
381
-			'earnings'          => __( 'Revenue', 'invoicing' ),
382
-			'refunds'           => __( 'Refunded', 'invoicing' ),
383
-			'items'             => __( 'Items', 'invoicing' ),
384
-			'date'              => __( 'Date', 'invoicing' ),
385
-		);
377
+        $columns = array(
378
+            'cb'                => $columns['cb'],
379
+            'title'             => __( 'Name', 'invoicing' ),
380
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
381
+            'earnings'          => __( 'Revenue', 'invoicing' ),
382
+            'refunds'           => __( 'Refunded', 'invoicing' ),
383
+            'items'             => __( 'Items', 'invoicing' ),
384
+            'date'              => __( 'Date', 'invoicing' ),
385
+        );
386 386
 
387
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
387
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
388 388
 
389
-	}
389
+    }
390 390
 
391
-	/**
392
-	 * Displays payment form table columns.
393
-	 */
394
-	public static function display_payment_form_columns( $column_name, $post_id ) {
391
+    /**
392
+     * Displays payment form table columns.
393
+     */
394
+    public static function display_payment_form_columns( $column_name, $post_id ) {
395 395
 
396
-		// Retrieve the payment form.
397
-		$form = new GetPaid_Payment_Form( $post_id );
396
+        // Retrieve the payment form.
397
+        $form = new GetPaid_Payment_Form( $post_id );
398 398
 
399
-		switch ( $column_name ) {
399
+        switch ( $column_name ) {
400 400
 
401
-			case 'earnings' :
402
-				echo wpinv_price( $form->get_earned() );
403
-				break;
401
+            case 'earnings' :
402
+                echo wpinv_price( $form->get_earned() );
403
+                break;
404 404
 
405
-			case 'refunds' :
406
-				echo wpinv_price( $form->get_refunded() );
407
-				break;
405
+            case 'refunds' :
406
+                echo wpinv_price( $form->get_refunded() );
407
+                break;
408 408
 
409
-			case 'refunds' :
410
-				echo wpinv_price( $form->get_refunded() );
411
-				break;
409
+            case 'refunds' :
410
+                echo wpinv_price( $form->get_refunded() );
411
+                break;
412 412
 
413
-			case 'shortcode' :
413
+            case 'shortcode' :
414 414
 
415
-				if ( $form->is_default() ) {
416
-					echo '&mdash;';
417
-				} else {
418
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
419
-				}
415
+                if ( $form->is_default() ) {
416
+                    echo '&mdash;';
417
+                } else {
418
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
419
+                }
420 420
 
421
-				break;
421
+                break;
422 422
 
423
-			case 'items' :
423
+            case 'items' :
424 424
 
425
-				$items = $form->get_items();
425
+                $items = $form->get_items();
426 426
 
427
-				if ( $form->is_default() || empty( $items ) ) {
428
-					echo '&mdash;';
429
-					return;
430
-				}
427
+                if ( $form->is_default() || empty( $items ) ) {
428
+                    echo '&mdash;';
429
+                    return;
430
+                }
431 431
 
432
-				$_items = array();
432
+                $_items = array();
433 433
 
434
-				foreach ( $items as $item ) {
435
-					$url = $item->get_edit_url();
434
+                foreach ( $items as $item ) {
435
+                    $url = $item->get_edit_url();
436 436
 
437
-					if ( empty( $url ) ) {
438
-						$_items[] = sanitize_text_field( $item->get_name() );
439
-					} else {
440
-						$_items[] = sprintf(
441
-							'<a href="%s">%s</a>',
442
-							esc_url( $url ),
443
-							sanitize_text_field( $item->get_name() )
444
-						);
445
-					}
437
+                    if ( empty( $url ) ) {
438
+                        $_items[] = sanitize_text_field( $item->get_name() );
439
+                    } else {
440
+                        $_items[] = sprintf(
441
+                            '<a href="%s">%s</a>',
442
+                            esc_url( $url ),
443
+                            sanitize_text_field( $item->get_name() )
444
+                        );
445
+                    }
446 446
 
447
-				}
447
+                }
448 448
 
449
-				echo implode( '<br>', $_items );
449
+                echo implode( '<br>', $_items );
450 450
 
451
-				break;
451
+                break;
452 452
 
453
-		}
453
+        }
454 454
 
455
-	}
455
+    }
456 456
 
457
-	/**
458
-	 * Filters post states.
459
-	 */
460
-	public static function filter_payment_form_state( $post_states, $post ) {
457
+    /**
458
+     * Filters post states.
459
+     */
460
+    public static function filter_payment_form_state( $post_states, $post ) {
461 461
 
462
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
463
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
464
-		}
462
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
463
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
464
+        }
465 465
 	
466
-		return $post_states;
467
-
468
-	}
469
-
470
-	/**
471
-	 * Returns an array of coupon table columns.
472
-	 */
473
-	public static function discount_columns( $columns ) {
474
-
475
-		$columns = array(
476
-			'cb'                => $columns['cb'],
477
-			'title'             => __( 'Name', 'invoicing' ),
478
-			'code'              => __( 'Code', 'invoicing' ),
479
-			'amount'            => __( 'Amount', 'invoicing' ),
480
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
481
-			'start_date'        => __( 'Start Date', 'invoicing' ),
482
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
483
-		);
484
-
485
-		return apply_filters( 'wpi_discount_table_columns', $columns );
486
-	}
487
-
488
-	/**
489
-	 * Filters post states.
490
-	 */
491
-	public static function filter_discount_state( $post_states, $post ) {
492
-
493
-		if ( 'wpi_discount' == $post->post_type ) {
494
-
495
-			$discount = new WPInv_Discount( $post );
496
-
497
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
498
-
499
-			if ( $status != 'publish' ) {
500
-				return array(
501
-					'discount_status' => wpinv_discount_status( $status ),
502
-				);
503
-			}
504
-
505
-			return array();
506
-
507
-		}
508
-
509
-		return $post_states;
510
-
511
-	}
512
-
513
-	/**
514
-	 * Returns an array of items table columns.
515
-	 */
516
-	public static function item_columns( $columns ) {
517
-
518
-		$columns = array(
519
-			'cb'                => $columns['cb'],
520
-			'title'             => __( 'Name', 'invoicing' ),
521
-			'price'             => __( 'Price', 'invoicing' ),
522
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
523
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
524
-			'type'              => __( 'Type', 'invoicing' ),
525
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
526
-		);
527
-
528
-		if ( ! wpinv_use_taxes() ) {
529
-			unset( $columns['vat_rule'] );
530
-			unset( $columns['vat_class'] );
531
-		}
532
-
533
-		return apply_filters( 'wpi_item_table_columns', $columns );
534
-	}
535
-
536
-	/**
537
-	 * Returns an array of sortable items table columns.
538
-	 */
539
-	public static function sortable_item_columns( $columns ) {
540
-
541
-		return array_merge(
542
-			$columns,
543
-			array(
544
-				'price'     => 'price',
545
-				'vat_rule'  => 'vat_rule',
546
-				'vat_class' => 'vat_class',
547
-				'type'      => 'type',
548
-			)
549
-		);
550
-
551
-	}
552
-
553
-	/**
554
-	 * Displays items table columns.
555
-	 */
556
-	public static function display_item_columns( $column_name, $post_id ) {
466
+        return $post_states;
467
+
468
+    }
469
+
470
+    /**
471
+     * Returns an array of coupon table columns.
472
+     */
473
+    public static function discount_columns( $columns ) {
474
+
475
+        $columns = array(
476
+            'cb'                => $columns['cb'],
477
+            'title'             => __( 'Name', 'invoicing' ),
478
+            'code'              => __( 'Code', 'invoicing' ),
479
+            'amount'            => __( 'Amount', 'invoicing' ),
480
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
481
+            'start_date'        => __( 'Start Date', 'invoicing' ),
482
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
483
+        );
484
+
485
+        return apply_filters( 'wpi_discount_table_columns', $columns );
486
+    }
487
+
488
+    /**
489
+     * Filters post states.
490
+     */
491
+    public static function filter_discount_state( $post_states, $post ) {
492
+
493
+        if ( 'wpi_discount' == $post->post_type ) {
494
+
495
+            $discount = new WPInv_Discount( $post );
496
+
497
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
498
+
499
+            if ( $status != 'publish' ) {
500
+                return array(
501
+                    'discount_status' => wpinv_discount_status( $status ),
502
+                );
503
+            }
504
+
505
+            return array();
506
+
507
+        }
508
+
509
+        return $post_states;
510
+
511
+    }
512
+
513
+    /**
514
+     * Returns an array of items table columns.
515
+     */
516
+    public static function item_columns( $columns ) {
517
+
518
+        $columns = array(
519
+            'cb'                => $columns['cb'],
520
+            'title'             => __( 'Name', 'invoicing' ),
521
+            'price'             => __( 'Price', 'invoicing' ),
522
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
523
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
524
+            'type'              => __( 'Type', 'invoicing' ),
525
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
526
+        );
527
+
528
+        if ( ! wpinv_use_taxes() ) {
529
+            unset( $columns['vat_rule'] );
530
+            unset( $columns['vat_class'] );
531
+        }
532
+
533
+        return apply_filters( 'wpi_item_table_columns', $columns );
534
+    }
535
+
536
+    /**
537
+     * Returns an array of sortable items table columns.
538
+     */
539
+    public static function sortable_item_columns( $columns ) {
540
+
541
+        return array_merge(
542
+            $columns,
543
+            array(
544
+                'price'     => 'price',
545
+                'vat_rule'  => 'vat_rule',
546
+                'vat_class' => 'vat_class',
547
+                'type'      => 'type',
548
+            )
549
+        );
550
+
551
+    }
552
+
553
+    /**
554
+     * Displays items table columns.
555
+     */
556
+    public static function display_item_columns( $column_name, $post_id ) {
557 557
  
558
-		$item = new WPInv_Item( $post_id );
558
+        $item = new WPInv_Item( $post_id );
559 559
 
560
-		switch ( $column_name ) {
560
+        switch ( $column_name ) {
561 561
 
562
-			case 'price' :
562
+            case 'price' :
563 563
 
564
-				if ( ! $item->is_recurring() ) {
565
-					echo $item->get_the_price();
566
-					break;
567
-				}
564
+                if ( ! $item->is_recurring() ) {
565
+                    echo $item->get_the_price();
566
+                    break;
567
+                }
568 568
 
569
-				$price = wp_sprintf(
570
-					__( '%s / %s', 'invoicing' ),
571
-					$item->get_the_price(),
572
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
573
-				);
569
+                $price = wp_sprintf(
570
+                    __( '%s / %s', 'invoicing' ),
571
+                    $item->get_the_price(),
572
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
573
+                );
574 574
 
575
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
576
-					echo $price;
577
-					break;
578
-				}
575
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
576
+                    echo $price;
577
+                    break;
578
+                }
579 579
 
580
-				echo $item->get_the_initial_price();
580
+                echo $item->get_the_initial_price();
581 581
 
582
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
583
-				break;
582
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
583
+                break;
584 584
 
585
-			case 'vat_rule' :
586
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
587
-				break;
585
+            case 'vat_rule' :
586
+                echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
587
+                break;
588 588
 
589
-			case 'vat_class' :
590
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
591
-				break;
589
+            case 'vat_class' :
590
+                echo getpaid_get_tax_class_label( $item->get_vat_class() );
591
+                break;
592 592
 
593
-			case 'shortcode' :
594
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
595
-				break;
593
+            case 'shortcode' :
594
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
595
+                break;
596 596
 
597
-			case 'type' :
598
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
599
-				break;
597
+            case 'type' :
598
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
599
+                break;
600 600
 
601
-		}
601
+        }
602 602
 
603
-	}
603
+    }
604 604
 
605
-	/**
606
-	 * Lets users filter items using taxes.
607
-	 */
608
-	public static function add_item_filters( $post_type ) {
605
+    /**
606
+     * Lets users filter items using taxes.
607
+     */
608
+    public static function add_item_filters( $post_type ) {
609 609
 
610
-		// Abort if we're not dealing with items.
611
-		if ( $post_type != 'wpi_item' ) {
612
-			return;
613
-		}
610
+        // Abort if we're not dealing with items.
611
+        if ( $post_type != 'wpi_item' ) {
612
+            return;
613
+        }
614 614
 
615
-		// Filter by vat rules.
616
-		if ( wpinv_use_taxes() ) {
615
+        // Filter by vat rules.
616
+        if ( wpinv_use_taxes() ) {
617 617
 	
618
-			// Sanitize selected vat rule.
619
-			$vat_rule   = '';
620
-			$vat_rules  = getpaid_get_tax_rules();
621
-			if ( isset( $_GET['vat_rule'] ) ) {
622
-				$vat_rule   =  $_GET['vat_rule'];
623
-			}
624
-
625
-			// Filter by VAT rule.
626
-			echo wpinv_html_select(
627
-				array(
628
-					'options'          => array_merge(
629
-						array(
630
-							'' => __( 'All VAT rules', 'invoicing' )
631
-						),
632
-						$vat_rules
633
-					),
634
-					'name'             => 'vat_rule',
635
-					'id'               => 'vat_rule',
636
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
637
-					'show_option_all'  => false,
638
-					'show_option_none' => false,
639
-				)
640
-			);
641
-
642
-			// Filter by VAT class.
618
+            // Sanitize selected vat rule.
619
+            $vat_rule   = '';
620
+            $vat_rules  = getpaid_get_tax_rules();
621
+            if ( isset( $_GET['vat_rule'] ) ) {
622
+                $vat_rule   =  $_GET['vat_rule'];
623
+            }
624
+
625
+            // Filter by VAT rule.
626
+            echo wpinv_html_select(
627
+                array(
628
+                    'options'          => array_merge(
629
+                        array(
630
+                            '' => __( 'All VAT rules', 'invoicing' )
631
+                        ),
632
+                        $vat_rules
633
+                    ),
634
+                    'name'             => 'vat_rule',
635
+                    'id'               => 'vat_rule',
636
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
637
+                    'show_option_all'  => false,
638
+                    'show_option_none' => false,
639
+                )
640
+            );
641
+
642
+            // Filter by VAT class.
643 643
 	
644
-			// Sanitize selected vat rule.
645
-			$vat_class   = '';
646
-			$vat_classes = getpaid_get_tax_classes();
647
-			if ( isset( $_GET['vat_class'] ) ) {
648
-				$vat_class   =  $_GET['vat_class'];
649
-			}
650
-
651
-			echo wpinv_html_select(
652
-				array(
653
-					'options'          => array_merge(
654
-						array(
655
-							'' => __( 'All VAT classes', 'invoicing' )
656
-						),
657
-						$vat_classes
658
-					),
659
-					'name'             => 'vat_class',
660
-					'id'               => 'vat_class',
661
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
662
-					'show_option_all'  => false,
663
-					'show_option_none' => false,
664
-				)
665
-			);
666
-
667
-		}
668
-
669
-		// Filter by item type.
670
-		$type   = '';
671
-		if ( isset( $_GET['type'] ) ) {
672
-			$type   =  $_GET['type'];
673
-		}
674
-
675
-		echo wpinv_html_select(
676
-			array(
677
-				'options'          => array_merge(
678
-					array(
679
-						'' => __( 'All item types', 'invoicing' )
680
-					),
681
-					wpinv_get_item_types()
682
-				),
683
-				'name'             => 'type',
684
-				'id'               => 'type',
685
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
686
-				'show_option_all'  => false,
687
-				'show_option_none' => false,
688
-			)
689
-		);
690
-
691
-	}
692
-
693
-	/**
694
-	 * Filters the item query.
695
-	 */
696
-	public static function filter_item_query( $query ) {
697
-
698
-		// modify the query only if it admin and main query.
699
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
700
-			return $query;
701
-		}
702
-
703
-		// we want to modify the query for our items.
704
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
705
-			return $query;
706
-		}
707
-
708
-		if ( empty( $query->query_vars['meta_query'] ) ) {
709
-			$query->query_vars['meta_query'] = array();
710
-		}
711
-
712
-		// Filter vat rule type
644
+            // Sanitize selected vat rule.
645
+            $vat_class   = '';
646
+            $vat_classes = getpaid_get_tax_classes();
647
+            if ( isset( $_GET['vat_class'] ) ) {
648
+                $vat_class   =  $_GET['vat_class'];
649
+            }
650
+
651
+            echo wpinv_html_select(
652
+                array(
653
+                    'options'          => array_merge(
654
+                        array(
655
+                            '' => __( 'All VAT classes', 'invoicing' )
656
+                        ),
657
+                        $vat_classes
658
+                    ),
659
+                    'name'             => 'vat_class',
660
+                    'id'               => 'vat_class',
661
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
662
+                    'show_option_all'  => false,
663
+                    'show_option_none' => false,
664
+                )
665
+            );
666
+
667
+        }
668
+
669
+        // Filter by item type.
670
+        $type   = '';
671
+        if ( isset( $_GET['type'] ) ) {
672
+            $type   =  $_GET['type'];
673
+        }
674
+
675
+        echo wpinv_html_select(
676
+            array(
677
+                'options'          => array_merge(
678
+                    array(
679
+                        '' => __( 'All item types', 'invoicing' )
680
+                    ),
681
+                    wpinv_get_item_types()
682
+                ),
683
+                'name'             => 'type',
684
+                'id'               => 'type',
685
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
686
+                'show_option_all'  => false,
687
+                'show_option_none' => false,
688
+            )
689
+        );
690
+
691
+    }
692
+
693
+    /**
694
+     * Filters the item query.
695
+     */
696
+    public static function filter_item_query( $query ) {
697
+
698
+        // modify the query only if it admin and main query.
699
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
700
+            return $query;
701
+        }
702
+
703
+        // we want to modify the query for our items.
704
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
705
+            return $query;
706
+        }
707
+
708
+        if ( empty( $query->query_vars['meta_query'] ) ) {
709
+            $query->query_vars['meta_query'] = array();
710
+        }
711
+
712
+        // Filter vat rule type
713 713
         if ( ! empty( $_GET['vat_rule'] ) ) {
714 714
             $query->query_vars['meta_query'][] = array(
715 715
                 'key'     => '_wpinv_vat_rule',
@@ -734,97 +734,97 @@  discard block
 block discarded – undo
734 734
                 'value'   => sanitize_text_field( $_GET['type'] ),
735 735
                 'compare' => '='
736 736
             );
737
-		}
738
-
739
-	}
740
-
741
-	/**
742
-	 * Reorders items.
743
-	 */
744
-	public static function reorder_items( $vars ) {
745
-		global $typenow;
746
-
747
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
748
-			return $vars;
749
-		}
750
-
751
-		// By item type.
752
-		if ( 'type' == $vars['orderby'] ) {
753
-			return array_merge(
754
-				$vars,
755
-				array(
756
-					'meta_key' => '_wpinv_type',
757
-					'orderby'  => 'meta_value'
758
-				)
759
-			);
760
-		}
761
-
762
-		// By vat class.
763
-		if ( 'vat_class' == $vars['orderby'] ) {
764
-			return array_merge(
765
-				$vars,
766
-				array(
767
-					'meta_key' => '_wpinv_vat_class',
768
-					'orderby'  => 'meta_value'
769
-				)
770
-			);
771
-		}
772
-
773
-		// By vat rule.
774
-		if ( 'vat_rule' == $vars['orderby'] ) {
775
-			return array_merge(
776
-				$vars,
777
-				array(
778
-					'meta_key' => '_wpinv_vat_rule',
779
-					'orderby'  => 'meta_value'
780
-				)
781
-			);
782
-		}
783
-
784
-		// By price.
785
-		if ( 'price' == $vars['orderby'] ) {
786
-			return array_merge(
787
-				$vars,
788
-				array(
789
-					'meta_key' => '_wpinv_price',
790
-					'orderby'  => 'meta_value_num'
791
-				)
792
-			);
793
-		}
794
-
795
-		return $vars;
796
-
797
-	}
798
-
799
-	/**
800
-	 * Fired when deleting a post.
801
-	 */
802
-	public static function delete_post( $post_id ) {
803
-
804
-		switch ( get_post_type( $post_id ) ) {
805
-
806
-			case 'wpi_item' :
807
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
808
-				break;
809
-
810
-			case 'wpi_payment_form' :
811
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
812
-				break;
813
-
814
-			case 'wpi_discount' :
815
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
816
-				break;
817
-
818
-			case 'wpi_invoice' :
819
-				$invoice = new WPInv_Invoice( $post_id );
820
-				do_action( "getpaid_before_delete_invoice", $invoice );
821
-				$invoice->get_data_store()->delete_items( $invoice );
822
-				$invoice->get_data_store()->delete_special_fields( $invoice );
823
-				break;
824
-		}
825
-	}
826
-
827
-	/**
737
+        }
738
+
739
+    }
740
+
741
+    /**
742
+     * Reorders items.
743
+     */
744
+    public static function reorder_items( $vars ) {
745
+        global $typenow;
746
+
747
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
748
+            return $vars;
749
+        }
750
+
751
+        // By item type.
752
+        if ( 'type' == $vars['orderby'] ) {
753
+            return array_merge(
754
+                $vars,
755
+                array(
756
+                    'meta_key' => '_wpinv_type',
757
+                    'orderby'  => 'meta_value'
758
+                )
759
+            );
760
+        }
761
+
762
+        // By vat class.
763
+        if ( 'vat_class' == $vars['orderby'] ) {
764
+            return array_merge(
765
+                $vars,
766
+                array(
767
+                    'meta_key' => '_wpinv_vat_class',
768
+                    'orderby'  => 'meta_value'
769
+                )
770
+            );
771
+        }
772
+
773
+        // By vat rule.
774
+        if ( 'vat_rule' == $vars['orderby'] ) {
775
+            return array_merge(
776
+                $vars,
777
+                array(
778
+                    'meta_key' => '_wpinv_vat_rule',
779
+                    'orderby'  => 'meta_value'
780
+                )
781
+            );
782
+        }
783
+
784
+        // By price.
785
+        if ( 'price' == $vars['orderby'] ) {
786
+            return array_merge(
787
+                $vars,
788
+                array(
789
+                    'meta_key' => '_wpinv_price',
790
+                    'orderby'  => 'meta_value_num'
791
+                )
792
+            );
793
+        }
794
+
795
+        return $vars;
796
+
797
+    }
798
+
799
+    /**
800
+     * Fired when deleting a post.
801
+     */
802
+    public static function delete_post( $post_id ) {
803
+
804
+        switch ( get_post_type( $post_id ) ) {
805
+
806
+            case 'wpi_item' :
807
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
808
+                break;
809
+
810
+            case 'wpi_payment_form' :
811
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
812
+                break;
813
+
814
+            case 'wpi_discount' :
815
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
816
+                break;
817
+
818
+            case 'wpi_invoice' :
819
+                $invoice = new WPInv_Invoice( $post_id );
820
+                do_action( "getpaid_before_delete_invoice", $invoice );
821
+                $invoice->get_data_store()->delete_items( $invoice );
822
+                $invoice->get_data_store()->delete_special_fields( $invoice );
823
+                break;
824
+        }
825
+    }
826
+
827
+    /**
828 828
      * Add a post display state for special GetPaid pages in the page list table.
829 829
      *
830 830
      * @param array   $post_states An array of post display states.
@@ -838,22 +838,22 @@  discard block
 block discarded – undo
838 838
             $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
839 839
         }
840 840
 
841
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
841
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
842 842
 
843
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
844
-				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
845
-					__( 'GetPaid %s History Page', 'invoicing' ),
846
-					$label
847
-				);
848
-			}
843
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
844
+                $post_states["getpaid_{$post_type}_history_page"] = sprintf(
845
+                    __( 'GetPaid %s History Page', 'invoicing' ),
846
+                    $label
847
+                );
848
+            }
849 849
 
850
-		}
850
+        }
851 851
 		
852
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
852
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
853 853
             $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
854 854
         }
855 855
 
856
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
856
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
857 857
             $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
858 858
         }
859 859
 
Please login to merge, or discard this patch.
Spacing   +230 added lines, -230 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
  * Post types Admin Class
@@ -21,74 +21,74 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2);
29 29
 
30 30
 		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
31
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
32
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
33
+		add_filter('bulk_actions-edit-wpi_invoice', array(__CLASS__, 'invoice_bulk_actions'));
34
+		add_filter('handle_bulk_actions-edit-wpi_invoice', array(__CLASS__, 'handle_invoice_bulk_actions'), 10, 3);
35 35
 
36 36
 		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
37
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
38
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
39
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
40
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
41
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
42
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
43 43
 
44 44
 		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
46
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
47
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
48 48
 
49 49
 		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
51
+		add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100);
52 52
 
53 53
 		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
55
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
56 56
 
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
57
+		add_filter('display_post_states', array(__CLASS__, 'add_display_post_states'), 10, 2);
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * Post updated messages.
62 62
 	 */
63
-	public static function post_updated_messages( $messages ) {
63
+	public static function post_updated_messages($messages) {
64 64
 		global $post;
65 65
 
66 66
 		$messages['wpi_discount'] = array(
67 67
 			0   => '',
68
-			1   => __( 'Discount updated.', 'invoicing' ),
69
-			2   => __( 'Custom field updated.', 'invoicing' ),
70
-			3   => __( 'Custom field deleted.', 'invoicing' ),
71
-			4   => __( 'Discount updated.', 'invoicing' ),
72
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6   => __( 'Discount updated.', 'invoicing' ),
74
-			7   => __( 'Discount saved.', 'invoicing' ),
75
-			8   => __( 'Discount submitted.', 'invoicing' ),
76
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10  => __( 'Discount draft updated.', 'invoicing' ),
68
+			1   => __('Discount updated.', 'invoicing'),
69
+			2   => __('Custom field updated.', 'invoicing'),
70
+			3   => __('Custom field deleted.', 'invoicing'),
71
+			4   => __('Discount updated.', 'invoicing'),
72
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
73
+			6   => __('Discount updated.', 'invoicing'),
74
+			7   => __('Discount saved.', 'invoicing'),
75
+			8   => __('Discount submitted.', 'invoicing'),
76
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
77
+			10  => __('Discount draft updated.', 'invoicing'),
78 78
 		);
79 79
 
80 80
 		$messages['wpi_payment_form'] = array(
81 81
 			0   => '',
82
-			1   => __( 'Payment Form updated.', 'invoicing' ),
83
-			2   => __( 'Custom field updated.', 'invoicing' ),
84
-			3   => __( 'Custom field deleted.', 'invoicing' ),
85
-			4   => __( 'Payment Form updated.', 'invoicing' ),
86
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6   => __( 'Payment Form updated.', 'invoicing' ),
88
-			7   => __( 'Payment Form saved.', 'invoicing' ),
89
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
82
+			1   => __('Payment Form updated.', 'invoicing'),
83
+			2   => __('Custom field updated.', 'invoicing'),
84
+			3   => __('Custom field deleted.', 'invoicing'),
85
+			4   => __('Payment Form updated.', 'invoicing'),
86
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
87
+			6   => __('Payment Form updated.', 'invoicing'),
88
+			7   => __('Payment Form saved.', 'invoicing'),
89
+			8   => __('Payment Form submitted.', 'invoicing'),
90
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
91
+			10  => __('Payment Form draft updated.', 'invoicing'),
92 92
 		);
93 93
 
94 94
 		return $messages;
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 	/**
99 99
 	 * Post row actions.
100 100
 	 */
101
-	public static function post_row_actions( $actions, $post ) {
101
+	public static function post_row_actions($actions, $post) {
102 102
 
103
-		$post = get_post( $post );
103
+		$post = get_post($post);
104 104
 
105 105
 		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
106
+		if ('wpi_payment_form' == $post->post_type) {
107 107
 
108
-			if ( $post->ID == wpinv_get_default_payment_form() ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
108
+			if ($post->ID == wpinv_get_default_payment_form()) {
109
+				unset($actions['trash']);
110
+				unset($actions['inline hide-if-no-js']);
111 111
 			}
112 112
 
113
-			$actions['duplicate'] =  sprintf(
113
+			$actions['duplicate'] = sprintf(
114 114
 				'<a href="%1$s">%2$s</a>',
115 115
 				esc_url(
116 116
 					wp_nonce_url(
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 						'getpaid-nonce'
125 125
 					)
126 126
 				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
127
+				esc_html(__('Duplicate', 'invoicing'))
128 128
 			);
129 129
 
130 130
 		}
@@ -140,31 +140,31 @@  discard block
 block discarded – undo
140 140
 	 * @param WP_Post $post
141 141
      * @return array $actions actions without edit option
142 142
      */
143
-    public static function filter_invoice_row_actions( $actions, $post ) {
143
+    public static function filter_invoice_row_actions($actions, $post) {
144 144
 
145
-        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
145
+        if (getpaid_is_invoice_post_type($post->post_type)) {
146 146
 
147 147
 			$actions = array();
148
-			$invoice = new WPInv_Invoice( $post );
148
+			$invoice = new WPInv_Invoice($post);
149 149
 
150
-			$actions['edit'] =  sprintf(
150
+			$actions['edit'] = sprintf(
151 151
 				'<a href="%1$s">%2$s</a>',
152
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
153
-				esc_html( __( 'Edit', 'invoicing' ) )
152
+				esc_url(get_edit_post_link($invoice->get_id())),
153
+				esc_html(__('Edit', 'invoicing'))
154 154
 			);
155 155
 
156
-			if ( ! $invoice->is_draft() ) {
156
+			if (!$invoice->is_draft()) {
157 157
 
158
-				$actions['view'] =  sprintf(
158
+				$actions['view'] = sprintf(
159 159
 					'<a href="%1$s">%2$s</a>',
160
-					esc_url( $invoice->get_view_url() ),
160
+					esc_url($invoice->get_view_url()),
161 161
 					sprintf(
162
-						esc_html( __( 'View %s', 'invoicing' ) ),
163
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
162
+						esc_html(__('View %s', 'invoicing')),
163
+						getpaid_get_post_type_label($invoice->get_post_type(), false)
164 164
 					)
165 165
 				);
166 166
 
167
-				$actions['send'] =  sprintf(
167
+				$actions['send'] = sprintf(
168 168
 					'<a href="%1$s">%2$s</a>',
169 169
 					esc_url(
170 170
 						wp_nonce_url(
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 							'getpaid-nonce'
179 179
 						)
180 180
 					),
181
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
181
+					esc_html(__('Send to Customer', 'invoicing'))
182 182
 				);
183 183
 
184 184
 			}
@@ -191,42 +191,42 @@  discard block
 block discarded – undo
191 191
 	/**
192 192
 	 * Returns an array of invoice table columns.
193 193
 	 */
194
-	public static function invoice_columns( $columns ) {
194
+	public static function invoice_columns($columns) {
195 195
 
196 196
 		$columns = array(
197 197
 			'cb'                => $columns['cb'],
198
-			'number'            => __( 'Invoice', 'invoicing' ),
199
-			'customer'          => __( 'Customer', 'invoicing' ),
200
-			'invoice_date'      => __( 'Created', 'invoicing' ),
201
-			'payment_date'      => __( 'Completed', 'invoicing' ),
202
-			'amount'            => __( 'Amount', 'invoicing' ),
203
-			'recurring'         => __( 'Recurring', 'invoicing' ),
204
-			'status'            => __( 'Status', 'invoicing' ),
198
+			'number'            => __('Invoice', 'invoicing'),
199
+			'customer'          => __('Customer', 'invoicing'),
200
+			'invoice_date'      => __('Created', 'invoicing'),
201
+			'payment_date'      => __('Completed', 'invoicing'),
202
+			'amount'            => __('Amount', 'invoicing'),
203
+			'recurring'         => __('Recurring', 'invoicing'),
204
+			'status'            => __('Status', 'invoicing'),
205 205
 		);
206 206
 
207
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
207
+		return apply_filters('wpi_invoice_table_columns', $columns);
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Displays invoice table columns.
212 212
 	 */
213
-	public static function display_invoice_columns( $column_name, $post_id ) {
213
+	public static function display_invoice_columns($column_name, $post_id) {
214 214
 
215
-		$invoice = new WPInv_Invoice( $post_id );
215
+		$invoice = new WPInv_Invoice($post_id);
216 216
 
217
-		switch ( $column_name ) {
217
+		switch ($column_name) {
218 218
 
219 219
 			case 'invoice_date' :
220
-				$date_time = esc_attr( $invoice->get_created_date() );
221
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
220
+				$date_time = esc_attr($invoice->get_created_date());
221
+				$date      = getpaid_format_date_value($date_time, "&mdash;", true);
222 222
 				echo "<span title='$date_time'>$date</span>";
223 223
 				break;
224 224
 
225 225
 			case 'payment_date' :
226 226
 
227
-				if ( $invoice->is_paid() ) {
228
-					$date_time = esc_attr( $invoice->get_completed_date() );
229
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
227
+				if ($invoice->is_paid()) {
228
+					$date_time = esc_attr($invoice->get_completed_date());
229
+					$date      = getpaid_format_date_value($date_time, "&mdash;", true);
230 230
 					echo "<span title='$date_time'>$date</span>";
231 231
 				} else {
232 232
 					echo "&mdash;";
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
 			case 'amount' :
238 238
 
239 239
 				$amount = $invoice->get_total();
240
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
240
+				$formated_amount = wpinv_price($amount, $invoice->get_currency());
241 241
 
242
-				if ( $invoice->is_refunded() ) {
243
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
242
+				if ($invoice->is_refunded()) {
243
+					$refunded_amount = wpinv_price(0, $invoice->get_currency());
244 244
 					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
245 245
 				} else {
246 246
 
247 247
 					$discount = $invoice->get_total_discount();
248 248
 
249
-					if ( ! empty( $discount ) ) {
250
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
249
+					if (!empty($discount)) {
250
+						$new_amount = wpinv_price($amount + $discount, $invoice->get_currency());
251 251
 						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
252 252
 					} else {
253 253
 						echo $formated_amount;
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
 				break;
259 259
 
260 260
 			case 'status' :
261
-				$status       = sanitize_text_field( $invoice->get_status() );
262
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
261
+				$status       = sanitize_text_field($invoice->get_status());
262
+				$status_label = sanitize_text_field($invoice->get_status_nicename());
263 263
 
264 264
 				// If it is paid, show the gateway title.
265
-				if ( $invoice->is_paid() ) {
266
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
267
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
265
+				if ($invoice->is_paid()) {
266
+					$gateway = sanitize_text_field($invoice->get_gateway_title());
267
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway);
268 268
 
269 269
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
270 270
 				} else {
@@ -272,22 +272,22 @@  discard block
 block discarded – undo
272 272
 				}
273 273
 
274 274
 				// If it is not paid, display the overdue and view status.
275
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
275
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
276 276
 
277 277
 					// Invoice view status.
278
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
279
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
278
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
279
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
280 280
 					} else {
281
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
281
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
282 282
 					}
283 283
 
284 284
 					// Display the overview status.
285
-					if ( wpinv_get_option( 'overdue_active' ) ) {
285
+					if (wpinv_get_option('overdue_active')) {
286 286
 						$due_date = $invoice->get_due_date();
287
-						$fomatted = getpaid_format_date( $due_date );
287
+						$fomatted = getpaid_format_date($due_date);
288 288
 
289
-						if ( ! empty( $fomatted ) ) {
290
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
289
+						if (!empty($fomatted)) {
290
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted);
291 291
 							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
292 292
 						}
293 293
 					}
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 
299 299
 			case 'recurring':
300 300
 
301
-				if ( $invoice->is_recurring() ) {
301
+				if ($invoice->is_recurring()) {
302 302
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
303 303
 				} else {
304 304
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -307,9 +307,9 @@  discard block
 block discarded – undo
307 307
 
308 308
 			case 'number' :
309 309
 
310
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
311
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
312
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
310
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
311
+				$invoice_number  = sanitize_text_field($invoice->get_number());
312
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
313 313
 
314 314
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
315 315
 
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
 	
320 320
 				$customer_name = $invoice->get_user_full_name();
321 321
 	
322
-				if ( empty( $customer_name ) ) {
322
+				if (empty($customer_name)) {
323 323
 					$customer_name = $invoice->get_email();
324 324
 				}
325 325
 	
326
-				if ( ! empty( $customer_name ) ) {
327
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
328
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
326
+				if (!empty($customer_name)) {
327
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
328
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
329 329
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
330 330
 				} else {
331 331
 					echo '<div>&mdash;</div>';
@@ -340,27 +340,27 @@  discard block
 block discarded – undo
340 340
 	/**
341 341
 	 * Displays invoice bulk actions.
342 342
 	 */
343
-	public static function invoice_bulk_actions( $actions ) {
344
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
343
+	public static function invoice_bulk_actions($actions) {
344
+		$actions['resend-invoice'] = __('Send to Customer', 'invoicing');
345 345
 		return $actions;
346 346
 	}
347 347
 
348 348
 	/**
349 349
 	 * Processes invoice bulk actions.
350 350
 	 */
351
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
351
+	public static function handle_invoice_bulk_actions($redirect_url, $action, $post_ids) {
352 352
 
353
-		if ( $action == 'resend-invoice' ) {
353
+		if ($action == 'resend-invoice') {
354 354
 
355 355
 			$success = false;
356
-			foreach ( $post_ids as $post_id ) {
357
-				$success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
356
+			foreach ($post_ids as $post_id) {
357
+				$success = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($post_id), true);
358 358
 			}
359 359
 
360
-			if ( $success ) {
361
-				getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) );
360
+			if ($success) {
361
+				getpaid_admin()->show_success(__('Invoices were successfully sent', 'invoicing'));
362 362
 			} else {
363
-				getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) );
363
+				getpaid_admin()->show_error(__('Could not send some invoices', 'invoicing'));
364 364
 			}
365 365
 
366 366
 		}
@@ -372,50 +372,50 @@  discard block
 block discarded – undo
372 372
 	/**
373 373
 	 * Returns an array of payment forms table columns.
374 374
 	 */
375
-	public static function payment_form_columns( $columns ) {
375
+	public static function payment_form_columns($columns) {
376 376
 
377 377
 		$columns = array(
378 378
 			'cb'                => $columns['cb'],
379
-			'title'             => __( 'Name', 'invoicing' ),
380
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
381
-			'earnings'          => __( 'Revenue', 'invoicing' ),
382
-			'refunds'           => __( 'Refunded', 'invoicing' ),
383
-			'items'             => __( 'Items', 'invoicing' ),
384
-			'date'              => __( 'Date', 'invoicing' ),
379
+			'title'             => __('Name', 'invoicing'),
380
+			'shortcode'         => __('Shortcode', 'invoicing'),
381
+			'earnings'          => __('Revenue', 'invoicing'),
382
+			'refunds'           => __('Refunded', 'invoicing'),
383
+			'items'             => __('Items', 'invoicing'),
384
+			'date'              => __('Date', 'invoicing'),
385 385
 		);
386 386
 
387
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
387
+		return apply_filters('wpi_payment_form_table_columns', $columns);
388 388
 
389 389
 	}
390 390
 
391 391
 	/**
392 392
 	 * Displays payment form table columns.
393 393
 	 */
394
-	public static function display_payment_form_columns( $column_name, $post_id ) {
394
+	public static function display_payment_form_columns($column_name, $post_id) {
395 395
 
396 396
 		// Retrieve the payment form.
397
-		$form = new GetPaid_Payment_Form( $post_id );
397
+		$form = new GetPaid_Payment_Form($post_id);
398 398
 
399
-		switch ( $column_name ) {
399
+		switch ($column_name) {
400 400
 
401 401
 			case 'earnings' :
402
-				echo wpinv_price( $form->get_earned() );
402
+				echo wpinv_price($form->get_earned());
403 403
 				break;
404 404
 
405 405
 			case 'refunds' :
406
-				echo wpinv_price( $form->get_refunded() );
406
+				echo wpinv_price($form->get_refunded());
407 407
 				break;
408 408
 
409 409
 			case 'refunds' :
410
-				echo wpinv_price( $form->get_refunded() );
410
+				echo wpinv_price($form->get_refunded());
411 411
 				break;
412 412
 
413 413
 			case 'shortcode' :
414 414
 
415
-				if ( $form->is_default() ) {
415
+				if ($form->is_default()) {
416 416
 					echo '&mdash;';
417 417
 				} else {
418
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
418
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
419 419
 				}
420 420
 
421 421
 				break;
@@ -424,29 +424,29 @@  discard block
 block discarded – undo
424 424
 
425 425
 				$items = $form->get_items();
426 426
 
427
-				if ( $form->is_default() || empty( $items ) ) {
427
+				if ($form->is_default() || empty($items)) {
428 428
 					echo '&mdash;';
429 429
 					return;
430 430
 				}
431 431
 
432 432
 				$_items = array();
433 433
 
434
-				foreach ( $items as $item ) {
434
+				foreach ($items as $item) {
435 435
 					$url = $item->get_edit_url();
436 436
 
437
-					if ( empty( $url ) ) {
438
-						$_items[] = sanitize_text_field( $item->get_name() );
437
+					if (empty($url)) {
438
+						$_items[] = sanitize_text_field($item->get_name());
439 439
 					} else {
440 440
 						$_items[] = sprintf(
441 441
 							'<a href="%s">%s</a>',
442
-							esc_url( $url ),
443
-							sanitize_text_field( $item->get_name() )
442
+							esc_url($url),
443
+							sanitize_text_field($item->get_name())
444 444
 						);
445 445
 					}
446 446
 
447 447
 				}
448 448
 
449
-				echo implode( '<br>', $_items );
449
+				echo implode('<br>', $_items);
450 450
 
451 451
 				break;
452 452
 
@@ -457,10 +457,10 @@  discard block
 block discarded – undo
457 457
 	/**
458 458
 	 * Filters post states.
459 459
 	 */
460
-	public static function filter_payment_form_state( $post_states, $post ) {
460
+	public static function filter_payment_form_state($post_states, $post) {
461 461
 
462
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
463
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
462
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
463
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
464 464
 		}
465 465
 	
466 466
 		return $post_states;
@@ -470,35 +470,35 @@  discard block
 block discarded – undo
470 470
 	/**
471 471
 	 * Returns an array of coupon table columns.
472 472
 	 */
473
-	public static function discount_columns( $columns ) {
473
+	public static function discount_columns($columns) {
474 474
 
475 475
 		$columns = array(
476 476
 			'cb'                => $columns['cb'],
477
-			'title'             => __( 'Name', 'invoicing' ),
478
-			'code'              => __( 'Code', 'invoicing' ),
479
-			'amount'            => __( 'Amount', 'invoicing' ),
480
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
481
-			'start_date'        => __( 'Start Date', 'invoicing' ),
482
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
477
+			'title'             => __('Name', 'invoicing'),
478
+			'code'              => __('Code', 'invoicing'),
479
+			'amount'            => __('Amount', 'invoicing'),
480
+			'usage'             => __('Usage / Limit', 'invoicing'),
481
+			'start_date'        => __('Start Date', 'invoicing'),
482
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
483 483
 		);
484 484
 
485
-		return apply_filters( 'wpi_discount_table_columns', $columns );
485
+		return apply_filters('wpi_discount_table_columns', $columns);
486 486
 	}
487 487
 
488 488
 	/**
489 489
 	 * Filters post states.
490 490
 	 */
491
-	public static function filter_discount_state( $post_states, $post ) {
491
+	public static function filter_discount_state($post_states, $post) {
492 492
 
493
-		if ( 'wpi_discount' == $post->post_type ) {
493
+		if ('wpi_discount' == $post->post_type) {
494 494
 
495
-			$discount = new WPInv_Discount( $post );
495
+			$discount = new WPInv_Discount($post);
496 496
 
497 497
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
498 498
 
499
-			if ( $status != 'publish' ) {
499
+			if ($status != 'publish') {
500 500
 				return array(
501
-					'discount_status' => wpinv_discount_status( $status ),
501
+					'discount_status' => wpinv_discount_status($status),
502 502
 				);
503 503
 			}
504 504
 
@@ -513,30 +513,30 @@  discard block
 block discarded – undo
513 513
 	/**
514 514
 	 * Returns an array of items table columns.
515 515
 	 */
516
-	public static function item_columns( $columns ) {
516
+	public static function item_columns($columns) {
517 517
 
518 518
 		$columns = array(
519 519
 			'cb'                => $columns['cb'],
520
-			'title'             => __( 'Name', 'invoicing' ),
521
-			'price'             => __( 'Price', 'invoicing' ),
522
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
523
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
524
-			'type'              => __( 'Type', 'invoicing' ),
525
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
520
+			'title'             => __('Name', 'invoicing'),
521
+			'price'             => __('Price', 'invoicing'),
522
+			'vat_rule'          => __('VAT rule', 'invoicing'),
523
+			'vat_class'         => __('VAT class', 'invoicing'),
524
+			'type'              => __('Type', 'invoicing'),
525
+			'shortcode'         => __('Shortcode', 'invoicing'),
526 526
 		);
527 527
 
528
-		if ( ! wpinv_use_taxes() ) {
529
-			unset( $columns['vat_rule'] );
530
-			unset( $columns['vat_class'] );
528
+		if (!wpinv_use_taxes()) {
529
+			unset($columns['vat_rule']);
530
+			unset($columns['vat_class']);
531 531
 		}
532 532
 
533
-		return apply_filters( 'wpi_item_table_columns', $columns );
533
+		return apply_filters('wpi_item_table_columns', $columns);
534 534
 	}
535 535
 
536 536
 	/**
537 537
 	 * Returns an array of sortable items table columns.
538 538
 	 */
539
-	public static function sortable_item_columns( $columns ) {
539
+	public static function sortable_item_columns($columns) {
540 540
 
541 541
 		return array_merge(
542 542
 			$columns,
@@ -553,49 +553,49 @@  discard block
 block discarded – undo
553 553
 	/**
554 554
 	 * Displays items table columns.
555 555
 	 */
556
-	public static function display_item_columns( $column_name, $post_id ) {
556
+	public static function display_item_columns($column_name, $post_id) {
557 557
  
558
-		$item = new WPInv_Item( $post_id );
558
+		$item = new WPInv_Item($post_id);
559 559
 
560
-		switch ( $column_name ) {
560
+		switch ($column_name) {
561 561
 
562 562
 			case 'price' :
563 563
 
564
-				if ( ! $item->is_recurring() ) {
564
+				if (!$item->is_recurring()) {
565 565
 					echo $item->get_the_price();
566 566
 					break;
567 567
 				}
568 568
 
569 569
 				$price = wp_sprintf(
570
-					__( '%s / %s', 'invoicing' ),
570
+					__('%s / %s', 'invoicing'),
571 571
 					$item->get_the_price(),
572
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
572
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
573 573
 				);
574 574
 
575
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
575
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
576 576
 					echo $price;
577 577
 					break;
578 578
 				}
579 579
 
580 580
 				echo $item->get_the_initial_price();
581 581
 
582
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
582
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
583 583
 				break;
584 584
 
585 585
 			case 'vat_rule' :
586
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
586
+				echo getpaid_get_tax_rule_label($item->get_vat_rule());
587 587
 				break;
588 588
 
589 589
 			case 'vat_class' :
590
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
590
+				echo getpaid_get_tax_class_label($item->get_vat_class());
591 591
 				break;
592 592
 
593 593
 			case 'shortcode' :
594
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
594
+				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
595 595
 				break;
596 596
 
597 597
 			case 'type' :
598
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
598
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
599 599
 				break;
600 600
 
601 601
 		}
@@ -605,21 +605,21 @@  discard block
 block discarded – undo
605 605
 	/**
606 606
 	 * Lets users filter items using taxes.
607 607
 	 */
608
-	public static function add_item_filters( $post_type ) {
608
+	public static function add_item_filters($post_type) {
609 609
 
610 610
 		// Abort if we're not dealing with items.
611
-		if ( $post_type != 'wpi_item' ) {
611
+		if ($post_type != 'wpi_item') {
612 612
 			return;
613 613
 		}
614 614
 
615 615
 		// Filter by vat rules.
616
-		if ( wpinv_use_taxes() ) {
616
+		if (wpinv_use_taxes()) {
617 617
 	
618 618
 			// Sanitize selected vat rule.
619 619
 			$vat_rule   = '';
620 620
 			$vat_rules  = getpaid_get_tax_rules();
621
-			if ( isset( $_GET['vat_rule'] ) ) {
622
-				$vat_rule   =  $_GET['vat_rule'];
621
+			if (isset($_GET['vat_rule'])) {
622
+				$vat_rule = $_GET['vat_rule'];
623 623
 			}
624 624
 
625 625
 			// Filter by VAT rule.
@@ -627,13 +627,13 @@  discard block
 block discarded – undo
627 627
 				array(
628 628
 					'options'          => array_merge(
629 629
 						array(
630
-							'' => __( 'All VAT rules', 'invoicing' )
630
+							'' => __('All VAT rules', 'invoicing')
631 631
 						),
632 632
 						$vat_rules
633 633
 					),
634 634
 					'name'             => 'vat_rule',
635 635
 					'id'               => 'vat_rule',
636
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
636
+					'selected'         => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '',
637 637
 					'show_option_all'  => false,
638 638
 					'show_option_none' => false,
639 639
 				)
@@ -644,21 +644,21 @@  discard block
 block discarded – undo
644 644
 			// Sanitize selected vat rule.
645 645
 			$vat_class   = '';
646 646
 			$vat_classes = getpaid_get_tax_classes();
647
-			if ( isset( $_GET['vat_class'] ) ) {
648
-				$vat_class   =  $_GET['vat_class'];
647
+			if (isset($_GET['vat_class'])) {
648
+				$vat_class = $_GET['vat_class'];
649 649
 			}
650 650
 
651 651
 			echo wpinv_html_select(
652 652
 				array(
653 653
 					'options'          => array_merge(
654 654
 						array(
655
-							'' => __( 'All VAT classes', 'invoicing' )
655
+							'' => __('All VAT classes', 'invoicing')
656 656
 						),
657 657
 						$vat_classes
658 658
 					),
659 659
 					'name'             => 'vat_class',
660 660
 					'id'               => 'vat_class',
661
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
661
+					'selected'         => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '',
662 662
 					'show_option_all'  => false,
663 663
 					'show_option_none' => false,
664 664
 				)
@@ -667,22 +667,22 @@  discard block
 block discarded – undo
667 667
 		}
668 668
 
669 669
 		// Filter by item type.
670
-		$type   = '';
671
-		if ( isset( $_GET['type'] ) ) {
672
-			$type   =  $_GET['type'];
670
+		$type = '';
671
+		if (isset($_GET['type'])) {
672
+			$type = $_GET['type'];
673 673
 		}
674 674
 
675 675
 		echo wpinv_html_select(
676 676
 			array(
677 677
 				'options'          => array_merge(
678 678
 					array(
679
-						'' => __( 'All item types', 'invoicing' )
679
+						'' => __('All item types', 'invoicing')
680 680
 					),
681 681
 					wpinv_get_item_types()
682 682
 				),
683 683
 				'name'             => 'type',
684 684
 				'id'               => 'type',
685
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
685
+				'selected'         => in_array($type, wpinv_item_types()) ? $type : '',
686 686
 				'show_option_all'  => false,
687 687
 				'show_option_none' => false,
688 688
 			)
@@ -693,45 +693,45 @@  discard block
 block discarded – undo
693 693
 	/**
694 694
 	 * Filters the item query.
695 695
 	 */
696
-	public static function filter_item_query( $query ) {
696
+	public static function filter_item_query($query) {
697 697
 
698 698
 		// modify the query only if it admin and main query.
699
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
699
+		if (!(is_admin() && $query->is_main_query())) { 
700 700
 			return $query;
701 701
 		}
702 702
 
703 703
 		// we want to modify the query for our items.
704
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
704
+		if (empty($query->query['post_type']) || 'wpi_item' != $query->query['post_type']) {
705 705
 			return $query;
706 706
 		}
707 707
 
708
-		if ( empty( $query->query_vars['meta_query'] ) ) {
708
+		if (empty($query->query_vars['meta_query'])) {
709 709
 			$query->query_vars['meta_query'] = array();
710 710
 		}
711 711
 
712 712
 		// Filter vat rule type
713
-        if ( ! empty( $_GET['vat_rule'] ) ) {
713
+        if (!empty($_GET['vat_rule'])) {
714 714
             $query->query_vars['meta_query'][] = array(
715 715
                 'key'     => '_wpinv_vat_rule',
716
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
716
+                'value'   => sanitize_text_field($_GET['vat_rule']),
717 717
                 'compare' => '='
718 718
             );
719 719
         }
720 720
 
721 721
         // Filter vat class
722
-        if ( ! empty( $_GET['vat_class'] ) ) {
722
+        if (!empty($_GET['vat_class'])) {
723 723
             $query->query_vars['meta_query'][] = array(
724 724
                 'key'     => '_wpinv_vat_class',
725
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
725
+                'value'   => sanitize_text_field($_GET['vat_class']),
726 726
                 'compare' => '='
727 727
             );
728 728
         }
729 729
 
730 730
         // Filter item type
731
-        if ( ! empty( $_GET['type'] ) ) {
731
+        if (!empty($_GET['type'])) {
732 732
             $query->query_vars['meta_query'][] = array(
733 733
                 'key'     => '_wpinv_type',
734
-                'value'   => sanitize_text_field( $_GET['type'] ),
734
+                'value'   => sanitize_text_field($_GET['type']),
735 735
                 'compare' => '='
736 736
             );
737 737
 		}
@@ -741,15 +741,15 @@  discard block
 block discarded – undo
741 741
 	/**
742 742
 	 * Reorders items.
743 743
 	 */
744
-	public static function reorder_items( $vars ) {
744
+	public static function reorder_items($vars) {
745 745
 		global $typenow;
746 746
 
747
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
747
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
748 748
 			return $vars;
749 749
 		}
750 750
 
751 751
 		// By item type.
752
-		if ( 'type' == $vars['orderby'] ) {
752
+		if ('type' == $vars['orderby']) {
753 753
 			return array_merge(
754 754
 				$vars,
755 755
 				array(
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 		}
761 761
 
762 762
 		// By vat class.
763
-		if ( 'vat_class' == $vars['orderby'] ) {
763
+		if ('vat_class' == $vars['orderby']) {
764 764
 			return array_merge(
765 765
 				$vars,
766 766
 				array(
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 		}
772 772
 
773 773
 		// By vat rule.
774
-		if ( 'vat_rule' == $vars['orderby'] ) {
774
+		if ('vat_rule' == $vars['orderby']) {
775 775
 			return array_merge(
776 776
 				$vars,
777 777
 				array(
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 		}
783 783
 
784 784
 		// By price.
785
-		if ( 'price' == $vars['orderby'] ) {
785
+		if ('price' == $vars['orderby']) {
786 786
 			return array_merge(
787 787
 				$vars,
788 788
 				array(
@@ -799,27 +799,27 @@  discard block
 block discarded – undo
799 799
 	/**
800 800
 	 * Fired when deleting a post.
801 801
 	 */
802
-	public static function delete_post( $post_id ) {
802
+	public static function delete_post($post_id) {
803 803
 
804
-		switch ( get_post_type( $post_id ) ) {
804
+		switch (get_post_type($post_id)) {
805 805
 
806 806
 			case 'wpi_item' :
807
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
807
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
808 808
 				break;
809 809
 
810 810
 			case 'wpi_payment_form' :
811
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
811
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
812 812
 				break;
813 813
 
814 814
 			case 'wpi_discount' :
815
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
815
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
816 816
 				break;
817 817
 
818 818
 			case 'wpi_invoice' :
819
-				$invoice = new WPInv_Invoice( $post_id );
820
-				do_action( "getpaid_before_delete_invoice", $invoice );
821
-				$invoice->get_data_store()->delete_items( $invoice );
822
-				$invoice->get_data_store()->delete_special_fields( $invoice );
819
+				$invoice = new WPInv_Invoice($post_id);
820
+				do_action("getpaid_before_delete_invoice", $invoice);
821
+				$invoice->get_data_store()->delete_items($invoice);
822
+				$invoice->get_data_store()->delete_special_fields($invoice);
823 823
 				break;
824 824
 		}
825 825
 	}
@@ -832,29 +832,29 @@  discard block
 block discarded – undo
832 832
      *
833 833
      * @return mixed
834 834
      */
835
-    public static function add_display_post_states( $post_states, $post ) {
835
+    public static function add_display_post_states($post_states, $post) {
836 836
 
837
-        if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) {
838
-            $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
837
+        if (wpinv_get_option('success_page', 0) == $post->ID) {
838
+            $post_states['getpaid_success_page'] = __('GetPaid Receipt Page', 'invoicing');
839 839
         }
840 840
 
841
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
841
+		foreach (getpaid_get_invoice_post_types() as $post_type => $label) {
842 842
 
843
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
843
+			if (wpinv_get_option("{$post_type}_history_page", 0) == $post->ID) {
844 844
 				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
845
-					__( 'GetPaid %s History Page', 'invoicing' ),
845
+					__('GetPaid %s History Page', 'invoicing'),
846 846
 					$label
847 847
 				);
848 848
 			}
849 849
 
850 850
 		}
851 851
 		
852
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
853
-            $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
852
+		if (wpinv_get_option('invoice_subscription_page', 0) == $post->ID) {
853
+            $post_states['getpaid_invoice_subscription_page'] = __('GetPaid Subscription Page', 'invoicing');
854 854
         }
855 855
 
856
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
857
-            $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
856
+		if (wpinv_get_option('checkout_page', 0) == $post->ID) {
857
+            $post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing');
858 858
         }
859 859
 
860 860
         return $post_states;
Please login to merge, or discard this patch.
templates/payment-forms/elements/address-fields.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -11,58 +11,58 @@  discard block
 block discarded – undo
11 11
  * @var string $country The current user's country
12 12
  */
13 13
 
14
-defined( 'ABSPATH' ) || exit;
14
+defined('ABSPATH') || exit;
15 15
 
16 16
 
17
-$field_type = sanitize_key( $field_type );
17
+$field_type = sanitize_key($field_type);
18 18
 
19 19
 echo "<div class='row $field_type'>";
20 20
 
21
-foreach ( $fields as $address_field ) {
21
+foreach ($fields as $address_field) {
22 22
 
23 23
     // Skip if it is hidden.
24
-    if ( empty( $address_field['visible'] ) ) {
24
+    if (empty($address_field['visible'])) {
25 25
         continue;
26 26
     }
27 27
 
28
-    do_action( 'getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field );
28
+    do_action('getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field);
29 29
 
30 30
     // Prepare variables.
31
-    if ( ! empty( $form->invoice ) ) {
31
+    if (!empty($form->invoice)) {
32 32
         $user_id = $form->invoice->get_user_id();
33 33
     }
34 34
 
35
-    if ( empty( $user_id ) && is_user_logged_in() ) {
35
+    if (empty($user_id) && is_user_logged_in()) {
36 36
         $user_id = get_current_user_id();
37 37
     }
38 38
 
39 39
     $field_name  = $address_field['name'];
40 40
     $field_name  = "{$field_type}[$field_name]";
41
-    $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
42
-    $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
43
-    $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
44
-    $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
45
-    $value       = ! empty( $user_id ) ? get_user_meta( $user_id, '_' . $address_field['name'], true ) : '';
46
-    $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
47
-
48
-    if ( ! empty( $address_field['required'] ) ) {
41
+    $wrap_class  = getpaid_get_form_element_grid_class($address_field);
42
+    $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
43
+    $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
44
+    $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
45
+    $value       = !empty($user_id) ? get_user_meta($user_id, '_' . $address_field['name'], true) : '';
46
+    $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
47
+
48
+    if (!empty($address_field['required'])) {
49 49
         $label .= "<span class='text-danger'> *</span>";
50 50
     }
51 51
 
52 52
     // Display the country.
53
-    if ( 'wpinv_country' == $address_field['name'] ) {
53
+    if ('wpinv_country' == $address_field['name']) {
54 54
 
55 55
         echo "<div class='form-group $wrap_class getpaid-address-field-wrapper__country'";
56 56
 
57 57
         echo aui()->select(
58 58
             array(
59 59
                 'options'     => wpinv_get_country_list(),
60
-                'name'        => esc_attr( $field_name ),
61
-                'id'          => sanitize_html_class( $field_name ) . $uniqid,
62
-                'value'       => sanitize_text_field( $country ),
60
+                'name'        => esc_attr($field_name),
61
+                'id'          => sanitize_html_class($field_name) . $uniqid,
62
+                'value'       => sanitize_text_field($country),
63 63
                 'placeholder' => $placeholder,
64
-                'required'    => ! empty( $address_field['required'] ),
65
-                'label'       => wp_kses_post( $label ),
64
+                'required'    => !empty($address_field['required']),
65
+                'label'       => wp_kses_post($label),
66 66
                 'label_type'  => 'vertical',
67 67
                 'help_text'   => $description,
68 68
                 'class'       => 'getpaid-address-field wpinv_country',
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             )
76 76
         );
77 77
 
78
-        if ( wpinv_should_validate_vat_number() ) {
78
+        if (wpinv_should_validate_vat_number()) {
79 79
 
80 80
             echo aui()->input(
81 81
                 array(
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                     'id'         => "shipping-toggle$uniqid",
85 85
                     'wrap_class' => "getpaid-address-field-wrapper__address-confirm mt-1 d-none",
86 86
                     'required'   => false,
87
-                    'label'      => __( 'I certify that I live in the country selected above', 'invoicing' ) . "<span class='text-danger'> *</span>",
87
+                    'label'      => __('I certify that I live in the country selected above', 'invoicing') . "<span class='text-danger'> *</span>",
88 88
                     'value'      => 1,
89 89
                     'checked'    => true,
90 90
                     'class'      => 'w-auto',
@@ -98,27 +98,27 @@  discard block
 block discarded – undo
98 98
     }
99 99
 
100 100
     // Display the state.
101
-    else if ( 'wpinv_state' == $address_field['name'] ) {
101
+    else if ('wpinv_state' == $address_field['name']) {
102 102
 
103
-        if ( empty( $value ) ) {
103
+        if (empty($value)) {
104 104
             $value = wpinv_get_default_state();
105 105
         }
106 106
 
107
-        echo getpaid_get_states_select_markup (
107
+        echo getpaid_get_states_select_markup(
108 108
             $country,
109 109
             $value,
110 110
             $placeholder,
111 111
             $label,
112 112
             $description,
113
-            ! empty( $address_field['required'] ),
113
+            !empty($address_field['required']),
114 114
             $wrap_class,
115 115
             $field_name
116 116
         );
117 117
 
118 118
     } else {
119 119
 
120
-        $key      = str_replace( 'wpinv_', '', $address_field['name'] );
121
-        $key      = esc_attr( str_replace( '_', '-', $key ) );
120
+        $key      = str_replace('wpinv_', '', $address_field['name']);
121
+        $key      = esc_attr(str_replace('_', '-', $key));
122 122
         $autocomplete = '';
123 123
         $replacements = array(
124 124
             'zip'        => 'postal-code',
@@ -131,37 +131,37 @@  discard block
 block discarded – undo
131 131
         );
132 132
 
133 133
 
134
-        if ( isset( $replacements[ $key ] ) ) {
134
+        if (isset($replacements[$key])) {
135 135
             $autocomplete = array(
136
-                'autocomplete' => "$field_type {$replacements[ $key ]}",
136
+                'autocomplete' => "$field_type {$replacements[$key]}",
137 137
             );
138 138
         }
139 139
 
140 140
         $append = '';
141 141
 
142
-        if ( 'billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key ) {
143
-            $valid    = esc_attr__( 'Valid', 'invoicing' );
144
-            $invalid  = esc_attr__( 'Invalid', 'invoicing' );
145
-            $validate = esc_attr__( 'Validate', 'invoicing' );
142
+        if ('billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key) {
143
+            $valid    = esc_attr__('Valid', 'invoicing');
144
+            $invalid  = esc_attr__('Invalid', 'invoicing');
145
+            $validate = esc_attr__('Validate', 'invoicing');
146 146
             $append   = "<span class='btn btn-primary getpaid-vat-number-validate' data-valid='$valid' data-invalid='$invalid' data-validate='$validate'>$validate</span>";
147 147
         }
148 148
 
149
-        if ( 'billing' === $field_type ) {
150
-            $description .= '<div class="getpaid-error-' . sanitize_html_class( $field_name ) . ' getpaid-custom-payment-form-errors alert alert-danger d-none"></div>';
149
+        if ('billing' === $field_type) {
150
+            $description .= '<div class="getpaid-error-' . sanitize_html_class($field_name) . ' getpaid-custom-payment-form-errors alert alert-danger d-none"></div>';
151 151
         }
152 152
 
153 153
         echo aui()->input(
154 154
             array(
155
-                'name'        => esc_attr( $field_name ),
156
-                'id'          => sanitize_html_class( $field_name ) . $uniqid,
157
-                'required'    => ! empty( $address_field['required'] ),
155
+                'name'        => esc_attr($field_name),
156
+                'id'          => sanitize_html_class($field_name) . $uniqid,
157
+                'required'    => !empty($address_field['required']),
158 158
                 'placeholder' => $placeholder,
159
-                'label'       => wp_kses_post( $label ),
159
+                'label'       => wp_kses_post($label),
160 160
                 'label_type'  => 'vertical',
161 161
                 'help_text'   => $description,
162 162
                 'type'        => 'text',
163
-                'value'       => sanitize_text_field( $value ),
164
-                'class'       => 'getpaid-address-field ' . esc_attr( $address_field['name'] ),
163
+                'value'       => sanitize_text_field($value),
164
+                'class'       => 'getpaid-address-field ' . esc_attr($address_field['name']),
165 165
                 'wrap_class'  => "$wrap_class getpaid-address-field-wrapper__$key",
166 166
                 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__' . $key,
167 167
                 'extra_attributes'  => $autocomplete,
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
     }
173 173
 
174
-    do_action( 'getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field );
174
+    do_action('getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field);
175 175
 }
176 176
 
177 177
 echo "</div>";
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,228 +12,228 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26 26
 
27 27
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
-
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
74
-				continue;
75
-			}
76
-
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
-
80
-		}
81
-
82
-	}
83
-
84
-	/**
85
-	 * Checks if the submission has a digital item.
86
-	 *
87
-	 * @param GetPaid_Payment_Form_Submission $submission
88
-	 * @since 1.0.19
89
-	 * @return bool
90
-	 */
91
-	public function has_digital_item( $submission ) {
92
-
93
-		foreach ( $submission->get_items() as $item ) {
94
-
95
-			if ( 'digital' == $item->get_vat_rule() ) {
96
-				return true;
97
-			}
98
-
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
202 38
             return;
203
-		}
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+
72
+            if ( ! isset( $this->taxes[ $name ] ) ) {
73
+                $this->taxes[ $name ] = $tax;
74
+                continue;
75
+            }
76
+
77
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
+
80
+        }
81
+
82
+    }
83
+
84
+    /**
85
+     * Checks if the submission has a digital item.
86
+     *
87
+     * @param GetPaid_Payment_Form_Submission $submission
88
+     * @since 1.0.19
89
+     * @return bool
90
+     */
91
+    public function has_digital_item( $submission ) {
92
+
93
+        foreach ( $submission->get_items() as $item ) {
94
+
95
+            if ( 'digital' == $item->get_vat_rule() ) {
96
+                return true;
97
+            }
98
+
99
+        }
204 100
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202
+            return;
203
+        }
204
+
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215 215
 
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
219
+            // Ensure that a vat number has been specified.
220
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221 221
 
222
-		}
222
+        }
223 223
 
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231 231
 
232
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
232
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235 235
 
236
-		$this->skip_taxes = true;
237
-	}
236
+        $this->skip_taxes = true;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 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
  * Payment form submission taxes class
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 
34 34
 		// Validate VAT number.
35
-		$this->validate_vat( $submission );
35
+		$this->validate_vat($submission);
36 36
 
37
-		if ( $this->skip_taxes ) {
37
+		if ($this->skip_taxes) {
38 38
 			return;
39 39
 		}
40 40
 
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
41
+		foreach ($submission->get_items() as $item) {
42
+			$this->process_item_tax($item, $submission);
43 43
 		}
44 44
 
45 45
 		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
46
+		if ($submission->has_invoice()) {
47
+			$this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes);
48 48
 		}
49 49
 
50 50
 	}
@@ -56,26 +56,26 @@  discard block
 block discarded – undo
56 56
 	 * @param GetPaid_Form_Item $item
57 57
 	 * @param GetPaid_Payment_Form_Submission $submission
58 58
 	 */
59
-	public function process_item_tax( $item, $submission ) {
59
+	public function process_item_tax($item, $submission) {
60 60
 
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
61
+		$rates    = getpaid_get_item_tax_rates($item, $submission->country, $submission->state);
62
+		$rates    = getpaid_filter_item_tax_rates($item, $rates);
63
+		$taxes    = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates);
64
+		$r_taxes  = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates);
65 65
 
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
66
+		foreach ($taxes as $name => $amount) {
67
+			$recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0;
68
+			$tax       = getpaid_prepare_item_tax($item, $name, $amount, $recurring);
69 69
 
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
70
+			$item->item_tax += wpinv_sanitize_amount($tax['initial_tax']);
71 71
 
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
72
+			if (!isset($this->taxes[$name])) {
73
+				$this->taxes[$name] = $tax;
74 74
 				continue;
75 75
 			}
76 76
 
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+			$this->taxes[$name]['initial_tax']   += $tax['initial_tax'];
78
+			$this->taxes[$name]['recurring_tax'] += $tax['recurring_tax'];
79 79
 
80 80
 		}
81 81
 
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 	 * @since 1.0.19
89 89
 	 * @return bool
90 90
 	 */
91
-	public function has_digital_item( $submission ) {
91
+	public function has_digital_item($submission) {
92 92
 
93
-		foreach ( $submission->get_items() as $item ) {
93
+		foreach ($submission->get_items() as $item) {
94 94
 
95
-			if ( 'digital' == $item->get_vat_rule() ) {
95
+			if ('digital' == $item->get_vat_rule()) {
96 96
 				return true;
97 97
 			}
98 98
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @return bool
109 109
 	 */
110 110
 	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
111
+		return self::is_eu_country(wpinv_get_default_country());
112 112
 	}
113 113
 
114 114
 	/**
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * @since 1.0.19
119 119
 	 * @return bool
120 120
 	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
121
+	public static function is_eu_country($country) {
122
+		return getpaid_is_eu_state($country);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @since 1.0.19
130 130
 	 * @return bool
131 131
 	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+	public static function is_eu_transaction($customer_country) {
133
+		return self::is_eu_country($customer_country) && self::is_eu_store();
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @since 1.0.19
141 141
 	 * @return string
142 142
 	 */
143
-	public function get_vat_number( $submission ) {
143
+	public function get_vat_number($submission) {
144 144
 
145 145
 		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
146
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
147
+		if (!is_null($vat_number)) {
148
+			return wpinv_clean($vat_number);
149 149
 		}
150 150
 
151 151
 		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @since 1.0.19
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_company( $submission ) {
161
+	public function get_company($submission) {
162 162
 
163 163
 		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
164
+		$company = $submission->get_field('wpinv_company', 'billing');
165
+		if (!empty($company)) {
166
+			return wpinv_clean($company);
167 167
 		}
168 168
 
169 169
 		// Retrieve from the invoice.
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 * @since 1.0.19
179 179
 	 * @return string
180 180
 	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
+	public function requires_vat($ip_in_eu, $country_in_eu) {
182 182
 
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
183
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
184
+		$prevent_b2c = !empty($prevent_b2c);
185 185
 		$is_eu       = $ip_in_eu || $country_in_eu;
186 186
 
187 187
 		return $prevent_b2c && $is_eu;
@@ -193,43 +193,43 @@  discard block
 block discarded – undo
193 193
 	 * @param GetPaid_Payment_Form_Submission $submission
194 194
 	 * @since 1.0.19
195 195
 	 */
196
-	public function validate_vat( $submission ) {
196
+	public function validate_vat($submission) {
197 197
 
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
198
+		$in_eu = $this->is_eu_transaction($submission->country);
199 199
 
200 200
 		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
201
+		if (!$in_eu) {
202 202
             return;
203 203
 		}
204 204
 
205 205
 		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
206
+		$vat_number  = $this->get_vat_number($submission);
207 207
 		$ip_country  = getpaid_get_ip_country();
208
-        $is_eu       = $this->is_eu_country( $submission->country );
209
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
208
+        $is_eu       = $this->is_eu_country($submission->country);
209
+        $is_ip_eu    = $this->is_eu_country($ip_country);
210 210
 
211 211
 		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
212
+		if ($submission->is_initial_fetch() && empty($vat_number)) {
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
220
+			throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing'));
221 221
 
222 222
 		}
223 223
 
224
-		if ( empty( $vat_number ) ) {
224
+		if (empty($vat_number)) {
225 225
 			return;
226 226
 		}
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
228
+		if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) {
229
+			throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Your VAT number is invalid', 'invoicing'));
230 230
 		}
231 231
 
232
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
232
+		if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) {
233 233
 			return;
234 234
 		}
235 235
 
Please login to merge, or discard this patch.