Passed
Pull Request — master (#262)
by Brian
04:33
created
templates/emails/wpinv-email-invoice-items.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat, $ajax_cart_details;
@@ -10,153 +10,153 @@  discard block
 block discarded – undo
10 10
 $invoice_id         = $invoice->ID;
11 11
 $quantities_enabled = wpinv_item_quantities_enabled();
12 12
 $use_taxes          = wpinv_use_taxes();
13
-$zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
14
-$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
15
-$tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
13
+$zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
14
+$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
15
+$tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
16 16
 
17
-do_action( 'wpinv_before_email_items', $invoice ); ?>
17
+do_action('wpinv_before_email_items', $invoice); ?>
18 18
 <div id="wpinv-email-items">
19
-    <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3>
19
+    <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3>
20 20
     <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
21 21
         <thead>
22 22
             <tr class="wpinv_cart_header_row">
23
-                <?php do_action( 'wpinv_email_items_table_header_first' ); ?>
24
-                <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
25
-                <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
26
-                <?php if ( $quantities_enabled ) { ?>
27
-                <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
23
+                <?php do_action('wpinv_email_items_table_header_first'); ?>
24
+                <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
25
+                <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
26
+                <?php if ($quantities_enabled) { ?>
27
+                <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
28 28
                 <?php } ?>
29
-                <?php if ( !$zero_tax && $use_taxes ) { ?>
29
+                <?php if (!$zero_tax && $use_taxes) { ?>
30 30
                 <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
31 31
                 <?php } ?>
32
-                <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
-                <?php do_action( 'wpinv_email_items_table_header_last' ); ?>
32
+                <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
+                <?php do_action('wpinv_email_items_table_header_last'); ?>
34 34
             </tr>
35 35
         </thead>
36 36
         <tbody>
37 37
             <?php
38
-                do_action( 'wpinv_email_items_before' );
39
-                if ( $cart_items ) {
40
-                    foreach ( $cart_items as $key => $item ) {
41
-                        $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL;
38
+                do_action('wpinv_email_items_before');
39
+                if ($cart_items) {
40
+                    foreach ($cart_items as $key => $item) {
41
+                        $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL;
42 42
                     ?>
43
-                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
44
-                        <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?>
43
+                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
44
+                        <?php do_action('wpinv_email_items_table_body_first', $item); ?>
45 45
                         <td class="wpinv_cart_item_name text-left">
46 46
                             <?php
47
-                                if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
47
+                                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
48 48
                                     echo '<div class="wpinv_cart_item_image">';
49
-                                        echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
49
+                                        echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
50 50
                                     echo '</div>';
51 51
                                 }
52
-                                $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
52
+                                $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
53 53
                                 echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>';
54 54
                                 
55
-                                $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice );
56
-                                if ( !empty( $summary ) ) {
55
+                                $summary = apply_filters('wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice);
56
+                                if (!empty($summary)) {
57 57
                                     echo '<p class="small">' . $summary . '</p>';
58 58
                                 }
59 59
     
60
-                                do_action( 'wpinv_email_cart_item_title_after', $item, $key );
60
+                                do_action('wpinv_email_cart_item_title_after', $item, $key);
61 61
                             ?>
62 62
                         </td>
63 63
                         <td class="wpinv_cart_item_price text-right">
64 64
                             <?php 
65
-                            echo wpinv_cart_item_price( $item );
66
-                            do_action( 'wpinv_email_cart_item_price_after', $item, $key );
65
+                            echo wpinv_cart_item_price($item);
66
+                            do_action('wpinv_email_cart_item_price_after', $item, $key);
67 67
                             ?>
68 68
                         </td>
69
-                        <?php if ( $quantities_enabled ) { ?>
69
+                        <?php if ($quantities_enabled) { ?>
70 70
                         <td class="wpinv_cart_item_qty text-right">
71 71
                             <?php
72
-                            echo wpinv_get_cart_item_quantity( $item );
73
-                            do_action( 'wpinv_email_item_quantitiy', $item, $key );
72
+                            echo wpinv_get_cart_item_quantity($item);
73
+                            do_action('wpinv_email_item_quantitiy', $item, $key);
74 74
                             ?>
75 75
                         </td>
76 76
                         <?php } ?>
77
-                        <?php if ( !$zero_tax && $use_taxes ) { ?>
77
+                        <?php if (!$zero_tax && $use_taxes) { ?>
78 78
                         <td class="wpinv_cart_item_tax text-right">
79 79
                             <?php
80
-                            echo wpinv_cart_item_tax( $item );
81
-                            do_action( 'wpinv_email_item_tax', $item, $key );
80
+                            echo wpinv_cart_item_tax($item);
81
+                            do_action('wpinv_email_item_tax', $item, $key);
82 82
                             ?>
83 83
                         </td>
84 84
                         <?php } ?>
85 85
                         <td class="wpinv_cart_item_subtotal text-right">
86 86
                             <?php
87
-                            echo wpinv_cart_item_subtotal( $item );
88
-                            do_action( 'wpinv_email_item_subtotal', $item, $key );
87
+                            echo wpinv_cart_item_subtotal($item);
88
+                            do_action('wpinv_email_item_subtotal', $item, $key);
89 89
                             ?>
90 90
                         </td>
91
-                        <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?>
91
+                        <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?>
92 92
                     </tr>
93 93
                 <?php } ?>
94 94
             <?php } ?>
95
-            <?php do_action( 'wpinv_email_items_middle' ); ?>
96
-            <?php do_action( 'wpinv_email_items_after' ); ?>
95
+            <?php do_action('wpinv_email_items_middle'); ?>
96
+            <?php do_action('wpinv_email_items_after'); ?>
97 97
         </tbody>
98 98
         <tfoot>
99
-            <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?>
100
-            <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?>
99
+            <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?>
100
+            <?php if (has_action('wpinv_email_footer_buttons')) { ?>
101 101
                 <tr class="wpinv_cart_footer_row">
102
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
103
-                    <td colspan="<?php echo ( $cart_columns ); ?>">
104
-                        <?php do_action( 'wpinv_email_footer_buttons' ); ?>
102
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
103
+                    <td colspan="<?php echo ($cart_columns); ?>">
104
+                        <?php do_action('wpinv_email_footer_buttons'); ?>
105 105
                     </td>
106
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
106
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
107 107
                 </tr>
108 108
             <?php } ?>
109 109
 
110
-            <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?>
110
+            <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?>
111 111
                 <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row">
112
-                    <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?>
113
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
114
-                        <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
112
+                    <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?>
113
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
114
+                        <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
115 115
                     </td>
116 116
                     <td class="wpinv_cart_subtotal text-right">
117
-                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span>
117
+                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span>
118 118
                     </td>
119
-                    <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?>
119
+                    <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?>
120 120
                 </tr>
121 121
             <?php } ?>
122 122
             
123
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
123
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
124 124
                 <tr class="wpinv_cart_footer_row wpinv_cart_discount_row">
125
-                    <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?>
126
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right">
127
-                        <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong>
125
+                    <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?>
126
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right">
127
+                        <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong>
128 128
                     </td>
129 129
                     <td class="wpinv_cart_discount text-right">
130
-                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span>
130
+                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span>
131 131
                     </td>
132
-                    <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?>
132
+                    <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?>
133 133
                 </tr>
134 134
             <?php } ?>
135 135
 
136
-            <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?>
136
+            <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?>
137 137
                 <tr class="wpinv_cart_footer_row wpinv_cart_tax_row">
138
-                    <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?>
139
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
138
+                    <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?>
139
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
140 140
                         <strong><?php echo $tax_label; ?>:</strong>
141 141
                     </td>
142 142
                     <td class="wpinv_cart_tax text-right">
143
-                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span>
143
+                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span>
144 144
                     </td>
145
-                    <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?>
145
+                    <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?>
146 146
                 </tr>
147 147
             <?php } ?>
148 148
 
149 149
             <tr class="wpinv_cart_footer_row">
150
-                <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?>
151
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
152
-                    <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
150
+                <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?>
151
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
152
+                    <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
153 153
                 </td>
154 154
                 <td class="wpinv_cart_total text-right">
155
-                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span>
155
+                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span>
156 156
                 </td>
157
-                <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?>
157
+                <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?>
158 158
             </tr>
159 159
         </tfoot>
160 160
     </table>
161 161
 </div>
162
-<?php do_action( 'wpinv_after_email_items', $invoice ); ?>
163 162
\ No newline at end of file
163
+<?php do_action('wpinv_after_email_items', $invoice); ?>
164 164
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-invoice-receipt.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@  discard block
 block discarded – undo
4 4
  */
5 5
 global $wpinv_receipt_args;
6 6
 
7
-$invoice   = get_post( $wpinv_receipt_args['id'] );
7
+$invoice = get_post($wpinv_receipt_args['id']);
8 8
 
9
-if( empty( $invoice ) ) {
9
+if (empty($invoice)) {
10 10
     ?>
11 11
     <div class="wpinv_errors alert wpi-alert-error">
12
-        <?php _e( 'The specified receipt ID appears to be invalid', 'invoicing' ); ?>
12
+        <?php _e('The specified receipt ID appears to be invalid', 'invoicing'); ?>
13 13
     </div>
14 14
     <?php
15 15
     return;
16 16
 }
17
-$invoice = wpinv_get_invoice( $invoice->ID );
17
+$invoice = wpinv_get_invoice($invoice->ID);
18 18
 
19 19
 global $ajax_cart_details;
20 20
 $ajax_cart_details = $invoice->get_cart_details();
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
 $invoice_id         = $invoice->ID;
24 24
 $quantities_enabled = wpinv_item_quantities_enabled();
25 25
 $use_taxes          = wpinv_use_taxes();
26
-$zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
27
-$tax_label          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? __( '(Tax Incl.)', 'invoicing' ) : __( '(Tax Excl.)', 'invoicing' ) ) : '';
26
+$zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
27
+$tax_label          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? __('(Tax Incl.)', 'invoicing') : __('(Tax Excl.)', 'invoicing')) : '';
28 28
 ?>
29
-<?php do_action( 'wpinv_before_receipt', $invoice ); ?>
29
+<?php do_action('wpinv_before_receipt', $invoice); ?>
30 30
 <div class="wpinv-receipt">
31
-    <?php do_action( 'wpinv_receipt_start', $invoice ); ?>
32
-    <div class="wpinv-receipt-message"><?php _e( 'Thank you for your payment!', 'invoicing' ); ?></div>
33
-    <?php do_action( 'wpinv_before_receipt_details', $invoice ); ?>
31
+    <?php do_action('wpinv_receipt_start', $invoice); ?>
32
+    <div class="wpinv-receipt-message"><?php _e('Thank you for your payment!', 'invoicing'); ?></div>
33
+    <?php do_action('wpinv_before_receipt_details', $invoice); ?>
34 34
     <div class="wpinv-receipt-details">
35
-        <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3>
36
-        <?php wpinv_display_invoice_details( $invoice ); ?>
35
+        <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing')); ?></h3>
36
+        <?php wpinv_display_invoice_details($invoice); ?>
37 37
     </div>
38
-    <?php do_action( 'wpinv_after_receipt_details', $invoice ); ?>
39
-    <?php do_action( 'wpinv_receipt_end', $invoice ); ?>
38
+    <?php do_action('wpinv_after_receipt_details', $invoice); ?>
39
+    <?php do_action('wpinv_receipt_end', $invoice); ?>
40 40
 </div>
41
-<?php do_action( 'wpinv_after_receipt', $invoice ); ?>
42 41
\ No newline at end of file
42
+<?php do_action('wpinv_after_receipt', $invoice); ?>
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +480 added lines, -480 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@  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
 function wpinv_get_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array) apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!wpinv_current_user_can_manage_invoicing()) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!wpinv_current_user_can_manage_invoicing()) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!wpinv_current_user_can_manage_invoicing()) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
97 97
     return false;
98 98
 }
99 99
 
100
-function wpinv_get_all_discounts( $args = array() ) {
100
+function wpinv_get_all_discounts($args = array()) {
101 101
 
102
-    $args = wp_parse_args( $args, array(
103
-        'status'         => array( 'publish' ),
104
-        'limit'          => get_option( 'posts_per_page' ),
102
+    $args = wp_parse_args($args, array(
103
+        'status'         => array('publish'),
104
+        'limit'          => get_option('posts_per_page'),
105 105
         'page'           => 1,
106 106
         'exclude'        => array(),
107 107
         'orderby'        => 'date',
108 108
         'order'          => 'DESC',
109
-        'type'           => array_keys( wpinv_get_discount_types() ),
109
+        'type'           => array_keys(wpinv_get_discount_types()),
110 110
         'meta_query'     => array(),
111 111
         'return'         => 'objects',
112 112
         'paginate'       => false,
113
-    ) );
113
+    ));
114 114
 
115 115
     $wp_query_args = array(
116 116
         'post_type'      => 'wpi_discount',
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
         'fields'         => 'ids',
121 121
         'orderby'        => $args['orderby'],
122 122
         'order'          => $args['order'],
123
-        'paged'          => absint( $args['page'] ),
123
+        'paged'          => absint($args['page']),
124 124
     );
125 125
 
126
-    if ( ! empty( $args['exclude'] ) ) {
127
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
126
+    if (!empty($args['exclude'])) {
127
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
128 128
     }
129 129
 
130
-    if ( ! $args['paginate' ] ) {
130
+    if (!$args['paginate']) {
131 131
         $wp_query_args['no_found_rows'] = true;
132 132
     }
133 133
 
134
-    if ( ! empty( $args['search'] ) ) {
134
+    if (!empty($args['search'])) {
135 135
 
136 136
         $wp_query_args['meta_query'][] = array(
137 137
             'key'     => '_wpi_discount_code',
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 
142 142
     }
143 143
     
144
-    if ( ! empty( $args['type'] ) ) {
145
-        $types = wpinv_parse_list( $args['type'] );
144
+    if (!empty($args['type'])) {
145
+        $types = wpinv_parse_list($args['type']);
146 146
         $wp_query_args['meta_query'][] = array(
147 147
             'key'     => '_wpi_discount_type',
148
-            'value'   => implode( ',', $types ),
148
+            'value'   => implode(',', $types),
149 149
             'compare' => 'IN',
150 150
         );
151 151
     }
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
     $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args);
154 154
 
155 155
     // Get results.
156
-    $discounts = new WP_Query( $wp_query_args );
156
+    $discounts = new WP_Query($wp_query_args);
157 157
 
158
-    if ( 'objects' === $args['return'] ) {
159
-        $return = array_map( 'get_post', $discounts->posts );
160
-    } elseif ( 'self' === $args['return'] ) {
158
+    if ('objects' === $args['return']) {
159
+        $return = array_map('get_post', $discounts->posts);
160
+    } elseif ('self' === $args['return']) {
161 161
         return $discounts;
162 162
     } else {
163 163
         $return = $discounts->posts;
164 164
     }
165 165
 
166
-    if ( $args['paginate' ] ) {
166
+    if ($args['paginate']) {
167 167
         return (object) array(
168 168
             'discounts'      => $return,
169 169
             'total'         => $discounts->found_posts,
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 
181 181
     $discounts  = wpinv_get_discounts();
182 182
 
183
-    if ( $discounts) {
184
-        foreach ( $discounts as $discount ) {
185
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
183
+    if ($discounts) {
184
+        foreach ($discounts as $discount) {
185
+            if (wpinv_is_discount_active($discount->ID)) {
186 186
                 $has_active = true;
187 187
                 break;
188 188
             }
@@ -191,38 +191,38 @@  discard block
 block discarded – undo
191 191
     return $has_active;
192 192
 }
193 193
 
194
-function wpinv_get_discount( $discount_id = 0 ) {
195
-    if( empty( $discount_id ) ) {
194
+function wpinv_get_discount($discount_id = 0) {
195
+    if (empty($discount_id)) {
196 196
         return false;
197 197
     }
198 198
     
199
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
199
+    if (get_post_type($discount_id) != 'wpi_discount') {
200 200
         return false;
201 201
     }
202 202
 
203
-    $discount = get_post( $discount_id );
203
+    $discount = get_post($discount_id);
204 204
 
205 205
     return $discount;
206 206
 }
207 207
 
208
-function wpinv_get_discount_by_code( $code = '' ) {
209
-    if( empty( $code ) || ! is_string( $code ) ) {
208
+function wpinv_get_discount_by_code($code = '') {
209
+    if (empty($code) || !is_string($code)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    return wpinv_get_discount_by( 'code', $code );
213
+    return wpinv_get_discount_by('code', $code);
214 214
 }
215 215
 
216
-function wpinv_get_discount_by( $field = '', $value = '' ) {
217
-    if( empty( $field ) || empty( $value ) ) {
216
+function wpinv_get_discount_by($field = '', $value = '') {
217
+    if (empty($field) || empty($value)) {
218 218
         return false;
219 219
     }
220 220
 
221
-    if( ! is_string( $field ) ) {
221
+    if (!is_string($field)) {
222 222
         return false;
223 223
     }
224 224
 
225
-    switch( strtolower( $field ) ) {
225
+    switch (strtolower($field)) {
226 226
 
227 227
         case 'code':
228 228
             $meta_query     = array();
@@ -232,32 +232,32 @@  discard block
 block discarded – undo
232 232
                 'compare' => '='
233 233
             );
234 234
             
235
-            $discount = wpinv_get_discounts( array(
235
+            $discount = wpinv_get_discounts(array(
236 236
                 'posts_per_page' => 1,
237 237
                 'post_status'    => 'any',
238 238
                 'meta_query'     => $meta_query,
239
-            ) );
239
+            ));
240 240
             
241
-            if( $discount ) {
241
+            if ($discount) {
242 242
                 $discount = $discount[0];
243 243
             }
244 244
 
245 245
             break;
246 246
 
247 247
         case 'id':
248
-            $discount = wpinv_get_discount( $value );
248
+            $discount = wpinv_get_discount($value);
249 249
 
250 250
             break;
251 251
 
252 252
         case 'name':
253
-            $discount = get_posts( array(
253
+            $discount = get_posts(array(
254 254
                 'post_type'      => 'wpi_discount',
255 255
                 'name'           => $value,
256 256
                 'posts_per_page' => 1,
257 257
                 'post_status'    => 'any'
258
-            ) );
258
+            ));
259 259
 
260
-            if( $discount ) {
260
+            if ($discount) {
261 261
                 $discount = $discount[0];
262 262
             }
263 263
 
@@ -267,96 +267,96 @@  discard block
 block discarded – undo
267 267
             return false;
268 268
     }
269 269
 
270
-    if( ! empty( $discount ) ) {
270
+    if (!empty($discount)) {
271 271
         return $discount;
272 272
     }
273 273
 
274 274
     return false;
275 275
 }
276 276
 
277
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
277
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
278 278
     $meta = array(
279
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
280
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
281
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
282
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
283
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
284
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
285
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
286
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
287
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
288
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
289
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
290
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
291
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
279
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
280
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
281
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
282
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
283
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
284
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
285
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
286
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
287
+        'items'             => isset($data['items']) ? $data['items'] : array(),
288
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
289
+        'is_recurring'      => isset($data['recurring']) ? (bool) $data['recurring'] : false,
290
+        'is_single_use'     => isset($data['single_use']) ? (bool) $data['single_use'] : false,
291
+        'uses'              => isset($data['uses']) ? (int) $data['uses'] : false,
292 292
     );
293 293
 
294
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
294
+    if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) {
295 295
         $meta['amount'] = 100;
296 296
     }
297 297
 
298
-    if ( !empty( $meta['start'] ) ) {
299
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
298
+    if (!empty($meta['start'])) {
299
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
300 300
     }
301 301
 
302
-    if ( !empty( $meta['expiration'] ) ) {
303
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
302
+    if (!empty($meta['expiration'])) {
303
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
304 304
 
305
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
305
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
306 306
             $meta['expiration'] = $meta['start'];
307 307
         }
308 308
     }
309 309
     
310
-    if ( $meta['uses'] === false ) {
311
-        unset( $meta['uses'] );
310
+    if ($meta['uses'] === false) {
311
+        unset($meta['uses']);
312 312
     }
313 313
     
314
-    if ( ! empty( $meta['items'] ) ) {
315
-        foreach ( $meta['items'] as $key => $item ) {
316
-            if ( 0 === intval( $item ) ) {
317
-                unset( $meta['items'][ $key ] );
314
+    if (!empty($meta['items'])) {
315
+        foreach ($meta['items'] as $key => $item) {
316
+            if (0 === intval($item)) {
317
+                unset($meta['items'][$key]);
318 318
             }
319 319
         }
320 320
     }
321 321
     
322
-    if ( ! empty( $meta['excluded_items'] ) ) {
323
-        foreach ( $meta['excluded_items'] as $key => $item ) {
324
-            if ( 0 === intval( $item ) ) {
325
-                unset( $meta['excluded_items'][ $key ] );
322
+    if (!empty($meta['excluded_items'])) {
323
+        foreach ($meta['excluded_items'] as $key => $item) {
324
+            if (0 === intval($item)) {
325
+                unset($meta['excluded_items'][$key]);
326 326
             }
327 327
         }
328 328
     }
329 329
     
330
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
330
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
331 331
     
332
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
332
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
333 333
     
334
-    foreach( $meta as $key => $value ) {
335
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
334
+    foreach ($meta as $key => $value) {
335
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
336 336
     }
337 337
     
338
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
338
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
339 339
     
340 340
     return $post_id;
341 341
 }
342 342
 
343
-function wpinv_remove_discount( $discount_id = 0 ) {
344
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
343
+function wpinv_remove_discount($discount_id = 0) {
344
+    do_action('wpinv_pre_delete_discount', $discount_id);
345 345
 
346
-    wp_delete_post( $discount_id, true );
346
+    wp_delete_post($discount_id, true);
347 347
 
348
-    do_action( 'wpinv_post_delete_discount', $discount_id );
348
+    do_action('wpinv_post_delete_discount', $discount_id);
349 349
 }
350 350
 
351
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
352
-    $discount = wpinv_get_discount(  $code_id );
351
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
352
+    $discount = wpinv_get_discount($code_id);
353 353
 
354
-    if ( $discount ) {
355
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
354
+    if ($discount) {
355
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
356 356
 
357
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
357
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
358 358
 
359
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
359
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
360 360
 
361 361
         return true;
362 362
     }
@@ -364,173 +364,173 @@  discard block
 block discarded – undo
364 364
     return false;
365 365
 }
366 366
 
367
-function wpinv_discount_exists( $code_id ) {
368
-    if ( wpinv_get_discount(  $code_id ) ) {
367
+function wpinv_discount_exists($code_id) {
368
+    if (wpinv_get_discount($code_id)) {
369 369
         return true;
370 370
     }
371 371
 
372 372
     return false;
373 373
 }
374 374
 
375
-function wpinv_is_discount_active( $code_id = null ) {
376
-    $discount = wpinv_get_discount(  $code_id );
375
+function wpinv_is_discount_active($code_id = null) {
376
+    $discount = wpinv_get_discount($code_id);
377 377
     $return   = false;
378 378
 
379
-    if ( $discount ) {
380
-        if ( wpinv_is_discount_expired( $code_id ) ) {
381
-            if( defined( 'DOING_AJAX' ) ) {
382
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
379
+    if ($discount) {
380
+        if (wpinv_is_discount_expired($code_id)) {
381
+            if (defined('DOING_AJAX')) {
382
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
383 383
             }
384
-        } elseif ( $discount->post_status == 'publish' ) {
384
+        } elseif ($discount->post_status == 'publish') {
385 385
             $return = true;
386 386
         } else {
387
-            if( defined( 'DOING_AJAX' ) ) {
388
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
387
+            if (defined('DOING_AJAX')) {
388
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
389 389
             }
390 390
         }
391 391
     }
392 392
 
393
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
393
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
394 394
 }
395 395
 
396
-function wpinv_get_discount_code( $code_id = null ) {
397
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
396
+function wpinv_get_discount_code($code_id = null) {
397
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
398 398
 
399
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
399
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
400 400
 }
401 401
 
402
-function wpinv_get_discount_start_date( $code_id = null ) {
403
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
402
+function wpinv_get_discount_start_date($code_id = null) {
403
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
404 404
 
405
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
405
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
406 406
 }
407 407
 
408
-function wpinv_get_discount_expiration( $code_id = null ) {
409
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
408
+function wpinv_get_discount_expiration($code_id = null) {
409
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
410 410
 
411
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
411
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_max_uses( $code_id = null ) {
415
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
414
+function wpinv_get_discount_max_uses($code_id = null) {
415
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
416 416
 
417
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
417
+    return (int) apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
418 418
 }
419 419
 
420
-function wpinv_get_discount_uses( $code_id = null ) {
421
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
420
+function wpinv_get_discount_uses($code_id = null) {
421
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
422 422
 
423
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
423
+    return (int) apply_filters('wpinv_get_discount_uses', $uses, $code_id);
424 424
 }
425 425
 
426
-function wpinv_get_discount_min_total( $code_id = null ) {
427
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
426
+function wpinv_get_discount_min_total($code_id = null) {
427
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
428 428
 
429
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
429
+    return (float) apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
430 430
 }
431 431
 
432
-function wpinv_get_discount_max_total( $code_id = null ) {
433
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
432
+function wpinv_get_discount_max_total($code_id = null) {
433
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
434 434
 
435
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
435
+    return (float) apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
436 436
 }
437 437
 
438
-function wpinv_get_discount_amount( $code_id = null ) {
439
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
438
+function wpinv_get_discount_amount($code_id = null) {
439
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
440 440
 
441
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
441
+    return (float) apply_filters('wpinv_get_discount_amount', $amount, $code_id);
442 442
 }
443 443
 
444
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
445
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
444
+function wpinv_get_discount_type($code_id = null, $name = false) {
445
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
446 446
     
447
-    if ( $name ) {
448
-        $name = wpinv_get_discount_type_name( $type );
447
+    if ($name) {
448
+        $name = wpinv_get_discount_type_name($type);
449 449
         
450
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
450
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
451 451
     }
452 452
 
453
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
453
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
454 454
 }
455 455
 
456
-function wpinv_discount_status( $status ) {
457
-    switch( $status ){
456
+function wpinv_discount_status($status) {
457
+    switch ($status) {
458 458
         case 'expired' :
459
-            $name = __( 'Expired', 'invoicing' );
459
+            $name = __('Expired', 'invoicing');
460 460
             break;
461 461
         case 'publish' :
462 462
         case 'active' :
463
-            $name = __( 'Active', 'invoicing' );
463
+            $name = __('Active', 'invoicing');
464 464
             break;
465 465
         default :
466
-            $name = __( 'Inactive', 'invoicing' );
466
+            $name = __('Inactive', 'invoicing');
467 467
             break;
468 468
     }
469 469
     return $name;
470 470
 }
471 471
 
472
-function wpinv_get_discount_excluded_items( $code_id = null ) {
473
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
472
+function wpinv_get_discount_excluded_items($code_id = null) {
473
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
474 474
 
475
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
475
+    if (empty($excluded_items) || !is_array($excluded_items)) {
476 476
         $excluded_items = array();
477 477
     }
478 478
 
479
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
479
+    return (array) apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
480 480
 }
481 481
 
482
-function wpinv_get_discount_item_reqs( $code_id = null ) {
483
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
482
+function wpinv_get_discount_item_reqs($code_id = null) {
483
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
484 484
 
485
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
485
+    if (empty($item_reqs) || !is_array($item_reqs)) {
486 486
         $item_reqs = array();
487 487
     }
488 488
 
489
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
489
+    return (array) apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
490 490
 }
491 491
 
492
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
493
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
492
+function wpinv_get_discount_item_condition($code_id = 0) {
493
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
494 494
 }
495 495
 
496
-function wpinv_is_discount_not_global( $code_id = 0 ) {
497
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
496
+function wpinv_is_discount_not_global($code_id = 0) {
497
+    return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true);
498 498
 }
499 499
 
500
-function wpinv_is_discount_expired( $code_id = null ) {
501
-    $discount = wpinv_get_discount(  $code_id );
500
+function wpinv_is_discount_expired($code_id = null) {
501
+    $discount = wpinv_get_discount($code_id);
502 502
     $return   = false;
503 503
 
504
-    if ( $discount ) {
505
-        $expiration = wpinv_get_discount_expiration( $code_id );
506
-        if ( $expiration ) {
507
-            $expiration = strtotime( $expiration );
508
-            if ( $expiration < current_time( 'timestamp' ) ) {
504
+    if ($discount) {
505
+        $expiration = wpinv_get_discount_expiration($code_id);
506
+        if ($expiration) {
507
+            $expiration = strtotime($expiration);
508
+            if ($expiration < current_time('timestamp')) {
509 509
                 // Discount is expired
510
-                wpinv_update_discount_status( $code_id, 'pending' );
510
+                wpinv_update_discount_status($code_id, 'pending');
511 511
                 $return = true;
512 512
             }
513 513
         }
514 514
     }
515 515
 
516
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
516
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
517 517
 }
518 518
 
519
-function wpinv_is_discount_started( $code_id = null ) {
520
-    $discount = wpinv_get_discount(  $code_id );
519
+function wpinv_is_discount_started($code_id = null) {
520
+    $discount = wpinv_get_discount($code_id);
521 521
     $return   = false;
522 522
 
523
-    if ( $discount ) {
524
-        $start_date = wpinv_get_discount_start_date( $code_id );
523
+    if ($discount) {
524
+        $start_date = wpinv_get_discount_start_date($code_id);
525 525
 
526
-        if ( $start_date ) {
527
-            $start_date = strtotime( $start_date );
526
+        if ($start_date) {
527
+            $start_date = strtotime($start_date);
528 528
 
529
-            if ( $start_date < current_time( 'timestamp' ) ) {
529
+            if ($start_date < current_time('timestamp')) {
530 530
                 // Discount has past the start date
531 531
                 $return = true;
532 532
             } else {
533
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
533
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
534 534
             }
535 535
         } else {
536 536
             // No start date for this discount, so has to be true
@@ -538,159 +538,159 @@  discard block
 block discarded – undo
538 538
         }
539 539
     }
540 540
 
541
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
541
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
542 542
 }
543 543
 
544
-function wpinv_check_discount_dates( $code_id = null ) {
545
-    $discount = wpinv_get_discount(  $code_id );
544
+function wpinv_check_discount_dates($code_id = null) {
545
+    $discount = wpinv_get_discount($code_id);
546 546
     $return   = false;
547 547
 
548
-    if ( $discount ) {
549
-        $start_date = wpinv_get_discount_start_date( $code_id );
548
+    if ($discount) {
549
+        $start_date = wpinv_get_discount_start_date($code_id);
550 550
 
551
-        if ( $start_date ) {
552
-            $start_date = strtotime( $start_date );
551
+        if ($start_date) {
552
+            $start_date = strtotime($start_date);
553 553
 
554
-            if ( $start_date < current_time( 'timestamp' ) ) {
554
+            if ($start_date < current_time('timestamp')) {
555 555
                 // Discount has past the start date
556 556
                 $return = true;
557 557
             } else {
558
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
558
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
559 559
             }
560 560
         } else {
561 561
             // No start date for this discount, so has to be true
562 562
             $return = true;
563 563
         }
564 564
         
565
-        if ( $return ) {
566
-            $expiration = wpinv_get_discount_expiration( $code_id );
565
+        if ($return) {
566
+            $expiration = wpinv_get_discount_expiration($code_id);
567 567
             
568
-            if ( $expiration ) {
569
-                $expiration = strtotime( $expiration );
570
-                if ( $expiration < current_time( 'timestamp' ) ) {
568
+            if ($expiration) {
569
+                $expiration = strtotime($expiration);
570
+                if ($expiration < current_time('timestamp')) {
571 571
                     // Discount is expired
572
-                    wpinv_update_discount_status( $code_id, 'pending' );
572
+                    wpinv_update_discount_status($code_id, 'pending');
573 573
                     $return = true;
574 574
                 }
575 575
             }
576 576
         }
577 577
     }
578 578
     
579
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
579
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
580 580
 }
581 581
 
582
-function wpinv_is_discount_maxed_out( $code_id = null ) {
583
-    $discount = wpinv_get_discount(  $code_id );
582
+function wpinv_is_discount_maxed_out($code_id = null) {
583
+    $discount = wpinv_get_discount($code_id);
584 584
     $return   = false;
585 585
 
586
-    if ( $discount ) {
587
-        $uses = wpinv_get_discount_uses( $code_id );
586
+    if ($discount) {
587
+        $uses = wpinv_get_discount_uses($code_id);
588 588
         // Large number that will never be reached
589
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
589
+        $max_uses = wpinv_get_discount_max_uses($code_id);
590 590
         // Should never be greater than, but just in case
591
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
591
+        if ($uses >= $max_uses && !empty($max_uses)) {
592 592
             // Discount is maxed out
593
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
593
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
594 594
             $return = true;
595 595
         }
596 596
     }
597 597
 
598
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
598
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
599 599
 }
600 600
 
601
-function wpinv_discount_is_min_met( $code_id = null ) {
602
-    $discount = wpinv_get_discount( $code_id );
601
+function wpinv_discount_is_min_met($code_id = null) {
602
+    $discount = wpinv_get_discount($code_id);
603 603
     $return   = false;
604 604
 
605
-    if ( $discount ) {
606
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
607
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
605
+    if ($discount) {
606
+        $min         = (float) wpinv_get_discount_min_total($code_id);
607
+        $cart_amount = (float) wpinv_get_cart_discountable_subtotal($code_id);
608 608
 
609
-        if ( !$min > 0 || $cart_amount >= $min ) {
609
+        if (!$min > 0 || $cart_amount >= $min) {
610 610
             // Minimum has been met
611 611
             $return = true;
612 612
         } else {
613
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
613
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
614 614
         }
615 615
     }
616 616
 
617
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
617
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
618 618
 }
619 619
 
620
-function wpinv_discount_is_max_met( $code_id = null ) {
621
-    $discount = wpinv_get_discount( $code_id );
620
+function wpinv_discount_is_max_met($code_id = null) {
621
+    $discount = wpinv_get_discount($code_id);
622 622
     $return   = false;
623 623
 
624
-    if ( $discount ) {
625
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
626
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
624
+    if ($discount) {
625
+        $max         = (float) wpinv_get_discount_max_total($code_id);
626
+        $cart_amount = (float) wpinv_get_cart_discountable_subtotal($code_id);
627 627
 
628
-        if ( !$max > 0 || $cart_amount <= $max ) {
628
+        if (!$max > 0 || $cart_amount <= $max) {
629 629
             // Minimum has been met
630 630
             $return = true;
631 631
         } else {
632
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
632
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
633 633
         }
634 634
     }
635 635
 
636
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
636
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
637 637
 }
638 638
 
639
-function wpinv_discount_is_single_use( $code_id = 0 ) {
640
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
641
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
639
+function wpinv_discount_is_single_use($code_id = 0) {
640
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
641
+    return (bool) apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
642 642
 }
643 643
 
644
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
645
-    if ( $code ) {
646
-        $discount = wpinv_get_discount_by_code( $code_id );
644
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
645
+    if ($code) {
646
+        $discount = wpinv_get_discount_by_code($code_id);
647 647
         
648
-        if ( !empty( $discount ) ) {
648
+        if (!empty($discount)) {
649 649
             $code_id = $discount->ID;
650 650
         }
651 651
     }
652 652
     
653
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
653
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
654 654
     
655
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
655
+    return (bool) apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
656 656
 }
657 657
 
658
-function wpinv_discount_item_reqs_met( $code_id = null ) {
659
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
660
-    $condition    = wpinv_get_discount_item_condition( $code_id );
661
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
658
+function wpinv_discount_item_reqs_met($code_id = null) {
659
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
660
+    $condition    = wpinv_get_discount_item_condition($code_id);
661
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
662 662
     $cart_items   = wpinv_get_cart_contents();
663
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
663
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
664 664
     $ret          = false;
665 665
 
666
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
666
+    if (empty($item_reqs) && empty($excluded_ps)) {
667 667
         $ret = true;
668 668
     }
669 669
 
670 670
     // Normalize our data for item requirements, exclusions and cart data
671 671
     // First absint the items, then sort, and reset the array keys
672
-    $item_reqs = array_map( 'absint', $item_reqs );
673
-    asort( $item_reqs );
674
-    $item_reqs = array_values( $item_reqs );
672
+    $item_reqs = array_map('absint', $item_reqs);
673
+    asort($item_reqs);
674
+    $item_reqs = array_values($item_reqs);
675 675
 
676
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
677
-    asort( $excluded_ps );
678
-    $excluded_ps  = array_values( $excluded_ps );
676
+    $excluded_ps  = array_map('absint', $excluded_ps);
677
+    asort($excluded_ps);
678
+    $excluded_ps  = array_values($excluded_ps);
679 679
 
680
-    $cart_ids     = array_map( 'absint', $cart_ids );
681
-    asort( $cart_ids );
682
-    $cart_ids     = array_values( $cart_ids );
680
+    $cart_ids     = array_map('absint', $cart_ids);
681
+    asort($cart_ids);
682
+    $cart_ids     = array_values($cart_ids);
683 683
 
684 684
     // Ensure we have requirements before proceeding
685
-    if ( !$ret && ! empty( $item_reqs ) ) {
686
-        switch( $condition ) {
685
+    if (!$ret && !empty($item_reqs)) {
686
+        switch ($condition) {
687 687
             case 'all' :
688 688
                 // Default back to true
689 689
                 $ret = true;
690 690
 
691
-                foreach ( $item_reqs as $item_id ) {
692
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
693
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
691
+                foreach ($item_reqs as $item_id) {
692
+                    if (!wpinv_item_in_cart($item_id)) {
693
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
694 694
                         $ret = false;
695 695
                         break;
696 696
                     }
@@ -699,15 +699,15 @@  discard block
 block discarded – undo
699 699
                 break;
700 700
 
701 701
             default : // Any
702
-                foreach ( $item_reqs as $item_id ) {
703
-                    if ( wpinv_item_in_cart( $item_id ) ) {
702
+                foreach ($item_reqs as $item_id) {
703
+                    if (wpinv_item_in_cart($item_id)) {
704 704
                         $ret = true;
705 705
                         break;
706 706
                     }
707 707
                 }
708 708
 
709
-                if( ! $ret ) {
710
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
709
+                if (!$ret) {
710
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
711 711
                 }
712 712
 
713 713
                 break;
@@ -716,70 +716,70 @@  discard block
 block discarded – undo
716 716
         $ret = true;
717 717
     }
718 718
 
719
-    if( ! empty( $excluded_ps ) ) {
719
+    if (!empty($excluded_ps)) {
720 720
         // Check that there are items other than excluded ones in the cart
721
-        if( $cart_ids == $excluded_ps ) {
722
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
721
+        if ($cart_ids == $excluded_ps) {
722
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
723 723
             $ret = false;
724 724
         }
725 725
     }
726 726
 
727
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
727
+    return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
728 728
 }
729 729
 
730
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
730
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
731 731
     global $wpi_checkout_id;
732 732
     
733 733
     $return = false;
734 734
 
735
-    if ( empty( $code_id ) ) {
736
-        $code_id = wpinv_get_discount_id_by_code( $code );
735
+    if (empty($code_id)) {
736
+        $code_id = wpinv_get_discount_id_by_code($code);
737 737
         
738
-        if( empty( $code_id ) ) {
738
+        if (empty($code_id)) {
739 739
             return false; // No discount was found
740 740
         }
741 741
     }
742 742
 
743
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
743
+    if (wpinv_discount_is_single_use($code_id)) {
744 744
         $payments = array();
745 745
 
746 746
         $user_id = 0;
747
-        if ( is_int( $user ) ) {
748
-            $user_id = absint( $user );
749
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
747
+        if (is_int($user)) {
748
+            $user_id = absint($user);
749
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
750 750
             $user_id = $user_data->ID;
751
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
751
+        } else if ($user_data = get_user_by('login', $user)) {
752 752
             $user_id = $user_data->ID;
753
-        } else if ( absint( $user ) > 0 ) {
754
-            $user_id = absint( $user );
753
+        } else if (absint($user) > 0) {
754
+            $user_id = absint($user);
755 755
         }
756 756
 
757
-        if ( !empty( $user_id ) ) {
758
-            $query    = array( 'user' => $user_id, 'limit' => false );
759
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
757
+        if (!empty($user_id)) {
758
+            $query    = array('user' => $user_id, 'limit' => false);
759
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
760 760
         }
761 761
 
762
-        if ( $payments ) {
763
-            foreach ( $payments as $payment ) {
762
+        if ($payments) {
763
+            foreach ($payments as $payment) {
764 764
                 // Don't count discount used for current invoice chekcout.
765
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
765
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
766 766
                     continue;
767 767
                 }
768 768
                 
769
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
769
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
770 770
                     continue;
771 771
                 }
772 772
 
773
-                $discounts = $payment->get_discounts( true );
774
-                if ( empty( $discounts ) ) {
773
+                $discounts = $payment->get_discounts(true);
774
+                if (empty($discounts)) {
775 775
                     continue;
776 776
                 }
777 777
 
778
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
778
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
779 779
 
780
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
781
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
782
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
780
+                if (!empty($discounts) && is_array($discounts)) {
781
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
782
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
783 783
                         $return = true;
784 784
                         break;
785 785
                     }
@@ -788,61 +788,61 @@  discard block
 block discarded – undo
788 788
         }
789 789
     }
790 790
 
791
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
791
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
792 792
 }
793 793
 
794
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
794
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
795 795
     $return      = false;
796
-    $discount_id = wpinv_get_discount_id_by_code( $code );
797
-    $user        = trim( $user );
796
+    $discount_id = wpinv_get_discount_id_by_code($code);
797
+    $user        = trim($user);
798 798
 
799
-    if ( wpinv_get_cart_contents() ) {
800
-        if ( $discount_id ) {
799
+    if (wpinv_get_cart_contents()) {
800
+        if ($discount_id) {
801 801
             if (
802
-                wpinv_is_discount_active( $discount_id ) &&
803
-                wpinv_check_discount_dates( $discount_id ) &&
804
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
805
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
806
-                wpinv_discount_is_min_met( $discount_id ) &&
807
-                wpinv_discount_is_max_met( $discount_id ) &&
808
-                wpinv_discount_item_reqs_met( $discount_id )
802
+                wpinv_is_discount_active($discount_id) &&
803
+                wpinv_check_discount_dates($discount_id) &&
804
+                !wpinv_is_discount_maxed_out($discount_id) &&
805
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
806
+                wpinv_discount_is_min_met($discount_id) &&
807
+                wpinv_discount_is_max_met($discount_id) &&
808
+                wpinv_discount_item_reqs_met($discount_id)
809 809
             ) {
810 810
                 $return = true;
811 811
             }
812
-        } elseif( $set_error ) {
813
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
812
+        } elseif ($set_error) {
813
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
814 814
         }
815 815
     }
816 816
 
817
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
817
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
818 818
 }
819 819
 
820
-function wpinv_get_discount_id_by_code( $code ) {
821
-    $discount = wpinv_get_discount_by_code( $code );
822
-    if( $discount ) {
820
+function wpinv_get_discount_id_by_code($code) {
821
+    $discount = wpinv_get_discount_by_code($code);
822
+    if ($discount) {
823 823
         return $discount->ID;
824 824
     }
825 825
     return false;
826 826
 }
827 827
 
828
-function wpinv_get_discounted_amount( $code, $base_price ) {
828
+function wpinv_get_discounted_amount($code, $base_price) {
829 829
     $amount      = $base_price;
830
-    $discount_id = wpinv_get_discount_id_by_code( $code );
830
+    $discount_id = wpinv_get_discount_id_by_code($code);
831 831
 
832
-    if( $discount_id ) {
833
-        $type        = wpinv_get_discount_type( $discount_id );
834
-        $rate        = wpinv_get_discount_amount( $discount_id );
832
+    if ($discount_id) {
833
+        $type        = wpinv_get_discount_type($discount_id);
834
+        $rate        = wpinv_get_discount_amount($discount_id);
835 835
 
836
-        if ( $type == 'flat' ) {
836
+        if ($type == 'flat') {
837 837
             // Set amount
838 838
             $amount = $base_price - $rate;
839
-            if ( $amount < 0 ) {
839
+            if ($amount < 0) {
840 840
                 $amount = 0;
841 841
             }
842 842
 
843 843
         } else {
844 844
             // Percentage discount
845
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
845
+            $amount = $base_price - ($base_price * ($rate / 100));
846 846
         }
847 847
 
848 848
     } else {
@@ -851,108 +851,108 @@  discard block
 block discarded – undo
851 851
 
852 852
     }
853 853
 
854
-    return apply_filters( 'wpinv_discounted_amount', $amount );
854
+    return apply_filters('wpinv_discounted_amount', $amount);
855 855
 }
856 856
 
857
-function wpinv_increase_discount_usage( $code ) {
857
+function wpinv_increase_discount_usage($code) {
858 858
 
859
-    $id   = wpinv_get_discount_id_by_code( $code );
860
-    $uses = wpinv_get_discount_uses( $id );
859
+    $id   = wpinv_get_discount_id_by_code($code);
860
+    $uses = wpinv_get_discount_uses($id);
861 861
 
862
-    if ( $uses ) {
862
+    if ($uses) {
863 863
         $uses++;
864 864
     } else {
865 865
         $uses = 1;
866 866
     }
867 867
 
868
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
868
+    update_post_meta($id, '_wpi_discount_uses', $uses);
869 869
 
870
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
870
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
871 871
 
872 872
     return $uses;
873 873
 
874 874
 }
875 875
 
876
-function wpinv_decrease_discount_usage( $code ) {
876
+function wpinv_decrease_discount_usage($code) {
877 877
 
878
-    $id   = wpinv_get_discount_id_by_code( $code );
879
-    $uses = wpinv_get_discount_uses( $id );
878
+    $id   = wpinv_get_discount_id_by_code($code);
879
+    $uses = wpinv_get_discount_uses($id);
880 880
 
881
-    if ( $uses ) {
881
+    if ($uses) {
882 882
         $uses--;
883 883
     }
884 884
 
885
-    if ( $uses < 0 ) {
885
+    if ($uses < 0) {
886 886
         $uses = 0;
887 887
     }
888 888
 
889
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
889
+    update_post_meta($id, '_wpi_discount_uses', $uses);
890 890
 
891
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
891
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
892 892
 
893 893
     return $uses;
894 894
 
895 895
 }
896 896
 
897
-function wpinv_format_discount_rate( $type, $amount ) {
898
-    if ( $type == 'flat' ) {
899
-        return wpinv_price( wpinv_format_amount( $amount ) );
897
+function wpinv_format_discount_rate($type, $amount) {
898
+    if ($type == 'flat') {
899
+        return wpinv_price(wpinv_format_amount($amount));
900 900
     } else {
901 901
         return $amount . '%';
902 902
     }
903 903
 }
904 904
 
905
-function wpinv_set_cart_discount( $code = '' ) {    
906
-    if ( wpinv_multiple_discounts_allowed() ) {
905
+function wpinv_set_cart_discount($code = '') {    
906
+    if (wpinv_multiple_discounts_allowed()) {
907 907
         // Get all active cart discounts
908 908
         $discounts = wpinv_get_cart_discounts();
909 909
     } else {
910 910
         $discounts = false; // Only one discount allowed per purchase, so override any existing
911 911
     }
912 912
 
913
-    if ( $discounts ) {
914
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
915
-        if( false !== $key ) {
916
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
913
+    if ($discounts) {
914
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
915
+        if (false !== $key) {
916
+            unset($discounts[$key]); // Can't set the same discount more than once
917 917
         }
918 918
         $discounts[] = $code;
919 919
     } else {
920 920
         $discounts = array();
921 921
         $discounts[] = $code;
922 922
     }
923
-    $discounts = array_values( $discounts );
923
+    $discounts = array_values($discounts);
924 924
     
925 925
     $data = wpinv_get_checkout_session();
926
-    if ( empty( $data ) ) {
926
+    if (empty($data)) {
927 927
         $data = array();
928 928
     } else {
929
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
930
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
931
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
929
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
930
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
931
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
932 932
         }
933 933
     }
934 934
     $data['cart_discounts'] = $discounts;
935 935
     
936
-    wpinv_set_checkout_session( $data );
936
+    wpinv_set_checkout_session($data);
937 937
     
938 938
     return $discounts;
939 939
 }
940 940
 
941
-function wpinv_unset_cart_discount( $code = '' ) {    
941
+function wpinv_unset_cart_discount($code = '') {    
942 942
     $discounts = wpinv_get_cart_discounts();
943 943
 
944
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
945
-        $key = array_search( $code, $discounts );
946
-        unset( $discounts[ $key ] );
944
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
945
+        $key = array_search($code, $discounts);
946
+        unset($discounts[$key]);
947 947
             
948 948
         $data = wpinv_get_checkout_session();
949 949
         $data['cart_discounts'] = $discounts;
950
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
951
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
952
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
950
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
951
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
952
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
953 953
         }
954 954
         
955
-        wpinv_set_checkout_session( $data );
955
+        wpinv_set_checkout_session($data);
956 956
     }
957 957
 
958 958
     return $discounts;
@@ -961,27 +961,27 @@  discard block
 block discarded – undo
961 961
 function wpinv_unset_all_cart_discounts() {
962 962
     $data = wpinv_get_checkout_session();
963 963
     
964
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
965
-        unset( $data['cart_discounts'] );
964
+    if (!empty($data) && isset($data['cart_discounts'])) {
965
+        unset($data['cart_discounts']);
966 966
         
967
-         wpinv_set_checkout_session( $data );
967
+         wpinv_set_checkout_session($data);
968 968
          return true;
969 969
     }
970 970
     
971 971
     return false;
972 972
 }
973 973
 
974
-function wpinv_get_cart_discounts( $items = array() ) {
974
+function wpinv_get_cart_discounts($items = array()) {
975 975
     $session = wpinv_get_checkout_session();
976 976
     
977
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
977
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
978 978
     return $discounts;
979 979
 }
980 980
 
981
-function wpinv_cart_has_discounts( $items = array() ) {
981
+function wpinv_cart_has_discounts($items = array()) {
982 982
     $ret = false;
983 983
 
984
-    if ( wpinv_get_cart_discounts( $items ) ) {
984
+    if (wpinv_get_cart_discounts($items)) {
985 985
         $ret = true;
986 986
     }
987 987
     
@@ -992,131 +992,131 @@  discard block
 block discarded – undo
992 992
     }
993 993
     */
994 994
 
995
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
995
+    return apply_filters('wpinv_cart_has_discounts', $ret);
996 996
 }
997 997
 
998
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
998
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
999 999
     $amount = 0.00;
1000
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1000
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
1001 1001
 
1002
-    if ( $items ) {
1003
-        $discounts = wp_list_pluck( $items, 'discount' );
1002
+    if ($items) {
1003
+        $discounts = wp_list_pluck($items, 'discount');
1004 1004
 
1005
-        if ( is_array( $discounts ) ) {
1006
-            $discounts = array_map( 'floatval', $discounts );
1007
-            $amount    = array_sum( $discounts );
1005
+        if (is_array($discounts)) {
1006
+            $discounts = array_map('floatval', $discounts);
1007
+            $amount    = array_sum($discounts);
1008 1008
         }
1009 1009
     }
1010 1010
 
1011
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
1011
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
1012 1012
 }
1013 1013
 
1014
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
1015
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1014
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
1015
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1016 1016
     
1017
-    if ( empty( $discount ) || empty( $items ) ) {
1017
+    if (empty($discount) || empty($items)) {
1018 1018
         return 0;
1019 1019
     }
1020 1020
 
1021 1021
     $amount = 0;
1022 1022
     
1023
-    foreach ( $items as $item ) {
1024
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
1023
+    foreach ($items as $item) {
1024
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
1025 1025
     }
1026 1026
     
1027
-    $amount = wpinv_round_amount( $amount );
1027
+    $amount = wpinv_round_amount($amount);
1028 1028
 
1029 1029
     return $amount;
1030 1030
 }
1031 1031
 
1032
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
1032
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
1033 1033
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
1034 1034
     
1035 1035
     $amount = 0;
1036 1036
 
1037
-    if ( empty( $item ) || empty( $item['id'] ) ) {
1037
+    if (empty($item) || empty($item['id'])) {
1038 1038
         return $amount;
1039 1039
     }
1040 1040
 
1041
-    if ( empty( $item['quantity'] ) ) {
1041
+    if (empty($item['quantity'])) {
1042 1042
         return $amount;
1043 1043
     }
1044 1044
 
1045
-    if ( empty( $item['options'] ) ) {
1045
+    if (empty($item['options'])) {
1046 1046
         $item['options'] = array();
1047 1047
     }
1048 1048
 
1049
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
1049
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
1050 1050
     $discounted_price = $price;
1051 1051
 
1052 1052
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
1053
-    if ( empty( $discounts ) ) {
1053
+    if (empty($discounts)) {
1054 1054
         return $amount;
1055 1055
     }
1056 1056
 
1057
-    if ( $discounts ) {
1058
-        if ( is_array( $discounts ) ) {
1059
-            $discounts = array_values( $discounts );
1057
+    if ($discounts) {
1058
+        if (is_array($discounts)) {
1059
+            $discounts = array_values($discounts);
1060 1060
         } else {
1061
-            $discounts = explode( ',', $discounts );
1061
+            $discounts = explode(',', $discounts);
1062 1062
         }
1063 1063
     }
1064 1064
 
1065
-    if( $discounts ) {
1066
-        foreach ( $discounts as $discount ) {
1067
-            $code_id = wpinv_get_discount_id_by_code( $discount );
1065
+    if ($discounts) {
1066
+        foreach ($discounts as $discount) {
1067
+            $code_id = wpinv_get_discount_id_by_code($discount);
1068 1068
 
1069 1069
             // Check discount exists
1070
-            if( ! $code_id ) {
1070
+            if (!$code_id) {
1071 1071
                 continue;
1072 1072
             }
1073 1073
 
1074
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
1075
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
1074
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
1075
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
1076 1076
 
1077 1077
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1078
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1079
-                foreach ( $reqs as $item_id ) {
1080
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1081
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1078
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1079
+                foreach ($reqs as $item_id) {
1080
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1081
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1082 1082
                     }
1083 1083
                 }
1084 1084
             } else {
1085 1085
                 // This is a global cart discount
1086
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1087
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1086
+                if (!in_array($item['id'], $excluded_items)) {
1087
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1088 1088
                         $items_subtotal    = 0.00;
1089 1089
                         $cart_items        = wpinv_get_cart_contents();
1090 1090
                         
1091
-                        foreach ( $cart_items as $cart_item ) {
1092
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1093
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1094
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1091
+                        foreach ($cart_items as $cart_item) {
1092
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1093
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1094
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1095 1095
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1096 1096
                             }
1097 1097
                         }
1098 1098
 
1099
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1100
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1099
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1100
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1101 1101
                         $discounted_amount = $code_amount * $subtotal_percent;
1102 1102
                         $discounted_price -= $discounted_amount;
1103 1103
 
1104
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1104
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1105 1105
 
1106
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1106
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1107 1107
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1108 1108
                             $discounted_price -= $adjustment;
1109 1109
                         }
1110 1110
                     } else {
1111
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1111
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1112 1112
                     }
1113 1113
                 }
1114 1114
             }
1115 1115
         }
1116 1116
 
1117
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1117
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1118 1118
 
1119
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1119
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1120 1120
             $amount = $amount * $item['quantity'];
1121 1121
         }
1122 1122
     }
@@ -1124,59 +1124,59 @@  discard block
 block discarded – undo
1124 1124
     return $amount;
1125 1125
 }
1126 1126
 
1127
-function wpinv_cart_discounts_html( $items = array() ) {
1128
-    echo wpinv_get_cart_discounts_html( $items );
1127
+function wpinv_cart_discounts_html($items = array()) {
1128
+    echo wpinv_get_cart_discounts_html($items);
1129 1129
 }
1130 1130
 
1131
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1131
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1132 1132
     global $wpi_cart_columns;
1133 1133
     
1134
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1134
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1135 1135
     
1136
-    if ( !$discounts ) {
1137
-        $discounts = wpinv_get_cart_discounts( $items );
1136
+    if (!$discounts) {
1137
+        $discounts = wpinv_get_cart_discounts($items);
1138 1138
     }
1139 1139
 
1140
-    if ( !$discounts ) {
1140
+    if (!$discounts) {
1141 1141
         return;
1142 1142
     }
1143 1143
     
1144
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1144
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1145 1145
     
1146 1146
     $html = '';
1147 1147
 
1148
-    foreach ( $discounts as $discount ) {
1149
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1150
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1151
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1152
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1153
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1148
+    foreach ($discounts as $discount) {
1149
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1150
+        $discount_value = wpinv_get_discount_amount($discount_id);
1151
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1152
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1153
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1154 1154
         
1155 1155
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1156 1156
         ob_start();
1157
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1157
+        do_action('wpinv_checkout_table_discount_first', $items);
1158 1158
         $html .= ob_get_clean();
1159
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1159
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1160 1160
         ob_start();
1161
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1161
+        do_action('wpinv_checkout_table_discount_last', $items);
1162 1162
         $html .= ob_get_clean();
1163 1163
         $html .= '</tr>';
1164 1164
     }
1165 1165
 
1166
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1166
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1169
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1170 1170
     $discounts = wpinv_get_cart_discounts();
1171 1171
 
1172
-    if ( empty( $discounts ) ) {
1172
+    if (empty($discounts)) {
1173 1173
         return false;
1174 1174
     }
1175 1175
 
1176
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1177
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1176
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1177
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1178 1178
 
1179
-    if ( $echo ) {
1179
+    if ($echo) {
1180 1180
         echo $amount;
1181 1181
     }
1182 1182
 
@@ -1184,101 +1184,101 @@  discard block
 block discarded – undo
1184 1184
 }
1185 1185
 
1186 1186
 function wpinv_remove_cart_discount() {
1187
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1187
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1188 1188
         return;
1189 1189
     }
1190 1190
 
1191
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1191
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1192 1192
 
1193
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1193
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1194 1194
 
1195
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1195
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1196 1196
 
1197
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1197
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1198 1198
 }
1199
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1199
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1200 1200
 
1201
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1201
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1202 1202
     $discounts = wpinv_get_cart_discounts();
1203 1203
 
1204
-    if ( !$discounts ) {
1204
+    if (!$discounts) {
1205 1205
         return;
1206 1206
     }
1207 1207
 
1208
-    foreach ( $discounts as $discount ) {
1209
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1210
-            wpinv_unset_cart_discount( $discount );
1208
+    foreach ($discounts as $discount) {
1209
+        if (!wpinv_is_discount_valid($discount)) {
1210
+            wpinv_unset_cart_discount($discount);
1211 1211
         }
1212 1212
     }
1213 1213
 }
1214
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1214
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1215 1215
 
1216 1216
 function wpinv_multiple_discounts_allowed() {
1217
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1218
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1217
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1218
+    return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret);
1219 1219
 }
1220 1220
 
1221
-function wpinv_get_discount_label( $code, $echo = true ) {
1222
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1223
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1221
+function wpinv_get_discount_label($code, $echo = true) {
1222
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1223
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1224 1224
 
1225
-    if ( $echo ) {
1225
+    if ($echo) {
1226 1226
         echo $label;
1227 1227
     } else {
1228 1228
         return $label;
1229 1229
     }
1230 1230
 }
1231 1231
 
1232
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1233
-    $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code );
1234
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1232
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1233
+    $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code);
1234
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1235 1235
 
1236
-    if ( $echo ) {
1236
+    if ($echo) {
1237 1237
         echo $label;
1238 1238
     } else {
1239 1239
         return $label;
1240 1240
     }
1241 1241
 }
1242 1242
 
1243
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1244
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1243
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1244
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1245 1245
         return true;
1246 1246
     }
1247 1247
     
1248 1248
     return $check;
1249 1249
 }
1250
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1250
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1251 1251
 
1252 1252
 function wpinv_checkout_form_validate_discounts() {
1253 1253
     global $wpi_checkout_id;
1254 1254
     
1255 1255
     $discounts = wpinv_get_cart_discounts();
1256 1256
     
1257
-    if ( !empty( $discounts ) ) {
1257
+    if (!empty($discounts)) {
1258 1258
         $invalid = false;
1259 1259
         
1260
-        foreach ( $discounts as $key => $code ) {
1261
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1260
+        foreach ($discounts as $key => $code) {
1261
+            if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) {
1262 1262
                 $invalid = true;
1263 1263
                 
1264
-                wpinv_unset_cart_discount( $code );
1264
+                wpinv_unset_cart_discount($code);
1265 1265
             }
1266 1266
         }
1267 1267
         
1268
-        if ( $invalid ) {
1268
+        if ($invalid) {
1269 1269
             $errors = wpinv_get_errors();
1270
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1271
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1272
-            wpinv_set_error( 'wpinv-discount-error', $error );
1270
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1271
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1272
+            wpinv_set_error('wpinv-discount-error', $error);
1273 1273
             
1274
-            wpinv_recalculate_tax( true );
1274
+            wpinv_recalculate_tax(true);
1275 1275
         }
1276 1276
     }
1277 1277
 }
1278
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1278
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1279 1279
 
1280 1280
 function wpinv_discount_amount() {
1281 1281
     $output = 0.00;
1282 1282
     
1283
-    return apply_filters( 'wpinv_discount_amount', $output );
1283
+    return apply_filters('wpinv_discount_amount', $output);
1284 1284
 }
1285 1285
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-api.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
10
+if (!defined('WPINC')) {
11 11
     exit;
12 12
 }
13 13
 
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     /**
20 20
      * @param string A prefix for our REST routes
21 21
      */
22
-    public $api_namespace    = '';
22
+    public $api_namespace = '';
23 23
 
24 24
     /**
25 25
      * @param WPInv_REST_Invoice_Controller Invoices controller
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
      * @since 1.0.13
38 38
      * Sets the API namespace and inits hooks
39 39
      */
40
-    public function __construct( $api_namespace = 'invoicing/v1' ) {
40
+    public function __construct($api_namespace = 'invoicing/v1') {
41 41
 
42 42
         // Include controllers and related files
43 43
         $this->includes();
44 44
 
45 45
         // Set up class variables
46
-        $this->api_namespace       = apply_filters( 'wpinv_rest_api_namespace', $api_namespace );
47
-        $this->invoices_controller = new WPInv_REST_Invoice_Controller( $this->api_namespace );
48
-        $this->items_controller    = new WPInv_REST_Items_Controller( $this->api_namespace );
49
-        $this->discounts_controller= new WPInv_REST_Discounts_Controller( $this->api_namespace );
46
+        $this->api_namespace       = apply_filters('wpinv_rest_api_namespace', $api_namespace);
47
+        $this->invoices_controller = new WPInv_REST_Invoice_Controller($this->api_namespace);
48
+        $this->items_controller    = new WPInv_REST_Items_Controller($this->api_namespace);
49
+        $this->discounts_controller = new WPInv_REST_Discounts_Controller($this->api_namespace);
50 50
 
51 51
         //Register REST routes
52
-        add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );
52
+        add_action('rest_api_init', array($this, 'register_rest_routes'));
53 53
     }
54 54
 
55 55
 
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
     protected function includes() {
81 81
         
82 82
         // Invoices
83
-        require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php' );
83
+        require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php');
84 84
 
85 85
         // Items
86
-        require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-items-controller.php' );
86
+        require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-items-controller.php');
87 87
 
88 88
         // Discounts
89
-        require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-discounts-controller.php' );
89
+        require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-discounts-controller.php');
90 90
 
91 91
     }
92 92
     
Please login to merge, or discard this patch.
includes/api/class-wpinv-rest-items-controller.php 1 patch
Spacing   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since    1.0.13
9 9
  */
10 10
 
11
-if ( !defined( 'WPINC' ) ) {
11
+if (!defined('WPINC')) {
12 12
     exit;
13 13
 }
14 14
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @param string $namespace Api Namespace
43 43
 	 */
44
-	public function __construct( $namespace ) {
44
+	public function __construct($namespace) {
45 45
         
46 46
         // Set api namespace...
47 47
 		$this->namespace = $namespace;
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 			array(
69 69
 				array(
70 70
 					'methods'             => WP_REST_Server::READABLE,
71
-					'callback'            => array( $this, 'get_item_types' ),
71
+					'callback'            => array($this, 'get_item_types'),
72 72
 				),
73 73
 			)
74 74
 		);
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 	 * @param WP_REST_Request $request Full details about the request.
85 85
 	 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
86 86
 	 */
87
-	public function get_items_permissions_check( $request ) {
87
+	public function get_items_permissions_check($request) {
88 88
 	
89
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
89
+		if (current_user_can('manage_options') || current_user_can('manage_invoicing')) {
90 90
 			return true;
91 91
 		}
92 92
 
93
-		return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice items.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
93
+		return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to view invoice items.', 'invoicing'), array('status' => rest_authorization_required_code()));
94 94
 
95 95
     }
96 96
     
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
 	 * @param WP_REST_Request $request Full details about the request.
103 103
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
104 104
 	 */
105
-	public function get_items( $request ) {
105
+	public function get_items($request) {
106 106
 		
107 107
 		// Retrieve the list of registered item query parameters.
108 108
         $registered = $this->get_collection_params();
109 109
         
110 110
         $args       = array();
111 111
 
112
-        foreach( array_keys( $registered ) as $key ) {
112
+        foreach (array_keys($registered) as $key) {
113 113
 
114
-            if( isset( $request[ $key] ) ) {
115
-                $args[ $key ] = $request[ $key];
114
+            if (isset($request[$key])) {
115
+                $args[$key] = $request[$key];
116 116
             }
117 117
 
118 118
         }
@@ -127,32 +127,32 @@  discard block
 block discarded – undo
127 127
 		 * @param array           $args    Key value array of query var to query value.
128 128
 		 * @param WP_REST_Request $request The request used.
129 129
 		 */
130
-        $args       = apply_filters( "wpinv_rest_get_items_arguments", $args, $request, $this );
130
+        $args = apply_filters("wpinv_rest_get_items_arguments", $args, $request, $this);
131 131
 		
132 132
 		// Special args
133
-		$args[ 'return' ]   = 'objects';
134
-		$args[ 'paginate' ] = true;
133
+		$args['return']   = 'objects';
134
+		$args['paginate'] = true;
135 135
 
136 136
         // Run the query.
137
-		$query = wpinv_get_all_items( $args );
137
+		$query = wpinv_get_all_items($args);
138 138
 		
139 139
 		// Prepare the retrieved items
140 140
 		$items = array();
141
-		foreach( $query->items as $item ) {
141
+		foreach ($query->items as $item) {
142 142
 
143
-			if ( ! $this->check_read_permission( $item ) ) {
143
+			if (!$this->check_read_permission($item)) {
144 144
 				continue;
145 145
 			}
146 146
 
147
-			$data       = $this->prepare_item_for_response( $item, $request );
148
-			$items[]    = $this->prepare_response_for_collection( $data );
147
+			$data       = $this->prepare_item_for_response($item, $request);
148
+			$items[]    = $this->prepare_response_for_collection($data);
149 149
 
150 150
 		}
151 151
 
152 152
 		// Prepare the response.
153
-		$response = rest_ensure_response( $items );
154
-		$response->header( 'X-WP-Total', (int) $query->total );
155
-		$response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
153
+		$response = rest_ensure_response($items);
154
+		$response->header('X-WP-Total', (int) $query->total);
155
+		$response->header('X-WP-TotalPages', (int) $query->max_num_pages);
156 156
 
157 157
 		/**
158 158
 		 * Filters the responses for item requests.
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 		 * @param WP_REST_Request     $request The request used.
166 166
          * @param array               $args Array of args used to retrieve the items
167 167
 		 */
168
-        $response       = apply_filters( "wpinv_rest_items_response", $response, $request, $args );
168
+        $response = apply_filters("wpinv_rest_items_response", $response, $request, $args);
169 169
 
170
-        return rest_ensure_response( $response );
170
+        return rest_ensure_response($response);
171 171
         
172 172
     }
173 173
 
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
 	 * @param int $item_id Supplied ID.
180 180
 	 * @return WPInv_Item|WP_Error Item object if ID is valid, WP_Error otherwise.
181 181
 	 */
182
-	protected function get_post( $item_id ) {
182
+	protected function get_post($item_id) {
183 183
 		
184
-		$error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid item ID.', 'invoicing' ), array( 'status' => 404 ) );
184
+		$error = new WP_Error('rest_item_invalid_id', __('Invalid item ID.', 'invoicing'), array('status' => 404));
185 185
 
186 186
         // Ids start from 1
187
-        if ( (int) $item_id <= 0 ) {
187
+        if ((int) $item_id <= 0) {
188 188
 			return $error;
189 189
 		}
190 190
 
191
-		$item = wpinv_get_item_by( 'id', (int) $item_id );
192
-		if ( empty( $item ) ) {
191
+		$item = wpinv_get_item_by('id', (int) $item_id);
192
+		if (empty($item)) {
193 193
 			return $error;
194 194
         }
195 195
 
@@ -205,29 +205,29 @@  discard block
 block discarded – undo
205 205
 	 * @param WP_REST_Request $request Full details about the request.
206 206
 	 * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
207 207
 	 */
208
-	public function get_item_permissions_check( $request ) {
208
+	public function get_item_permissions_check($request) {
209 209
 
210 210
         // Retrieve the item object.
211
-        $item = $this->get_post( $request['id'] );
211
+        $item = $this->get_post($request['id']);
212 212
         
213 213
         // Ensure it is valid.
214
-		if ( is_wp_error( $item ) ) {
214
+		if (is_wp_error($item)) {
215 215
 			return $item;
216 216
 		}
217 217
 
218
-		$post_type = get_post_type_object( $this->post_type );
218
+		$post_type = get_post_type_object($this->post_type);
219 219
 
220
-		if ( ! current_user_can(  $post_type->cap->read_post, $item->ID  ) ) {
220
+		if (!current_user_can($post_type->cap->read_post, $item->ID)) {
221 221
 			return new WP_Error( 
222 222
                 'rest_cannot_edit', 
223
-                __( 'Sorry, you are not allowed to view this item.', 'invoicing' ), 
223
+                __('Sorry, you are not allowed to view this item.', 'invoicing'), 
224 224
                 array( 
225 225
                     'status' => rest_authorization_required_code(),
226 226
                 )
227 227
             );
228 228
         }
229 229
 
230
-		return $this->check_read_permission( $item );
230
+		return $this->check_read_permission($item);
231 231
     }
232 232
     
233 233
     /**
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @param WPInv_Item $item WPInv_Item object.
242 242
 	 * @return bool Whether the post can be read.
243 243
 	 */
244
-	public function check_read_permission( $item ) {
244
+	public function check_read_permission($item) {
245 245
 
246 246
 		// An item can be read by an admin...
247
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
247
+		if (current_user_can('manage_options') || current_user_can('manage_invoicing')) {
248 248
 			return true;
249 249
 		}
250 250
 
@@ -259,18 +259,18 @@  discard block
 block discarded – undo
259 259
 	 * @param WP_REST_Request $request Full details about the request.
260 260
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
261 261
 	 */
262
-	public function get_item( $request ) {
262
+	public function get_item($request) {
263 263
 
264 264
         // Fetch the item.
265
-        $item = $this->get_post( $request['id'] );
265
+        $item = $this->get_post($request['id']);
266 266
         
267 267
         // Abort early if it does not exist
268
-		if ( is_wp_error( $item ) ) {
268
+		if (is_wp_error($item)) {
269 269
 			return $item;
270 270
 		}
271 271
 
272 272
 		// Prepare the response
273
-		$response = $this->prepare_item_for_response( $item, $request );
273
+		$response = $this->prepare_item_for_response($item, $request);
274 274
 
275 275
 		/**
276 276
 		 * Filters the responses for single invoice item requests.
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 		 * @param WP_HTTP_Response $response Response.
283 283
 		 * @param WP_REST_Request  $request The request used.
284 284
 		 */
285
-        $response       = apply_filters( "wpinv_rest_get_item_response", $response, $request );
285
+        $response = apply_filters("wpinv_rest_get_item_response", $response, $request);
286 286
 
287
-        return rest_ensure_response( $response );
287
+        return rest_ensure_response($response);
288 288
 
289 289
     }
290 290
     
@@ -296,21 +296,21 @@  discard block
 block discarded – undo
296 296
 	 * @param WP_REST_Request $request Full details about the request.
297 297
 	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
298 298
 	 */
299
-	public function create_item_permissions_check( $request ) {
299
+	public function create_item_permissions_check($request) {
300 300
 	
301
-		if ( ! empty( $request['id'] ) ) {
302
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
301
+		if (!empty($request['id'])) {
302
+			return new WP_Error('rest_item_exists', __('Cannot create existing item.', 'invoicing'), array('status' => 400));
303 303
 		}
304 304
 
305
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
305
+		if (current_user_can('manage_options') || current_user_can('manage_invoicing')) {
306 306
 			return true;
307 307
 		}
308 308
 
309
-		$post_type = get_post_type_object( $this->post_type );
310
-		if ( ! current_user_can( $post_type->cap->create_posts ) ) {
309
+		$post_type = get_post_type_object($this->post_type);
310
+		if (!current_user_can($post_type->cap->create_posts)) {
311 311
 			return new WP_Error( 
312 312
                 'rest_cannot_create', 
313
-                __( 'Sorry, you are not allowed to create invoice items as this user.', 'invoicing' ), 
313
+                __('Sorry, you are not allowed to create invoice items as this user.', 'invoicing'), 
314 314
                 array( 
315 315
                     'status' => rest_authorization_required_code(),
316 316
                 )
@@ -328,30 +328,30 @@  discard block
 block discarded – undo
328 328
 	 * @param WP_REST_Request $request Full details about the request.
329 329
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
330 330
 	 */
331
-	public function create_item( $request ) {
331
+	public function create_item($request) {
332 332
 
333
-		if ( ! empty( $request['id'] ) ) {
334
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing invoice item.', 'invoicing' ), array( 'status' => 400 ) );
333
+		if (!empty($request['id'])) {
334
+			return new WP_Error('rest_item_exists', __('Cannot create existing invoice item.', 'invoicing'), array('status' => 400));
335 335
 		}
336 336
 
337
-		$request->set_param( 'context', 'edit' );
337
+		$request->set_param('context', 'edit');
338 338
 
339 339
 		// Prepare the updated data.
340
-		$item_data = $this->prepare_item_for_database( $request );
340
+		$item_data = $this->prepare_item_for_database($request);
341 341
 
342
-		if ( is_wp_error( $item_data ) ) {
342
+		if (is_wp_error($item_data)) {
343 343
 			return $item_data;
344 344
 		}
345 345
 
346 346
 		// Try creating the item.
347
-        $item = wpinv_create_item( $item_data, true );
347
+        $item = wpinv_create_item($item_data, true);
348 348
 
349
-		if ( is_wp_error( $item ) ) {
349
+		if (is_wp_error($item)) {
350 350
             return $item;
351 351
 		}
352 352
 
353 353
 		// Prepare the response
354
-		$response = $this->prepare_item_for_response( $item, $request );
354
+		$response = $this->prepare_item_for_response($item, $request);
355 355
 
356 356
 		/**
357 357
 		 * Fires after a single invoice item is created or updated via the REST API.
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		 * @param WP_REST_Request $request  Request object.
363 363
 		 * @param bool            $creating True when creating a post, false when updating.
364 364
 		 */
365
-		do_action( "wpinv_rest_insert_item", $item, $request, true );
365
+		do_action("wpinv_rest_insert_item", $item, $request, true);
366 366
 
367 367
 		/**
368 368
 		 * Filters the responses for creating single item requests.
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
 		 * @param array           $item_data Invoice properties.
375 375
 		 * @param WP_REST_Request $request The request used.
376 376
 		 */
377
-        $response       = apply_filters( "wpinv_rest_create_item_response", $response, $request );
377
+        $response = apply_filters("wpinv_rest_create_item_response", $response, $request);
378 378
 
379
-        return rest_ensure_response( $response );
379
+        return rest_ensure_response($response);
380 380
 	}
381 381
 
382 382
 	/**
@@ -387,21 +387,21 @@  discard block
 block discarded – undo
387 387
 	 * @param WP_REST_Request $request Full details about the request.
388 388
 	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
389 389
 	 */
390
-	public function update_item_permissions_check( $request ) {
390
+	public function update_item_permissions_check($request) {
391 391
 
392 392
 		// Retrieve the item.
393
-		$item = $this->get_post( $request['id'] );
394
-		if ( is_wp_error( $item ) ) {
393
+		$item = $this->get_post($request['id']);
394
+		if (is_wp_error($item)) {
395 395
 			return $item;
396 396
 		}
397 397
 
398
-		if ( wpinv_current_user_can_manage_invoicing() ) {
398
+		if (wpinv_current_user_can_manage_invoicing()) {
399 399
 			return true;
400 400
 		}
401 401
 
402 402
 		return new WP_Error( 
403 403
 			'rest_cannot_edit', 
404
-			__( 'Sorry, you are not allowed to update this item.', 'invoicing' ), 
404
+			__('Sorry, you are not allowed to update this item.', 'invoicing'), 
405 405
 			array( 
406 406
 				'status' => rest_authorization_required_code(),
407 407
 			)
@@ -417,46 +417,46 @@  discard block
 block discarded – undo
417 417
 	 * @param WP_REST_Request $request Full details about the request.
418 418
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
419 419
 	 */
420
-	public function update_item( $request ) {
420
+	public function update_item($request) {
421 421
 		
422 422
 		// Ensure the item exists.
423
-        $valid_check = $this->get_post( $request['id'] );
423
+        $valid_check = $this->get_post($request['id']);
424 424
         
425 425
         // Abort early if it does not exist
426
-		if ( is_wp_error( $valid_check ) ) {
426
+		if (is_wp_error($valid_check)) {
427 427
 			return $valid_check;
428 428
 		}
429 429
 
430
-		$request->set_param( 'context', 'edit' );
430
+		$request->set_param('context', 'edit');
431 431
 
432 432
 		// Prepare the updated data.
433
-		$data_to_update = $this->prepare_item_for_database( $request );
433
+		$data_to_update = $this->prepare_item_for_database($request);
434 434
 
435
-		if ( is_wp_error( $data_to_update ) ) {
435
+		if (is_wp_error($data_to_update)) {
436 436
 			return $data_to_update;
437 437
 		}
438 438
 
439 439
 		// Abort if no item data is provided
440
-        if( empty( $data_to_update ) ) {
441
-            return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) );
440
+        if (empty($data_to_update)) {
441
+            return new WP_Error('missing_data', __('An update request cannot be empty.', 'invoicing'));
442 442
         }
443 443
 
444 444
 		// Include the item ID
445 445
 		$data_to_update['ID'] = $request['id'];
446 446
 
447 447
 		// Update the item
448
-		$updated_item = wpinv_update_item( $data_to_update, true );
448
+		$updated_item = wpinv_update_item($data_to_update, true);
449 449
 
450 450
 		// Incase the update operation failed...
451
-		if ( is_wp_error( $updated_item ) ) {
451
+		if (is_wp_error($updated_item)) {
452 452
 			return $updated_item;
453 453
 		}
454 454
 
455 455
 		// Prepare the response
456
-		$response = $this->prepare_item_for_response( $updated_item, $request );
456
+		$response = $this->prepare_item_for_response($updated_item, $request);
457 457
 
458 458
 		/** This action is documented in includes/class-wpinv-rest-item-controller.php */
459
-		do_action( "wpinv_rest_insert_item", $updated_item, $request, false );
459
+		do_action("wpinv_rest_insert_item", $updated_item, $request, false);
460 460
 
461 461
 		/**
462 462
 		 * Filters the responses for updating single item requests.
@@ -468,9 +468,9 @@  discard block
 block discarded – undo
468 468
 		 * @param array           $data_to_update Item properties.
469 469
 		 * @param WP_REST_Request $request The request used.
470 470
 		 */
471
-        $response       = apply_filters( "wpinv_rest_update_item_response", $response,  $data_to_update, $request );
471
+        $response = apply_filters("wpinv_rest_update_item_response", $response, $data_to_update, $request);
472 472
 
473
-        return rest_ensure_response( $response );
473
+        return rest_ensure_response($response);
474 474
 	}
475 475
 
476 476
 	/**
@@ -481,21 +481,21 @@  discard block
 block discarded – undo
481 481
 	 * @param WP_REST_Request $request Full details about the request.
482 482
 	 * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
483 483
 	 */
484
-	public function delete_item_permissions_check( $request ) {
484
+	public function delete_item_permissions_check($request) {
485 485
 
486 486
 		// Retrieve the item.
487
-		$item = $this->get_post( $request['id'] );
488
-		if ( is_wp_error( $item ) ) {
487
+		$item = $this->get_post($request['id']);
488
+		if (is_wp_error($item)) {
489 489
 			return $item;
490 490
 		}
491 491
 
492 492
 		// 
493 493
 
494 494
 		// Ensure the current user can delete the item
495
-		if (! wpinv_can_delete_item( $request['id'] ) ) {
495
+		if (!wpinv_can_delete_item($request['id'])) {
496 496
 			return new WP_Error( 
497 497
                 'rest_cannot_delete', 
498
-                __( 'Sorry, you are not allowed to delete this item.', 'invoicing' ), 
498
+                __('Sorry, you are not allowed to delete this item.', 'invoicing'), 
499 499
                 array( 
500 500
                     'status' => rest_authorization_required_code(),
501 501
                 )
@@ -513,31 +513,31 @@  discard block
 block discarded – undo
513 513
 	 * @param WP_REST_Request $request Full details about the request.
514 514
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
515 515
 	 */
516
-	public function delete_item( $request ) {
516
+	public function delete_item($request) {
517 517
 		
518 518
 		// Retrieve the item.
519
-		$item = $this->get_post( $request['id'] );
520
-		if ( is_wp_error( $item ) ) {
519
+		$item = $this->get_post($request['id']);
520
+		if (is_wp_error($item)) {
521 521
 			return $item;
522 522
 		}
523 523
 
524
-		$request->set_param( 'context', 'edit' );
524
+		$request->set_param('context', 'edit');
525 525
 
526 526
 		// Prepare the item id
527
-		$id    = $item->ID;
527
+		$id = $item->ID;
528 528
 
529 529
 		// Prepare the response
530
-		$response = $this->prepare_item_for_response( $item, $request );
530
+		$response = $this->prepare_item_for_response($item, $request);
531 531
 
532 532
 		// Check if the user wants to bypass the trash...
533 533
 		$force_delete = (bool) $request['force'];
534 534
 
535 535
 		// Try deleting the item.
536
-		$deleted = wp_delete_post( $id, $force_delete );
536
+		$deleted = wp_delete_post($id, $force_delete);
537 537
 
538 538
 		// Abort early if we can't delete the item.
539
-		if ( ! $deleted ) {
540
-			return new WP_Error( 'rest_cannot_delete', __( 'The item cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) );
539
+		if (!$deleted) {
540
+			return new WP_Error('rest_cannot_delete', __('The item cannot be deleted.', 'invoicing'), array('status' => 500));
541 541
 		}
542 542
 
543 543
 		/**
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 		 * @param WPInv_Item    $item  The deleted or trashed item.
550 550
 		 * @param WP_REST_Request  $request  The request sent to the API.
551 551
 		 */
552
-		do_action( "wpinv_rest_delete_item", $item, $request );
552
+		do_action("wpinv_rest_delete_item", $item, $request);
553 553
 
554 554
 		return $response;
555 555
 
@@ -565,19 +565,19 @@  discard block
 block discarded – undo
565 565
 	 */
566 566
 	public function get_collection_params() {
567 567
         
568
-        $query_params               = array(
568
+        $query_params = array(
569 569
 
570 570
             // Item status.
571 571
             'status'                => array(
572 572
                 'default'           => 'publish',
573
-                'description'       => __( 'Limit result set to items assigned one or more statuses.', 'invoicing' ),
573
+                'description'       => __('Limit result set to items assigned one or more statuses.', 'invoicing'),
574 574
                 'type'              => 'array',
575
-                'sanitize_callback' => array( $this, 'sanitize_post_statuses' ),
575
+                'sanitize_callback' => array($this, 'sanitize_post_statuses'),
576 576
             ),
577 577
             
578 578
             // Item types
579 579
             'type'                  => array(
580
-				'description'       => __( 'Type of items to fetch.', 'invoicing' ),
580
+				'description'       => __('Type of items to fetch.', 'invoicing'),
581 581
 				'type'              => 'array',
582 582
 				'default'           => wpinv_item_types(),
583 583
 				'items'             => array(
@@ -588,21 +588,21 @@  discard block
 block discarded – undo
588 588
 			
589 589
 			// Number of results per page
590 590
             'limit'                 => array(
591
-				'description'       => __( 'Number of items to fetch.', 'invoicing' ),
591
+				'description'       => __('Number of items to fetch.', 'invoicing'),
592 592
 				'type'              => 'integer',
593
-				'default'           => (int) get_option( 'posts_per_page' ),
593
+				'default'           => (int) get_option('posts_per_page'),
594 594
             ),
595 595
 
596 596
             // Pagination
597 597
             'page'     => array(
598
-				'description'       => __( 'Current page to fetch.', 'invoicing' ),
598
+				'description'       => __('Current page to fetch.', 'invoicing'),
599 599
 				'type'              => 'integer',
600 600
 				'default'           => 1,
601 601
             ),
602 602
 
603 603
             // Exclude certain items
604 604
             'exclude'  => array(
605
-                'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ),
605
+                'description' => __('Ensure result set excludes specific IDs.', 'invoicing'),
606 606
                 'type'        => 'array',
607 607
                 'items'       => array(
608 608
                     'type' => 'integer',
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 
613 613
             // Order items by
614 614
             'orderby'  => array(
615
-                'description' => __( 'Sort items by object attribute.', 'invoicing' ),
615
+                'description' => __('Sort items by object attribute.', 'invoicing'),
616 616
                 'type'        => 'string',
617 617
                 'default'     => 'date',
618 618
                 'enum'        => array(
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 
629 629
             // How to order
630 630
             'order'    => array(
631
-                'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ),
631
+                'description' => __('Order sort attribute ascending or descending.', 'invoicing'),
632 632
                 'type'        => 'string',
633 633
                 'default'     => 'DESC',
634
-                'enum'        => array( 'ASC', 'DESC' ),
634
+                'enum'        => array('ASC', 'DESC'),
635 635
 			),
636 636
 			
637 637
 			// Search term
638 638
             'search'                => array(
639
-				'description'       => __( 'Return items that match the search term.', 'invoicing' ),
639
+				'description'       => __('Return items that match the search term.', 'invoicing'),
640 640
 				'type'              => 'string',
641 641
             ),
642 642
         );
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 		 *
650 650
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
651 651
 		 */
652
-		return apply_filters( "wpinv_rest_items_collection_params", $query_params );
652
+		return apply_filters("wpinv_rest_items_collection_params", $query_params);
653 653
     }
654 654
     
655 655
     /**
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 	 * @param object|string $post_type Post type name or object.
661 661
 	 * @return bool Whether the post type is allowed in REST.
662 662
 	 */
663
-	protected function check_is_post_type_allowed( $post_type ) {
663
+	protected function check_is_post_type_allowed($post_type) {
664 664
 		return true;
665 665
 	}
666 666
 
@@ -672,84 +672,84 @@  discard block
 block discarded – undo
672 672
 	 * @param WP_REST_Request $request Request object.
673 673
 	 * @return array|WP_Error Invoice Properties or WP_Error.
674 674
 	 */
675
-	protected function prepare_item_for_database( $request ) {
675
+	protected function prepare_item_for_database($request) {
676 676
 		$prepared_item = new stdClass();
677 677
 
678 678
 		// Post ID.
679
-		if ( isset( $request['id'] ) ) {
680
-			$existing_item = $this->get_post( $request['id'] );
681
-			if ( is_wp_error( $existing_item ) ) {
679
+		if (isset($request['id'])) {
680
+			$existing_item = $this->get_post($request['id']);
681
+			if (is_wp_error($existing_item)) {
682 682
 				return $existing_item;
683 683
 			}
684 684
 
685
-			$prepared_item->ID 		  = $existing_item->ID;
685
+			$prepared_item->ID = $existing_item->ID;
686 686
 		}
687 687
 
688 688
 		$schema = $this->get_item_schema();
689 689
 
690 690
 		// item title.
691
-		if ( ! empty( $schema['properties']['name'] ) && isset( $request['name'] ) ) {
692
-			$prepared_item->title = sanitize_text_field( $request['name'] );
691
+		if (!empty($schema['properties']['name']) && isset($request['name'])) {
692
+			$prepared_item->title = sanitize_text_field($request['name']);
693 693
 		}
694 694
 
695 695
 		// item summary.
696
-		if ( ! empty( $schema['properties']['summary'] ) && isset( $request['summary'] ) ) {
697
-			$prepared_item->excerpt = wp_kses_post( $request['summary'] );
696
+		if (!empty($schema['properties']['summary']) && isset($request['summary'])) {
697
+			$prepared_item->excerpt = wp_kses_post($request['summary']);
698 698
 		}
699 699
 
700 700
 		// item price.
701
-		if ( ! empty( $schema['properties']['price'] ) && isset( $request['price'] ) ) {
702
-			$prepared_item->price = floatval( $request['price'] );
701
+		if (!empty($schema['properties']['price']) && isset($request['price'])) {
702
+			$prepared_item->price = floatval($request['price']);
703 703
 		}
704 704
 
705 705
 		// minimum price (for dynamc items).
706
-		if ( ! empty( $schema['properties']['minimum_price'] ) && isset( $request['minimum_price'] ) ) {
707
-			$prepared_item->minimum_price = floatval( $request['minimum_price'] );
706
+		if (!empty($schema['properties']['minimum_price']) && isset($request['minimum_price'])) {
707
+			$prepared_item->minimum_price = floatval($request['minimum_price']);
708 708
 		}
709 709
 
710 710
 		// item status.
711
-		if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
711
+		if (!empty($schema['properties']['status']) && isset($request['status'])) {
712 712
 			$prepared_item->status = 'publish' === $request['status'] ? 'publish' : 'pending';
713 713
 		}
714 714
 
715 715
 		// item type.
716
-		if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] ) ) {
717
-			$prepared_item->type = in_array( $request['type'], wpinv_item_types() ) ? trim( strtolower( $request['type'] ) ) : 'custom';
716
+		if (!empty($schema['properties']['type']) && isset($request['type'])) {
717
+			$prepared_item->type = in_array($request['type'], wpinv_item_types()) ? trim(strtolower($request['type'])) : 'custom';
718 718
 		}
719 719
 
720 720
 		// VAT rule.
721
-		if ( ! empty( $schema['properties']['vat_rule'] ) && isset( $request['vat_rule'] ) ) {
721
+		if (!empty($schema['properties']['vat_rule']) && isset($request['vat_rule'])) {
722 722
 			$prepared_item->vat_rule = 'digital' === $request['vat_rule'] ? 'digital' : 'physical';
723 723
 		}
724 724
 
725 725
 		// Simple strings.
726
-		foreach( array( 'custom_id', 'custom_name', 'custom_singular_name' ) as $property ) {
726
+		foreach (array('custom_id', 'custom_name', 'custom_singular_name') as $property) {
727 727
 
728
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
729
-				$prepared_item->$property = sanitize_text_field( $request[$property] );
728
+			if (!empty($schema['properties'][$property]) && isset($request[$property])) {
729
+				$prepared_item->$property = sanitize_text_field($request[$property]);
730 730
 			}
731 731
 
732 732
 		}
733 733
 
734 734
 		// Simple integers.
735
-		foreach( array( 'is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable' ) as $property ) {
735
+		foreach (array('is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable') as $property) {
736 736
 
737
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
738
-				$prepared_item->$property = intval( $request[$property] );
737
+			if (!empty($schema['properties'][$property]) && isset($request[$property])) {
738
+				$prepared_item->$property = intval($request[$property]);
739 739
 			}
740 740
 
741 741
 		}
742 742
 
743 743
 		// Time periods.
744
-		foreach( array( 'recurring_period',  'trial_period' ) as $property ) {
744
+		foreach (array('recurring_period', 'trial_period') as $property) {
745 745
 
746
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
747
-				$prepared_item->$property = in_array( $request[$property], array( 'D', 'W', 'M', 'Y' ) ) ? trim( strtoupper( $request[$property] ) ) : 'D';
746
+			if (!empty($schema['properties'][$property]) && isset($request[$property])) {
747
+				$prepared_item->$property = in_array($request[$property], array('D', 'W', 'M', 'Y')) ? trim(strtoupper($request[$property])) : 'D';
748 748
 			}
749 749
 
750 750
 		}
751 751
 
752
-		$item_data = (array) wp_unslash( $prepared_item );
752
+		$item_data = (array) wp_unslash($prepared_item);
753 753
 
754 754
 		/**
755 755
 		 * Filters an item before it is inserted via the REST API.
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 		 * @param array        $item_data An array of item data
760 760
 		 * @param WP_REST_Request $request       Request object.
761 761
 		 */
762
-		return apply_filters( "wpinv_rest_pre_insert_item", $item_data, $request );
762
+		return apply_filters("wpinv_rest_pre_insert_item", $item_data, $request);
763 763
 
764 764
 	}
765 765
 
@@ -772,20 +772,20 @@  discard block
 block discarded – undo
772 772
 	 * @param WP_REST_Request $request Request object.
773 773
 	 * @return WP_REST_Response Response object.
774 774
 	 */
775
-	public function prepare_item_for_response( $item, $request ) {
775
+	public function prepare_item_for_response($item, $request) {
776 776
 
777
-		$GLOBALS['post'] = get_post( $item->get_ID() );
777
+		$GLOBALS['post'] = get_post($item->get_ID());
778 778
 
779
-		setup_postdata( $item->get_ID() );
779
+		setup_postdata($item->get_ID());
780 780
 
781 781
 		// Fetch the fields to include in this response.
782
-		$fields = $this->get_fields_for_response( $request );
782
+		$fields = $this->get_fields_for_response($request);
783 783
 
784 784
 		// Base fields for every item.
785 785
 		$data = array();
786 786
 
787 787
 		// Set up ID
788
-		if ( rest_is_field_included( 'id', $fields ) ) {
788
+		if (rest_is_field_included('id', $fields)) {
789 789
 			$data['id'] = $item->get_ID();
790 790
 		}
791 791
 
@@ -798,49 +798,49 @@  discard block
 block discarded – undo
798 798
 			'editable'
799 799
 		);
800 800
 
801
-		foreach( $item_properties as $property ) {
801
+		foreach ($item_properties as $property) {
802 802
 
803
-			if ( rest_is_field_included( $property, $fields ) && method_exists( $item, 'get_' . $property ) ) {
804
-				$data[$property] = call_user_func( array( $item, 'get_' . $property ) );
803
+			if (rest_is_field_included($property, $fields) && method_exists($item, 'get_' . $property)) {
804
+				$data[$property] = call_user_func(array($item, 'get_' . $property));
805 805
 			}
806 806
 
807 807
 		}
808 808
 
809 809
 		// Dynamic pricing.
810
-		if( $item->supports_dynamic_pricing() ) {
810
+		if ($item->supports_dynamic_pricing()) {
811 811
 
812
-			if( rest_is_field_included( 'dynamic_pricing', $fields ) ) {
812
+			if (rest_is_field_included('dynamic_pricing', $fields)) {
813 813
 				$data['dynamic_pricing'] = $item->get_is_dynamic_pricing();
814 814
 			}
815 815
 
816
-			if( rest_is_field_included( 'minimum_price', $fields ) ) {
816
+			if (rest_is_field_included('minimum_price', $fields)) {
817 817
 				$data['minimum_price'] = $item->get_minimum_price();
818 818
 			}
819 819
 		}
820 820
 
821 821
 		// Subscriptions.
822
-		if( rest_is_field_included( 'is_recurring', $fields ) ) {
822
+		if (rest_is_field_included('is_recurring', $fields)) {
823 823
 			$data['is_recurring'] = $item->get_is_recurring();
824 824
 		}
825 825
 
826
-		if( $item->is_recurring() ) {
826
+		if ($item->is_recurring()) {
827 827
 
828
-			$recurring_fields = array( 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial' );
829
-			foreach( $recurring_fields as $field ) {
828
+			$recurring_fields = array('is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial');
829
+			foreach ($recurring_fields as $field) {
830 830
 
831
-				if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
832
-					$data[$field] = call_user_func( array( $item, 'get_' . $field ) );
831
+				if (rest_is_field_included($field, $fields) && method_exists($item, 'get_' . $field)) {
832
+					$data[$field] = call_user_func(array($item, 'get_' . $field));
833 833
 				}
834 834
 	
835 835
 			}
836 836
 
837
-			if( $item->has_free_trial() ) {
837
+			if ($item->has_free_trial()) {
838 838
 
839
-				$trial_fields = array( 'trial_period', 'trial_interval' );
840
-				foreach( $trial_fields as $field ) {
839
+				$trial_fields = array('trial_period', 'trial_interval');
840
+				foreach ($trial_fields as $field) {
841 841
 
842
-					if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
843
-						$data[$field] = call_user_func( array( $item, 'get_' . $field ) );
842
+					if (rest_is_field_included($field, $fields) && method_exists($item, 'get_' . $field)) {
843
+						$data[$field] = call_user_func(array($item, 'get_' . $field));
844 844
 					}
845 845
 	
846 846
 				}
@@ -849,23 +849,23 @@  discard block
 block discarded – undo
849 849
 
850 850
 		}
851 851
 
852
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
853
-		$data    = $this->add_additional_fields_to_object( $data, $request );
854
-		$data    = $this->filter_response_by_context( $data, $context );
852
+		$context = !empty($request['context']) ? $request['context'] : 'view';
853
+		$data    = $this->add_additional_fields_to_object($data, $request);
854
+		$data    = $this->filter_response_by_context($data, $context);
855 855
 
856 856
 		// Wrap the data in a response object.
857
-		$response = rest_ensure_response( $data );
857
+		$response = rest_ensure_response($data);
858 858
 
859
-		$links = $this->prepare_links( $item );
860
-		$response->add_links( $links );
859
+		$links = $this->prepare_links($item);
860
+		$response->add_links($links);
861 861
 
862
-		if ( ! empty( $links['self']['href'] ) ) {
863
-			$actions = $this->get_available_actions( $item, $request );
862
+		if (!empty($links['self']['href'])) {
863
+			$actions = $this->get_available_actions($item, $request);
864 864
 
865 865
 			$self = $links['self']['href'];
866 866
 
867
-			foreach ( $actions as $rel ) {
868
-				$response->add_link( $rel, $self );
867
+			foreach ($actions as $rel) {
868
+				$response->add_link($rel, $self);
869 869
 			}
870 870
 		}
871 871
 
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
 		 * @param WPInv_Item    $item  The item object.
879 879
 		 * @param WP_REST_Request  $request  Request object.
880 880
 		 */
881
-		return apply_filters( "wpinv_rest_prepare_item", $response, $item, $request );
881
+		return apply_filters("wpinv_rest_prepare_item", $response, $item, $request);
882 882
 	}
883 883
 
884 884
 	/**
@@ -891,57 +891,57 @@  discard block
 block discarded – undo
891 891
 	 * @param WP_REST_Request $request Full details about the request.
892 892
 	 * @return array Fields to be included in the response.
893 893
 	 */
894
-	public function get_fields_for_response( $request ) {
894
+	public function get_fields_for_response($request) {
895 895
 		$schema     = $this->get_item_schema();
896
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
896
+		$properties = isset($schema['properties']) ? $schema['properties'] : array();
897 897
 
898 898
 		$additional_fields = $this->get_additional_fields();
899
-		foreach ( $additional_fields as $field_name => $field_options ) {
899
+		foreach ($additional_fields as $field_name => $field_options) {
900 900
 			// For back-compat, include any field with an empty schema
901 901
 			// because it won't be present in $this->get_item_schema().
902
-			if ( is_null( $field_options['schema'] ) ) {
903
-				$properties[ $field_name ] = $field_options;
902
+			if (is_null($field_options['schema'])) {
903
+				$properties[$field_name] = $field_options;
904 904
 			}
905 905
 		}
906 906
 
907 907
 		// Exclude fields that specify a different context than the request context.
908 908
 		$context = $request['context'];
909
-		if ( $context ) {
910
-			foreach ( $properties as $name => $options ) {
911
-				if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
912
-					unset( $properties[ $name ] );
909
+		if ($context) {
910
+			foreach ($properties as $name => $options) {
911
+				if (!empty($options['context']) && !in_array($context, $options['context'], true)) {
912
+					unset($properties[$name]);
913 913
 				}
914 914
 			}
915 915
 		}
916 916
 
917
-		$fields = array_keys( $properties );
917
+		$fields = array_keys($properties);
918 918
 
919
-		if ( ! isset( $request['_fields'] ) ) {
919
+		if (!isset($request['_fields'])) {
920 920
 			return $fields;
921 921
 		}
922
-		$requested_fields = wpinv_parse_list( $request['_fields'] );
923
-		if ( 0 === count( $requested_fields ) ) {
922
+		$requested_fields = wpinv_parse_list($request['_fields']);
923
+		if (0 === count($requested_fields)) {
924 924
 			return $fields;
925 925
 		}
926 926
 		// Trim off outside whitespace from the comma delimited list.
927
-		$requested_fields = array_map( 'trim', $requested_fields );
927
+		$requested_fields = array_map('trim', $requested_fields);
928 928
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
929
-		if ( in_array( 'id', $fields, true ) ) {
929
+		if (in_array('id', $fields, true)) {
930 930
 			$requested_fields[] = 'id';
931 931
 		}
932 932
 		// Return the list of all requested fields which appear in the schema.
933 933
 		return array_reduce(
934 934
 			$requested_fields,
935
-			function( $response_fields, $field ) use ( $fields ) {
936
-				if ( in_array( $field, $fields, true ) ) {
935
+			function($response_fields, $field) use ($fields) {
936
+				if (in_array($field, $fields, true)) {
937 937
 					$response_fields[] = $field;
938 938
 					return $response_fields;
939 939
 				}
940 940
 				// Check for nested fields if $field is not a direct match.
941
-				$nested_fields = explode( '.', $field );
941
+				$nested_fields = explode('.', $field);
942 942
 				// A nested field is included so long as its top-level property is
943 943
 				// present in the schema.
944
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
944
+				if (in_array($nested_fields[0], $fields, true)) {
945 945
 					$response_fields[] = $field;
946 946
 				}
947 947
 				return $response_fields;
@@ -960,8 +960,8 @@  discard block
 block discarded – undo
960 960
 	public function get_item_schema() {
961 961
 
962 962
 		// Maybe retrieve the schema from cache.
963
-		if ( $this->schema ) {
964
-			return $this->add_additional_fields_schema( $this->schema );
963
+		if ($this->schema) {
964
+			return $this->add_additional_fields_schema($this->schema);
965 965
 		}
966 966
 
967 967
 		$schema = array(
@@ -973,136 +973,136 @@  discard block
 block discarded – undo
973 973
 			'properties' 		  => array(
974 974
 
975 975
 				'id'           => array(
976
-					'description' => __( 'Unique identifier for the item.', 'invoicing' ),
976
+					'description' => __('Unique identifier for the item.', 'invoicing'),
977 977
 					'type'        => 'integer',
978
-					'context'     => array( 'view', 'edit', 'embed' ),
978
+					'context'     => array('view', 'edit', 'embed'),
979 979
 					'readonly'    => true,
980 980
 				),
981 981
 
982 982
 				'name'			  => array(
983
-					'description' => __( 'The name for the item.', 'invoicing' ),
983
+					'description' => __('The name for the item.', 'invoicing'),
984 984
 					'type'        => 'string',
985
-					'context'     => array( 'view', 'edit', 'embed' ),
985
+					'context'     => array('view', 'edit', 'embed'),
986 986
 				),
987 987
 
988 988
 				'summary'        => array(
989
-					'description' => __( 'A summary for the item.', 'invoicing' ),
989
+					'description' => __('A summary for the item.', 'invoicing'),
990 990
 					'type'        => 'string',
991
-					'context'     => array( 'view', 'edit', 'embed' ),
991
+					'context'     => array('view', 'edit', 'embed'),
992 992
 				),
993 993
 
994 994
 				'price'        => array(
995
-					'description' => __( 'The price for the item.', 'invoicing' ),
995
+					'description' => __('The price for the item.', 'invoicing'),
996 996
 					'type'        => 'number',
997
-					'context'     => array( 'view', 'edit', 'embed' ),
997
+					'context'     => array('view', 'edit', 'embed'),
998 998
 				),
999 999
 
1000 1000
 				'status'       => array(
1001
-					'description' => __( 'A named status for the item.', 'invoicing' ),
1001
+					'description' => __('A named status for the item.', 'invoicing'),
1002 1002
 					'type'        => 'string',
1003
-					'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1004
-					'context'     => array( 'view', 'edit' ),
1003
+					'enum'        => array_keys(get_post_stati(array('internal' => false))),
1004
+					'context'     => array('view', 'edit'),
1005 1005
 				),
1006 1006
 
1007 1007
 				'type'       => array(
1008
-					'description' => __( 'The item type.', 'invoicing' ),
1008
+					'description' => __('The item type.', 'invoicing'),
1009 1009
 					'type'        => 'string',
1010 1010
 					'enum'        => wpinv_item_types(),
1011
-					'context'     => array( 'view', 'edit', 'embed' ),
1011
+					'context'     => array('view', 'edit', 'embed'),
1012 1012
 				),
1013 1013
 
1014 1014
 				'vat_rule'       => array(
1015
-					'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
1015
+					'description' => __('VAT rule applied to the item.', 'invoicing'),
1016 1016
 					'type'        => 'string',
1017
-					'enum'        => array( 'digital', 'physical' ),
1018
-					'context'     => array( 'view', 'edit' ),
1017
+					'enum'        => array('digital', 'physical'),
1018
+					'context'     => array('view', 'edit'),
1019 1019
 				),
1020 1020
 
1021 1021
 				'vat_class'       => array(
1022
-					'description' => __( 'VAT class for the item.', 'invoicing' ),
1022
+					'description' => __('VAT class for the item.', 'invoicing'),
1023 1023
 					'type'        => 'string',
1024
-					'context'     => array( 'view', 'edit' ),
1024
+					'context'     => array('view', 'edit'),
1025 1025
 					'readonly'    => true,
1026 1026
 				),
1027 1027
 
1028 1028
 				'custom_id'       => array(
1029
-					'description' => __( 'Custom id for the item.', 'invoicing' ),
1029
+					'description' => __('Custom id for the item.', 'invoicing'),
1030 1030
 					'type'        => 'string',
1031
-					'context'     => array( 'view', 'edit', 'embed' ),
1031
+					'context'     => array('view', 'edit', 'embed'),
1032 1032
 				),
1033 1033
 				
1034 1034
 				'custom_name'       => array(
1035
-					'description' => __( 'Custom name for the item.', 'invoicing' ),
1035
+					'description' => __('Custom name for the item.', 'invoicing'),
1036 1036
 					'type'        => 'string',
1037
-					'context'     => array( 'view', 'edit', 'embed' ),
1037
+					'context'     => array('view', 'edit', 'embed'),
1038 1038
 				),
1039 1039
 
1040 1040
 				'custom_singular_name'       => array(
1041
-					'description' => __( 'Custom singular name for the item.', 'invoicing' ),
1041
+					'description' => __('Custom singular name for the item.', 'invoicing'),
1042 1042
 					'type'        => 'string',
1043
-					'context'     => array( 'view', 'edit', 'embed' ),
1043
+					'context'     => array('view', 'edit', 'embed'),
1044 1044
 				),
1045 1045
 
1046 1046
 				'dynamic_pricing'        => array(
1047
-					'description' => __( 'Whether the item allows a user to set their own price.', 'invoicing' ),
1047
+					'description' => __('Whether the item allows a user to set their own price.', 'invoicing'),
1048 1048
 					'type'        => 'integer',
1049
-					'context'     => array( 'view', 'edit', 'embed' ),
1049
+					'context'     => array('view', 'edit', 'embed'),
1050 1050
 				),
1051 1051
 
1052 1052
 				'minimum_price'        => array(
1053
-					'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
1053
+					'description' => __('For dynamic prices, this is the minimum price that a user can set.', 'invoicing'),
1054 1054
 					'type'        => 'number',
1055
-					'context'     => array( 'view', 'edit', 'embed' ),
1055
+					'context'     => array('view', 'edit', 'embed'),
1056 1056
 				),
1057 1057
 
1058 1058
 				'is_recurring'        => array(
1059
-					'description' => __( 'Whether the item is a subscription item.', 'invoicing' ),
1059
+					'description' => __('Whether the item is a subscription item.', 'invoicing'),
1060 1060
 					'type'        => 'integer',
1061
-					'context'     => array( 'view', 'edit', 'embed' ),
1061
+					'context'     => array('view', 'edit', 'embed'),
1062 1062
 				),
1063 1063
 
1064 1064
 				'recurring_period'        => array(
1065
-					'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
1065
+					'description' => __('The recurring period for a recurring item.', 'invoicing'),
1066 1066
 					'type'        => 'string',
1067
-					'context'     => array( 'view', 'edit', 'embed' ),
1068
-					'enum'        => array( 'D', 'W', 'M', 'Y' ),
1067
+					'context'     => array('view', 'edit', 'embed'),
1068
+					'enum'        => array('D', 'W', 'M', 'Y'),
1069 1069
 				),
1070 1070
 
1071 1071
 				'recurring_interval'        => array(
1072
-					'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
1072
+					'description' => __('The recurring interval for a subscription item.', 'invoicing'),
1073 1073
 					'type'        => 'integer',
1074
-					'context'     => array( 'view', 'edit', 'embed' ),
1074
+					'context'     => array('view', 'edit', 'embed'),
1075 1075
 				),
1076 1076
 
1077 1077
 				'recurring_limit'        => array(
1078
-					'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
1078
+					'description' => __('The maximum number of renewals for a subscription item.', 'invoicing'),
1079 1079
 					'type'        => 'integer',
1080
-					'context'     => array( 'view', 'edit', 'embed' ),
1080
+					'context'     => array('view', 'edit', 'embed'),
1081 1081
 				),
1082 1082
 
1083 1083
 				'free_trial'        => array(
1084
-					'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
1084
+					'description' => __('Whether the item has a free trial period.', 'invoicing'),
1085 1085
 					'type'        => 'integer',
1086
-					'context'     => array( 'view', 'edit', 'embed' ),
1086
+					'context'     => array('view', 'edit', 'embed'),
1087 1087
 				),
1088 1088
 
1089 1089
 				'trial_period'        => array(
1090
-					'description' => __( 'The trial period of a recurring item.', 'invoicing' ),
1090
+					'description' => __('The trial period of a recurring item.', 'invoicing'),
1091 1091
 					'type'        => 'string',
1092
-					'context'     => array( 'view', 'edit', 'embed' ),
1093
-					'enum'        => array( 'D', 'W', 'M', 'Y' ),
1092
+					'context'     => array('view', 'edit', 'embed'),
1093
+					'enum'        => array('D', 'W', 'M', 'Y'),
1094 1094
 				),
1095 1095
 
1096 1096
 				'trial_interval'        => array(
1097
-					'description' => __( 'The trial interval for a subscription item.', 'invoicing' ),
1097
+					'description' => __('The trial interval for a subscription item.', 'invoicing'),
1098 1098
 					'type'        => 'integer',
1099
-					'context'     => array( 'view', 'edit', 'embed' ),
1099
+					'context'     => array('view', 'edit', 'embed'),
1100 1100
 				),
1101 1101
 
1102 1102
 				'editable'        => array(
1103
-					'description' => __( 'Whether or not the item is editable.', 'invoicing' ),
1103
+					'description' => __('Whether or not the item is editable.', 'invoicing'),
1104 1104
 					'type'        => 'integer',
1105
-					'context'     => array( 'view', 'edit' ),
1105
+					'context'     => array('view', 'edit'),
1106 1106
 				),
1107 1107
 
1108 1108
 			),
@@ -1120,12 +1120,12 @@  discard block
 block discarded – undo
1120 1120
 		 *
1121 1121
 		 * @param array   $schema    The item schema.
1122 1122
 		 */
1123
-        $schema = apply_filters( "wpinv_rest_item_schema", $schema );
1123
+        $schema = apply_filters("wpinv_rest_item_schema", $schema);
1124 1124
 
1125 1125
 		//  Cache the item schema.
1126 1126
 		$this->schema = $schema;
1127 1127
 		
1128
-		return $this->add_additional_fields_schema( $this->schema );
1128
+		return $this->add_additional_fields_schema($this->schema);
1129 1129
 	}
1130 1130
 
1131 1131
 	/**
@@ -1137,20 +1137,20 @@  discard block
 block discarded – undo
1137 1137
 	 */
1138 1138
 	protected function get_schema_links() {
1139 1139
 
1140
-		$href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1140
+		$href = rest_url("{$this->namespace}/{$this->rest_base}/{id}");
1141 1141
 
1142 1142
 		$links = array();
1143 1143
 
1144 1144
 		$links[] = array(
1145 1145
 			'rel'          => 'https://api.w.org/action-publish',
1146
-			'title'        => __( 'The current user can publish this item.' ),
1146
+			'title'        => __('The current user can publish this item.'),
1147 1147
 			'href'         => $href,
1148 1148
 			'targetSchema' => array(
1149 1149
 				'type'       => 'object',
1150 1150
 				'properties' => array(
1151 1151
 					'status' => array(
1152 1152
 						'type' => 'string',
1153
-						'enum' => array( 'publish', 'future' ),
1153
+						'enum' => array('publish', 'future'),
1154 1154
 					),
1155 1155
 				),
1156 1156
 			),
@@ -1167,18 +1167,18 @@  discard block
 block discarded – undo
1167 1167
 	 * @param WPInv_Item $item Item Object.
1168 1168
 	 * @return array Links for the given item.
1169 1169
 	 */
1170
-	protected function prepare_links( $item ) {
1170
+	protected function prepare_links($item) {
1171 1171
 
1172 1172
 		// Prepare the base REST API endpoint for items.
1173
-		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1173
+		$base = sprintf('%s/%s', $this->namespace, $this->rest_base);
1174 1174
 
1175 1175
 		// Entity meta.
1176 1176
 		$links = array(
1177 1177
 			'self'       => array(
1178
-				'href' => rest_url( trailingslashit( $base ) . $item->ID ),
1178
+				'href' => rest_url(trailingslashit($base) . $item->ID),
1179 1179
 			),
1180 1180
 			'collection' => array(
1181
-				'href' => rest_url( $base ),
1181
+				'href' => rest_url($base),
1182 1182
 			),
1183 1183
 		);
1184 1184
 
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 		 *
1192 1192
 		 * @param array   $links    Rest links.
1193 1193
 		 */
1194
-		return apply_filters( "wpinv_rest_item_links", $links );
1194
+		return apply_filters("wpinv_rest_item_links", $links);
1195 1195
 
1196 1196
 	}
1197 1197
 
@@ -1204,19 +1204,19 @@  discard block
 block discarded – undo
1204 1204
 	 * @param WP_REST_Request $request Request object.
1205 1205
 	 * @return array List of link relations.
1206 1206
 	 */
1207
-	protected function get_available_actions( $item, $request ) {
1207
+	protected function get_available_actions($item, $request) {
1208 1208
 
1209
-		if ( 'edit' !== $request['context'] ) {
1209
+		if ('edit' !== $request['context']) {
1210 1210
 			return array();
1211 1211
 		}
1212 1212
 
1213 1213
 		$rels = array();
1214 1214
 
1215 1215
 		// Retrieve the post type object.
1216
-		$post_type = get_post_type_object( $item->post_type );
1216
+		$post_type = get_post_type_object($item->post_type);
1217 1217
 
1218 1218
 		// Mark item as published.
1219
-		if ( current_user_can( $post_type->cap->publish_posts ) ) {
1219
+		if (current_user_can($post_type->cap->publish_posts)) {
1220 1220
 			$rels[] = 'https://api.w.org/action-publish';
1221 1221
 		}
1222 1222
 
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 		 *
1230 1230
 		 * @param array   $rels    Available link relations.
1231 1231
 		 */
1232
-		return apply_filters( "wpinv_rest_item_link_relations", $rels );
1232
+		return apply_filters("wpinv_rest_item_link_relations", $rels);
1233 1233
 	}
1234 1234
 
1235 1235
 	/**
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1242 1242
 	 */
1243 1243
 	public function get_item_types() {
1244
-		return rest_ensure_response( wpinv_get_item_types() );
1244
+		return rest_ensure_response(wpinv_get_item_types());
1245 1245
 	}
1246 1246
 
1247 1247
     
Please login to merge, or discard this patch.
includes/gateways/paypal.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -25,30 +25,30 @@  discard block
 block discarded – undo
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
             'lc'            => 'US', // this will force paypal site to english
69
-            'landing_page'  => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
69
+            'landing_page'  => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
70 70
         );
71 71
 
72 72
         $paypal_args['address1'] = $invoice->get_address();
@@ -80,83 +80,83 @@  discard block
 block discarded – undo
80 80
             'upload' => '1'
81 81
         );
82 82
 
83
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
83
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
84 84
 
85 85
         // Add cart items
86 86
         $i = 1;
87
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
88
-            foreach ( $purchase_data['cart_details'] as $item ) {
87
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
88
+            foreach ($purchase_data['cart_details'] as $item) {
89 89
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
90
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
90
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
91 91
 
92
-                if ( $item_amount <= 0 ) {
92
+                if ($item_amount <= 0) {
93 93
                     $item_amount = 0;
94 94
                 }
95 95
 
96
-                $paypal_args['item_number_' . $i ]      = $item['id'];
97
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
98
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
99
-                $paypal_args['amount_' . $i ]           = $item_amount;
100
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
96
+                $paypal_args['item_number_' . $i]      = $item['id'];
97
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
98
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
99
+                $paypal_args['amount_' . $i]           = $item_amount;
100
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
101 101
 
102 102
                 $i++;
103 103
             }
104 104
         }
105 105
 
106 106
         // Add taxes to the cart
107
-        if ( wpinv_use_taxes() ) {
108
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 );
107
+        if (wpinv_use_taxes()) {
108
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_tax(), 2);
109 109
         }
110 110
 
111
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
111
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
112 112
 
113 113
         // Build query
114
-        $paypal_redirect .= http_build_query( $paypal_args );
114
+        $paypal_redirect .= http_build_query($paypal_args);
115 115
 
116 116
         // Fix for some sites that encode the entities
117
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
117
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
118 118
 
119 119
         // Get rid of cart contents
120 120
         wpinv_empty_cart();
121 121
         
122 122
         // Redirect to PayPal
123
-        wp_redirect( $paypal_redirect );
123
+        wp_redirect($paypal_redirect);
124 124
         exit;
125 125
     }
126 126
 }
127
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
127
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
128 128
 
129
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
130
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
131
-        $item   = new WPInv_Item( $item_id );
129
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
130
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
131
+        $item = new WPInv_Item($item_id);
132 132
         
133
-        if ( empty( $item ) ) {
133
+        if (empty($item)) {
134 134
             return $paypal_args;
135 135
         }
136 136
 
137 137
         $period             = $item->get_recurring_period();
138 138
         $interval           = $item->get_recurring_interval();
139
-        $bill_times         = (int)$item->get_recurring_limit();
139
+        $bill_times         = (int) $item->get_recurring_limit();
140 140
         
141
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
142
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
141
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
142
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
143 143
         
144 144
         $paypal_args['cmd'] = '_xclick-subscriptions';
145 145
         $paypal_args['sra'] = '1';
146 146
         $paypal_args['src'] = '1';
147 147
         
148 148
         // Set item description
149
-        $item_name                  = sprintf( '[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name( array( 'id' => $item->ID ) ) );
150
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) );
149
+        $item_name                  = sprintf('[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name(array('id' => $item->ID)));
150
+        $paypal_args['item_name']   = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8'));
151 151
         
152
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
152
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
153 153
             $paypal_args['a1']  = $initial_amount;
154 154
             $paypal_args['p1']  = $item->get_trial_interval();
155 155
             $paypal_args['t1']  = $item->get_trial_period();
156 156
             
157 157
             // Set the recurring amount
158 158
             $paypal_args['a3']  = $recurring_amount;
159
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
159
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
160 160
             $paypal_args['a1']  = $initial_amount;
161 161
             $paypal_args['p1']  = $interval;
162 162
             $paypal_args['t1']  = $period;
@@ -164,63 +164,63 @@  discard block
 block discarded – undo
164 164
             // Set the recurring amount
165 165
             $paypal_args['a3']  = $recurring_amount;
166 166
             
167
-            if ( $bill_times > 1 ) {
167
+            if ($bill_times > 1) {
168 168
                 $bill_times--;
169 169
             }
170 170
         } else {
171
-            $paypal_args['a3']  = $initial_amount;
171
+            $paypal_args['a3'] = $initial_amount;
172 172
         }
173 173
         
174 174
         $paypal_args['p3']  = $interval;
175 175
         $paypal_args['t3']  = $period;
176 176
         
177
-        if ( $bill_times > 1 ) {
177
+        if ($bill_times > 1) {
178 178
             // Make sure it's not over the max of 52
179
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
179
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
180 180
         }
181 181
                 
182 182
         // Remove cart items
183 183
         $i = 1;
184
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
185
-            foreach ( $purchase_data['cart_details'] as $item ) {                
186
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
187
-                    unset( $paypal_args['item_number_' . $i] );
184
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
185
+            foreach ($purchase_data['cart_details'] as $item) {                
186
+                if (isset($paypal_args['item_number_' . $i])) {
187
+                    unset($paypal_args['item_number_' . $i]);
188 188
                 }
189
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
190
-                    unset( $paypal_args['item_name_' . $i] );
189
+                if (isset($paypal_args['item_name_' . $i])) {
190
+                    unset($paypal_args['item_name_' . $i]);
191 191
                 }
192
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
193
-                    unset( $paypal_args['quantity_' . $i] );
192
+                if (isset($paypal_args['quantity_' . $i])) {
193
+                    unset($paypal_args['quantity_' . $i]);
194 194
                 }
195
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
196
-                    unset( $paypal_args['amount_' . $i] );
195
+                if (isset($paypal_args['amount_' . $i])) {
196
+                    unset($paypal_args['amount_' . $i]);
197 197
                 }
198
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
199
-                    unset( $paypal_args['discount_amount_' . $i] );
198
+                if (isset($paypal_args['discount_amount_' . $i])) {
199
+                    unset($paypal_args['discount_amount_' . $i]);
200 200
                 }
201 201
 
202 202
                 $i++;
203 203
             }
204 204
         }
205 205
         
206
-        if ( isset( $paypal_args['tax_cart'] ) ) {
207
-            unset( $paypal_args['tax_cart'] );
206
+        if (isset($paypal_args['tax_cart'])) {
207
+            unset($paypal_args['tax_cart']);
208 208
         }
209 209
                 
210
-        if ( isset( $paypal_args['upload'] ) ) {
211
-            unset( $paypal_args['upload'] );
210
+        if (isset($paypal_args['upload'])) {
211
+            unset($paypal_args['upload']);
212 212
         }
213 213
         
214
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
214
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
215 215
     }
216 216
     
217 217
     return $paypal_args;
218 218
 }
219
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
220 220
 
221 221
 function wpinv_process_paypal_ipn() {
222 222
 	// Check the request method is POST
223
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
224 224
 		return;
225 225
 	}
226 226
 
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
 	$post_data = '';
229 229
 
230 230
 	// Fallback just in case post_max_size is lower than needed
231
-	if ( ini_get( 'allow_url_fopen' ) ) {
232
-		$post_data = file_get_contents( 'php://input' );
231
+	if (ini_get('allow_url_fopen')) {
232
+		$post_data = file_get_contents('php://input');
233 233
 	} else {
234 234
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
235
-		ini_set( 'post_max_size', '12M' );
235
+		ini_set('post_max_size', '12M');
236 236
 	}
237 237
 	// Start the encoded data collection with notification command
238 238
 	$encoded_data = 'cmd=_notify-validate';
@@ -241,43 +241,43 @@  discard block
 block discarded – undo
241 241
 	$arg_separator = wpinv_get_php_arg_separator_output();
242 242
 
243 243
 	// Verify there is a post_data
244
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
+	if ($post_data || strlen($post_data) > 0) {
245 245
 		// Append the data
246
-		$encoded_data .= $arg_separator.$post_data;
246
+		$encoded_data .= $arg_separator . $post_data;
247 247
 	} else {
248 248
 		// Check if POST is empty
249
-		if ( empty( $_POST ) ) {
249
+		if (empty($_POST)) {
250 250
 			// Nothing to do
251 251
 			return;
252 252
 		} else {
253 253
 			// Loop through each POST
254
-			foreach ( $_POST as $key => $value ) {
254
+			foreach ($_POST as $key => $value) {
255 255
 				// Encode the value and append the data
256
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
257 257
 			}
258 258
 		}
259 259
 	}
260 260
 
261 261
 	// Convert collected post data to an array
262
-	wp_parse_str( $encoded_data, $encoded_data_array );
262
+	wp_parse_str($encoded_data, $encoded_data_array);
263 263
 
264
-	foreach ( $encoded_data_array as $key => $value ) {
265
-		if ( false !== strpos( $key, 'amp;' ) ) {
266
-			$new_key = str_replace( '&amp;', '&', $key );
267
-			$new_key = str_replace( 'amp;', '&' , $new_key );
264
+	foreach ($encoded_data_array as $key => $value) {
265
+		if (false !== strpos($key, 'amp;')) {
266
+			$new_key = str_replace('&amp;', '&', $key);
267
+			$new_key = str_replace('amp;', '&', $new_key);
268 268
 
269
-			unset( $encoded_data_array[ $key ] );
270
-			$encoded_data_array[ $new_key ] = $value;
269
+			unset($encoded_data_array[$key]);
270
+			$encoded_data_array[$new_key] = $value;
271 271
 		}
272 272
 	}
273 273
 
274 274
 	// Get the PayPal redirect uri
275
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
276 276
 
277
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
278 278
 		// Validate the IPN
279 279
 
280
-		$remote_post_vars      = array(
280
+		$remote_post_vars = array(
281 281
 			'method'           => 'POST',
282 282
 			'timeout'          => 45,
283 283
 			'redirection'      => 5,
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
 		);
296 296
 
297 297
 		// Get response
298
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
299 299
 
300
-		if ( is_wp_error( $api_response ) ) {
301
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
300
+		if (is_wp_error($api_response)) {
301
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
302 302
 			return; // Something went wrong
303 303
 		}
304 304
 
305
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
306
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
305
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
306
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
307 307
 			return; // Response not okay
308 308
 		}
309 309
 	}
310 310
 
311 311
 	// Check if $post_data_array has been populated
312
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
313 313
 		return;
314 314
 
315 315
 	$defaults = array(
@@ -317,265 +317,265 @@  discard block
 block discarded – undo
317 317
 		'payment_status' => ''
318 318
 	);
319 319
 
320
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
321 321
 
322
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
323 323
     
324
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
325
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
324
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
325
+	wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__);
326 326
 
327
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
328 328
 		// Allow PayPal IPN types to be processed separately
329
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
330 330
 	} else {
331 331
 		// Fallback to web accept just in case the txn_type isn't present
332
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
332
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
333 333
 	}
334 334
 	exit;
335 335
 }
336
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
336
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
337 337
 
338
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
339
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
338
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
339
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
340 340
 		return;
341 341
 	}
342 342
 
343
-	if( empty( $invoice_id ) ) {
343
+	if (empty($invoice_id)) {
344 344
 		return;
345 345
 	}
346 346
 
347 347
 	// Collect payment details
348
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
348
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
349 349
 	$paypal_amount  = $data['mc_gross'];
350
-	$payment_status = strtolower( $data['payment_status'] );
351
-	$currency_code  = strtolower( $data['mc_currency'] );
352
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
353
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
350
+	$payment_status = strtolower($data['payment_status']);
351
+	$currency_code  = strtolower($data['mc_currency']);
352
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
353
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
354 354
 
355
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
356 356
 		return; // this isn't a PayPal standard IPN
357 357
 	}
358 358
 
359 359
 	// Verify payment recipient
360
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
361
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
362
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
363
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
360
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
361
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
362
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
363
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true);
364 364
 		return;
365 365
 	}
366 366
 
367 367
 	// Verify payment currency
368
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
369
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
370
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
371
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
368
+	if ($currency_code != strtolower($payment_meta['currency'])) {
369
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
370
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
371
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true);
372 372
 		return;
373 373
 	}
374 374
 
375
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
+	if (!wpinv_get_payment_user_email($invoice_id)) {
376 376
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
377 377
 		// No email associated with purchase, so store from PayPal
378
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
379 379
 
380 380
 		// Setup and store the customer's details
381 381
 		$user_info = array(
382 382
 			'user_id'    => '-1',
383
-			'email'      => sanitize_text_field( $data['payer_email'] ),
384
-			'first_name' => sanitize_text_field( $data['first_name'] ),
385
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
383
+			'email'      => sanitize_text_field($data['payer_email']),
384
+			'first_name' => sanitize_text_field($data['first_name']),
385
+			'last_name'  => sanitize_text_field($data['last_name']),
386 386
 			'discount'   => '',
387 387
 		);
388
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
389
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
390
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
391
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
392
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
388
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
389
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
390
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
391
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
392
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
393 393
 
394 394
 		$payment_meta['user_info'] = $user_info;
395
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
396 396
 	}
397 397
 
398
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
399 399
 		// Process a refund
400
-		wpinv_process_paypal_refund( $data, $invoice_id );
400
+		wpinv_process_paypal_refund($data, $invoice_id);
401 401
 	} else {
402
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
402
+		if (get_post_status($invoice_id) == 'publish') {
403 403
 			return; // Only paid payments once
404 404
 		}
405 405
 
406 406
 		// Retrieve the total purchase amount (before PayPal)
407
-		$payment_amount = wpinv_payment_total( $invoice_id );
407
+		$payment_amount = wpinv_payment_total($invoice_id);
408 408
 
409
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
409
+		if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) {
410 410
 			// The prices don't match
411
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
412
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
413
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
411
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
412
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
413
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true);
414 414
 			return;
415 415
 		}
416
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
416
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
417 417
 			// Purchase keys don't match
418
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
419
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
420
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
418
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
419
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
420
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true);
421 421
 			return;
422 422
 		}
423 423
 
424
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
425
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
426
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
427
-			wpinv_update_payment_status( $invoice_id, 'publish' );
428
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
424
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
425
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
426
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
427
+			wpinv_update_payment_status($invoice_id, 'publish');
428
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
429 429
 			// Look for possible pending reasons, such as an echeck
430 430
 			$note = '';
431 431
 
432
-			switch( strtolower( $data['pending_reason'] ) ) {
432
+			switch (strtolower($data['pending_reason'])) {
433 433
 				case 'echeck' :
434
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
435 435
 					break;
436 436
 				
437 437
                 case 'address' :
438
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
439 439
 					break;
440 440
 				
441 441
                 case 'intl' :
442
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
443 443
 					break;
444 444
 				
445 445
                 case 'multi-currency' :
446
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
446
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
447 447
 					break;
448 448
 				
449 449
                 case 'paymentreview' :
450 450
                 case 'regulatory_review' :
451
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
452 452
 					break;
453 453
 				
454 454
                 case 'unilateral' :
455
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
456 456
 					break;
457 457
 				
458 458
                 case 'upgrade' :
459
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
460 460
 					break;
461 461
 				
462 462
                 case 'verify' :
463
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
464 464
 					break;
465 465
 
466 466
 				case 'other' :
467
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
468 468
 					break;
469 469
 			}
470 470
 
471
-			if ( ! empty( $note ) ) {
472
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
471
+			if (!empty($note)) {
472
+				wpinv_insert_payment_note($invoice_id, $note, '', '', true);
473 473
 			}
474 474
 		} else {
475
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
475
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true);
476 476
 		}
477 477
 	}
478 478
 }
479
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
479
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
480 480
 
481 481
 // Process PayPal subscription sign ups
482
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
482
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
483 483
 
484 484
 // Process PayPal subscription payments
485
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
485
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
486 486
 
487 487
 // Process PayPal subscription cancellations
488
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
488
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
489 489
 
490 490
 // Process PayPal subscription end of term notices
491
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
491
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
492 492
 
493 493
 // Process PayPal payment failed
494
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
494
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
495 495
 
496 496
 
497 497
 /**
498 498
  * Process the subscription started IPN.
499 499
  */
500
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
501
-    $parent_invoice_id = absint( $ipn_data['custom'] );
502
-    if( empty( $parent_invoice_id ) ) {
500
+function wpinv_process_paypal_subscr_signup($ipn_data) {
501
+    $parent_invoice_id = absint($ipn_data['custom']);
502
+    if (empty($parent_invoice_id)) {
503 503
         return;
504 504
     }
505 505
 
506
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
507
-    if ( empty( $invoice ) ) {
506
+    $invoice = wpinv_get_invoice($parent_invoice_id);
507
+    if (empty($invoice)) {
508 508
         return;
509 509
     }
510 510
 
511
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
512
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true);
513
-        if ( !empty( $ipn_data['txn_id'] ) ) {
514
-            wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
511
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
512
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true);
513
+        if (!empty($ipn_data['txn_id'])) {
514
+            wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
515 515
         }
516 516
     }
517 517
 
518
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
519
-    if ( false === $subscription ) {
518
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
519
+    if (false === $subscription) {
520 520
         return;
521 521
     }
522 522
     
523
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
523
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
524 524
     sleep(1);
525
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
526
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
525
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
526
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
527 527
 
528 528
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
529
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
530
-    $created    = date_i18n( 'Y-m-d H:i:s' );
531
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
529
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
530
+    $created    = date_i18n('Y-m-d H:i:s');
531
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
532 532
 
533 533
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
534
-    $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
534
+    $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration));
535 535
 }
536 536
 
537 537
 /**
538 538
  * Process the subscription payment received IPN.
539 539
  */
540
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
541
-    $parent_invoice_id = absint( $ipn_data['custom'] );
540
+function wpinv_process_paypal_subscr_payment($ipn_data) {
541
+    $parent_invoice_id = absint($ipn_data['custom']);
542 542
 
543
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
544
-    if ( empty( $parent_invoice ) ) {
543
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
544
+    if (empty($parent_invoice)) {
545 545
         return;
546 546
     }
547 547
 
548
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
549
-    if ( false === $subscription ) {
548
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
549
+    if (false === $subscription) {
550 550
         return;
551 551
     }
552 552
 
553
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
553
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
554 554
     $times_billed   = $subscription->get_times_billed();
555
-    $signup_date    = strtotime( $subscription->created );
556
-    $today          = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) );
555
+    $signup_date    = strtotime($subscription->created);
556
+    $today          = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date']));
557 557
 
558 558
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
559
-    if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
560
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
559
+    if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
560
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
561 561
         sleep(1);
562 562
         
563 563
         // This is the very first payment
564
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
565
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
564
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
565
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
566 566
         return;
567 567
     }
568 568
 
569
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
569
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
570 570
         return; // Payment already recorded
571 571
     }
572 572
 
573
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
573
+    $currency_code = strtolower($ipn_data['mc_currency']);
574 574
 
575 575
     // verify details
576
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
576
+    if ($currency_code != strtolower(wpinv_get_currency())) {
577 577
         // the currency code is invalid
578
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
578
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
579 579
         return;
580 580
     }
581 581
 
@@ -585,11 +585,11 @@  discard block
 block discarded – undo
585 585
         'gateway'        => 'paypal'
586 586
     );
587 587
     
588
-    $invoice_id = $subscription->add_payment( $args );
588
+    $invoice_id = $subscription->add_payment($args);
589 589
 
590
-    if ( $invoice_id > 0 ) {
591
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
592
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
590
+    if ($invoice_id > 0) {
591
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
592
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
593 593
 
594 594
         $subscription->renew();
595 595
     }
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 /**
599 599
  * Process the subscription canceled IPN.
600 600
  */
601
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
602
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
601
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
602
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
603 603
 
604
-    if( false === $subscription ) {
604
+    if (false === $subscription) {
605 605
         return;
606 606
     }
607 607
 
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription expired IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_eot($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,40 +624,40 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription payment failed IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_failed($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
634 634
     $subscription->failing();
635 635
 
636
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
636
+    do_action('wpinv_recurring_payment_failed', $subscription);
637 637
 }
638 638
 
639 639
 /**
640 640
  * Retrieve the subscription this IPN notice is for.
641 641
  */
642
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
643
-    $parent_invoice_id = absint( $ipn_data['custom'] );
642
+function wpinv_get_paypal_subscription($ipn_data = array()) {
643
+    $parent_invoice_id = absint($ipn_data['custom']);
644 644
 
645
-    if( empty( $parent_invoice_id ) ) {
645
+    if (empty($parent_invoice_id)) {
646 646
         return false;
647 647
     }
648 648
 
649
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
650
-    if ( empty( $invoice ) ) {
649
+    $invoice = wpinv_get_invoice($parent_invoice_id);
650
+    if (empty($invoice)) {
651 651
         return false;
652 652
     }
653 653
 
654
-    $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true );
654
+    $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true);
655 655
 
656
-    if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) {
657
-        $subscription = wpinv_get_subscription( $parent_invoice_id );
656
+    if (!(!empty($subscription) && $subscription->id > 0)) {
657
+        $subscription = wpinv_get_subscription($parent_invoice_id);
658 658
 
659
-        if ( ! empty( $subscription ) && $subscription->id > 0 ) {
660
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
659
+        if (!empty($subscription) && $subscription->id > 0) {
660
+            $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
661 661
         } else {
662 662
             return false;
663 663
         }
@@ -667,46 +667,46 @@  discard block
 block discarded – undo
667 667
 
668 668
 }
669 669
 
670
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
670
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
671 671
 	// Collect payment details
672 672
 
673
-	if( empty( $invoice_id ) ) {
673
+	if (empty($invoice_id)) {
674 674
 		return;
675 675
 	}
676 676
 
677
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
677
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
678 678
 		return; // Only refund payments once
679 679
 	}
680 680
 
681
-	$payment_amount = wpinv_payment_total( $invoice_id );
681
+	$payment_amount = wpinv_payment_total($invoice_id);
682 682
 	$refund_amount  = $data['mc_gross'] * -1;
683 683
 
684
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
684
+	do_action('wpinv_paypal_refund_request', $data, $invoice_id);
685 685
 
686
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
687
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
686
+	if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) {
687
+		wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float) $refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true);
688 688
 
689
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
689
+		do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount);
690 690
 
691 691
 		return; // This is a partial refund
692 692
 	}
693 693
 
694
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
695
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
696
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
694
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true);
695
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
696
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
697 697
 
698
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
698
+	do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id);
699 699
 }
700 700
 
701
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
702
-    if ( is_ssl() || ! $ssl_check ) {
701
+function wpinv_get_paypal_redirect($ssl_check = false) {
702
+    if (is_ssl() || !$ssl_check) {
703 703
         $protocol = 'https://';
704 704
     } else {
705 705
         $protocol = 'http://';
706 706
     }
707 707
 
708 708
     // Check the current payment mode
709
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
709
+    if (wpinv_is_test_mode('paypal')) {
710 710
         // Test mode
711 711
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
712 712
     } else {
@@ -714,120 +714,120 @@  discard block
 block discarded – undo
714 714
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
715 715
     }
716 716
 
717
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
717
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
718 718
 }
719 719
 
720
-function wpinv_paypal_success_page_content( $content ) {
720
+function wpinv_paypal_success_page_content($content) {
721 721
     global $wpi_invoice;
722 722
     
723 723
     $session = wpinv_get_checkout_session();
724 724
 
725
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
725
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
726 726
         return $content;
727 727
     }
728 728
 
729
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
729
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
730 730
 
731
-    if ( empty(  $invoice_id ) ) {
731
+    if (empty($invoice_id)) {
732 732
         return $content;
733 733
     }
734 734
 
735
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
735
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
736 736
     
737
-    if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) {
737
+    if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) {
738 738
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
739 739
         ob_start();
740
-        wpinv_get_template_part( 'wpinv-payment-processing' );
740
+        wpinv_get_template_part('wpinv-payment-processing');
741 741
         $content = ob_get_clean();
742 742
     }
743 743
 
744 744
     return $content;
745 745
 }
746
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
746
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
747 747
 
748
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
748
+function wpinv_paypal_get_transaction_id($invoice_id) {
749 749
     $transaction_id = '';
750
-    $notes = wpinv_get_invoice_notes( $invoice_id );
750
+    $notes = wpinv_get_invoice_notes($invoice_id);
751 751
 
752
-    foreach ( $notes as $note ) {
753
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
752
+    foreach ($notes as $note) {
753
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
754 754
             $transaction_id = $match[1];
755 755
             continue;
756 756
         }
757 757
     }
758 758
 
759
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
759
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
760 760
 }
761
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
761
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
762 762
 
763
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
764
-    if ( $transaction_id == $invoice_id ) {
763
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
764
+    if ($transaction_id == $invoice_id) {
765 765
         $transaction_link = $transaction_id;
766 766
     } else {
767
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
767
+        if (!empty($invoice) && !empty($invoice->mode)) {
768 768
             $mode = $invoice->mode;
769 769
         } else {
770
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
770
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
771 771
         }
772 772
 
773 773
         $sandbox = $mode == 'test' ? '.sandbox' : '';
774 774
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id;
775 775
 
776
-        $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
776
+        $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
777 777
     }
778 778
 
779
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice );
779
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice);
780 780
 }
781
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
781
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
782 782
 
783
-function wpinv_paypal_profile_id_link( $profile_id, $subscription ) {
783
+function wpinv_paypal_profile_id_link($profile_id, $subscription) {
784 784
     $link = $profile_id;
785 785
 
786
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
787
-        $invoice = wpinv_get_invoice( $invoice_id );
786
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
787
+        $invoice = wpinv_get_invoice($invoice_id);
788 788
 
789
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
789
+        if (!empty($invoice) && !empty($invoice->mode)) {
790 790
             $mode = $invoice->mode;
791 791
         } else {
792
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
792
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
793 793
         }
794 794
 
795 795
         $sandbox = $mode == 'test' ? '.sandbox' : '';
796 796
         $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id;
797 797
 
798
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
798
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
799 799
     }
800 800
     
801
-    return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription );
801
+    return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription);
802 802
 }
803
-add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 );
803
+add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2);
804 804
 
805
-function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) {
806
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
807
-        $invoice = wpinv_get_invoice( $invoice_id );
805
+function wpinv_paypal_transaction_id_link($transaction_id, $subscription) {
806
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
807
+        $invoice = wpinv_get_invoice($invoice_id);
808 808
 
809
-        if ( ! empty( $invoice ) ) {
810
-            return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice );
809
+        if (!empty($invoice)) {
810
+            return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice);
811 811
         }        
812 812
     }
813 813
     
814 814
     return $transaction_id;
815 815
 }
816
-add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 );
816
+add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2);
817 817
 
818 818
 function wpinv_is_paypal_valid_for_use() {
819
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) );
819
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR')));
820 820
 }
821 821
 
822
-function wpinv_check_paypal_currency_support( $gateway_list ) {
823
-    if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) {
824
-        unset( $gateway_list['paypal'] );
822
+function wpinv_check_paypal_currency_support($gateway_list) {
823
+    if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) {
824
+        unset($gateway_list['paypal']);
825 825
     }
826 826
     return $gateway_list;
827 827
 }
828
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 );
828
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1);
829 829
 
830
-function wpinv_gateway_paypal_button_label( $label ) {
831
-    return __( 'Proceed to PayPal', 'invoicing' );
830
+function wpinv_gateway_paypal_button_label($label) {
831
+    return __('Proceed to PayPal', 'invoicing');
832 832
 }
833
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
834 833
\ No newline at end of file
834
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
835 835
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -7,245 +7,245 @@  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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
82
+            $date_format = get_option('date_format');
83 83
             
84 84
             $m_time = $post->post_date;
85
-            $h_time = mysql2date( $date_format, $m_time );
85
+            $h_time = mysql2date($date_format, $m_time);
86 86
             
87
-            $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
87
+            $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
88 88
             break;
89 89
         case 'payment_date' :
90
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
91
-                $date_format = get_option( 'date_format' );
90
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
91
+                $date_format = get_option('date_format');
92 92
                 
93 93
                 $m_time = $date_completed;
94
-                $h_time = mysql2date( $date_format, $m_time );
94
+                $h_time = mysql2date($date_format, $m_time);
95 95
                 
96
-                $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
96
+                $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
97 97
             } else {
98 98
                 $value = '-';
99 99
             }
100 100
             break;
101 101
         case 'status' :
102
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
103
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
104
-	        $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() );
102
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
103
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
104
+	        $gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway());
105 105
 	        $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod'));
106 106
 	        $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false;
107 107
 
108
-            if ( 1 == $is_viewed ) {
109
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
108
+            if (1 == $is_viewed) {
109
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
110 110
             }
111
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment ) && ( isset( $gateway_title ) ) ) {
112
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
111
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment) && (isset($gateway_title))) {
112
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
113 113
             }
114 114
             break;
115 115
         case 'number' :
116
-            $edit_link = get_edit_post_link( $post->ID );
117
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
116
+            $edit_link = get_edit_post_link($post->ID);
117
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
118 118
             break;
119 119
         case 'wpi_actions' :
120 120
             $value = '';
121
-            if ( !empty( $post->post_name ) ) {
122
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121
+            if (!empty($post->post_name)) {
122
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123 123
             }
124 124
             
125
-            if ( $email = $wpi_invoice->get_email() ) {
126
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125
+            if ($email = $wpi_invoice->get_email()) {
126
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127 127
             }
128 128
             
129 129
             break;
130 130
         default:
131
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
131
+            $value = isset($post->$column_name) ? $post->$column_name : '';
132 132
             break;
133 133
 
134 134
     }
135
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
135
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
136 136
     
137
-    if ( $value !== NULL ) {
137
+    if ($value !== NULL) {
138 138
         echo $value;
139 139
     }
140 140
 }
141 141
 
142
-function wpinv_admin_post_id( $id = 0 ) {
142
+function wpinv_admin_post_id($id = 0) {
143 143
     global $post;
144 144
 
145
-    if ( isset( $id ) && ! empty( $id ) ) {
146
-        return (int)$id;
147
-    } else if ( get_the_ID() ) {
145
+    if (isset($id) && !empty($id)) {
146
+        return (int) $id;
147
+    } else if (get_the_ID()) {
148 148
         return (int) get_the_ID();
149
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
149
+    } else if (isset($post->ID) && !empty($post->ID)) {
150 150
         return (int) $post->ID;
151
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
151
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
152 152
         return (int) $_GET['post'];
153
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
153
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
154 154
         return (int) $_GET['id'];
155
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
155
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
156 156
         return (int) $_POST['id'];
157 157
     } 
158 158
 
159 159
     return null;
160 160
 }
161 161
     
162
-function wpinv_admin_post_type( $id = 0 ) {
163
-    if ( !$id ) {
162
+function wpinv_admin_post_type($id = 0) {
163
+    if (!$id) {
164 164
         $id = wpinv_admin_post_id();
165 165
     }
166 166
     
167
-    $type = get_post_type( $id );
167
+    $type = get_post_type($id);
168 168
     
169
-    if ( !$type ) {
170
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
169
+    if (!$type) {
170
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
171 171
     }
172 172
     
173
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
173
+    return apply_filters('wpinv_admin_post_type', $type, $id);
174 174
 }
175 175
 
176 176
 function wpinv_admin_messages() {
177 177
 	global $wpinv_options, $pagenow, $post;
178 178
 
179
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
180
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
179
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
180
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
181 181
 	}
182 182
 
183
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
184
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
183
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
184
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
185 185
 	}
186 186
 
187
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
188
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
187
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
188
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
189 189
 	}
190 190
 
191
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
192
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
191
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
192
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
193 193
 	}
194 194
 
195
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
196
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
195
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
196
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
197 197
 	}
198 198
 
199
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
200
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
199
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
200
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
201 201
 	}
202 202
 
203
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
204
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
203
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
204
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
205 205
 	}
206 206
 
207
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
208
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
207
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
208
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
209 209
     }
210 210
     
211
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
212
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
211
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
212
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
213 213
     }
214 214
 
215
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
216
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
215
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
216
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
217 217
     }
218 218
 
219
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
220
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
219
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
220
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
221 221
 	}
222 222
 
223
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
224
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
223
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
224
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
225 225
 	}
226 226
 
227
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
228
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
227
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
228
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
229 229
 	}
230 230
     
231
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
232
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
231
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
232
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
233 233
 
234
-		if ( !empty( $message ) ) {
235
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
234
+		if (!empty($message)) {
235
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
236 236
 		}
237 237
 	}
238 238
 
239
-	settings_errors( 'wpinv-notices' );
239
+	settings_errors('wpinv-notices');
240 240
 }
241
-add_action( 'admin_notices', 'wpinv_admin_messages' );
241
+add_action('admin_notices', 'wpinv_admin_messages');
242 242
 
243
-add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' );
244
-function wpinv_show_test_payment_gateway_notice(){
245
-    add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' );
243
+add_action('admin_init', 'wpinv_show_test_payment_gateway_notice');
244
+function wpinv_show_test_payment_gateway_notice() {
245
+    add_action('admin_notices', 'wpinv_test_payment_gateway_messages');
246 246
 }
247 247
 
248
-function wpinv_test_payment_gateway_messages(){
248
+function wpinv_test_payment_gateway_messages() {
249 249
     $gateways = wpinv_get_enabled_payment_gateways();
250 250
     $name = array(); $test_gateways = '';
251 251
     if ($gateways) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         }
257 257
         $test_gateways = implode(', ', $name);
258 258
     }
259
-    if(isset($test_gateways) && !empty($test_gateways)){
259
+    if (isset($test_gateways) && !empty($test_gateways)) {
260 260
         $link = admin_url('admin.php?page=wpinv-settings&tab=gateways');
261
-        $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link );
261
+        $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link);
262 262
         ?>
263 263
         <div class="notice notice-warning is-dismissible">
264 264
             <p><?php echo $notice; ?></p>
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
     }
268 268
 }
269 269
 
270
-function wpinv_items_columns( $existing_columns ) {
270
+function wpinv_items_columns($existing_columns) {
271 271
     global $wpinv_euvat;
272 272
     
273 273
     $columns                = array();
274 274
     $columns['cb']          = $existing_columns['cb'];
275
-    $columns['title']       = __( 'Title', 'invoicing' );
276
-    $columns['price']       = __( 'Price', 'invoicing' );
277
-    if ( $wpinv_euvat->allow_vat_rules() ) {
278
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
275
+    $columns['title']       = __('Title', 'invoicing');
276
+    $columns['price']       = __('Price', 'invoicing');
277
+    if ($wpinv_euvat->allow_vat_rules()) {
278
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
279 279
     }
280
-    if ( $wpinv_euvat->allow_vat_classes() ) {
281
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
280
+    if ($wpinv_euvat->allow_vat_classes()) {
281
+        $columns['vat_class']   = __('VAT class', 'invoicing');
282 282
     }
283
-    $columns['type']        = __( 'Type', 'invoicing' );
284
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
285
-    $columns['date']        = __( 'Date', 'invoicing' );
286
-    $columns['id']          = __( 'ID', 'invoicing' );
283
+    $columns['type']        = __('Type', 'invoicing');
284
+    $columns['recurring']   = __('Recurring', 'invoicing');
285
+    $columns['date']        = __('Date', 'invoicing');
286
+    $columns['id']          = __('ID', 'invoicing');
287 287
 
288
-    return apply_filters( 'wpinv_items_columns', $columns );
288
+    return apply_filters('wpinv_items_columns', $columns);
289 289
 }
290
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
290
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
291 291
 
292
-function wpinv_items_sortable_columns( $columns ) {
292
+function wpinv_items_sortable_columns($columns) {
293 293
     $columns['price']       = 'price';
294 294
     $columns['vat_rule']    = 'vat_rule';
295 295
     $columns['vat_class']   = 'vat_class';
@@ -299,175 +299,175 @@  discard block
 block discarded – undo
299 299
 
300 300
     return $columns;
301 301
 }
302
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
302
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
303 303
 
304
-function wpinv_items_table_custom_column( $column ) {
304
+function wpinv_items_table_custom_column($column) {
305 305
     global $wpinv_euvat, $post, $wpi_item;
306 306
     
307
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
308
-        $wpi_item = new WPInv_Item( $post->ID );
307
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
308
+        $wpi_item = new WPInv_Item($post->ID);
309 309
     }
310 310
 
311
-    switch ( $column ) {
311
+    switch ($column) {
312 312
         case 'price' :
313
-            echo wpinv_item_price( $post->ID );
313
+            echo wpinv_item_price($post->ID);
314 314
         break;
315 315
         case 'vat_rule' :
316
-            echo $wpinv_euvat->item_rule_label( $post->ID );
316
+            echo $wpinv_euvat->item_rule_label($post->ID);
317 317
         break;
318 318
         case 'vat_class' :
319
-            echo $wpinv_euvat->item_class_label( $post->ID );
319
+            echo $wpinv_euvat->item_class_label($post->ID);
320 320
         break;
321 321
         case 'type' :
322
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
322
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
323 323
         break;
324 324
         case 'recurring' :
325
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
325
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
326 326
         break;
327 327
         case 'id' :
328 328
            echo $post->ID;
329 329
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
330
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
331
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
332
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
330
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
331
+                    if ($wpinv_euvat->allow_vat_rules()) {
332
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
333 333
                     }
334
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
335
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
334
+                    if ($wpinv_euvat->allow_vat_classes()) {
335
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
336 336
                     }
337
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
337
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
338 338
                 </div>';
339 339
         break;
340 340
     }
341 341
     
342
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
342
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
343 343
 }
344
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
344
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
345 345
 
346 346
 function wpinv_add_items_filters() {
347 347
     global $wpinv_euvat, $typenow;
348 348
 
349 349
     // Checks if the current post type is 'item'
350
-    if ( $typenow == 'wpi_item') {
351
-        if ( $wpinv_euvat->allow_vat_rules() ) {
350
+    if ($typenow == 'wpi_item') {
351
+        if ($wpinv_euvat->allow_vat_rules()) {
352 352
 
353 353
             // Sanitize selected vat rule.
354
-            $vat_rule   = '';
355
-            if( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['type'], $wpinv_euvat->get_rules() ) ) {
356
-                $class   =  $_GET['type'];
354
+            $vat_rule = '';
355
+            if (isset($_GET['vat_rule']) && array_key_exists($_GET['type'], $wpinv_euvat->get_rules())) {
356
+                $class = $_GET['type'];
357 357
             }
358 358
 
359
-            echo wpinv_html_select( array(
360
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
359
+            echo wpinv_html_select(array(
360
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
361 361
                     'name'             => 'vat_rule',
362 362
                     'id'               => 'vat_rule',
363
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
363
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
364 364
                     'show_option_all'  => false,
365 365
                     'show_option_none' => false,
366 366
                     'class'            => 'gdmbx2-text-medium wpi_select2',
367
-                    'placeholder'      => __( 'Select VAT rule', 'invoicing' ),
368
-                ) );
367
+                    'placeholder'      => __('Select VAT rule', 'invoicing'),
368
+                ));
369 369
         }
370 370
 
371
-        if ( $wpinv_euvat->allow_vat_classes() ) {
371
+        if ($wpinv_euvat->allow_vat_classes()) {
372 372
 
373 373
             $classes = $wpinv_euvat->get_all_classes();
374 374
 
375 375
             // Sanitize selected vat class.
376 376
             $class   = '';
377
-            if( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $classes ) ) {
378
-                $class   =  $_GET['vat_class'];
377
+            if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $classes)) {
378
+                $class = $_GET['vat_class'];
379 379
             }
380 380
 
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $classes ),
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $classes),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385 385
                     'selected'         => $class,
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium wpi_select2',
389
-                    'placeholder'      => __( 'Select VAT class', 'invoicing' ),
390
-                ) );
389
+                    'placeholder'      => __('Select VAT class', 'invoicing'),
390
+                ));
391 391
         }
392 392
         
393 393
         // Sanitize selected item type.
394
-        $type   = '';
395
-        if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
396
-            $class   =  $_GET['type'];
394
+        $type = '';
395
+        if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) {
396
+            $class = $_GET['type'];
397 397
         }
398 398
 
399
-        echo wpinv_html_select( array(
400
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
399
+        echo wpinv_html_select(array(
400
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
401 401
                 'name'             => 'type',
402 402
                 'id'               => 'type',
403 403
                 'selected'         => $type,
404 404
                 'show_option_all'  => false,
405 405
                 'show_option_none' => false,
406 406
                 'class'            => 'gdmbx2-text-medium',
407
-            ) );
407
+            ));
408 408
 
409
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
409
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
410 410
             echo '<input type="hidden" name="all_posts" value="1" />';
411 411
         }
412 412
     }
413 413
 }
414
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
414
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
415 415
 
416
-function wpinv_send_invoice_after_save( $invoice ) {
417
-    if ( empty( $_POST['wpi_save_send'] ) ) {
416
+function wpinv_send_invoice_after_save($invoice) {
417
+    if (empty($_POST['wpi_save_send'])) {
418 418
         return;
419 419
     }
420 420
     
421
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
422
-        wpinv_user_invoice_notification( $invoice->ID );
421
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
422
+        wpinv_user_invoice_notification($invoice->ID);
423 423
     }
424 424
 }
425
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
425
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
426 426
 
427
-function wpinv_send_register_new_user( $data, $postarr ) {
428
-    if ( wpinv_current_user_can_manage_invoicing() && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
429
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
430
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
427
+function wpinv_send_register_new_user($data, $postarr) {
428
+    if (wpinv_current_user_can_manage_invoicing() && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
429
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
430
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
431 431
         
432
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
433
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
434
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
435
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
436
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
437
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
432
+        if ($is_new_user && $email && !email_exists($email)) {
433
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
434
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
435
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
436
+            $user_nicename = $display_name ? trim($display_name) : $email;
437
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
438 438
             
439
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
440
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
439
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
440
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
441 441
                 $new_user_login = strstr($email, '@', true);
442
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
443
-                    $user_login = sanitize_user($new_user_login, true );
442
+                if (validate_username($user_login) && username_exists($user_login)) {
443
+                    $user_login = sanitize_user($new_user_login, true);
444 444
                 }
445
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
446
-                    $user_append_text = rand(10,1000);
447
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
445
+                if (validate_username($user_login) && username_exists($user_login)) {
446
+                    $user_append_text = rand(10, 1000);
447
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
448 448
                 }
449 449
                 
450
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
450
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
451 451
                     $user_login = $email;
452 452
                 }
453 453
             }
454 454
             
455 455
             $userdata = array(
456 456
                 'user_login' => $user_login,
457
-                'user_pass' => wp_generate_password( 12, false ),
458
-                'user_email' => sanitize_text_field( $email ),
457
+                'user_pass' => wp_generate_password(12, false),
458
+                'user_email' => sanitize_text_field($email),
459 459
                 'first_name' => $first_name,
460 460
                 'last_name' => $last_name,
461
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
461
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
462 462
                 'nickname' => $display_name,
463 463
                 'display_name' => $display_name,
464 464
             );
465 465
 
466
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
466
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
467 467
             
468
-            $new_user_id = wp_insert_user( $userdata );
468
+            $new_user_id = wp_insert_user($userdata);
469 469
             
470
-            if ( !is_wp_error( $new_user_id ) ) {
470
+            if (!is_wp_error($new_user_id)) {
471 471
                 $data['post_author'] = $new_user_id;
472 472
                 $_POST['post_author'] = $new_user_id;
473 473
                 $_POST['post_author_override'] = $new_user_id;
@@ -488,72 +488,72 @@  discard block
 block discarded – undo
488 488
                 
489 489
                 $meta = array();
490 490
                 ///$meta['_wpinv_user_id'] = $new_user_id;
491
-                foreach ( $meta_fields as $field ) {
492
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
491
+                foreach ($meta_fields as $field) {
492
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
493 493
                 }
494 494
                 
495
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
495
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
496 496
 
497 497
                 // Update user meta.
498
-                foreach ( $meta as $key => $value ) {
499
-                    update_user_meta( $new_user_id, $key, $value );
498
+                foreach ($meta as $key => $value) {
499
+                    update_user_meta($new_user_id, $key, $value);
500 500
                 }
501 501
                 
502
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
502
+                if (function_exists('wp_send_new_user_notifications')) {
503 503
                     // Send email notifications related to the creation of new user.
504
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
504
+                    wp_send_new_user_notifications($new_user_id, 'user');
505 505
                 }
506 506
             } else {
507
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
507
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
508 508
             }
509 509
         }
510 510
     }
511 511
     
512 512
     return $data;
513 513
 }
514
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
514
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
515 515
 
516
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
516
+function wpinv_show_recurring_supported_gateways($item_ID) {
517 517
     $all_gateways = wpinv_get_payment_gateways();
518 518
 
519
-    if ( !empty( $all_gateways ) ) {
519
+    if (!empty($all_gateways)) {
520 520
         $gateways = array();
521 521
 
522
-        foreach ( $all_gateways as $key => $gateway ) {
523
-            if ( wpinv_gateway_support_subscription( $key ) ) {
522
+        foreach ($all_gateways as $key => $gateway) {
523
+            if (wpinv_gateway_support_subscription($key)) {
524 524
                 $gateways[] = $gateway['admin_label'];
525 525
             }
526 526
         }
527 527
 
528
-        if ( !empty( $gateways ) ) {
528
+        if (!empty($gateways)) {
529 529
             ?>
530
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
530
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
531 531
             <?php
532 532
         }
533 533
     }
534 534
 }
535
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
535
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
536 536
 
537
-function wpinv_post_updated_messages( $messages ) {
537
+function wpinv_post_updated_messages($messages) {
538 538
     global $post, $post_ID;
539 539
 
540 540
     $messages['wpi_discount'] = array(
541 541
         0   => '',
542
-        1   => __( 'Discount updated.', 'invoicing' ),
543
-        2   => __( 'Custom field updated.', 'invoicing' ),
544
-        3   => __( 'Custom field deleted.', 'invoicing' ),
545
-        4   => __( 'Discount updated.', 'invoicing' ),
546
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
547
-        6   => __( 'Discount updated.', 'invoicing' ),
548
-        7   => __( 'Discount saved.', 'invoicing' ),
549
-        8   => __( 'Discount submitted.', 'invoicing' ),
550
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
551
-        10  => __( 'Discount draft updated.', 'invoicing' ),
542
+        1   => __('Discount updated.', 'invoicing'),
543
+        2   => __('Custom field updated.', 'invoicing'),
544
+        3   => __('Custom field deleted.', 'invoicing'),
545
+        4   => __('Discount updated.', 'invoicing'),
546
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
547
+        6   => __('Discount updated.', 'invoicing'),
548
+        7   => __('Discount saved.', 'invoicing'),
549
+        8   => __('Discount submitted.', 'invoicing'),
550
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
551
+        10  => __('Discount draft updated.', 'invoicing'),
552 552
     );
553 553
 
554 554
     return $messages;
555 555
 }
556
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
556
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
557 557
 
558 558
 add_action('admin_init', 'admin_init_example_type');
559 559
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 function admin_init_example_type() {
564 564
     global $typenow;
565 565
 
566
-    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) {
566
+    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') {
567 567
         add_filter('posts_search', 'posts_search_example_type', 10, 2);
568 568
     }
569 569
 }
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
     global $wpdb;
579 579
 
580 580
     if ($query->is_main_query() && !empty($query->query['s'])) {
581
-        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )";
582
-        if ( ! empty( $search ) ) {
583
-            $search = preg_replace( '/^ AND /', '', $search );
581
+        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )";
582
+        if (!empty($search)) {
583
+            $search = preg_replace('/^ AND /', '', $search);
584 584
             $search = " AND ( {$search} OR ( {$conditions_str} ) )";
585 585
         } else {
586 586
             $search = " AND ( {$conditions_str} )";
@@ -590,9 +590,9 @@  discard block
 block discarded – undo
590 590
     return $search;
591 591
 }
592 592
 
593
-add_action( 'admin_init', 'wpinv_reset_invoice_count' );
594
-function wpinv_reset_invoice_count(){
595
-    if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
593
+add_action('admin_init', 'wpinv_reset_invoice_count');
594
+function wpinv_reset_invoice_count() {
595
+    if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
596 596
         wpinv_update_option('invoice_sequence_start', 1);
597 597
         delete_option('wpinv_last_invoice_number');
598 598
         $url = add_query_arg(array('reset_invoice_done' => 1));
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
 }
604 604
 
605 605
 add_action('admin_notices', 'wpinv_invoice_count_reset_message');
606
-function wpinv_invoice_count_reset_message(){
607
-    if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
606
+function wpinv_invoice_count_reset_message() {
607
+    if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
608 608
         $notice = __('Invoice number sequence reset successfully.', 'invoicing');
609 609
         ?>
610 610
         <div class="notice notice-success is-dismissible">
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +559 added lines, -559 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  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
-function wpinv_get_option( $key = '', $default = false ) {
7
+function wpinv_get_option($key = '', $default = false) {
8 8
     global $wpinv_options;
9 9
 
10
-    $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default;
11
-    $value = apply_filters( 'wpinv_get_option', $value, $key, $default );
10
+    $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default;
11
+    $value = apply_filters('wpinv_get_option', $value, $key, $default);
12 12
 
13
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
13
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
14 14
 }
15 15
 
16
-function wpinv_update_option( $key = '', $value = false ) {
16
+function wpinv_update_option($key = '', $value = false) {
17 17
     // If no key, exit
18
-    if ( empty( $key ) ) {
18
+    if (empty($key)) {
19 19
         return false;
20 20
     }
21 21
 
22
-    if ( empty( $value ) ) {
23
-        $remove_option = wpinv_delete_option( $key );
22
+    if (empty($value)) {
23
+        $remove_option = wpinv_delete_option($key);
24 24
         return $remove_option;
25 25
     }
26 26
 
27 27
     // First let's grab the current settings
28
-    $options = get_option( 'wpinv_settings' );
28
+    $options = get_option('wpinv_settings');
29 29
 
30 30
     // Let other plugin alter the value
31
-    $value = apply_filters( 'wpinv_update_option', $value, $key );
31
+    $value = apply_filters('wpinv_update_option', $value, $key);
32 32
 
33 33
     // Next let's try to update the value
34
-    $options[ $key ] = $value;
35
-    $did_update = update_option( 'wpinv_settings', $options );
34
+    $options[$key] = $value;
35
+    $did_update = update_option('wpinv_settings', $options);
36 36
 
37 37
     // If it's updated, let's update the global variable
38
-    if ( $did_update ) {
38
+    if ($did_update) {
39 39
         global $wpinv_options;
40
-        $wpinv_options[ $key ] = $value;
40
+        $wpinv_options[$key] = $value;
41 41
     }
42 42
 
43 43
     return $did_update;
44 44
 }
45 45
 
46
-function wpinv_delete_option( $key = '' ) {
46
+function wpinv_delete_option($key = '') {
47 47
     // If no key, exit
48
-    if ( empty( $key ) ) {
48
+    if (empty($key)) {
49 49
         return false;
50 50
     }
51 51
 
52 52
     // First let's grab the current settings
53
-    $options = get_option( 'wpinv_settings' );
53
+    $options = get_option('wpinv_settings');
54 54
 
55 55
     // Next let's try to update the value
56
-    if( isset( $options[ $key ] ) ) {
57
-        unset( $options[ $key ] );
56
+    if (isset($options[$key])) {
57
+        unset($options[$key]);
58 58
     }
59 59
 
60
-    $did_update = update_option( 'wpinv_settings', $options );
60
+    $did_update = update_option('wpinv_settings', $options);
61 61
 
62 62
     // If it updated, let's update the global variable
63
-    if ( $did_update ){
63
+    if ($did_update) {
64 64
         global $wpinv_options;
65 65
         $wpinv_options = $options;
66 66
     }
@@ -69,37 +69,37 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 function wpinv_get_settings() {
72
-    $settings = get_option( 'wpinv_settings' );
72
+    $settings = get_option('wpinv_settings');
73 73
 
74
-    if ( empty( $settings ) ) {
74
+    if (empty($settings)) {
75 75
         // Update old settings with new single option
76
-        $general_settings   = is_array( get_option( 'wpinv_settings_general' ) )    ? get_option( 'wpinv_settings_general' )    : array();
77
-        $gateways_settings  = is_array( get_option( 'wpinv_settings_gateways' ) )   ? get_option( 'wpinv_settings_gateways' )   : array();
78
-        $email_settings     = is_array( get_option( 'wpinv_settings_emails' ) )     ? get_option( 'wpinv_settings_emails' )     : array();
79
-        $tax_settings       = is_array( get_option( 'wpinv_settings_taxes' ) )      ? get_option( 'wpinv_settings_taxes' )      : array();
80
-        $misc_settings      = is_array( get_option( 'wpinv_settings_misc' ) )       ? get_option( 'wpinv_settings_misc' )       : array();
81
-        $tool_settings      = is_array( get_option( 'wpinv_settings_tools' ) )      ? get_option( 'wpinv_settings_tools' )      : array();
76
+        $general_settings   = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array();
77
+        $gateways_settings  = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array();
78
+        $email_settings     = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array();
79
+        $tax_settings       = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array();
80
+        $misc_settings      = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array();
81
+        $tool_settings      = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array();
82 82
 
83
-        $settings = array_merge( $general_settings, $gateways_settings, $email_settings, $tax_settings, $misc_settings, $tool_settings );
83
+        $settings = array_merge($general_settings, $gateways_settings, $email_settings, $tax_settings, $misc_settings, $tool_settings);
84 84
 
85
-        update_option( 'wpinv_settings', $settings );
85
+        update_option('wpinv_settings', $settings);
86 86
 
87 87
     }
88
-    return apply_filters( 'wpinv_get_settings', $settings );
88
+    return apply_filters('wpinv_get_settings', $settings);
89 89
 }
90 90
 
91 91
 function wpinv_register_settings() {
92
-    if ( false == get_option( 'wpinv_settings' ) ) {
93
-        add_option( 'wpinv_settings' );
92
+    if (false == get_option('wpinv_settings')) {
93
+        add_option('wpinv_settings');
94 94
     }
95 95
     
96 96
     $register_settings = wpinv_get_registered_settings();
97 97
     
98
-    foreach ( $register_settings as $tab => $sections ) {
99
-        foreach ( $sections as $section => $settings) {
98
+    foreach ($register_settings as $tab => $sections) {
99
+        foreach ($sections as $section => $settings) {
100 100
             // Check for backwards compatibility
101
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
102
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
101
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
102
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
103 103
                 $section = 'main';
104 104
                 $settings = $sections;
105 105
             }
@@ -111,41 +111,41 @@  discard block
 block discarded – undo
111 111
                 'wpinv_settings_' . $tab . '_' . $section
112 112
             );
113 113
 
114
-            foreach ( $settings as $option ) {
114
+            foreach ($settings as $option) {
115 115
                 // For backwards compatibility
116
-                if ( empty( $option['id'] ) ) {
116
+                if (empty($option['id'])) {
117 117
                     continue;
118 118
                 }
119 119
 
120
-                $name = isset( $option['name'] ) ? $option['name'] : '';
120
+                $name = isset($option['name']) ? $option['name'] : '';
121 121
 
122 122
                 add_settings_field(
123 123
                     'wpinv_settings[' . $option['id'] . ']',
124 124
                     $name,
125
-                    function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
125
+                    function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
126 126
                     'wpinv_settings_' . $tab . '_' . $section,
127 127
                     'wpinv_settings_' . $tab . '_' . $section,
128 128
                     array(
129 129
                         'section'     => $section,
130
-                        'id'          => isset( $option['id'] )          ? $option['id']          : null,
131
-                        'desc'        => ! empty( $option['desc'] )      ? $option['desc']        : '',
132
-                        'name'        => isset( $option['name'] )        ? $option['name']        : null,
133
-                        'size'        => isset( $option['size'] )        ? $option['size']        : null,
134
-                        'options'     => isset( $option['options'] )     ? $option['options']     : '',
135
-                        'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
136
-                        'std'         => isset( $option['std'] )         ? $option['std']         : '',
137
-                        'min'         => isset( $option['min'] )         ? $option['min']         : null,
138
-                        'max'         => isset( $option['max'] )         ? $option['max']         : null,
139
-                        'step'        => isset( $option['step'] )        ? $option['step']        : null,
140
-                        'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
141
-                        'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
142
-                        'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
143
-                        'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
144
-                        'onchange'    => !empty( $option['onchange'] )   ? $option['onchange']    : '',
145
-                        'custom'      => !empty( $option['custom'] )     ? $option['custom']      : '',
146
-                        'class'       =>  !empty( $option['class'] )     ? $option['class']      : '',
147
-                        'cols'        => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
148
-                        'rows'        => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
130
+                        'id'          => isset($option['id']) ? $option['id'] : null,
131
+                        'desc'        => !empty($option['desc']) ? $option['desc'] : '',
132
+                        'name'        => isset($option['name']) ? $option['name'] : null,
133
+                        'size'        => isset($option['size']) ? $option['size'] : null,
134
+                        'options'     => isset($option['options']) ? $option['options'] : '',
135
+                        'selected'    => isset($option['selected']) ? $option['selected'] : null,
136
+                        'std'         => isset($option['std']) ? $option['std'] : '',
137
+                        'min'         => isset($option['min']) ? $option['min'] : null,
138
+                        'max'         => isset($option['max']) ? $option['max'] : null,
139
+                        'step'        => isset($option['step']) ? $option['step'] : null,
140
+                        'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
141
+                        'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
142
+                        'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
143
+                        'faux'        => isset($option['faux']) ? $option['faux'] : false,
144
+                        'onchange'    => !empty($option['onchange']) ? $option['onchange'] : '',
145
+                        'custom'      => !empty($option['custom']) ? $option['custom'] : '',
146
+                        'class'       =>  !empty($option['class']) ? $option['class'] : '',
147
+                        'cols'        => !empty($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
148
+                        'rows'        => !empty($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
149 149
                     )
150 150
                 );
151 151
             }
@@ -153,203 +153,203 @@  discard block
 block discarded – undo
153 153
     }
154 154
 
155 155
     // Creates our settings in the options table
156
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
156
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
157 157
 }
158
-add_action( 'admin_init', 'wpinv_register_settings' );
158
+add_action('admin_init', 'wpinv_register_settings');
159 159
 
160 160
 function wpinv_get_registered_settings() {
161
-    $pages = wpinv_get_pages( true );
161
+    $pages = wpinv_get_pages(true);
162 162
     
163 163
     $currencies = wpinv_get_currencies();
164 164
     
165 165
     $currency_code_options = array();
166
-    foreach ( $currencies as $code => $name ) {
167
-        $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')';
166
+    foreach ($currencies as $code => $name) {
167
+        $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')';
168 168
     }
169 169
     
170 170
     $due_payment_options       = array();
171
-    $due_payment_options[0]    = __( 'Now', 'invoicing' );
172
-    for ( $i = 1; $i <= 30; $i++ ) {
171
+    $due_payment_options[0]    = __('Now', 'invoicing');
172
+    for ($i = 1; $i <= 30; $i++) {
173 173
         $due_payment_options[$i] = $i;
174 174
     }
175 175
     
176 176
     $invoice_number_padd_options = array();
177
-    for ( $i = 0; $i <= 20; $i++ ) {
177
+    for ($i = 0; $i <= 20; $i++) {
178 178
         $invoice_number_padd_options[$i] = $i;
179 179
     }
180 180
     
181 181
     $currency_symbol = wpinv_currency_symbol();
182 182
     
183 183
     $last_number = $reset_number = '';
184
-    if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) {
185
-        $last_invoice_number = is_numeric( $last_invoice_number ) ? $last_invoice_number : wpinv_clean_invoice_number( $last_invoice_number );
184
+    if ($last_invoice_number = get_option('wpinv_last_invoice_number')) {
185
+        $last_invoice_number = is_numeric($last_invoice_number) ? $last_invoice_number : wpinv_clean_invoice_number($last_invoice_number);
186 186
 
187
-        if ( !empty( $last_invoice_number ) ) {
188
-            $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number );
187
+        if (!empty($last_invoice_number)) {
188
+            $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number);
189 189
         }
190 190
 
191 191
         $nonce = wp_create_nonce('reset_invoice_count');
192
-        $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>';
192
+        $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>';
193 193
     }
194 194
     
195 195
     $alert_wrapper_start = '<p style="color: #F00">';
196 196
     $alert_wrapper_close = '</p>';
197 197
     $wpinv_settings = array(
198
-        'general' => apply_filters( 'wpinv_settings_general',
198
+        'general' => apply_filters('wpinv_settings_general',
199 199
             array(
200 200
                 'main' => array(
201 201
                     'location_settings' => array(
202 202
                         'id'   => 'location_settings',
203
-                        'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
203
+                        'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
204 204
                         'desc' => '',
205 205
                         'type' => 'header',
206 206
                     ),
207 207
                     'default_country' => array(
208 208
                         'id'      => 'default_country',
209
-                        'name'    => __( 'Default Country', 'invoicing' ),
210
-                        'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
209
+                        'name'    => __('Default Country', 'invoicing'),
210
+                        'desc'    => __('Where does your store operate from?', 'invoicing'),
211 211
                         'type'    => 'select',
212 212
                         'options' => wpinv_get_country_list(),
213 213
                         'std'     => 'GB',
214 214
                         'class'   => 'wpi_select2',
215
-                        'placeholder' => __( 'Select a country', 'invoicing' ),
215
+                        'placeholder' => __('Select a country', 'invoicing'),
216 216
                     ),
217 217
                     'default_state' => array(
218 218
                         'id'      => 'default_state',
219
-                        'name'    => __( 'Default State / Province', 'invoicing' ),
220
-                        'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
219
+                        'name'    => __('Default State / Province', 'invoicing'),
220
+                        'desc'    => __('What state / province does your store operate from?', 'invoicing'),
221 221
                         'type'    => 'country_states',
222 222
                         'class'   => 'wpi_select2',
223
-                        'placeholder' => __( 'Select a state', 'invoicing' ),
223
+                        'placeholder' => __('Select a state', 'invoicing'),
224 224
                     ),
225 225
                     'store_name' => array(
226 226
                         'id'   => 'store_name',
227
-                        'name' => __( 'Store Name', 'invoicing' ),
228
-                        'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
227
+                        'name' => __('Store Name', 'invoicing'),
228
+                        'desc' => __('Store name to print on invoices.', 'invoicing'),
229 229
                         'std'     => get_option('blogname'),
230 230
                         'type' => 'text',
231 231
                     ),
232 232
                     'logo' => array(
233 233
                         'id'   => 'logo',
234
-                        'name' => __( 'Logo URL', 'invoicing' ),
235
-                        'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
234
+                        'name' => __('Logo URL', 'invoicing'),
235
+                        'desc' => __('Store logo to print on invoices.', 'invoicing'),
236 236
                         'type' => 'text',
237 237
                     ),
238 238
                     'store_address' => array(
239 239
                         'id'   => 'store_address',
240
-                        'name' => __( 'Store Address', 'invoicing' ),
241
-                        'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
240
+                        'name' => __('Store Address', 'invoicing'),
241
+                        'desc' => __('Enter the store address to display on invoice', 'invoicing'),
242 242
                         'type' => 'textarea',
243 243
                     ),
244 244
                     'page_settings' => array(
245 245
                         'id'   => 'page_settings',
246
-                        'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
246
+                        'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
247 247
                         'desc' => '',
248 248
                         'type' => 'header',
249 249
                     ),
250 250
                     'checkout_page' => array(
251 251
                         'id'          => 'checkout_page',
252
-                        'name'        => __( 'Checkout Page', 'invoicing' ),
253
-                        'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
252
+                        'name'        => __('Checkout Page', 'invoicing'),
253
+                        'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
254 254
                         'type'        => 'select',
255 255
                         'options'     => $pages,
256 256
                         'class'       => 'wpi_select2',
257
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
257
+                        'placeholder' => __('Select a page', 'invoicing'),
258 258
                     ),
259 259
                     'tandc_page' => array(
260 260
                         'id'          => 'tandc_page',
261
-                        'name'        => __( 'Terms & Conditions', 'invoicing' ),
262
-                        'desc'        => __( 'If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing' ),
261
+                        'name'        => __('Terms & Conditions', 'invoicing'),
262
+                        'desc'        => __('If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing'),
263 263
                         'type'        => 'select',
264
-                        'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
264
+                        'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
265 265
                         'class'       => 'wpi_select2',
266
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
266
+                        'placeholder' => __('Select a page', 'invoicing'),
267 267
                     ),
268 268
                     'success_page' => array(
269 269
                         'id'          => 'success_page',
270
-                        'name'        => __( 'Success Page', 'invoicing' ),
271
-                        'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
270
+                        'name'        => __('Success Page', 'invoicing'),
271
+                        'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
272 272
                         'type'        => 'select',
273 273
                         'options'     => $pages,
274 274
                         'class'       => 'wpi_select2',
275
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
275
+                        'placeholder' => __('Select a page', 'invoicing'),
276 276
                     ),
277 277
                     'failure_page' => array(
278 278
                         'id'          => 'failure_page',
279
-                        'name'        => __( 'Failed Transaction Page', 'invoicing' ),
280
-                        'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ),
279
+                        'name'        => __('Failed Transaction Page', 'invoicing'),
280
+                        'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'),
281 281
                         'type'        => 'select',
282 282
                         'options'     => $pages,
283 283
                         'class'       => 'wpi_select2',
284
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
284
+                        'placeholder' => __('Select a page', 'invoicing'),
285 285
                     ),
286 286
                     'invoice_history_page' => array(
287 287
                         'id'          => 'invoice_history_page',
288
-                        'name'        => __( 'Invoice History Page', 'invoicing' ),
289
-                        'desc'        => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ),
288
+                        'name'        => __('Invoice History Page', 'invoicing'),
289
+                        'desc'        => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'),
290 290
                         'type'        => 'select',
291 291
                         'options'     => $pages,
292 292
                         'class'       => 'wpi_select2',
293
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
293
+                        'placeholder' => __('Select a page', 'invoicing'),
294 294
                     ),
295 295
                     'invoice_subscription_page' => array(
296 296
                         'id'          => 'invoice_subscription_page',
297
-                        'name'        => __( 'Invoice Subscriptions Page', 'invoicing' ),
298
-                        'desc'        => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ),
297
+                        'name'        => __('Invoice Subscriptions Page', 'invoicing'),
298
+                        'desc'        => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'),
299 299
                         'type'        => 'select',
300 300
                         'options'     => $pages,
301 301
                         'class'       => 'wpi_select2',
302
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
302
+                        'placeholder' => __('Select a page', 'invoicing'),
303 303
                     ),
304 304
                 ),
305 305
                 'currency_section' => array(
306 306
                     'currency_settings' => array(
307 307
                         'id'   => 'currency_settings',
308
-                        'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
308
+                        'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
309 309
                         'desc' => '',
310 310
                         'type' => 'header',
311 311
                     ),
312 312
                     'currency' => array(
313 313
                         'id'      => 'currency',
314
-                        'name'    => __( 'Currency', 'invoicing' ),
315
-                        'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
314
+                        'name'    => __('Currency', 'invoicing'),
315
+                        'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
316 316
                         'type'    => 'select',
317 317
                         'class'       => 'wpi_select2',
318 318
                         'options' => $currency_code_options,
319 319
                     ),
320 320
                     'currency_position' => array(
321 321
                         'id'      => 'currency_position',
322
-                        'name'    => __( 'Currency Position', 'invoicing' ),
323
-                        'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
322
+                        'name'    => __('Currency Position', 'invoicing'),
323
+                        'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
324 324
                         'type'    => 'select',
325 325
                         'class'   => 'wpi_select2',
326 326
                         'options'  => array(
327
-                            'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
328
-                            'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
329
-                            'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
330
-                            'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
327
+                            'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
328
+                            'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
329
+                            'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
330
+                            'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
331 331
                         )
332 332
                     ),
333 333
                     'thousands_separator' => array(
334 334
                         'id'   => 'thousands_separator',
335
-                        'name' => __( 'Thousands Separator', 'invoicing' ),
336
-                        'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
335
+                        'name' => __('Thousands Separator', 'invoicing'),
336
+                        'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
337 337
                         'type' => 'text',
338 338
                         'size' => 'small',
339 339
                         'std'  => ',',
340 340
                     ),
341 341
                     'decimal_separator' => array(
342 342
                         'id'   => 'decimal_separator',
343
-                        'name' => __( 'Decimal Separator', 'invoicing' ),
344
-                        'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
343
+                        'name' => __('Decimal Separator', 'invoicing'),
344
+                        'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
345 345
                         'type' => 'text',
346 346
                         'size' => 'small',
347 347
                         'std'  => '.',
348 348
                     ),
349 349
                     'decimals' => array(
350 350
                         'id'   => 'decimals',
351
-                        'name' => __( 'Number of Decimals', 'invoicing' ),
352
-                        'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
351
+                        'name' => __('Number of Decimals', 'invoicing'),
352
+                        'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
353 353
                         'type' => 'number',
354 354
                         'size' => 'small',
355 355
                         'std'  => '2',
@@ -361,60 +361,60 @@  discard block
 block discarded – undo
361 361
                 'labels' => array(
362 362
                     'labels' => array(
363 363
                         'id'   => 'labels_settings',
364
-                        'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
364
+                        'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
365 365
                         'desc' => '',
366 366
                         'type' => 'header',
367 367
                     ),
368 368
                     'vat_name' => array(
369 369
                         'id' => 'vat_name',
370
-                        'name' => __( 'VAT Name', 'invoicing' ),
371
-                        'desc' => __( 'Enter the VAT name', 'invoicing' ),
370
+                        'name' => __('VAT Name', 'invoicing'),
371
+                        'desc' => __('Enter the VAT name', 'invoicing'),
372 372
                         'type' => 'text',
373 373
                         'size' => 'regular',
374 374
                         'std' => 'VAT'
375 375
                     ),
376 376
                     'vat_invoice_notice_label' => array(
377 377
                         'id' => 'vat_invoice_notice_label',
378
-                        'name' => __( 'Invoice Notice Label', 'invoicing' ),
379
-                        'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ),
378
+                        'name' => __('Invoice Notice Label', 'invoicing'),
379
+                        'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'),
380 380
                         'type' => 'text',
381 381
                         'size' => 'regular',
382 382
                     ),
383 383
                     'vat_invoice_notice' => array(
384 384
                         'id' => 'vat_invoice_notice',
385
-                        'name' => __( 'Invoice notice', 'invoicing' ),
386
-                        'desc' =>   __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ),
385
+                        'name' => __('Invoice notice', 'invoicing'),
386
+                        'desc' =>   __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'),
387 387
                         'type' => 'text',
388 388
                         'size' => 'regular',
389 389
                     ),
390 390
                     'name_your_price' => array(
391 391
                         'id'   => 'name_your_price_settings',
392
-                        'name' => '<h3>' . __( 'Name Your Price', 'invoicing' ) . '</h3>',
392
+                        'name' => '<h3>' . __('Name Your Price', 'invoicing') . '</h3>',
393 393
                         'desc' => '',
394 394
                         'type' => 'header',
395 395
                     ),
396 396
                     'suggested_price_text' => array(
397 397
                         'id'   => 'suggested_price_text',
398
-                        'name' => __( 'Suggested Price Text', 'invoicing' ),
399
-                        'desc' => __( "The label used to indicate an item's suggested price", 'invoicing' ),
398
+                        'name' => __('Suggested Price Text', 'invoicing'),
399
+                        'desc' => __("The label used to indicate an item's suggested price", 'invoicing'),
400 400
                         'type' => 'text',
401 401
                         'size' => 'regular',
402
-                        'std'  => __( 'Suggested Price:', 'invoicing' ),
402
+                        'std'  => __('Suggested Price:', 'invoicing'),
403 403
                     ),
404 404
                     'minimum_price_text' => array(
405 405
                         'id'   => 'minimum_price_text',
406
-                        'name' => __( 'Minimum Price Text', 'invoicing' ),
407
-                        'desc' => __( "The label used to indicate an item's minimum price", 'invoicing' ),
406
+                        'name' => __('Minimum Price Text', 'invoicing'),
407
+                        'desc' => __("The label used to indicate an item's minimum price", 'invoicing'),
408 408
                         'type' => 'text',
409 409
                         'size' => 'regular',
410
-                        'std'  => __( 'Minimum Price:', 'invoicing' ),
410
+                        'std'  => __('Minimum Price:', 'invoicing'),
411 411
                     ),
412 412
                     'name_your_price_text' => array(
413 413
                         'id'   => 'name_your_price_text',
414
-                        'name' => __( 'Name Your Price Text', 'invoicing' ),
414
+                        'name' => __('Name Your Price Text', 'invoicing'),
415 415
                         'type' => 'text',
416 416
                         'size' => 'regular',
417
-                        'std'  => __( 'Name Your Price', 'invoicing' ),
417
+                        'std'  => __('Name Your Price', 'invoicing'),
418 418
                     ),
419 419
                 )
420 420
             )
@@ -424,22 +424,22 @@  discard block
 block discarded – undo
424 424
                 'main' => array(
425 425
                     'gateway_settings' => array(
426 426
                         'id'   => 'api_header',
427
-                        'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
427
+                        'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
428 428
                         'desc' => '',
429 429
                         'type' => 'header',
430 430
                     ),
431 431
                     'gateways' => array(
432 432
                         'id'      => 'gateways',
433
-                        'name'    => __( 'Payment Gateways', 'invoicing' ),
434
-                        'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
433
+                        'name'    => __('Payment Gateways', 'invoicing'),
434
+                        'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
435 435
                         'type'    => 'gateways',
436 436
                         'std'     => array('manual'=>1),
437 437
                         'options' => wpinv_get_payment_gateways(),
438 438
                     ),
439 439
                     'default_gateway' => array(
440 440
                         'id'      => 'default_gateway',
441
-                        'name'    => __( 'Default Gateway', 'invoicing' ),
442
-                        'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
441
+                        'name'    => __('Default Gateway', 'invoicing'),
442
+                        'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
443 443
                         'type'    => 'gateway_select',
444 444
                         'std'     => 'manual',
445 445
                         'class'   => 'wpi_select2',
@@ -454,19 +454,19 @@  discard block
 block discarded – undo
454 454
                 'main' => array(
455 455
                     'tax_settings' => array(
456 456
                         'id'   => 'tax_settings',
457
-                        'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
457
+                        'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
458 458
                         'type' => 'header',
459 459
                     ),
460 460
                     'enable_taxes' => array(
461 461
                         'id'   => 'enable_taxes',
462
-                        'name' => __( 'Enable Taxes', 'invoicing' ),
463
-                        'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
462
+                        'name' => __('Enable Taxes', 'invoicing'),
463
+                        'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
464 464
                         'type' => 'checkbox',
465 465
                     ),
466 466
                     'tax_rate' => array(
467 467
                         'id'   => 'tax_rate',
468
-                        'name' => __( 'Fallback Tax Rate', 'invoicing' ),
469
-                        'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
468
+                        'name' => __('Fallback Tax Rate', 'invoicing'),
469
+                        'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
470 470
                         'type' => 'number',
471 471
                         'size' => 'small',
472 472
                         'min'  => '0',
@@ -478,8 +478,8 @@  discard block
 block discarded – undo
478 478
                 'rates' => array(
479 479
                     'tax_rates' => array(
480 480
                         'id'   => 'tax_rates',
481
-                        'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
482
-                        'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
481
+                        'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
482
+                        'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
483 483
                         'type' => 'tax_rates',
484 484
                     ),
485 485
                 )
@@ -491,61 +491,61 @@  discard block
 block discarded – undo
491 491
                 'main' => array(
492 492
                     'email_settings_header' => array(
493 493
                         'id'   => 'email_settings_header',
494
-                        'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
494
+                        'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
495 495
                         'type' => 'header',
496 496
                     ),
497 497
                     'email_from_name' => array(
498 498
                         'id'   => 'email_from_name',
499
-                        'name' => __( 'From Name', 'invoicing' ),
500
-                        'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
501
-                        'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
499
+                        'name' => __('From Name', 'invoicing'),
500
+                        'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
501
+                        'std' => esc_attr(get_bloginfo('name', 'display')),
502 502
                         'type' => 'text',
503 503
                     ),
504 504
                     'email_from' => array(
505 505
                         'id'   => 'email_from',
506
-                        'name' => __( 'From Email', 'invoicing' ),
507
-                        'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
508
-                        'std' => get_option( 'admin_email' ),
506
+                        'name' => __('From Email', 'invoicing'),
507
+                        'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
508
+                        'std' => get_option('admin_email'),
509 509
                         'type' => 'text',
510 510
                     ),
511 511
                     'overdue_settings_header' => array(
512 512
                         'id'   => 'overdue_settings_header',
513
-                        'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
513
+                        'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
514 514
                         'type' => 'header',
515 515
                     ),
516 516
                     'overdue_active' => array(
517 517
                         'id'   => 'overdue_active',
518
-                        'name' => __( 'Enable Due Date', 'invoicing' ),
519
-                        'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
518
+                        'name' => __('Enable Due Date', 'invoicing'),
519
+                        'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
520 520
                         'type' => 'checkbox',
521 521
                         'std'  => false,
522 522
                     ),
523 523
                     'overdue_days' => array(
524 524
                         'id'          => 'overdue_days',
525
-                        'name'        => __( 'Default Due Date', 'invoicing' ),
526
-                        'desc'        => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ),
525
+                        'name'        => __('Default Due Date', 'invoicing'),
526
+                        'desc'        => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'),
527 527
                         'type'        => 'select',
528 528
                         'options'     => $due_payment_options,
529 529
                         'std'         => 0,
530
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
530
+                        'placeholder' => __('Select a page', 'invoicing'),
531 531
                     ),
532 532
                     'email_template_header' => array(
533 533
                         'id'   => 'email_template_header',
534
-                        'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
534
+                        'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
535 535
                         'type' => 'header',
536 536
                     ),
537 537
                     'email_header_image' => array(
538 538
                         'id'   => 'email_header_image',
539
-                        'name' => __( 'Header Image', 'invoicing' ),
540
-                        'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
539
+                        'name' => __('Header Image', 'invoicing'),
540
+                        'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
541 541
                         'std' => '',
542 542
                         'type' => 'text',
543 543
                     ),
544 544
                     'email_footer_text' => array(
545 545
                         'id'   => 'email_footer_text',
546
-                        'name' => __( 'Footer Text', 'invoicing' ),
547
-                        'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
548
-                        'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
546
+                        'name' => __('Footer Text', 'invoicing'),
547
+                        'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
548
+                        'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
549 549
                         'type' => 'textarea',
550 550
                         'class' => 'regular-text',
551 551
                         'rows' => 2,
@@ -553,29 +553,29 @@  discard block
 block discarded – undo
553 553
                     ),
554 554
                     'email_base_color' => array(
555 555
                         'id'   => 'email_base_color',
556
-                        'name' => __( 'Base Color', 'invoicing' ),
557
-                        'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
556
+                        'name' => __('Base Color', 'invoicing'),
557
+                        'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
558 558
                         'std' => '#557da2',
559 559
                         'type' => 'color',
560 560
                     ),
561 561
                     'email_background_color' => array(
562 562
                         'id'   => 'email_background_color',
563
-                        'name' => __( 'Background Color', 'invoicing' ),
564
-                        'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
563
+                        'name' => __('Background Color', 'invoicing'),
564
+                        'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
565 565
                         'std' => '#f5f5f5',
566 566
                         'type' => 'color',
567 567
                     ),
568 568
                     'email_body_background_color' => array(
569 569
                         'id'   => 'email_body_background_color',
570
-                        'name' => __( 'Body Background Color', 'invoicing' ),
571
-                        'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
570
+                        'name' => __('Body Background Color', 'invoicing'),
571
+                        'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
572 572
                         'std' => '#fdfdfd',
573 573
                         'type' => 'color',
574 574
                     ),
575 575
                     'email_text_color' => array(
576 576
                         'id'   => 'email_text_color',
577
-                        'name' => __( 'Body Text Color', 'invoicing' ),
578
-                        'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
577
+                        'name' => __('Body Text Color', 'invoicing'),
578
+                        'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
579 579
                         'std' => '#505050',
580 580
                         'type' => 'color',
581 581
                     ),
@@ -594,26 +594,26 @@  discard block
 block discarded – undo
594 594
                 'main' => array(
595 595
                     'invoicing_privacy_policy_settings' => array(
596 596
                         'id'   => 'invoicing_privacy_policy_settings',
597
-                        'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>',
597
+                        'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>',
598 598
                         'type' => 'header',
599 599
                     ),
600 600
                     'privacy_page' => array(
601 601
                         'id'          => 'privacy_page',
602
-                        'name'        => __( 'Privacy Page', 'invoicing' ),
603
-                        'desc'        => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ),
602
+                        'name'        => __('Privacy Page', 'invoicing'),
603
+                        'desc'        => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'),
604 604
                         'type'        => 'select',
605
-                        'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
605
+                        'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
606 606
                         'class'       => 'wpi_select2',
607
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
607
+                        'placeholder' => __('Select a page', 'invoicing'),
608 608
                     ),
609 609
                     'invoicing_privacy_checkout_message' => array(
610 610
                         'id' => 'invoicing_privacy_checkout_message',
611
-                        'name' => __( 'Checkout privacy policy', 'invoicing' ),
612
-                        'desc' => __( 'Optionally add privacy policy message which will display on checkout page.', 'invoicing' ),
611
+                        'name' => __('Checkout privacy policy', 'invoicing'),
612
+                        'desc' => __('Optionally add privacy policy message which will display on checkout page.', 'invoicing'),
613 613
                         'type' => 'textarea',
614 614
                         'class'=> 'regular-text',
615 615
                         'rows' => 4,
616
-                        'std'  => sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ),
616
+                        'std'  => sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'),
617 617
                     ),
618 618
                 ),
619 619
             )
@@ -624,19 +624,19 @@  discard block
 block discarded – undo
624 624
                 'main' => array(
625 625
                     'invoice_number_format_settings' => array(
626 626
                         'id'   => 'invoice_number_format_settings',
627
-                        'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
627
+                        'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
628 628
                         'type' => 'header',
629 629
                     ),
630 630
                     'sequential_invoice_number' => array(
631 631
                         'id'   => 'sequential_invoice_number',
632
-                        'name' => __( 'Sequential Invoice Numbers', 'invoicing' ),
633
-                        'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number,
632
+                        'name' => __('Sequential Invoice Numbers', 'invoicing'),
633
+                        'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number,
634 634
                         'type' => 'checkbox',
635 635
                     ),
636 636
                     'invoice_sequence_start' => array(
637 637
                         'id'   => 'invoice_sequence_start',
638
-                        'name' => __( 'Sequential Starting Number', 'invoicing' ),
639
-                        'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number,
638
+                        'name' => __('Sequential Starting Number', 'invoicing'),
639
+                        'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number,
640 640
                         'type' => 'number',
641 641
                         'size' => 'small',
642 642
                         'std'  => '1',
@@ -644,8 +644,8 @@  discard block
 block discarded – undo
644 644
                     ),
645 645
                     'invoice_number_padd' => array(
646 646
                         'id'      => 'invoice_number_padd',
647
-                        'name'    => __( 'Minimum Digits', 'invoicing' ),
648
-                        'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
647
+                        'name'    => __('Minimum Digits', 'invoicing'),
648
+                        'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
649 649
                         'type'    => 'select',
650 650
                         'options' => $invoice_number_padd_options,
651 651
                         'std'     => 5,
@@ -653,8 +653,8 @@  discard block
 block discarded – undo
653 653
                     ),
654 654
                     'invoice_number_prefix' => array(
655 655
                         'id' => 'invoice_number_prefix',
656
-                        'name' => __( 'Invoice Number Prefix', 'invoicing' ),
657
-                        'desc' => __( 'Prefix for all invoice numbers. Ex: WPINV-', 'invoicing' ),
656
+                        'name' => __('Invoice Number Prefix', 'invoicing'),
657
+                        'desc' => __('Prefix for all invoice numbers. Ex: WPINV-', 'invoicing'),
658 658
                         'type' => 'text',
659 659
                         'size' => 'regular',
660 660
                         'std' => 'WPINV-',
@@ -662,32 +662,32 @@  discard block
 block discarded – undo
662 662
                     ),
663 663
                     'invoice_number_postfix' => array(
664 664
                         'id' => 'invoice_number_postfix',
665
-                        'name' => __( 'Invoice Number Postfix', 'invoicing' ),
666
-                        'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ),
665
+                        'name' => __('Invoice Number Postfix', 'invoicing'),
666
+                        'desc' => __('Postfix for all invoice numbers.', 'invoicing'),
667 667
                         'type' => 'text',
668 668
                         'size' => 'regular',
669 669
                         'std' => ''
670 670
                     ),
671 671
                     'checkout_settings' => array(
672 672
                         'id'   => 'checkout_settings',
673
-                        'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>',
673
+                        'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>',
674 674
                         'type' => 'header',
675 675
                     ),
676 676
                     'login_to_checkout' => array(
677 677
                         'id'   => 'login_to_checkout',
678
-                        'name' => __( 'Require Login To Checkout', 'invoicing' ),
679
-                        'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ),
678
+                        'name' => __('Require Login To Checkout', 'invoicing'),
679
+                        'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'),
680 680
                         'type' => 'checkbox',
681 681
                     ),
682 682
                     'uninstall_settings' => array(
683 683
                         'id'   => 'uninstall_settings',
684
-                        'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>',
684
+                        'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>',
685 685
                         'type' => 'header',
686 686
                     ),
687 687
                     'remove_data_on_unistall' => array(
688 688
                         'id'   => 'remove_data_on_unistall',
689
-                        'name' => __( 'Remove Data on Uninstall?', 'invoicing' ),
690
-                        'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ),
689
+                        'name' => __('Remove Data on Uninstall?', 'invoicing'),
690
+                        'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'),
691 691
                         'type' => 'checkbox',
692 692
                         'std'  => ''
693 693
                     ),
@@ -695,80 +695,80 @@  discard block
 block discarded – undo
695 695
                 'fields' => array(
696 696
                     'fields_settings' => array(
697 697
                         'id'   => 'fields_settings',
698
-                        'name' => '<h3>' . __( 'Address Fields', 'invoicing' ) . '</h3>',
699
-                        'desc' => __( 'Tick fields which are mandatory in invoice address fields.', 'invoicing' ),
698
+                        'name' => '<h3>' . __('Address Fields', 'invoicing') . '</h3>',
699
+                        'desc' => __('Tick fields which are mandatory in invoice address fields.', 'invoicing'),
700 700
                         'type' => 'header',
701 701
                     ),
702 702
                     'fname_mandatory' => array(
703 703
                         'id'   => 'fname_mandatory',
704
-                        'name' => __( 'First Name', 'invoicing' ),
704
+                        'name' => __('First Name', 'invoicing'),
705 705
                         'type' => 'checkbox',
706 706
                         'std'  => true,
707 707
                     ),
708 708
                     'lname_mandatory' => array(
709 709
                         'id'   => 'lname_mandatory',
710
-                        'name' => __( 'Last Name', 'invoicing' ),
710
+                        'name' => __('Last Name', 'invoicing'),
711 711
                         'type' => 'checkbox',
712 712
                         'std'  => true,
713 713
                     ),
714 714
                     'address_mandatory' => array(
715 715
                         'id'   => 'address_mandatory',
716
-                        'name' => __( 'Address', 'invoicing' ),
716
+                        'name' => __('Address', 'invoicing'),
717 717
                         'type' => 'checkbox',
718 718
                         'std'  => true,
719 719
                     ),
720 720
                     'city_mandatory' => array(
721 721
                         'id'   => 'city_mandatory',
722
-                        'name' => __( 'City', 'invoicing' ),
722
+                        'name' => __('City', 'invoicing'),
723 723
                         'type' => 'checkbox',
724 724
                         'std'  => true,
725 725
                     ),
726 726
                     'country_mandatory' => array(
727 727
                         'id'   => 'country_mandatory',
728
-                        'name' => __( 'Country', 'invoicing' ),
728
+                        'name' => __('Country', 'invoicing'),
729 729
                         'type' => 'checkbox',
730 730
                         'std'  => true,
731 731
                     ),
732 732
                     'state_mandatory' => array(
733 733
                         'id'   => 'state_mandatory',
734
-                        'name' => __( 'State / Province', 'invoicing' ),
734
+                        'name' => __('State / Province', 'invoicing'),
735 735
                         'type' => 'checkbox',
736 736
                         'std'  => true,
737 737
                     ),
738 738
                     'zip_mandatory' => array(
739 739
                         'id'   => 'zip_mandatory',
740
-                        'name' => __( 'ZIP / Postcode', 'invoicing' ),
740
+                        'name' => __('ZIP / Postcode', 'invoicing'),
741 741
                         'type' => 'checkbox',
742 742
                         'std'  => true,
743 743
                     ),
744 744
                     'phone_mandatory' => array(
745 745
                         'id'   => 'phone_mandatory',
746
-                        'name' => __( 'Phone Number', 'invoicing' ),
746
+                        'name' => __('Phone Number', 'invoicing'),
747 747
                         'type' => 'checkbox',
748 748
                         'std'  => true,
749 749
                     ),
750 750
                     'force_show_company' => array(
751 751
                         'id'   => 'force_show_company',
752
-                        'name' => __( 'Force show company name at checkout.', 'invoicing' ),
752
+                        'name' => __('Force show company name at checkout.', 'invoicing'),
753 753
                         'type' => 'checkbox',
754 754
                         'std'  => false,
755 755
                     ),
756 756
                     'address_autofill_settings' => array(
757 757
                         'id'   => 'address_autofill_settings',
758
-                        'name' => '<h3>' . __( 'Google Address Auto Complete', 'invoicing' ) . '</h3>',
758
+                        'name' => '<h3>' . __('Google Address Auto Complete', 'invoicing') . '</h3>',
759 759
                         'type' => 'header',
760 760
                     ),
761 761
                     'address_autofill_active' => array(
762 762
                         'id'   => 'address_autofill_active',
763
-                        'name' => __( 'Enable/Disable', 'invoicing' ),
764
-                        'desc' => __( 'Enable google address auto complete', 'invoicing' ),
763
+                        'name' => __('Enable/Disable', 'invoicing'),
764
+                        'desc' => __('Enable google address auto complete', 'invoicing'),
765 765
                         'type' => 'checkbox',
766 766
                         'std'  => 0
767 767
                     ),
768 768
                     'address_autofill_api' => array(
769 769
                         'id' => 'address_autofill_api',
770
-                        'name' => __( 'Google Place API Key', 'invoicing' ),
771
-                        'desc' => wp_sprintf(__( 'Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing' ), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>' ),
770
+                        'name' => __('Google Place API Key', 'invoicing'),
771
+                        'desc' => wp_sprintf(__('Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing'), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>'),
772 772
                         'type' => 'text',
773 773
                         'size' => 'regular',
774 774
                         'std' => ''
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
                 'custom-css' => array(
778 778
                     'css_settings' => array(
779 779
                         'id'   => 'css_settings',
780
-                        'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>',
780
+                        'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>',
781 781
                         'type' => 'header',
782 782
                     ),
783 783
                     'template_custom_css' => array(
784 784
                         'id' => 'template_custom_css',
785
-                        'name' => __( 'Invoice Template CSS', 'invoicing' ),
786
-                        'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ),
785
+                        'name' => __('Invoice Template CSS', 'invoicing'),
786
+                        'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'),
787 787
                         'type' => 'textarea',
788 788
                         'class'=> 'regular-text',
789 789
                         'rows' => 10,
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
                 'main' => array(
798 798
                     'tool_settings' => array(
799 799
                         'id'   => 'tool_settings',
800
-                        'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
801
-                        'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
800
+                        'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
801
+                        'desc' => __('Invoicing diagnostic tools', 'invoicing'),
802 802
                         'type' => 'tools',
803 803
                     ),
804 804
                 ),
@@ -806,136 +806,136 @@  discard block
 block discarded – undo
806 806
         )
807 807
     );
808 808
 
809
-    return apply_filters( 'wpinv_registered_settings', $wpinv_settings );
809
+    return apply_filters('wpinv_registered_settings', $wpinv_settings);
810 810
 }
811 811
 
812
-function wpinv_settings_sanitize( $input = array() ) {
812
+function wpinv_settings_sanitize($input = array()) {
813 813
     global $wpinv_options;
814 814
 
815
-    if ( empty( wp_get_raw_referer() ) ) {
815
+    if (empty(wp_get_raw_referer())) {
816 816
         return $input;
817 817
     }
818 818
 
819
-    wp_parse_str( wp_get_raw_referer(), $referrer );
819
+    wp_parse_str(wp_get_raw_referer(), $referrer);
820 820
 
821 821
     $settings = wpinv_get_registered_settings();
822
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
823
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
822
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
823
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
824 824
 
825 825
     $input = $input ? $input : array();
826
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
827
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
826
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
827
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
828 828
 
829 829
     // Loop through each setting being saved and pass it through a sanitization filter
830
-    foreach ( $input as $key => $value ) {
830
+    foreach ($input as $key => $value) {
831 831
         // Get the setting type (checkbox, select, etc)
832
-        $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
832
+        $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
833 833
 
834
-        if ( $type ) {
834
+        if ($type) {
835 835
             // Field type specific filter
836
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
836
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
837 837
         }
838 838
 
839 839
         // General filter
840
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
840
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
841 841
     }
842 842
 
843 843
     // Loop through the whitelist and unset any that are empty for the tab being saved
844
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
845
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
844
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
845
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
846 846
 
847
-    $found_settings = array_merge( $main_settings, $section_settings );
847
+    $found_settings = array_merge($main_settings, $section_settings);
848 848
 
849
-    if ( ! empty( $found_settings ) ) {
850
-        foreach ( $found_settings as $key => $value ) {
849
+    if (!empty($found_settings)) {
850
+        foreach ($found_settings as $key => $value) {
851 851
 
852 852
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
853
-            if ( is_numeric( $key ) ) {
853
+            if (is_numeric($key)) {
854 854
                 $key = $value['id'];
855 855
             }
856 856
 
857
-            if ( empty( $input[ $key ] ) ) {
858
-                unset( $wpinv_options[ $key ] );
857
+            if (empty($input[$key])) {
858
+                unset($wpinv_options[$key]);
859 859
             }
860 860
         }
861 861
     }
862 862
 
863 863
     // Merge our new settings with the existing
864
-    $output = array_merge( $wpinv_options, $input );
864
+    $output = array_merge($wpinv_options, $input);
865 865
 
866
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
866
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
867 867
 
868 868
     return $output;
869 869
 }
870 870
 
871
-function wpinv_settings_sanitize_misc_accounting( $input ) {
871
+function wpinv_settings_sanitize_misc_accounting($input) {
872 872
     global $wpi_session;
873 873
 
874
-    if ( ! wpinv_current_user_can_manage_invoicing() ) {
874
+    if (!wpinv_current_user_can_manage_invoicing()) {
875 875
         return $input;
876 876
     }
877 877
 
878
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
878
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
879 879
         // Shows an admin notice about upgrading previous order numbers
880
-        $wpi_session->set( 'upgrade_sequential', '1' );
880
+        $wpi_session->set('upgrade_sequential', '1');
881 881
     }
882 882
 
883 883
     return $input;
884 884
 }
885
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
885
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
886 886
 
887
-function wpinv_settings_sanitize_tax_rates( $input ) {
888
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
887
+function wpinv_settings_sanitize_tax_rates($input) {
888
+    if (!wpinv_current_user_can_manage_invoicing()) {
889 889
         return $input;
890 890
     }
891 891
 
892
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
892
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
893 893
 
894 894
     $tax_rates = array();
895 895
 
896
-    if ( !empty( $new_rates ) ) {
897
-        foreach ( $new_rates as $rate ) {
898
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
896
+    if (!empty($new_rates)) {
897
+        foreach ($new_rates as $rate) {
898
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
899 899
                 continue;
900 900
             }
901 901
             
902
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
902
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
903 903
             
904 904
             $tax_rates[] = $rate;
905 905
         }
906 906
     }
907 907
 
908
-    update_option( 'wpinv_tax_rates', $tax_rates );
908
+    update_option('wpinv_tax_rates', $tax_rates);
909 909
 
910 910
     return $input;
911 911
 }
912
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
912
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
913 913
 
914
-function wpinv_sanitize_text_field( $input ) {
915
-    return trim( $input );
914
+function wpinv_sanitize_text_field($input) {
915
+    return trim($input);
916 916
 }
917
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
917
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
918 918
 
919 919
 function wpinv_get_settings_tabs() {
920 920
     $tabs             = array();
921
-    $tabs['general']  = __( 'General', 'invoicing' );
922
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
923
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
924
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
925
-    $tabs['privacy']  = __( 'Privacy', 'invoicing' );
926
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
927
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
928
-
929
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
921
+    $tabs['general']  = __('General', 'invoicing');
922
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
923
+    $tabs['taxes']    = __('Taxes', 'invoicing');
924
+    $tabs['emails']   = __('Emails', 'invoicing');
925
+    $tabs['privacy']  = __('Privacy', 'invoicing');
926
+    $tabs['misc']     = __('Misc', 'invoicing');
927
+    $tabs['tools']    = __('Tools', 'invoicing');
928
+
929
+    return apply_filters('wpinv_settings_tabs', $tabs);
930 930
 }
931 931
 
932
-function wpinv_get_settings_tab_sections( $tab = false ) {
932
+function wpinv_get_settings_tab_sections($tab = false) {
933 933
     $tabs     = false;
934 934
     $sections = wpinv_get_registered_settings_sections();
935 935
 
936
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
937
-        $tabs = $sections[ $tab ];
938
-    } else if ( $tab ) {
936
+    if ($tab && !empty($sections[$tab])) {
937
+        $tabs = $sections[$tab];
938
+    } else if ($tab) {
939 939
         $tabs = false;
940 940
     }
941 941
 
@@ -945,143 +945,143 @@  discard block
 block discarded – undo
945 945
 function wpinv_get_registered_settings_sections() {
946 946
     static $sections = false;
947 947
 
948
-    if ( false !== $sections ) {
948
+    if (false !== $sections) {
949 949
         return $sections;
950 950
     }
951 951
 
952 952
     $sections = array(
953
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
954
-            'main' => __( 'General Settings', 'invoicing' ),
955
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
956
-            'labels' => __( 'Label Texts', 'invoicing' ),
957
-        ) ),
958
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
959
-            'main' => __( 'Gateway Settings', 'invoicing' ),
960
-        ) ),
961
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
962
-            'main' => __( 'Tax Settings', 'invoicing' ),
963
-            'rates' => __( 'Tax Rates', 'invoicing' ),
964
-        ) ),
965
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
966
-            'main' => __( 'Email Settings', 'invoicing' ),
967
-        ) ),
968
-        'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
969
-            'main' => __( 'Privacy policy', 'invoicing' ),
970
-        ) ),
971
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
972
-            'main' => __( 'Miscellaneous', 'invoicing' ),
973
-            'fields' => __( 'Fields Settings', 'invoicing' ),
974
-            'custom-css' => __( 'Custom CSS', 'invoicing' ),
975
-        ) ),
976
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
977
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
978
-        ) ),
953
+        'general' => apply_filters('wpinv_settings_sections_general', array(
954
+            'main' => __('General Settings', 'invoicing'),
955
+            'currency_section' => __('Currency Settings', 'invoicing'),
956
+            'labels' => __('Label Texts', 'invoicing'),
957
+        )),
958
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
959
+            'main' => __('Gateway Settings', 'invoicing'),
960
+        )),
961
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
962
+            'main' => __('Tax Settings', 'invoicing'),
963
+            'rates' => __('Tax Rates', 'invoicing'),
964
+        )),
965
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
966
+            'main' => __('Email Settings', 'invoicing'),
967
+        )),
968
+        'privacy' => apply_filters('wpinv_settings_sections_privacy', array(
969
+            'main' => __('Privacy policy', 'invoicing'),
970
+        )),
971
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
972
+            'main' => __('Miscellaneous', 'invoicing'),
973
+            'fields' => __('Fields Settings', 'invoicing'),
974
+            'custom-css' => __('Custom CSS', 'invoicing'),
975
+        )),
976
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
977
+            'main' => __('Diagnostic Tools', 'invoicing'),
978
+        )),
979 979
     );
980 980
 
981
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
981
+    $sections = apply_filters('wpinv_settings_sections', $sections);
982 982
 
983 983
     return $sections;
984 984
 }
985 985
 
986
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
986
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
987 987
 	$pages_options = array();
988 988
 
989
-	if( $default_label !== NULL && $default_label !== false ) {
990
-		$pages_options = array( '' => $default_label ); // Blank option
989
+	if ($default_label !== NULL && $default_label !== false) {
990
+		$pages_options = array('' => $default_label); // Blank option
991 991
 	}
992 992
 
993 993
 	$pages = get_pages();
994
-	if ( $pages ) {
995
-		foreach ( $pages as $page ) {
994
+	if ($pages) {
995
+		foreach ($pages as $page) {
996 996
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
997
-            $pages_options[ $page->ID ] = $title;
997
+            $pages_options[$page->ID] = $title;
998 998
 		}
999 999
 	}
1000 1000
 
1001 1001
 	return $pages_options;
1002 1002
 }
1003 1003
 
1004
-function wpinv_header_callback( $args ) {
1005
-	if ( !empty( $args['desc'] ) ) {
1004
+function wpinv_header_callback($args) {
1005
+	if (!empty($args['desc'])) {
1006 1006
         echo $args['desc'];
1007 1007
     }
1008 1008
 }
1009 1009
 
1010
-function wpinv_hidden_callback( $args ) {
1010
+function wpinv_hidden_callback($args) {
1011 1011
 	global $wpinv_options;
1012 1012
 
1013
-	if ( isset( $args['set_value'] ) ) {
1013
+	if (isset($args['set_value'])) {
1014 1014
 		$value = $args['set_value'];
1015
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
1016
-		$value = $wpinv_options[ $args['id'] ];
1015
+	} elseif (isset($wpinv_options[$args['id']])) {
1016
+		$value = $wpinv_options[$args['id']];
1017 1017
 	} else {
1018
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1018
+		$value = isset($args['std']) ? $args['std'] : '';
1019 1019
 	}
1020 1020
 
1021
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1021
+	if (isset($args['faux']) && true === $args['faux']) {
1022 1022
 		$args['readonly'] = true;
1023
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1023
+		$value = isset($args['std']) ? $args['std'] : '';
1024 1024
 		$name  = '';
1025 1025
 	} else {
1026
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1026
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1027 1027
 	}
1028 1028
 
1029
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
1029
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
1030 1030
     
1031 1031
 	echo $html;
1032 1032
 }
1033 1033
 
1034
-function wpinv_checkbox_callback( $args ) {
1034
+function wpinv_checkbox_callback($args) {
1035 1035
 	global $wpinv_options;
1036 1036
     
1037
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1037
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1038 1038
 
1039
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1039
+	if (isset($args['faux']) && true === $args['faux']) {
1040 1040
 		$name = '';
1041 1041
 	} else {
1042 1042
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
1043 1043
 	}
1044 1044
 
1045
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
1045
+	$checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : '';
1046 1046
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
1047
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1047
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1048 1048
 
1049 1049
 	echo $html;
1050 1050
 }
1051 1051
 
1052
-function wpinv_multicheck_callback( $args ) {
1052
+function wpinv_multicheck_callback($args) {
1053 1053
 	global $wpinv_options;
1054 1054
 
1055
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
1056
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
1055
+	$sanitize_id = wpinv_sanitize_key($args['id']);
1056
+	$class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
1057 1057
 
1058
-	if ( ! empty( $args['options'] ) ) {
1058
+	if (!empty($args['options'])) {
1059 1059
 		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
1060
-        foreach( $args['options'] as $key => $option ):
1061
-			$sanitize_key = wpinv_sanitize_key( $key );
1062
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
1060
+        foreach ($args['options'] as $key => $option):
1061
+			$sanitize_key = wpinv_sanitize_key($key);
1062
+			if (isset($wpinv_options[$args['id']][$sanitize_key])) { 
1063 1063
 				$enabled = $sanitize_key;
1064 1064
 			} else { 
1065 1065
 				$enabled = NULL; 
1066 1066
 			}
1067
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
1068
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
1067
+			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
1068
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>';
1069 1069
 		endforeach;
1070 1070
 		echo '</div>';
1071 1071
 		echo '<p class="description">' . $args['desc'] . '</p>';
1072 1072
 	}
1073 1073
 }
1074 1074
 
1075
-function wpinv_payment_icons_callback( $args ) {
1075
+function wpinv_payment_icons_callback($args) {
1076 1076
 	global $wpinv_options;
1077 1077
     
1078
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1078
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1079 1079
 
1080
-	if ( ! empty( $args['options'] ) ) {
1081
-		foreach( $args['options'] as $key => $option ) {
1082
-            $sanitize_key = wpinv_sanitize_key( $key );
1080
+	if (!empty($args['options'])) {
1081
+		foreach ($args['options'] as $key => $option) {
1082
+            $sanitize_key = wpinv_sanitize_key($key);
1083 1083
             
1084
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
1084
+			if (isset($wpinv_options[$args['id']][$key])) {
1085 1085
 				$enabled = $option;
1086 1086
 			} else {
1087 1087
 				$enabled = NULL;
@@ -1089,197 +1089,197 @@  discard block
 block discarded – undo
1089 1089
 
1090 1090
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
1091 1091
 
1092
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
1092
+				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
1093 1093
 
1094
-				if ( wpinv_string_is_image_url( $key ) ) {
1095
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1094
+				if (wpinv_string_is_image_url($key)) {
1095
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1096 1096
 				} else {
1097
-					$card = strtolower( str_replace( ' ', '', $option ) );
1097
+					$card = strtolower(str_replace(' ', '', $option));
1098 1098
 
1099
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
1100
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
1099
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
1100
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
1101 1101
 					} else {
1102
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
1102
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
1103 1103
 						$content_dir = WP_CONTENT_DIR;
1104 1104
 
1105
-						if ( function_exists( 'wp_normalize_path' ) ) {
1105
+						if (function_exists('wp_normalize_path')) {
1106 1106
 							// Replaces backslashes with forward slashes for Windows systems
1107
-							$image = wp_normalize_path( $image );
1108
-							$content_dir = wp_normalize_path( $content_dir );
1107
+							$image = wp_normalize_path($image);
1108
+							$content_dir = wp_normalize_path($content_dir);
1109 1109
 						}
1110 1110
 
1111
-						$image = str_replace( $content_dir, content_url(), $image );
1111
+						$image = str_replace($content_dir, content_url(), $image);
1112 1112
 					}
1113 1113
 
1114
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1114
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1115 1115
 				}
1116 1116
 			echo $option . '</label>';
1117 1117
 		}
1118
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
1118
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
1119 1119
 	}
1120 1120
 }
1121 1121
 
1122
-function wpinv_radio_callback( $args ) {
1122
+function wpinv_radio_callback($args) {
1123 1123
 	global $wpinv_options;
1124 1124
     
1125
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1125
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1126 1126
     
1127
-    foreach ( $args['options'] as $key => $option ) :
1128
-		$sanitize_key = wpinv_sanitize_key( $key );
1127
+    foreach ($args['options'] as $key => $option) :
1128
+		$sanitize_key = wpinv_sanitize_key($key);
1129 1129
         
1130 1130
         $checked = false;
1131 1131
 
1132
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
1132
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
1133 1133
 			$checked = true;
1134
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
1134
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
1135 1135
 			$checked = true;
1136 1136
 
1137 1137
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
1138
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
1138
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
1139 1139
 	endforeach;
1140 1140
 
1141
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
1141
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
1142 1142
 }
1143 1143
 
1144
-function wpinv_gateways_callback( $args ) {
1144
+function wpinv_gateways_callback($args) {
1145 1145
 	global $wpinv_options;
1146 1146
     
1147
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1147
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1148 1148
 
1149
-	foreach ( $args['options'] as $key => $option ) :
1150
-		$sanitize_key = wpinv_sanitize_key( $key );
1149
+	foreach ($args['options'] as $key => $option) :
1150
+		$sanitize_key = wpinv_sanitize_key($key);
1151 1151
         
1152
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
1152
+        if (isset($wpinv_options['gateways'][$key]))
1153 1153
 			$enabled = '1';
1154 1154
 		else
1155 1155
 			$enabled = null;
1156 1156
 
1157
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
1158
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
1157
+		echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
1158
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
1159 1159
 	endforeach;
1160 1160
 }
1161 1161
 
1162 1162
 function wpinv_gateway_select_callback($args) {
1163 1163
 	global $wpinv_options;
1164 1164
     
1165
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1166
-    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
1165
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1166
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
1167 1167
 
1168
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
1168
+	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >';
1169 1169
 
1170
-	foreach ( $args['options'] as $key => $option ) :
1171
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1172
-            $selected = selected( $key, $args['selected'], false );
1170
+	foreach ($args['options'] as $key => $option) :
1171
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1172
+            $selected = selected($key, $args['selected'], false);
1173 1173
         } else {
1174
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
1174
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
1175 1175
         }
1176
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1176
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
1177 1177
 	endforeach;
1178 1178
 
1179 1179
 	echo '</select>';
1180
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1180
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1181 1181
 }
1182 1182
 
1183
-function wpinv_text_callback( $args ) {
1183
+function wpinv_text_callback($args) {
1184 1184
 	global $wpinv_options;
1185 1185
     
1186
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1186
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1187 1187
 
1188
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1189
-		$value = $wpinv_options[ $args['id'] ];
1188
+	if (isset($wpinv_options[$args['id']])) {
1189
+		$value = $wpinv_options[$args['id']];
1190 1190
 	} else {
1191
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1191
+		$value = isset($args['std']) ? $args['std'] : '';
1192 1192
 	}
1193 1193
 
1194
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1194
+	if (isset($args['faux']) && true === $args['faux']) {
1195 1195
 		$args['readonly'] = true;
1196
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1196
+		$value = isset($args['std']) ? $args['std'] : '';
1197 1197
 		$name  = '';
1198 1198
 	} else {
1199
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1199
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1200 1200
 	}
1201
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1201
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
1202 1202
 
1203 1203
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1204
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1205
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1206
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1204
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1205
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
1206
+	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1207 1207
 
1208 1208
 	echo $html;
1209 1209
 }
1210 1210
 
1211
-function wpinv_number_callback( $args ) {
1211
+function wpinv_number_callback($args) {
1212 1212
 	global $wpinv_options;
1213 1213
     
1214
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1214
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1215 1215
 
1216
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1217
-		$value = $wpinv_options[ $args['id'] ];
1216
+	if (isset($wpinv_options[$args['id']])) {
1217
+		$value = $wpinv_options[$args['id']];
1218 1218
 	} else {
1219
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1219
+		$value = isset($args['std']) ? $args['std'] : '';
1220 1220
 	}
1221 1221
 
1222
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1222
+	if (isset($args['faux']) && true === $args['faux']) {
1223 1223
 		$args['readonly'] = true;
1224
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1224
+		$value = isset($args['std']) ? $args['std'] : '';
1225 1225
 		$name  = '';
1226 1226
 	} else {
1227
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1227
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1228 1228
 	}
1229 1229
 
1230
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1231
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1232
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1233
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1230
+	$max  = isset($args['max']) ? $args['max'] : 999999;
1231
+	$min  = isset($args['min']) ? $args['min'] : 0;
1232
+	$step = isset($args['step']) ? $args['step'] : 1;
1233
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
1234 1234
 
1235
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1236
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1237
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1235
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1236
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
1237
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1238 1238
 
1239 1239
 	echo $html;
1240 1240
 }
1241 1241
 
1242
-function wpinv_textarea_callback( $args ) {
1242
+function wpinv_textarea_callback($args) {
1243 1243
 	global $wpinv_options;
1244 1244
     
1245
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1245
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1246 1246
 
1247
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1248
-		$value = $wpinv_options[ $args['id'] ];
1247
+	if (isset($wpinv_options[$args['id']])) {
1248
+		$value = $wpinv_options[$args['id']];
1249 1249
 	} else {
1250
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1250
+		$value = isset($args['std']) ? $args['std'] : '';
1251 1251
 	}
1252 1252
     
1253
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1254
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1253
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1254
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
1255 1255
 
1256
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1257
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1256
+	$html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
1257
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1258 1258
 
1259 1259
 	echo $html;
1260 1260
 }
1261 1261
 
1262
-function wpinv_password_callback( $args ) {
1262
+function wpinv_password_callback($args) {
1263 1263
 	global $wpinv_options;
1264 1264
     
1265
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1265
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1266 1266
 
1267
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1268
-		$value = $wpinv_options[ $args['id'] ];
1267
+	if (isset($wpinv_options[$args['id']])) {
1268
+		$value = $wpinv_options[$args['id']];
1269 1269
 	} else {
1270
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1270
+		$value = isset($args['std']) ? $args['std'] : '';
1271 1271
 	}
1272 1272
 
1273
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1274
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
1275
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1273
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1274
+	$html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
1275
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1276 1276
 
1277 1277
 	echo $html;
1278 1278
 }
1279 1279
 
1280 1280
 function wpinv_missing_callback($args) {
1281 1281
 	printf(
1282
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1282
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
1283 1283
 		'<strong>' . $args['id'] . '</strong>'
1284 1284
 	);
1285 1285
 }
@@ -1287,133 +1287,133 @@  discard block
 block discarded – undo
1287 1287
 function wpinv_select_callback($args) {
1288 1288
 	global $wpinv_options;
1289 1289
     
1290
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1290
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1291 1291
 
1292
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1293
-		$value = $wpinv_options[ $args['id'] ];
1292
+	if (isset($wpinv_options[$args['id']])) {
1293
+		$value = $wpinv_options[$args['id']];
1294 1294
 	} else {
1295
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1295
+		$value = isset($args['std']) ? $args['std'] : '';
1296 1296
 	}
1297 1297
     
1298
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1298
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1299 1299
         $value = $args['selected'];
1300 1300
     }
1301 1301
 
1302
-	if ( isset( $args['placeholder'] ) ) {
1302
+	if (isset($args['placeholder'])) {
1303 1303
 		$placeholder = $args['placeholder'];
1304 1304
 	} else {
1305 1305
 		$placeholder = '';
1306 1306
 	}
1307 1307
     
1308
-    if( !empty( $args['onchange'] ) ) {
1309
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
1308
+    if (!empty($args['onchange'])) {
1309
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
1310 1310
     } else {
1311 1311
         $onchange = '';
1312 1312
     }
1313 1313
 
1314
-    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
1314
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
1315 1315
 
1316
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1316
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '"  name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
1317 1317
 
1318
-	foreach ( $args['options'] as $option => $name ) {
1319
-		$selected = selected( $option, $value, false );
1320
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1318
+	foreach ($args['options'] as $option => $name) {
1319
+		$selected = selected($option, $value, false);
1320
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1321 1321
 	}
1322 1322
 
1323 1323
 	$html .= '</select>';
1324
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1324
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1325 1325
 
1326 1326
 	echo $html;
1327 1327
 }
1328 1328
 
1329
-function wpinv_color_select_callback( $args ) {
1329
+function wpinv_color_select_callback($args) {
1330 1330
 	global $wpinv_options;
1331 1331
     
1332
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1332
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1333 1333
 
1334
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1335
-		$value = $wpinv_options[ $args['id'] ];
1334
+	if (isset($wpinv_options[$args['id']])) {
1335
+		$value = $wpinv_options[$args['id']];
1336 1336
 	} else {
1337
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1337
+		$value = isset($args['std']) ? $args['std'] : '';
1338 1338
 	}
1339 1339
 
1340
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1340
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
1341 1341
 
1342
-	foreach ( $args['options'] as $option => $color ) {
1343
-		$selected = selected( $option, $value, false );
1344
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1342
+	foreach ($args['options'] as $option => $color) {
1343
+		$selected = selected($option, $value, false);
1344
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
1345 1345
 	}
1346 1346
 
1347 1347
 	$html .= '</select>';
1348
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1348
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1349 1349
 
1350 1350
 	echo $html;
1351 1351
 }
1352 1352
 
1353
-function wpinv_rich_editor_callback( $args ) {
1353
+function wpinv_rich_editor_callback($args) {
1354 1354
 	global $wpinv_options, $wp_version;
1355 1355
     
1356
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1356
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1357 1357
 
1358
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1359
-		$value = $wpinv_options[ $args['id'] ];
1358
+	if (isset($wpinv_options[$args['id']])) {
1359
+		$value = $wpinv_options[$args['id']];
1360 1360
 
1361
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1362
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1361
+		if (empty($args['allow_blank']) && empty($value)) {
1362
+			$value = isset($args['std']) ? $args['std'] : '';
1363 1363
 		}
1364 1364
 	} else {
1365
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1365
+		$value = isset($args['std']) ? $args['std'] : '';
1366 1366
 	}
1367 1367
 
1368
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1368
+	$rows = isset($args['size']) ? $args['size'] : 20;
1369 1369
 
1370
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1370
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
1371 1371
 		ob_start();
1372
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
1372
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false));
1373 1373
 		$html = ob_get_clean();
1374 1374
 	} else {
1375
-		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1375
+		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
1376 1376
 	}
1377 1377
 
1378
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1378
+	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1379 1379
 
1380 1380
 	echo $html;
1381 1381
 }
1382 1382
 
1383
-function wpinv_upload_callback( $args ) {
1383
+function wpinv_upload_callback($args) {
1384 1384
 	global $wpinv_options;
1385 1385
     
1386
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1386
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1387 1387
 
1388
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1388
+	if (isset($wpinv_options[$args['id']])) {
1389 1389
 		$value = $wpinv_options[$args['id']];
1390 1390
 	} else {
1391 1391
 		$value = isset($args['std']) ? $args['std'] : '';
1392 1392
 	}
1393 1393
 
1394
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1395
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1396
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1397
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1394
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1395
+	$html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
1396
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
1397
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1398 1398
 
1399 1399
 	echo $html;
1400 1400
 }
1401 1401
 
1402
-function wpinv_color_callback( $args ) {
1402
+function wpinv_color_callback($args) {
1403 1403
 	global $wpinv_options;
1404 1404
     
1405
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1405
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1406 1406
 
1407
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1408
-		$value = $wpinv_options[ $args['id'] ];
1407
+	if (isset($wpinv_options[$args['id']])) {
1408
+		$value = $wpinv_options[$args['id']];
1409 1409
 	} else {
1410
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1410
+		$value = isset($args['std']) ? $args['std'] : '';
1411 1411
 	}
1412 1412
 
1413
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1413
+	$default = isset($args['std']) ? $args['std'] : '';
1414 1414
 
1415
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
1416
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1415
+	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />';
1416
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1417 1417
 
1418 1418
 	echo $html;
1419 1419
 }
@@ -1421,9 +1421,9 @@  discard block
 block discarded – undo
1421 1421
 function wpinv_country_states_callback($args) {
1422 1422
 	global $wpinv_options;
1423 1423
     
1424
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1424
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1425 1425
 
1426
-	if ( isset( $args['placeholder'] ) ) {
1426
+	if (isset($args['placeholder'])) {
1427 1427
 		$placeholder = $args['placeholder'];
1428 1428
 	} else {
1429 1429
 		$placeholder = '';
@@ -1431,16 +1431,16 @@  discard block
 block discarded – undo
1431 1431
 
1432 1432
 	$states = wpinv_get_country_states();
1433 1433
 
1434
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
1435
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1434
+	$class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
1435
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
1436 1436
 
1437
-	foreach ( $states as $option => $name ) {
1438
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1439
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1437
+	foreach ($states as $option => $name) {
1438
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
1439
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1440 1440
 	}
1441 1441
 
1442 1442
 	$html .= '</select>';
1443
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1443
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1444 1444
 
1445 1445
 	echo $html;
1446 1446
 }
@@ -1455,96 +1455,96 @@  discard block
 block discarded – undo
1455 1455
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
1456 1456
 		<thead>
1457 1457
 			<tr>
1458
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
1459
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
1460
-                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
1461
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
1462
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
1463
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
1458
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
1459
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
1460
+                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
1461
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
1462
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
1463
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
1464 1464
 			</tr>
1465 1465
 		</thead>
1466 1466
         <tbody>
1467
-		<?php if( !empty( $rates ) ) : ?>
1468
-			<?php foreach( $rates as $key => $rate ) : ?>
1467
+		<?php if (!empty($rates)) : ?>
1468
+			<?php foreach ($rates as $key => $rate) : ?>
1469 1469
             <?php 
1470
-            $sanitized_key = wpinv_sanitize_key( $key );
1470
+            $sanitized_key = wpinv_sanitize_key($key);
1471 1471
             ?>
1472 1472
 			<tr>
1473 1473
 				<td class="wpinv_tax_country">
1474 1474
 					<?php
1475
-					echo wpinv_html_select( array(
1476
-						'options'          => wpinv_get_country_list( true ),
1475
+					echo wpinv_html_select(array(
1476
+						'options'          => wpinv_get_country_list(true),
1477 1477
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1478 1478
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1479 1479
 						'selected'         => $rate['country'],
1480 1480
 						'show_option_all'  => false,
1481 1481
 						'show_option_none' => false,
1482 1482
 						'class'            => 'wpinv-tax-country wpi_select2',
1483
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1484
-					) );
1483
+						'placeholder'      => __('Choose a country', 'invoicing')
1484
+					));
1485 1485
 					?>
1486 1486
 				</td>
1487 1487
 				<td class="wpinv_tax_state">
1488 1488
 					<?php
1489
-					$states = wpinv_get_country_states( $rate['country'] );
1490
-					if( !empty( $states ) ) {
1491
-						echo wpinv_html_select( array(
1492
-							'options'          => array_merge( array( '' => '' ), $states ),
1489
+					$states = wpinv_get_country_states($rate['country']);
1490
+					if (!empty($states)) {
1491
+						echo wpinv_html_select(array(
1492
+							'options'          => array_merge(array('' => ''), $states),
1493 1493
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1494 1494
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1495 1495
 							'selected'         => $rate['state'],
1496 1496
 							'show_option_all'  => false,
1497 1497
 							'show_option_none' => false,
1498 1498
                             'class'            => 'wpi_select2',
1499
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1500
-						) );
1499
+							'placeholder'      => __('Choose a state', 'invoicing')
1500
+						));
1501 1501
 					} else {
1502
-						echo wpinv_html_text( array(
1502
+						echo wpinv_html_text(array(
1503 1503
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1504
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1504
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
1505 1505
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1506
-						) );
1506
+						));
1507 1507
 					}
1508 1508
 					?>
1509 1509
 				</td>
1510 1510
 				<td class="wpinv_tax_global">
1511
-					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
1512
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1511
+					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/>
1512
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1513 1513
 				</td>
1514
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td>
1515
-                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td>
1516
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1514
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td>
1515
+                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td>
1516
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1517 1517
 			</tr>
1518 1518
 			<?php endforeach; ?>
1519 1519
 		<?php else : ?>
1520 1520
 			<tr>
1521 1521
 				<td class="wpinv_tax_country">
1522 1522
 					<?php
1523
-					echo wpinv_html_select( array(
1524
-						'options'          => wpinv_get_country_list( true ),
1523
+					echo wpinv_html_select(array(
1524
+						'options'          => wpinv_get_country_list(true),
1525 1525
 						'name'             => 'tax_rates[0][country]',
1526 1526
 						'show_option_all'  => false,
1527 1527
 						'show_option_none' => false,
1528 1528
 						'class'            => 'wpinv-tax-country wpi_select2',
1529
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1530
-					) ); ?>
1529
+						'placeholder'      => __('Choose a country', 'invoicing')
1530
+					)); ?>
1531 1531
 				</td>
1532 1532
 				<td class="wpinv_tax_state">
1533
-					<?php echo wpinv_html_text( array(
1533
+					<?php echo wpinv_html_text(array(
1534 1534
 						'name' => 'tax_rates[0][state]'
1535
-					) ); ?>
1535
+					)); ?>
1536 1536
 				</td>
1537 1537
 				<td class="wpinv_tax_global">
1538 1538
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
1539
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1539
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1540 1540
 				</td>
1541
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td>
1541
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>"/></td>
1542 1542
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
1543
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1543
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1544 1544
 			</tr>
1545 1545
 		<?php endif; ?>
1546 1546
         </tbody>
1547
-        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1547
+        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot>
1548 1548
 	</table>
1549 1549
 	<?php
1550 1550
 	echo ob_get_clean();
@@ -1555,76 +1555,76 @@  discard block
 block discarded – undo
1555 1555
     ob_start(); ?>
1556 1556
     </td><tr>
1557 1557
     <td colspan="2" class="wpinv_tools_tdbox">
1558
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1559
-    <?php do_action( 'wpinv_tools_before' ); ?>
1558
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1559
+    <?php do_action('wpinv_tools_before'); ?>
1560 1560
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1561 1561
         <thead>
1562 1562
             <tr>
1563
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1564
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1565
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1563
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1564
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1565
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1566 1566
             </tr>
1567 1567
         </thead>
1568
-            <?php do_action( 'wpinv_tools_row' ); ?>
1568
+            <?php do_action('wpinv_tools_row'); ?>
1569 1569
         <tbody>
1570 1570
         </tbody>
1571 1571
     </table>
1572
-    <?php do_action( 'wpinv_tools_after' ); ?>
1572
+    <?php do_action('wpinv_tools_after'); ?>
1573 1573
     <?php
1574 1574
     echo ob_get_clean();
1575 1575
 }
1576 1576
 
1577
-function wpinv_descriptive_text_callback( $args ) {
1578
-	echo wp_kses_post( $args['desc'] );
1577
+function wpinv_descriptive_text_callback($args) {
1578
+	echo wp_kses_post($args['desc']);
1579 1579
 }
1580 1580
 
1581
-function wpinv_hook_callback( $args ) {
1582
-	do_action( 'wpinv_' . $args['id'], $args );
1581
+function wpinv_hook_callback($args) {
1582
+	do_action('wpinv_' . $args['id'], $args);
1583 1583
 }
1584 1584
 
1585 1585
 function wpinv_set_settings_cap() {
1586 1586
 	return wpinv_get_capability();
1587 1587
 }
1588
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1588
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1589 1589
 
1590
-function wpinv_settings_sanitize_input( $value, $key ) {
1591
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1592
-        $value = wpinv_sanitize_amount( $value, 4 );
1590
+function wpinv_settings_sanitize_input($value, $key) {
1591
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1592
+        $value = wpinv_sanitize_amount($value, 4);
1593 1593
         $value = $value >= 100 ? 99 : $value;
1594 1594
     }
1595 1595
         
1596 1596
     return $value;
1597 1597
 }
1598
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1598
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1599 1599
 
1600
-function wpinv_on_update_settings( $old_value, $value, $option ) {
1601
-    $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : '';
1602
-    $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : '';
1600
+function wpinv_on_update_settings($old_value, $value, $option) {
1601
+    $old = !empty($old_value['remove_data_on_unistall']) ? 1 : '';
1602
+    $new = !empty($value['remove_data_on_unistall']) ? 1 : '';
1603 1603
     
1604
-    if ( $old != $new ) {
1605
-        update_option( 'wpinv_remove_data_on_invoice_unistall', $new );
1604
+    if ($old != $new) {
1605
+        update_option('wpinv_remove_data_on_invoice_unistall', $new);
1606 1606
     }
1607 1607
 }
1608
-add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 );
1609
-add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1610
-add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1611
-add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1612
-add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1613
-add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1614
-add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1615
-add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1616
-add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1617
-add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1618
-add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1619
-
1620
-function wpinv_settings_tab_bottom_emails( $active_tab, $section ) {
1608
+add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3);
1609
+add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1610
+add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1611
+add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1612
+add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1613
+add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1614
+add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1615
+add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1616
+add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1617
+add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2);
1618
+add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2);
1619
+
1620
+function wpinv_settings_tab_bottom_emails($active_tab, $section) {
1621 1621
     ?>
1622 1622
     <div class="wpinv-email-wc-row ">
1623 1623
         <div class="wpinv-email-wc-td">
1624
-            <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3>
1624
+            <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3>
1625 1625
             <p class="wpinv-email-wc-description">
1626 1626
                 <?php
1627
-                $description = __( 'The following wildcards can be used in email subjects, heading and content:<br>
1627
+                $description = __('The following wildcards can be used in email subjects, heading and content:<br>
1628 1628
                     <strong>{site_title} :</strong> Site Title<br>
1629 1629
                     <strong>{name} :</strong> Customer\'s full name<br>
1630 1630
                     <strong>{first_name} :</strong> Customer\'s first name<br>
@@ -1638,7 +1638,7 @@  discard block
 block discarded – undo
1638 1638
                     <strong>{invoice_due_date} :</strong> The date the invoice is due<br>
1639 1639
                     <strong>{date} :</strong> Today\'s date.<br>
1640 1640
                     <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br>
1641
-                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' );
1641
+                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing');
1642 1642
                 echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section);
1643 1643
                 ?>
1644 1644
             </p>
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  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
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
             'buy_items' => true,
78 78
         );
79 79
 
80
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
81
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
80
+        foreach ($ajax_events as $ajax_event => $nopriv) {
81
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
82 82
             
83
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
84
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
83
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
84
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
85 85
             }
86 86
 
87
-            if ( $nopriv ) {
88
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
+            if ($nopriv) {
88
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
89 89
 
90
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
91 91
             }
92 92
         }
93 93
     }
94 94
     
95 95
     public static function add_note() {
96
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
96
+        check_ajax_referer('add-invoice-note', '_nonce');
97 97
 
98
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
98
+        if (!wpinv_current_user_can_manage_invoicing()) {
99 99
             die(-1);
100 100
         }
101 101
 
102
-        $post_id   = absint( $_POST['post_id'] );
103
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
104
-        $note_type = sanitize_text_field( $_POST['note_type'] );
102
+        $post_id   = absint($_POST['post_id']);
103
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
104
+        $note_type = sanitize_text_field($_POST['note_type']);
105 105
 
106 106
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
107 107
 
108
-        if ( $post_id > 0 ) {
109
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
108
+        if ($post_id > 0) {
109
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
110 110
 
111
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
112
-                wpinv_get_invoice_note_line_item( $note_id );
111
+            if ($note_id > 0 && !is_wp_error($note_id)) {
112
+                wpinv_get_invoice_note_line_item($note_id);
113 113
             }
114 114
         }
115 115
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
     }
118 118
 
119 119
     public static function delete_note() {
120
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
120
+        check_ajax_referer('delete-invoice-note', '_nonce');
121 121
 
122
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
122
+        if (!wpinv_current_user_can_manage_invoicing()) {
123 123
             die(-1);
124 124
         }
125 125
 
126
-        $note_id = (int)$_POST['note_id'];
126
+        $note_id = (int) $_POST['note_id'];
127 127
 
128
-        if ( $note_id > 0 ) {
129
-            wp_delete_comment( $note_id, true );
128
+        if ($note_id > 0) {
129
+            wp_delete_comment($note_id, true);
130 130
         }
131 131
 
132 132
         die();
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     }
140 140
     
141 141
     public static function checkout() {
142
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
143
-            define( 'WPINV_CHECKOUT', true );
142
+        if (!defined('WPINV_CHECKOUT')) {
143
+            define('WPINV_CHECKOUT', true);
144 144
         }
145 145
 
146 146
         wpinv_process_checkout();
@@ -149,53 +149,53 @@  discard block
 block discarded – undo
149 149
     
150 150
     public static function add_invoice_item() {
151 151
         global $wpi_userID, $wpinv_ip_address_country;
152
-        check_ajax_referer( 'invoice-item', '_nonce' );
153
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
152
+        check_ajax_referer('invoice-item', '_nonce');
153
+        if (!wpinv_current_user_can_manage_invoicing()) {
154 154
             die(-1);
155 155
         }
156 156
         
157
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
158
-        $invoice_id = absint( $_POST['invoice_id'] );
157
+        $item_id    = sanitize_text_field($_POST['item_id']);
158
+        $invoice_id = absint($_POST['invoice_id']);
159 159
         
160
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
160
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
161 161
             die();
162 162
         }
163 163
         
164
-        $invoice    = wpinv_get_invoice( $invoice_id );
165
-        if ( empty( $invoice ) ) {
164
+        $invoice = wpinv_get_invoice($invoice_id);
165
+        if (empty($invoice)) {
166 166
             die();
167 167
         }
168 168
         
169
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
169
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
170 170
             die(); // Don't allow modify items for paid invoice.
171 171
         }
172 172
         
173
-        if ( !empty( $_POST['user_id'] ) ) {
174
-            $wpi_userID = absint( $_POST['user_id'] ); 
173
+        if (!empty($_POST['user_id'])) {
174
+            $wpi_userID = absint($_POST['user_id']); 
175 175
         }
176 176
 
177
-        $item = new WPInv_Item( $item_id );
178
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
177
+        $item = new WPInv_Item($item_id);
178
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
179 179
             die();
180 180
         }
181 181
         
182 182
         // Validate item before adding to invoice because recurring item must be paid individually.
183
-        if ( !empty( $invoice->cart_details ) ) {
183
+        if (!empty($invoice->cart_details)) {
184 184
             $valid = true;
185 185
             
186
-            if ( $recurring_item = $invoice->get_recurring() ) {
187
-                if ( $recurring_item != $item_id ) {
186
+            if ($recurring_item = $invoice->get_recurring()) {
187
+                if ($recurring_item != $item_id) {
188 188
                     $valid = false;
189 189
                 }
190
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
190
+            } else if (wpinv_is_recurring_item($item_id)) {
191 191
                 $valid = false;
192 192
             }
193 193
             
194
-            if ( !$valid ) {
194
+            if (!$valid) {
195 195
                 $response               = array();
196 196
                 $response['success']    = false;
197
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
198
-                wp_send_json( $response );
197
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
198
+                wp_send_json($response);
199 199
             }
200 200
         }
201 201
         
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
         
204 204
         $data                   = array();
205 205
         $data['invoice_id']     = $invoice_id;
206
-        $data['cart_discounts'] = $invoice->get_discounts( true );
206
+        $data['cart_discounts'] = $invoice->get_discounts(true);
207 207
         
208
-        wpinv_set_checkout_session( $data );
208
+        wpinv_set_checkout_session($data);
209 209
         
210
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
210
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
211 211
 
212 212
         $args = array(
213 213
             'id'            => $item_id,
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
             'fees'          => array()
221 221
         );
222 222
 
223
-        $invoice->add_item( $item_id, $args );
223
+        $invoice->add_item($item_id, $args);
224 224
         $invoice->save();
225 225
         
226
-        if ( empty( $_POST['country'] ) ) {
226
+        if (empty($_POST['country'])) {
227 227
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
228 228
         }
229
-        if ( empty( $_POST['state'] ) ) {
229
+        if (empty($_POST['state'])) {
230 230
             $_POST['state'] = $invoice->state;
231 231
         }
232 232
          
233
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
234
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
233
+        $invoice->country   = sanitize_text_field($_POST['country']);
234
+        $invoice->state     = sanitize_text_field($_POST['state']);
235 235
         
236
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
237
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
236
+        $invoice->set('country', sanitize_text_field($_POST['country']));
237
+        $invoice->set('state', sanitize_text_field($_POST['state']));
238 238
         
239 239
         $wpinv_ip_address_country = $invoice->country;
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         
243 243
         $response                       = array();
244 244
         $response['success']            = true;
245
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
245
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
246 246
         $response['data']['subtotal']   = $invoice->get_subtotal();
247 247
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
248 248
         $response['data']['tax']        = $invoice->get_tax();
@@ -254,40 +254,40 @@  discard block
 block discarded – undo
254 254
         
255 255
         wpinv_set_checkout_session($checkout_session);
256 256
         
257
-        wp_send_json( $response );
257
+        wp_send_json($response);
258 258
     }
259 259
     
260 260
     public static function remove_invoice_item() {
261 261
         global $wpi_userID, $wpinv_ip_address_country;
262 262
         
263
-        check_ajax_referer( 'invoice-item', '_nonce' );
264
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
263
+        check_ajax_referer('invoice-item', '_nonce');
264
+        if (!wpinv_current_user_can_manage_invoicing()) {
265 265
             die(-1);
266 266
         }
267 267
         
268
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
269
-        $invoice_id = absint( $_POST['invoice_id'] );
270
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
268
+        $item_id    = sanitize_text_field($_POST['item_id']);
269
+        $invoice_id = absint($_POST['invoice_id']);
270
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
271 271
         
272
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
272
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
273 273
             die();
274 274
         }
275 275
 
276
-        $invoice    = wpinv_get_invoice( $invoice_id );
277
-        if ( empty( $invoice ) ) {
276
+        $invoice = wpinv_get_invoice($invoice_id);
277
+        if (empty($invoice)) {
278 278
             die();
279 279
         }
280 280
         
281
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
281
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
282 282
             die(); // Don't allow modify items for paid invoice.
283 283
         }
284 284
         
285
-        if ( !empty( $_POST['user_id'] ) ) {
286
-            $wpi_userID = absint( $_POST['user_id'] ); 
285
+        if (!empty($_POST['user_id'])) {
286
+            $wpi_userID = absint($_POST['user_id']); 
287 287
         }
288 288
 
289
-        $item       = new WPInv_Item( $item_id );
290
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
289
+        $item = new WPInv_Item($item_id);
290
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
291 291
             die();
292 292
         }
293 293
         
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
         
296 296
         $data                   = array();
297 297
         $data['invoice_id']     = $invoice_id;
298
-        $data['cart_discounts'] = $invoice->get_discounts( true );
298
+        $data['cart_discounts'] = $invoice->get_discounts(true);
299 299
         
300
-        wpinv_set_checkout_session( $data );
300
+        wpinv_set_checkout_session($data);
301 301
 
302 302
         $args = array(
303 303
             'id'         => $item_id,
@@ -305,21 +305,21 @@  discard block
 block discarded – undo
305 305
             'cart_index' => $cart_index
306 306
         );
307 307
 
308
-        $invoice->remove_item( $item_id, $args );
308
+        $invoice->remove_item($item_id, $args);
309 309
         $invoice->save();
310 310
         
311
-        if ( empty( $_POST['country'] ) ) {
311
+        if (empty($_POST['country'])) {
312 312
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
313 313
         }
314
-        if ( empty( $_POST['state'] ) ) {
314
+        if (empty($_POST['state'])) {
315 315
             $_POST['state'] = $invoice->state;
316 316
         }
317 317
          
318
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
319
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
318
+        $invoice->country   = sanitize_text_field($_POST['country']);
319
+        $invoice->state     = sanitize_text_field($_POST['state']);
320 320
         
321
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
322
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
321
+        $invoice->set('country', sanitize_text_field($_POST['country']));
322
+        $invoice->set('state', sanitize_text_field($_POST['state']));
323 323
         
324 324
         $wpinv_ip_address_country = $invoice->country;
325 325
         
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         
328 328
         $response                       = array();
329 329
         $response['success']            = true;
330
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
330
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
331 331
         $response['data']['subtotal']   = $invoice->get_subtotal();
332 332
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
333 333
         $response['data']['tax']        = $invoice->get_tax();
@@ -339,40 +339,40 @@  discard block
 block discarded – undo
339 339
         
340 340
         wpinv_set_checkout_session($checkout_session);
341 341
         
342
-        wp_send_json( $response );
342
+        wp_send_json($response);
343 343
     }
344 344
     
345 345
     public static function create_invoice_item() {
346
-        check_ajax_referer( 'invoice-item', '_nonce' );
347
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
346
+        check_ajax_referer('invoice-item', '_nonce');
347
+        if (!wpinv_current_user_can_manage_invoicing()) {
348 348
             die(-1);
349 349
         }
350 350
         
351
-        $invoice_id = absint( $_POST['invoice_id'] );
351
+        $invoice_id = absint($_POST['invoice_id']);
352 352
 
353 353
         // Find the item
354
-        if ( !is_numeric( $invoice_id ) ) {
354
+        if (!is_numeric($invoice_id)) {
355 355
             die();
356 356
         }        
357 357
         
358
-        $invoice     = wpinv_get_invoice( $invoice_id );
359
-        if ( empty( $invoice ) ) {
358
+        $invoice = wpinv_get_invoice($invoice_id);
359
+        if (empty($invoice)) {
360 360
             die();
361 361
         }
362 362
         
363 363
         // Validate item before adding to invoice because recurring item must be paid individually.
364
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
364
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
365 365
             $response               = array();
366 366
             $response['success']    = false;
367
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
368
-            wp_send_json( $response );
367
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
368
+            wp_send_json($response);
369 369
         }        
370 370
         
371 371
         $save_item = $_POST['_wpinv_quick'];
372 372
         
373 373
         $meta               = array();
374 374
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
375
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
375
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
376 376
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
377 377
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
378 378
         
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
         $data['meta']           = $meta;
383 383
         
384 384
         $item = new WPInv_Item();
385
-        $item->create( $data );
385
+        $item->create($data);
386 386
         
387
-        if ( !empty( $item ) ) {
387
+        if (!empty($item)) {
388 388
             $_POST['item_id']   = $item->ID;
389
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
389
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
390 390
             
391 391
             self::add_invoice_item();
392 392
         }
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     }
395 395
     
396 396
     public static function get_billing_details() {
397
-        check_ajax_referer( 'get-billing-details', '_nonce' );
397
+        check_ajax_referer('get-billing-details', '_nonce');
398 398
         
399
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
399
+        if (!wpinv_current_user_can_manage_invoicing()) {
400 400
             die(-1);
401 401
         }
402 402
 
403
-        $user_id            = (int)$_POST['user_id'];
403
+        $user_id            = (int) $_POST['user_id'];
404 404
         $billing_details    = wpinv_get_user_address($user_id);
405
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
405
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
406 406
         
407 407
         if (isset($billing_details['user_id'])) {
408 408
             unset($billing_details['user_id']);
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
         $response['success']                    = true;
417 417
         $response['data']['billing_details']    = $billing_details;
418 418
         
419
-        wp_send_json( $response );
419
+        wp_send_json($response);
420 420
     }
421 421
     
422 422
     public static function admin_recalculate_totals() {
423 423
         global $wpi_userID, $wpinv_ip_address_country;
424 424
         
425
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
426
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
425
+        check_ajax_referer('wpinv-nonce', '_nonce');
426
+        if (!wpinv_current_user_can_manage_invoicing()) {
427 427
             die(-1);
428 428
         }
429 429
         
430
-        $invoice_id = absint( $_POST['invoice_id'] );        
431
-        $invoice    = wpinv_get_invoice( $invoice_id );
432
-        if ( empty( $invoice ) ) {
430
+        $invoice_id = absint($_POST['invoice_id']);        
431
+        $invoice    = wpinv_get_invoice($invoice_id);
432
+        if (empty($invoice)) {
433 433
             die();
434 434
         }
435 435
         
@@ -437,23 +437,23 @@  discard block
 block discarded – undo
437 437
         
438 438
         $data                   = array();
439 439
         $data['invoice_id']     = $invoice_id;
440
-        $data['cart_discounts'] = $invoice->get_discounts( true );
440
+        $data['cart_discounts'] = $invoice->get_discounts(true);
441 441
         
442
-        wpinv_set_checkout_session( $data );
442
+        wpinv_set_checkout_session($data);
443 443
         
444
-        if ( !empty( $_POST['user_id'] ) ) {
445
-            $wpi_userID = absint( $_POST['user_id'] ); 
444
+        if (!empty($_POST['user_id'])) {
445
+            $wpi_userID = absint($_POST['user_id']); 
446 446
         }
447 447
         
448
-        if ( empty( $_POST['country'] ) ) {
448
+        if (empty($_POST['country'])) {
449 449
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
450 450
         }
451 451
             
452
-        $invoice->country = sanitize_text_field( $_POST['country'] );
453
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
454
-        if ( isset( $_POST['state'] ) ) {
455
-            $invoice->state = sanitize_text_field( $_POST['state'] );
456
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
452
+        $invoice->country = sanitize_text_field($_POST['country']);
453
+        $invoice->set('country', sanitize_text_field($_POST['country']));
454
+        if (isset($_POST['state'])) {
455
+            $invoice->state = sanitize_text_field($_POST['state']);
456
+            $invoice->set('state', sanitize_text_field($_POST['state']));
457 457
         }
458 458
         
459 459
         $wpinv_ip_address_country = $invoice->country;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         
463 463
         $response                       = array();
464 464
         $response['success']            = true;
465
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
465
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
466 466
         $response['data']['subtotal']   = $invoice->get_subtotal();
467 467
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
468 468
         $response['data']['tax']        = $invoice->get_tax();
@@ -474,25 +474,25 @@  discard block
 block discarded – undo
474 474
         
475 475
         wpinv_set_checkout_session($checkout_session);
476 476
         
477
-        wp_send_json( $response );
477
+        wp_send_json($response);
478 478
     }
479 479
     
480 480
     public static function admin_apply_discount() {
481 481
         global $wpi_userID;
482 482
         
483
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
484
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
483
+        check_ajax_referer('wpinv-nonce', '_nonce');
484
+        if (!wpinv_current_user_can_manage_invoicing()) {
485 485
             die(-1);
486 486
         }
487 487
         
488
-        $invoice_id = absint( $_POST['invoice_id'] );
489
-        $discount_code = sanitize_text_field( $_POST['code'] );
490
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
488
+        $invoice_id = absint($_POST['invoice_id']);
489
+        $discount_code = sanitize_text_field($_POST['code']);
490
+        if (empty($invoice_id) || empty($discount_code)) {
491 491
             die();
492 492
         }
493 493
         
494
-        $invoice = wpinv_get_invoice( $invoice_id );
495
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
494
+        $invoice = wpinv_get_invoice($invoice_id);
495
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
496 496
             die();
497 497
         }
498 498
         
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
         
501 501
         $data                   = array();
502 502
         $data['invoice_id']     = $invoice_id;
503
-        $data['cart_discounts'] = $invoice->get_discounts( true );
503
+        $data['cart_discounts'] = $invoice->get_discounts(true);
504 504
         
505
-        wpinv_set_checkout_session( $data );
505
+        wpinv_set_checkout_session($data);
506 506
         
507 507
         $response               = array();
508 508
         $response['success']    = false;
509
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
509
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
510 510
         $response['data']['code'] = $discount_code;
511 511
         
512
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
513
-            $discounts = wpinv_set_cart_discount( $discount_code );
512
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
513
+            $discounts = wpinv_set_cart_discount($discount_code);
514 514
             
515 515
             $response['success'] = true;
516
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
517
-        }  else {
516
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
517
+        } else {
518 518
             $errors = wpinv_get_errors();
519
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
519
+            if (!empty($errors['wpinv-discount-error'])) {
520 520
                 $response['msg'] = $errors['wpinv-discount-error'];
521 521
             }
522
-            wpinv_unset_error( 'wpinv-discount-error' );
522
+            wpinv_unset_error('wpinv-discount-error');
523 523
         }
524 524
         
525 525
         wpinv_set_checkout_session($checkout_session);
526 526
         
527
-        wp_send_json( $response );
527
+        wp_send_json($response);
528 528
     }
529 529
     
530 530
     public static function admin_remove_discount() {
531 531
         global $wpi_userID;
532 532
         
533
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
534
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
533
+        check_ajax_referer('wpinv-nonce', '_nonce');
534
+        if (!wpinv_current_user_can_manage_invoicing()) {
535 535
             die(-1);
536 536
         }
537 537
         
538
-        $invoice_id = absint( $_POST['invoice_id'] );
539
-        $discount_code = sanitize_text_field( $_POST['code'] );
540
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
538
+        $invoice_id = absint($_POST['invoice_id']);
539
+        $discount_code = sanitize_text_field($_POST['code']);
540
+        if (empty($invoice_id) || empty($discount_code)) {
541 541
             die();
542 542
         }
543 543
         
544
-        $invoice = wpinv_get_invoice( $invoice_id );
545
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
544
+        $invoice = wpinv_get_invoice($invoice_id);
545
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
546 546
             die();
547 547
         }
548 548
         
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
         
551 551
         $data                   = array();
552 552
         $data['invoice_id']     = $invoice_id;
553
-        $data['cart_discounts'] = $invoice->get_discounts( true );
553
+        $data['cart_discounts'] = $invoice->get_discounts(true);
554 554
         
555
-        wpinv_set_checkout_session( $data );
555
+        wpinv_set_checkout_session($data);
556 556
         
557 557
         $response               = array();
558 558
         $response['success']    = false;
559 559
         $response['msg']        = NULL;
560 560
         
561
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
561
+        $discounts = wpinv_unset_cart_discount($discount_code);
562 562
         $response['success'] = true;
563
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
563
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
564 564
         
565 565
         wpinv_set_checkout_session($checkout_session);
566 566
         
567
-        wp_send_json( $response );
567
+        wp_send_json($response);
568 568
     }
569 569
     
570 570
     public static function check_email() {
571
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
572
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
571
+        check_ajax_referer('wpinv-nonce', '_nonce');
572
+        if (!wpinv_current_user_can_manage_invoicing()) {
573 573
             die(-1);
574 574
         }
575 575
         
576
-        $email = sanitize_text_field( $_POST['email'] );
576
+        $email = sanitize_text_field($_POST['email']);
577 577
         
578 578
         $response = array();
579
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
579
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
580 580
             $user_id            = $user_data->ID;
581 581
             $user_login         = $user_data->user_login;
582 582
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
583 583
             $billing_details    = wpinv_get_user_address($user_id);
584
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
584
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
585 585
             
586 586
             if (isset($billing_details['user_id'])) {
587 587
                 unset($billing_details['user_id']);
@@ -597,54 +597,54 @@  discard block
 block discarded – undo
597 597
             $response['data']['billing_details']    = $billing_details;
598 598
         }
599 599
         
600
-        wp_send_json( $response );
600
+        wp_send_json($response);
601 601
     }
602 602
     
603 603
     public static function run_tool() {
604
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
605
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
604
+        check_ajax_referer('wpinv-nonce', '_nonce');
605
+        if (!wpinv_current_user_can_manage_invoicing()) {
606 606
             die(-1);
607 607
         }
608 608
         
609
-        $tool = sanitize_text_field( $_POST['tool'] );
609
+        $tool = sanitize_text_field($_POST['tool']);
610 610
         
611
-        do_action( 'wpinv_run_tool' );
611
+        do_action('wpinv_run_tool');
612 612
         
613
-        if ( !empty( $tool ) ) {
614
-            do_action( 'wpinv_tool_' . $tool );
613
+        if (!empty($tool)) {
614
+            do_action('wpinv_tool_' . $tool);
615 615
         }
616 616
     }
617 617
     
618 618
     public static function apply_discount() {
619 619
         global $wpi_userID;
620 620
         
621
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
621
+        check_ajax_referer('wpinv-nonce', '_nonce');
622 622
         
623 623
         $response = array();
624 624
         
625
-        if ( isset( $_POST['code'] ) ) {
626
-            $discount_code = sanitize_text_field( $_POST['code'] );
625
+        if (isset($_POST['code'])) {
626
+            $discount_code = sanitize_text_field($_POST['code']);
627 627
 
628 628
             $response['success']        = false;
629 629
             $response['msg']            = '';
630 630
             $response['data']['code']   = $discount_code;
631 631
             
632 632
             $invoice = wpinv_get_invoice_cart();
633
-            if ( empty( $invoice->ID ) ) {
634
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
635
-                wp_send_json( $response );
633
+            if (empty($invoice->ID)) {
634
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
635
+                wp_send_json($response);
636 636
             }
637 637
 
638 638
             $wpi_userID = $invoice->get_user_id();
639 639
 
640
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
641
-                $discount       = wpinv_get_discount_by_code( $discount_code );
642
-                $discounts      = wpinv_set_cart_discount( $discount_code );
643
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
644
-                $total          = wpinv_get_cart_total( null, $discounts );
645
-                $cart_totals    = wpinv_recalculate_tax( true );
640
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
641
+                $discount       = wpinv_get_discount_by_code($discount_code);
642
+                $discounts      = wpinv_set_cart_discount($discount_code);
643
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
644
+                $total          = wpinv_get_cart_total(null, $discounts);
645
+                $cart_totals    = wpinv_recalculate_tax(true);
646 646
             
647
-                if ( !empty( $cart_totals ) ) {
647
+                if (!empty($cart_totals)) {
648 648
                     $response['success']        = true;
649 649
                     $response['data']           = $cart_totals;
650 650
                     $response['data']['code']   = $discount_code;
@@ -653,29 +653,29 @@  discard block
 block discarded – undo
653 653
                 }
654 654
             } else {
655 655
                 $errors = wpinv_get_errors();
656
-                $response['msg']  = $errors['wpinv-discount-error'];
657
-                wpinv_unset_error( 'wpinv-discount-error' );
656
+                $response['msg'] = $errors['wpinv-discount-error'];
657
+                wpinv_unset_error('wpinv-discount-error');
658 658
             }
659 659
 
660 660
             // Allow for custom discount code handling
661
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
661
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
662 662
         }
663 663
         
664
-        wp_send_json( $response );
664
+        wp_send_json($response);
665 665
     }
666 666
     
667 667
     public static function remove_discount() {
668
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
668
+        check_ajax_referer('wpinv-nonce', '_nonce');
669 669
         
670 670
         $response = array();
671 671
         
672
-        if ( isset( $_POST['code'] ) ) {
673
-            $discount_code  = sanitize_text_field( $_POST['code'] );
674
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
675
-            $total          = wpinv_get_cart_total( null, $discounts );
676
-            $cart_totals    = wpinv_recalculate_tax( true );
672
+        if (isset($_POST['code'])) {
673
+            $discount_code  = sanitize_text_field($_POST['code']);
674
+            $discounts      = wpinv_unset_cart_discount($discount_code);
675
+            $total          = wpinv_get_cart_total(null, $discounts);
676
+            $cart_totals    = wpinv_recalculate_tax(true);
677 677
             
678
-            if ( !empty( $cart_totals ) ) {
678
+            if (!empty($cart_totals)) {
679 679
                 $response['success']        = true;
680 680
                 $response['data']           = $cart_totals;
681 681
                 $response['data']['code']   = $discount_code;
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
             }
685 685
             
686 686
             // Allow for custom discount code handling
687
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
687
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
688 688
         }
689 689
         
690
-        wp_send_json( $response );
690
+        wp_send_json($response);
691 691
     }
692 692
 
693 693
 
@@ -699,53 +699,53 @@  discard block
 block discarded – undo
699 699
     public static function buy_items() {
700 700
         $user_id = get_current_user_id();
701 701
 
702
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
703
-            wp_send_json( array(
704
-                'success' => wp_login_url( wp_get_referer() )
705
-            ) );
702
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
703
+            wp_send_json(array(
704
+                'success' => wp_login_url(wp_get_referer())
705
+            ));
706 706
         } else {
707 707
             // Only check nonce if logged in as it could be cached when logged out.
708
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
709
-                wp_send_json( array(
710
-                    'error' => __( 'Security checks failed.', 'invoicing' )
711
-                ) );
708
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
709
+                wp_send_json(array(
710
+                    'error' => __('Security checks failed.', 'invoicing')
711
+                ));
712 712
                 wp_die();
713 713
             }
714 714
 
715 715
             // allow to set a custom price through post_id
716 716
             $items = $_POST['items'];
717
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
718
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
717
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
718
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
719 719
 
720 720
             $cart_items = array();
721
-            if ( $items ) {
722
-                $items = explode( ',', $items );
721
+            if ($items) {
722
+                $items = explode(',', $items);
723 723
 
724
-                foreach( $items as $item ) {
724
+                foreach ($items as $item) {
725 725
                     $item_id = $item;
726 726
                     $quantity = 1;
727 727
 
728
-                    if ( strpos( $item, '|' ) !== false ) {
729
-                        $item_parts = explode( '|', $item );
728
+                    if (strpos($item, '|') !== false) {
729
+                        $item_parts = explode('|', $item);
730 730
                         $item_id = $item_parts[0];
731 731
                         $quantity = $item_parts[1];
732 732
                     }
733 733
 
734
-                    if ( $item_id && $quantity ) {
734
+                    if ($item_id && $quantity) {
735 735
                         $cart_items_arr = array(
736
-                            'id'            => (int)$item_id,
737
-                            'quantity'      => (int)$quantity
736
+                            'id'            => (int) $item_id,
737
+                            'quantity'      => (int) $quantity
738 738
                         );
739 739
 
740 740
                         // If there is a related post id then add it to meta
741
-                        if ( $related_post_id ) {
741
+                        if ($related_post_id) {
742 742
                             $cart_items_arr['meta'] = array(
743 743
                                 'post_id'   => $related_post_id
744 744
                             );
745 745
                         }
746 746
 
747 747
                         // If there is a custom price then set it.
748
-                        if ( $custom_item_price ) {
748
+                        if ($custom_item_price) {
749 749
                             $cart_items_arr['custom_price'] = $custom_item_price;
750 750
                         }
751 751
 
@@ -761,37 +761,37 @@  discard block
 block discarded – undo
761 761
              * @param int $related_post_id The related post id if any.
762 762
              * @since 1.0.0
763 763
              */
764
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
764
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
765 765
 
766 766
             // Make sure its not in the cart already, if it is then redirect to checkout.
767 767
             $cart_invoice = wpinv_get_invoice_cart();
768 768
 
769
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
770
-                wp_send_json( array(
769
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
770
+                wp_send_json(array(
771 771
                     'success' =>  $cart_invoice->get_checkout_payment_url()
772
-                ) );
772
+                ));
773 773
                 wp_die();
774 774
             }
775 775
 
776 776
             // Check if user has invoice with same items waiting to be paid.
777
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
778
-            if ( !empty( $user_invoices ) ) {
779
-                foreach( $user_invoices as $user_invoice ) {
777
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
778
+            if (!empty($user_invoices)) {
779
+                foreach ($user_invoices as $user_invoice) {
780 780
                     $user_cart_details = array();
781
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
781
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
782 782
                     $cart_details = $invoice->get_cart_details();
783 783
 
784
-                    if ( !empty( $cart_details ) ) {
785
-                        foreach ( $cart_details as $invoice_item ) {
784
+                    if (!empty($cart_details)) {
785
+                        foreach ($cart_details as $invoice_item) {
786 786
                             $ii_arr = array();
787
-                            $ii_arr['id'] = (int)$invoice_item['id'];
788
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
787
+                            $ii_arr['id'] = (int) $invoice_item['id'];
788
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
789 789
 
790
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
790
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
791 791
                                 $ii_arr['meta'] = $invoice_item['meta'];
792 792
                             }
793 793
 
794
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
794
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
795 795
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
796 796
                             }
797 797
 
@@ -799,17 +799,17 @@  discard block
 block discarded – undo
799 799
                         }
800 800
                     }
801 801
 
802
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
803
-                        wp_send_json( array(
802
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
803
+                        wp_send_json(array(
804 804
                             'success' =>  $invoice->get_checkout_payment_url()
805
-                        ) );
805
+                        ));
806 806
                         wp_die();
807 807
                     }
808 808
                 }
809 809
             }
810 810
 
811 811
             // Create invoice and send user to checkout
812
-            if ( !empty( $cart_items ) ) {
812
+            if (!empty($cart_items)) {
813 813
                 $invoice_data = array(
814 814
                     'status'        =>  'wpi-pending',
815 815
                     'created_via'   =>  'wpi',
@@ -817,21 +817,21 @@  discard block
 block discarded – undo
817 817
                     'cart_details'  =>  $cart_items,
818 818
                 );
819 819
 
820
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
820
+                $invoice = wpinv_insert_invoice($invoice_data, true);
821 821
 
822
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
823
-                    wp_send_json( array(
822
+                if (!empty($invoice) && isset($invoice->ID)) {
823
+                    wp_send_json(array(
824 824
                         'success' =>  $invoice->get_checkout_payment_url()
825
-                    ) );
825
+                    ));
826 826
                 } else {
827
-                    wp_send_json( array(
828
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
829
-                    ) );
827
+                    wp_send_json(array(
828
+                        'error' => __('Invoice failed to create', 'invoicing')
829
+                    ));
830 830
                 }
831 831
             } else {
832
-                wp_send_json( array(
833
-                    'error' => __( 'Items not valid.', 'invoicing' )
834
-                ) );
832
+                wp_send_json(array(
833
+                    'error' => __('Items not valid.', 'invoicing')
834
+                ));
835 835
             }
836 836
         }
837 837
 
Please login to merge, or discard this patch.