Passed
Push — master ( c6d0db...756836 )
by Brian
04:55 queued 28s
created
includes/admin/meta-boxes/class-getpaid-meta-box-resend-invoice.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit; // Exit if accessed directly
10 10
 }
11 11
 
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param WP_Post $post
21 21
 	 */
22
-    public static function output( $post ) {
22
+    public static function output($post) {
23 23
 
24 24
         // Fetch the invoice.
25
-        $invoice = new WPInv_Invoice( $post );
25
+        $invoice = new WPInv_Invoice($post);
26 26
 
27
-        do_action( 'wpinv_metabox_resend_invoice_before', $invoice );
27
+        do_action('wpinv_metabox_resend_invoice_before', $invoice);
28 28
 
29 29
         $email_url = esc_url(
30 30
             add_query_arg(
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
         );
51 51
 
52 52
         ?>
53
-            <p class="wpi-meta-row wpi-resend-info"><?php _e( "This will send a copy of the invoice to the customer's email address.", 'invoicing' ); ?></p>
54
-            <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e( 'Resend Invoice', 'invoicing' ); ?></a></p>
55
-            <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
53
+            <p class="wpi-meta-row wpi-resend-info"><?php _e("This will send a copy of the invoice to the customer's email address.", 'invoicing'); ?></p>
54
+            <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e('Resend Invoice', 'invoicing'); ?></a></p>
55
+            <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
56 56
         <?php
57 57
 
58
-        do_action( 'wpinv_metabox_resend_invoice_after', $invoice );
58
+        do_action('wpinv_metabox_resend_invoice_after', $invoice);
59 59
 
60 60
     }
61 61
 
Please login to merge, or discard this patch.
templates/invoice-history.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Current page.
13
-$current_page   = empty( $_GET[ 'page' ] ) ? 1 : absint( $_GET[ 'page' ] );
13
+$current_page = empty($_GET['page']) ? 1 : absint($_GET['page']);
14 14
 
15 15
 // Fires before displaying user invoices.
16
-do_action( 'wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages );
16
+do_action('wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages);
17 17
 
18 18
 ?>
19 19
 
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 		<thead>
24 24
 			<tr>
25 25
 
26
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
27
-					<th class="<?php echo sanitize_html_class( $column_id ); ?> <?php echo ( ! empty( $column_name['class'] ) ? sanitize_html_class( $column_name['class'] ) : '');?> border-bottom-0">
28
-						<span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span>
26
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
27
+					<th class="<?php echo sanitize_html_class($column_id); ?> <?php echo (!empty($column_name['class']) ? sanitize_html_class($column_name['class']) : ''); ?> border-bottom-0">
28
+						<span class="nobr"><?php echo esc_html($column_name['title']); ?></span>
29 29
 					</th>
30 30
 				<?php endforeach; ?>
31 31
 
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
 
36 36
 		
37 37
 		<tbody>
38
-			<?php foreach ( $invoices->invoices as $invoice ) : ?>
38
+			<?php foreach ($invoices->invoices as $invoice) : ?>
39 39
 
40 40
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
41 41
 					<?php
42 42
 
43
-						foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) :
43
+						foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) :
44 44
 
45
-							$column_id = sanitize_html_class( $column_id );
46
-							$class     = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] );
45
+							$column_id = sanitize_html_class($column_id);
46
+							$class     = empty($column_name['class']) ? '' : sanitize_html_class($column_name['class']);
47 47
 
48 48
 							echo "<td class='$column_id $class'>";
49
-							switch ( $column_id ) {
49
+							switch ($column_id) {
50 50
 
51 51
 								case 'invoice-number':
52
-									echo wpinv_invoice_link( $invoice );
52
+									echo wpinv_invoice_link($invoice);
53 53
 									break;
54 54
 
55 55
 								case 'created-date':
56
-									echo getpaid_format_date_value( $invoice->get_date_created() );
56
+									echo getpaid_format_date_value($invoice->get_date_created());
57 57
 									break;
58 58
 
59 59
 								case 'payment-date':
60 60
 
61
-									if ( $invoice->needs_payment() ) {
61
+									if ($invoice->needs_payment()) {
62 62
 										echo "&mdash;";
63 63
 									} else {
64
-										echo getpaid_format_date_value( $invoice->get_date_completed() );
64
+										echo getpaid_format_date_value($invoice->get_date_completed());
65 65
 									}
66 66
 									
67 67
 									break;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 									break;
73 73
 
74 74
 								case 'invoice-total':
75
-									echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) );
75
+									echo wpinv_price(wpinv_format_amount($invoice->get_total()));
76 76
 									
77 77
 									break;
78 78
 
@@ -82,39 +82,39 @@  discard block
 block discarded – undo
82 82
 
83 83
 										'pay'       => array(
84 84
 											'url'   => $invoice->get_checkout_payment_url(),
85
-											'name'  => __( 'Pay Now', 'invoicing' ),
85
+											'name'  => __('Pay Now', 'invoicing'),
86 86
                                             'class' => 'btn-success'
87 87
 										),
88 88
 
89 89
                                         'print'     => array(
90 90
 											'url'   => $invoice->get_view_url(),
91
-											'name'  => __( 'View Invoice', 'invoicing' ),
91
+											'name'  => __('View Invoice', 'invoicing'),
92 92
                                             'class' => 'btn-secondary',
93 93
                                             'attrs' => 'target="_blank"'
94 94
 										)
95 95
 									);
96 96
 
97
-									if ( ! $invoice->needs_payment() ) {
98
-										unset( $actions['pay'] );
97
+									if (!$invoice->needs_payment()) {
98
+										unset($actions['pay']);
99 99
 									}
100 100
 
101
-									$actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice );
101
+									$actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice);
102 102
 
103
-									foreach ( $actions as $key => $action ) {
103
+									foreach ($actions as $key => $action) {
104 104
 										$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
105
-										echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
105
+										echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
106 106
 									}
107 107
 									
108 108
 									break;
109 109
 
110 110
 								default:
111
-									do_action( "wpinv_user_invoices_column_$column_id", $invoice );
111
+									do_action("wpinv_user_invoices_column_$column_id", $invoice);
112 112
 									break;
113 113
 
114 114
 								
115 115
 							}
116 116
 
117
-							do_action( "wpinv_user_invoices_column_after_$column_id", $invoice );
117
+							do_action("wpinv_user_invoices_column_after_$column_id", $invoice);
118 118
 						
119 119
 							echo '</td>';
120 120
 
@@ -127,20 +127,20 @@  discard block
 block discarded – undo
127 127
 		</tbody>
128 128
 	</table>
129 129
 
130
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
130
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
131 131
 
132
-	<?php if ( 1 < $invoices->max_num_pages ) : ?>
132
+	<?php if (1 < $invoices->max_num_pages) : ?>
133 133
 		<div class="invoicing-Pagination">
134 134
 			<?php
135 135
 			$big = 999999;
136 136
 
137
-			echo paginate_links( array(
138
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
137
+			echo paginate_links(array(
138
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
139 139
 				'format'  => '?paged=%#%',
140 140
 				'total'   => $invoices->max_num_pages,
141
-			) );
141
+			));
142 142
 			?>
143 143
 		</div>
144 144
 	<?php endif; ?>
145 145
 
146
-<?php do_action( 'wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages  ); ?>
146
+<?php do_action('wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages); ?>
Please login to merge, or discard this patch.
includes/class-wpinv-legacy-invoice.php 1 patch
Spacing   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Legacy_Invoice {
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * Invoice id.
18 18
      */
19
-    public $ID  = 0;
19
+    public $ID = 0;
20 20
 
21 21
     /**
22 22
      * The title of the invoice. Usually the invoice number.
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * The invoice status.
134 134
      */
135
-    public $status      = 'wpi-pending';
135
+    public $status = 'wpi-pending';
136 136
 
137 137
     /**
138 138
      * Same as self::$status.
@@ -259,17 +259,17 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public $parent_invoice = 0;
261 261
     
262
-    public function __construct( $invoice_id = false ) {
263
-        if( empty( $invoice_id ) ) {
262
+    public function __construct($invoice_id = false) {
263
+        if (empty($invoice_id)) {
264 264
             return false;
265 265
         }
266 266
 
267
-        $this->setup_invoice( $invoice_id );
267
+        $this->setup_invoice($invoice_id);
268 268
     }
269 269
 
270
-    public function get( $key ) {
271
-        if ( method_exists( $this, 'get_' . $key ) ) {
272
-            $value = call_user_func( array( $this, 'get_' . $key ) );
270
+    public function get($key) {
271
+        if (method_exists($this, 'get_' . $key)) {
272
+            $value = call_user_func(array($this, 'get_' . $key));
273 273
         } else {
274 274
             $value = $this->$key;
275 275
         }
@@ -277,51 +277,51 @@  discard block
 block discarded – undo
277 277
         return $value;
278 278
     }
279 279
 
280
-    public function set( $key, $value ) {
281
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
280
+    public function set($key, $value) {
281
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
282 282
 
283
-        if ( $key === 'status' ) {
283
+        if ($key === 'status') {
284 284
             $this->old_status = $this->status;
285 285
         }
286 286
 
287
-        if ( ! in_array( $key, $ignore ) ) {
288
-            $this->pending[ $key ] = $value;
287
+        if (!in_array($key, $ignore)) {
288
+            $this->pending[$key] = $value;
289 289
         }
290 290
 
291
-        if( '_ID' !== $key ) {
291
+        if ('_ID' !== $key) {
292 292
             $this->$key = $value;
293 293
         }
294 294
     }
295 295
 
296
-    public function _isset( $name ) {
297
-        if ( property_exists( $this, $name) ) {
298
-            return false === empty( $this->$name );
296
+    public function _isset($name) {
297
+        if (property_exists($this, $name)) {
298
+            return false === empty($this->$name);
299 299
         } else {
300 300
             return null;
301 301
         }
302 302
     }
303 303
 
304
-    private function setup_invoice( $invoice_id ) {
304
+    private function setup_invoice($invoice_id) {
305 305
         $this->pending = array();
306 306
 
307
-        if ( empty( $invoice_id ) ) {
307
+        if (empty($invoice_id)) {
308 308
             return false;
309 309
         }
310 310
 
311
-        $invoice = get_post( $invoice_id );
311
+        $invoice = get_post($invoice_id);
312 312
 
313
-        if( !$invoice || is_wp_error( $invoice ) ) {
313
+        if (!$invoice || is_wp_error($invoice)) {
314 314
             return false;
315 315
         }
316 316
 
317
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
317
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
318 318
             return false;
319 319
         }
320 320
 
321
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
321
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
322 322
 
323 323
         // Primary Identifier
324
-        $this->ID              = absint( $invoice_id );
324
+        $this->ID              = absint($invoice_id);
325 325
         $this->post_type       = $invoice->post_type;
326 326
 
327 327
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
         $this->completed_date  = $this->setup_completed_date();
332 332
         $this->status          = $invoice->post_status;
333 333
 
334
-        if ( 'future' == $this->status ) {
334
+        if ('future' == $this->status) {
335 335
             $this->status = 'publish';
336 336
         }
337 337
 
338 338
         $this->post_status     = $this->status;
339 339
         $this->mode            = $this->setup_mode();
340 340
         $this->parent_invoice  = $invoice->post_parent;
341
-        $this->post_name       = $this->setup_post_name( $invoice );
341
+        $this->post_name       = $this->setup_post_name($invoice);
342 342
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
343 343
 
344 344
         // Items
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
         
362 362
         // User based
363 363
         $this->ip              = $this->setup_ip();
364
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
365
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
364
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
365
+        $this->email           = get_the_author_meta('email', $this->user_id);
366 366
 
367 367
         $this->user_info       = $this->setup_user_info();
368 368
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $this->company         = $this->user_info['company'];
372 372
         $this->vat_number      = $this->user_info['vat_number'];
373 373
         $this->vat_rate        = $this->user_info['vat_rate'];
374
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
374
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
375 375
         $this->address         = $this->user_info['address'];
376 376
         $this->city            = $this->user_info['city'];
377 377
         $this->country         = $this->user_info['country'];
@@ -386,39 +386,39 @@  discard block
 block discarded – undo
386 386
         // Other Identifiers
387 387
         $this->key             = $this->setup_invoice_key();
388 388
         $this->number          = $this->setup_invoice_number();
389
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
389
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
390 390
         
391
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
391
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
392 392
         
393 393
         // Allow extensions to add items to this object via hook
394
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
394
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
395 395
 
396 396
         return true;
397 397
     }
398 398
 
399
-    private function setup_status_nicename( $status ) {
400
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
399
+    private function setup_status_nicename($status) {
400
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
401 401
 
402
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
403
-            $all_invoice_statuses  = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
402
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
403
+            $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
404 404
         }
405
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
405
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
406 406
 
407
-        return apply_filters( 'setup_status_nicename', $status );
407
+        return apply_filters('setup_status_nicename', $status);
408 408
     }
409 409
 
410
-    private function setup_post_name( $post = NULL ) {
410
+    private function setup_post_name($post = NULL) {
411 411
         global $wpdb;
412 412
         
413 413
         $post_name = '';
414 414
         
415
-        if ( !empty( $post ) ) {
416
-            if( !empty( $post->post_name ) ) {
415
+        if (!empty($post)) {
416
+            if (!empty($post->post_name)) {
417 417
                 $post_name = $post->post_name;
418
-            } else if ( !empty( $post->ID ) ) {
419
-                $post_name = wpinv_generate_post_name( $post->ID );
418
+            } else if (!empty($post->ID)) {
419
+                $post_name = wpinv_generate_post_name($post->ID);
420 420
 
421
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
421
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
422 422
             }
423 423
         }
424 424
 
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
     }
427 427
     
428 428
     private function setup_due_date() {
429
-        $due_date = $this->get_meta( '_wpinv_due_date' );
429
+        $due_date = $this->get_meta('_wpinv_due_date');
430 430
         
431
-        if ( empty( $due_date ) ) {
432
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
433
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
434
-        } else if ( $due_date == 'none' ) {
431
+        if (empty($due_date)) {
432
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
433
+            $due_date = date_i18n('Y-m-d', $overdue_time);
434
+        } else if ($due_date == 'none') {
435 435
             $due_date = '';
436 436
         }
437 437
         
@@ -439,67 +439,67 @@  discard block
 block discarded – undo
439 439
     }
440 440
     
441 441
     private function setup_completed_date() {
442
-        $invoice = get_post( $this->ID );
442
+        $invoice = get_post($this->ID);
443 443
 
444
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
444
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
445 445
             return false; // This invoice was never paid
446 446
         }
447 447
 
448
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
448
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
449 449
 
450 450
         return $date;
451 451
     }
452 452
     
453 453
     private function setup_cart_details() {
454
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
454
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
455 455
         return $cart_details;
456 456
     }
457 457
     
458 458
     public function array_convert() {
459
-        return get_object_vars( $this );
459
+        return get_object_vars($this);
460 460
     }
461 461
     
462 462
     private function setup_items() {
463
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
463
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
464 464
         return $items;
465 465
     }
466 466
     
467 467
     private function setup_fees() {
468
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
468
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
469 469
         return $payment_fees;
470 470
     }
471 471
         
472 472
     private function setup_currency() {
473
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
473
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
474 474
         return $currency;
475 475
     }
476 476
     
477 477
     private function setup_discount() {
478 478
         //$discount = $this->get_meta( '_wpinv_discount', true );
479
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
480
-        if ( $discount < 0 ) {
479
+        $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total);
480
+        if ($discount < 0) {
481 481
             $discount = 0;
482 482
         }
483
-        $discount = wpinv_round_amount( $discount );
483
+        $discount = wpinv_round_amount($discount);
484 484
         
485 485
         return $discount;
486 486
     }
487 487
     
488 488
     private function setup_discount_code() {
489
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
489
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
490 490
         return $discount_code;
491 491
     }
492 492
     
493 493
     private function setup_tax() {
494 494
 
495
-        $tax = $this->get_meta( '_wpinv_tax', true );
495
+        $tax = $this->get_meta('_wpinv_tax', true);
496 496
 
497 497
         // We don't have tax as it's own meta and no meta was passed
498
-        if ( '' === $tax ) {            
499
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
498
+        if ('' === $tax) {            
499
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
500 500
         }
501 501
         
502
-        if ( $tax < 0 || ! $this->is_taxable() ) {
502
+        if ($tax < 0 || !$this->is_taxable()) {
503 503
             $tax = 0;
504 504
         }
505 505
 
@@ -510,16 +510,16 @@  discard block
 block discarded – undo
510 510
      * If taxes are enabled, allow users to enable/disable taxes per invoice.
511 511
      */
512 512
     private function setup_is_taxable() {
513
-        return (int) $this->get_meta( '_wpinv_disable_taxes', true );
513
+        return (int) $this->get_meta('_wpinv_disable_taxes', true);
514 514
     }
515 515
 
516 516
     private function setup_subtotal() {
517 517
         $subtotal     = 0;
518 518
         $cart_details = $this->cart_details;
519 519
 
520
-        if ( is_array( $cart_details ) ) {
521
-            foreach ( $cart_details as $item ) {
522
-                if ( isset( $item['subtotal'] ) ) {
520
+        if (is_array($cart_details)) {
521
+            foreach ($cart_details as $item) {
522
+                if (isset($item['subtotal'])) {
523 523
                     $subtotal += $item['subtotal'];
524 524
                 }
525 525
             }
@@ -533,23 +533,23 @@  discard block
 block discarded – undo
533 533
     }
534 534
 
535 535
     private function setup_discounts() {
536
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
536
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
537 537
         return $discounts;
538 538
     }
539 539
     
540 540
     private function setup_total() {
541
-        $amount = $this->get_meta( '_wpinv_total', true );
541
+        $amount = $this->get_meta('_wpinv_total', true);
542 542
 
543
-        if ( empty( $amount ) && '0.00' != $amount ) {
544
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
545
-            $meta   = maybe_unserialize( $meta );
543
+        if (empty($amount) && '0.00' != $amount) {
544
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
545
+            $meta   = maybe_unserialize($meta);
546 546
 
547
-            if ( isset( $meta['amount'] ) ) {
547
+            if (isset($meta['amount'])) {
548 548
                 $amount = $meta['amount'];
549 549
             }
550 550
         }
551 551
 
552
-        if($amount < 0){
552
+        if ($amount < 0) {
553 553
             $amount = 0;
554 554
         }
555 555
 
@@ -557,13 +557,13 @@  discard block
 block discarded – undo
557 557
     }
558 558
     
559 559
     private function setup_mode() {
560
-        return $this->get_meta( '_wpinv_mode' );
560
+        return $this->get_meta('_wpinv_mode');
561 561
     }
562 562
 
563 563
     private function setup_gateway() {
564
-        $gateway = $this->get_meta( '_wpinv_gateway' );
564
+        $gateway = $this->get_meta('_wpinv_gateway');
565 565
         
566
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
566
+        if (empty($gateway) && 'publish' === $this->status) {
567 567
             $gateway = 'manual';
568 568
         }
569 569
         
@@ -571,23 +571,23 @@  discard block
 block discarded – undo
571 571
     }
572 572
 
573 573
     private function setup_gateway_title() {
574
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
574
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
575 575
         return $gateway_title;
576 576
     }
577 577
 
578 578
     private function setup_transaction_id() {
579
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
579
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
580 580
 
581
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
581
+        if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) {
582 582
             $gateway        = $this->gateway;
583
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
583
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
584 584
         }
585 585
 
586 586
         return $transaction_id;
587 587
     }
588 588
 
589 589
     private function setup_ip() {
590
-        $ip = $this->get_meta( '_wpinv_user_ip' );
590
+        $ip = $this->get_meta('_wpinv_user_ip');
591 591
         return $ip;
592 592
     }
593 593
 
@@ -597,62 +597,62 @@  discard block
 block discarded – undo
597 597
     ///}
598 598
         
599 599
     private function setup_first_name() {
600
-        $first_name = $this->get_meta( '_wpinv_first_name' );
600
+        $first_name = $this->get_meta('_wpinv_first_name');
601 601
         return $first_name;
602 602
     }
603 603
     
604 604
     private function setup_last_name() {
605
-        $last_name = $this->get_meta( '_wpinv_last_name' );
605
+        $last_name = $this->get_meta('_wpinv_last_name');
606 606
         return $last_name;
607 607
     }
608 608
     
609 609
     private function setup_company() {
610
-        $company = $this->get_meta( '_wpinv_company' );
610
+        $company = $this->get_meta('_wpinv_company');
611 611
         return $company;
612 612
     }
613 613
     
614 614
     private function setup_vat_number() {
615
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
615
+        $vat_number = $this->get_meta('_wpinv_vat_number');
616 616
         return $vat_number;
617 617
     }
618 618
     
619 619
     private function setup_vat_rate() {
620
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
620
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
621 621
         return $vat_rate;
622 622
     }
623 623
     
624 624
     private function setup_adddress_confirmed() {
625
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
625
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
626 626
         return $adddress_confirmed;
627 627
     }
628 628
     
629 629
     private function setup_phone() {
630
-        $phone = $this->get_meta( '_wpinv_phone' );
630
+        $phone = $this->get_meta('_wpinv_phone');
631 631
         return $phone;
632 632
     }
633 633
     
634 634
     private function setup_address() {
635
-        $address = $this->get_meta( '_wpinv_address', true );
635
+        $address = $this->get_meta('_wpinv_address', true);
636 636
         return $address;
637 637
     }
638 638
     
639 639
     private function setup_city() {
640
-        $city = $this->get_meta( '_wpinv_city', true );
640
+        $city = $this->get_meta('_wpinv_city', true);
641 641
         return $city;
642 642
     }
643 643
     
644 644
     private function setup_country() {
645
-        $country = $this->get_meta( '_wpinv_country', true );
645
+        $country = $this->get_meta('_wpinv_country', true);
646 646
         return $country;
647 647
     }
648 648
     
649 649
     private function setup_state() {
650
-        $state = $this->get_meta( '_wpinv_state', true );
650
+        $state = $this->get_meta('_wpinv_state', true);
651 651
         return $state;
652 652
     }
653 653
     
654 654
     private function setup_zip() {
655
-        $zip = $this->get_meta( '_wpinv_zip', true );
655
+        $zip = $this->get_meta('_wpinv_zip', true);
656 656
         return $zip;
657 657
     }
658 658
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
             'user_id'        => $this->user_id,
662 662
             'first_name'     => $this->first_name,
663 663
             'last_name'      => $this->last_name,
664
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
664
+            'email'          => get_the_author_meta('email', $this->user_id),
665 665
             'phone'          => $this->phone,
666 666
             'address'        => $this->address,
667 667
             'city'           => $this->city,
@@ -676,12 +676,12 @@  discard block
 block discarded – undo
676 676
         );
677 677
         
678 678
         $user_info = array();
679
-        if ( isset( $this->payment_meta['user_info'] ) ) {
680
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
679
+        if (isset($this->payment_meta['user_info'])) {
680
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
681 681
             
682
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
682
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
683 683
                 $this->user_id = $post->post_author;
684
-                $this->email = get_the_author_meta( 'email', $this->user_id );
684
+                $this->email = get_the_author_meta('email', $this->user_id);
685 685
                 
686 686
                 $user_info['user_id'] = $this->user_id;
687 687
                 $user_info['email'] = $this->email;
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
             }
691 691
         }
692 692
         
693
-        $user_info    = wp_parse_args( $user_info, $defaults );
693
+        $user_info = wp_parse_args($user_info, $defaults);
694 694
         
695 695
         // Get the user, but only if it's been created
696
-        $user = get_userdata( $this->user_id );
696
+        $user = get_userdata($this->user_id);
697 697
         
698
-        if ( !empty( $user ) && $user->ID > 0 ) {
699
-            if ( empty( $user_info ) ) {
698
+        if (!empty($user) && $user->ID > 0) {
699
+            if (empty($user_info)) {
700 700
                 $user_info = array(
701 701
                     'user_id'    => $user->ID,
702 702
                     'first_name' => $user->first_name,
@@ -705,23 +705,23 @@  discard block
 block discarded – undo
705 705
                     'discount'   => '',
706 706
                 );
707 707
             } else {
708
-                foreach ( $user_info as $key => $value ) {
709
-                    if ( ! empty( $value ) ) {
708
+                foreach ($user_info as $key => $value) {
709
+                    if (!empty($value)) {
710 710
                         continue;
711 711
                     }
712 712
 
713
-                    switch( $key ) {
713
+                    switch ($key) {
714 714
                         case 'user_id':
715
-                            $user_info[ $key ] = $user->ID;
715
+                            $user_info[$key] = $user->ID;
716 716
                             break;
717 717
                         case 'first_name':
718
-                            $user_info[ $key ] = $user->first_name;
718
+                            $user_info[$key] = $user->first_name;
719 719
                             break;
720 720
                         case 'last_name':
721
-                            $user_info[ $key ] = $user->last_name;
721
+                            $user_info[$key] = $user->last_name;
722 722
                             break;
723 723
                         case 'email':
724
-                            $user_info[ $key ] = $user->user_email;
724
+                            $user_info[$key] = $user->user_email;
725 725
                             break;
726 726
                     }
727 727
                 }
@@ -732,25 +732,25 @@  discard block
 block discarded – undo
732 732
     }
733 733
 
734 734
     private function setup_invoice_key() {
735
-        $key = $this->get_meta( '_wpinv_key', true );
735
+        $key = $this->get_meta('_wpinv_key', true);
736 736
         
737 737
         return $key;
738 738
     }
739 739
 
740 740
     private function setup_invoice_number() {
741
-        $number = $this->get_meta( '_wpinv_number', true );
741
+        $number = $this->get_meta('_wpinv_number', true);
742 742
 
743
-        if ( !$number ) {
743
+        if (!$number) {
744 744
             $number = $this->ID;
745 745
 
746
-            if ( $this->status == 'auto-draft' ) {
747
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
748
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
746
+            if ($this->status == 'auto-draft') {
747
+                if (wpinv_sequential_number_active($this->post_type)) {
748
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
749 749
                     $number      = $next_number;
750 750
                 }
751 751
             }
752 752
             
753
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
753
+            $number = wpinv_format_invoice_number($number, $this->post_type);
754 754
         }
755 755
 
756 756
         return $number;
@@ -759,10 +759,10 @@  discard block
 block discarded – undo
759 759
     private function insert_invoice() {
760 760
         global $wpdb;
761 761
 
762
-        if ( empty( $this->post_type ) ) {
763
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
762
+        if (empty($this->post_type)) {
763
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
764 764
                 $this->post_type = $post_type;
765
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
765
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
766 766
                 $this->post_type = $post_type;
767 767
             } else {
768 768
                 $this->post_type = 'wpi_invoice';
@@ -770,16 +770,16 @@  discard block
 block discarded – undo
770 770
         }
771 771
 
772 772
         $invoice_number = $this->ID;
773
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
773
+        if ($number = $this->get_meta('_wpinv_number', true)) {
774 774
             $invoice_number = $number;
775 775
         }
776 776
 
777
-        if ( empty( $this->key ) ) {
777
+        if (empty($this->key)) {
778 778
             $this->key = self::generate_key();
779 779
             $this->pending['key'] = $this->key;
780 780
         }
781 781
 
782
-        if ( empty( $this->ip ) ) {
782
+        if (empty($this->ip)) {
783 783
             $this->ip = wpinv_get_ip();
784 784
             $this->pending['ip'] = $this->ip;
785 785
         }
@@ -816,60 +816,60 @@  discard block
 block discarded – undo
816 816
                         'post_status'   => $this->status,
817 817
                         'post_author'   => $this->user_id,
818 818
                         'post_type'     => $this->post_type,
819
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
820
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
819
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
820
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
821 821
                         'post_parent'   => $this->parent_invoice,
822 822
                     );
823
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
823
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
824 824
 
825 825
         // Create a blank invoice
826
-        if ( !empty( $this->ID ) ) {
827
-            $args['ID']         = $this->ID;
826
+        if (!empty($this->ID)) {
827
+            $args['ID'] = $this->ID;
828 828
 
829
-            $invoice_id = wp_update_post( $args, true );
829
+            $invoice_id = wp_update_post($args, true);
830 830
         } else {
831
-            $invoice_id = wp_insert_post( $args, true );
831
+            $invoice_id = wp_insert_post($args, true);
832 832
         }
833 833
 
834
-        if ( is_wp_error( $invoice_id ) ) {
834
+        if (is_wp_error($invoice_id)) {
835 835
             return false;
836 836
         }
837 837
 
838
-        if ( !empty( $invoice_id ) ) {
838
+        if (!empty($invoice_id)) {
839 839
             $this->ID  = $invoice_id;
840 840
             $this->_ID = $invoice_id;
841 841
 
842
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
843
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
844
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
845
-                foreach( $this->fees as $fee ) {
846
-                    $this->increase_fees( $fee['amount'] );
842
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
843
+            if (!empty($this->payment_meta['fees'])) {
844
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
845
+                foreach ($this->fees as $fee) {
846
+                    $this->increase_fees($fee['amount']);
847 847
                 }
848 848
             }
849 849
 
850
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );    
850
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);    
851 851
             $this->new = true;
852 852
         }
853 853
 
854 854
         return $this->ID;
855 855
     }
856 856
 
857
-    public function save( $setup = false ) {
857
+    public function save($setup = false) {
858 858
         
859 859
         $saved = false;
860
-        if ( empty( $this->items ) ) {
860
+        if (empty($this->items)) {
861 861
             return $saved; // Don't save empty invoice.
862 862
         }
863 863
         
864
-        if ( empty( $this->key ) ) {
864
+        if (empty($this->key)) {
865 865
             $this->key = self::generate_key();
866 866
             $this->pending['key'] = $this->key;
867 867
         }
868 868
         
869
-        if ( empty( $this->ID ) ) {
869
+        if (empty($this->ID)) {
870 870
             $invoice_id = $this->insert_invoice();
871 871
 
872
-            if ( false === $invoice_id ) {
872
+            if (false === $invoice_id) {
873 873
                 $saved = false;
874 874
             } else {
875 875
                 $this->ID = $invoice_id;
@@ -877,27 +877,27 @@  discard block
 block discarded – undo
877 877
         }
878 878
 
879 879
         // If we have something pending, let's save it
880
-        if ( !empty( $this->pending ) ) {
880
+        if (!empty($this->pending)) {
881 881
             $total_increase = 0;
882 882
             $total_decrease = 0;
883 883
 
884
-            foreach ( $this->pending as $key => $value ) {
885
-                switch( $key ) {
884
+            foreach ($this->pending as $key => $value) {
885
+                switch ($key) {
886 886
                     case 'items':
887 887
                         // Update totals for pending items
888
-                        foreach ( $this->pending[ $key ] as $item ) {
889
-                            switch( $item['action'] ) {
888
+                        foreach ($this->pending[$key] as $item) {
889
+                            switch ($item['action']) {
890 890
                                 case 'add':
891 891
                                     $price = $item['price'];
892 892
                                     $taxes = $item['tax'];
893 893
 
894
-                                    if ( 'publish' === $this->status ) {
894
+                                    if ('publish' === $this->status) {
895 895
                                         $total_increase += $price;
896 896
                                     }
897 897
                                     break;
898 898
 
899 899
                                 case 'remove':
900
-                                    if ( 'publish' === $this->status ) {
900
+                                    if ('publish' === $this->status) {
901 901
                                         $total_decrease += $item['price'];
902 902
                                     }
903 903
                                     break;
@@ -905,16 +905,16 @@  discard block
 block discarded – undo
905 905
                         }
906 906
                         break;
907 907
                     case 'fees':
908
-                        if ( 'publish' !== $this->status ) {
908
+                        if ('publish' !== $this->status) {
909 909
                             break;
910 910
                         }
911 911
 
912
-                        if ( empty( $this->pending[ $key ] ) ) {
912
+                        if (empty($this->pending[$key])) {
913 913
                             break;
914 914
                         }
915 915
 
916
-                        foreach ( $this->pending[ $key ] as $fee ) {
917
-                            switch( $fee['action'] ) {
916
+                        foreach ($this->pending[$key] as $fee) {
917
+                            switch ($fee['action']) {
918 918
                                 case 'add':
919 919
                                     $total_increase += $fee['amount'];
920 920
                                     break;
@@ -926,86 +926,86 @@  discard block
 block discarded – undo
926 926
                         }
927 927
                         break;
928 928
                     case 'status':
929
-                        $this->update_status( $this->status );
929
+                        $this->update_status($this->status);
930 930
                         break;
931 931
                     case 'gateway':
932
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
932
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
933 933
                         break;
934 934
                     case 'mode':
935
-                        $this->update_meta( '_wpinv_mode', $this->mode );
935
+                        $this->update_meta('_wpinv_mode', $this->mode);
936 936
                         break;
937 937
                     case 'transaction_id':
938
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
938
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
939 939
                         break;
940 940
                     case 'ip':
941
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
941
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
942 942
                         break;
943 943
                     ///case 'user_id':
944 944
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
945 945
                         ///$this->user_info['user_id'] = $this->user_id;
946 946
                         ///break;
947 947
                     case 'first_name':
948
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
948
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
949 949
                         $this->user_info['first_name'] = $this->first_name;
950 950
                         break;
951 951
                     case 'last_name':
952
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
952
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
953 953
                         $this->user_info['last_name'] = $this->last_name;
954 954
                         break;
955 955
                     case 'phone':
956
-                        $this->update_meta( '_wpinv_phone', $this->phone );
956
+                        $this->update_meta('_wpinv_phone', $this->phone);
957 957
                         $this->user_info['phone'] = $this->phone;
958 958
                         break;
959 959
                     case 'address':
960
-                        $this->update_meta( '_wpinv_address', $this->address );
960
+                        $this->update_meta('_wpinv_address', $this->address);
961 961
                         $this->user_info['address'] = $this->address;
962 962
                         break;
963 963
                     case 'city':
964
-                        $this->update_meta( '_wpinv_city', $this->city );
964
+                        $this->update_meta('_wpinv_city', $this->city);
965 965
                         $this->user_info['city'] = $this->city;
966 966
                         break;
967 967
                     case 'country':
968
-                        $this->update_meta( '_wpinv_country', $this->country );
968
+                        $this->update_meta('_wpinv_country', $this->country);
969 969
                         $this->user_info['country'] = $this->country;
970 970
                         break;
971 971
                     case 'state':
972
-                        $this->update_meta( '_wpinv_state', $this->state );
972
+                        $this->update_meta('_wpinv_state', $this->state);
973 973
                         $this->user_info['state'] = $this->state;
974 974
                         break;
975 975
                     case 'zip':
976
-                        $this->update_meta( '_wpinv_zip', $this->zip );
976
+                        $this->update_meta('_wpinv_zip', $this->zip);
977 977
                         $this->user_info['zip'] = $this->zip;
978 978
                         break;
979 979
                     case 'company':
980
-                        $this->update_meta( '_wpinv_company', $this->company );
980
+                        $this->update_meta('_wpinv_company', $this->company);
981 981
                         $this->user_info['company'] = $this->company;
982 982
                         break;
983 983
                     case 'vat_number':
984
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
984
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
985 985
                         $this->user_info['vat_number'] = $this->vat_number;
986 986
                         
987
-                        $vat_info = getpaid_session()->get( 'user_vat_data' );
988
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
989
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
990
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
991
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
987
+                        $vat_info = getpaid_session()->get('user_vat_data');
988
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
989
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
990
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
991
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
992 992
                         }
993 993
     
994 994
                         break;
995 995
                     case 'vat_rate':
996
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
996
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
997 997
                         $this->user_info['vat_rate'] = $this->vat_rate;
998 998
                         break;
999 999
                     case 'adddress_confirmed':
1000
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
1000
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
1001 1001
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
1002 1002
                         break;
1003 1003
                     
1004 1004
                     case 'key':
1005
-                        $this->update_meta( '_wpinv_key', $this->key );
1005
+                        $this->update_meta('_wpinv_key', $this->key);
1006 1006
                         break;
1007 1007
                     case 'disable_taxes':
1008
-                        $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes );
1008
+                        $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes);
1009 1009
                         break;
1010 1010
                     case 'date':
1011 1011
                         $args = array(
@@ -1014,49 +1014,49 @@  discard block
 block discarded – undo
1014 1014
                             'edit_date' => true,
1015 1015
                         );
1016 1016
 
1017
-                        wp_update_post( $args );
1017
+                        wp_update_post($args);
1018 1018
                         break;
1019 1019
                     case 'due_date':
1020
-                        if ( empty( $this->due_date ) ) {
1020
+                        if (empty($this->due_date)) {
1021 1021
                             $this->due_date = 'none';
1022 1022
                         }
1023 1023
                         
1024
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
1024
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
1025 1025
                         break;
1026 1026
                     case 'completed_date':
1027
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
1027
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
1028 1028
                         break;
1029 1029
                     case 'discounts':
1030
-                        if ( ! is_array( $this->discounts ) ) {
1031
-                            $this->discounts = explode( ',', $this->discounts );
1030
+                        if (!is_array($this->discounts)) {
1031
+                            $this->discounts = explode(',', $this->discounts);
1032 1032
                         }
1033 1033
 
1034
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
1034
+                        $this->user_info['discount'] = implode(',', $this->discounts);
1035 1035
                         break;
1036 1036
                     case 'discount':
1037
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
1037
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
1038 1038
                         break;
1039 1039
                     case 'discount_code':
1040
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
1040
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
1041 1041
                         break;
1042 1042
                     case 'parent_invoice':
1043 1043
                         $args = array(
1044 1044
                             'ID'          => $this->ID,
1045 1045
                             'post_parent' => $this->parent_invoice,
1046 1046
                         );
1047
-                        wp_update_post( $args );
1047
+                        wp_update_post($args);
1048 1048
                         break;
1049 1049
                     default:
1050
-                        do_action( 'wpinv_save', $this, $key );
1050
+                        do_action('wpinv_save', $this, $key);
1051 1051
                         break;
1052 1052
                 }
1053 1053
             }
1054 1054
 
1055
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1056
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1057
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1055
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1056
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1057
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1058 1058
             
1059
-            $this->items    = array_values( $this->items );
1059
+            $this->items = array_values($this->items);
1060 1060
             
1061 1061
             $new_meta = array(
1062 1062
                 'items'         => $this->items,
@@ -1067,12 +1067,12 @@  discard block
 block discarded – undo
1067 1067
             );
1068 1068
             
1069 1069
             $meta        = $this->get_meta();
1070
-            $merged_meta = array_merge( $meta, $new_meta );
1070
+            $merged_meta = array_merge($meta, $new_meta);
1071 1071
 
1072 1072
             // Only save the payment meta if it's changed
1073
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
1074
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
1075
-                if ( false !== $updated ) {
1073
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
1074
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
1075
+                if (false !== $updated) {
1076 1076
                     $saved = true;
1077 1077
                 }
1078 1078
             }
@@ -1080,15 +1080,15 @@  discard block
 block discarded – undo
1080 1080
             $this->pending = array();
1081 1081
             $saved         = true;
1082 1082
         } else {
1083
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1084
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1085
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1083
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1084
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1085
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1086 1086
         }
1087 1087
         
1088
-        do_action( 'wpinv_invoice_save', $this, $saved );
1088
+        do_action('wpinv_invoice_save', $this, $saved);
1089 1089
 
1090
-        if ( true === $saved || $setup ) {
1091
-            $this->setup_invoice( $this->ID );
1090
+        if (true === $saved || $setup) {
1091
+            $this->setup_invoice($this->ID);
1092 1092
         }
1093 1093
         
1094 1094
         $this->refresh_item_ids();
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
         return $saved;
1097 1097
     }
1098 1098
     
1099
-    public function add_fee( $args, $global = true ) {
1099
+    public function add_fee($args, $global = true) {
1100 1100
         $default_args = array(
1101 1101
             'label'       => '',
1102 1102
             'amount'      => 0,
@@ -1106,75 +1106,75 @@  discard block
 block discarded – undo
1106 1106
             'item_id'     => 0,
1107 1107
         );
1108 1108
 
1109
-        $fee = wp_parse_args( $args, $default_args );
1109
+        $fee = wp_parse_args($args, $default_args);
1110 1110
         
1111
-        if ( empty( $fee['label'] ) ) {
1111
+        if (empty($fee['label'])) {
1112 1112
             return false;
1113 1113
         }
1114 1114
         
1115
-        $fee['id']  = sanitize_title( $fee['label'] );
1115
+        $fee['id'] = sanitize_title($fee['label']);
1116 1116
         
1117
-        $this->fees[]               = $fee;
1117
+        $this->fees[] = $fee;
1118 1118
         
1119 1119
         $added_fee               = $fee;
1120 1120
         $added_fee['action']     = 'add';
1121 1121
         $this->pending['fees'][] = $added_fee;
1122
-        reset( $this->fees );
1122
+        reset($this->fees);
1123 1123
 
1124
-        $this->increase_fees( $fee['amount'] );
1124
+        $this->increase_fees($fee['amount']);
1125 1125
         return true;
1126 1126
     }
1127 1127
 
1128
-    public function remove_fee( $key ) {
1128
+    public function remove_fee($key) {
1129 1129
         $removed = false;
1130 1130
 
1131
-        if ( is_numeric( $key ) ) {
1132
-            $removed = $this->remove_fee_by( 'index', $key );
1131
+        if (is_numeric($key)) {
1132
+            $removed = $this->remove_fee_by('index', $key);
1133 1133
         }
1134 1134
 
1135 1135
         return $removed;
1136 1136
     }
1137 1137
 
1138
-    public function remove_fee_by( $key, $value, $global = false ) {
1139
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
1138
+    public function remove_fee_by($key, $value, $global = false) {
1139
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
1140 1140
             'index', 'label', 'amount', 'type',
1141
-        ) );
1141
+        ));
1142 1142
 
1143
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
1143
+        if (!in_array($key, $allowed_fee_keys)) {
1144 1144
             return false;
1145 1145
         }
1146 1146
 
1147 1147
         $removed = false;
1148
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
1149
-            $removed_fee             = $this->fees[ $value ];
1148
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
1149
+            $removed_fee             = $this->fees[$value];
1150 1150
             $removed_fee['action']   = 'remove';
1151 1151
             $this->pending['fees'][] = $removed_fee;
1152 1152
 
1153
-            $this->decrease_fees( $removed_fee['amount'] );
1153
+            $this->decrease_fees($removed_fee['amount']);
1154 1154
 
1155
-            unset( $this->fees[ $value ] );
1155
+            unset($this->fees[$value]);
1156 1156
             $removed = true;
1157
-        } else if ( 'index' !== $key ) {
1158
-            foreach ( $this->fees as $index => $fee ) {
1159
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
1157
+        } else if ('index' !== $key) {
1158
+            foreach ($this->fees as $index => $fee) {
1159
+                if (isset($fee[$key]) && $fee[$key] == $value) {
1160 1160
                     $removed_fee             = $fee;
1161 1161
                     $removed_fee['action']   = 'remove';
1162 1162
                     $this->pending['fees'][] = $removed_fee;
1163 1163
 
1164
-                    $this->decrease_fees( $removed_fee['amount'] );
1164
+                    $this->decrease_fees($removed_fee['amount']);
1165 1165
 
1166
-                    unset( $this->fees[ $index ] );
1166
+                    unset($this->fees[$index]);
1167 1167
                     $removed = true;
1168 1168
 
1169
-                    if ( false === $global ) {
1169
+                    if (false === $global) {
1170 1170
                         break;
1171 1171
                     }
1172 1172
                 }
1173 1173
             }
1174 1174
         }
1175 1175
 
1176
-        if ( true === $removed ) {
1177
-            $this->fees = array_values( $this->fees );
1176
+        if (true === $removed) {
1177
+            $this->fees = array_values($this->fees);
1178 1178
         }
1179 1179
 
1180 1180
         return $removed;
@@ -1182,35 +1182,35 @@  discard block
 block discarded – undo
1182 1182
 
1183 1183
     
1184 1184
 
1185
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
1185
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
1186 1186
         // Bail if no note specified
1187
-        if( !$note ) {
1187
+        if (!$note) {
1188 1188
             return false;
1189 1189
         }
1190 1190
 
1191
-        if ( empty( $this->ID ) )
1191
+        if (empty($this->ID))
1192 1192
             return false;
1193 1193
         
1194
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
1195
-            $user                 = get_user_by( 'id', get_current_user_id() );
1194
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
1195
+            $user                 = get_user_by('id', get_current_user_id());
1196 1196
             $comment_author       = $user->display_name;
1197 1197
             $comment_author_email = $user->user_email;
1198 1198
         } else {
1199 1199
             $comment_author       = 'System';
1200 1200
             $comment_author_email = 'system@';
1201
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
1202
-            $comment_author_email = sanitize_email( $comment_author_email );
1201
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
1202
+            $comment_author_email = sanitize_email($comment_author_email);
1203 1203
         }
1204 1204
 
1205
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
1205
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
1206 1206
 
1207
-        $note_id = wp_insert_comment( wp_filter_comment( array(
1207
+        $note_id = wp_insert_comment(wp_filter_comment(array(
1208 1208
             'comment_post_ID'      => $this->ID,
1209 1209
             'comment_content'      => $note,
1210 1210
             'comment_agent'        => 'WPInvoicing',
1211 1211
             'user_id'              => is_admin() ? get_current_user_id() : 0,
1212
-            'comment_date'         => current_time( 'mysql' ),
1213
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
1212
+            'comment_date'         => current_time('mysql'),
1213
+            'comment_date_gmt'     => current_time('mysql', 1),
1214 1214
             'comment_approved'     => 1,
1215 1215
             'comment_parent'       => 0,
1216 1216
             'comment_author'       => $comment_author,
@@ -1218,53 +1218,53 @@  discard block
 block discarded – undo
1218 1218
             'comment_author_url'   => '',
1219 1219
             'comment_author_email' => $comment_author_email,
1220 1220
             'comment_type'         => 'wpinv_note'
1221
-        ) ) );
1221
+        )));
1222 1222
 
1223
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1223
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1224 1224
         
1225
-        if ( $customer_type ) {
1226
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1225
+        if ($customer_type) {
1226
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1227 1227
 
1228
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1228
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1229 1229
         }
1230 1230
 
1231 1231
         return $note_id;
1232 1232
     }
1233 1233
 
1234
-    private function increase_subtotal( $amount = 0.00 ) {
1234
+    private function increase_subtotal($amount = 0.00) {
1235 1235
         $amount          = (float) $amount;
1236 1236
         $this->subtotal += $amount;
1237
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1237
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1238 1238
 
1239 1239
         $this->recalculate_total();
1240 1240
     }
1241 1241
 
1242
-    private function decrease_subtotal( $amount = 0.00 ) {
1242
+    private function decrease_subtotal($amount = 0.00) {
1243 1243
         $amount          = (float) $amount;
1244 1244
         $this->subtotal -= $amount;
1245
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1245
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1246 1246
 
1247
-        if ( $this->subtotal < 0 ) {
1247
+        if ($this->subtotal < 0) {
1248 1248
             $this->subtotal = 0;
1249 1249
         }
1250 1250
 
1251 1251
         $this->recalculate_total();
1252 1252
     }
1253 1253
 
1254
-    private function increase_fees( $amount = 0.00 ) {
1255
-        $amount            = (float)$amount;
1254
+    private function increase_fees($amount = 0.00) {
1255
+        $amount            = (float) $amount;
1256 1256
         $this->fees_total += $amount;
1257
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1257
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1258 1258
 
1259 1259
         $this->recalculate_total();
1260 1260
     }
1261 1261
 
1262
-    private function decrease_fees( $amount = 0.00 ) {
1262
+    private function decrease_fees($amount = 0.00) {
1263 1263
         $amount            = (float) $amount;
1264 1264
         $this->fees_total -= $amount;
1265
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1265
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1266 1266
 
1267
-        if ( $this->fees_total < 0 ) {
1267
+        if ($this->fees_total < 0) {
1268 1268
             $this->fees_total = 0;
1269 1269
         }
1270 1270
 
@@ -1275,54 +1275,54 @@  discard block
 block discarded – undo
1275 1275
         global $wpi_nosave;
1276 1276
         
1277 1277
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1278
-        $this->total = wpinv_round_amount( $this->total );
1278
+        $this->total = wpinv_round_amount($this->total);
1279 1279
         
1280
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1280
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1281 1281
     }
1282 1282
     
1283
-    public function increase_tax( $amount = 0.00 ) {
1283
+    public function increase_tax($amount = 0.00) {
1284 1284
         $amount       = (float) $amount;
1285 1285
         $this->tax   += $amount;
1286 1286
 
1287 1287
         $this->recalculate_total();
1288 1288
     }
1289 1289
 
1290
-    public function decrease_tax( $amount = 0.00 ) {
1290
+    public function decrease_tax($amount = 0.00) {
1291 1291
         $amount     = (float) $amount;
1292 1292
         $this->tax -= $amount;
1293 1293
 
1294
-        if ( $this->tax < 0 ) {
1294
+        if ($this->tax < 0) {
1295 1295
             $this->tax = 0;
1296 1296
         }
1297 1297
 
1298 1298
         $this->recalculate_total();
1299 1299
     }
1300 1300
 
1301
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1302
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1301
+    public function update_status($new_status = false, $note = '', $manual = false) {
1302
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1303 1303
 
1304
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1304
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1305 1305
             return false; // Don't permit status changes that aren't changes
1306 1306
         }
1307 1307
 
1308
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1308
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1309 1309
         $updated = false;
1310 1310
 
1311
-        if ( $do_change ) {
1312
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1311
+        if ($do_change) {
1312
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1313 1313
 
1314 1314
             $update_post_data                   = array();
1315 1315
             $update_post_data['ID']             = $this->ID;
1316 1316
             $update_post_data['post_status']    = $new_status;
1317
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1318
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1317
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1318
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1319 1319
             
1320
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1320
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1321 1321
 
1322
-            $updated = wp_update_post( $update_post_data );     
1322
+            $updated = wp_update_post($update_post_data);     
1323 1323
            
1324 1324
             // Process any specific status functions
1325
-            switch( $new_status ) {
1325
+            switch ($new_status) {
1326 1326
                 case 'wpi-refunded':
1327 1327
                     $this->process_refund();
1328 1328
                     break;
@@ -1335,9 +1335,9 @@  discard block
 block discarded – undo
1335 1335
             }
1336 1336
             
1337 1337
             // Status was changed.
1338
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1339
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1340
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1338
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1339
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1340
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1341 1341
         }
1342 1342
 
1343 1343
         return $updated;
@@ -1351,20 +1351,20 @@  discard block
 block discarded – undo
1351 1351
         $this->save();
1352 1352
     }
1353 1353
 
1354
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1355
-        if ( empty( $meta_key ) ) {
1354
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1355
+        if (empty($meta_key)) {
1356 1356
             return false;
1357 1357
         }
1358 1358
 
1359
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1359
+        if ($meta_key == 'key' || $meta_key == 'date') {
1360 1360
             $current_meta = $this->get_meta();
1361
-            $current_meta[ $meta_key ] = $meta_value;
1361
+            $current_meta[$meta_key] = $meta_value;
1362 1362
 
1363 1363
             $meta_key     = '_wpinv_payment_meta';
1364 1364
             $meta_value   = $current_meta;
1365 1365
         }
1366 1366
 
1367
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1367
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1368 1368
         
1369 1369
         // Do not update created date on invoice marked as paid.
1370 1370
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1379,45 +1379,45 @@  discard block
 block discarded – undo
1379 1379
             wp_update_post( $args );
1380 1380
         }*/
1381 1381
         
1382
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1382
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1383 1383
     }
1384 1384
 
1385 1385
     private function process_refund() {
1386 1386
         $process_refund = true;
1387 1387
 
1388 1388
         // If the payment was not in publish, don't decrement stats as they were never incremented
1389
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1389
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1390 1390
             $process_refund = false;
1391 1391
         }
1392 1392
 
1393 1393
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1394
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1394
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1395 1395
 
1396
-        if ( false === $process_refund ) {
1396
+        if (false === $process_refund) {
1397 1397
             return;
1398 1398
         }
1399 1399
 
1400
-        do_action( 'wpinv_pre_refund_invoice', $this );
1400
+        do_action('wpinv_pre_refund_invoice', $this);
1401 1401
         
1402
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1403
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1404
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1402
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1403
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1404
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1405 1405
         
1406
-        do_action( 'wpinv_post_refund_invoice', $this );
1406
+        do_action('wpinv_post_refund_invoice', $this);
1407 1407
     }
1408 1408
 
1409 1409
     private function process_failure() {
1410 1410
         $discounts = $this->discounts;
1411
-        if ( empty( $discounts ) ) {
1411
+        if (empty($discounts)) {
1412 1412
             return;
1413 1413
         }
1414 1414
 
1415
-        if ( ! is_array( $discounts ) ) {
1416
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1415
+        if (!is_array($discounts)) {
1416
+            $discounts = array_map('trim', explode(',', $discounts));
1417 1417
         }
1418 1418
 
1419
-        foreach ( $discounts as $discount ) {
1420
-            wpinv_decrease_discount_usage( $discount );
1419
+        foreach ($discounts as $discount) {
1420
+            wpinv_decrease_discount_usage($discount);
1421 1421
         }
1422 1422
     }
1423 1423
     
@@ -1425,92 +1425,92 @@  discard block
 block discarded – undo
1425 1425
         $process_pending = true;
1426 1426
 
1427 1427
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1428
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1428
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1429 1429
             $process_pending = false;
1430 1430
         }
1431 1431
 
1432 1432
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1433
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1433
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1434 1434
 
1435
-        if ( false === $process_pending ) {
1435
+        if (false === $process_pending) {
1436 1436
             return;
1437 1437
         }
1438 1438
 
1439
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1440
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1441
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1439
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1440
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1441
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1442 1442
 
1443 1443
         $this->completed_date = '';
1444
-        $this->update_meta( '_wpinv_completed_date', '' );
1444
+        $this->update_meta('_wpinv_completed_date', '');
1445 1445
     }
1446 1446
     
1447 1447
     // get data
1448
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1449
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1448
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1449
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1450 1450
 
1451
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1451
+        if ($meta_key === '_wpinv_payment_meta') {
1452 1452
 
1453
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1453
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1454 1454
 
1455
-            if ( empty( $meta['key'] ) ) {
1455
+            if (empty($meta['key'])) {
1456 1456
                 $meta['key'] = $this->setup_invoice_key();
1457 1457
             }
1458 1458
 
1459
-            if ( empty( $meta['date'] ) ) {
1460
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1459
+            if (empty($meta['date'])) {
1460
+                $meta['date'] = get_post_field('post_date', $this->ID);
1461 1461
             }
1462 1462
         }
1463 1463
 
1464
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1464
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1465 1465
 
1466
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1466
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1467 1467
     }
1468 1468
     
1469 1469
     public function get_description() {
1470
-        $post = get_post( $this->ID );
1470
+        $post = get_post($this->ID);
1471 1471
         
1472
-        $description = !empty( $post ) ? $post->post_content : '';
1473
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1472
+        $description = !empty($post) ? $post->post_content : '';
1473
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1474 1474
     }
1475 1475
     
1476
-    public function get_status( $nicename = false ) {
1477
-        if ( !$nicename ) {
1476
+    public function get_status($nicename = false) {
1477
+        if (!$nicename) {
1478 1478
             $status = $this->status;
1479 1479
         } else {
1480 1480
             $status = $this->status_nicename;
1481 1481
         }
1482 1482
         
1483
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1483
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_cart_details() {
1487
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1487
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490
-    public function get_subtotal( $currency = false ) {
1491
-        $subtotal = wpinv_round_amount( $this->subtotal );
1490
+    public function get_subtotal($currency = false) {
1491
+        $subtotal = wpinv_round_amount($this->subtotal);
1492 1492
         
1493
-        if ( $currency ) {
1494
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1493
+        if ($currency) {
1494
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1495 1495
         }
1496 1496
         
1497
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1497
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1498 1498
     }
1499 1499
     
1500
-    public function get_total( $currency = false ) {        
1501
-        if ( $this->is_free_trial() ) {
1502
-            $total = wpinv_round_amount( 0 );
1500
+    public function get_total($currency = false) {        
1501
+        if ($this->is_free_trial()) {
1502
+            $total = wpinv_round_amount(0);
1503 1503
         } else {
1504
-            $total = wpinv_round_amount( $this->total );
1504
+            $total = wpinv_round_amount($this->total);
1505 1505
         }
1506
-        if ( $currency ) {
1507
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1506
+        if ($currency) {
1507
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1508 1508
         }
1509 1509
         
1510
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1510
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1511 1511
     }
1512 1512
     
1513
-    public function get_recurring_details( $field = '', $currency = false ) {        
1513
+    public function get_recurring_details($field = '', $currency = false) {        
1514 1514
         $data                 = array();
1515 1515
         $data['cart_details'] = $this->cart_details;
1516 1516
         $data['subtotal']     = $this->get_subtotal();
@@ -1518,119 +1518,119 @@  discard block
 block discarded – undo
1518 1518
         $data['tax']          = $this->get_tax();
1519 1519
         $data['total']        = $this->get_total();
1520 1520
     
1521
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1521
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1522 1522
             $is_free_trial = $this->is_free_trial();
1523
-            $discounts = $this->get_discounts( true );
1523
+            $discounts = $this->get_discounts(true);
1524 1524
             
1525
-            if ( $is_free_trial || !empty( $discounts ) ) {
1525
+            if ($is_free_trial || !empty($discounts)) {
1526 1526
                 $first_use_only = false;
1527 1527
                 
1528
-                if ( !empty( $discounts ) ) {
1529
-                    foreach ( $discounts as $key => $code ) {
1530
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1528
+                if (!empty($discounts)) {
1529
+                    foreach ($discounts as $key => $code) {
1530
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1531 1531
                             $first_use_only = true;
1532 1532
                             break;
1533 1533
                         }
1534 1534
                     }
1535 1535
                 }
1536 1536
                     
1537
-                if ( !$first_use_only ) {
1538
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1539
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1540
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1541
-                    $data['total']    = wpinv_round_amount( $this->total );
1537
+                if (!$first_use_only) {
1538
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1539
+                    $data['discount'] = wpinv_round_amount($this->discount);
1540
+                    $data['tax']      = wpinv_round_amount($this->tax);
1541
+                    $data['total']    = wpinv_round_amount($this->total);
1542 1542
                 } else {
1543 1543
                     $cart_subtotal   = 0;
1544 1544
                     $cart_discount   = $this->discount;
1545 1545
                     $cart_tax        = 0;
1546 1546
 
1547
-                    foreach ( $this->cart_details as $key => $item ) {
1548
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1549
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1547
+                    foreach ($this->cart_details as $key => $item) {
1548
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1549
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1550 1550
                         $item_discount  = 0;
1551
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1551
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1552 1552
                         
1553
-                        if ( wpinv_prices_include_tax() ) {
1554
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1553
+                        if (wpinv_prices_include_tax()) {
1554
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1555 1555
                         }
1556 1556
                         
1557 1557
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1558 1558
                         // Do not allow totals to go negative
1559
-                        if ( $item_total < 0 ) {
1559
+                        if ($item_total < 0) {
1560 1560
                             $item_total = 0;
1561 1561
                         }
1562 1562
                         
1563
-                        $cart_subtotal  += (float)($item_subtotal);
1564
-                        $cart_discount  += (float)($item_discount);
1565
-                        $cart_tax       += (float)($item_tax);
1563
+                        $cart_subtotal  += (float) ($item_subtotal);
1564
+                        $cart_discount  += (float) ($item_discount);
1565
+                        $cart_tax       += (float) ($item_tax);
1566 1566
                         
1567
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1568
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1569
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1567
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1568
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1569
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1570 1570
                     }
1571 1571
 
1572 1572
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1573
-	                if ( $total < 0 ) {
1573
+	                if ($total < 0) {
1574 1574
 		                $total = 0;
1575 1575
 	                }
1576 1576
 
1577
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1578
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1579
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1580
-                    $data['total']    = wpinv_round_amount( $total );
1577
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1578
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1579
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1580
+                    $data['total']    = wpinv_round_amount($total);
1581 1581
                 }
1582 1582
             }
1583 1583
         }
1584 1584
         
1585
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1585
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1586 1586
 
1587
-        if ( isset( $data[$field] ) ) {
1588
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1587
+        if (isset($data[$field])) {
1588
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1589 1589
         }
1590 1590
         
1591 1591
         return $data;
1592 1592
     }
1593 1593
     
1594
-    public function get_final_tax( $currency = false ) {        
1595
-        $final_total = wpinv_round_amount( $this->tax );
1596
-        if ( $currency ) {
1597
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1594
+    public function get_final_tax($currency = false) {        
1595
+        $final_total = wpinv_round_amount($this->tax);
1596
+        if ($currency) {
1597
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1598 1598
         }
1599 1599
         
1600
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1600
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1601 1601
     }
1602 1602
     
1603
-    public function get_discounts( $array = false ) {
1603
+    public function get_discounts($array = false) {
1604 1604
         $discounts = $this->discounts;
1605
-        if ( $array && $discounts ) {
1606
-            $discounts = explode( ',', $discounts );
1605
+        if ($array && $discounts) {
1606
+            $discounts = explode(',', $discounts);
1607 1607
         }
1608
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1608
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1609 1609
     }
1610 1610
     
1611
-    public function get_discount( $currency = false, $dash = false ) {
1612
-        if ( !empty( $this->discounts ) ) {
1611
+    public function get_discount($currency = false, $dash = false) {
1612
+        if (!empty($this->discounts)) {
1613 1613
             global $ajax_cart_details;
1614 1614
             $ajax_cart_details = $this->get_cart_details();
1615 1615
             
1616
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1616
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1617 1617
                 $cart_items = $ajax_cart_details;
1618 1618
             } else {
1619 1619
                 $cart_items = $this->items;
1620 1620
             }
1621 1621
 
1622
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1622
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1623 1623
         }
1624
-        $discount   = wpinv_round_amount( $this->discount );
1624
+        $discount   = wpinv_round_amount($this->discount);
1625 1625
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1626 1626
         
1627
-        if ( $currency ) {
1628
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1627
+        if ($currency) {
1628
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1629 1629
         }
1630 1630
         
1631
-        $discount   = $dash . $discount;
1631
+        $discount = $dash . $discount;
1632 1632
         
1633
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1633
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1634 1634
     }
1635 1635
     
1636 1636
     public function get_discount_code() {
@@ -1642,49 +1642,49 @@  discard block
 block discarded – undo
1642 1642
         return (int) $this->disable_taxes === 0;
1643 1643
     }
1644 1644
 
1645
-    public function get_tax( $currency = false ) {
1646
-        $tax = wpinv_round_amount( $this->tax );
1645
+    public function get_tax($currency = false) {
1646
+        $tax = wpinv_round_amount($this->tax);
1647 1647
 
1648
-        if ( $currency ) {
1649
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1648
+        if ($currency) {
1649
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1650 1650
         }
1651 1651
 
1652
-        if ( ! $this->is_taxable() ) {
1653
-            $tax = wpinv_round_amount( 0.00 );
1652
+        if (!$this->is_taxable()) {
1653
+            $tax = wpinv_round_amount(0.00);
1654 1654
         }
1655 1655
 
1656
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1656
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1657 1657
     }
1658 1658
     
1659
-    public function get_fees( $type = 'all' ) {
1660
-        $fees    = array();
1659
+    public function get_fees($type = 'all') {
1660
+        $fees = array();
1661 1661
 
1662
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1663
-            foreach ( $this->fees as $fee ) {
1664
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1662
+        if (!empty($this->fees) && is_array($this->fees)) {
1663
+            foreach ($this->fees as $fee) {
1664
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1665 1665
                     continue;
1666 1666
                 }
1667 1667
 
1668
-                $fee['label'] = stripslashes( $fee['label'] );
1669
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1670
-                $fees[]    = $fee;
1668
+                $fee['label'] = stripslashes($fee['label']);
1669
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1670
+                $fees[] = $fee;
1671 1671
             }
1672 1672
         }
1673 1673
 
1674
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1674
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1675 1675
     }
1676 1676
     
1677
-    public function get_fees_total( $type = 'all' ) {
1677
+    public function get_fees_total($type = 'all') {
1678 1678
         $fees_total = (float) 0.00;
1679 1679
 
1680
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1681
-        if ( ! empty( $payment_fees ) ) {
1682
-            foreach ( $payment_fees as $fee ) {
1680
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1681
+        if (!empty($payment_fees)) {
1682
+            foreach ($payment_fees as $fee) {
1683 1683
                 $fees_total += (float) $fee['amount'];
1684 1684
             }
1685 1685
         }
1686 1686
 
1687
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1687
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1688 1688
         /*
1689 1689
         $fees = $this->get_fees( $type );
1690 1690
 
@@ -1704,116 +1704,116 @@  discard block
 block discarded – undo
1704 1704
     }
1705 1705
 
1706 1706
     public function get_user_id() {
1707
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1707
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1708 1708
     }
1709 1709
     
1710 1710
     public function get_first_name() {
1711
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1711
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1712 1712
     }
1713 1713
     
1714 1714
     public function get_last_name() {
1715
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1715
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1716 1716
     }
1717 1717
     
1718 1718
     public function get_user_full_name() {
1719
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1719
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1720 1720
     }
1721 1721
     
1722 1722
     public function get_user_info() {
1723
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1723
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1724 1724
     }
1725 1725
     
1726 1726
     public function get_email() {
1727
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1727
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1728 1728
     }
1729 1729
     
1730 1730
     public function get_address() {
1731
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1731
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1732 1732
     }
1733 1733
     
1734 1734
     public function get_phone() {
1735
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1735
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1736 1736
     }
1737 1737
     
1738 1738
     public function get_number() {
1739
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1739
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1740 1740
     }
1741 1741
     
1742 1742
     public function get_items() {
1743
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1743
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1744 1744
     }
1745 1745
     
1746 1746
     public function get_key() {
1747
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1747
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1748 1748
     }
1749 1749
     
1750 1750
     public function get_transaction_id() {
1751
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1751
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1752 1752
     }
1753 1753
     
1754 1754
     public function get_gateway() {
1755
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1755
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1756 1756
     }
1757 1757
     
1758 1758
     public function get_gateway_title() {
1759
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1759
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1760 1760
         
1761
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1761
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1762 1762
     }
1763 1763
     
1764 1764
     public function get_currency() {
1765
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1765
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1766 1766
     }
1767 1767
     
1768 1768
     public function get_created_date() {
1769
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1769
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1770 1770
     }
1771 1771
     
1772
-    public function get_due_date( $display = false ) {
1773
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1772
+    public function get_due_date($display = false) {
1773
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1774 1774
 
1775
-        if ( ! $display ) {
1775
+        if (!$display) {
1776 1776
             return $due_date;
1777 1777
         }
1778 1778
         
1779
-        return getpaid_format_date( $this->due_date );
1779
+        return getpaid_format_date($this->due_date);
1780 1780
     }
1781 1781
     
1782 1782
     public function get_completed_date() {
1783
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1783
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1784 1784
     }
1785 1785
     
1786
-    public function get_invoice_date( $formatted = true ) {
1786
+    public function get_invoice_date($formatted = true) {
1787 1787
         $date_completed = $this->completed_date;
1788 1788
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1789 1789
         
1790
-        if ( $invoice_date == '' ) {
1790
+        if ($invoice_date == '') {
1791 1791
             $date_created   = $this->date;
1792 1792
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1793 1793
         }
1794 1794
         
1795
-        if ( $formatted && $invoice_date ) {
1796
-            $invoice_date   = getpaid_format_date( $invoice_date );
1795
+        if ($formatted && $invoice_date) {
1796
+            $invoice_date = getpaid_format_date($invoice_date);
1797 1797
         }
1798 1798
 
1799
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1799
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1800 1800
     }
1801 1801
     
1802 1802
     public function get_ip() {
1803
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1803
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1804 1804
     }
1805 1805
         
1806
-    public function has_status( $status ) {
1807
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1806
+    public function has_status($status) {
1807
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1808 1808
     }
1809 1809
     
1810
-    public function add_item( $item_id = 0, $args = array() ) {
1810
+    public function add_item($item_id = 0, $args = array()) {
1811 1811
         global $wpi_current_id, $wpi_item_id;
1812 1812
         
1813
-        $item = new WPInv_Item( $item_id );
1813
+        $item = new WPInv_Item($item_id);
1814 1814
 
1815 1815
         // Bail if this post isn't a item
1816
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1816
+        if (!$item || $item->post_type !== 'wpi_item') {
1817 1817
             return false;
1818 1818
         }
1819 1819
         
@@ -1832,8 +1832,8 @@  discard block
 block discarded – undo
1832 1832
             'fees'          => array()
1833 1833
         );
1834 1834
 
1835
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1836
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1835
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1836
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1837 1837
 
1838 1838
         $wpi_current_id         = $this->ID;
1839 1839
         $wpi_item_id            = $item->ID;
@@ -1845,19 +1845,19 @@  discard block
 block discarded – undo
1845 1845
         $found_cart_key         = false;
1846 1846
         
1847 1847
         if ($has_quantities) {
1848
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1848
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1849 1849
             
1850
-            foreach ( $this->items as $key => $cart_item ) {
1851
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1850
+            foreach ($this->items as $key => $cart_item) {
1851
+                if ((int) $item_id !== (int) $cart_item['id']) {
1852 1852
                     continue;
1853 1853
                 }
1854 1854
 
1855
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1855
+                $this->items[$key]['quantity'] += $args['quantity'];
1856 1856
                 break;
1857 1857
             }
1858 1858
             
1859
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1860
-                if ( $item_id != $cart_item['id'] ) {
1859
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1860
+                if ($item_id != $cart_item['id']) {
1861 1861
                     continue;
1862 1862
                 }
1863 1863
 
@@ -1869,29 +1869,29 @@  discard block
 block discarded – undo
1869 1869
         if ($has_quantities && $found_cart_key !== false) {
1870 1870
             $cart_item          = $this->cart_details[$found_cart_key];
1871 1871
             $item_price         = $cart_item['item_price'];
1872
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1873
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1872
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1873
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1874 1874
             
1875 1875
             $new_quantity       = $quantity + $args['quantity'];
1876 1876
             $subtotal           = $item_price * $new_quantity;
1877 1877
             
1878 1878
             $args['quantity']   = $new_quantity;
1879
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1880
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1879
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1880
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1881 1881
             
1882
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1883
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1882
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1883
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1884 1884
             // The total increase equals the number removed * the item_price
1885
-            $total_increased    = wpinv_round_amount( $item_price );
1885
+            $total_increased    = wpinv_round_amount($item_price);
1886 1886
             
1887
-            if ( wpinv_prices_include_tax() ) {
1888
-                $subtotal -= wpinv_round_amount( $tax );
1887
+            if (wpinv_prices_include_tax()) {
1888
+                $subtotal -= wpinv_round_amount($tax);
1889 1889
             }
1890 1890
 
1891
-            $total              = $subtotal - $discount + $tax;
1891
+            $total = $subtotal - $discount + $tax;
1892 1892
 
1893 1893
             // Do not allow totals to go negative
1894
-            if( $total < 0 ) {
1894
+            if ($total < 0) {
1895 1895
                 $total = 0;
1896 1896
             }
1897 1897
             
@@ -1907,25 +1907,25 @@  discard block
 block discarded – undo
1907 1907
             $this->cart_details[$found_cart_key] = $cart_item;
1908 1908
         } else {
1909 1909
             // Set custom price.
1910
-            if ( $args['custom_price'] !== '' ) {
1910
+            if ($args['custom_price'] !== '') {
1911 1911
                 $item_price = $args['custom_price'];
1912 1912
             } else {
1913 1913
                 // Allow overriding the price
1914
-                if ( false !== $args['item_price'] ) {
1914
+                if (false !== $args['item_price']) {
1915 1915
                     $item_price = $args['item_price'];
1916 1916
                 } else {
1917
-                    $item_price = wpinv_get_item_price( $item->ID );
1917
+                    $item_price = wpinv_get_item_price($item->ID);
1918 1918
                 }
1919 1919
             }
1920 1920
 
1921 1921
             // Sanitizing the price here so we don't have a dozen calls later
1922
-            $item_price = wpinv_sanitize_amount( $item_price );
1923
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1922
+            $item_price = wpinv_sanitize_amount($item_price);
1923
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1924 1924
         
1925
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1926
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1927
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1928
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1925
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1926
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1927
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1928
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1929 1929
 
1930 1930
             // Setup the items meta item
1931 1931
             $new_item = array(
@@ -1933,29 +1933,29 @@  discard block
 block discarded – undo
1933 1933
                 'quantity' => $args['quantity'],
1934 1934
             );
1935 1935
 
1936
-            $this->items[]  = $new_item;
1936
+            $this->items[] = $new_item;
1937 1937
 
1938
-            if ( wpinv_prices_include_tax() ) {
1939
-                $subtotal -= wpinv_round_amount( $tax );
1938
+            if (wpinv_prices_include_tax()) {
1939
+                $subtotal -= wpinv_round_amount($tax);
1940 1940
             }
1941 1941
 
1942
-            $total      = $subtotal - $discount + $tax;
1942
+            $total = $subtotal - $discount + $tax;
1943 1943
 
1944 1944
             // Do not allow totals to go negative
1945
-            if( $total < 0 ) {
1945
+            if ($total < 0) {
1946 1946
                 $total = 0;
1947 1947
             }
1948 1948
         
1949 1949
             $this->cart_details[] = array(
1950 1950
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1951 1951
                 'id'            => $item->ID,
1952
-                'item_price'    => wpinv_round_amount( $item_price ),
1953
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1952
+                'item_price'    => wpinv_round_amount($item_price),
1953
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1954 1954
                 'quantity'      => $args['quantity'],
1955 1955
                 'discount'      => $discount,
1956
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1957
-                'tax'           => wpinv_round_amount( $tax ),
1958
-                'price'         => wpinv_round_amount( $total ),
1956
+                'subtotal'      => wpinv_round_amount($subtotal),
1957
+                'tax'           => wpinv_round_amount($tax),
1958
+                'price'         => wpinv_round_amount($total),
1959 1959
                 'vat_rate'      => $tax_rate,
1960 1960
                 'vat_class'     => $tax_class,
1961 1961
                 'meta'          => $args['meta'],
@@ -1965,18 +1965,18 @@  discard block
 block discarded – undo
1965 1965
             $subtotal = $subtotal - $discount;
1966 1966
         }
1967 1967
         
1968
-        $added_item = end( $this->cart_details );
1969
-        $added_item['action']  = 'add';
1968
+        $added_item = end($this->cart_details);
1969
+        $added_item['action'] = 'add';
1970 1970
         
1971 1971
         $this->pending['items'][] = $added_item;
1972 1972
         
1973
-        $this->increase_subtotal( $subtotal );
1974
-        $this->increase_tax( $tax );
1973
+        $this->increase_subtotal($subtotal);
1974
+        $this->increase_tax($tax);
1975 1975
 
1976 1976
         return true;
1977 1977
     }
1978 1978
     
1979
-    public function remove_item( $item_id, $args = array() ) {
1979
+    public function remove_item($item_id, $args = array()) {
1980 1980
         // Set some defaults
1981 1981
         $defaults = array(
1982 1982
             'quantity'      => 1,
@@ -1984,51 +1984,51 @@  discard block
 block discarded – undo
1984 1984
             'custom_price'  => '',
1985 1985
             'cart_index'    => false,
1986 1986
         );
1987
-        $args = wp_parse_args( $args, $defaults );
1987
+        $args = wp_parse_args($args, $defaults);
1988 1988
 
1989 1989
         // Bail if this post isn't a item
1990
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1990
+        if (get_post_type($item_id) !== 'wpi_item') {
1991 1991
             return false;
1992 1992
         }
1993 1993
         
1994
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1994
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1995 1995
 
1996
-        foreach ( $this->items as $key => $item ) {
1997
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1996
+        foreach ($this->items as $key => $item) {
1997
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1998 1998
                 continue;
1999 1999
             }
2000 2000
 
2001
-            if ( false !== $args['cart_index'] ) {
2002
-                $cart_index = absint( $args['cart_index'] );
2003
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
2001
+            if (false !== $args['cart_index']) {
2002
+                $cart_index = absint($args['cart_index']);
2003
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
2004 2004
 
2005
-                if ( ! empty( $cart_item ) ) {
2005
+                if (!empty($cart_item)) {
2006 2006
                     // If the cart index item isn't the same item ID, don't remove it
2007
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
2007
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
2008 2008
                         continue;
2009 2009
                     }
2010 2010
                 }
2011 2011
             }
2012 2012
 
2013
-            $item_quantity = $this->items[ $key ]['quantity'];
2014
-            if ( $item_quantity > $args['quantity'] ) {
2015
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
2013
+            $item_quantity = $this->items[$key]['quantity'];
2014
+            if ($item_quantity > $args['quantity']) {
2015
+                $this->items[$key]['quantity'] -= $args['quantity'];
2016 2016
                 break;
2017 2017
             } else {
2018
-                unset( $this->items[ $key ] );
2018
+                unset($this->items[$key]);
2019 2019
                 break;
2020 2020
             }
2021 2021
         }
2022 2022
 
2023 2023
         $found_cart_key = false;
2024
-        if ( false === $args['cart_index'] ) {
2025
-            foreach ( $this->cart_details as $cart_key => $item ) {
2026
-                if ( $item_id != $item['id'] ) {
2024
+        if (false === $args['cart_index']) {
2025
+            foreach ($this->cart_details as $cart_key => $item) {
2026
+                if ($item_id != $item['id']) {
2027 2027
                     continue;
2028 2028
                 }
2029 2029
 
2030
-                if ( false !== $args['item_price'] ) {
2031
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
2030
+                if (false !== $args['item_price']) {
2031
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
2032 2032
                         continue;
2033 2033
                     }
2034 2034
                 }
@@ -2037,13 +2037,13 @@  discard block
 block discarded – undo
2037 2037
                 break;
2038 2038
             }
2039 2039
         } else {
2040
-            $cart_index = absint( $args['cart_index'] );
2040
+            $cart_index = absint($args['cart_index']);
2041 2041
 
2042
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
2042
+            if (!array_key_exists($cart_index, $this->cart_details)) {
2043 2043
                 return false; // Invalid cart index passed.
2044 2044
             }
2045 2045
 
2046
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
2046
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
2047 2047
                 return false; // We still need the proper Item ID to be sure.
2048 2048
             }
2049 2049
 
@@ -2051,41 +2051,41 @@  discard block
 block discarded – undo
2051 2051
         }
2052 2052
         
2053 2053
         $cart_item  = $this->cart_details[$found_cart_key];
2054
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
2054
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
2055 2055
         
2056
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
2056
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
2057 2057
             //return false; // Invoice must contain at least one item.
2058 2058
         }
2059 2059
         
2060
-        $discounts  = $this->get_discounts();
2060
+        $discounts = $this->get_discounts();
2061 2061
         
2062
-        if ( $quantity > $args['quantity'] ) {
2062
+        if ($quantity > $args['quantity']) {
2063 2063
             $item_price         = $cart_item['item_price'];
2064
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
2064
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
2065 2065
             
2066
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
2066
+            $new_quantity       = max($quantity - $args['quantity'], 1);
2067 2067
             $subtotal           = $item_price * $new_quantity;
2068 2068
             
2069 2069
             $args['quantity']   = $new_quantity;
2070
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2071
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2070
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2071
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2072 2072
             
2073
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
2074
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
2075
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
2076
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
2073
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
2074
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
2075
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
2076
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
2077 2077
             
2078 2078
             // The total increase equals the number removed * the item_price
2079
-            $total_decrease     = wpinv_round_amount( $item_price );
2079
+            $total_decrease     = wpinv_round_amount($item_price);
2080 2080
             
2081
-            if ( wpinv_prices_include_tax() ) {
2082
-                $subtotal -= wpinv_round_amount( $tax );
2081
+            if (wpinv_prices_include_tax()) {
2082
+                $subtotal -= wpinv_round_amount($tax);
2083 2083
             }
2084 2084
 
2085
-            $total              = $subtotal - $discount + $tax;
2085
+            $total = $subtotal - $discount + $tax;
2086 2086
 
2087 2087
             // Do not allow totals to go negative
2088
-            if( $total < 0 ) {
2088
+            if ($total < 0) {
2089 2089
                 $total = 0;
2090 2090
             }
2091 2091
             
@@ -2104,16 +2104,16 @@  discard block
 block discarded – undo
2104 2104
             
2105 2105
             $this->cart_details[$found_cart_key] = $cart_item;
2106 2106
             
2107
-            $remove_item = end( $this->cart_details );
2107
+            $remove_item = end($this->cart_details);
2108 2108
         } else {
2109 2109
             $item_price     = $cart_item['item_price'];
2110
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2111
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
2110
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2111
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
2112 2112
         
2113
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
2113
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
2114 2114
             $tax_decrease       = $tax;
2115 2115
 
2116
-            unset( $this->cart_details[$found_cart_key] );
2116
+            unset($this->cart_details[$found_cart_key]);
2117 2117
             
2118 2118
             $remove_item             = $args;
2119 2119
             $remove_item['id']       = $item_id;
@@ -2124,8 +2124,8 @@  discard block
 block discarded – undo
2124 2124
         $remove_item['action']      = 'remove';
2125 2125
         $this->pending['items'][]   = $remove_item;
2126 2126
                
2127
-        $this->decrease_subtotal( $subtotal_decrease );
2128
-        $this->decrease_tax( $tax_decrease );
2127
+        $this->decrease_subtotal($subtotal_decrease);
2128
+        $this->decrease_tax($tax_decrease);
2129 2129
         
2130 2130
         return true;
2131 2131
     }
@@ -2133,7 +2133,7 @@  discard block
 block discarded – undo
2133 2133
     public function update_items($temp = false) {
2134 2134
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
2135 2135
         
2136
-        if ( !empty( $this->cart_details ) ) {
2136
+        if (!empty($this->cart_details)) {
2137 2137
             $wpi_nosave             = $temp;
2138 2138
             $cart_subtotal          = 0;
2139 2139
             $cart_discount          = 0;
@@ -2143,65 +2143,65 @@  discard block
 block discarded – undo
2143 2143
             $_POST['wpinv_country'] = $this->country;
2144 2144
             $_POST['wpinv_state']   = $this->state;
2145 2145
 
2146
-            foreach ( $this->cart_details as $key => $item ) {
2146
+            foreach ($this->cart_details as $key => $item) {
2147 2147
                 $item_price = $item['item_price'];
2148
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
2149
-                $amount     = wpinv_round_amount( $item_price * $quantity );
2148
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
2149
+                $amount     = wpinv_round_amount($item_price * $quantity);
2150 2150
                 $subtotal   = $item_price * $quantity;
2151 2151
                 
2152 2152
                 $wpi_current_id         = $this->ID;
2153 2153
                 $wpi_item_id            = $item['id'];
2154 2154
                 
2155
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
2155
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
2156 2156
                 
2157
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
2158
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
2159
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2157
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
2158
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
2159
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2160 2160
 
2161
-                if ( ! $this->is_taxable() ) {
2161
+                if (!$this->is_taxable()) {
2162 2162
                     $tax = 0;
2163 2163
                 }
2164 2164
 
2165
-                if ( wpinv_prices_include_tax() ) {
2166
-                    $subtotal -= wpinv_round_amount( $tax );
2165
+                if (wpinv_prices_include_tax()) {
2166
+                    $subtotal -= wpinv_round_amount($tax);
2167 2167
                 }
2168 2168
 
2169
-                $total      = $subtotal - $discount + $tax;
2169
+                $total = $subtotal - $discount + $tax;
2170 2170
 
2171 2171
                 // Do not allow totals to go negative
2172
-                if( $total < 0 ) {
2172
+                if ($total < 0) {
2173 2173
                     $total = 0;
2174 2174
                 }
2175 2175
 
2176 2176
                 $cart_details[] = array(
2177 2177
                     'id'          => $item['id'],
2178 2178
                     'name'        => $item['name'],
2179
-                    'item_price'  => wpinv_round_amount( $item_price ),
2180
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
2179
+                    'item_price'  => wpinv_round_amount($item_price),
2180
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
2181 2181
                     'quantity'    => $quantity,
2182 2182
                     'discount'    => $discount,
2183
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
2184
-                    'tax'         => wpinv_round_amount( $tax ),
2185
-                    'price'       => wpinv_round_amount( $total ),
2183
+                    'subtotal'    => wpinv_round_amount($subtotal),
2184
+                    'tax'         => wpinv_round_amount($tax),
2185
+                    'price'       => wpinv_round_amount($total),
2186 2186
                     'vat_rate'    => $tax_rate,
2187 2187
                     'vat_class'   => $tax_class,
2188 2188
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
2189 2189
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
2190 2190
                 );
2191 2191
 
2192
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
2193
-                $cart_discount  += (float)($discount);
2194
-                $cart_tax       += (float)($tax);
2192
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
2193
+                $cart_discount  += (float) ($discount);
2194
+                $cart_tax       += (float) ($tax);
2195 2195
             }
2196
-            if ( $cart_subtotal < 0 ) {
2196
+            if ($cart_subtotal < 0) {
2197 2197
                 $cart_subtotal = 0;
2198 2198
             }
2199
-            if ( $cart_tax < 0 ) {
2199
+            if ($cart_tax < 0) {
2200 2200
                 $cart_tax = 0;
2201 2201
             }
2202
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
2203
-            $this->tax      = wpinv_round_amount( $cart_tax );
2204
-            $this->discount = wpinv_round_amount( $cart_discount );
2202
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
2203
+            $this->tax      = wpinv_round_amount($cart_tax);
2204
+            $this->discount = wpinv_round_amount($cart_discount);
2205 2205
             
2206 2206
             $this->recalculate_total();
2207 2207
             
@@ -2213,177 +2213,177 @@  discard block
 block discarded – undo
2213 2213
     
2214 2214
     public function recalculate_totals($temp = false) {        
2215 2215
         $this->update_items($temp);
2216
-        $this->save( true );
2216
+        $this->save(true);
2217 2217
         
2218 2218
         return $this;
2219 2219
     }
2220 2220
     
2221 2221
     public function needs_payment() {
2222
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
2222
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
2223 2223
 
2224
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
2224
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
2225 2225
             $needs_payment = true;
2226 2226
         } else {
2227 2227
             $needs_payment = false;
2228 2228
         }
2229 2229
 
2230
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2230
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2231 2231
     }
2232 2232
     
2233
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2233
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2234 2234
         $pay_url = wpinv_get_checkout_uri();
2235 2235
 
2236
-        if ( is_ssl() ) {
2237
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2236
+        if (is_ssl()) {
2237
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2238 2238
         }
2239 2239
         
2240 2240
         $key = $this->get_key();
2241 2241
 
2242
-        if ( $with_key ) {
2243
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2242
+        if ($with_key) {
2243
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2244 2244
         } else {
2245
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2245
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2246 2246
         }
2247 2247
         
2248
-        if ( $secret ) {
2249
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2248
+        if ($secret) {
2249
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2250 2250
         }
2251 2251
 
2252
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2252
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2253 2253
     }
2254 2254
     
2255
-    public function get_view_url( $with_key = false ) {
2256
-        $invoice_url = get_permalink( $this->ID );
2255
+    public function get_view_url($with_key = false) {
2256
+        $invoice_url = get_permalink($this->ID);
2257 2257
 
2258
-        if ( $with_key ) {
2259
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2258
+        if ($with_key) {
2259
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2260 2260
         }
2261 2261
 
2262
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2262
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2263 2263
     }
2264 2264
     
2265
-    public function generate_key( $string = '' ) {
2266
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2267
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2265
+    public function generate_key($string = '') {
2266
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2267
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2268 2268
     }
2269 2269
     
2270 2270
     public function is_recurring() {
2271
-        if ( empty( $this->cart_details ) ) {
2271
+        if (empty($this->cart_details)) {
2272 2272
             return false;
2273 2273
         }
2274 2274
         
2275 2275
         $has_subscription = false;
2276
-        foreach( $this->cart_details as $cart_item ) {
2277
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2276
+        foreach ($this->cart_details as $cart_item) {
2277
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2278 2278
                 $has_subscription = true;
2279 2279
                 break;
2280 2280
             }
2281 2281
         }
2282 2282
         
2283
-        if ( count( $this->cart_details ) > 1 ) {
2283
+        if (count($this->cart_details) > 1) {
2284 2284
             $has_subscription = false;
2285 2285
         }
2286 2286
 
2287
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2287
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2288 2288
     }
2289 2289
 
2290 2290
     public function is_free_trial() {
2291 2291
         $is_free_trial = false;
2292 2292
         
2293
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2294
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2293
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2294
+            if (!empty($item) && $item->has_free_trial()) {
2295 2295
                 $is_free_trial = true;
2296 2296
             }
2297 2297
         }
2298 2298
 
2299
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this );
2299
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this);
2300 2300
     }
2301 2301
 
2302 2302
     public function is_initial_free() {
2303 2303
         $is_initial_free = false;
2304 2304
         
2305
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2305
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2306 2306
             $is_initial_free = true;
2307 2307
         }
2308 2308
 
2309
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2309
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2310 2310
     }
2311 2311
     
2312
-    public function get_recurring( $object = false ) {
2312
+    public function get_recurring($object = false) {
2313 2313
         $item = NULL;
2314 2314
         
2315
-        if ( empty( $this->cart_details ) ) {
2315
+        if (empty($this->cart_details)) {
2316 2316
             return $item;
2317 2317
         }
2318 2318
         
2319
-        foreach( $this->cart_details as $cart_item ) {
2320
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2319
+        foreach ($this->cart_details as $cart_item) {
2320
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2321 2321
                 $item = $cart_item['id'];
2322 2322
                 break;
2323 2323
             }
2324 2324
         }
2325 2325
         
2326
-        if ( $object ) {
2327
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2326
+        if ($object) {
2327
+            $item = $item ? new WPInv_Item($item) : NULL;
2328 2328
             
2329
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2329
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2330 2330
         }
2331 2331
 
2332
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2332
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2333 2333
     }
2334 2334
 
2335 2335
     public function get_subscription_name() {
2336
-        $item = $this->get_recurring( true );
2336
+        $item = $this->get_recurring(true);
2337 2337
 
2338
-        if ( empty( $item ) ) {
2338
+        if (empty($item)) {
2339 2339
             return NULL;
2340 2340
         }
2341 2341
 
2342
-        if ( !($name = $item->get_name()) ) {
2342
+        if (!($name = $item->get_name())) {
2343 2343
             $name = $item->post_name;
2344 2344
         }
2345 2345
 
2346
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2346
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2347 2347
     }
2348 2348
 
2349 2349
     public function get_subscription_id() {
2350
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2350
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2351 2351
 
2352
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2353
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2352
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2353
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2354 2354
 
2355
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2355
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2356 2356
         }
2357 2357
         
2358 2358
         return $subscription_id;
2359 2359
     }
2360 2360
     
2361 2361
     public function is_parent() {
2362
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2362
+        $is_parent = empty($this->parent_invoice) ? true : false;
2363 2363
 
2364
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2364
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2365 2365
     }
2366 2366
     
2367 2367
     public function is_renewal() {
2368 2368
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2369 2369
 
2370
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2370
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2371 2371
     }
2372 2372
     
2373 2373
     public function get_parent_payment() {
2374 2374
         $parent_payment = NULL;
2375 2375
         
2376
-        if ( $this->is_renewal() ) {
2377
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2376
+        if ($this->is_renewal()) {
2377
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2378 2378
         }
2379 2379
         
2380 2380
         return $parent_payment;
2381 2381
     }
2382 2382
     
2383 2383
     public function is_paid() {
2384
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2384
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2385 2385
 
2386
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2386
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2387 2387
     }
2388 2388
 
2389 2389
     /**
@@ -2396,23 +2396,23 @@  discard block
 block discarded – undo
2396 2396
     }
2397 2397
     
2398 2398
     public function is_refunded() {
2399
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2399
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2400 2400
 
2401
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2401
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2402 2402
     }
2403 2403
     
2404 2404
     public function is_free() {
2405 2405
         $is_free = false;
2406 2406
         
2407
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2408
-            if ( $this->is_parent() && $this->is_recurring() ) {
2409
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2407
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2408
+            if ($this->is_parent() && $this->is_recurring()) {
2409
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2410 2410
             } else {
2411 2411
                 $is_free = true;
2412 2412
             }
2413 2413
         }
2414 2414
         
2415
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2415
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2416 2416
     }
2417 2417
     
2418 2418
     public function has_vat() {
@@ -2420,41 +2420,41 @@  discard block
 block discarded – undo
2420 2420
         
2421 2421
         $requires_vat = false;
2422 2422
         
2423
-        if ( $this->country ) {
2423
+        if ($this->country) {
2424 2424
             $wpi_country        = $this->country;
2425 2425
             
2426
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2426
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2427 2427
         }
2428 2428
         
2429
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2429
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2430 2430
     }
2431 2431
     
2432 2432
     public function refresh_item_ids() {
2433 2433
         $item_ids = array();
2434 2434
         
2435
-        if ( !empty( $this->cart_details ) ) {
2436
-            foreach ( $this->cart_details as $key => $item ) {
2437
-                if ( !empty( $item['id'] ) ) {
2435
+        if (!empty($this->cart_details)) {
2436
+            foreach ($this->cart_details as $key => $item) {
2437
+                if (!empty($item['id'])) {
2438 2438
                     $item_ids[] = $item['id'];
2439 2439
                 }
2440 2440
             }
2441 2441
         }
2442 2442
         
2443
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2443
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2444 2444
         
2445
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2445
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2446 2446
     }
2447 2447
     
2448
-    public function get_invoice_quote_type( $post_id ) {
2449
-        if ( empty( $post_id ) ) {
2448
+    public function get_invoice_quote_type($post_id) {
2449
+        if (empty($post_id)) {
2450 2450
             return '';
2451 2451
         }
2452 2452
 
2453
-        $type = get_post_type( $post_id );
2453
+        $type = get_post_type($post_id);
2454 2454
 
2455
-        if ( 'wpi_invoice' === $type ) {
2455
+        if ('wpi_invoice' === $type) {
2456 2456
             $post_type = __('Invoice', 'invoicing');
2457
-        } else{
2457
+        } else {
2458 2458
             $post_type = __('Quote', 'invoicing');
2459 2459
         }
2460 2460
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
8
-function wpinv_discount_custom_column( $column ) {
7
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
8
+function wpinv_discount_custom_column($column) {
9 9
     global $post;
10 10
 
11
-    $discount = new WPInv_Discount( $post );
11
+    $discount = new WPInv_Discount($post);
12 12
 
13
-    switch ( $column ) {
13
+    switch ($column) {
14 14
         case 'code' :
15 15
             echo $discount->get_code();
16 16
         break;
@@ -21,38 +21,38 @@  discard block
 block discarded – undo
21 21
             echo $discount->get_usage();
22 22
         break;
23 23
         case 'start_date' :
24
-            echo getpaid_format_date_value( $discount->get_start_date() );
24
+            echo getpaid_format_date_value($discount->get_start_date());
25 25
         break;
26 26
         case 'expiry_date' :
27
-            echo getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) );
27
+            echo getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing'));
28 28
         break;
29 29
     }
30 30
 }
31 31
 
32
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
33
-function wpinv_post_row_actions( $actions, $post ) {
34
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
32
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
33
+function wpinv_post_row_actions($actions, $post) {
34
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
35 35
 
36
-    if ( $post_type == 'wpi_invoice' ) {
36
+    if ($post_type == 'wpi_invoice') {
37 37
         $actions = array();
38 38
     }
39 39
 
40
-    if ( $post_type == 'wpi_discount' ) {
41
-        $actions = wpinv_discount_row_actions( $post, $actions );
40
+    if ($post_type == 'wpi_discount') {
41
+        $actions = wpinv_discount_row_actions($post, $actions);
42 42
     }
43 43
 
44 44
     return $actions;
45 45
 }
46 46
 
47
-function wpinv_discount_row_actions( $discount, $row_actions ) {
48
-    $row_actions  = array();
49
-    $edit_link = get_edit_post_link( $discount->ID );
50
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
47
+function wpinv_discount_row_actions($discount, $row_actions) {
48
+    $row_actions = array();
49
+    $edit_link = get_edit_post_link($discount->ID);
50
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
51 51
 
52
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
53
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
54
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
55
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
52
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
53
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
54
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
55
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
56 56
     }
57 57
 
58 58
     $delete_url = esc_url(
@@ -66,110 +66,110 @@  discard block
 block discarded – undo
66 66
             'wpinv_discount_nonce'
67 67
         )
68 68
     );
69
-    $row_actions['delete'] = '<a href="' . $delete_url . '">' . __( 'Delete', 'invoicing' ) . '</a>';
69
+    $row_actions['delete'] = '<a href="' . $delete_url . '">' . __('Delete', 'invoicing') . '</a>';
70 70
 
71
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
71
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
72 72
 
73 73
     return $row_actions;
74 74
 }
75 75
 
76
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
77
-function wpinv_table_primary_column( $default, $screen_id ) {
78
-    if ( 'edit-wpi_invoice' === $screen_id ) {
76
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
77
+function wpinv_table_primary_column($default, $screen_id) {
78
+    if ('edit-wpi_invoice' === $screen_id) {
79 79
         return 'name';
80 80
     }
81 81
 
82 82
     return $default;
83 83
 }
84 84
 
85
-function wpinv_discount_bulk_actions( $actions, $display = false ) {
86
-    if ( !$display ) {
85
+function wpinv_discount_bulk_actions($actions, $display = false) {
86
+    if (!$display) {
87 87
         return array();
88 88
     }
89 89
 
90 90
     $actions = array(
91
-        'activate'   => __( 'Activate', 'invoicing' ),
92
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
93
-        'delete'     => __( 'Delete', 'invoicing' ),
91
+        'activate'   => __('Activate', 'invoicing'),
92
+        'deactivate' => __('Deactivate', 'invoicing'),
93
+        'delete'     => __('Delete', 'invoicing'),
94 94
     );
95 95
     $two = '';
96 96
     $which = 'top';
97 97
     echo '</div><div class="alignleft actions bulkactions">';
98
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
99
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
100
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
98
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
99
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
100
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
101 101
 
102
-    foreach ( $actions as $name => $title ) {
102
+    foreach ($actions as $name => $title) {
103 103
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
104 104
 
105 105
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
106 106
     }
107 107
     echo "</select>";
108 108
 
109
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
109
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
110 110
 
111 111
     echo '</div><div class="alignleft actions">';
112 112
 }
113
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
113
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
114 114
 
115
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
116
-    if ( $post_type == 'wpi_discount' ) {
115
+function wpinv_disable_months_dropdown($disable, $post_type) {
116
+    if ($post_type == 'wpi_discount') {
117 117
         $disable = true;
118 118
     }
119 119
 
120 120
     return $disable;
121 121
 }
122
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
122
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
123 123
 
124 124
 function wpinv_restrict_manage_posts() {
125 125
     global $typenow;
126 126
 
127
-    if( 'wpi_discount' == $typenow ) {
127
+    if ('wpi_discount' == $typenow) {
128 128
         wpinv_discount_filters();
129 129
     }
130 130
 }
131
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
131
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
132 132
 
133 133
 function wpinv_discount_filters() {
134
-    wpinv_discount_bulk_actions( array(), true );
134
+    wpinv_discount_bulk_actions(array(), true);
135 135
 
136 136
     ?>
137 137
     <select name="discount_type" id="dropdown_wpinv_discount_type">
138
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
138
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
139 139
         <?php
140 140
             $types = wpinv_get_discount_types();
141 141
 
142
-            foreach ( $types as $name => $type ) {
143
-                echo '<option value="' . esc_attr( $name ) . '"';
142
+            foreach ($types as $name => $type) {
143
+                echo '<option value="' . esc_attr($name) . '"';
144 144
 
145
-                if ( isset( $_GET['discount_type'] ) )
146
-                    selected( $name, $_GET['discount_type'] );
145
+                if (isset($_GET['discount_type']))
146
+                    selected($name, $_GET['discount_type']);
147 147
 
148
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
148
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
149 149
             }
150 150
         ?>
151 151
     </select>
152 152
     <?php
153 153
 }
154 154
 
155
-function wpinv_request( $vars ) {
155
+function wpinv_request($vars) {
156 156
     global $typenow, $wp_query, $wp_post_statuses;
157 157
 
158
-    if ( 'wpi_invoice' === $typenow ) {
159
-        if ( !isset( $vars['post_status'] ) ) {
158
+    if ('wpi_invoice' === $typenow) {
159
+        if (!isset($vars['post_status'])) {
160 160
             $post_statuses = wpinv_get_invoice_statuses();
161 161
 
162
-            foreach ( $post_statuses as $status => $value ) {
163
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
164
-                    unset( $post_statuses[ $status ] );
162
+            foreach ($post_statuses as $status => $value) {
163
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
164
+                    unset($post_statuses[$status]);
165 165
                 }
166 166
             }
167 167
 
168
-            $vars['post_status'] = array_keys( $post_statuses );
168
+            $vars['post_status'] = array_keys($post_statuses);
169 169
         }
170 170
 
171
-        if ( isset( $vars['orderby'] ) ) {
172
-            if ( 'amount' == $vars['orderby'] ) {
171
+        if (isset($vars['orderby'])) {
172
+            if ('amount' == $vars['orderby']) {
173 173
                 $vars = array_merge(
174 174
                     $vars,
175 175
                     array(
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
                         'orderby'  => 'meta_value_num'
178 178
                     )
179 179
                 );
180
-            } else if ( 'customer' == $vars['orderby'] ) {
180
+            } else if ('customer' == $vars['orderby']) {
181 181
                 $vars = array_merge(
182 182
                     $vars,
183 183
                     array(
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                         'orderby'  => 'meta_value'
186 186
                     )
187 187
                 );
188
-            } else if ( 'number' == $vars['orderby'] ) {
188
+            } else if ('number' == $vars['orderby']) {
189 189
                 $vars = array_merge(
190 190
                     $vars,
191 191
                     array(
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                         'orderby'  => 'meta_value'
194 194
                     )
195 195
                 );
196
-            } else if ( 'payment_date' == $vars['orderby'] ) {
196
+            } else if ('payment_date' == $vars['orderby']) {
197 197
                 $vars = array_merge(
198 198
                     $vars,
199 199
                     array(
@@ -203,73 +203,73 @@  discard block
 block discarded – undo
203 203
                 );
204 204
             }
205 205
         }
206
-    } else if ( 'wpi_discount' == $typenow ) {
207
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
206
+    } else if ('wpi_discount' == $typenow) {
207
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
208 208
         // Filter vat rule type
209
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
209
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
210 210
             $meta_query[] = array(
211 211
                     'key'   => '_wpi_discount_type',
212
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
212
+                    'value' => sanitize_text_field($_GET['discount_type']),
213 213
                     'compare' => '='
214 214
                 );
215 215
         }
216 216
 
217
-        if ( !empty( $meta_query ) ) {
217
+        if (!empty($meta_query)) {
218 218
             $vars['meta_query'] = $meta_query;
219 219
         }
220 220
     }
221 221
 
222 222
     return $vars;
223 223
 }
224
-add_filter( 'request', 'wpinv_request' );
224
+add_filter('request', 'wpinv_request');
225 225
 
226
-function wpinv_item_type_class( $classes, $class, $post_id ) {
226
+function wpinv_item_type_class($classes, $class, $post_id) {
227 227
     global $pagenow, $typenow;
228 228
 
229
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
230
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
231
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
229
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
230
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
231
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
232 232
         }
233 233
 
234
-        if ( !wpinv_item_is_editable( $post_id ) ) {
234
+        if (!wpinv_item_is_editable($post_id)) {
235 235
             $classes[] = 'wpi-editable-n';
236 236
         }
237 237
     }
238 238
     return $classes;
239 239
 }
240
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
240
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
241 241
 
242 242
 function wpinv_check_quick_edit() {
243 243
     global $pagenow, $current_screen, $wpinv_item_screen;
244 244
 
245
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
246
-        if ( empty( $wpinv_item_screen ) ) {
247
-            if ( $current_screen->post_type == 'wpi_item' ) {
245
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
246
+        if (empty($wpinv_item_screen)) {
247
+            if ($current_screen->post_type == 'wpi_item') {
248 248
                 $wpinv_item_screen = 'y';
249 249
             } else {
250 250
                 $wpinv_item_screen = 'n';
251 251
             }
252 252
         }
253 253
 
254
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
255
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
256
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
254
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
255
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
256
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
257 257
         }
258 258
     }
259 259
 }
260
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
260
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
261 261
 
262
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
263
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
264
-        unset( $actions['inline hide-if-no-js'] );
262
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
263
+    if (isset($actions['inline hide-if-no-js'])) {
264
+        unset($actions['inline hide-if-no-js']);
265 265
     }
266 266
 
267
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
268
-        if ( isset( $actions['trash'] ) ) {
269
-            unset( $actions['trash'] );
267
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
268
+        if (isset($actions['trash'])) {
269
+            unset($actions['trash']);
270 270
         }
271
-        if ( isset( $actions['delete'] ) ) {
272
-            unset( $actions['delete'] );
271
+        if (isset($actions['delete'])) {
272
+            unset($actions['delete']);
273 273
         }
274 274
     }
275 275
 
@@ -286,19 +286,19 @@  discard block
 block discarded – undo
286 286
  * @param int $post_parent (default: 0) Parent for the new page
287 287
  * @return int page ID
288 288
  */
289
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
289
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
290 290
     global $wpdb;
291 291
 
292
-    $option_value = wpinv_get_option( $option );
292
+    $option_value = wpinv_get_option($option);
293 293
 
294
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
295
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
294
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
295
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
296 296
             // Valid page is already in place
297 297
             return $page_object->ID;
298 298
         }
299 299
     }
300 300
 
301
-    if(!empty($post_parent)){
301
+    if (!empty($post_parent)) {
302 302
         $page = get_page_by_path($post_parent);
303 303
         if ($page) {
304 304
             $post_parent = $page->ID;
@@ -307,40 +307,40 @@  discard block
 block discarded – undo
307 307
         }
308 308
     }
309 309
 
310
-    if ( strlen( $page_content ) > 0 ) {
310
+    if (strlen($page_content) > 0) {
311 311
         // Search for an existing page with the specified page content (typically a shortcode)
312
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
312
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
313 313
     } else {
314 314
         // Search for an existing page with the specified page slug
315
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
315
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
316 316
     }
317 317
 
318
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
318
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
319 319
 
320
-    if ( $valid_page_found ) {
321
-        if ( $option ) {
322
-            wpinv_update_option( $option, $valid_page_found );
320
+    if ($valid_page_found) {
321
+        if ($option) {
322
+            wpinv_update_option($option, $valid_page_found);
323 323
         }
324 324
         return $valid_page_found;
325 325
     }
326 326
 
327 327
     // Search for a matching valid trashed page
328
-    if ( strlen( $page_content ) > 0 ) {
328
+    if (strlen($page_content) > 0) {
329 329
         // Search for an existing page with the specified page content (typically a shortcode)
330
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
330
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
331 331
     } else {
332 332
         // Search for an existing page with the specified page slug
333
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
333
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
334 334
     }
335 335
 
336
-    if ( $trashed_page_found ) {
336
+    if ($trashed_page_found) {
337 337
         $page_id   = $trashed_page_found;
338 338
         $page_data = array(
339 339
             'ID'             => $page_id,
340 340
             'post_status'    => 'publish',
341 341
             'post_parent'    => $post_parent,
342 342
         );
343
-        wp_update_post( $page_data );
343
+        wp_update_post($page_data);
344 344
     } else {
345 345
         $page_data = array(
346 346
             'post_status'    => 'publish',
@@ -352,11 +352,11 @@  discard block
 block discarded – undo
352 352
             'post_parent'    => $post_parent,
353 353
             'comment_status' => 'closed',
354 354
         );
355
-        $page_id = wp_insert_post( $page_data );
355
+        $page_id = wp_insert_post($page_data);
356 356
     }
357 357
 
358
-    if ( $option ) {
359
-        wpinv_update_option( $option, (int)$page_id );
358
+    if ($option) {
359
+        wpinv_update_option($option, (int) $page_id);
360 360
     }
361 361
 
362 362
     return $page_id;
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 1 patch
Spacing   +45 added lines, -45 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
  * Metaboxes Admin Class
@@ -25,93 +25,93 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 		global $wpinv_euvat;
45 45
 
46 46
 		// For invoices...
47
-		if ( $post_type == 'wpi_invoice' ) {
48
-			$invoice = new WPInv_Invoice( $post );
47
+		if ($post_type == 'wpi_invoice') {
48
+			$invoice = new WPInv_Invoice($post);
49 49
 
50 50
 			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
-				add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' );
51
+			if (!$invoice->is_draft() && !$invoice->is_paid()) {
52
+				add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low');
53 53
 			}
54 54
 
55 55
 			// Subscriptions.
56
-			$subscription = getpaid_get_invoice_subscription( $invoice );
57
-			if ( ! empty( $subscription ) ) {
58
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' );
59
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' );
56
+			$subscription = getpaid_get_invoice_subscription($invoice);
57
+			if (!empty($subscription)) {
58
+				add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced');
59
+				add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced');
60 60
 			}
61 61
 
62 62
 			// Invoice details.
63
-			add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' );
63
+			add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default');
64 64
 			
65 65
 			// Payment details.
66
-			if ( ! $invoice->is_draft() ) {
67
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' );
66
+			if (!$invoice->is_draft()) {
67
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default');
68 68
 			}
69 69
 
70 70
 			// Billing details.
71
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' );
71
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high');
72 72
 			
73 73
 			// Invoice items.
74
-			add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' );
74
+			add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high');
75 75
 			
76 76
 			// Invoice notes.
77
-			add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' );
77
+			add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low');
78 78
 
79 79
 			// Payment form information.
80
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
81
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' );
80
+			if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) {
81
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high');
82 82
 			}
83 83
 		}
84 84
 
85 85
 		// For payment forms.
86
-		if ( $post_type == 'wpi_payment_form' ) {
86
+		if ($post_type == 'wpi_payment_form') {
87 87
 
88 88
 			// Design payment form.
89
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
89
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
90 90
 
91 91
 			// Payment form information.
92
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
92
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
93 93
 
94 94
 		}
95 95
 
96 96
 		// For invoice items.
97
-		if ( $post_type == 'wpi_item' ) {
97
+		if ($post_type == 'wpi_item') {
98 98
 
99 99
 			// Item details.
100
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
100
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
101 101
 
102 102
 			// If taxes are enabled, register the tax metabox.
103
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
104
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
103
+			if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) {
104
+				add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
105 105
 			}
106 106
 
107 107
 			// Item info.
108
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
108
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
109 109
 
110 110
 		}
111 111
 
112 112
 		// For invoice discounts.
113
-		if ( $post_type == 'wpi_discount' ) {
114
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
113
+		if ($post_type == 'wpi_discount') {
114
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
115 115
 		}
116 116
 		
117 117
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * Remove some metaboxes.
122 122
 	 */
123 123
 	public static function remove_meta_boxes() {
124
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
124
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
125 125
 	}
126 126
 
127 127
 	/**
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 	 * @param  int    $post_id Post ID.
138 138
 	 * @param  object $post Post object.
139 139
 	 */
140
-	public static function save_meta_boxes( $post_id, $post ) {
141
-		$post_id = absint( $post_id );
142
-		$data    = wp_unslash( $_POST );
140
+	public static function save_meta_boxes($post_id, $post) {
141
+		$post_id = absint($post_id);
142
+		$data    = wp_unslash($_POST);
143 143
 
144 144
 		// Do not save for ajax requests.
145
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
145
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
146 146
 			return;
147 147
 		}
148 148
 
149 149
 		// $post_id and $post are required
150
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
150
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
151 151
 			return;
152 152
 		}
153 153
 
154 154
 		// Dont' save meta boxes for revisions or autosaves.
155
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
155
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
156 156
 			return;
157 157
 		}
158 158
 
159 159
 		// Check the nonce.
160
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
160
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
161 161
 			return;
162 162
 		}
163 163
 
164 164
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
165
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
165
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
166 166
 			return;
167 167
 		}
168 168
 
169 169
 		// Check user has permission to edit.
170
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
170
+		if (!current_user_can('edit_post', $post_id)) {
171 171
 			return;
172 172
 		}
173 173
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		);
182 182
 
183 183
 		// Is this our post type?
184
-		if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) {
184
+		if (empty($post->post_type) || !isset($post_types_map[$post->post_type])) {
185 185
 			return;
186 186
 		}
187 187
 
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 		self::$saved_meta_boxes = true;
190 190
 		
191 191
 		// Save the post.
192
-		$class = $post_types_map[ $post->post_type ];
193
-		$class::save( $post_id, $_POST, $post );
192
+		$class = $post_types_map[$post->post_type];
193
+		$class::save($post_id, $_POST, $post);
194 194
 
195 195
 	}
196 196
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-payment-meta.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice = new WPInv_Invoice( $post );
27
+        $invoice = new WPInv_Invoice($post);
28 28
 
29 29
         ?>
30 30
 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
                                 'type'        => 'text',
47 47
                                 'id'          => 'wpinv_key',
48 48
                                 'name'        => 'wpinv_key',
49
-                                'label'       => __( 'Invoice Key:', 'invoicing' ),
49
+                                'label'       => __('Invoice Key:', 'invoicing'),
50 50
                                 'label_type'  => 'vertical',
51 51
                                 'class'       => 'form-control-sm',
52
-                                'value'       => $invoice->get_key( 'edit' ),
52
+                                'value'       => $invoice->get_key('edit'),
53 53
                                 'extra_attributes' => array(
54 54
                                     'onclick'  => 'this.select();',
55 55
                                     'readonly' => 'true',
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                                 'type'        => 'text',
64 64
                                 'id'          => 'wpinv_view_url',
65 65
                                 'name'        => 'wpinv_view_url',
66
-                                'label'       => __( 'Invoice URL:', 'invoicing' ),
66
+                                'label'       => __('Invoice URL:', 'invoicing'),
67 67
                                 'label_type'  => 'vertical',
68 68
                                 'class'       => 'form-control-sm',
69 69
                                 'value'       => $invoice->get_view_url(),
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
                         );
76 76
 
77 77
                         // If the invoice is paid...
78
-                        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
78
+                        if ($invoice->is_paid() || $invoice->is_refunded()) {
79 79
 
80 80
                             // Payment date.
81 81
                             echo aui()->input(
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
                                     'type'        => 'datepicker',
84 84
                                     'id'          => 'wpinv_date_completed',
85 85
                                     'name'        => 'date_completed',
86
-                                    'label'       => __( 'Payment Date:', 'invoicing' ),
86
+                                    'label'       => __('Payment Date:', 'invoicing'),
87 87
                                     'label_type'  => 'vertical',
88 88
                                     'placeholder' => 'YYYY-MM-DD 00:00',
89 89
                                     'class'       => 'form-control-sm',
90
-                                    'value'       => $invoice->get_date_completed( 'edit' ),
90
+                                    'value'       => $invoice->get_date_completed('edit'),
91 91
                                     'extra_attributes' => array(
92 92
                                         'data-enable-time' => 'true',
93 93
                                         'data-time_24hr'   => 'true',
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
                                     'type'        => 'text',
103 103
                                     'id'          => 'wpinv_gateway',
104 104
                                     'name'        => 'wpinv_gateway',
105
-                                    'label'       => __( 'Gateway:', 'invoicing' ),
105
+                                    'label'       => __('Gateway:', 'invoicing'),
106 106
                                     'label_type'  => 'vertical',
107 107
                                     'class'       => 'form-control-sm',
108
-                                    'value'       => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ),
108
+                                    'value'       => wpinv_get_gateway_admin_label($invoice->get_gateway('edit')),
109 109
                                     'extra_attributes' => array(
110 110
                                         'onclick'  => 'this.select();',
111 111
                                         'readonly' => 'true',
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
                                     'type'        => 'text',
120 120
                                     'id'          => 'wpinv_transaction_id',
121 121
                                     'name'        => 'wpinv_transaction_id',
122
-                                    'label'       => __( 'Transaction ID:', 'invoicing' ),
122
+                                    'label'       => __('Transaction ID:', 'invoicing'),
123 123
                                     'label_type'  => 'vertical',
124 124
                                     'class'       => 'form-control-sm',
125
-                                    'value'       => $invoice->get_transaction_id( 'edit' ),
126
-                                    'help_text'   => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ),
125
+                                    'value'       => $invoice->get_transaction_id('edit'),
126
+                                    'help_text'   => apply_filters('wpinv_invoice_transaction_link_' . $invoice->get_gateway('edit'), '', $invoice->get_transaction_id(), $invoice),
127 127
                                     'extra_attributes' => array(
128 128
                                         'onclick'  => 'this.select();',
129 129
                                         'readonly' => 'true',
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
                                     'type'        => 'text',
138 138
                                     'id'          => 'wpinv_currency',
139 139
                                     'name'        => 'wpinv_currency',
140
-                                    'label'       => __( 'Currency:', 'invoicing' ),
140
+                                    'label'       => __('Currency:', 'invoicing'),
141 141
                                     'label_type'  => 'vertical',
142 142
                                     'class'       => 'form-control-sm',
143
-                                    'value'       => $invoice->get_currency( 'edit' ),
143
+                                    'value'       => $invoice->get_currency('edit'),
144 144
                                     'extra_attributes' => array(
145 145
                                         'onclick'  => 'this.select();',
146 146
                                         'readonly' => 'true',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                                     'type'        => 'text',
157 157
                                     'id'          => 'wpinv_payment_url',
158 158
                                     'name'        => 'wpinv_payment_url',
159
-                                    'label'       => __( 'Payment URL:', 'invoicing' ),
159
+                                    'label'       => __('Payment URL:', 'invoicing'),
160 160
                                     'label_type'  => 'vertical',
161 161
                                     'class'       => 'form-control-sm',
162 162
                                     'value'       => $invoice->get_checkout_payment_url(),
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
                                 array(
173 173
                                     'id'               => 'wpinv_gateway',
174 174
                                     'name'             => 'wpinv_gateway',
175
-                                    'label'            => __( 'Gateway:', 'invoicing' ),
175
+                                    'label'            => __('Gateway:', 'invoicing'),
176 176
                                     'label_type'       => 'vertical',
177
-                                    'placeholder'      => __( 'Select Gateway', 'invoicing' ),
178
-                                    'value'            => $invoice->get_gateway( 'edit' ),
177
+                                    'placeholder'      => __('Select Gateway', 'invoicing'),
178
+                                    'value'            => $invoice->get_gateway('edit'),
179 179
                                     'select2'          => true,
180 180
                                     'data-allow-clear' => 'false',
181
-                                    'options'          => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ),
181
+                                    'options'          => wp_list_pluck(wpinv_get_enabled_payment_gateways(true), 'admin_label'),
182 182
                                 )
183 183
                             );
184 184
 
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -11,55 +11,55 @@  discard block
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
 
16 16
     // Update tables.
17
-    if ( ! get_option( 'getpaid_created_invoice_tables' ) ) {
17
+    if (!get_option('getpaid_created_invoice_tables')) {
18 18
         wpinv_v119_upgrades();
19
-        update_option( 'getpaid_created_invoice_tables', true );
19
+        update_option('getpaid_created_invoice_tables', true);
20 20
     }
21 21
 
22
-    if ( $wpi_version == WPINV_VERSION ) {
22
+    if ($wpi_version == WPINV_VERSION) {
23 23
         return;
24 24
     }
25 25
 
26
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
26
+    if (version_compare($wpi_version, '0.0.5', '<')) {
27 27
         wpinv_v005_upgrades();
28 28
     }
29 29
 
30
-    if ( version_compare( $wpi_version, '1.0.3', '<' ) ) {
30
+    if (version_compare($wpi_version, '1.0.3', '<')) {
31 31
         wpinv_v110_upgrades();
32 32
     }
33 33
 
34
-    update_option( 'wpinv_version', WPINV_VERSION );
34
+    update_option('wpinv_version', WPINV_VERSION);
35 35
 }
36
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
36
+add_action('admin_init', 'wpinv_automatic_upgrade');
37 37
 
38 38
 function wpinv_v005_upgrades() {
39 39
     global $wpdb;
40 40
 
41 41
     // Invoices status
42
-    $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
43
-    if ( !empty( $results ) ) {
44
-        $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
42
+    $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
43
+    if (!empty($results)) {
44
+        $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
45 45
 
46 46
         // Clean post cache
47
-        foreach ( $results as $row ) {
48
-            clean_post_cache( $row->ID );
47
+        foreach ($results as $row) {
48
+            clean_post_cache($row->ID);
49 49
         }
50 50
     }
51 51
 
52 52
     // Item meta key changes
53 53
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
54
-    $results = $wpdb->get_results( $query );
54
+    $results = $wpdb->get_results($query);
55 55
 
56
-    if ( !empty( $results ) ) {
57
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
58
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
59
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
56
+    if (!empty($results)) {
57
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
58
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
59
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
60 60
         
61
-        foreach ( $results as $row ) {
62
-            clean_post_cache( $row->post_id );
61
+        foreach ($results as $row) {
62
+            clean_post_cache($row->post_id);
63 63
         }
64 64
     }
65 65
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 function wpinv_create_invoices_table() {
89 89
     global $wpdb;
90 90
 
91
-    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
91
+    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
92 92
 
93 93
     // Create invoices table.
94 94
     $table = $wpdb->prefix . 'getpaid_invoices';
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             KEY `key` ( `key` )
133 133
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
134 134
 
135
-    dbDelta( $sql );
135
+    dbDelta($sql);
136 136
 
137 137
     // Create invoice items table.
138 138
     $table = $wpdb->prefix . 'getpaid_invoice_items';
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             KEY post_id ( post_id )
161 161
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
162 162
 
163
-    dbDelta( $sql );
163
+    dbDelta($sql);
164 164
 }
165 165
 
166 166
 /**
@@ -172,29 +172,29 @@  discard block
 block discarded – undo
172 172
     $invoices = array_unique(
173 173
         get_posts(
174 174
             array(
175
-                'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
175
+                'post_type'      => array('wpi_invoice', 'wpi_quote'),
176 176
                 'posts_per_page' => -1,
177 177
                 'fields'         => 'ids',
178
-                'post_status'    => array_keys( wpinv_get_invoice_statuses( true ) ),
178
+                'post_status'    => array_keys(wpinv_get_invoice_statuses(true)),
179 179
             )
180 180
         )
181 181
     );
182 182
     $invoices_table = $wpdb->prefix . 'getpaid_invoices';
183 183
     $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
184 184
 
185
-    if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) {
186
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
185
+    if (!class_exists('WPInv_Legacy_Invoice')) {
186
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
187 187
     }
188 188
 
189 189
     $invoice_rows = array();
190
-    foreach ( $invoices as $invoice ) {
190
+    foreach ($invoices as $invoice) {
191 191
 
192
-        $invoice = new WPInv_Legacy_Invoice( $invoice );
193
-        $fields = array (
192
+        $invoice = new WPInv_Legacy_Invoice($invoice);
193
+        $fields = array(
194 194
             'post_id'        => $invoice->ID,
195 195
             'number'         => $invoice->get_number(),
196 196
             'key'            => $invoice->get_key(),
197
-            'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
197
+            'type'           => str_replace('wpi_', '', $invoice->post_type),
198 198
             'mode'           => $invoice->mode,
199 199
             'user_ip'        => $invoice->get_ip(),
200 200
             'first_name'     => $invoice->get_first_name(),
@@ -223,27 +223,27 @@  discard block
 block discarded – undo
223 223
             'custom_meta'    => $invoice->payment_meta
224 224
         );
225 225
 
226
-        foreach ( $fields as $key => $val ) {
227
-            if ( is_null( $val ) ) {
226
+        foreach ($fields as $key => $val) {
227
+            if (is_null($val)) {
228 228
                 $val = '';
229 229
             }
230
-            $val = maybe_serialize( $val );
231
-            $fields[ $key ] = $wpdb->prepare( '%s', $val );
230
+            $val = maybe_serialize($val);
231
+            $fields[$key] = $wpdb->prepare('%s', $val);
232 232
         }
233 233
 
234
-        $fields = implode( ', ', $fields );
234
+        $fields = implode(', ', $fields);
235 235
         $invoice_rows[] = "($fields)";
236 236
 
237 237
         $item_rows    = array();
238 238
         $item_columns = array();
239
-        foreach ( $invoice->get_cart_details() as $details ) {
239
+        foreach ($invoice->get_cart_details() as $details) {
240 240
             $fields = array(
241 241
                 'post_id'          => $invoice->ID,
242 242
                 'item_id'          => $details['id'],
243 243
                 'item_name'        => $details['name'],
244
-                'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
244
+                'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
245 245
                 'vat_rate'         => $details['vat_rate'],
246
-                'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
246
+                'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
247 247
                 'tax'              => $details['tax'],
248 248
                 'item_price'       => $details['item_price'],
249 249
                 'custom_price'     => $details['custom_price'],
@@ -255,26 +255,26 @@  discard block
 block discarded – undo
255 255
                 'fees'             => $details['fees'],
256 256
             );
257 257
 
258
-            $item_columns = array_keys ( $fields );
258
+            $item_columns = array_keys($fields);
259 259
 
260
-            foreach ( $fields as $key => $val ) {
261
-                if ( is_null( $val ) ) {
260
+            foreach ($fields as $key => $val) {
261
+                if (is_null($val)) {
262 262
                     $val = '';
263 263
                 }
264
-                $val = maybe_serialize( $val );
265
-                $fields[ $key ] = $wpdb->prepare( '%s', $val );
264
+                $val = maybe_serialize($val);
265
+                $fields[$key] = $wpdb->prepare('%s', $val);
266 266
             }
267 267
 
268
-            $fields = implode( ', ', $fields );
268
+            $fields = implode(', ', $fields);
269 269
             $item_rows[] = "($fields)";
270 270
         }
271 271
 
272
-        $item_rows    = implode( ', ', $item_rows );
273
-        $item_columns = implode( ', ', $item_columns );
274
-        $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
272
+        $item_rows    = implode(', ', $item_rows);
273
+        $item_columns = implode(', ', $item_columns);
274
+        $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
275 275
     }
276 276
 
277
-    $invoice_rows = implode( ', ', $invoice_rows );
278
-    $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
277
+    $invoice_rows = implode(', ', $invoice_rows);
278
+    $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
279 279
 
280 280
 }
Please login to merge, or discard this patch.
includes/subscription-functions.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
17 17
  */
18
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
18
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
19 19
 
20 20
 	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
21
+	if ('count' == $return) {
22 22
 		$args['fields'] = 'id';
23 23
 		$args['number'] = 1;
24 24
 	}
25 25
 
26 26
 	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
27
+	if ('results' == $return) {
28 28
 		$args['count_total'] = false;
29 29
 	}
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+	$query = new GetPaid_Subscriptions_Query($args);
32 32
 
33
-	if ( 'results' == $return ) {
33
+	if ('results' == $return) {
34 34
 		return $query->get_results();
35 35
 	}
36 36
 
37
-	if ( 'count' == $return ) {
37
+	if ('count' == $return) {
38 38
 		return $query->get_total();
39 39
 	}
40 40
 
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	return apply_filters(
52 52
 		'getpaid_get_subscription_statuses',
53 53
 		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
54
+			'pending'    => __('Pending', 'invoicing'),
55
+			'trialling'  => __('Trialing', 'invoicing'),
56
+			'active'     => __('Active', 'invoicing'),
57
+			'failing'    => __('Failing', 'invoicing'),
58
+			'expired'    => __('Expired', 'invoicing'),
59
+			'completed'  => __('Complete', 'invoicing'),
60
+			'cancelled'  => __('Cancelled', 'invoicing'),
61 61
 		)
62 62
 	);
63 63
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @return string
70 70
  */
71
-function getpaid_get_subscription_status_label( $status ) {
71
+function getpaid_get_subscription_status_label($status) {
72 72
 	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
73
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
74 74
 }
75 75
 
76 76
 /**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
  *
101 101
  * @return array
102 102
  */
103
-function getpaid_get_subscription_status_counts( $args = array() ) {
103
+function getpaid_get_subscription_status_counts($args = array()) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
105
+	$statuses = array_keys(getpaid_get_subscription_statuses());
106 106
 	$counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
108
+	foreach ($statuses as $status) {
109
+		$_args             = wp_parse_args("status=$status", $args);
110
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
111 111
 	}
112 112
 
113 113
 	return $counts;
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		array(
127 127
 
128 128
 			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
129
+				'singular' => __('%s day', 'invoicing'),
130
+				'plural'   => __('%d days', 'invoicing'),
131 131
 			),
132 132
 
133 133
 			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
134
+				'singular' => __('%s week', 'invoicing'),
135
+				'plural'   => __('%d weeks', 'invoicing'),
136 136
 			),
137 137
 
138 138
 			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
139
+				'singular' => __('%s month', 'invoicing'),
140
+				'plural'   => __('%d months', 'invoicing'),
141 141
 			),
142 142
 
143 143
 			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
144
+				'singular' => __('%s year', 'invoicing'),
145
+				'plural'   => __('%d years', 'invoicing'),
146 146
 			),
147 147
 
148 148
 		)
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * @param string $trial_period
157 157
  * @return int
158 158
  */
159
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
159
+function getpaid_get_subscription_trial_period_interval($trial_period) {
160
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
161 161
 }
162 162
 
163 163
 /**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
  * @param string $trial_period
167 167
  * @return string
168 168
  */
169
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
169
+function getpaid_get_subscription_trial_period_period($trial_period) {
170
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
171 171
 }
172 172
 
173 173
 /**
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
  * @param int $interval
178 178
  * @return string
179 179
  */
180
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
180
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
181
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
182
+	return strtolower(sanitize_text_field($label));
183 183
 }
184 184
 
185 185
 /**
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
  * @param string $period
189 189
  * @return string
190 190
  */
191
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
191
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
192 192
 
193 193
 	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
194
+	$period  = strtolower($period);
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
196
+	if (isset($periods[$period])) {
197
+		return sprintf($periods[$period]['singular'], $singular_prefix);
198 198
 	}
199 199
 
200 200
 	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
201
+	foreach ($periods as $key => $data) {
202
+		if (strpos($key, $period) === 0) {
203
+			return sprintf($data['singular'], $singular_prefix);
204 204
 		}
205 205
 	}
206 206
 
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
  * @param int $interval
216 216
  * @return string
217 217
  */
218
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
218
+function getpaid_get_plural_subscription_period_label($period, $interval) {
219 219
 
220 220
 	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
221
+	$period  = strtolower($period);
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
223
+	if (isset($periods[$period])) {
224
+		return sprintf($periods[$period]['plural'], $interval);
225 225
 	}
226 226
 
227 227
 	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
228
+	foreach ($periods as $key => $data) {
229
+		if (strpos($key, $period) === 0) {
230
+			return sprintf($data['plural'], $interval);
231 231
 		}
232 232
 	}
233 233
 
@@ -241,23 +241,23 @@  discard block
 block discarded – undo
241 241
  * @param WPInv_Subscription $subscription
242 242
  * @return string
243 243
  */
244
-function getpaid_get_formatted_subscription_amount( $subscription ) {
244
+function getpaid_get_formatted_subscription_amount($subscription) {
245 245
 
246
-	$initial   = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() );
248
-	$period    = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
246
+	$initial   = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency());
247
+	$recurring = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency());
248
+	$period    = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
249 249
 
250 250
 	// Trial periods.
251
-	if ( $subscription->has_trial_period() ) {
251
+	if ($subscription->has_trial_period()) {
252 252
 
253
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
254
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
253
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
254
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
255 255
 		return sprintf(
256 256
 
257 257
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
258
-			_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
258
+			_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
259 259
 			$initial,
260
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
260
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
261 261
 			$recurring,
262 262
 			$period
263 263
 
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 
266 266
 	}
267 267
 
268
-	if ( $initial != $recurring ) {
268
+	if ($initial != $recurring) {
269 269
 
270 270
 		return sprintf(
271 271
 
272 272
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
273
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
273
+			_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
274 274
 			$initial,
275 275
 			$recurring,
276 276
 			$period
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	return sprintf(
283 283
 
284 284
 		// translators: $1: is the recurring amount, $2: is the recurring period
285
-		_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
285
+		_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
286 286
 		$initial,
287 287
 		$period
288 288
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
  * @param WPInv_Invoice $invoice
297 297
  * @return WPInv_Subscription|bool
298 298
  */
299
-function getpaid_get_invoice_subscription( $invoice ) {
300
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
299
+function getpaid_get_invoice_subscription($invoice) {
300
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
301 301
 }
302 302
 
303 303
 /**
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
  *
306 306
  * @param WPInv_Invoice $invoice
307 307
  */
308
-function getpaid_activate_invoice_subscription( $invoice ) {
309
-	$subscription = getpaid_get_invoice_subscription( $invoice );
310
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
308
+function getpaid_activate_invoice_subscription($invoice) {
309
+	$subscription = getpaid_get_invoice_subscription($invoice);
310
+	if (is_a($subscription, 'WPInv_Subscription')) {
311 311
 		$subscription->activate();
312 312
 	}
313 313
 }
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return WPInv_Subscriptions
319 319
  */
320 320
 function getpaid_subscriptions() {
321
-	return getpaid()->get( 'subscriptions' );
321
+	return getpaid()->get('subscriptions');
322 322
 }
323 323
 
324 324
 /**
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
  *
327 327
  * @return WPInv_Subscription|bool
328 328
  */
329
-function wpinv_get_subscription( $invoice ) {
329
+function wpinv_get_subscription($invoice) {
330 330
 
331 331
     // Retrieve the invoice.
332
-    $invoice = new WPInv_Invoice( $invoice );
332
+    $invoice = new WPInv_Invoice($invoice);
333 333
 
334 334
     // Ensure it is a recurring invoice.
335
-    if ( ! $invoice->is_recurring() ) {
335
+    if (!$invoice->is_recurring()) {
336 336
         return false;
337 337
     }
338 338
 
@@ -344,6 +344,6 @@  discard block
 block discarded – undo
344 344
 		)
345 345
 	);
346 346
 
347
-	return empty( $subscription ) ? false : $subscription[0];
347
+	return empty($subscription) ? false : $subscription[0];
348 348
 
349 349
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 1 patch
Spacing   +11 added lines, -11 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
  * Manual Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription' );
27
+    protected $supports = array('subscription');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	public function __construct() {
40 40
         parent::__construct();
41 41
 
42
-        $this->title        = __( 'Manual Payment', 'invoicing' );
43
-        $this->method_title = __( 'Manual Payment', 'invoicing' );
42
+        $this->title        = __('Manual Payment', 'invoicing');
43
+        $this->method_title = __('Manual Payment', 'invoicing');
44 44
 
45
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
45
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
46 46
     }
47 47
 
48 48
     /**
@@ -54,16 +54,16 @@  discard block
 block discarded – undo
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55 55
 	 * @return array
56 56
 	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+	public function process_payment($invoice, $submission_data, $submission) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
61 61
 
62 62
         // (Maybe) activate subscription.
63
-        getpaid_activate_invoice_subscription( $invoice );
63
+        getpaid_activate_invoice_subscription($invoice);
64 64
 
65 65
         // Send to the success page.
66
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
66
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
67 67
 
68 68
     }
69 69
 
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
 	 * @param bool $should_expire
75 75
      * @param WPInv_Subscription $subscription
76 76
 	 */
77
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
77
+	public function maybe_renew_subscription($should_expire, $subscription) {
78 78
 
79 79
         // Ensure its our subscription && it's active.
80
-        if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
80
+        if ('manual' != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
81 81
             return $should_expire;
82 82
         }
83 83
 
84 84
         // If this is the last renewal, complete the subscription.
85
-        if ( $subscription->is_last_renewal() ) {
85
+        if ($subscription->is_last_renewal()) {
86 86
             $subscription->complete();
87 87
             return false;
88 88
         }
Please login to merge, or discard this patch.