Completed
Push — master ( 3495f4...0c435d )
by Stiofan
18s
created
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  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_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,256 +72,256 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    if ( $field == '_wpinv_price' ) {
86
-                        if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) {
87
-                            $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price.
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    if ($field == '_wpinv_price') {
86
+                        if (get_post_meta($post_id, '_wpinv_type', true) === 'package') {
87
+                            $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price.
88 88
                         } else {
89
-                            $value = wpinv_sanitize_amount( $_POST[ $name ] );
89
+                            $value = wpinv_sanitize_amount($_POST[$name]);
90 90
                         }
91 91
                     } else {
92
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
92
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
93 93
                     }
94 94
                     
95
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
96
-                    update_post_meta( $post_id, $field, $value );
95
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
96
+                    update_post_meta($post_id, $field, $value);
97 97
                 }
98 98
             }
99 99
             
100
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
101
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
100
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
101
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
102 102
             }
103 103
         }
104 104
     }
105 105
 }
106
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
106
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
107 107
 
108 108
 function wpinv_register_item_meta_boxes() {    
109 109
     global $wpinv_euvat;
110 110
     
111
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
111
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
112 112
 
113
-    if ( $wpinv_euvat->allow_vat_rules() ) {
114
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
113
+    if ($wpinv_euvat->allow_vat_rules()) {
114
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
115 115
     }
116 116
     
117
-    if ( $wpinv_euvat->allow_vat_classes() ) {
118
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
117
+    if ($wpinv_euvat->allow_vat_classes()) {
118
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
119 119
     }
120 120
     
121
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
122
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
121
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
122
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
123 123
 }
124 124
 
125 125
 function wpinv_register_discount_meta_boxes() {
126
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
126
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
127 127
 }
128 128
 
129
-function wpinv_discount_metabox_details( $post ) {
129
+function wpinv_discount_metabox_details($post) {
130 130
     $discount_id    = $post->ID;
131
-    $discount       = wpinv_get_discount( $discount_id );
131
+    $discount       = wpinv_get_discount($discount_id);
132 132
     
133
-    $type           = wpinv_get_discount_type( $discount_id );
134
-    $item_reqs      = wpinv_get_discount_item_reqs( $discount_id );
135
-    $excluded_items = wpinv_get_discount_excluded_items( $discount_id );
136
-    $min_total      = wpinv_get_discount_min_total( $discount_id );
137
-    $max_total      = wpinv_get_discount_max_total( $discount_id );
138
-    $max_uses       = wpinv_get_discount_max_uses( $discount_id );
139
-    $single_use     = wpinv_discount_is_single_use( $discount_id );
140
-    $recurring      = (bool)wpinv_discount_is_recurring( $discount_id );
133
+    $type           = wpinv_get_discount_type($discount_id);
134
+    $item_reqs      = wpinv_get_discount_item_reqs($discount_id);
135
+    $excluded_items = wpinv_get_discount_excluded_items($discount_id);
136
+    $min_total      = wpinv_get_discount_min_total($discount_id);
137
+    $max_total      = wpinv_get_discount_max_total($discount_id);
138
+    $max_uses       = wpinv_get_discount_max_uses($discount_id);
139
+    $single_use     = wpinv_discount_is_single_use($discount_id);
140
+    $recurring      = (bool)wpinv_discount_is_recurring($discount_id);
141 141
     
142 142
     $min_total      = $min_total > 0 ? $min_total : '';
143 143
     $max_total      = $max_total > 0 ? $max_total : '';
144 144
     $max_uses       = $max_uses > 0 ? $max_uses : '';
145 145
 ?>
146
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
147
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
146
+<?php do_action('wpinv_discount_form_top', $post); ?>
147
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
148 148
 <table class="form-table wpi-form-table">
149 149
     <tbody>
150
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
151
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
150
+        <?php do_action('wpinv_discount_form_first', $post); ?>
151
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
152 152
         <tr>
153 153
             <th valign="top" scope="row">
154
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
154
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
155 155
             </th>
156 156
             <td>
157
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
158
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
157
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
158
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
159 159
             </td>
160 160
         </tr>
161
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
161
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
162 162
         <tr>
163 163
             <th valign="top" scope="row">
164
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
164
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
165 165
             </th>
166 166
             <td>
167 167
                 <select id="wpinv_discount_type" name="type" class="medium-text">
168
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
169
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
168
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
169
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
170 170
                     <?php } ?>
171 171
                 </select>
172
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
172
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
173 173
             </td>
174 174
         </tr>
175
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
175
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
176 176
         <tr>
177 177
             <th valign="top" scope="row">
178
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
178
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
179 179
             </th>
180 180
             <td>
181
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
182
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
183
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
181
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
182
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
183
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
184 184
             </td>
185 185
         </tr>
186
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
186
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
187 187
         <tr>
188 188
             <th valign="top" scope="row">
189
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
189
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
190 190
             </th>
191 191
             <td>
192
-                <p><?php echo wpinv_item_dropdown( array(
192
+                <p><?php echo wpinv_item_dropdown(array(
193 193
                         'name'              => 'items[]',
194 194
                         'id'                => 'items',
195 195
                         'selected'          => $item_reqs,
196 196
                         'multiple'          => true,
197 197
                         'chosen'            => true,
198 198
                         'class'             => 'medium-text',
199
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
199
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
200 200
                         'show_recurring'    => true,
201
-                    ) ); ?>
201
+                    )); ?>
202 202
                 </p>
203
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
203
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
204 204
             </td>
205 205
         </tr>
206
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
206
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
207 207
         <tr>
208 208
             <th valign="top" scope="row">
209
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
209
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
210 210
             </th>
211 211
             <td>
212
-                <p><?php echo wpinv_item_dropdown( array(
212
+                <p><?php echo wpinv_item_dropdown(array(
213 213
                         'name'              => 'excluded_items[]',
214 214
                         'id'                => 'excluded_items',
215 215
                         'selected'          => $excluded_items,
216 216
                         'multiple'          => true,
217 217
                         'chosen'            => true,
218 218
                         'class'             => 'medium-text',
219
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
219
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
220 220
                         'show_recurring'    => true,
221
-                    ) ); ?>
221
+                    )); ?>
222 222
                 </p>
223
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
223
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
224 224
             </td>
225 225
         </tr>
226
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
226
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
227 227
         <tr>
228 228
             <th valign="top" scope="row">
229
-                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
229
+                <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label>
230 230
             </th>
231 231
             <td>
232
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>">
233
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
232
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>">
233
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
234 234
             </td>
235 235
         </tr>
236
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
236
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
237 237
         <tr>
238 238
             <th valign="top" scope="row">
239
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
239
+                <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label>
240 240
             </th>
241 241
             <td>
242
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>">
243
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
242
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>">
243
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
244 244
             </td>
245 245
         </tr>
246
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
246
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
247 247
         <tr>
248 248
             <th valign="top" scope="row">
249
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
249
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
250 250
             </th>
251 251
             <td>
252 252
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
253
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
253
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
254 254
             </td>
255 255
         </tr>
256
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
256
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
257 257
         <tr>
258 258
             <th valign="top" scope="row">
259
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
259
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
260 260
             </th>
261 261
             <td>
262 262
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
263
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272 272
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
273
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
274
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
273
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
274
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
275 275
                 </select>
276
-                <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
276
+                <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
277 277
             </td>
278 278
         </tr>
279
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
279
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
280 280
         <tr>
281 281
             <th valign="top" scope="row">
282
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
282
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
283 283
             </th>
284 284
             <td>
285 285
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
286
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
286
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
287 287
             </td>
288 288
         </tr>
289
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
289
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
290 290
         <tr>
291 291
             <th valign="top" scope="row">
292
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
292
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
293 293
             </th>
294 294
             <td>
295
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
296
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
295
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
296
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
297 297
             </td>
298 298
         </tr>
299
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
299
+        <?php do_action('wpinv_discount_form_last', $post); ?>
300 300
     </tbody>
301 301
 </table>
302
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
302
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
303 303
     <?php
304 304
 }
305 305
 
306
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
307
-    $post_type = !empty( $post ) ? $post->post_type : '';
306
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
307
+    $post_type = !empty($post) ? $post->post_type : '';
308 308
     
309
-    if ( $post_type != 'wpi_discount' ) {
309
+    if ($post_type != 'wpi_discount') {
310 310
         return;
311 311
     }
312 312
     
313
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
313
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
314 314
         return;
315 315
     }
316 316
     
317
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
317
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
318 318
         return;
319 319
     }
320 320
     
321
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
321
+    if (!current_user_can('manage_options', $post_id)) {
322 322
         return;
323 323
     }
324 324
     
325
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
325
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
326 326
 }
327
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
328 327
\ No newline at end of file
328
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
329 329
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +709 added lines, -709 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  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 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,132 +17,132 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
90
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
91 91
         
92
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
93
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
92
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
93
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
94 94
         
95
-        $vat_name   = self::get_vat_name();
95
+        $vat_name = self::get_vat_name();
96 96
         
97 97
         $vars = array();
98 98
         $vars['UseTaxes'] = wpinv_use_taxes();
99 99
         $vars['EUStates'] = self::get_eu_states();
100
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
101
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
102
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
103
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
104
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
105
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
106
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
107
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
100
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
101
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
102
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
103
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
104
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
105
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
106
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
107
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
108 108
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
109 109
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
110
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
111
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
112
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
113
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
114
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
115
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
116
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
117
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
118
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
119
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
120
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
121
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
122
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
110
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
111
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
112
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
113
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
114
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
115
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
116
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
117
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
118
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
119
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
120
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
121
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
122
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
123 123
         $vars['isFront'] = is_admin() ? false : true;
124
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
124
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
125 125
         $vars['baseCountry'] = wpinv_get_default_country();
126
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
127
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
126
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
127
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
128 128
         
129
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
130
-        wp_enqueue_script( 'wpinv-vat-script' );
131
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
129
+        wp_enqueue_script('wpinv-vat-validation-script');
130
+        wp_enqueue_script('wpinv-vat-script');
131
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
132 132
     }
133 133
 
134 134
     public static function enqueue_admin_scripts() {
135
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
135
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
136 136
             self::enqueue_vat_scripts();
137 137
         }
138 138
     }
139 139
     
140
-    public static function section_vat_settings( $sections ) {
141
-        if ( !empty( $sections ) ) {
142
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
140
+    public static function section_vat_settings($sections) {
141
+        if (!empty($sections)) {
142
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
143 143
             
144
-            if ( self::allow_vat_classes() ) {
145
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
144
+            if (self::allow_vat_classes()) {
145
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
146 146
             }
147 147
         }
148 148
         return $sections;
@@ -151,52 +151,52 @@  discard block
 block discarded – undo
151 151
     public static function vat_rates_settings() {
152 152
         $vat_classes = self::get_rate_classes();
153 153
         $vat_rates = array();
154
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
155
-        $current_url = remove_query_arg( 'wpi_sub' );
154
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
155
+        $current_url = remove_query_arg('wpi_sub');
156 156
         
157 157
         $vat_rates['vat_rates_header'] = array(
158 158
             'id' => 'vat_rates_header',
159
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
159
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
160 160
             'desc' => '',
161 161
             'type' => 'header',
162 162
             'size' => 'regular'
163 163
         );
164 164
         $vat_rates['vat_rates_class'] = array(
165 165
             'id'          => 'vat_rates_class',
166
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
167
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
166
+            'name'        => __('Edit VAT Rates', 'invoicing'),
167
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
168 168
             'type'        => 'select',
169
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
169
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
170 170
             'chosen'      => true,
171
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
171
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
172 172
             'selected'    => $vat_class,
173 173
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
174 174
         );
175 175
         
176
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
176
+        if ($vat_class != '_standard' && $vat_class != '_new') {
177 177
             $vat_rates['vat_rate_delete'] = array(
178 178
                 'id'   => 'vat_rate_delete',
179 179
                 'type' => 'vat_rate_delete',
180 180
             );
181 181
         }
182 182
                     
183
-        if ( $vat_class == '_new' ) {
183
+        if ($vat_class == '_new') {
184 184
             $vat_rates['vat_rates_settings'] = array(
185 185
                 'id' => 'vat_rates_settings',
186
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
186
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
187 187
                 'type' => 'header',
188 188
             );
189 189
             $vat_rates['vat_rate_name'] = array(
190 190
                 'id'   => 'vat_rate_name',
191
-                'name' => __( 'Name', 'invoicing' ),
192
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
191
+                'name' => __('Name', 'invoicing'),
192
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
193 193
                 'type' => 'text',
194 194
                 'size' => 'regular',
195 195
             );
196 196
             $vat_rates['vat_rate_desc'] = array(
197 197
                 'id'   => 'vat_rate_desc',
198
-                'name' => __( 'Description', 'invoicing' ),
199
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
198
+                'name' => __('Description', 'invoicing'),
199
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
200 200
                 'type' => 'text',
201 201
                 'size' => 'regular',
202 202
             );
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             $vat_rates['vat_rates'] = array(
209 209
                 'id'   => 'vat_rates',
210 210
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
211
-                'desc' => self::get_class_desc( $vat_class ),
211
+                'desc' => self::get_class_desc($vat_class),
212 212
                 'type' => 'vat_rates',
213 213
             );
214 214
         }
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
         return $vat_rates;
217 217
     }
218 218
     
219
-    public static function vat_settings( $settings ) {
220
-        if ( !empty( $settings ) ) {    
219
+    public static function vat_settings($settings) {
220
+        if (!empty($settings)) {    
221 221
             $vat_settings = array();
222 222
             $vat_settings['vat_company_title'] = array(
223 223
                 'id' => 'vat_company_title',
224
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
224
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
225 225
                 'desc' => '',
226 226
                 'type' => 'header',
227 227
                 'size' => 'regular'
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
             
230 230
             $vat_settings['vat_company_name'] = array(
231 231
                 'id' => 'vat_company_name',
232
-                'name' => __( 'Your Company Name', 'invoicing' ),
233
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
232
+                'name' => __('Your Company Name', 'invoicing'),
233
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
234 234
                 'type' => 'text',
235 235
                 'size' => 'regular',
236 236
             );
237 237
             
238 238
             $vat_settings['vat_number'] = array(
239 239
                 'id'   => 'vat_number',
240
-                'name' => __( 'Your VAT Number', 'invoicing' ),
240
+                'name' => __('Your VAT Number', 'invoicing'),
241 241
                 'type' => 'vat_number',
242 242
                 'size' => 'regular',
243 243
             );
244 244
 
245 245
             $vat_settings['vat_settings_title'] = array(
246 246
                 'id' => 'vat_settings_title',
247
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
247
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
248 248
                 'desc' => '',
249 249
                 'type' => 'header',
250 250
                 'size' => 'regular'
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 
253 253
             $vat_settings['apply_vat_rules'] = array(
254 254
                 'id' => 'apply_vat_rules',
255
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
256
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
255
+                'name' => __('Enable VAT Rules', 'invoicing'),
256
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
257 257
                 'type' => 'checkbox',
258 258
                 'std' => '1'
259 259
             );
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 
270 270
             $vat_settings['vat_prevent_b2c_purchase'] = array(
271 271
                 'id' => 'vat_prevent_b2c_purchase',
272
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
273
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
272
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
273
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
274 274
                 'type' => 'checkbox'
275 275
             );
276 276
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 
279 279
             $vat_settings['vat_same_country_rule'] = array(
280 280
                 'id'          => 'vat_same_country_rule',
281
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
282
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
281
+                'name'        => __('Same Country Rule', 'invoicing'),
282
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
283 283
                 'type'        => 'select',
284 284
                 'options'     => array(
285
-                    ''          => __( 'Normal', 'invoicing' ),
286
-                    'no'        => __( 'No VAT', 'invoicing' ),
287
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
285
+                    ''          => __('Normal', 'invoicing'),
286
+                    'no'        => __('No VAT', 'invoicing'),
287
+                    'always'    => __('Always apply VAT', 'invoicing'),
288 288
                 ),
289
-                'placeholder' => __( 'Select an option', 'invoicing' ),
289
+                'placeholder' => __('Select an option', 'invoicing'),
290 290
                 'std'         => ''
291 291
             );
292 292
 
293 293
             $vat_settings['vat_checkout_title'] = array(
294 294
                 'id' => 'vat_checkout_title',
295
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
295
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
296 296
                 'desc' => '',
297 297
                 'type' => 'header',
298 298
                 'size' => 'regular'
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
 
301 301
             $vat_settings['vat_disable_fields'] = array(
302 302
                 'id' => 'vat_disable_fields',
303
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
304
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
303
+                'name' => __('Disable VAT Fields', 'invoicing'),
304
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
305 305
                 'type' => 'checkbox'
306 306
             );
307 307
 
308 308
             $vat_settings['vat_ip_lookup'] = array(
309 309
                 'id'   => 'vat_ip_lookup',
310
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
310
+                'name' => __('IP Country Look-up', 'invoicing'),
311 311
                 'type' => 'vat_ip_lookup',
312 312
                 'size' => 'regular',
313 313
                 'std' => 'default'
@@ -315,21 +315,21 @@  discard block
 block discarded – undo
315 315
 
316 316
             $vat_settings['hide_ip_address'] = array(
317 317
                 'id' => 'hide_ip_address',
318
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
319
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
318
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
319
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
320 320
                 'type' => 'checkbox'
321 321
             );
322 322
 
323 323
             $vat_settings['vat_ip_country_default'] = array(
324 324
                 'id' => 'vat_ip_country_default',
325
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
326
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
325
+                'name' => __('Enable IP Country as Default', 'invoicing'),
326
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vies_validation_title'] = array(
331 331
                 'id' => 'vies_validation_title',
332
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
332
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
333 333
                 'desc' => '',
334 334
                 'type' => 'header',
335 335
                 'size' => 'regular'
@@ -337,37 +337,37 @@  discard block
 block discarded – undo
337 337
 
338 338
             $vat_settings['vat_vies_check'] = array(
339 339
                 'id' => 'vat_vies_check',
340
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
341
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
340
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
341
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
342 342
                 'type' => 'checkbox'
343 343
             );
344 344
 
345 345
             $vat_settings['vat_disable_company_name_check'] = array(
346 346
                 'id' => 'vat_disable_company_name_check',
347
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
348
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
347
+                'name' => __('Disable VIES Name Check', 'invoicing'),
348
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_offline_check'] = array(
353 353
                 'id' => 'vat_offline_check',
354
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
355
-                'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ),
354
+                'name' => __('Disable Basic Checks', 'invoicing'),
355
+                'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
             
359 359
 
360 360
             $settings['vat'] = $vat_settings;
361 361
             
362
-            if ( self::allow_vat_classes() ) {
362
+            if (self::allow_vat_classes()) {
363 363
                 $settings['vat_rates'] = self::vat_rates_settings();
364 364
             }
365 365
             
366 366
             $eu_fallback_rate = array(
367 367
                 'id'   => 'eu_fallback_rate',
368
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
368
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
369 369
                 'type' => 'eu_fallback_rate',
370
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
370
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
371 371
                 'std'  => '20',
372 372
                 'size' => 'small'
373 373
             );
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
384 384
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
385 385
         
386
-        if ( !is_dir( $destination_dir ) ) { 
387
-            mkdir( $destination_dir );
386
+        if (!is_dir($destination_dir)) { 
387
+            mkdir($destination_dir);
388 388
         }
389 389
         
390
-        $database_files     = array(
390
+        $database_files = array(
391 391
             'country'   => array(
392 392
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
393 393
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -398,57 +398,57 @@  discard block
 block discarded – undo
398 398
             )
399 399
         );
400 400
 
401
-        foreach( $database_files as $database => $files ) {
402
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
401
+        foreach ($database_files as $database => $files) {
402
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
403 403
             
404
-            if ( empty( $result['success'] ) ) {
404
+            if (empty($result['success'])) {
405 405
                 echo $result['message'];
406 406
                 exit;
407 407
             }
408 408
             
409
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
410
-            echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
409
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
410
+            echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' ';
411 411
         }
412 412
         
413 413
         exit;
414 414
     }
415 415
     
416
-    public static function geoip2_download_file( $source_url, $destination_file ) {
416
+    public static function geoip2_download_file($source_url, $destination_file) {
417 417
         $success    = false;
418 418
         $message    = '';
419 419
         
420
-        if ( !function_exists( 'download_url' ) ) {
421
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
420
+        if (!function_exists('download_url')) {
421
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
422 422
         }
423 423
 
424
-        $temp_file  = download_url( $source_url );
424
+        $temp_file = download_url($source_url);
425 425
         
426
-        if ( is_wp_error( $temp_file ) ) {
427
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
426
+        if (is_wp_error($temp_file)) {
427
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
428 428
         } else {
429
-            $handle = gzopen( $temp_file, 'rb' );
429
+            $handle = gzopen($temp_file, 'rb');
430 430
             
431
-            if ( $handle ) {
432
-                $fopen  = fopen( $destination_file, 'wb' );
433
-                if ( $fopen ) {
434
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
435
-                        fwrite( $fopen, $data );
431
+            if ($handle) {
432
+                $fopen = fopen($destination_file, 'wb');
433
+                if ($fopen) {
434
+                    while (($data = gzread($handle, 4096)) != false) {
435
+                        fwrite($fopen, $data);
436 436
                     }
437 437
 
438
-                    gzclose( $handle );
439
-                    fclose( $fopen );
438
+                    gzclose($handle);
439
+                    fclose($fopen);
440 440
                         
441 441
                     $success = true;
442 442
                 } else {
443
-                    gzclose( $handle );
444
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
443
+                    gzclose($handle);
444
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
445 445
                 }
446 446
             } else {
447
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
447
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
448 448
             }
449 449
             
450
-            if ( file_exists( $temp_file ) ) {
451
-                unlink( $temp_file );
450
+            if (file_exists($temp_file)) {
451
+                unlink($temp_file);
452 452
             }
453 453
         }
454 454
         
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
     }
461 461
     
462 462
     public static function load_geoip2() {
463
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
463
+        if (defined('WPINV_GEOIP2_LODDED')) {
464 464
             return;
465 465
         }
466 466
         
467
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
467
+        if (!class_exists('\MaxMind\Db\Reader')) {
468 468
             $maxmind_db_files = array(
469 469
                 'Reader/Decoder.php',
470 470
                 'Reader/InvalidDatabaseException.php',
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
                 'Reader.php',
474 474
             );
475 475
             
476
-            foreach ( $maxmind_db_files as $key => $file ) {
477
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
476
+            foreach ($maxmind_db_files as $key => $file) {
477
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
478 478
             }
479 479
         }
480 480
         
481
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
481
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
482 482
             $geoip2_files = array(
483 483
                 'ProviderInterface.php',
484 484
                 'Compat/JsonSerializable.php',
@@ -512,23 +512,23 @@  discard block
 block discarded – undo
512 512
                 'WebService/Client.php',
513 513
             );
514 514
             
515
-            foreach ( $geoip2_files as $key => $file ) {
516
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
515
+            foreach ($geoip2_files as $key => $file) {
516
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
517 517
             }
518 518
         }
519 519
 
520
-        define( 'WPINV_GEOIP2_LODDED', true );
520
+        define('WPINV_GEOIP2_LODDED', true);
521 521
     }
522 522
 
523 523
     public static function geoip2_country_dbfile() {
524 524
         $upload_dir = wp_upload_dir();
525 525
 
526
-        if ( !isset( $upload_dir['basedir'] ) ) {
526
+        if (!isset($upload_dir['basedir'])) {
527 527
             return false;
528 528
         }
529 529
 
530 530
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
531
-        if ( !file_exists( $filename ) ) {
531
+        if (!file_exists($filename)) {
532 532
             return false;
533 533
         }
534 534
         
@@ -538,12 +538,12 @@  discard block
 block discarded – undo
538 538
     public static function geoip2_city_dbfile() {
539 539
         $upload_dir = wp_upload_dir();
540 540
 
541
-        if ( !isset( $upload_dir['basedir'] ) ) {
541
+        if (!isset($upload_dir['basedir'])) {
542 542
             return false;
543 543
         }
544 544
 
545 545
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
546
-        if ( !file_exists( $filename ) ) {
546
+        if (!file_exists($filename)) {
547 547
             return false;
548 548
         }
549 549
         
@@ -554,10 +554,10 @@  discard block
 block discarded – undo
554 554
         try {
555 555
             self::load_geoip2();
556 556
 
557
-            if ( $filename = self::geoip2_country_dbfile() ) {
558
-                return new \GeoIp2\Database\Reader( $filename );
557
+            if ($filename = self::geoip2_country_dbfile()) {
558
+                return new \GeoIp2\Database\Reader($filename);
559 559
             }
560
-        } catch( Exception $e ) {
560
+        } catch (Exception $e) {
561 561
             return false;
562 562
         }
563 563
         
@@ -568,173 +568,173 @@  discard block
 block discarded – undo
568 568
         try {
569 569
             self::load_geoip2();
570 570
 
571
-            if ( $filename = self::geoip2_city_dbfile() ) {
572
-                return new \GeoIp2\Database\Reader( $filename );
571
+            if ($filename = self::geoip2_city_dbfile()) {
572
+                return new \GeoIp2\Database\Reader($filename);
573 573
             }
574
-        } catch( Exception $e ) {
574
+        } catch (Exception $e) {
575 575
             return false;
576 576
         }
577 577
         
578 578
         return false;
579 579
     }
580 580
 
581
-    public static function geoip2_country_record( $ip_address ) {
581
+    public static function geoip2_country_record($ip_address) {
582 582
         try {
583 583
             $reader = self::geoip2_country_reader();
584 584
 
585
-            if ( $reader ) {
586
-                $record = $reader->country( $ip_address );
585
+            if ($reader) {
586
+                $record = $reader->country($ip_address);
587 587
                 
588
-                if ( !empty( $record->country->isoCode ) ) {
588
+                if (!empty($record->country->isoCode)) {
589 589
                     return $record;
590 590
                 }
591 591
             }
592
-        } catch(\InvalidArgumentException $e) {
593
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
592
+        } catch (\InvalidArgumentException $e) {
593
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
594 594
             
595 595
             return false;
596
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
597
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
596
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
597
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
598 598
             
599 599
             return false;
600
-        } catch( Exception $e ) {
600
+        } catch (Exception $e) {
601 601
             return false;
602 602
         }
603 603
         
604 604
         return false;
605 605
     }
606 606
 
607
-    public static function geoip2_city_record( $ip_address ) {
607
+    public static function geoip2_city_record($ip_address) {
608 608
         try {
609 609
             $reader = self::geoip2_city_reader();
610 610
 
611
-            if ( $reader ) {
612
-                $record = $reader->city( $ip_address );
611
+            if ($reader) {
612
+                $record = $reader->city($ip_address);
613 613
                 
614
-                if ( !empty( $record->country->isoCode ) ) {
614
+                if (!empty($record->country->isoCode)) {
615 615
                     return $record;
616 616
                 }
617 617
             }
618
-        } catch(\InvalidArgumentException $e) {
619
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
618
+        } catch (\InvalidArgumentException $e) {
619
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
620 620
             
621 621
             return false;
622
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
623
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
622
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
623
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
624 624
             
625 625
             return false;
626
-        } catch( Exception $e ) {
626
+        } catch (Exception $e) {
627 627
             return false;
628 628
         }
629 629
         
630 630
         return false;
631 631
     }
632 632
 
633
-    public static function geoip2_country_code( $ip_address ) {
634
-        $record = self::geoip2_country_record( $ip_address );
635
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
633
+    public static function geoip2_country_code($ip_address) {
634
+        $record = self::geoip2_country_record($ip_address);
635
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
636 636
     }
637 637
 
638 638
     // Find country by IP address.
639
-    public static function get_country_by_ip( $ip = '' ) {
639
+    public static function get_country_by_ip($ip = '') {
640 640
         global $wpinv_ip_address_country;
641 641
         
642
-        if ( !empty( $wpinv_ip_address_country ) ) {
642
+        if (!empty($wpinv_ip_address_country)) {
643 643
             return $wpinv_ip_address_country;
644 644
         }
645 645
         
646
-        if ( empty( $ip ) ) {
646
+        if (empty($ip)) {
647 647
             $ip = wpinv_get_ip();
648 648
         }
649 649
 
650
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
651
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
650
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
651
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
652 652
 
653
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
654
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
653
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
654
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
655 655
                 try {
656
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
657
-                } catch( Exception $e ) {
658
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
656
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
657
+                } catch (Exception $e) {
658
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
659 659
                 }
660
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
661
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
662
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
663
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
660
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
661
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
662
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
663
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
664 664
                 
665
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
665
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
666 666
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
667 667
                 }
668 668
             }
669 669
         }
670 670
 
671
-        if ( empty( $wpinv_ip_address_country ) ) {
671
+        if (empty($wpinv_ip_address_country)) {
672 672
             $wpinv_ip_address_country = wpinv_get_default_country();
673 673
         }
674 674
 
675 675
         return $wpinv_ip_address_country;
676 676
     }
677 677
     
678
-    public static function sanitize_vat_settings( $input ) {
678
+    public static function sanitize_vat_settings($input) {
679 679
         global $wpinv_options;
680 680
         
681 681
         $valid      = false;
682 682
         $message    = '';
683 683
         
684
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
685
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
686
-                $valid = self::offline_check( $input['vat_number'] );
684
+        if (!empty($wpinv_options['vat_vies_check'])) {
685
+            if (empty($wpinv_options['vat_offline_check'])) {
686
+                $valid = self::offline_check($input['vat_number']);
687 687
             } else {
688 688
                 $valid = true;
689 689
             }
690 690
             
691
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
691
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
692 692
         } else {
693
-            $result = self::check_vat( $input['vat_number'] );
693
+            $result = self::check_vat($input['vat_number']);
694 694
             
695
-            if ( empty( $result['valid'] ) ) {
695
+            if (empty($result['valid'])) {
696 696
                 $valid      = false;
697 697
                 $message    = $result['message'];
698 698
             } else {
699
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
700
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
699
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
700
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
701 701
             }
702 702
         }
703 703
 
704
-        if ( $message && self::is_vat_validated() != $valid ) {
705
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
704
+        if ($message && self::is_vat_validated() != $valid) {
705
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
706 706
         }
707 707
 
708 708
         $input['vat_valid'] = $valid;
709 709
         return $input;
710 710
     }
711 711
     
712
-    public static function sanitize_vat_rates( $input ) {
713
-        if( !current_user_can( 'manage_options' ) ) {
714
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
712
+    public static function sanitize_vat_rates($input) {
713
+        if (!current_user_can('manage_options')) {
714
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
715 715
             return $input;
716 716
         }
717 717
         
718 718
         $vat_classes = self::get_rate_classes();
719
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
719
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
720 720
         
721
-        if ( empty( $vat_class ) ) {
722
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
721
+        if (empty($vat_class)) {
722
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
723 723
             
724 724
             return $input;
725 725
         }
726 726
 
727
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
727
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
728 728
 
729
-        if ( $vat_class === '_standard' ) {
729
+        if ($vat_class === '_standard') {
730 730
             // Save the active rates in the invoice settings
731
-            update_option( 'wpinv_tax_rates', $new_rates );
731
+            update_option('wpinv_tax_rates', $new_rates);
732 732
         } else {
733 733
             // Get the existing set of rates
734 734
             $rates = self::get_non_standard_rates();
735 735
             $rates[$vat_class] = $new_rates;
736 736
 
737
-            update_option( 'wpinv_vat_rates', $rates );
737
+            update_option('wpinv_vat_rates', $rates);
738 738
         }
739 739
         
740 740
         return $input;
@@ -744,71 +744,71 @@  discard block
 block discarded – undo
744 744
         $response = array();
745 745
         $response['success'] = false;
746 746
         
747
-        if ( !current_user_can( 'manage_options' ) ) {
748
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
749
-            wp_send_json( $response );
747
+        if (!current_user_can('manage_options')) {
748
+            $response['error'] = __('Invalid access!', 'invoicing');
749
+            wp_send_json($response);
750 750
         }
751 751
         
752
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
753
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
752
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
753
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
754 754
         
755
-        if ( empty( $vat_class_name ) ) {
756
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
757
-            wp_send_json( $response );
755
+        if (empty($vat_class_name)) {
756
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
757
+            wp_send_json($response);
758 758
         }
759 759
         
760 760
         $vat_classes = (array)self::get_rate_classes();
761 761
 
762
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
763
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
764
-            wp_send_json( $response );
762
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
763
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
764
+            wp_send_json($response);
765 765
         }
766 766
         
767
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
768
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
767
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
768
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
769 769
         
770
-        $vat_classes = (array)self::get_rate_classes( true );
771
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
770
+        $vat_classes = (array)self::get_rate_classes(true);
771
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
772 772
         
773
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
773
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
774 774
         
775 775
         $response['success'] = true;
776
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
776
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
777 777
         
778
-        wp_send_json( $response );
778
+        wp_send_json($response);
779 779
     }
780 780
     
781 781
     public static function delete_class() {
782 782
         $response = array();
783 783
         $response['success'] = false;
784 784
         
785
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
786
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
787
-            wp_send_json( $response );
785
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
786
+            $response['error'] = __('Invalid access!', 'invoicing');
787
+            wp_send_json($response);
788 788
         }
789 789
         
790
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
790
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
791 791
         $vat_classes = (array)self::get_rate_classes();
792 792
 
793
-        if ( !isset( $vat_classes[$vat_class] ) ) {
794
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
795
-            wp_send_json( $response );
793
+        if (!isset($vat_classes[$vat_class])) {
794
+            $response['error'] = __('Requested class does not exists', 'invoicing');
795
+            wp_send_json($response);
796 796
         }
797 797
         
798
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
799
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
800
-            wp_send_json( $response );
798
+        if ($vat_class == '_new' || $vat_class == '_standard') {
799
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
800
+            wp_send_json($response);
801 801
         }
802 802
             
803
-        $vat_classes = (array)self::get_rate_classes( true );
804
-        unset( $vat_classes[$vat_class] );
803
+        $vat_classes = (array)self::get_rate_classes(true);
804
+        unset($vat_classes[$vat_class]);
805 805
         
806
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
806
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
807 807
         
808 808
         $response['success'] = true;
809
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
809
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
810 810
         
811
-        wp_send_json( $response );
811
+        wp_send_json($response);
812 812
     }
813 813
     
814 814
     public static function update_eu_rates() {        
@@ -817,72 +817,72 @@  discard block
 block discarded – undo
817 817
         $response['error']      = null;
818 818
         $response['data']       = null;
819 819
         
820
-        if ( !current_user_can( 'manage_options' ) ) {
821
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
822
-            wp_send_json( $response );
820
+        if (!current_user_can('manage_options')) {
821
+            $response['error'] = __('Invalid access!', 'invoicing');
822
+            wp_send_json($response);
823 823
         }
824 824
         
825
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
826
-        $euvatrates = self::request_euvatrates( $group );
825
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
826
+        $euvatrates = self::request_euvatrates($group);
827 827
         
828
-        if ( !empty( $euvatrates ) ) {
829
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
828
+        if (!empty($euvatrates)) {
829
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
830 830
                 $response['success']        = true;
831 831
                 $response['data']['rates']  = $euvatrates['rates'];
832
-            } else if ( !empty( $euvatrates['error'] ) ) {
832
+            } else if (!empty($euvatrates['error'])) {
833 833
                 $response['error']          = $euvatrates['error'];
834 834
             }
835 835
         }
836 836
             
837
-        wp_send_json( $response );
837
+        wp_send_json($response);
838 838
     }
839 839
     
840 840
     public static function hide_vat_fields() {
841
-        $hide = wpinv_get_option( 'vat_disable_fields' );
841
+        $hide = wpinv_get_option('vat_disable_fields');
842 842
         
843
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
843
+        return apply_filters('wpinv_hide_vat_fields', $hide);
844 844
     }
845 845
     
846 846
     public static function same_country_rule() {
847
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
847
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
848 848
         
849
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
849
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
850 850
     }
851 851
     
852 852
     public static function get_vat_name() {
853
-        $vat_name   = wpinv_get_option( 'vat_name' );
854
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
853
+        $vat_name   = wpinv_get_option('vat_name');
854
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
855 855
         
856
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
856
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
857 857
     }
858 858
     
859 859
     public static function get_company_name() {
860
-        $company_name = wpinv_get_option( 'vat_company_name' );
860
+        $company_name = wpinv_get_option('vat_company_name');
861 861
         
862
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
862
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
863 863
     }
864 864
     
865 865
     public static function get_vat_number() {
866
-        $vat_number = wpinv_get_option( 'vat_number' );
866
+        $vat_number = wpinv_get_option('vat_number');
867 867
         
868
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
868
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
869 869
     }
870 870
     
871 871
     public static function is_vat_validated() {
872
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
872
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
873 873
         
874
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
874
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
875 875
     }
876 876
     
877
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
878
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
877
+    public static function sanitize_vat($vat_number, $country_code = '') {        
878
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
879 879
         
880
-        if ( empty( $country_code ) ) {
881
-            $country_code = substr( $vat_number, 0, 2 );
880
+        if (empty($country_code)) {
881
+            $country_code = substr($vat_number, 0, 2);
882 882
         }
883 883
         
884
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
885
-            $vat = str_replace( $country_code, '', $vat_number );
884
+        if (strpos($vat_number, $country_code) === 0) {
885
+            $vat = str_replace($country_code, '', $vat_number);
886 886
         } else {
887 887
             $vat = $country_code . $vat_number;
888 888
         }
@@ -895,140 +895,140 @@  discard block
 block discarded – undo
895 895
         return $return;
896 896
     }
897 897
     
898
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
899
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
898
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
899
+        $vat            = self::sanitize_vat($vat_number, $country_code);
900 900
         $vat_number     = $vat['vat_number'];
901 901
         $country_code   = $vat['iso'];
902 902
         $regex          = array();
903 903
         
904
-        switch ( $country_code ) {
904
+        switch ($country_code) {
905 905
             case 'AT':
906
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
906
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
907 907
                 break;
908 908
             case 'BE':
909
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
909
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
910 910
                 break;
911 911
             case 'BG':
912
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
912
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
913 913
                 break;
914 914
             case 'CH':
915 915
             case 'CHE':
916
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
916
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
917 917
                 break;
918 918
             case 'CY':
919
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
919
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
920 920
                 break;
921 921
             case 'CZ':
922
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
922
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
923 923
                 break;
924 924
             case 'DE':
925
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
925
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
926 926
                 break;
927 927
             case 'DK':
928
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
928
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
929 929
                 break;
930 930
             case 'EE':
931
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
931
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
932 932
                 break;
933 933
             case 'EL':
934
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
934
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
935 935
                 break;
936 936
             case 'ES':
937
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
938
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
939
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
940
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
937
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
938
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
939
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
940
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
941 941
                 break;
942 942
             case 'EU':
943
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
943
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
944 944
                 break;
945 945
             case 'FI':
946
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
946
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
947 947
                 break;
948 948
             case 'FR':
949
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
950
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
951
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
952
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
949
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
950
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
951
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
952
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
953 953
                 break;
954 954
             case 'GB':
955
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
956
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
957
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
958
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
955
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
956
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
957
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
958
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
959 959
                 break;
960 960
             case 'GR':
961
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
961
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
962 962
                 break;
963 963
             case 'HR':
964
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
964
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
965 965
                 break;
966 966
             case 'HU':
967
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
967
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
968 968
                 break;
969 969
             case 'IE':
970
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
971
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
972
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
970
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
971
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
972
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
973 973
                 break;
974 974
             case 'IT':
975
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
975
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
976 976
                 break;
977 977
             case 'LV':
978
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
978
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
979 979
                 break;
980 980
             case 'LT':
981
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
981
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
982 982
                 break;
983 983
             case 'LU':
984
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
984
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
985 985
                 break;
986 986
             case 'MT':
987
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
987
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
988 988
                 break;
989 989
             case 'NL':
990
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
990
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
991 991
                 break;
992 992
             case 'NO':
993
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
993
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
994 994
                 break;
995 995
             case 'PL':
996
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
996
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
997 997
                 break;
998 998
             case 'PT':
999
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
999
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1000 1000
                 break;
1001 1001
             case 'RO':
1002
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1002
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1003 1003
                 break;
1004 1004
             case 'RS':
1005
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1005
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1006 1006
                 break;
1007 1007
             case 'SI':
1008
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1008
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1009 1009
                 break;
1010 1010
             case 'SK':
1011
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1011
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1012 1012
                 break;
1013 1013
             case 'SE':
1014
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1014
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1015 1015
                 break;
1016 1016
             default:
1017 1017
                 $regex = array();
1018 1018
             break;
1019 1019
         }
1020 1020
         
1021
-        if ( empty( $regex ) ) {
1021
+        if (empty($regex)) {
1022 1022
             return false;
1023 1023
         }
1024 1024
         
1025
-        foreach ( $regex as $pattern ) {
1025
+        foreach ($regex as $pattern) {
1026 1026
             $matches = null;
1027
-            preg_match_all( $pattern, $vat_number, $matches );
1027
+            preg_match_all($pattern, $vat_number, $matches);
1028 1028
             
1029
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1030
-                if ( $formatted ) {
1031
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1029
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1030
+                if ($formatted) {
1031
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1032 1032
                 } else {
1033 1033
                     return true;
1034 1034
                 }
@@ -1038,75 +1038,75 @@  discard block
 block discarded – undo
1038 1038
         return false;
1039 1039
     }
1040 1040
     
1041
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1042
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1041
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1042
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1043 1043
         $vat_number     = $vat['vat'];
1044 1044
         $iso            = $vat['iso'];
1045 1045
         
1046
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1046
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1047 1047
         
1048
-        if ( ini_get( 'allow_url_fopen' ) ) {
1049
-            $response = file_get_contents( $url );
1050
-        } else if ( function_exists( 'curl_init' ) ) {
1048
+        if (ini_get('allow_url_fopen')) {
1049
+            $response = file_get_contents($url);
1050
+        } else if (function_exists('curl_init')) {
1051 1051
             $ch = curl_init();
1052 1052
             
1053
-            curl_setopt( $ch, CURLOPT_URL, $url );
1054
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1055
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1056
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1057
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1053
+            curl_setopt($ch, CURLOPT_URL, $url);
1054
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1055
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1056
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1057
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1058 1058
             
1059
-            $response = curl_exec( $ch );
1059
+            $response = curl_exec($ch);
1060 1060
             
1061
-            if ( curl_errno( $ch ) ) {
1062
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1061
+            if (curl_errno($ch)) {
1062
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1063 1063
                 $response = '';
1064 1064
             }
1065 1065
             
1066
-            curl_close( $ch );
1066
+            curl_close($ch);
1067 1067
         } else {
1068
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1068
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1069 1069
         }
1070 1070
         
1071
-        if ( empty( $response ) ) {
1071
+        if (empty($response)) {
1072 1072
             return $result;
1073 1073
         }
1074 1074
 
1075
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1075
+        if (preg_match('/invalid VAT number/i', $response)) {
1076 1076
             return false;
1077
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1078
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1077
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1078
+            $content = explode("valid VAT number", htmlentities($response));
1079 1079
             
1080
-            if ( !empty( $content[1] ) ) {
1081
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1080
+            if (!empty($content[1])) {
1081
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1082 1082
                 
1083
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1083
+                if (!empty($matches[2]) && $matches[3]) {
1084 1084
                     $return = array();
1085 1085
                     
1086
-                    foreach ( $matches[2] as $key => $label ) {
1087
-                        $label = trim( $label );
1086
+                    foreach ($matches[2] as $key => $label) {
1087
+                        $label = trim($label);
1088 1088
                         
1089
-                        switch ( strtolower( $label ) ) {
1089
+                        switch (strtolower($label)) {
1090 1090
                             case 'member state':
1091
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1091
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1092 1092
                             break;
1093 1093
                             case 'vat number':
1094
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1094
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1095 1095
                             break;
1096 1096
                             case 'name':
1097
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1097
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1098 1098
                             break;
1099 1099
                             case 'address':
1100
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1101
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1100
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1101
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1102 1102
                             break;
1103 1103
                             case 'consultation number':
1104
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1104
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1105 1105
                             break;
1106 1106
                         }
1107 1107
                     }
1108 1108
                     
1109
-                    if ( !empty( $return ) ) {
1109
+                    if (!empty($return)) {
1110 1110
                         return $return;
1111 1111
                     }
1112 1112
                 }
@@ -1118,55 +1118,55 @@  discard block
 block discarded – undo
1118 1118
         }
1119 1119
     }
1120 1120
     
1121
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1121
+    public static function check_vat($vat_number, $country_code = '') {        
1122 1122
         $vat_name           = self::get_vat_name();
1123 1123
         
1124 1124
         $return             = array();
1125 1125
         $return['valid']    = false;
1126
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1126
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1127 1127
                 
1128
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1128
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1129 1129
             return $return;
1130 1130
         }
1131 1131
             
1132
-        $response = self::vies_check( $vat_number, $country_code );
1132
+        $response = self::vies_check($vat_number, $country_code);
1133 1133
         
1134
-        if ( $response ) {
1135
-            $return['valid']    = true;
1134
+        if ($response) {
1135
+            $return['valid'] = true;
1136 1136
             
1137
-            if ( is_array( $response ) ) {
1138
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1139
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1137
+            if (is_array($response)) {
1138
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1139
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1140 1140
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1141 1141
             }
1142 1142
         } else {
1143 1143
             $return['valid']    = false;
1144
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1144
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1145 1145
         }
1146 1146
         
1147 1147
         return $return;
1148 1148
     }
1149 1149
     
1150
-    public static function request_euvatrates( $group ) {
1150
+    public static function request_euvatrates($group) {
1151 1151
         $response               = array();
1152 1152
         $response['success']    = false;
1153 1153
         $response['error']      = null;
1154 1154
         $response['eurates']    = null;
1155 1155
         
1156 1156
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1157
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1158
-        $api_response   = wp_remote_get( $euvatrates_url );
1157
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1158
+        $api_response   = wp_remote_get($euvatrates_url);
1159 1159
     
1160 1160
         try {
1161
-            if ( is_wp_error( $api_response ) ) {
1162
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1161
+            if (is_wp_error($api_response)) {
1162
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1163 1163
             } else {
1164
-                $body = json_decode( $api_response['body'] );
1164
+                $body = json_decode($api_response['body']);
1165 1165
                 
1166
-                if ( isset( $body->rates ) ) {
1166
+                if (isset($body->rates)) {
1167 1167
                     $rates = array();
1168 1168
                     
1169
-                    foreach ( $body->rates as $country_code => $rate ) {
1169
+                    foreach ($body->rates as $country_code => $rate) {
1170 1170
                         $vat_rate = array();
1171 1171
                         $vat_rate['country']        = $rate->country;
1172 1172
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1175 1175
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1176 1176
                         
1177
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1177
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1178 1178
                             $vat_rate_group = array();
1179 1179
                             $vat_rate_group['country'] = $rate->country;
1180 1180
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1186,79 +1186,79 @@  discard block
 block discarded – undo
1186 1186
                     }
1187 1187
                     
1188 1188
                     $response['success']    = true;                                
1189
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1189
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1190 1190
                 } else {
1191
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1191
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1192 1192
                 }
1193 1193
             }
1194
-        } catch ( Exception $e ) {
1195
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1194
+        } catch (Exception $e) {
1195
+            $response['error'] = __($e->getMessage(), 'invoicing');
1196 1196
         }
1197 1197
         
1198
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1198
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1199 1199
     }    
1200 1200
     
1201
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1201
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1202 1202
         global $wpi_item_id, $wpi_country;
1203 1203
         
1204
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1205
-            $country_code = trim( $_POST['wpinv_country'] );
1206
-        } else if ( !empty( $_POST['country'] ) ) {
1207
-            $country_code = trim( $_POST['country'] );
1208
-        } else if ( !empty( $wpi_country ) ) {
1204
+        if (!empty($_POST['wpinv_country'])) {
1205
+            $country_code = trim($_POST['wpinv_country']);
1206
+        } else if (!empty($_POST['country'])) {
1207
+            $country_code = trim($_POST['country']);
1208
+        } else if (!empty($wpi_country)) {
1209 1209
             $country_code = $wpi_country;
1210 1210
         } else {
1211
-            $country_code = self::get_user_country( '', $user_id );
1211
+            $country_code = self::get_user_country('', $user_id);
1212 1212
         }
1213 1213
         
1214
-        if ( $is_digital === null && $wpi_item_id ) {
1215
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1214
+        if ($is_digital === null && $wpi_item_id) {
1215
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1216 1216
         }
1217 1217
         
1218
-        if ( !empty( $country_code ) ) {
1219
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1218
+        if (!empty($country_code)) {
1219
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1220 1220
         }
1221 1221
         
1222
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1222
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1223 1223
     }
1224 1224
     
1225
-    public static function tax_label( $label = '' ) {
1225
+    public static function tax_label($label = '') {
1226 1226
         global $wpi_requires_vat;
1227 1227
         
1228
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1229
-            $wpi_requires_vat = self::requires_vat( 0, false );
1228
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1229
+            $wpi_requires_vat = self::requires_vat(0, false);
1230 1230
         }
1231 1231
         
1232
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1232
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1233 1233
     }
1234 1234
     
1235 1235
     public static function standard_rates_label() {
1236
-        return __( 'Standard Rates', 'invoicing' );
1236
+        return __('Standard Rates', 'invoicing');
1237 1237
     }
1238 1238
     
1239
-    public static function get_rate_classes( $with_desc = false ) {        
1240
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1241
-        $classes = maybe_unserialize( $rate_classes_option );
1239
+    public static function get_rate_classes($with_desc = false) {        
1240
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1241
+        $classes = maybe_unserialize($rate_classes_option);
1242 1242
         
1243
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1243
+        if (empty($classes) || !is_array($classes)) {
1244 1244
             $classes = array();
1245 1245
         }
1246 1246
 
1247 1247
         $rate_classes = array();
1248
-        if ( !array_key_exists( '_standard', $classes ) ) {
1249
-            if ( $with_desc ) {
1250
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1248
+        if (!array_key_exists('_standard', $classes)) {
1249
+            if ($with_desc) {
1250
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1251 1251
             } else {
1252 1252
                 $rate_classes['_standard'] = self::standard_rates_label();
1253 1253
             }
1254 1254
         }
1255 1255
         
1256
-        foreach ( $classes as $key => $class ) {
1257
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1258
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1256
+        foreach ($classes as $key => $class) {
1257
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1258
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1259 1259
             
1260
-            if ( $with_desc ) {
1261
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1260
+            if ($with_desc) {
1261
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1262 1262
             } else {
1263 1263
                 $rate_classes[$key] = $name;
1264 1264
             }
@@ -1269,15 +1269,15 @@  discard block
 block discarded – undo
1269 1269
     
1270 1270
     public static function get_all_classes() {        
1271 1271
         $classes            = self::get_rate_classes();
1272
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1272
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1273 1273
         
1274
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1274
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1275 1275
     }
1276 1276
     
1277
-    public static function get_class_desc( $rate_class ) {        
1278
-        $rate_classes = self::get_rate_classes( true );
1277
+    public static function get_class_desc($rate_class) {        
1278
+        $rate_classes = self::get_rate_classes(true);
1279 1279
 
1280
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1280
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1281 1281
             return $rate_classes[$rate_class]['desc'];
1282 1282
         }
1283 1283
         
@@ -1293,106 +1293,106 @@  discard block
 block discarded – undo
1293 1293
             'increased'     => 'Increased'
1294 1294
         );
1295 1295
         
1296
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1296
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1297 1297
     }
1298 1298
 
1299 1299
     public static function get_rules() {
1300 1300
         $vat_rules = array(
1301
-            'digital' => __( 'Digital Product', 'invoicing' ),
1302
-            'physical' => __( 'Physical Product', 'invoicing' )
1301
+            'digital' => __('Digital Product', 'invoicing'),
1302
+            'physical' => __('Physical Product', 'invoicing')
1303 1303
         );
1304
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1304
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1305 1305
     }
1306 1306
 
1307
-    public static function get_vat_rates( $class ) {
1308
-        if ( $class === '_standard' ) {
1307
+    public static function get_vat_rates($class) {
1308
+        if ($class === '_standard') {
1309 1309
             return wpinv_get_tax_rates();
1310 1310
         }
1311 1311
 
1312 1312
         $rates = self::get_non_standard_rates();
1313 1313
 
1314
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1314
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1315 1315
     }
1316 1316
 
1317 1317
     public static function get_non_standard_rates() {
1318
-        $option = get_option( 'wpinv_vat_rates', array());
1319
-        return is_array( $option ) ? $option : array();
1318
+        $option = get_option('wpinv_vat_rates', array());
1319
+        return is_array($option) ? $option : array();
1320 1320
     }
1321 1321
     
1322 1322
     public static function allow_vat_rules() {
1323
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1323
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1324 1324
     }
1325 1325
     
1326 1326
     public static function allow_vat_classes() {
1327 1327
         return false; // TODO
1328
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1328
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1329 1329
     }
1330 1330
     
1331
-    public static function get_item_class( $postID ) {
1332
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1331
+    public static function get_item_class($postID) {
1332
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1333 1333
 
1334
-        if ( empty( $class ) ) {
1334
+        if (empty($class)) {
1335 1335
             $class = '_standard';
1336 1336
         }
1337 1337
         
1338
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1338
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1339 1339
     }
1340 1340
     
1341
-    public static function item_class_label( $postID ) {        
1341
+    public static function item_class_label($postID) {        
1342 1342
         $vat_classes = self::get_all_classes();
1343 1343
         
1344
-        $class = self::get_item_class( $postID );
1345
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1344
+        $class = self::get_item_class($postID);
1345
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1346 1346
         
1347
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1347
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1348 1348
     }
1349 1349
     
1350
-    public static function get_item_rule( $postID ) {        
1351
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1350
+    public static function get_item_rule($postID) {        
1351
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1352 1352
         
1353
-        if ( empty( $rule_type ) ) {        
1353
+        if (empty($rule_type)) {        
1354 1354
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1355 1355
         }
1356 1356
         
1357
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1357
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1358 1358
     }
1359 1359
     
1360
-    public static function item_rule_label( $postID ) {
1360
+    public static function item_rule_label($postID) {
1361 1361
         $vat_rules  = self::get_rules();
1362
-        $vat_rule   = self::get_item_rule( $postID );
1363
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1362
+        $vat_rule   = self::get_item_rule($postID);
1363
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1364 1364
         
1365
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1365
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1366 1366
     }
1367 1367
     
1368
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1369
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1368
+    public static function item_has_digital_rule($item_id = 0) {        
1369
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1370 1370
     }
1371 1371
     
1372
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1373
-        if ( !self::allow_vat_rules() ) {
1372
+    public static function invoice_has_digital_rule($invoice = 0) {        
1373
+        if (!self::allow_vat_rules()) {
1374 1374
             return false;
1375 1375
         }
1376 1376
         
1377
-        if ( empty( $invoice ) ) {
1377
+        if (empty($invoice)) {
1378 1378
             return true;
1379 1379
         }
1380 1380
         
1381
-        if ( is_int( $invoice ) ) {
1382
-            $invoice = new WPInv_Invoice( $invoice );
1381
+        if (is_int($invoice)) {
1382
+            $invoice = new WPInv_Invoice($invoice);
1383 1383
         }
1384 1384
         
1385
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1385
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1386 1386
             return true;
1387 1387
         }
1388 1388
         
1389
-        $cart_items  = $invoice->get_cart_details();
1389
+        $cart_items = $invoice->get_cart_details();
1390 1390
         
1391
-        if ( !empty( $cart_items ) ) {
1391
+        if (!empty($cart_items)) {
1392 1392
             $has_digital_rule = false;
1393 1393
             
1394
-            foreach ( $cart_items as $key => $item ) {
1395
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1394
+            foreach ($cart_items as $key => $item) {
1395
+                if (self::item_has_digital_rule($item['id'])) {
1396 1396
                     $has_digital_rule = true;
1397 1397
                     break;
1398 1398
                 }
@@ -1404,67 +1404,67 @@  discard block
 block discarded – undo
1404 1404
         return $has_digital_rule;
1405 1405
     }
1406 1406
     
1407
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1408
-        if ( !wpinv_use_taxes() ) {
1407
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1408
+        if (!wpinv_use_taxes()) {
1409 1409
             return false;
1410 1410
         }
1411 1411
         
1412 1412
         $is_taxable = true;
1413 1413
 
1414
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1414
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1415 1415
             $is_taxable = false;
1416 1416
         }
1417 1417
         
1418
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1418
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1419 1419
     }
1420 1420
     
1421
-    public static function find_rate( $country, $state, $rate, $class ) {
1421
+    public static function find_rate($country, $state, $rate, $class) {
1422 1422
         global $wpi_zero_tax;
1423 1423
 
1424
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1424
+        if ($class === '_exempt' || $wpi_zero_tax) {
1425 1425
             return 0;
1426 1426
         }
1427 1427
 
1428
-        $tax_rates   = wpinv_get_tax_rates();
1428
+        $tax_rates = wpinv_get_tax_rates();
1429 1429
         
1430
-        if ( $class !== '_standard' ) {
1431
-            $class_rates = self::get_vat_rates( $class );
1430
+        if ($class !== '_standard') {
1431
+            $class_rates = self::get_vat_rates($class);
1432 1432
             
1433
-            if ( is_array( $class_rates ) ) {
1433
+            if (is_array($class_rates)) {
1434 1434
                 $indexed_class_rates = array();
1435 1435
                 
1436
-                foreach ( $class_rates as $key => $cr ) {
1436
+                foreach ($class_rates as $key => $cr) {
1437 1437
                     $indexed_class_rates[$cr['country']] = $cr;
1438 1438
                 }
1439 1439
 
1440
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1440
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1441 1441
                     $tr_country = $tr['country'];
1442
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1442
+                    if (!isset($indexed_class_rates[$tr_country])) {
1443 1443
                         return $tr;
1444 1444
                     }
1445 1445
                     $icr = $indexed_class_rates[$tr_country];
1446
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1446
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1447 1447
 
1448
-                }, $tax_rates, $class_rates );
1448
+                }, $tax_rates, $class_rates);
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        if ( !empty( $tax_rates ) ) {
1453
-            foreach ( $tax_rates as $key => $tax_rate ) {
1454
-                if ( $country != $tax_rate['country'] )
1452
+        if (!empty($tax_rates)) {
1453
+            foreach ($tax_rates as $key => $tax_rate) {
1454
+                if ($country != $tax_rate['country'])
1455 1455
                     continue;
1456 1456
 
1457
-                if ( !empty( $tax_rate['global'] ) ) {
1458
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1459
-                        $rate = number_format( $tax_rate['rate'], 4 );
1457
+                if (!empty($tax_rate['global'])) {
1458
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1459
+                        $rate = number_format($tax_rate['rate'], 4);
1460 1460
                     }
1461 1461
                 } else {
1462
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1462
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1463 1463
                         continue;
1464 1464
 
1465 1465
                     $state_rate = $tax_rate['rate'];
1466
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1467
-                        $rate = number_format( $state_rate, 4 );
1466
+                    if (0 !== $state_rate || !empty($state_rate)) {
1467
+                        $rate = number_format($state_rate, 4);
1468 1468
                     }
1469 1469
                 }
1470 1470
             }
@@ -1473,84 +1473,84 @@  discard block
 block discarded – undo
1473 1473
         return $rate;
1474 1474
     }
1475 1475
     
1476
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1476
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1477 1477
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1478 1478
         
1479 1479
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1480 1480
         $allow_vat_classes = self::allow_vat_classes();
1481
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1481
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1482 1482
 
1483
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1483
+        if ($class === '_exempt' || $wpi_zero_tax) {
1484 1484
             return 0;
1485
-        } else if ( !$allow_vat_classes ) {
1485
+        } else if (!$allow_vat_classes) {
1486 1486
             $class = '_standard';
1487 1487
         }
1488 1488
 
1489
-        if( !empty( $_POST['wpinv_country'] ) ) {
1489
+        if (!empty($_POST['wpinv_country'])) {
1490 1490
             $post_country = $_POST['wpinv_country'];
1491
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1491
+        } elseif (!empty($_POST['wpinv_country'])) {
1492 1492
             $post_country = $_POST['wpinv_country'];
1493
-        } elseif( !empty( $_POST['country'] ) ) {
1493
+        } elseif (!empty($_POST['country'])) {
1494 1494
             $post_country = $_POST['country'];
1495 1495
         } else {
1496 1496
             $post_country = '';
1497 1497
         }
1498 1498
 
1499
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1500
-        $base_country   = wpinv_is_base_country( $country );
1499
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1500
+        $base_country   = wpinv_is_base_country($country);
1501 1501
         
1502
-        $requires_vat   = self::requires_vat( 0, false );
1503
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1504
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1502
+        $requires_vat   = self::requires_vat(0, false);
1503
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1504
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1505 1505
           
1506
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1506
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1507 1507
             $rate = 0;
1508
-        } else if ( $requires_vat ) {
1509
-            $vat_number = self::get_user_vat_number( '', 0, true );
1508
+        } else if ($requires_vat) {
1509
+            $vat_number = self::get_user_vat_number('', 0, true);
1510 1510
             $vat_info   = self::current_vat_data();
1511 1511
             
1512
-            if ( is_array( $vat_info ) ) {
1513
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1512
+            if (is_array($vat_info)) {
1513
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1514 1514
             }
1515 1515
             
1516
-            if ( $country == 'UK' ) {
1516
+            if ($country == 'UK') {
1517 1517
                 $country = 'GB';
1518 1518
             }
1519 1519
 
1520
-            if ( !empty( $vat_number ) ) {
1520
+            if (!empty($vat_number)) {
1521 1521
                 $rate = 0;
1522 1522
             } else {
1523
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1523
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1524 1524
             }
1525 1525
 
1526
-            if ( empty( $vat_number ) && !$is_digital ) {
1527
-                if ( $base_country ) {
1528
-                    $rate = self::find_rate( $country, null, $rate, $class );
1526
+            if (empty($vat_number) && !$is_digital) {
1527
+                if ($base_country) {
1528
+                    $rate = self::find_rate($country, null, $rate, $class);
1529 1529
                 } else {
1530
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1530
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1531 1531
                         $rate = $wpinv_options['eu_fallback_rate'];
1532
-                    } else if( !empty( $country ) ) {
1533
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1532
+                    } else if (!empty($country)) {
1533
+                        $rate = self::find_rate($country, $state, $rate, $class);
1534 1534
                     }
1535 1535
                 }
1536
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1537
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1536
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1537
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1538 1538
                     $rate = $wpinv_options['eu_fallback_rate'];
1539
-                } else if( !empty( $country ) ) {
1540
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1539
+                } else if (!empty($country)) {
1540
+                    $rate = self::find_rate($country, $state, $rate, $class);
1541 1541
                 }
1542 1542
             }
1543 1543
         } else {
1544
-            if ( $is_digital ) {
1544
+            if ($is_digital) {
1545 1545
                 $ip_country_code = self::get_country_by_ip();
1546 1546
                 
1547
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1548
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1547
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1548
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1549 1549
                 } else {
1550
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1550
+                    $rate = self::find_rate($country, $state, $rate, $class);
1551 1551
                 }
1552 1552
             } else {
1553
-                $rate = self::find_rate( $country, $state, $rate, $class );
1553
+                $rate = self::find_rate($country, $state, $rate, $class);
1554 1554
             }
1555 1555
         }
1556 1556
 
@@ -1560,48 +1560,48 @@  discard block
 block discarded – undo
1560 1560
     public static function current_vat_data() {
1561 1561
         global $wpi_session;
1562 1562
         
1563
-        return $wpi_session->get( 'user_vat_data' );
1563
+        return $wpi_session->get('user_vat_data');
1564 1564
     }
1565 1565
     
1566
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1567
-        $user_address = wpinv_get_user_address( $user_id, false );
1566
+    public static function get_user_country($country = '', $user_id = 0) {
1567
+        $user_address = wpinv_get_user_address($user_id, false);
1568 1568
         
1569
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1569
+        if (wpinv_get_option('vat_ip_country_default')) {
1570 1570
             $country = '';
1571 1571
         }
1572 1572
         
1573
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1574
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1573
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1574
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1575 1575
 
1576
-        if ( empty( $result ) ) {
1576
+        if (empty($result)) {
1577 1577
             $result = self::get_country_by_ip();
1578 1578
         }
1579 1579
 
1580 1580
         return $result;
1581 1581
     }
1582 1582
     
1583
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1583
+    public static function set_user_country($country = '', $user_id = 0) {
1584 1584
         global $wpi_userID;
1585 1585
         
1586
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1586
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1587 1587
             $country = wpinv_get_default_country();
1588 1588
         }
1589 1589
         
1590 1590
         return $country;
1591 1591
     }
1592 1592
     
1593
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1593
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1594 1594
         global $wpi_current_id, $wpi_userID;
1595 1595
         
1596
-        if ( !empty( $_POST['new_user'] ) ) {
1596
+        if (!empty($_POST['new_user'])) {
1597 1597
             return '';
1598 1598
         }
1599 1599
         
1600
-        if ( empty( $user_id ) ) {
1601
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1600
+        if (empty($user_id)) {
1601
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1602 1602
         }
1603 1603
 
1604
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1604
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1605 1605
         
1606 1606
         /* TODO
1607 1607
         if ( $is_valid && $vat_number ) {
@@ -1612,36 +1612,36 @@  discard block
 block discarded – undo
1612 1612
         }
1613 1613
         */
1614 1614
 
1615
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1615
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1616 1616
     }
1617 1617
     
1618
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1619
-        if ( empty( $user_id ) ) {
1618
+    public static function get_user_company($company = '', $user_id = 0) {
1619
+        if (empty($user_id)) {
1620 1620
             $user_id = get_current_user_id();
1621 1621
         }
1622 1622
 
1623
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1623
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1624 1624
 
1625
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1625
+        return apply_filters('wpinv_user_company', $company, $user_id);
1626 1626
     }
1627 1627
     
1628
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1629
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1628
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1629
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1630 1630
 
1631
-        if ( is_user_logged_in() && $save ) {
1631
+        if (is_user_logged_in() && $save) {
1632 1632
             $user_id = get_current_user_id();
1633 1633
 
1634
-            if ( !empty( $vat_number ) ) {
1635
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1634
+            if (!empty($vat_number)) {
1635
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1636 1636
             } else {
1637
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1637
+                delete_user_meta($user_id, '_wpinv_vat_number');
1638 1638
             }
1639 1639
 
1640
-            if ( !empty( $company ) ) {
1641
-                update_user_meta( $user_id, '_wpinv_company', $company );
1640
+            if (!empty($company)) {
1641
+                update_user_meta($user_id, '_wpinv_company', $company);
1642 1642
             } else {
1643
-                delete_user_meta( $user_id, '_wpinv_company');
1644
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1643
+                delete_user_meta($user_id, '_wpinv_company');
1644
+                delete_user_meta($user_id, '_wpinv_vat_number');
1645 1645
             }
1646 1646
         }
1647 1647
 
@@ -1651,113 +1651,113 @@  discard block
 block discarded – undo
1651 1651
     public static function ajax_vat_validate() {
1652 1652
         global $wpinv_options, $wpi_session;
1653 1653
         
1654
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1654
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1655 1655
         $response               = array();
1656 1656
         $response['success']    = false;
1657 1657
         
1658
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1659
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1660
-            wp_send_json( $response );
1658
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1659
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1660
+            wp_send_json($response);
1661 1661
         }
1662 1662
         
1663
-        $vat_name   = self::get_vat_name();
1663
+        $vat_name = self::get_vat_name();
1664 1664
         
1665
-        if ( $is_checkout ) {
1665
+        if ($is_checkout) {
1666 1666
             $invoice = wpinv_get_invoice_cart();
1667 1667
             
1668
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1668
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1669 1669
                 $vat_info = array();
1670
-                $wpi_session->set( 'user_vat_data', $vat_info );
1670
+                $wpi_session->set('user_vat_data', $vat_info);
1671 1671
 
1672 1672
                 self::save_user_vat_details();
1673 1673
                 
1674 1674
                 $response['success'] = true;
1675
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1676
-                wp_send_json( $response );
1675
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1676
+                wp_send_json($response);
1677 1677
             }
1678 1678
         }
1679 1679
         
1680
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1681
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1680
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1681
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1682 1682
         
1683
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1684
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1685
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1683
+        $vat_info = $wpi_session->get('user_vat_data');
1684
+        if (!is_array($vat_info) || empty($vat_info)) {
1685
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1686 1686
         }
1687 1687
         
1688
-        if ( empty( $vat_number ) ) {
1689
-            if ( $is_checkout ) {
1688
+        if (empty($vat_number)) {
1689
+            if ($is_checkout) {
1690 1690
                 $response['success'] = true;
1691
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1691
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1692 1692
                 
1693
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1693
+                $vat_info = $wpi_session->get('user_vat_data');
1694 1694
                 $vat_info['number'] = "";
1695 1695
                 $vat_info['valid'] = true;
1696 1696
                 
1697
-                self::save_user_vat_details( $company );
1697
+                self::save_user_vat_details($company);
1698 1698
             } else {
1699
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1699
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1700 1700
                 
1701 1701
                 $vat_info['valid'] = false;
1702 1702
             }
1703 1703
 
1704
-            $wpi_session->set( 'user_vat_data', $vat_info );
1705
-            wp_send_json( $response );
1704
+            $wpi_session->set('user_vat_data', $vat_info);
1705
+            wp_send_json($response);
1706 1706
         }
1707 1707
         
1708
-        if ( empty( $company ) ) {
1708
+        if (empty($company)) {
1709 1709
             $vat_info['valid'] = false;
1710
-            $wpi_session->set( 'user_vat_data', $vat_info );
1710
+            $wpi_session->set('user_vat_data', $vat_info);
1711 1711
             
1712
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1713
-            wp_send_json( $response );
1712
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1713
+            wp_send_json($response);
1714 1714
         }
1715 1715
         
1716
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1717
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1716
+        if (!empty($wpinv_options['vat_vies_check'])) {
1717
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1718 1718
                 $vat_info['valid'] = false;
1719
-                $wpi_session->set( 'user_vat_data', $vat_info );
1719
+                $wpi_session->set('user_vat_data', $vat_info);
1720 1720
                 
1721
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1722
-                wp_send_json( $response );
1721
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1722
+                wp_send_json($response);
1723 1723
             }
1724 1724
             
1725 1725
             $response['success'] = true;
1726
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1726
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1727 1727
         } else {
1728
-            $result = self::check_vat( $vat_number );
1728
+            $result = self::check_vat($vat_number);
1729 1729
             
1730
-            if ( empty( $result['valid'] ) ) {
1730
+            if (empty($result['valid'])) {
1731 1731
                 $response['error'] = $result['message'];
1732
-                wp_send_json( $response );
1732
+                wp_send_json($response);
1733 1733
             }
1734 1734
             
1735
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1736
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1735
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1736
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1737 1737
             
1738
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1738
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1739 1739
 
1740
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1740
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1741 1741
                 $response['success'] = true;
1742
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1742
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1743 1743
             } else {           
1744 1744
                 $vat_info['valid'] = false;
1745
-                $wpi_session->set( 'user_vat_data', $vat_info );
1745
+                $wpi_session->set('user_vat_data', $vat_info);
1746 1746
                 
1747 1747
                 $response['success'] = false;
1748
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1749
-                wp_send_json( $response );
1748
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1749
+                wp_send_json($response);
1750 1750
             }
1751 1751
         }
1752 1752
         
1753
-        if ( $is_checkout ) {
1754
-            self::save_user_vat_details( $company, $vat_number );
1753
+        if ($is_checkout) {
1754
+            self::save_user_vat_details($company, $vat_number);
1755 1755
 
1756
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1757
-            $wpi_session->set( 'user_vat_data', $vat_info );
1756
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1757
+            $wpi_session->set('user_vat_data', $vat_info);
1758 1758
         }
1759 1759
 
1760
-        wp_send_json( $response );
1760
+        wp_send_json($response);
1761 1761
     }
1762 1762
     
1763 1763
     public static function ajax_vat_reset() {
@@ -1766,161 +1766,161 @@  discard block
 block discarded – undo
1766 1766
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1767 1767
         $vat_number = self::get_user_vat_number();
1768 1768
         
1769
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1770
-        $wpi_session->set( 'user_vat_data', $vat_info );
1769
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1770
+        $wpi_session->set('user_vat_data', $vat_info);
1771 1771
         
1772 1772
         $response                       = array();
1773 1773
         $response['success']            = true;
1774 1774
         $response['data']['company']    = $company;
1775 1775
         $response['data']['number']     = $vat_number;
1776 1776
         
1777
-        wp_send_json( $response );
1777
+        wp_send_json($response);
1778 1778
     }
1779 1779
     
1780
-    public static function checkout_vat_validate( $valid_data, $post ) {
1780
+    public static function checkout_vat_validate($valid_data, $post) {
1781 1781
         global $wpinv_options, $wpi_session;
1782 1782
         
1783
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1783
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1784 1784
         
1785
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1786
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1785
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1786
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1787 1787
             return;
1788 1788
         }
1789 1789
         
1790
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1791
-        $wpi_session->set( 'user_vat_data', null );
1790
+        $vat_saved = $wpi_session->get('user_vat_data');
1791
+        $wpi_session->set('user_vat_data', null);
1792 1792
         
1793 1793
         $invoice        = wpinv_get_invoice_cart();
1794 1794
         $amount         = $invoice->get_total();
1795
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1796
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1795
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1796
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1797 1797
         
1798
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1799
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1800
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1801
-        if ( empty( $country ) ) {
1798
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1799
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1800
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1801
+        if (empty($country)) {
1802 1802
             $country = wpinv_default_billing_country();
1803 1803
         }
1804 1804
         
1805
-        if ( !$is_digital && $no_vat ) {
1805
+        if (!$is_digital && $no_vat) {
1806 1806
             return;
1807 1807
         }
1808 1808
             
1809
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1809
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1810 1810
         
1811 1811
         $ip_country_code    = self::get_country_by_ip();
1812
-        $is_eu_state        = self::is_eu_state( $country );
1813
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1812
+        $is_eu_state        = self::is_eu_state($country);
1813
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1814 1814
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1815 1815
         
1816
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1816
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1817 1817
             $vat_data['adddress_confirmed'] = false;
1818 1818
             
1819
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1820
-                if ( $ip_country_code != $country ) {
1821
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1819
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1820
+                if ($ip_country_code != $country) {
1821
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1822 1822
                 }
1823 1823
             } else {
1824 1824
                 $vat_data['adddress_confirmed'] = true;
1825 1825
             }
1826 1826
         }
1827 1827
         
1828
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1829
-            if ( $is_eu_state ) {
1830
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1831
-            } else if ( $is_digital && $is_eu_state_ip ) {
1832
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1828
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1829
+            if ($is_eu_state) {
1830
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1831
+            } else if ($is_digital && $is_eu_state_ip) {
1832
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1833 1833
             }
1834 1834
         }
1835 1835
         
1836
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1836
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1837 1837
             return;
1838 1838
         }
1839 1839
 
1840
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1841
-            $vat_data['valid']  = $vat_saved['valid'];
1840
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1841
+            $vat_data['valid'] = $vat_saved['valid'];
1842 1842
         }
1843 1843
             
1844
-        if ( $company !== null ) {
1844
+        if ($company !== null) {
1845 1845
             $vat_data['company'] = $company;
1846 1846
         }
1847 1847
 
1848 1848
         $message = '';
1849
-        if ( $vat_number !== null ) {
1849
+        if ($vat_number !== null) {
1850 1850
             $vat_data['number'] = $vat_number;
1851 1851
             
1852
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1853
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1854
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1852
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1853
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1854
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1855 1855
                         $vat_data['valid'] = false;
1856 1856
                     }
1857 1857
                 } else {
1858
-                    $result = self::check_vat( $vat_number );
1858
+                    $result = self::check_vat($vat_number);
1859 1859
                     
1860
-                    if ( !empty( $result['valid'] ) ) {                
1860
+                    if (!empty($result['valid'])) {                
1861 1861
                         $vat_data['valid'] = true;
1862
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1863
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1862
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1863
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1864 1864
                     
1865
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1865
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1866 1866
 
1867
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1867
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1868 1868
                             $vat_data['valid'] = false;
1869 1869
                             
1870
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1870
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1871 1871
                         }
1872 1872
                     } else {
1873
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1873
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1874 1874
                     }
1875 1875
                 }
1876 1876
                 
1877
-                if ( !$vat_data['valid'] ) {
1878
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1879
-                    wpinv_set_error( 'vat_validation', $error );
1877
+                if (!$vat_data['valid']) {
1878
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1879
+                    wpinv_set_error('vat_validation', $error);
1880 1880
                 }
1881 1881
             }
1882 1882
         }
1883 1883
 
1884
-        $wpi_session->set( 'user_vat_data', $vat_data );
1884
+        $wpi_session->set('user_vat_data', $vat_data);
1885 1885
     }
1886 1886
     
1887
-    public static function checkout_vat_fields( $billing_details ) {
1887
+    public static function checkout_vat_fields($billing_details) {
1888 1888
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1889 1889
         
1890 1890
         $ip_address         = wpinv_get_ip();
1891 1891
         $ip_country_code    = self::get_country_by_ip();
1892 1892
         
1893
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1893
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1894 1894
         $invoice            = wpinv_get_invoice_cart();
1895
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1895
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1896 1896
         $wpi_country        = $invoice->country;
1897 1897
         
1898
-        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital );
1898
+        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital);
1899 1899
         $wpi_requires_vat   = $requires_vat;
1900 1900
         
1901 1901
         $company            = is_user_logged_in() ? self::get_user_company() : '';
1902 1902
         $vat_number         = self::get_user_vat_number();
1903 1903
         
1904
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1905
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1904
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1905
+        $vat_info           = $wpi_session->get('user_vat_data');
1906 1906
 
1907
-        if ( is_array( $vat_info ) ) {
1908
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1909
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1910
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1907
+        if (is_array($vat_info)) {
1908
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1909
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1910
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1911 1911
         }
1912 1912
         
1913 1913
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1914 1914
 
1915
-        if ( $ip_country_code == 'UK' ) {
1915
+        if ($ip_country_code == 'UK') {
1916 1916
             $ip_country_code = 'GB';
1917 1917
         }
1918 1918
         
1919
-        if ( $selected_country == 'UK' ) {
1919
+        if ($selected_country == 'UK') {
1920 1920
             $selected_country = 'GB';
1921 1921
         }
1922 1922
         
1923
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1923
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1924 1924
             $requires_vat = false;
1925 1925
         }
1926 1926
 
@@ -1928,52 +1928,52 @@  discard block
 block discarded – undo
1928 1928
         $display_validate_btn   = 'none';
1929 1929
         $display_reset_btn      = 'none';
1930 1930
         
1931
-        if ( !empty( $vat_number ) && $validated ) {
1932
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1931
+        if (!empty($vat_number) && $validated) {
1932
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1933 1933
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1934 1934
             $display_reset_btn      = 'block';
1935 1935
         } else {
1936
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1937
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1936
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1937
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1938 1938
             $display_validate_btn   = 'block';
1939 1939
         }
1940 1940
         
1941
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1941
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1942 1942
         ?>
1943 1943
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1944 1944
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1945
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1945
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1946 1946
                 <div id="wpinv-fields-box" class="panel-body">
1947 1947
                     <p id="wpi_show_vat_note">
1948
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1948
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1949 1949
                     </p>
1950 1950
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1951 1951
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1952
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1952
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1953 1953
                             <?php
1954
-                            echo wpinv_html_text( array(
1954
+                            echo wpinv_html_text(array(
1955 1955
                                     'id'            => 'wpinv_company',
1956 1956
                                     'name'          => 'wpinv_company',
1957 1957
                                     'value'         => $company,
1958 1958
                                     'class'         => 'wpi-input form-control',
1959
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1960
-                                ) );
1959
+                                    'placeholder'   => __('Company name', 'invoicing'),
1960
+                                ));
1961 1961
                             ?>
1962 1962
                         </p>
1963 1963
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1964
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1964
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1965 1965
                             <span id="wpinv_vat_number-wrap">
1966 1966
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1967
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1968
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1967
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1968
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1969 1969
                             </span>
1970 1970
                         </p>
1971 1971
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1972
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1973
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1972
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1973
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1974 1974
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1975 1975
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1976
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1976
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1977 1977
                         </p>
1978 1978
                     </div>
1979 1979
                 </div>
@@ -1987,32 +1987,32 @@  discard block
 block discarded – undo
1987 1987
                 </span>
1988 1988
             </div>
1989 1989
         </div>
1990
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1991
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1990
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1991
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1992 1992
         ?>
1993 1993
         <div class="wpi-ip-info clearfix panel panel-info">
1994 1994
             <div id="wpinv-fields-box" class="panel-body">
1995
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
1995
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
1996 1996
             </div>
1997 1997
         </div>
1998 1998
         <?php }
1999 1999
     }
2000 2000
     
2001
-    public static function show_vat_notice( $invoice ) {
2002
-        if ( empty( $invoice ) ) {
2001
+    public static function show_vat_notice($invoice) {
2002
+        if (empty($invoice)) {
2003 2003
             return NULL;
2004 2004
         }
2005 2005
         
2006
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2007
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2008
-        if ( $label || $notice ) {
2006
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2007
+        $notice     = wpinv_get_option('vat_invoice_notice');
2008
+        if ($label || $notice) {
2009 2009
         ?>
2010 2010
         <div class="row wpinv-vat-notice">
2011 2011
             <div class="col-sm-12">
2012
-                <?php if ( $label ) { ?>
2013
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2014
-                <?php } if ( $notice ) { ?>
2015
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2012
+                <?php if ($label) { ?>
2013
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2014
+                <?php } if ($notice) { ?>
2015
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2016 2016
                 <?php } ?>
2017 2017
             </div>
2018 2018
         </div>
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  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 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
     public $filter;
48 48
 
49 49
 
50
-    public function __construct( $_id = false, $_args = array() ) {
51
-        $item = WP_Post::get_instance( $_id );
52
-        return $this->setup_item( $item );
50
+    public function __construct($_id = false, $_args = array()) {
51
+        $item = WP_Post::get_instance($_id);
52
+        return $this->setup_item($item);
53 53
     }
54 54
 
55
-    private function setup_item( $item ) {
56
-        if( ! is_object( $item ) ) {
55
+    private function setup_item($item) {
56
+        if (!is_object($item)) {
57 57
             return false;
58 58
         }
59 59
 
60
-        if( ! is_a( $item, 'WP_Post' ) ) {
60
+        if (!is_a($item, 'WP_Post')) {
61 61
             return false;
62 62
         }
63 63
 
64
-        if( 'wpi_item' !== $item->post_type ) {
64
+        if ('wpi_item' !== $item->post_type) {
65 65
             return false;
66 66
         }
67 67
 
68
-        foreach ( $item as $key => $value ) {
69
-            switch ( $key ) {
68
+        foreach ($item as $key => $value) {
69
+            switch ($key) {
70 70
                 default:
71 71
                     $this->$key = $value;
72 72
                     break;
@@ -76,38 +76,38 @@  discard block
 block discarded – undo
76 76
         return true;
77 77
     }
78 78
 
79
-    public function __get( $key ) {
80
-        if ( method_exists( $this, 'get_' . $key ) ) {
81
-            return call_user_func( array( $this, 'get_' . $key ) );
79
+    public function __get($key) {
80
+        if (method_exists($this, 'get_' . $key)) {
81
+            return call_user_func(array($this, 'get_' . $key));
82 82
         } else {
83
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
83
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
84 84
         }
85 85
     }
86 86
 
87
-    public function create( $data = array(), $wp_error = false ) {
88
-        if ( $this->ID != 0 ) {
87
+    public function create($data = array(), $wp_error = false) {
88
+        if ($this->ID != 0) {
89 89
             return false;
90 90
         }
91 91
 
92 92
         $defaults = array(
93 93
             'post_type'   => 'wpi_item',
94 94
             'post_status' => 'draft',
95
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
95
+            'post_title'  => __('New Invoice Item', 'invoicing')
96 96
         );
97 97
 
98
-        $args = wp_parse_args( $data, $defaults );
98
+        $args = wp_parse_args($data, $defaults);
99 99
 
100
-        do_action( 'wpinv_item_pre_create', $args );
100
+        do_action('wpinv_item_pre_create', $args);
101 101
 
102
-        $id = wp_insert_post( $args, $wp_error );
102
+        $id = wp_insert_post($args, $wp_error);
103 103
         if ($wp_error && is_wp_error($id)) {
104 104
             return $id;
105 105
         }
106
-        if ( !$id ) {
106
+        if (!$id) {
107 107
             return false;
108 108
         }
109 109
         
110
-        $item = WP_Post::get_instance( $id );
110
+        $item = WP_Post::get_instance($id);
111 111
         
112 112
         if (!empty($item) && !empty($data['meta'])) {
113 113
             $this->ID = $item->ID;
@@ -115,47 +115,47 @@  discard block
 block discarded – undo
115 115
         }
116 116
         
117 117
         // Set custom id if not set.
118
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
119
-            $this->save_metas( array( 'custom_id' => $id ) );
118
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
119
+            $this->save_metas(array('custom_id' => $id));
120 120
         }
121 121
 
122
-        do_action( 'wpinv_item_create', $id, $args );
122
+        do_action('wpinv_item_create', $id, $args);
123 123
 
124
-        return $this->setup_item( $item );
124
+        return $this->setup_item($item);
125 125
     }
126 126
     
127
-    public function update( $data = array(), $wp_error = false ) {
128
-        if ( !$this->ID > 0 ) {
127
+    public function update($data = array(), $wp_error = false) {
128
+        if (!$this->ID > 0) {
129 129
             return false;
130 130
         }
131 131
         
132 132
         $data['ID'] = $this->ID;
133 133
 
134
-        do_action( 'wpinv_item_pre_update', $data );
134
+        do_action('wpinv_item_pre_update', $data);
135 135
         
136
-        $id = wp_update_post( $data, $wp_error );
136
+        $id = wp_update_post($data, $wp_error);
137 137
         if ($wp_error && is_wp_error($id)) {
138 138
             return $id;
139 139
         }
140 140
         
141
-        if ( !$id ) {
141
+        if (!$id) {
142 142
             return false;
143 143
         }
144 144
 
145
-        $item = WP_Post::get_instance( $id );
145
+        $item = WP_Post::get_instance($id);
146 146
         if (!empty($item) && !empty($data['meta'])) {
147 147
             $this->ID = $item->ID;
148 148
             $this->save_metas($data['meta']);
149 149
         }
150 150
         
151 151
         // Set custom id if not set.
152
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
153
-            $this->save_metas( array( 'custom_id' => $id ) );
152
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
153
+            $this->save_metas(array('custom_id' => $id));
154 154
         }
155 155
 
156
-        do_action( 'wpinv_item_update', $id, $data );
156
+        do_action('wpinv_item_update', $id, $data);
157 157
 
158
-        return $this->setup_item( $item );
158
+        return $this->setup_item($item);
159 159
     }
160 160
 
161 161
     public function get_ID() {
@@ -163,119 +163,119 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     public function get_name() {
166
-        return get_the_title( $this->ID );
166
+        return get_the_title($this->ID);
167 167
     }
168 168
     
169 169
     public function get_title() {
170
-        return get_the_title( $this->ID );
170
+        return get_the_title($this->ID);
171 171
     }
172 172
     
173 173
     public function get_status() {
174
-        return get_post_status( $this->ID );
174
+        return get_post_status($this->ID);
175 175
     }
176 176
     
177 177
     public function get_summary() {
178
-        return get_the_excerpt( $this->ID );
178
+        return get_the_excerpt($this->ID);
179 179
     }
180 180
 
181 181
     public function get_price() {
182
-        if ( ! isset( $this->price ) ) {
183
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
182
+        if (!isset($this->price)) {
183
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
184 184
             
185
-            if ( $this->price ) {
186
-                $this->price = wpinv_sanitize_amount( $this->price );
185
+            if ($this->price) {
186
+                $this->price = wpinv_sanitize_amount($this->price);
187 187
             } else {
188 188
                 $this->price = 0;
189 189
             }
190 190
         }
191 191
         
192
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
192
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
193 193
     }
194 194
     
195 195
     public function get_vat_rule() {
196 196
         global $wpinv_euvat;
197 197
         
198
-        if( !isset( $this->vat_rule ) ) {
199
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
198
+        if (!isset($this->vat_rule)) {
199
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
200 200
 
201
-            if ( empty( $this->vat_rule ) ) {        
201
+            if (empty($this->vat_rule)) {        
202 202
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
203 203
             }
204 204
         }
205 205
         
206
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
206
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
207 207
     }
208 208
     
209 209
     public function get_vat_class() {
210
-        if( !isset( $this->vat_class ) ) {
211
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
210
+        if (!isset($this->vat_class)) {
211
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
212 212
 
213
-            if ( empty( $this->vat_class ) ) {        
213
+            if (empty($this->vat_class)) {        
214 214
                 $this->vat_class = '_standard';
215 215
             }
216 216
         }
217 217
         
218
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
218
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
219 219
     }
220 220
 
221 221
     public function get_type() {
222
-        if( ! isset( $this->type ) ) {
223
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
222
+        if (!isset($this->type)) {
223
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
224 224
 
225
-            if ( empty( $this->type ) ) {
225
+            if (empty($this->type)) {
226 226
                 $this->type = 'custom';
227 227
             }
228 228
         }
229 229
 
230
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
230
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
231 231
     }
232 232
     
233 233
     public function get_custom_id() {
234
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
234
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
235 235
 
236
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
236
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
237 237
     }
238 238
     
239 239
     public function get_custom_name() {
240
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
240
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
241 241
 
242
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
242
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
243 243
     }
244 244
     
245 245
     public function get_custom_singular_name() {
246
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
246
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
247 247
 
248
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
248
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
249 249
     }
250 250
     
251 251
     public function get_editable() {
252
-        $editable = get_post_meta( $this->ID, '_wpinv_editable', true );
252
+        $editable = get_post_meta($this->ID, '_wpinv_editable', true);
253 253
 
254
-        return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID );
254
+        return apply_filters('wpinv_item_get_editable', $editable, $this->ID);
255 255
     }
256 256
     
257 257
     public function get_excerpt() {
258
-        $excerpt = get_the_excerpt( $this->ID );
258
+        $excerpt = get_the_excerpt($this->ID);
259 259
         
260
-        return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID );
260
+        return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID);
261 261
     }
262 262
     
263 263
     public function get_is_recurring() {
264
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
264
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
265 265
 
266
-        return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID );
266
+        return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID);
267 267
 
268 268
     }
269 269
     
270
-    public function get_recurring_period( $full = false ) {
271
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
270
+    public function get_recurring_period($full = false) {
271
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
272 272
         
273
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
273
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
274 274
             $period = 'D';
275 275
         }
276 276
         
277
-        if ( $full ) {
278
-            switch( $period ) {
277
+        if ($full) {
278
+            switch ($period) {
279 279
                 case 'D':
280 280
                     $period = 'day';
281 281
                 break;
@@ -291,40 +291,40 @@  discard block
 block discarded – undo
291 291
             }
292 292
         }
293 293
 
294
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
294
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
295 295
     }
296 296
     
297 297
     public function get_recurring_interval() {
298
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
298
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
299 299
         
300
-        if ( !$interval > 0 ) {
300
+        if (!$interval > 0) {
301 301
             $interval = 1;
302 302
         }
303 303
 
304
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
304
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
305 305
     }
306 306
     
307 307
     public function get_recurring_limit() {
308
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
308
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
309 309
 
310
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
310
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
311 311
     }
312 312
     
313 313
     public function get_free_trial() {
314
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
314
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
315 315
 
316
-        return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID );
316
+        return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID);
317 317
     }
318 318
     
319
-    public function get_trial_period( $full = false ) {
320
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
319
+    public function get_trial_period($full = false) {
320
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
321 321
         
322
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
322
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
323 323
             $period = 'D';
324 324
         }
325 325
         
326
-        if ( $full ) {
327
-            switch( $period ) {
326
+        if ($full) {
327
+            switch ($period) {
328 328
                 case 'D':
329 329
                     $period = 'day';
330 330
                 break;
@@ -340,54 +340,54 @@  discard block
 block discarded – undo
340 340
             }
341 341
         }
342 342
 
343
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
343
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
344 344
     }
345 345
     
346 346
     public function get_trial_interval() {
347
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
347
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
348 348
         
349
-        if ( !$interval > 0 ) {
349
+        if (!$interval > 0) {
350 350
             $interval = 1;
351 351
         }
352 352
 
353
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
353
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
354 354
     }
355 355
     
356 356
     public function get_the_price() {
357
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
357
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
358 358
         
359
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
359
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
360 360
     }
361 361
     
362 362
     public function is_recurring() {
363 363
         $is_recurring = $this->get_is_recurring();
364 364
 
365
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
365
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
366 366
     }
367 367
     
368 368
     public function has_free_trial() {
369 369
         $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false;
370 370
 
371
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
371
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
372 372
     }
373 373
 
374 374
     public function is_free() {
375 375
         $is_free = false;
376 376
         
377
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
377
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
378 378
 
379
-        if ( (float)$price == 0 ) {
379
+        if ((float)$price == 0) {
380 380
             $is_free = true;
381 381
         }
382 382
 
383
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
383
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
384 384
 
385 385
     }
386 386
     
387 387
     public function is_package() {
388 388
         $is_package = $this->get_type() == 'package' ? true : false;
389 389
 
390
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
390
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
391 391
 
392 392
     }
393 393
     
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 
397 397
         $is_editable = $editable === 0 || $editable === '0' ? false : true;
398 398
 
399
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
399
+        return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
400 400
     }
401 401
     
402
-    public function save_metas( $metas = array() ) {
403
-        if ( empty( $metas ) ) {
402
+    public function save_metas($metas = array()) {
403
+        if (empty($metas)) {
404 404
             return false;
405 405
         }
406 406
         
407
-        foreach ( $metas as $meta_key => $meta_value ) {
407
+        foreach ($metas as $meta_key => $meta_value) {
408 408
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
409 409
             
410 410
             $this->update_meta($meta_key, $meta_value);
@@ -413,66 +413,66 @@  discard block
 block discarded – undo
413 413
         return true;
414 414
     }
415 415
 
416
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
417
-        if ( empty( $meta_key ) ) {
416
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
417
+        if (empty($meta_key)) {
418 418
             return false;
419 419
         }
420 420
         
421
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
421
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
422 422
 
423
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
423
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
424 424
     }
425 425
     
426
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
426
+    public function get_fees($type = 'fee', $item_id = 0) {
427 427
         global $wpi_session;
428 428
         
429
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
429
+        $fees = $wpi_session->get('wpi_cart_fees');
430 430
 
431
-        if ( ! wpinv_get_cart_contents() ) {
431
+        if (!wpinv_get_cart_contents()) {
432 432
             // We can only get item type fees when the cart is empty
433 433
             $type = 'custom';
434 434
         }
435 435
 
436
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
437
-            foreach( $fees as $key => $fee ) {
438
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
439
-                    unset( $fees[ $key ] );
436
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
437
+            foreach ($fees as $key => $fee) {
438
+                if (!empty($fee['type']) && $type != $fee['type']) {
439
+                    unset($fees[$key]);
440 440
                 }
441 441
             }
442 442
         }
443 443
 
444
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
444
+        if (!empty($fees) && !empty($item_id)) {
445 445
             // Remove fees that don't belong to the specified Item
446
-            foreach ( $fees as $key => $fee ) {
447
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
448
-                    unset( $fees[ $key ] );
446
+            foreach ($fees as $key => $fee) {
447
+                if ((int)$item_id !== (int)$fee['custom_id']) {
448
+                    unset($fees[$key]);
449 449
                 }
450 450
             }
451 451
         }
452 452
 
453
-        if ( ! empty( $fees ) ) {
453
+        if (!empty($fees)) {
454 454
             // Remove fees that belong to a specific item but are not in the cart
455
-            foreach( $fees as $key => $fee ) {
456
-                if( empty( $fee['custom_id'] ) ) {
455
+            foreach ($fees as $key => $fee) {
456
+                if (empty($fee['custom_id'])) {
457 457
                     continue;
458 458
                 }
459 459
 
460
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
461
-                    unset( $fees[ $key ] );
460
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
461
+                    unset($fees[$key]);
462 462
                 }
463 463
             }
464 464
         }
465 465
 
466
-        return ! empty( $fees ) ? $fees : array();
466
+        return !empty($fees) ? $fees : array();
467 467
     }
468 468
     
469 469
     public function can_purchase() {
470 470
         $can_purchase = true;
471 471
 
472
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
472
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
473 473
             $can_purchase = false;
474 474
         }
475 475
 
476
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
476
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
477 477
     }
478 478
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  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
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = new WPInv_Item( $value );
14
+            $item = new WPInv_Item($value);
15 15
 
16
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
16
+            if (!empty($item) && $item->post_type == 'wpi_item') {
17 17
                 return $item;
18 18
             }
19 19
             return false;
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 
23 23
         case 'slug':
24 24
         case 'name':
25
-            $posts = get_posts( array(
25
+            $posts = get_posts(array(
26 26
                 'post_type'      => 'wpi_item',
27 27
                 'name'           => $value,
28 28
                 'posts_per_page' => 1,
29 29
                 'post_status'    => 'any'
30
-            ) );
30
+            ));
31 31
 
32 32
             break;
33 33
         case 'custom_id':
34
-            if ( empty( $value ) || empty( $type ) ) {
34
+            if (empty($value) || empty($type)) {
35 35
                 return false;
36 36
             }
37 37
             
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
                 'post_status'    => 'any',
52 52
                 'orderby'        => 'ID',
53 53
                 'order'          => 'ASC',
54
-                'meta_query'     => array( $meta_query )
54
+                'meta_query'     => array($meta_query)
55 55
             );
56 56
             
57
-            $posts = get_posts( $args );
57
+            $posts = get_posts($args);
58 58
 
59 59
             break;
60 60
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
             return false;
63 63
     }
64 64
     
65
-    if ( !empty( $posts[0] ) ) {
66
-        $item = new WPInv_Item( $posts[0]->ID );
65
+    if (!empty($posts[0])) {
66
+        $item = new WPInv_Item($posts[0]->ID);
67 67
 
68
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
68
+        if (!empty($item) && $item->post_type == 'wpi_item') {
69 69
             return $item;
70 70
         }
71 71
     }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
     return false;
74 74
 }
75 75
 
76
-function wpinv_get_item( $item = 0 ) {
77
-    if ( is_numeric( $item ) ) {
78
-        $item = get_post( $item );
79
-        if ( ! $item || 'wpi_item' !== $item->post_type )
76
+function wpinv_get_item($item = 0) {
77
+    if (is_numeric($item)) {
78
+        $item = get_post($item);
79
+        if (!$item || 'wpi_item' !== $item->post_type)
80 80
             return null;
81 81
         return $item;
82 82
     }
@@ -89,150 +89,150 @@  discard block
 block discarded – undo
89 89
 
90 90
     $item = get_posts($args);
91 91
 
92
-    if ( $item ) {
92
+    if ($item) {
93 93
         return $item[0];
94 94
     }
95 95
 
96 96
     return null;
97 97
 }
98 98
 
99
-function wpinv_is_free_item( $item_id = 0 ) {
100
-    if( empty( $item_id ) ) {
99
+function wpinv_is_free_item($item_id = 0) {
100
+    if (empty($item_id)) {
101 101
         return false;
102 102
     }
103 103
 
104
-    $item = new WPInv_Item( $item_id );
104
+    $item = new WPInv_Item($item_id);
105 105
     
106 106
     return $item->is_free();
107 107
 }
108 108
 
109
-function wpinv_item_is_editable( $item = 0 ) {
110
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
109
+function wpinv_item_is_editable($item = 0) {
110
+    if (!empty($item) && is_a($item, 'WP_Post')) {
111 111
         $item = $item->ID;
112 112
     }
113 113
         
114
-    if ( empty( $item ) ) {
114
+    if (empty($item)) {
115 115
         return true;
116 116
     }
117 117
 
118
-    $item = new WPInv_Item( $item );
118
+    $item = new WPInv_Item($item);
119 119
     
120
-    return (bool) $item->is_editable();
120
+    return (bool)$item->is_editable();
121 121
 }
122 122
 
123
-function wpinv_get_item_price( $item_id = 0 ) {
124
-    if( empty( $item_id ) ) {
123
+function wpinv_get_item_price($item_id = 0) {
124
+    if (empty($item_id)) {
125 125
         return false;
126 126
     }
127 127
 
128
-    $item = new WPInv_Item( $item_id );
128
+    $item = new WPInv_Item($item_id);
129 129
     
130 130
     return $item->get_price();
131 131
 }
132 132
 
133
-function wpinv_is_recurring_item( $item_id = 0 ) {
134
-    if( empty( $item_id ) ) {
133
+function wpinv_is_recurring_item($item_id = 0) {
134
+    if (empty($item_id)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $item = new WPInv_Item( $item_id );
138
+    $item = new WPInv_Item($item_id);
139 139
     
140 140
     return $item->is_recurring();
141 141
 }
142 142
 
143
-function wpinv_item_price( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_item_price($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $price = wpinv_get_item_price( $item_id );
149
-    $price = wpinv_price( wpinv_format_amount( $price ) );
148
+    $price = wpinv_get_item_price($item_id);
149
+    $price = wpinv_price(wpinv_format_amount($price));
150 150
     
151
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
151
+    return apply_filters('wpinv_item_price', $price, $item_id);
152 152
 }
153 153
 
154
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_item_show_price($item_id = 0, $echo = true) {
155
+    if (empty($item_id)) {
156 156
         $item_id = get_the_ID();
157 157
     }
158 158
 
159
-    $price = wpinv_item_price( $item_id );
159
+    $price = wpinv_item_price($item_id);
160 160
 
161
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
161
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
162 162
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
163
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
163
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
164 164
 
165
-    if ( $echo ) {
165
+    if ($echo) {
166 166
         echo $formatted_price;
167 167
     } else {
168 168
         return $formatted_price;
169 169
     }
170 170
 }
171 171
 
172
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
173
-    if ( is_null( $amount_override ) ) {
174
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
172
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
173
+    if (is_null($amount_override)) {
174
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
175 175
     } else {
176 176
         $original_price = $amount_override;
177 177
     }
178 178
     
179 179
     $price = $original_price;
180 180
 
181
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
181
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_custom_singular_name( $item_id ) {
185
-    if( empty( $item_id ) ) {
184
+function wpinv_item_custom_singular_name($item_id) {
185
+    if (empty($item_id)) {
186 186
         return false;
187 187
     }
188 188
 
189
-    $item = new WPInv_Item( $item_id );
189
+    $item = new WPInv_Item($item_id);
190 190
     
191 191
     return $item->get_custom_singular_name();
192 192
 }
193 193
 
194 194
 function wpinv_get_item_types() {
195 195
     $item_types = array(
196
-            'custom'    => __( 'Standard', 'invoicing' ),
197
-            'fee'       => __( 'Fee', 'invoicing' ),
196
+            'custom'    => __('Standard', 'invoicing'),
197
+            'fee'       => __('Fee', 'invoicing'),
198 198
         );
199
-    return apply_filters( 'wpinv_get_item_types', $item_types );
199
+    return apply_filters('wpinv_get_item_types', $item_types);
200 200
 }
201 201
 
202 202
 function wpinv_item_types() {
203 203
     $item_types = wpinv_get_item_types();
204 204
     
205
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
205
+    return (!empty($item_types) ? array_keys($item_types) : array());
206 206
 }
207 207
 
208
-function wpinv_get_item_type( $item_id ) {
209
-    if( empty( $item_id ) ) {
208
+function wpinv_get_item_type($item_id) {
209
+    if (empty($item_id)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    $item = new WPInv_Item( $item_id );
213
+    $item = new WPInv_Item($item_id);
214 214
     
215 215
     return $item->get_type();
216 216
 }
217 217
 
218
-function wpinv_item_type( $item_id ) {
218
+function wpinv_item_type($item_id) {
219 219
     $item_types = wpinv_get_item_types();
220 220
     
221
-    $item_type = wpinv_get_item_type( $item_id );
221
+    $item_type = wpinv_get_item_type($item_id);
222 222
     
223
-    if ( empty( $item_type ) ) {
223
+    if (empty($item_type)) {
224 224
         $item_type = '-';
225 225
     }
226 226
     
227
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
227
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
228 228
 
229
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
229
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
230 230
 }
231 231
 
232
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
232
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
233 233
     global $wpinv_logs;
234 234
     
235
-    if ( empty( $wpinv_logs ) ) {
235
+    if (empty($wpinv_logs)) {
236 236
         return false;
237 237
     }
238 238
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         'log_type'		=> 'wpi_item'
242 242
     );
243 243
 
244
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
244
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
245 245
 
246 246
     $log_meta = array(
247 247
         'user_info'	=> $user_info,
@@ -251,253 +251,253 @@  discard block
 block discarded – undo
251 251
         'invoice_id'=> $invoice_id,
252 252
     );
253 253
 
254
-    $wpinv_logs->insert_log( $log_data, $log_meta );
254
+    $wpinv_logs->insert_log($log_data, $log_meta);
255 255
 }
256 256
 
257
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
258
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
257
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
258
+    if ('wpi_item' !== get_post_type($item_id))
259 259
         return;
260 260
 
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
267 267
     // Remove all log entries related to this item
268
-    $wpinv_logs->delete_logs( $item_id );
268
+    $wpinv_logs->delete_logs($item_id);
269 269
 }
270
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
270
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
271 271
 
272
-function wpinv_get_random_item( $post_ids = true ) {
273
-    wpinv_get_random_items( 1, $post_ids );
272
+function wpinv_get_random_item($post_ids = true) {
273
+    wpinv_get_random_items(1, $post_ids);
274 274
 }
275 275
 
276
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
277
-    if ( $post_ids ) {
278
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
276
+function wpinv_get_random_items($num = 3, $post_ids = true) {
277
+    if ($post_ids) {
278
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
279 279
     } else {
280
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
280
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
281 281
     }
282 282
     
283
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
283
+    $args = apply_filters('wpinv_get_random_items', $args);
284 284
     
285
-    return get_posts( $args );
285
+    return get_posts($args);
286 286
 }
287 287
 
288
-function wpinv_get_item_token( $url = '' ) {
288
+function wpinv_get_item_token($url = '') {
289 289
     $args    = array();
290
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
291
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
290
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
291
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
292 292
 
293
-    $parts   = parse_url( $url );
293
+    $parts   = parse_url($url);
294 294
     $options = array();
295 295
 
296
-    if ( isset( $parts['query'] ) ) {
297
-        wp_parse_str( $parts['query'], $query_args );
296
+    if (isset($parts['query'])) {
297
+        wp_parse_str($parts['query'], $query_args);
298 298
 
299
-        if ( ! empty( $query_args['o'] ) ) {
300
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
299
+        if (!empty($query_args['o'])) {
300
+            $options = explode(':', rawurldecode($query_args['o']));
301 301
 
302
-            if ( in_array( 'ip', $options ) ) {
302
+            if (in_array('ip', $options)) {
303 303
                 $args['ip'] = wpinv_get_ip();
304 304
             }
305 305
 
306
-            if ( in_array( 'ua', $options ) ) {
306
+            if (in_array('ua', $options)) {
307 307
                 $ua = wpinv_get_user_agent();
308
-                $args['user_agent'] = rawurlencode( $ua );
308
+                $args['user_agent'] = rawurlencode($ua);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
313
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
314 314
 
315 315
     $args['secret'] = $secret;
316 316
     $args['token']  = false;
317 317
 
318
-    $url   = add_query_arg( $args, $url );
319
-    $parts = parse_url( $url );
318
+    $url   = add_query_arg($args, $url);
319
+    $parts = parse_url($url);
320 320
 
321
-    if ( ! isset( $parts['path'] ) ) {
321
+    if (!isset($parts['path'])) {
322 322
         $parts['path'] = '';
323 323
     }
324 324
 
325
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
325
+    $token = md5($parts['path'] . '?' . $parts['query']);
326 326
 
327 327
     return $token;
328 328
 }
329 329
 
330
-function wpinv_validate_url_token( $url = '' ) {
330
+function wpinv_validate_url_token($url = '') {
331 331
     $ret   = false;
332
-    $parts = parse_url( $url );
332
+    $parts = parse_url($url);
333 333
 
334
-    if ( isset( $parts['query'] ) ) {
335
-        wp_parse_str( $parts['query'], $query_args );
334
+    if (isset($parts['query'])) {
335
+        wp_parse_str($parts['query'], $query_args);
336 336
 
337
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
337
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
338 338
             'item',
339 339
             'ttl',
340 340
             'token'
341
-        ) );
341
+        ));
342 342
 
343 343
         $remove = array();
344 344
 
345
-        foreach( $query_args as $key => $value ) {
346
-            if( false === in_array( $key, $allowed ) ) {
345
+        foreach ($query_args as $key => $value) {
346
+            if (false === in_array($key, $allowed)) {
347 347
                 $remove[] = $key;
348 348
             }
349 349
         }
350 350
 
351
-        if( ! empty( $remove ) ) {
352
-            $url = remove_query_arg( $remove, $url );
351
+        if (!empty($remove)) {
352
+            $url = remove_query_arg($remove, $url);
353 353
         }
354 354
 
355
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
356
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
355
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
356
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
357 357
         }
358 358
 
359
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
359
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
360 360
             $ret = true;
361 361
         }
362 362
 
363 363
     }
364 364
 
365
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
365
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
366 366
 }
367 367
 
368
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
368
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
369 369
     $cart_items = wpinv_get_cart_contents();
370 370
 
371 371
     $ret = false;
372 372
 
373
-    if ( is_array( $cart_items ) ) {
374
-        foreach ( $cart_items as $item ) {
375
-            if ( $item['id'] == $item_id ) {
373
+    if (is_array($cart_items)) {
374
+        foreach ($cart_items as $item) {
375
+            if ($item['id'] == $item_id) {
376 376
                 $ret = true;
377 377
                 break;
378 378
             }
379 379
         }
380 380
     }
381 381
 
382
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
382
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
383 383
 }
384 384
 
385
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
385
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
386 386
     $tax = 0;
387
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
388
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
389
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
387
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
388
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
389
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
390 390
 
391
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
391
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
392 392
     }
393 393
 
394
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
394
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
395 395
 }
396 396
 
397
-function wpinv_cart_item_price( $item ) {
397
+function wpinv_cart_item_price($item) {
398 398
     $use_taxes  = wpinv_use_taxes();
399
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
400
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
401
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
402
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
403
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
404
-    
405
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
406
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
399
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
400
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
401
+    $options    = isset($item['options']) ? $item['options'] : array();
402
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
403
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
404
+    
405
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
406
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
407 407
             $price += $tax;
408 408
         }
409 409
         
410
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
410
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
411 411
             $price -= $tax;
412 412
         }        
413 413
     }
414 414
 
415
-    $price = wpinv_price( wpinv_format_amount( $price ) );
415
+    $price = wpinv_price(wpinv_format_amount($price));
416 416
 
417
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
417
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
418 418
 }
419 419
 
420
-function wpinv_cart_item_subtotal( $item ) {
421
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
422
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
420
+function wpinv_cart_item_subtotal($item) {
421
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
422
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
423 423
 
424
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
424
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
425 425
 }
426 426
 
427
-function wpinv_cart_item_tax( $item ) {
427
+function wpinv_cart_item_tax($item) {
428 428
     $tax        = '';
429 429
     $tax_rate   = '';
430 430
     
431
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
432
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
433
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
434
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
431
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
432
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
433
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
434
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
435 435
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
436 436
     }
437 437
     
438
-    $tax        = $tax . $tax_rate;
438
+    $tax = $tax . $tax_rate;
439 439
     
440
-    if ( $tax === '' ) {
440
+    if ($tax === '') {
441 441
         $tax = 0; // Zero tax
442 442
     }
443 443
 
444
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
444
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
445 445
 }
446 446
 
447
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
447
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
448 448
     $price = 0;
449 449
     
450 450
     // Set custom price
451
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
451
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
452 452
         $price = $cart_item['custom_price'];
453 453
     } else {
454
-        $variable_prices = wpinv_has_variable_prices( $item_id );
454
+        $variable_prices = wpinv_has_variable_prices($item_id);
455 455
 
456
-        if ( $variable_prices ) {
457
-            $prices = wpinv_get_variable_prices( $item_id );
456
+        if ($variable_prices) {
457
+            $prices = wpinv_get_variable_prices($item_id);
458 458
 
459
-            if ( $prices ) {
460
-                if( ! empty( $options ) ) {
461
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
459
+            if ($prices) {
460
+                if (!empty($options)) {
461
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
462 462
                 } else {
463 463
                     $price = false;
464 464
                 }
465 465
             }
466 466
         }
467 467
 
468
-        if( ! $variable_prices || false === $price ) {
468
+        if (!$variable_prices || false === $price) {
469 469
             // Get the standard Item price if not using variable prices
470
-            $price = wpinv_get_item_price( $item_id );
470
+            $price = wpinv_get_item_price($item_id);
471 471
         }
472 472
     }
473 473
 
474
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
475
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
474
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
475
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
476 476
     }
477 477
 
478
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
478
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
479 479
 }
480 480
 
481
-function wpinv_get_cart_item_price_id( $item = array() ) {
482
-    if( isset( $item['item_number'] ) ) {
483
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
481
+function wpinv_get_cart_item_price_id($item = array()) {
482
+    if (isset($item['item_number'])) {
483
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
484 484
     } else {
485
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
485
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
486 486
     }
487 487
     return $price_id;
488 488
 }
489 489
 
490
-function wpinv_get_cart_item_price_name( $item = array() ) {
491
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
492
-    $prices   = wpinv_get_variable_prices( $item['id'] );
493
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
494
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
490
+function wpinv_get_cart_item_price_name($item = array()) {
491
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
492
+    $prices   = wpinv_get_variable_prices($item['id']);
493
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
494
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
495 495
 }
496 496
 
497
-function wpinv_get_cart_item_name( $item = array() ) {
498
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
497
+function wpinv_get_cart_item_name($item = array()) {
498
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
499 499
 
500
-    if ( empty( $item_title ) ) {
500
+    if (empty($item_title)) {
501 501
         $item_title = $item['id'];
502 502
     }
503 503
 
@@ -507,23 +507,23 @@  discard block
 block discarded – undo
507 507
     }
508 508
     */
509 509
 
510
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
510
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
511 511
 }
512 512
 
513
-function wpinv_has_variable_prices( $item_id = 0 ) {
513
+function wpinv_has_variable_prices($item_id = 0) {
514 514
     return false;
515 515
 }
516 516
 
517
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
517
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
518 518
     $cart_items = wpinv_get_cart_contents();
519 519
 
520
-    if ( !is_array( $cart_items ) ) {
520
+    if (!is_array($cart_items)) {
521 521
         return false; // Empty cart
522 522
     } else {
523
-        foreach ( $cart_items as $position => $item ) {
524
-            if ( $item['id'] == $item_id ) {
525
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
526
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
523
+        foreach ($cart_items as $position => $item) {
524
+            if ($item['id'] == $item_id) {
525
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
526
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
527 527
                         return $position;
528 528
                     }
529 529
                 } else {
@@ -536,80 +536,80 @@  discard block
 block discarded – undo
536 536
     return false; // Not found
537 537
 }
538 538
 
539
-function wpinv_get_cart_item_quantity( $item ) {
540
-    if ( wpinv_item_quantities_enabled() ) {
541
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
539
+function wpinv_get_cart_item_quantity($item) {
540
+    if (wpinv_item_quantities_enabled()) {
541
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
542 542
     } else {
543 543
         $quantity = 1;
544 544
     }
545 545
     
546
-    if ( $quantity < 1 ) {
546
+    if ($quantity < 1) {
547 547
         $quantity = 1;
548 548
     }
549 549
     
550
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
550
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
551 551
 }
552 552
 
553
-function wpinv_get_item_suffix( $item, $html = true ) {
554
-    if ( empty( $item ) ) {
553
+function wpinv_get_item_suffix($item, $html = true) {
554
+    if (empty($item)) {
555 555
         return NULL;
556 556
     }
557 557
     
558
-    if ( is_int( $item ) ) {
559
-        $item = new WPInv_Item( $item );
558
+    if (is_int($item)) {
559
+        $item = new WPInv_Item($item);
560 560
     }
561 561
     
562
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
562
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
563 563
         return NULL;
564 564
     }
565 565
     
566
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
566
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
567 567
     
568
-    if ( !$html && $suffix ) {
569
-        $suffix = strip_tags( $suffix );
568
+    if (!$html && $suffix) {
569
+        $suffix = strip_tags($suffix);
570 570
     }
571 571
     
572
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
572
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
573 573
 }
574 574
 
575
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
576
-    if ( empty( $item ) ) {
575
+function wpinv_remove_item($item = 0, $force_delete = false) {
576
+    if (empty($item)) {
577 577
         return NULL;
578 578
     }
579 579
     
580
-    if ( is_int( $item ) ) {
581
-        $item = new WPInv_Item( $item );
580
+    if (is_int($item)) {
581
+        $item = new WPInv_Item($item);
582 582
     }
583 583
     
584
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
584
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
585 585
         return NULL;
586 586
     }
587 587
     
588
-    do_action( 'wpinv_pre_delete_item', $item );
588
+    do_action('wpinv_pre_delete_item', $item);
589 589
 
590
-    wp_delete_post( $item->ID, $force_delete );
590
+    wp_delete_post($item->ID, $force_delete);
591 591
 
592
-    do_action( 'wpinv_post_delete_item', $item );
592
+    do_action('wpinv_post_delete_item', $item);
593 593
 }
594 594
 
595
-function wpinv_can_delete_item( $post_id ) {
596
-    $return = current_user_can( 'manage_options' ) ? true : false;
595
+function wpinv_can_delete_item($post_id) {
596
+    $return = current_user_can('manage_options') ? true : false;
597 597
     
598
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
598
+    if ($return && wpinv_item_in_use($post_id)) {
599 599
         $return = false; // Don't delete item already use in invoices.
600 600
     }
601 601
     
602
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
602
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
603 603
 }
604 604
 
605 605
 function wpinv_admin_action_delete() {
606 606
     $screen = get_current_screen();
607 607
     
608
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
608
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
609 609
         $post_ids = array();
610 610
         
611
-        foreach ( $_REQUEST['post'] as $post_id ) {
612
-            if ( !wpinv_can_delete_item( $post_id ) ) {
611
+        foreach ($_REQUEST['post'] as $post_id) {
612
+            if (!wpinv_can_delete_item($post_id)) {
613 613
                 continue;
614 614
             }
615 615
             
@@ -619,86 +619,86 @@  discard block
 block discarded – undo
619 619
         $_REQUEST['post'] = $post_ids;
620 620
     }
621 621
 }
622
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
623
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
622
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
623
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
624 624
 
625
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
626
-    if ( $post->post_type == 'wpi_item' ) {
627
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
625
+function wpinv_check_delete_item($check, $post, $force_delete) {
626
+    if ($post->post_type == 'wpi_item') {
627
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
628 628
             return true;
629 629
         }
630 630
     }
631 631
     
632 632
     return $check;
633 633
 }
634
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
634
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
635 635
 
636
-function wpinv_item_in_use( $item_id ) {
636
+function wpinv_item_in_use($item_id) {
637 637
     global $wpdb, $wpi_items_in_use;
638 638
     
639
-    if ( !$item_id > 0 ) {
639
+    if (!$item_id > 0) {
640 640
         return false;
641 641
     }
642 642
     
643
-    if ( !empty( $wpi_items_in_use ) ) {
644
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
643
+    if (!empty($wpi_items_in_use)) {
644
+        if (isset($wpi_items_in_use[$item_id])) {
645 645
             return $wpi_items_in_use[$item_id];
646 646
         }
647 647
     } else {
648 648
         $wpi_items_in_use = array();
649 649
     }
650 650
     
651
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
651
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
652 652
     
653
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
653
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
655 655
     
656 656
     $wpi_items_in_use[$item_id] = $in_use;
657 657
     
658 658
     return $in_use;
659 659
 }
660 660
 
661
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
661
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
662 662
     // Set some defaults
663 663
     $defaults = array(
664
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
665
-        'title'                => '',                                                      // Required. Item title.
666
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
667
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
668
-        'status'               => 'pending',                                               // Optional. pending, publish
669
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
670
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
671
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
672
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
673
-        'excerpt'              => '',                                                      // Optional. Item short description
664
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
665
+        'title'                => '', // Required. Item title.
666
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
667
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
668
+        'status'               => 'pending', // Optional. pending, publish
669
+        'custom_name'          => '', // Optional. Plural sub title for item.
670
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
671
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
672
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
673
+        'excerpt'              => '', // Optional. Item short description
674 674
         /* Recurring item fields */
675
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
678
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
679
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
680
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
675
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
678
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
679
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
680
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
+        'trial_interval'       => 0, // Optional. Any integer number.
682 682
     );
683 683
 
684
-    $data = wp_parse_args( $args, $defaults );
684
+    $data = wp_parse_args($args, $defaults);
685 685
 
686
-    if ( empty( $data['type'] ) ) {
686
+    if (empty($data['type'])) {
687 687
         $data['type'] = 'custom';
688 688
     }
689 689
 
690
-    if ( !empty( $data['custom_id'] ) ) {
691
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
690
+    if (!empty($data['custom_id'])) {
691
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
692 692
     } else {
693 693
         $item = NULL;
694 694
     }
695 695
 
696
-    if ( !empty( $item ) ) {
697
-        if ( $force_update ) {
698
-            if ( empty( $args['ID'] ) ) {
696
+    if (!empty($item)) {
697
+        if ($force_update) {
698
+            if (empty($args['ID'])) {
699 699
                 $args['ID'] = $item->ID;
700 700
             }
701
-            return wpinv_update_item( $args, $wp_error );
701
+            return wpinv_update_item($args, $wp_error);
702 702
         }
703 703
 
704 704
         return $item;
@@ -709,19 +709,19 @@  discard block
 block discarded – undo
709 709
     $meta['custom_id']              = $data['custom_id'];
710 710
     $meta['custom_singular_name']   = $data['custom_singular_name'];
711 711
     $meta['custom_name']            = $data['custom_name'];
712
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
712
+    $meta['price']                  = wpinv_round_amount($data['price']);
713 713
     $meta['editable']               = (int)$data['editable'];
714 714
     $meta['vat_rule']               = $data['vat_rule'];
715 715
     $meta['vat_class']              = '_standard';
716 716
     
717
-    if ( !empty( $data['is_recurring'] ) ) {
717
+    if (!empty($data['is_recurring'])) {
718 718
         $meta['is_recurring']       = $data['is_recurring'];
719 719
         $meta['recurring_period']   = $data['recurring_period'];
720
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
721
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
720
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
721
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
722 722
         $meta['free_trial']         = $data['free_trial'];
723 723
         $meta['trial_period']       = $data['trial_period'];
724
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
724
+        $meta['trial_interval']     = absint($data['trial_interval']);
725 725
     } else {
726 726
         $meta['is_recurring']       = 0;
727 727
         $meta['recurring_period']   = '';
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         $meta['trial_interval']     = '';
733 733
     }
734 734
     
735
-    $post_data  = array( 
735
+    $post_data = array( 
736 736
         'post_title'    => $data['title'],
737 737
         'post_excerpt'  => $data['excerpt'],
738 738
         'post_status'   => $data['status'],
@@ -740,86 +740,86 @@  discard block
 block discarded – undo
740 740
     );
741 741
 
742 742
     $item = new WPInv_Item();
743
-    $return = $item->create( $post_data, $wp_error );
743
+    $return = $item->create($post_data, $wp_error);
744 744
 
745
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
745
+    if ($return && !empty($item) && !is_wp_error($return)) {
746 746
         return $item;
747 747
     }
748 748
 
749
-    if ( $wp_error && is_wp_error( $return ) ) {
749
+    if ($wp_error && is_wp_error($return)) {
750 750
         return $return;
751 751
     }
752 752
     return 0;
753 753
 }
754 754
 
755
-function wpinv_update_item( $args = array(), $wp_error = false ) {
756
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
755
+function wpinv_update_item($args = array(), $wp_error = false) {
756
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
757 757
 
758
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
759
-        if ( $wp_error ) {
760
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
758
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
759
+        if ($wp_error) {
760
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
761 761
         }
762 762
         return 0;
763 763
     }
764 764
     
765
-    if ( !empty( $args['custom_id'] ) ) {
766
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
765
+    if (!empty($args['custom_id'])) {
766
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
767 767
         
768
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
769
-            if ( $wp_error ) {
770
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
768
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
769
+            if ($wp_error) {
770
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
771 771
             }
772 772
             return 0;
773 773
         }
774 774
     }
775 775
 
776
-    $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' );
776
+    $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval');
777 777
 
778 778
     $post_data = array();
779
-    if ( isset( $args['title'] ) ) { 
779
+    if (isset($args['title'])) { 
780 780
         $post_data['post_title'] = $args['title'];
781 781
     }
782
-    if ( isset( $args['excerpt'] ) ) { 
782
+    if (isset($args['excerpt'])) { 
783 783
         $post_data['post_excerpt'] = $args['excerpt'];
784 784
     }
785
-    if ( isset( $args['status'] ) ) { 
785
+    if (isset($args['status'])) { 
786 786
         $post_data['post_status'] = $args['status'];
787 787
     }
788 788
     
789
-    foreach ( $meta_fields as $meta_field ) {
790
-        if ( isset( $args[ $meta_field ] ) ) { 
791
-            $value = $args[ $meta_field ];
789
+    foreach ($meta_fields as $meta_field) {
790
+        if (isset($args[$meta_field])) { 
791
+            $value = $args[$meta_field];
792 792
 
793
-            switch ( $meta_field ) {
793
+            switch ($meta_field) {
794 794
                 case 'price':
795
-                    $value = wpinv_round_amount( $value );
795
+                    $value = wpinv_round_amount($value);
796 796
                 break;
797 797
                 case 'recurring_interval':
798 798
                 case 'recurring_limit':
799 799
                 case 'trial_interval':
800
-                    $value = absint( $value );
800
+                    $value = absint($value);
801 801
                 break;
802 802
             }
803 803
 
804
-            $post_data['meta'][ $meta_field ] = $value;
804
+            $post_data['meta'][$meta_field] = $value;
805 805
         };
806 806
     }
807 807
 
808
-    if ( empty( $post_data ) ) {
809
-        if ( $wp_error ) {
810
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
808
+    if (empty($post_data)) {
809
+        if ($wp_error) {
810
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
811 811
         }
812 812
         return 0;
813 813
     }
814 814
     $post_data['ID'] = $args['ID'];
815 815
 
816
-    $return = $item->update( $post_data, $wp_error );
816
+    $return = $item->update($post_data, $wp_error);
817 817
 
818
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
818
+    if ($return && !empty($item) && !is_wp_error($return)) {
819 819
         return $item;
820 820
     }
821 821
 
822
-    if ( $wp_error && is_wp_error( $return ) ) {
822
+    if ($wp_error && is_wp_error($return)) {
823 823
         return $return;
824 824
     }
825 825
     return 0;
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58
-    if($invoice->post_type == 'wpi_invoice'){
58
+    if ($invoice->post_type == 'wpi_invoice') {
59 59
     
60 60
         $user_id = (int)$invoice->get_user_id();
61 61
         $current_user_id = (int)get_current_user_id();
62 62
 
63
-        if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
63
+        if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
64 64
             ?> 
65
-            <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a>
65
+            <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a>
66 66
             <?php
67 67
         }
68 68
     }
69 69
     do_action('wpinv_invoice_display_left_actions', $invoice);
70 70
 }
71 71
 
72
-function wpinv_invoice_display_right_actions( $invoice ) {
73
-    if ( empty( $invoice ) ) return; //Exit if invoice is not set.
72
+function wpinv_invoice_display_right_actions($invoice) {
73
+    if (empty($invoice)) return; //Exit if invoice is not set.
74 74
     
75
-    if($invoice->post_type == 'wpi_invoice'){
75
+    if ($invoice->post_type == 'wpi_invoice') {
76 76
         $user_id = (int)$invoice->get_user_id();
77 77
         $current_user_id = (int)get_current_user_id();
78 78
 
79
-        if ( $user_id > 0 && $user_id == $current_user_id ) {
79
+        if ($user_id > 0 && $user_id == $current_user_id) {
80 80
         ?>
81
-            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> &nbsp;
82
-            <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
81
+            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> &nbsp;
82
+            <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
83 83
         <?php } 
84 84
     }
85 85
     do_action('wpinv_invoice_display_right_actions', $invoice);
86 86
 }
87 87
 
88
-function wpinv_before_invoice_content( $content ) {
88
+function wpinv_before_invoice_content($content) {
89 89
     global $post;
90 90
 
91
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
91
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
92 92
         ob_start();
93
-        do_action( 'wpinv_before_invoice_content', $post->ID );
93
+        do_action('wpinv_before_invoice_content', $post->ID);
94 94
         $content = ob_get_clean() . $content;
95 95
     }
96 96
 
97 97
     return $content;
98 98
 }
99
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
99
+add_filter('the_content', 'wpinv_before_invoice_content');
100 100
 
101
-function wpinv_after_invoice_content( $content ) {
101
+function wpinv_after_invoice_content($content) {
102 102
     global $post;
103 103
 
104
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
104
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
105 105
         ob_start();
106
-        do_action( 'wpinv_after_invoice_content', $post->ID );
106
+        do_action('wpinv_after_invoice_content', $post->ID);
107 107
         $content .= ob_get_clean();
108 108
     }
109 109
 
110 110
     return $content;
111 111
 }
112
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
112
+add_filter('the_content', 'wpinv_after_invoice_content');
113 113
 
114 114
 function wpinv_get_templates_dir() {
115 115
     return WPINV_PLUGIN_DIR . 'templates';
@@ -119,105 +119,105 @@  discard block
 block discarded – undo
119 119
     return WPINV_PLUGIN_URL . 'templates';
120 120
 }
121 121
 
122
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
123
-    if ( ! empty( $args ) && is_array( $args ) ) {
124
-		extract( $args );
122
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
123
+    if (!empty($args) && is_array($args)) {
124
+		extract($args);
125 125
 	}
126 126
 
127
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
127
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
128 128
 	// Allow 3rd party plugin filter template file from their plugin.
129
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
129
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
130 130
 
131
-	if ( ! file_exists( $located ) ) {
132
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
131
+	if (!file_exists($located)) {
132
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
133 133
 		return;
134 134
 	}
135 135
 
136
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
137 137
 
138
-	include( $located );
138
+	include($located);
139 139
 
140
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
140
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
141 141
 }
142 142
 
143
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
144 144
 	ob_start();
145
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
145
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
146 146
 	return ob_get_clean();
147 147
 }
148 148
 
149
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
150
-    if ( ! $template_path ) {
149
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
150
+    if (!$template_path) {
151 151
         $template_path = wpinv_template_path();
152 152
     }
153 153
 
154
-    if ( ! $default_path ) {
154
+    if (!$default_path) {
155 155
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
156 156
     }
157 157
 
158 158
     // Look within passed path within the theme - this is priority.
159 159
     $template = locate_template(
160 160
         array(
161
-            trailingslashit( $template_path ) . $template_name,
161
+            trailingslashit($template_path) . $template_name,
162 162
             $template_name
163 163
         )
164 164
     );
165 165
 
166 166
     // Get default templates/
167
-    if ( !$template && $default_path ) {
168
-        $template = trailingslashit( $default_path ) . $template_name;
167
+    if (!$template && $default_path) {
168
+        $template = trailingslashit($default_path) . $template_name;
169 169
     }
170 170
 
171 171
     // Return what we found.
172
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
172
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
173 173
 }
174 174
 
175
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
176
-	do_action( 'get_template_part_' . $slug, $slug, $name );
175
+function wpinv_get_template_part($slug, $name = null, $load = true) {
176
+	do_action('get_template_part_' . $slug, $slug, $name);
177 177
 
178 178
 	// Setup possible parts
179 179
 	$templates = array();
180
-	if ( isset( $name ) )
180
+	if (isset($name))
181 181
 		$templates[] = $slug . '-' . $name . '.php';
182 182
 	$templates[] = $slug . '.php';
183 183
 
184 184
 	// Allow template parts to be filtered
185
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
185
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
186 186
 
187 187
 	// Return the part that is found
188
-	return wpinv_locate_tmpl( $templates, $load, false );
188
+	return wpinv_locate_tmpl($templates, $load, false);
189 189
 }
190 190
 
191
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
191
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
192 192
 	// No file found yet
193 193
 	$located = false;
194 194
 
195 195
 	// Try to find a template file
196
-	foreach ( (array)$template_names as $template_name ) {
196
+	foreach ((array)$template_names as $template_name) {
197 197
 
198 198
 		// Continue if template is empty
199
-		if ( empty( $template_name ) )
199
+		if (empty($template_name))
200 200
 			continue;
201 201
 
202 202
 		// Trim off any slashes from the template name
203
-		$template_name = ltrim( $template_name, '/' );
203
+		$template_name = ltrim($template_name, '/');
204 204
 
205 205
 		// try locating this template file by looping through the template paths
206
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
206
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
207 207
 
208
-			if( file_exists( $template_path . $template_name ) ) {
208
+			if (file_exists($template_path . $template_name)) {
209 209
 				$located = $template_path . $template_name;
210 210
 				break;
211 211
 			}
212 212
 		}
213 213
 
214
-		if( !empty( $located ) ) {
214
+		if (!empty($located)) {
215 215
 			break;
216 216
 		}
217 217
 	}
218 218
 
219
-	if ( ( true == $load ) && ! empty( $located ) )
220
-		load_template( $located, $require_once );
219
+	if ((true == $load) && !empty($located))
220
+		load_template($located, $require_once);
221 221
 
222 222
 	return $located;
223 223
 }
@@ -226,143 +226,143 @@  discard block
 block discarded – undo
226 226
 	$template_dir = wpinv_get_theme_template_dir_name();
227 227
 
228 228
 	$file_paths = array(
229
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
230
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
229
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
230
+		10 => trailingslashit(get_template_directory()) . $template_dir,
231 231
 		100 => wpinv_get_templates_dir()
232 232
 	);
233 233
 
234
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
234
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
235 235
 
236 236
 	// sort the file paths based on priority
237
-	ksort( $file_paths, SORT_NUMERIC );
237
+	ksort($file_paths, SORT_NUMERIC);
238 238
 
239
-	return array_map( 'trailingslashit', $file_paths );
239
+	return array_map('trailingslashit', $file_paths);
240 240
 }
241 241
 
242 242
 function wpinv_get_theme_template_dir_name() {
243
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
243
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
244 244
 }
245 245
 
246 246
 function wpinv_checkout_meta_tags() {
247 247
 
248 248
 	$pages   = array();
249
-	$pages[] = wpinv_get_option( 'success_page' );
250
-	$pages[] = wpinv_get_option( 'failure_page' );
251
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
249
+	$pages[] = wpinv_get_option('success_page');
250
+	$pages[] = wpinv_get_option('failure_page');
251
+	$pages[] = wpinv_get_option('invoice_history_page');
252 252
 
253
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+	if (!wpinv_is_checkout() && !is_page($pages)) {
254 254
 		return;
255 255
 	}
256 256
 
257 257
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
258 258
 }
259
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259
+add_action('wp_head', 'wpinv_checkout_meta_tags');
260 260
 
261
-function wpinv_add_body_classes( $class ) {
261
+function wpinv_add_body_classes($class) {
262 262
 	$classes = (array)$class;
263 263
 
264
-	if( wpinv_is_checkout() ) {
264
+	if (wpinv_is_checkout()) {
265 265
 		$classes[] = 'wpinv-checkout';
266 266
 		$classes[] = 'wpinv-page';
267 267
 	}
268 268
 
269
-	if( wpinv_is_success_page() ) {
269
+	if (wpinv_is_success_page()) {
270 270
 		$classes[] = 'wpinv-success';
271 271
 		$classes[] = 'wpinv-page';
272 272
 	}
273 273
 
274
-	if( wpinv_is_failed_transaction_page() ) {
274
+	if (wpinv_is_failed_transaction_page()) {
275 275
 		$classes[] = 'wpinv-failed-transaction';
276 276
 		$classes[] = 'wpinv-page';
277 277
 	}
278 278
 
279
-	if( wpinv_is_invoice_history_page() ) {
279
+	if (wpinv_is_invoice_history_page()) {
280 280
 		$classes[] = 'wpinv-history';
281 281
 		$classes[] = 'wpinv-page';
282 282
 	}
283 283
 
284
-	if( wpinv_is_test_mode() ) {
284
+	if (wpinv_is_test_mode()) {
285 285
 		$classes[] = 'wpinv-test-mode';
286 286
 		$classes[] = 'wpinv-page';
287 287
 	}
288 288
 
289
-	return array_unique( $classes );
289
+	return array_unique($classes);
290 290
 }
291
-add_filter( 'body_class', 'wpinv_add_body_classes' );
291
+add_filter('body_class', 'wpinv_add_body_classes');
292 292
 
293
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
294
-    $args = array( 'nopaging' => true );
293
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
294
+    $args = array('nopaging' => true);
295 295
 
296
-    if ( ! empty( $status ) )
296
+    if (!empty($status))
297 297
         $args['post_status'] = $status;
298 298
 
299
-    $discounts = wpinv_get_discounts( $args );
299
+    $discounts = wpinv_get_discounts($args);
300 300
     $options   = array();
301 301
 
302
-    if ( $discounts ) {
303
-        foreach ( $discounts as $discount ) {
304
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
302
+    if ($discounts) {
303
+        foreach ($discounts as $discount) {
304
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
305 305
         }
306 306
     } else {
307
-        $options[0] = __( 'No discounts found', 'invoicing' );
307
+        $options[0] = __('No discounts found', 'invoicing');
308 308
     }
309 309
 
310
-    $output = wpinv_html_select( array(
310
+    $output = wpinv_html_select(array(
311 311
         'name'             => $name,
312 312
         'selected'         => $selected,
313 313
         'options'          => $options,
314 314
         'show_option_all'  => false,
315 315
         'show_option_none' => false,
316
-    ) );
316
+    ));
317 317
 
318 318
     return $output;
319 319
 }
320 320
 
321
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
322
-    $current     = date( 'Y' );
323
-    $start_year  = $current - absint( $years_before );
324
-    $end_year    = $current + absint( $years_after );
325
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
321
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
322
+    $current     = date('Y');
323
+    $start_year  = $current - absint($years_before);
324
+    $end_year    = $current + absint($years_after);
325
+    $selected    = empty($selected) ? date('Y') : $selected;
326 326
     $options     = array();
327 327
 
328
-    while ( $start_year <= $end_year ) {
329
-        $options[ absint( $start_year ) ] = $start_year;
328
+    while ($start_year <= $end_year) {
329
+        $options[absint($start_year)] = $start_year;
330 330
         $start_year++;
331 331
     }
332 332
 
333
-    $output = wpinv_html_select( array(
333
+    $output = wpinv_html_select(array(
334 334
         'name'             => $name,
335 335
         'selected'         => $selected,
336 336
         'options'          => $options,
337 337
         'show_option_all'  => false,
338 338
         'show_option_none' => false
339
-    ) );
339
+    ));
340 340
 
341 341
     return $output;
342 342
 }
343 343
 
344
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
344
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
345 345
     $month   = 1;
346 346
     $options = array();
347
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
347
+    $selected = empty($selected) ? date('n') : $selected;
348 348
 
349
-    while ( $month <= 12 ) {
350
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
349
+    while ($month <= 12) {
350
+        $options[absint($month)] = wpinv_month_num_to_name($month);
351 351
         $month++;
352 352
     }
353 353
 
354
-    $output = wpinv_html_select( array(
354
+    $output = wpinv_html_select(array(
355 355
         'name'             => $name,
356 356
         'selected'         => $selected,
357 357
         'options'          => $options,
358 358
         'show_option_all'  => false,
359 359
         'show_option_none' => false
360
-    ) );
360
+    ));
361 361
 
362 362
     return $output;
363 363
 }
364 364
 
365
-function wpinv_html_select( $args = array() ) {
365
+function wpinv_html_select($args = array()) {
366 366
     $defaults = array(
367 367
         'options'          => array(),
368 368
         'name'             => null,
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
         'chosen'           => false,
373 373
         'placeholder'      => null,
374 374
         'multiple'         => false,
375
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
376
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
375
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
376
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
377 377
         'data'             => array(),
378 378
         'onchange'         => null,
379 379
         'required'         => false,
@@ -381,78 +381,78 @@  discard block
 block discarded – undo
381 381
         'readonly'         => false,
382 382
     );
383 383
 
384
-    $args = wp_parse_args( $args, $defaults );
384
+    $args = wp_parse_args($args, $defaults);
385 385
 
386 386
     $data_elements = '';
387
-    foreach ( $args['data'] as $key => $value ) {
388
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
387
+    foreach ($args['data'] as $key => $value) {
388
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
389 389
     }
390 390
 
391
-    if( $args['multiple'] ) {
391
+    if ($args['multiple']) {
392 392
         $multiple = ' MULTIPLE';
393 393
     } else {
394 394
         $multiple = '';
395 395
     }
396 396
 
397
-    if( $args['chosen'] ) {
397
+    if ($args['chosen']) {
398 398
         $args['class'] .= ' wpinv-select-chosen';
399 399
     }
400 400
 
401
-    if( $args['placeholder'] ) {
401
+    if ($args['placeholder']) {
402 402
         $placeholder = $args['placeholder'];
403 403
     } else {
404 404
         $placeholder = '';
405 405
     }
406 406
     
407 407
     $options = '';
408
-    if( !empty( $args['onchange'] ) ) {
409
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
408
+    if (!empty($args['onchange'])) {
409
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
410 410
     }
411 411
     
412
-    if( !empty( $args['required'] ) ) {
412
+    if (!empty($args['required'])) {
413 413
         $options .= ' required="required"';
414 414
     }
415 415
     
416
-    if( !empty( $args['disabled'] ) ) {
416
+    if (!empty($args['disabled'])) {
417 417
         $options .= ' disabled';
418 418
     }
419 419
     
420
-    if( !empty( $args['readonly'] ) ) {
420
+    if (!empty($args['readonly'])) {
421 421
         $options .= ' readonly';
422 422
     }
423 423
 
424
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
425
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
424
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
425
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
426 426
 
427
-    if ( $args['show_option_all'] ) {
428
-        if( $args['multiple'] ) {
429
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
427
+    if ($args['show_option_all']) {
428
+        if ($args['multiple']) {
429
+            $selected = selected(true, in_array(0, $args['selected']), false);
430 430
         } else {
431
-            $selected = selected( $args['selected'], 0, false );
431
+            $selected = selected($args['selected'], 0, false);
432 432
         }
433
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
433
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
434 434
     }
435 435
 
436
-    if ( !empty( $args['options'] ) ) {
436
+    if (!empty($args['options'])) {
437 437
 
438
-        if ( $args['show_option_none'] ) {
439
-            if( $args['multiple'] ) {
440
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
438
+        if ($args['show_option_none']) {
439
+            if ($args['multiple']) {
440
+                $selected = selected(true, in_array("", $args['selected']), false);
441 441
             } else {
442
-                $selected = selected( $args['selected'] === "", true, false );
442
+                $selected = selected($args['selected'] === "", true, false);
443 443
             }
444
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
444
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
445 445
         }
446 446
 
447
-        foreach( $args['options'] as $key => $option ) {
447
+        foreach ($args['options'] as $key => $option) {
448 448
 
449
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
450
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
449
+            if ($args['multiple'] && is_array($args['selected'])) {
450
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
451 451
             } else {
452
-                $selected = selected( $args['selected'], $key, false );
452
+                $selected = selected($args['selected'], $key, false);
453 453
             }
454 454
 
455
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
455
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
456 456
         }
457 457
     }
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     return $output;
462 462
 }
463 463
 
464
-function wpinv_item_dropdown( $args = array() ) {
464
+function wpinv_item_dropdown($args = array()) {
465 465
     $defaults = array(
466 466
         'name'              => 'wpi_item',
467 467
         'id'                => 'wpi_item',
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
         'selected'          => 0,
471 471
         'chosen'            => false,
472 472
         'number'            => 100,
473
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
474
-        'data'              => array( 'search-type' => 'item' ),
473
+        'placeholder'       => __('Choose a item', 'invoicing'),
474
+        'data'              => array('search-type' => 'item'),
475 475
         'show_option_all'   => false,
476 476
         'show_option_none'  => false,
477 477
         'with_packages'     => true,
478 478
         'show_recurring'    => false,
479 479
     );
480 480
 
481
-    $args = wp_parse_args( $args, $defaults );
481
+    $args = wp_parse_args($args, $defaults);
482 482
 
483 483
     $item_args = array(
484 484
         'post_type'      => 'wpi_item',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         'posts_per_page' => $args['number']
488 488
     );
489 489
     
490
-    if ( !$args['with_packages'] ) {
490
+    if (!$args['with_packages']) {
491 491
         $item_args['meta_query'] = array(
492 492
             array(
493 493
                 'key'       => '_wpinv_type',
@@ -497,42 +497,42 @@  discard block
 block discarded – undo
497 497
         );
498 498
     }
499 499
 
500
-    $items      = get_posts( $item_args );
500
+    $items      = get_posts($item_args);
501 501
     $options    = array();
502
-    if ( $items ) {
503
-        foreach ( $items as $item ) {
504
-            $title = esc_html( $item->post_title );
502
+    if ($items) {
503
+        foreach ($items as $item) {
504
+            $title = esc_html($item->post_title);
505 505
             
506
-            if ( !empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $item->ID, false );
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($item->ID, false);
508 508
             }
509 509
             
510
-            $options[ absint( $item->ID ) ] = $title;
510
+            $options[absint($item->ID)] = $title;
511 511
         }
512 512
     }
513 513
 
514 514
     // This ensures that any selected items are included in the drop down
515
-    if( is_array( $args['selected'] ) ) {
516
-        foreach( $args['selected'] as $item ) {
517
-            if( ! in_array( $item, $options ) ) {
518
-                $title = get_the_title( $item );
519
-                if ( !empty( $args['show_recurring'] ) ) {
520
-                    $title .= wpinv_get_item_suffix( $item, false );
515
+    if (is_array($args['selected'])) {
516
+        foreach ($args['selected'] as $item) {
517
+            if (!in_array($item, $options)) {
518
+                $title = get_the_title($item);
519
+                if (!empty($args['show_recurring'])) {
520
+                    $title .= wpinv_get_item_suffix($item, false);
521 521
                 }
522 522
                 $options[$item] = $title;
523 523
             }
524 524
         }
525
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
526
-        if ( ! in_array( $args['selected'], $options ) ) {
527
-            $title = get_the_title( $args['selected'] );
528
-            if ( !empty( $args['show_recurring'] ) ) {
529
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
525
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
526
+        if (!in_array($args['selected'], $options)) {
527
+            $title = get_the_title($args['selected']);
528
+            if (!empty($args['show_recurring'])) {
529
+                $title .= wpinv_get_item_suffix($args['selected'], false);
530 530
             }
531
-            $options[$args['selected']] = get_the_title( $args['selected'] );
531
+            $options[$args['selected']] = get_the_title($args['selected']);
532 532
         }
533 533
     }
534 534
 
535
-    $output = wpinv_html_select( array(
535
+    $output = wpinv_html_select(array(
536 536
         'name'             => $args['name'],
537 537
         'selected'         => $args['selected'],
538 538
         'id'               => $args['id'],
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
         'show_option_all'  => $args['show_option_all'],
545 545
         'show_option_none' => $args['show_option_none'],
546 546
         'data'             => $args['data'],
547
-    ) );
547
+    ));
548 548
 
549 549
     return $output;
550 550
 }
551 551
 
552
-function wpinv_html_checkbox( $args = array() ) {
552
+function wpinv_html_checkbox($args = array()) {
553 553
     $defaults = array(
554 554
         'name'     => null,
555 555
         'current'  => null,
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
         )
561 561
     );
562 562
 
563
-    $args = wp_parse_args( $args, $defaults );
563
+    $args = wp_parse_args($args, $defaults);
564 564
 
565
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
565
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
566 566
     $options = '';
567
-    if ( ! empty( $args['options']['disabled'] ) ) {
567
+    if (!empty($args['options']['disabled'])) {
568 568
         $options .= ' disabled="disabled"';
569
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
569
+    } elseif (!empty($args['options']['readonly'])) {
570 570
         $options .= ' readonly';
571 571
     }
572 572
 
573
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
573
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
574 574
 
575 575
     return $output;
576 576
 }
577 577
 
578
-function wpinv_html_text( $args = array() ) {
578
+function wpinv_html_text($args = array()) {
579 579
     // Backwards compatibility
580
-    if ( func_num_args() > 1 ) {
580
+    if (func_num_args() > 1) {
581 581
         $args = func_get_args();
582 582
 
583 583
         $name  = $args[0];
584
-        $value = isset( $args[1] ) ? $args[1] : '';
585
-        $label = isset( $args[2] ) ? $args[2] : '';
586
-        $desc  = isset( $args[3] ) ? $args[3] : '';
584
+        $value = isset($args[1]) ? $args[1] : '';
585
+        $label = isset($args[2]) ? $args[2] : '';
586
+        $desc  = isset($args[3]) ? $args[3] : '';
587 587
     }
588 588
 
589 589
     $defaults = array(
590 590
         'id'           => '',
591
-        'name'         => isset( $name )  ? $name  : 'text',
592
-        'value'        => isset( $value ) ? $value : null,
593
-        'label'        => isset( $label ) ? $label : null,
594
-        'desc'         => isset( $desc )  ? $desc  : null,
591
+        'name'         => isset($name) ? $name : 'text',
592
+        'value'        => isset($value) ? $value : null,
593
+        'label'        => isset($label) ? $label : null,
594
+        'desc'         => isset($desc) ? $desc : null,
595 595
         'placeholder'  => '',
596 596
         'class'        => 'regular-text',
597 597
         'disabled'     => false,
@@ -601,51 +601,51 @@  discard block
 block discarded – undo
601 601
         'data'         => false
602 602
     );
603 603
 
604
-    $args = wp_parse_args( $args, $defaults );
604
+    $args = wp_parse_args($args, $defaults);
605 605
 
606
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
606
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
607 607
     $options = '';
608
-    if( $args['required'] ) {
608
+    if ($args['required']) {
609 609
         $options .= ' required="required"';
610 610
     }
611
-    if( $args['readonly'] ) {
611
+    if ($args['readonly']) {
612 612
         $options .= ' readonly';
613 613
     }
614
-    if( $args['readonly'] ) {
614
+    if ($args['readonly']) {
615 615
         $options .= ' readonly';
616 616
     }
617 617
 
618 618
     $data = '';
619
-    if ( !empty( $args['data'] ) ) {
620
-        foreach ( $args['data'] as $key => $value ) {
621
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
619
+    if (!empty($args['data'])) {
620
+        foreach ($args['data'] as $key => $value) {
621
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
622 622
         }
623 623
     }
624 624
 
625
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
626
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
627
-    if ( ! empty( $args['desc'] ) ) {
628
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
625
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
626
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
627
+    if (!empty($args['desc'])) {
628
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
629 629
     }
630 630
 
631
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
631
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
632 632
 
633 633
     $output .= '</span>';
634 634
 
635 635
     return $output;
636 636
 }
637 637
 
638
-function wpinv_html_date_field( $args = array() ) {
639
-    if( empty( $args['class'] ) ) {
638
+function wpinv_html_date_field($args = array()) {
639
+    if (empty($args['class'])) {
640 640
         $args['class'] = 'wpiDatepicker';
641
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
641
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
642 642
         $args['class'] .= ' wpiDatepicker';
643 643
     }
644 644
 
645
-    return wpinv_html_text( $args );
645
+    return wpinv_html_text($args);
646 646
 }
647 647
 
648
-function wpinv_html_textarea( $args = array() ) {
648
+function wpinv_html_textarea($args = array()) {
649 649
     $defaults = array(
650 650
         'name'        => 'textarea',
651 651
         'value'       => null,
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
         'disabled'    => false
656 656
     );
657 657
 
658
-    $args = wp_parse_args( $args, $defaults );
658
+    $args = wp_parse_args($args, $defaults);
659 659
 
660
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
660
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
661 661
     $disabled = '';
662
-    if( $args['disabled'] ) {
662
+    if ($args['disabled']) {
663 663
         $disabled = ' disabled="disabled"';
664 664
     }
665 665
 
666
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
667
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
668
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
666
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
667
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
668
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
669 669
 
670
-    if ( ! empty( $args['desc'] ) ) {
671
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
670
+    if (!empty($args['desc'])) {
671
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
672 672
     }
673 673
     $output .= '</span>';
674 674
 
675 675
     return $output;
676 676
 }
677 677
 
678
-function wpinv_html_ajax_user_search( $args = array() ) {
678
+function wpinv_html_ajax_user_search($args = array()) {
679 679
     $defaults = array(
680 680
         'name'        => 'user_id',
681 681
         'value'       => null,
682
-        'placeholder' => __( 'Enter username', 'invoicing' ),
682
+        'placeholder' => __('Enter username', 'invoicing'),
683 683
         'label'       => null,
684 684
         'desc'        => null,
685 685
         'class'       => '',
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         'data'        => false
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693 693
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
694 694
 
695 695
     $output  = '<span class="wpinv_user_search_wrap">';
696
-        $output .= wpinv_html_text( $args );
697
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
696
+        $output .= wpinv_html_text($args);
697
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
698 698
     $output .= '</span>';
699 699
 
700 700
     return $output;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 function wpinv_ip_geolocation() {
704 704
     global $wpinv_euvat;
705 705
     
706
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
706
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
707 707
     $content    = '';
708 708
     $iso        = '';
709 709
     $country    = '';
@@ -714,69 +714,69 @@  discard block
 block discarded – undo
714 714
     $credit     = '';
715 715
     $address    = '';
716 716
     
717
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
717
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
718 718
         try {
719 719
             $iso        = $geoip2_city->country->isoCode;
720 720
             $country    = $geoip2_city->country->name;
721
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
721
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
722 722
             $city       = $geoip2_city->city->name;
723 723
             $longitude  = $geoip2_city->location->longitude;
724 724
             $latitude   = $geoip2_city->location->latitude;
725
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
726
-        } catch( Exception $e ) { }
725
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
729
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
730 730
         try {
731
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
731
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
732 732
             
733
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
733
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
734 734
                 $iso        = $load_xml->geoplugin_countryCode;
735 735
                 $country    = $load_xml->geoplugin_countryName;
736
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
737
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
736
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
737
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
738 738
                 $longitude  = $load_xml->geoplugin_longitude;
739 739
                 $latitude   = $load_xml->geoplugin_latitude;
740 740
                 $credit     = $load_xml->geoplugin_credit;
741
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
741
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
742 742
             }
743
-        } catch( Exception $e ) { }
743
+        } catch (Exception $e) { }
744 744
     }
745 745
     
746
-    if ( $iso && $longitude && $latitude ) {
747
-        if ( $city ) {
746
+    if ($iso && $longitude && $latitude) {
747
+        if ($city) {
748 748
             $address .= $city . ', ';
749 749
         }
750 750
         
751
-        if ( $region ) {
751
+        if ($region) {
752 752
             $address .= $region . ', ';
753 753
         }
754 754
         
755 755
         $address .= $country . ' (' . $iso . ')';
756
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
757
-        $content .= '<p>'. $credit . '</p>';
756
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
757
+        $content .= '<p>' . $credit . '</p>';
758 758
     } else {
759
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
759
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
760 760
     }
761 761
     ?>
762 762
 <!DOCTYPE html>
763
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
763
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
764 764
 <body>
765
-    <?php if ( $latitude && $latitude ) { ?>
765
+    <?php if ($latitude && $latitude) { ?>
766 766
     <div id="map"></div>
767 767
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
768 768
         <script type="text/javascript">
769 769
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
770 770
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
771 771
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
772
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
772
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
773 773
 
774 774
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
775 775
 
776 776
         var marker = new L.Marker(latlng);
777 777
         map.addLayer(marker);
778 778
 
779
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
779
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
780 780
     </script>
781 781
     <?php } ?>
782 782
     <div style="height:100px"><?php echo $content; ?></div>
@@ -784,31 +784,31 @@  discard block
 block discarded – undo
784 784
 <?php
785 785
     exit;
786 786
 }
787
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
788
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
787
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
788
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
789 789
 
790 790
 // Set up the template for the invoice.
791
-function wpinv_template( $template ) {
791
+function wpinv_template($template) {
792 792
     global $post, $wp_query;
793 793
     
794
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
795
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
796
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
794
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
795
+        if (wpinv_user_can_print_invoice($post->ID)) {
796
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
797 797
         } else {
798
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
798
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
799 799
                 $user_id = $invoice->get_user_id();
800
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
800
+                $secret = sanitize_text_field($_GET['_wpipay']);
801 801
 
802
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
803
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
802
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
803
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
804 804
 
805
-                    wpinv_guest_redirect( $redirect_to, $user_id );
805
+                    wpinv_guest_redirect($redirect_to, $user_id);
806 806
                     wpinv_die();
807 807
                 }
808 808
             }
809
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
809
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
810 810
 
811
-            wp_redirect( $redirect_to );
811
+            wp_redirect($redirect_to);
812 812
             wpinv_die();
813 813
         }
814 814
     }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
 function wpinv_get_business_address() {
820 820
     $business_address   = wpinv_store_address();
821
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
821
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
822 822
     
823 823
     /*
824 824
     $default_country    = wpinv_get_default_country();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     
843 843
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
844 844
     
845
-    return apply_filters( 'wpinv_get_business_address', $business_address );
845
+    return apply_filters('wpinv_get_business_address', $business_address);
846 846
 }
847 847
 
848 848
 function wpinv_display_from_address() {
@@ -852,185 +852,185 @@  discard block
 block discarded – undo
852 852
     if (empty($from_name)) {
853 853
         $from_name = wpinv_get_business_name();
854 854
     }
855
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
855
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
856 856
     <div class="wrapper col-xs-10">
857
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
858
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
859
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
857
+        <div class="name"><?php echo esc_html($from_name); ?></div>
858
+        <?php if ($address = wpinv_get_business_address()) { ?>
859
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
860 860
         <?php } ?>
861
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
862
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
861
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
862
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
863 863
         <?php } ?>
864 864
     </div>
865 865
     <?php
866 866
 }
867 867
 
868
-function wpinv_watermark( $id = 0 ) {
869
-    $output = wpinv_get_watermark( $id );
868
+function wpinv_watermark($id = 0) {
869
+    $output = wpinv_get_watermark($id);
870 870
     
871
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
871
+    return apply_filters('wpinv_get_watermark', $output, $id);
872 872
 }
873 873
 
874
-function wpinv_get_watermark( $id ) {
875
-    if ( !$id > 0 ) {
874
+function wpinv_get_watermark($id) {
875
+    if (!$id > 0) {
876 876
         return NULL;
877 877
     }
878
-    $invoice = wpinv_get_invoice( $id );
878
+    $invoice = wpinv_get_invoice($id);
879 879
     
880
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
881
-        if ( $invoice->is_paid() ) {
882
-            return __( 'Paid', 'invoicing' );
880
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
881
+        if ($invoice->is_paid()) {
882
+            return __('Paid', 'invoicing');
883 883
         }
884
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
885
-            return __( 'Cancelled', 'invoicing' );
884
+        if ($invoice->has_status(array('wpi-cancelled'))) {
885
+            return __('Cancelled', 'invoicing');
886 886
         }
887 887
     }
888 888
     
889 889
     return NULL;
890 890
 }
891 891
 
892
-function wpinv_display_invoice_details( $invoice ) {
892
+function wpinv_display_invoice_details($invoice) {
893 893
     global $wpinv_euvat;
894 894
     
895 895
     $invoice_id = $invoice->ID;
896 896
     $vat_name   = $wpinv_euvat->get_vat_name();
897 897
     $use_taxes  = wpinv_use_taxes();
898 898
     
899
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
899
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
900 900
     
901
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
901
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
903 903
     ?>
904 904
     <table class="table table-bordered table-sm">
905
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
905
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
906 906
             <tr class="wpi-row-number">
907
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
908
-                <td><?php echo esc_html( $invoice_number ); ?></td>
907
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
908
+                <td><?php echo esc_html($invoice_number); ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="wpi-row-status">
912
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
912
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
914 914
         </tr>
915
-        <?php if ( $invoice->is_renewal() ) { ?>
915
+        <?php if ($invoice->is_renewal()) { ?>
916 916
         <tr class="wpi-row-parent">
917
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
918
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
917
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
918
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
919 919
         </tr>
920 920
         <?php } ?>
921 921
         <tr class="wpi-row-gateway">
922
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
923
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
922
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
923
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
924 924
         </tr>
925
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
925
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
926 926
             <tr class="wpi-row-date">
927
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
927
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
928 928
                 <td><?php echo $invoice_date; ?></td>
929 929
             </tr>
930 930
         <?php } ?>
931
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
931
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
932 932
             <tr class="wpi-row-date">
933
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
933
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
934 934
                 <td><?php echo $due_date; ?></td>
935 935
             </tr>
936 936
         <?php } ?>
937
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
937
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
938 938
             <tr class="wpi-row-ovatno">
939
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
939
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
940 940
                 <td><?php echo $owner_vat_number; ?></td>
941 941
             </tr>
942 942
         <?php } ?>
943
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
943
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
944 944
             <tr class="wpi-row-uvatno">
945
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
945
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
946 946
                 <td><?php echo $user_vat_number; ?></td>
947 947
             </tr>
948 948
         <?php } ?>
949 949
         <tr class="table-active tr-total wpi-row-total">
950
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
951
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
950
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
951
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
952 952
         </tr>
953 953
     </table>
954 954
 <?php
955 955
 }
956 956
 
957
-function wpinv_display_to_address( $invoice_id = 0 ) {
958
-    $invoice = wpinv_get_invoice( $invoice_id );
957
+function wpinv_display_to_address($invoice_id = 0) {
958
+    $invoice = wpinv_get_invoice($invoice_id);
959 959
     
960
-    if ( empty( $invoice ) ) {
960
+    if (empty($invoice)) {
961 961
         return NULL;
962 962
     }
963 963
     
964 964
     $billing_details = $invoice->get_user_info();
965
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
965
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
966 966
     $output .= '<div class="wrapper col-xs-10">';
967 967
     
968 968
     ob_start();
969
-    do_action( 'wpinv_display_to_address_top', $invoice );
969
+    do_action('wpinv_display_to_address_top', $invoice);
970 970
     $output .= ob_get_clean();
971 971
     
972
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
973
-    if ( $company = $billing_details['company'] ) {
974
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
972
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
973
+    if ($company = $billing_details['company']) {
974
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
975 975
     }
976 976
     $address_row = '';
977
-    if ( $address = $billing_details['address'] ) {
978
-        $address_row .= wpautop( wp_kses_post( $address ) );
977
+    if ($address = $billing_details['address']) {
978
+        $address_row .= wpautop(wp_kses_post($address));
979 979
     }
980 980
     
981 981
     $address_fields = array();
982
-    if ( !empty( $billing_details['city'] ) ) {
982
+    if (!empty($billing_details['city'])) {
983 983
         $address_fields[] = $billing_details['city'];
984 984
     }
985 985
     
986
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
987
-    if ( !empty( $billing_details['state'] ) ) {
988
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
986
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
987
+    if (!empty($billing_details['state'])) {
988
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
989 989
     }
990 990
     
991
-    if ( !empty( $billing_country ) ) {
992
-        $address_fields[] = wpinv_country_name( $billing_country );
991
+    if (!empty($billing_country)) {
992
+        $address_fields[] = wpinv_country_name($billing_country);
993 993
     }
994 994
     
995
-    if ( !empty( $address_fields ) ) {
996
-        $address_fields = implode( ", ", $address_fields );
995
+    if (!empty($address_fields)) {
996
+        $address_fields = implode(", ", $address_fields);
997 997
         
998
-        if ( !empty( $billing_details['zip'] ) ) {
998
+        if (!empty($billing_details['zip'])) {
999 999
             $address_fields .= ' ' . $billing_details['zip'];
1000 1000
         }
1001 1001
         
1002
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1002
+        $address_row .= wpautop(wp_kses_post($address_fields));
1003 1003
     }
1004 1004
     
1005
-    if ( $address_row ) {
1005
+    if ($address_row) {
1006 1006
         $output .= '<div class="address">' . $address_row . '</div>';
1007 1007
     }
1008 1008
     
1009
-    if ( $phone = $invoice->get_phone() ) {
1010
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1009
+    if ($phone = $invoice->get_phone()) {
1010
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1011 1011
     }
1012
-    if ( $email = $invoice->get_email() ) {
1013
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1012
+    if ($email = $invoice->get_email()) {
1013
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1014 1014
     }
1015 1015
     
1016 1016
     ob_start();
1017
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1017
+    do_action('wpinv_display_to_address_bottom', $invoice);
1018 1018
     $output .= ob_get_clean();
1019 1019
     
1020 1020
     $output .= '</div>';
1021
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1021
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1022 1022
 
1023 1023
     echo $output;
1024 1024
 }
1025 1025
 
1026
-function wpinv_display_line_items( $invoice_id = 0 ) {
1026
+function wpinv_display_line_items($invoice_id = 0) {
1027 1027
     global $wpinv_euvat, $ajax_cart_details;
1028
-    $invoice            = wpinv_get_invoice( $invoice_id );
1028
+    $invoice            = wpinv_get_invoice($invoice_id);
1029 1029
     $quantities_enabled = wpinv_item_quantities_enabled();
1030 1030
     $use_taxes          = wpinv_use_taxes();
1031 1031
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1032
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1033
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1032
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1033
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1034 1034
     
1035 1035
     $cart_details       = $invoice->get_cart_details();
1036 1036
     $ajax_cart_details  = $cart_details;
@@ -1039,68 +1039,68 @@  discard block
 block discarded – undo
1039 1039
     <table class="table table-sm table-bordered table-responsive">
1040 1040
         <thead>
1041 1041
             <tr>
1042
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1043
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1042
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1043
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1044 1044
                 <?php if ($quantities_enabled) { ?>
1045
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1045
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1046 1046
                 <?php } ?>
1047 1047
                 <?php if ($use_taxes && !$zero_tax) { ?>
1048 1048
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1049 1049
                 <?php } ?>
1050
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1050
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1051 1051
             </tr>
1052 1052
         </thead>
1053 1053
         <tbody>
1054 1054
         <?php 
1055
-            if ( !empty( $cart_details ) ) {
1056
-                do_action( 'wpinv_display_line_items_start', $invoice );
1055
+            if (!empty($cart_details)) {
1056
+                do_action('wpinv_display_line_items_start', $invoice);
1057 1057
                 
1058 1058
                 $count = 0;
1059 1059
                 $cols  = 3;
1060
-                foreach ( $cart_details as $key => $cart_item ) {
1061
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1062
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1063
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1064
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1060
+                foreach ($cart_details as $key => $cart_item) {
1061
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1062
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1063
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1064
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1065 1065
                     
1066
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1066
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1067 1067
                     $summary    = '';
1068 1068
                     $cols       = 3;
1069
-                    if ( !empty($item) ) {
1069
+                    if (!empty($item)) {
1070 1070
                         $item_name  = $item->get_name();
1071 1071
                         $summary    = $item->get_summary();
1072 1072
                     }
1073
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1073
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1074 1074
                     
1075 1075
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1076
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1077
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link );
1076
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1077
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link);
1078 1078
                     }
1079
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1079
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1080 1080
                     
1081 1081
                     $item_tax       = '';
1082 1082
                     $tax_rate       = '';
1083
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1084
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1085
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1086
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1083
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1084
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1085
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1086
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1087 1087
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1088 1088
                     }
1089 1089
                     
1090 1090
                     $line_item_tax = $item_tax . $tax_rate;
1091 1091
                     
1092
-                    if ( $line_item_tax === '' ) {
1092
+                    if ($line_item_tax === '') {
1093 1093
                         $line_item_tax = 0; // Zero tax
1094 1094
                     }
1095 1095
                     
1096
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1097
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1098
-                        if ( $summary !== '' ) {
1099
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1096
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1097
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1098
+                        if ($summary !== '') {
1099
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1100 1100
                         }
1101 1101
                         $line_item .= '</td>';
1102 1102
                         
1103
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1103
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1104 1104
                         if ($quantities_enabled) {
1105 1105
                             $cols++;
1106 1106
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1109,55 +1109,55 @@  discard block
 block discarded – undo
1109 1109
                             $cols++;
1110 1110
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1111 1111
                         }
1112
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1112
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1113 1113
                     $line_item .= '</tr>';
1114 1114
                     
1115
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1115
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1116 1116
 
1117 1117
                     $count++;
1118 1118
                 }
1119 1119
                 
1120
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1120
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1121 1121
                 ?>
1122 1122
                 <tr class="row-sub-total row_odd">
1123
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1124
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1123
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1124
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1125 1125
                 </tr>
1126 1126
                 <?php
1127
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1127
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1128 1128
                 
1129
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1130
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1129
+                if (wpinv_discount($invoice_id, false) > 0) {
1130
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1131 1131
                     ?>
1132 1132
                         <tr class="row-discount">
1133
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1134
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1133
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1134
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1135 1135
                         </tr>
1136 1136
                     <?php
1137
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1137
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1138 1138
                 }
1139 1139
                 
1140
-                if ( $use_taxes ) {
1141
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1140
+                if ($use_taxes) {
1141
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1142 1142
                     ?>
1143 1143
                     <tr class="row-tax">
1144
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1145
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1144
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1145
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1146 1146
                     </tr>
1147 1147
                     <?php
1148
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1148
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1149 1149
                 }
1150 1150
                 
1151
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1151
+                do_action('wpinv_display_before_total', $invoice, $cols);
1152 1152
                 ?>
1153 1153
                 <tr class="table-active row-total">
1154
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1155
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1154
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1155
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1156 1156
                 </tr>
1157 1157
                 <?php
1158
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1158
+                do_action('wpinv_display_after_total', $invoice, $cols);
1159 1159
                 
1160
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1160
+                do_action('wpinv_display_line_end', $invoice, $cols);
1161 1161
             }
1162 1162
         ?>
1163 1163
         </tbody>
@@ -1166,35 +1166,35 @@  discard block
 block discarded – undo
1166 1166
     echo ob_get_clean();
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1169
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1170 1170
     $use_taxes = wpinv_use_taxes();
1171 1171
     
1172
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1172
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1173 1173
     ?>
1174 1174
     <table class="table table-sm table-bordered table-responsive">
1175 1175
         <tbody>
1176
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1176
+            <?php do_action('wpinv_before_display_totals'); ?>
1177 1177
             <tr class="row-sub-total">
1178
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1179
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1178
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1179
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1180 1180
             </tr>
1181
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1182
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1181
+            <?php do_action('wpinv_after_display_totals'); ?>
1182
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1183 1183
                 <tr class="row-discount">
1184
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1185
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1184
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1185
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1186 1186
                 </tr>
1187
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1187
+            <?php do_action('wpinv_after_display_discount'); ?>
1188 1188
             <?php } ?>
1189
-            <?php if ( $use_taxes ) { ?>
1189
+            <?php if ($use_taxes) { ?>
1190 1190
             <tr class="row-tax">
1191
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1192
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1191
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1192
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1193 1193
             </tr>
1194
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1194
+            <?php do_action('wpinv_after_display_tax'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1197
-                <?php foreach ( $fees as $fee ) { ?>
1196
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1197
+                <?php foreach ($fees as $fee) { ?>
1198 1198
                     <tr class="row-fee">
1199 1199
                         <td class="rate"><?php echo $fee['label']; ?></td>
1200 1200
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1202,72 +1202,72 @@  discard block
 block discarded – undo
1202 1202
                 <?php } ?>
1203 1203
             <?php } ?>
1204 1204
             <tr class="table-active row-total">
1205
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1206
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1205
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1206
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1207 1207
             </tr>
1208
-            <?php do_action( 'wpinv_after_totals' ); ?>
1208
+            <?php do_action('wpinv_after_totals'); ?>
1209 1209
         </tbody>
1210 1210
 
1211 1211
     </table>
1212 1212
 
1213
-    <?php do_action( 'wpinv_after_totals_table' );
1213
+    <?php do_action('wpinv_after_totals_table');
1214 1214
 }
1215 1215
 
1216
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1217
-    $invoice = wpinv_get_invoice( $invoice_id );
1216
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1217
+    $invoice = wpinv_get_invoice($invoice_id);
1218 1218
     
1219 1219
     ob_start();
1220
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1221
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) {
1220
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1221
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) {
1222 1222
         ?>
1223 1223
         <div class="wpi-payment-info">
1224
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1225
-            <?php if ( $gateway_title ) { ?>
1226
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1224
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1225
+            <?php if ($gateway_title) { ?>
1226
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1227 1227
             <?php } ?>
1228 1228
         </div>
1229 1229
         <?php
1230 1230
     }
1231
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1231
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1232 1232
     $outout = ob_get_clean();
1233 1233
     
1234
-    if ( $echo ) {
1234
+    if ($echo) {
1235 1235
         echo $outout;
1236 1236
     } else {
1237 1237
         return $outout;
1238 1238
     }
1239 1239
 }
1240 1240
 
1241
-function wpinv_display_style( $invoice ) {
1242
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1241
+function wpinv_display_style($invoice) {
1242
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1243 1243
     
1244
-    wp_print_styles( 'open-sans' );
1245
-    wp_print_styles( 'wpinv-single-style' );
1244
+    wp_print_styles('open-sans');
1245
+    wp_print_styles('wpinv-single-style');
1246 1246
 }
1247
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1247
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1248 1248
 
1249 1249
 function wpinv_checkout_billing_details() {  
1250 1250
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1251 1251
     if (empty($invoice_id)) {
1252
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1252
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1253 1253
         return null;
1254 1254
     }
1255 1255
     
1256
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1256
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1257 1257
     if (empty($invoice)) {
1258
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1258
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1259 1259
         return null;
1260 1260
     }
1261 1261
     $user_id        = $invoice->get_user_id();
1262 1262
     $user_info      = $invoice->get_user_info();
1263
-    $address_info   = wpinv_get_user_address( $user_id );
1263
+    $address_info   = wpinv_get_user_address($user_id);
1264 1264
     
1265
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1265
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1266 1266
         $user_info['first_name'] = $user_info['first_name'];
1267 1267
         $user_info['last_name'] = $user_info['last_name'];
1268 1268
     }
1269 1269
     
1270
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1270
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1271 1271
         $user_info['country']   = $address_info['country'];
1272 1272
         $user_info['state']     = $address_info['state'];
1273 1273
         $user_info['city']      = $address_info['city'];
@@ -1283,103 +1283,103 @@  discard block
 block discarded – undo
1283 1283
         'address'
1284 1284
     );
1285 1285
     
1286
-    foreach ( $address_fields as $field ) {
1287
-        if ( empty( $user_info[$field] ) ) {
1286
+    foreach ($address_fields as $field) {
1287
+        if (empty($user_info[$field])) {
1288 1288
             $user_info[$field] = $address_info[$field];
1289 1289
         }
1290 1290
     }
1291 1291
     
1292
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1292
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1293 1293
 }
1294 1294
 
1295 1295
 function wpinv_admin_get_line_items($invoice = array()) {
1296 1296
     $item_quantities    = wpinv_item_quantities_enabled();
1297 1297
     $use_taxes          = wpinv_use_taxes();
1298 1298
     
1299
-    if ( empty( $invoice ) ) {
1299
+    if (empty($invoice)) {
1300 1300
         return NULL;
1301 1301
     }
1302 1302
     
1303 1303
     $cart_items = $invoice->get_cart_details();
1304
-    if ( empty( $cart_items ) ) {
1304
+    if (empty($cart_items)) {
1305 1305
         return NULL;
1306 1306
     }
1307 1307
     ob_start();
1308 1308
     
1309
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1309
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1310 1310
     
1311 1311
     $count = 0;
1312
-    foreach ( $cart_items as $key => $cart_item ) {
1312
+    foreach ($cart_items as $key => $cart_item) {
1313 1313
         $item_id    = $cart_item['id'];
1314
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1314
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1315 1315
         
1316 1316
         if (empty($wpi_item)) {
1317 1317
             continue;
1318 1318
         }
1319 1319
         
1320
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1321
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1320
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1321
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1323 1323
         $can_remove     = true;
1324 1324
         
1325 1325
         $summary = '';
1326 1326
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1327
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1328
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
1327
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1328
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
1329 1329
         }
1330
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1330
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1331 1331
         
1332 1332
         $item_tax       = '';
1333 1333
         $tax_rate       = '';
1334
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1335
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1336
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1337
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1334
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1335
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1336
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1337
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1338 1338
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1339 1339
         }
1340 1340
         $line_item_tax = $item_tax . $tax_rate;
1341 1341
         
1342
-        if ( $line_item_tax === '' ) {
1342
+        if ($line_item_tax === '') {
1343 1343
             $line_item_tax = 0; // Zero tax
1344 1344
         }
1345 1345
 
1346
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1346
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1347 1347
             $line_item .= '<td class="id">' . $item_id . '</td>';
1348
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1349
-            if ( $summary !== '' ) {
1350
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1348
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1349
+            if ($summary !== '') {
1350
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1351 1351
             }
1352 1352
             $line_item .= '</td>';
1353 1353
             $line_item .= '<td class="price">' . $item_price . '</td>';
1354 1354
             
1355
-            if ( $item_quantities ) {
1356
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1355
+            if ($item_quantities) {
1356
+                if (count($cart_items) == 1 && $quantity <= 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1360 1360
             } else {
1361
-                if ( count( $cart_items ) == 1 ) {
1361
+                if (count($cart_items) == 1) {
1362 1362
                     $can_remove = false;
1363 1363
                 }
1364 1364
             }
1365 1365
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1366 1366
             
1367
-            if ( $use_taxes ) {
1367
+            if ($use_taxes) {
1368 1368
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1369 1369
             }
1370 1370
             $line_item .= '<td class="action">';
1371
-            if ( !$invoice->is_paid() && $can_remove ) {
1371
+            if (!$invoice->is_paid() && $can_remove) {
1372 1372
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1373 1373
             }
1374 1374
             $line_item .= '</td>';
1375 1375
         $line_item .= '</tr>';
1376 1376
         
1377
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1377
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1378 1378
         
1379 1379
         $count++;
1380 1380
     } 
1381 1381
     
1382
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1382
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1383 1383
     
1384 1384
     return ob_get_clean();
1385 1385
 }
@@ -1390,35 +1390,35 @@  discard block
 block discarded – undo
1390 1390
     // Set current invoice id.
1391 1391
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1392 1392
     
1393
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1393
+    $form_action = esc_url(wpinv_get_checkout_uri());
1394 1394
 
1395 1395
     ob_start();
1396 1396
         echo '<div id="wpinv_checkout_wrap">';
1397 1397
         
1398
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1398
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1399 1399
             ?>
1400 1400
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1401
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1401
+                <?php do_action('wpinv_before_checkout_form'); ?>
1402 1402
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1403 1403
                     <?php
1404
-                    do_action( 'wpinv_checkout_form_top' );
1405
-                    do_action( 'wpinv_checkout_billing_info' );
1406
-                    do_action( 'wpinv_checkout_cart' );
1407
-                    do_action( 'wpinv_payment_mode_select'  );
1408
-                    do_action( 'wpinv_checkout_form_bottom' )
1404
+                    do_action('wpinv_checkout_form_top');
1405
+                    do_action('wpinv_checkout_billing_info');
1406
+                    do_action('wpinv_checkout_cart');
1407
+                    do_action('wpinv_payment_mode_select');
1408
+                    do_action('wpinv_checkout_form_bottom')
1409 1409
                     ?>
1410 1410
                 </form>
1411
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1411
+                <?php do_action('wpinv_after_purchase_form'); ?>
1412 1412
             </div><!--end #wpinv_checkout_form_wrap-->
1413 1413
         <?php
1414 1414
         } else {
1415
-            do_action( 'wpinv_cart_empty' );
1415
+            do_action('wpinv_cart_empty');
1416 1416
         }
1417 1417
         echo '</div><!--end #wpinv_checkout_wrap-->';
1418 1418
     return ob_get_clean();
1419 1419
 }
1420 1420
 
1421
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1421
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1422 1422
     global $ajax_cart_details;
1423 1423
     $ajax_cart_details = $cart_details;
1424 1424
     /*
@@ -1433,25 +1433,25 @@  discard block
 block discarded – undo
1433 1433
     }
1434 1434
     */
1435 1435
     ob_start();
1436
-    do_action( 'wpinv_before_checkout_cart' );
1436
+    do_action('wpinv_before_checkout_cart');
1437 1437
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1438 1438
         echo '<div id="wpinv_checkout_cart_wrap">';
1439
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1439
+            wpinv_get_template_part('wpinv-checkout-cart');
1440 1440
         echo '</div>';
1441 1441
     echo '</div>';
1442
-    do_action( 'wpinv_after_checkout_cart' );
1442
+    do_action('wpinv_after_checkout_cart');
1443 1443
     $content = ob_get_clean();
1444 1444
     
1445
-    if ( $echo ) {
1445
+    if ($echo) {
1446 1446
         echo $content;
1447 1447
     } else {
1448 1448
         return $content;
1449 1449
     }
1450 1450
 }
1451
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1451
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1452 1452
 
1453 1453
 function wpinv_empty_cart_message() {
1454
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1454
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1455 1455
 }
1456 1456
 
1457 1457
 /**
@@ -1463,91 +1463,91 @@  discard block
 block discarded – undo
1463 1463
 function wpinv_empty_checkout_cart() {
1464 1464
 	echo wpinv_empty_cart_message();
1465 1465
 }
1466
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1466
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1467 1467
 
1468 1468
 function wpinv_save_cart_button() {
1469
-    if ( wpinv_is_cart_saving_disabled() )
1469
+    if (wpinv_is_cart_saving_disabled())
1470 1470
         return;
1471 1471
 ?>
1472
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1472
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_update_cart_button() {
1477
-    if ( !wpinv_item_quantities_enabled() )
1477
+    if (!wpinv_item_quantities_enabled())
1478 1478
         return;
1479 1479
 ?>
1480
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1480
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1481 1481
     <input type="hidden" name="wpi_action" value="update_cart"/>
1482 1482
 <?php
1483 1483
 }
1484 1484
 
1485 1485
 function wpinv_checkout_cart_columns() {
1486 1486
     $default = 3;
1487
-    if ( wpinv_item_quantities_enabled() ) {
1487
+    if (wpinv_item_quantities_enabled()) {
1488 1488
         $default++;
1489 1489
     }
1490 1490
     
1491
-    if ( wpinv_use_taxes() ) {
1491
+    if (wpinv_use_taxes()) {
1492 1492
         $default++;
1493 1493
     }
1494 1494
 
1495
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1495
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_display_cart_messages() {
1499 1499
     global $wpi_session;
1500 1500
 
1501
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1501
+    $messages = $wpi_session->get('wpinv_cart_messages');
1502 1502
 
1503
-    if ( $messages ) {
1504
-        foreach ( $messages as $message_id => $message ) {
1503
+    if ($messages) {
1504
+        foreach ($messages as $message_id => $message) {
1505 1505
             // Try and detect what type of message this is
1506
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1506
+            if (strpos(strtolower($message), 'error')) {
1507 1507
                 $type = 'error';
1508
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1508
+            } elseif (strpos(strtolower($message), 'success')) {
1509 1509
                 $type = 'success';
1510 1510
             } else {
1511 1511
                 $type = 'info';
1512 1512
             }
1513 1513
 
1514
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1514
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1515 1515
 
1516
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1516
+            echo '<div class="' . implode(' ', $classes) . '">';
1517 1517
                 // Loop message codes and display messages
1518 1518
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1519 1519
             echo '</div>';
1520 1520
         }
1521 1521
 
1522 1522
         // Remove all of the cart saving messages
1523
-        $wpi_session->set( 'wpinv_cart_messages', null );
1523
+        $wpi_session->set('wpinv_cart_messages', null);
1524 1524
     }
1525 1525
 }
1526
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1526
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1527 1527
 
1528 1528
 function wpinv_discount_field() {
1529
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1529
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1530 1530
         return; // Only show before a payment method has been selected if ajax is disabled
1531 1531
     }
1532 1532
 
1533
-    if ( !wpinv_is_checkout() ) {
1533
+    if (!wpinv_is_checkout()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1537
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1538 1538
     ?>
1539 1539
     <div id="wpinv-discount-field" class="panel panel-default">
1540 1540
         <div class="panel-body">
1541 1541
             <p>
1542
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1543
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1542
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1543
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1544 1544
             </p>
1545 1545
             <div class="form-group row">
1546 1546
                 <div class="col-sm-4">
1547
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1547
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1548 1548
                 </div>
1549 1549
                 <div class="col-sm-3">
1550
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1550
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1551 1551
                 </div>
1552 1552
                 <div style="clear:both"></div>
1553 1553
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1560,10 +1560,10 @@  discard block
 block discarded – undo
1560 1560
 <?php
1561 1561
     }
1562 1562
 }
1563
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1563
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1564 1564
 
1565 1565
 function wpinv_agree_to_terms_js() {
1566
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1566
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1567 1567
 ?>
1568 1568
 <script type="text/javascript">
1569 1569
     jQuery(document).ready(function($){
@@ -1578,126 +1578,126 @@  discard block
 block discarded – undo
1578 1578
 <?php
1579 1579
     }
1580 1580
 }
1581
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1581
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1582 1582
 
1583 1583
 function wpinv_payment_mode_select() {
1584
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1585
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1584
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1585
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1586 1586
     $page_URL = wpinv_get_current_page_url();
1587
-    $invoice = wpinv_get_invoice( 0, true );
1587
+    $invoice = wpinv_get_invoice(0, true);
1588 1588
     
1589 1589
     do_action('wpinv_payment_mode_top');
1590 1590
     $invoice_id = (int)$invoice->ID;
1591
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1591
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1592 1592
     ?>
1593
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1594
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1593
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1594
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1595 1595
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1596
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1596
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1597 1597
                 <div class="panel-body list-group wpi-payment_methods">
1598 1598
                     <?php
1599
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1599
+                    do_action('wpinv_payment_mode_before_gateways');
1600 1600
                     
1601
-                    if(!empty($gateways)){
1602
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1603
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1604
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1605
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1601
+                    if (!empty($gateways)) {
1602
+	                    foreach ($gateways as $gateway_id => $gateway) {
1603
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1604
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1605
+		                    $description = wpinv_get_gateway_description($gateway_id);
1606 1606
 		                    ?>
1607 1607
 		                    <div class="list-group-item">
1608 1608
 			                    <div class="radio">
1609
-				                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1609
+				                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label>
1610 1610
 			                    </div>
1611
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1612
-				                    <?php if ( !empty( $description ) ) { ?>
1613
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1611
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1612
+				                    <?php if (!empty($description)) { ?>
1613
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1614 1614
 				                    <?php } ?>
1615
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1615
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1616 1616
 			                    </div>
1617 1617
 		                    </div>
1618 1618
 		                    <?php
1619 1619
 	                    }
1620
-                    }else{
1621
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1620
+                    } else {
1621
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1622 1622
                     }
1623 1623
 
1624
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1624
+                    do_action('wpinv_payment_mode_after_gateways');
1625 1625
                     ?>
1626 1626
                 </div>
1627 1627
             </div>
1628
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1628
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1629 1629
     </div>
1630 1630
     <?php
1631 1631
     do_action('wpinv_payment_mode_bottom');
1632 1632
 }
1633
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1633
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1634 1634
 
1635 1635
 function wpinv_checkout_billing_info() {    
1636
-    if ( wpinv_is_checkout() ) {
1636
+    if (wpinv_is_checkout()) {
1637 1637
         $logged_in          = is_user_logged_in();
1638 1638
         $billing_details    = wpinv_checkout_billing_details();
1639
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1639
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1640 1640
         ?>
1641 1641
         <div id="wpinv-fields" class="clearfix">
1642 1642
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1643
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1643
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1644 1644
                 <div id="wpinv-fields-box" class="panel-body">
1645
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1645
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1646 1646
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1647
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1647
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1648 1648
                         <?php
1649
-                        echo wpinv_html_text( array(
1649
+                        echo wpinv_html_text(array(
1650 1650
                                 'id'            => 'wpinv_first_name',
1651 1651
                                 'name'          => 'wpinv_first_name',
1652 1652
                                 'value'         => $billing_details['first_name'],
1653 1653
                                 'class'         => 'wpi-input form-control',
1654
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1655
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1656
-                            ) );
1654
+                                'placeholder'   => __('First name', 'invoicing'),
1655
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1656
+                            ));
1657 1657
                         ?>
1658 1658
                     </p>
1659 1659
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1660
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1660
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1661 1661
                         <?php
1662
-                        echo wpinv_html_text( array(
1662
+                        echo wpinv_html_text(array(
1663 1663
                                 'id'            => 'wpinv_last_name',
1664 1664
                                 'name'          => 'wpinv_last_name',
1665 1665
                                 'value'         => $billing_details['last_name'],
1666 1666
                                 'class'         => 'wpi-input form-control',
1667
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1668
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1669
-                            ) );
1667
+                                'placeholder'   => __('Last name', 'invoicing'),
1668
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1669
+                            ));
1670 1670
                         ?>
1671 1671
                     </p>
1672 1672
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1673
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1673
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1674 1674
                         <?php
1675
-                        echo wpinv_html_text( array(
1675
+                        echo wpinv_html_text(array(
1676 1676
                                 'id'            => 'wpinv_address',
1677 1677
                                 'name'          => 'wpinv_address',
1678 1678
                                 'value'         => $billing_details['address'],
1679 1679
                                 'class'         => 'wpi-input form-control',
1680
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1681
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1682
-                            ) );
1680
+                                'placeholder'   => __('Address', 'invoicing'),
1681
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1682
+                            ));
1683 1683
                         ?>
1684 1684
                     </p>
1685 1685
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1686
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1686
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1687 1687
                         <?php
1688
-                        echo wpinv_html_text( array(
1688
+                        echo wpinv_html_text(array(
1689 1689
                                 'id'            => 'wpinv_city',
1690 1690
                                 'name'          => 'wpinv_city',
1691 1691
                                 'value'         => $billing_details['city'],
1692 1692
                                 'class'         => 'wpi-input form-control',
1693
-                                'placeholder'   => __( 'City', 'invoicing' ),
1694
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1695
-                            ) );
1693
+                                'placeholder'   => __('City', 'invoicing'),
1694
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1695
+                            ));
1696 1696
                         ?>
1697 1697
                     </p>
1698 1698
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1699
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1700
-                        <?php echo wpinv_html_select( array(
1699
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1700
+                        <?php echo wpinv_html_select(array(
1701 1701
                             'options'          => wpinv_get_country_list(),
1702 1702
                             'name'             => 'wpinv_country',
1703 1703
                             'id'               => 'wpinv_country',
@@ -1705,16 +1705,16 @@  discard block
 block discarded – undo
1705 1705
                             'show_option_all'  => false,
1706 1706
                             'show_option_none' => false,
1707 1707
                             'class'            => 'wpi-input form-control',
1708
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1709
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1710
-                        ) ); ?>
1708
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1709
+                            'required'         => (bool)wpinv_get_option('country_mandatory'),
1710
+                        )); ?>
1711 1711
                     </p>
1712 1712
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1713
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1713
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1714 1714
                         <?php
1715
-                        $states = wpinv_get_country_states( $selected_country );
1716
-                        if( !empty( $states ) ) {
1717
-                            echo wpinv_html_select( array(
1715
+                        $states = wpinv_get_country_states($selected_country);
1716
+                        if (!empty($states)) {
1717
+                            echo wpinv_html_select(array(
1718 1718
                                 'options'          => $states,
1719 1719
                                 'name'             => 'wpinv_state',
1720 1720
                                 'id'               => 'wpinv_state',
@@ -1722,61 +1722,61 @@  discard block
 block discarded – undo
1722 1722
                                 'show_option_all'  => false,
1723 1723
                                 'show_option_none' => false,
1724 1724
                                 'class'            => 'wpi-input form-control',
1725
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1726
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1727
-                            ) );
1725
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1726
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1727
+                            ));
1728 1728
                         } else {
1729
-                            echo wpinv_html_text( array(
1729
+                            echo wpinv_html_text(array(
1730 1730
                                 'name'          => 'wpinv_state',
1731 1731
                                 'value'         => $billing_details['state'],
1732 1732
                                 'id'            => 'wpinv_state',
1733 1733
                                 'class'         => 'wpi-input form-control',
1734
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1735
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1736
-                            ) );
1734
+                                'placeholder'   => __('State / Province', 'invoicing'),
1735
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1736
+                            ));
1737 1737
                         }
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1741
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1741
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742 1742
                         <?php
1743
-                        echo wpinv_html_text( array(
1743
+                        echo wpinv_html_text(array(
1744 1744
                                 'name'          => 'wpinv_zip',
1745 1745
                                 'value'         => $billing_details['zip'],
1746 1746
                                 'id'            => 'wpinv_zip',
1747 1747
                                 'class'         => 'wpi-input form-control',
1748
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1749
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1750
-                            ) );
1748
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1749
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1750
+                            ));
1751 1751
                         ?>
1752 1752
                     </p>
1753 1753
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1754
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1754
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1755 1755
                         <?php
1756
-                        echo wpinv_html_text( array(
1756
+                        echo wpinv_html_text(array(
1757 1757
                                 'id'            => 'wpinv_phone',
1758 1758
                                 'name'          => 'wpinv_phone',
1759 1759
                                 'value'         => $billing_details['phone'],
1760 1760
                                 'class'         => 'wpi-input form-control',
1761
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1762
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1763
-                            ) );
1761
+                                'placeholder'   => __('Phone', 'invoicing'),
1762
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1763
+                            ));
1764 1764
                         ?>
1765 1765
                     </p>
1766
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1766
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1767 1767
                     <div class="clearfix"></div>
1768 1768
                 </div>
1769 1769
             </div>
1770
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1770
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1771 1771
         </div>
1772 1772
         <?php
1773 1773
     }
1774 1774
 }
1775
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1775
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1776 1776
 
1777 1777
 function wpinv_checkout_hidden_fields() {
1778 1778
 ?>
1779
-    <?php if ( is_user_logged_in() ) { ?>
1779
+    <?php if (is_user_logged_in()) { ?>
1780 1780
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1781 1781
     <?php } ?>
1782 1782
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1786,9 +1786,9 @@  discard block
 block discarded – undo
1786 1786
 function wpinv_checkout_button_purchase() {
1787 1787
     ob_start();
1788 1788
 ?>
1789
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1789
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1790 1790
 <?php
1791
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1791
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1792 1792
 }
1793 1793
 
1794 1794
 function wpinv_checkout_total() {
@@ -1797,96 +1797,96 @@  discard block
 block discarded – undo
1797 1797
 <div id="wpinv_checkout_total" class="panel panel-info">
1798 1798
     <div class="panel-body">
1799 1799
     <?php
1800
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1800
+    do_action('wpinv_purchase_form_before_checkout_total');
1801 1801
     ?>
1802
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1802
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1803 1803
     <?php
1804
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1804
+    do_action('wpinv_purchase_form_after_checkout_total');
1805 1805
     ?>
1806 1806
     </div>
1807 1807
 </div>
1808 1808
 <?php
1809 1809
 }
1810
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1810
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1811 1811
 
1812 1812
 function wpinv_checkout_submit() {
1813 1813
 ?>
1814 1814
 <div id="wpinv_purchase_submit" class="panel panel-success">
1815 1815
     <div class="panel-body text-center">
1816 1816
     <?php
1817
-    do_action( 'wpinv_purchase_form_before_submit' );
1817
+    do_action('wpinv_purchase_form_before_submit');
1818 1818
     wpinv_checkout_hidden_fields();
1819 1819
     echo wpinv_checkout_button_purchase();
1820
-    do_action( 'wpinv_purchase_form_after_submit' );
1820
+    do_action('wpinv_purchase_form_after_submit');
1821 1821
     ?>
1822 1822
     </div>
1823 1823
 </div>
1824 1824
 <?php
1825 1825
 }
1826
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1826
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1827 1827
 
1828
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1829
-    $invoice = wpinv_get_invoice( $invoice_id );
1828
+function wpinv_receipt_billing_address($invoice_id = 0) {
1829
+    $invoice = wpinv_get_invoice($invoice_id);
1830 1830
     
1831
-    if ( empty( $invoice ) ) {
1831
+    if (empty($invoice)) {
1832 1832
         return NULL;
1833 1833
     }
1834 1834
     
1835 1835
     $billing_details = $invoice->get_user_info();
1836 1836
     $address_row = '';
1837
-    if ( $address = $billing_details['address'] ) {
1838
-        $address_row .= wpautop( wp_kses_post( $address ) );
1837
+    if ($address = $billing_details['address']) {
1838
+        $address_row .= wpautop(wp_kses_post($address));
1839 1839
     }
1840 1840
     
1841 1841
     $address_fields = array();
1842
-    if ( !empty( $billing_details['city'] ) ) {
1842
+    if (!empty($billing_details['city'])) {
1843 1843
         $address_fields[] = $billing_details['city'];
1844 1844
     }
1845 1845
     
1846
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1847
-    if ( !empty( $billing_details['state'] ) ) {
1848
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1846
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1847
+    if (!empty($billing_details['state'])) {
1848
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1849 1849
     }
1850 1850
     
1851
-    if ( !empty( $billing_country ) ) {
1852
-        $address_fields[] = wpinv_country_name( $billing_country );
1851
+    if (!empty($billing_country)) {
1852
+        $address_fields[] = wpinv_country_name($billing_country);
1853 1853
     }
1854 1854
     
1855
-    if ( !empty( $address_fields ) ) {
1856
-        $address_fields = implode( ", ", $address_fields );
1855
+    if (!empty($address_fields)) {
1856
+        $address_fields = implode(", ", $address_fields);
1857 1857
         
1858
-        if ( !empty( $billing_details['zip'] ) ) {
1858
+        if (!empty($billing_details['zip'])) {
1859 1859
             $address_fields .= ' ' . $billing_details['zip'];
1860 1860
         }
1861 1861
         
1862
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1862
+        $address_row .= wpautop(wp_kses_post($address_fields));
1863 1863
     }
1864 1864
     ob_start();
1865 1865
     ?>
1866 1866
     <table class="table table-bordered table-sm wpi-billing-details">
1867 1867
         <tbody>
1868 1868
             <tr class="wpi-receipt-name">
1869
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1870
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1869
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1870
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1871 1871
             </tr>
1872 1872
             <tr class="wpi-receipt-email">
1873
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1874
-                <td><?php echo $billing_details['email'] ;?></td>
1873
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1874
+                <td><?php echo $billing_details['email']; ?></td>
1875 1875
             </tr>
1876
-            <?php if ( $billing_details['company'] ) { ?>
1876
+            <?php if ($billing_details['company']) { ?>
1877 1877
             <tr class="wpi-receipt-company">
1878
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1879
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1878
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1879
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1880 1880
             </tr>
1881 1881
             <?php } ?>
1882 1882
             <tr class="wpi-receipt-address">
1883
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1884
-                <td><?php echo $address_row ;?></td>
1883
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1884
+                <td><?php echo $address_row; ?></td>
1885 1885
             </tr>
1886
-            <?php if ( $billing_details['phone'] ) { ?>
1886
+            <?php if ($billing_details['phone']) { ?>
1887 1887
             <tr class="wpi-receipt-phone">
1888
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1889
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1888
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1889
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1890 1890
             </tr>
1891 1891
             <?php } ?>
1892 1892
         </tbody>
@@ -1894,98 +1894,98 @@  discard block
 block discarded – undo
1894 1894
     <?php
1895 1895
     $output = ob_get_clean();
1896 1896
     
1897
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1897
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1898 1898
 
1899 1899
     echo $output;
1900 1900
 }
1901 1901
 
1902
-function wpinv_filter_success_page_content( $content ) {
1903
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1904
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1905
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1902
+function wpinv_filter_success_page_content($content) {
1903
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1904
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1905
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1906 1906
         }
1907 1907
     }
1908 1908
 
1909 1909
     return $content;
1910 1910
 }
1911
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1911
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1912 1912
 
1913
-function wpinv_receipt_actions( $invoice ) {
1914
-    if ( !empty( $invoice ) ) {
1913
+function wpinv_receipt_actions($invoice) {
1914
+    if (!empty($invoice)) {
1915 1915
         $actions = array(
1916 1916
             'print'   => array(
1917 1917
                 'url'  => $invoice->get_view_url(),
1918
-                'name' => __( 'Print Invoice', 'invoicing' ),
1918
+                'name' => __('Print Invoice', 'invoicing'),
1919 1919
                 'class' => 'btn-primary',
1920 1920
             ),
1921 1921
             'history'   => array(
1922 1922
                 'url'  => wpinv_get_history_page_uri(),
1923
-                'name' => __( 'Invoice History', 'invoicing' ),
1923
+                'name' => __('Invoice History', 'invoicing'),
1924 1924
                 'class' => 'btn-warning',
1925 1925
             )
1926 1926
         );
1927 1927
 
1928
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1928
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1929 1929
         
1930
-        if ( !empty( $actions ) ) {
1930
+        if (!empty($actions)) {
1931 1931
         ?>
1932 1932
         <div class="wpinv-receipt-actions text-right">
1933
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1934
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1933
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1934
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1935 1935
             <?php } ?>
1936 1936
         </div>
1937 1937
         <?php
1938 1938
         }
1939 1939
     }
1940 1940
 }
1941
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1941
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1942 1942
 
1943
-function wpinv_invoice_link( $invoice_id ) {
1944
-    $invoice = wpinv_get_invoice( $invoice_id );
1943
+function wpinv_invoice_link($invoice_id) {
1944
+    $invoice = wpinv_get_invoice($invoice_id);
1945 1945
     
1946
-    if ( empty( $invoice ) ) {
1946
+    if (empty($invoice)) {
1947 1947
         return NULL;
1948 1948
     }
1949 1949
     
1950
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1950
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1951 1951
     
1952
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1952
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1953 1953
 }
1954 1954
 
1955
-function wpinv_invoice_subscription_details( $invoice ) {
1956
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1955
+function wpinv_invoice_subscription_details($invoice) {
1956
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1957 1957
         $total_payments = (int)$invoice->get_total_payments();
1958 1958
         $payments       = $invoice->get_child_payments();
1959 1959
         
1960 1960
         $subscription   = $invoice->get_subscription_data();
1961 1961
         
1962
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1962
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1963 1963
             return;
1964 1964
         }
1965 1965
         
1966
-        $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
1967
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1966
+        $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
1967
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1968 1968
         
1969 1969
         $subscription_status = $invoice->get_subscription_status();
1970 1970
         
1971 1971
         $status_desc = '';
1972
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1973
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1974
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1975
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1972
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1973
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1974
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1975
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1976 1976
         }
1977 1977
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1978 1978
         ?>
1979 1979
         <div class="wpinv-subscriptions-details">
1980
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1980
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1981 1981
             <table class="table">
1982 1982
                 <thead>
1983 1983
                     <tr>
1984
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1985
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1986
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1987
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1988
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1984
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1985
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1986
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1987
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1988
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1989 1989
                     </tr>
1990 1990
                 </thead>
1991 1991
                 <tbody>
@@ -1994,32 +1994,32 @@  discard block
 block discarded – undo
1994 1994
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1995 1995
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1996 1996
                         <td class="text-center"><?php echo $times_billed; ?></td>
1997
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1997
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1998 1998
                         <?php echo $status_desc; ?>
1999 1999
                         </td>
2000 2000
                     </tr>
2001 2001
                 </tbody>
2002 2002
             </table>
2003 2003
         </div>
2004
-        <?php if ( !empty( $payments ) ) { ?>
2004
+        <?php if (!empty($payments)) { ?>
2005 2005
         <div class="wpinv-renewal-payments">
2006
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2006
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2007 2007
             <table class="table">
2008 2008
                 <thead>
2009 2009
                     <tr>
2010 2010
                         <th>#</th>
2011
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2012
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2013
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2011
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2012
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2013
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
2017
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2017
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2018 2018
                     <tr>
2019
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2020
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2021
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2022
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2019
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2020
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2021
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2022
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2023 2023
                     </tr>
2024 2024
                     <?php } ?>
2025 2025
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2031,52 +2031,52 @@  discard block
 block discarded – undo
2031 2031
     }
2032 2032
 }
2033 2033
 
2034
-function wpinv_cart_total_label( $label, $invoice ) {
2035
-    if ( empty( $invoice ) ) {
2034
+function wpinv_cart_total_label($label, $invoice) {
2035
+    if (empty($invoice)) {
2036 2036
         return $label;
2037 2037
     }
2038 2038
     
2039 2039
     $prefix_label = '';
2040
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2041
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2042
-    } else if ( $invoice->is_renewal() ) {
2043
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2040
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2041
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2042
+    } else if ($invoice->is_renewal()) {
2043
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2044 2044
     }
2045 2045
     
2046
-    if ( $prefix_label != '' ) {
2047
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2046
+    if ($prefix_label != '') {
2047
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2048 2048
     }
2049 2049
     
2050 2050
     return $label;
2051 2051
 }
2052
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2053
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2054
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2052
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2053
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2054
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2055 2055
 
2056
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2056
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2057 2057
 
2058
-function wpinv_invoice_print_description( $invoice ) {
2059
-    if ( empty( $invoice ) ) {
2058
+function wpinv_invoice_print_description($invoice) {
2059
+    if (empty($invoice)) {
2060 2060
         return NULL;
2061 2061
     }
2062
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2062
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2063 2063
         ?>
2064 2064
         <div class="row wpinv-lower">
2065 2065
             <div class="col-sm-12 wpinv-description">
2066
-                <?php echo wpautop( $description ); ?>
2066
+                <?php echo wpautop($description); ?>
2067 2067
             </div>
2068 2068
         </div>
2069 2069
         <?php
2070 2070
     }
2071 2071
 }
2072
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2072
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2073 2073
 
2074
-function wpinv_invoice_print_payment_info( $invoice ) {
2075
-    if ( empty( $invoice ) ) {
2074
+function wpinv_invoice_print_payment_info($invoice) {
2075
+    if (empty($invoice)) {
2076 2076
         return NULL;
2077 2077
     }
2078 2078
     
2079
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2079
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2080 2080
         ?>
2081 2081
         <div class="row wpinv-payments">
2082 2082
             <div class="col-sm-12">
@@ -2088,43 +2088,43 @@  discard block
 block discarded – undo
2088 2088
 }
2089 2089
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2090 2090
 
2091
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2092
-    if ( empty( $note ) ) {
2091
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2092
+    if (empty($note)) {
2093 2093
         return NULL;
2094 2094
     }
2095 2095
     
2096
-    if ( is_int( $note ) ) {
2097
-        $note = get_comment( $note );
2096
+    if (is_int($note)) {
2097
+        $note = get_comment($note);
2098 2098
     }
2099 2099
     
2100
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2100
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2101 2101
         return NULL;
2102 2102
     }
2103 2103
     
2104
-    $note_classes   = array( 'note' );
2105
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2106
-    $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : '';
2107
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2108
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2104
+    $note_classes   = array('note');
2105
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2106
+    $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : '';
2107
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2108
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2109 2109
     
2110 2110
     ob_start();
2111 2111
     ?>
2112
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2112
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2113 2113
         <div class="note_content">
2114
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2114
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2115 2115
         </div>
2116 2116
         <p class="meta">
2117
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2118
-            <?php if($note->comment_author !== 'System') {?>
2119
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2117
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2118
+            <?php if ($note->comment_author !== 'System') {?>
2119
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2120 2120
             <?php } ?>
2121 2121
         </p>
2122 2122
     </li>
2123 2123
     <?php
2124 2124
     $note_content = ob_get_clean();
2125
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2125
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2126 2126
     
2127
-    if ( $echo ) {
2127
+    if ($echo) {
2128 2128
         echo $note_content;
2129 2129
     } else {
2130 2130
         return $note_content;
Please login to merge, or discard this patch.
includes/class-wpinv-shortcodes.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
             'wpinv_receipt'  => __CLASS__ . '::receipt',
15 15
         );
16 16
 
17
-        foreach ( $shortcodes as $shortcode => $function ) {
18
-            add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
17
+        foreach ($shortcodes as $shortcode => $function) {
18
+            add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function);
19 19
         }
20 20
         
21
-        add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' );
21
+        add_shortcode('wpinv_messages', __CLASS__ . '::messages');
22 22
     }
23 23
 
24 24
     public static function shortcode_wrapper(
@@ -32,25 +32,25 @@  discard block
 block discarded – undo
32 32
     ) {
33 33
         ob_start();
34 34
 
35
-        echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
36
-        call_user_func( $function, $atts );
37
-        echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
35
+        echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before'];
36
+        call_user_func($function, $atts);
37
+        echo empty($wrapper['after']) ? '</div>' : $wrapper['after'];
38 38
 
39 39
         return ob_get_clean();
40 40
     }
41 41
 
42
-    public static function checkout( $atts = array(), $content = null ) {
43
-        return wpinv_checkout_form( $atts, $content );
42
+    public static function checkout($atts = array(), $content = null) {
43
+        return wpinv_checkout_form($atts, $content);
44 44
     }
45 45
 
46
-    public static function messages( $atts, $content = null ) {
46
+    public static function messages($atts, $content = null) {
47 47
         ob_start();
48 48
         wpinv_print_errors();
49 49
         return '<div class="wpinv">' . ob_get_clean() . '</div>';
50 50
     }
51 51
     
52
-    public static function history( $atts, $content = null ) {
53
-        return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts );
52
+    public static function history($atts, $content = null) {
53
+        return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts);
54 54
     }
55 55
 
56 56
     /**
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @param array $atts
60 60
      */
61
-    public static function history_output( $atts ) {
62
-        do_action( 'wpinv_before_user_invoice_history' );
63
-        wpinv_get_template_part( 'wpinv-invoice-history', $atts );
64
-        do_action( 'wpinv_after_user_invoice_history' );
61
+    public static function history_output($atts) {
62
+        do_action('wpinv_before_user_invoice_history');
63
+        wpinv_get_template_part('wpinv-invoice-history', $atts);
64
+        do_action('wpinv_after_user_invoice_history');
65 65
     }
66 66
     
67
-    public static function receipt( $atts, $content = null ) {
68
-        return wpinv_payment_receipt( $atts, $content );
67
+    public static function receipt($atts, $content = null) {
68
+        return wpinv_payment_receipt($atts, $content);
69 69
     }
70 70
 }
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +490 added lines, -490 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, $tax_settings, $tool_settings );
83
+        $settings = array_merge($general_settings, $gateways_settings, $tax_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,42 +111,42 @@  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
-                        'chosen'      => isset( $option['chosen'] )      ? $option['chosen']      : null,
141
-                        'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
142
-                        'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
143
-                        'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
144
-                        'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
145
-                        'onchange'    => !empty( $option['onchange'] )   ? $option['onchange']    : '',
146
-                        'custom'      => !empty( $option['custom'] )     ? $option['custom']      : '',
147
-                        'class'       =>  !empty( $option['class'] )     ? $option['class']      : '',
148
-                        'cols'        => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
-                        '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
+                        'chosen'      => isset($option['chosen']) ? $option['chosen'] : null,
141
+                        'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
142
+                        'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
143
+                        'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
144
+                        'faux'        => isset($option['faux']) ? $option['faux'] : false,
145
+                        'onchange'    => !empty($option['onchange']) ? $option['onchange'] : '',
146
+                        'custom'      => !empty($option['custom']) ? $option['custom'] : '',
147
+                        'class'       =>  !empty($option['class']) ? $option['class'] : '',
148
+                        'cols'        => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
+                        'rows'        => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
150 150
                     )
151 151
                 );
152 152
             }
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
     }
155 155
 
156 156
     // Creates our settings in the options table
157
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
157
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
158 158
 }
159
-add_action( 'admin_init', 'wpinv_register_settings' );
159
+add_action('admin_init', 'wpinv_register_settings');
160 160
 
161 161
 function wpinv_get_registered_settings() {
162
-    $pages = wpinv_get_pages( true );
162
+    $pages = wpinv_get_pages(true);
163 163
     
164 164
     $due_payment_options       = array();
165
-    $due_payment_options[0]    = __( 'Now', 'invoicing' );
166
-    for ( $i = 1; $i <= 30; $i++ ) {
165
+    $due_payment_options[0]    = __('Now', 'invoicing');
166
+    for ($i = 1; $i <= 30; $i++) {
167 167
         $due_payment_options[$i] = $i;
168 168
     }
169 169
     
170 170
     $invoice_number_padd_options = array();
171
-    for ( $i = 0; $i <= 20; $i++ ) {
171
+    for ($i = 0; $i <= 20; $i++) {
172 172
         $invoice_number_padd_options[$i] = $i;
173 173
     }
174 174
     
@@ -177,141 +177,141 @@  discard block
 block discarded – undo
177 177
     $alert_wrapper_start = '<p style="color: #F00">';
178 178
     $alert_wrapper_close = '</p>';
179 179
     $wpinv_settings = array(
180
-        'general' => apply_filters( 'wpinv_settings_general',
180
+        'general' => apply_filters('wpinv_settings_general',
181 181
             array(
182 182
                 'main' => array(
183 183
                     'location_settings' => array(
184 184
                         'id'   => 'location_settings',
185
-                        'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
185
+                        'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
186 186
                         'desc' => '',
187 187
                         'type' => 'header',
188 188
                     ),
189 189
                     'default_country' => array(
190 190
                         'id'      => 'default_country',
191
-                        'name'    => __( 'Default Country', 'invoicing' ),
192
-                        'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
191
+                        'name'    => __('Default Country', 'invoicing'),
192
+                        'desc'    => __('Where does your store operate from?', 'invoicing'),
193 193
                         'type'    => 'select',
194 194
                         'options' => wpinv_get_country_list(),
195 195
                         'std'     => 'GB',
196 196
                         'chosen'  => true,
197
-                        'placeholder' => __( 'Select a country', 'invoicing' ),
197
+                        'placeholder' => __('Select a country', 'invoicing'),
198 198
                     ),
199 199
                     'default_state' => array(
200 200
                         'id'      => 'default_state',
201
-                        'name'    => __( 'Default State / Province', 'invoicing' ),
202
-                        'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
201
+                        'name'    => __('Default State / Province', 'invoicing'),
202
+                        'desc'    => __('What state / province does your store operate from?', 'invoicing'),
203 203
                         'type'    => 'country_states',
204
-                        'placeholder' => __( 'Select a state', 'invoicing' ),
204
+                        'placeholder' => __('Select a state', 'invoicing'),
205 205
                     ),
206 206
                     'store_name' => array(
207 207
                         'id'   => 'store_name',
208
-                        'name' => __( 'Store Name', 'invoicing' ),
209
-                        'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
208
+                        'name' => __('Store Name', 'invoicing'),
209
+                        'desc' => __('Store name to print on invoices.', 'invoicing'),
210 210
                         'std'     => get_option('blogname'),
211 211
                         'type' => 'text',
212 212
                     ),
213 213
                     'logo' => array(
214 214
                         'id'   => 'logo',
215
-                        'name' => __( 'Logo URL', 'invoicing' ),
216
-                        'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
215
+                        'name' => __('Logo URL', 'invoicing'),
216
+                        'desc' => __('Store logo to print on invoices.', 'invoicing'),
217 217
                         'type' => 'text',
218 218
                     ),
219 219
                     'store_address' => array(
220 220
                         'id'   => 'store_address',
221
-                        'name' => __( 'Store Address', 'invoicing' ),
222
-                        'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
221
+                        'name' => __('Store Address', 'invoicing'),
222
+                        'desc' => __('Enter the store address to display on invoice', 'invoicing'),
223 223
                         'type' => 'textarea',
224 224
                     ),
225 225
                     'page_settings' => array(
226 226
                         'id'   => 'page_settings',
227
-                        'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
227
+                        'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
228 228
                         'desc' => '',
229 229
                         'type' => 'header',
230 230
                     ),
231 231
                     'checkout_page' => array(
232 232
                         'id'          => 'checkout_page',
233
-                        'name'        => __( 'Checkout Page', 'invoicing' ),
234
-                        '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' ),
233
+                        'name'        => __('Checkout Page', 'invoicing'),
234
+                        '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'),
235 235
                         'type'        => 'select',
236 236
                         'options'     => $pages,
237 237
                         'chosen'      => true,
238
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
238
+                        'placeholder' => __('Select a page', 'invoicing'),
239 239
                     ),
240 240
                     'success_page' => array(
241 241
                         'id'          => 'success_page',
242
-                        'name'        => __( 'Success Page', 'invoicing' ),
243
-                        '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' ),
242
+                        'name'        => __('Success Page', 'invoicing'),
243
+                        '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'),
244 244
                         'type'        => 'select',
245 245
                         'options'     => $pages,
246 246
                         'chosen'      => true,
247
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
247
+                        'placeholder' => __('Select a page', 'invoicing'),
248 248
                     ),
249 249
                     'failure_page' => array(
250 250
                         'id'          => 'failure_page',
251
-                        'name'        => __( 'Failed Transaction Page', 'invoicing' ),
252
-                        'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing' ),
251
+                        'name'        => __('Failed Transaction Page', 'invoicing'),
252
+                        'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing'),
253 253
                         'type'        => 'select',
254 254
                         'options'     => $pages,
255 255
                         'chosen'      => true,
256
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
256
+                        'placeholder' => __('Select a page', 'invoicing'),
257 257
                     ),
258 258
                     'invoice_history_page' => array(
259 259
                         'id'          => 'invoice_history_page',
260
-                        'name'        => __( 'Invoice History Page', 'invoicing' ),
261
-                        'desc'        => __( 'This page shows an invoice history for the current user', 'invoicing' ),
260
+                        'name'        => __('Invoice History Page', 'invoicing'),
261
+                        'desc'        => __('This page shows an invoice history for the current user', 'invoicing'),
262 262
                         'type'        => 'select',
263 263
                         'options'     => $pages,
264 264
                         'chosen'      => true,
265
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
265
+                        'placeholder' => __('Select a page', 'invoicing'),
266 266
                     )
267 267
                 ),
268 268
                 'currency_section' => array(
269 269
                     'currency_settings' => array(
270 270
                         'id'   => 'currency_settings',
271
-                        'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
271
+                        'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
272 272
                         'desc' => '',
273 273
                         'type' => 'header',
274 274
                     ),
275 275
                     'currency' => array(
276 276
                         'id'      => 'currency',
277
-                        'name'    => __( 'Currency', 'invoicing' ),
278
-                        'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
277
+                        'name'    => __('Currency', 'invoicing'),
278
+                        'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
279 279
                         'type'    => 'select',
280 280
                         'options' => wpinv_get_currencies(),
281 281
                         'chosen'  => true,
282 282
                     ),
283 283
                     'currency_position' => array(
284 284
                         'id'      => 'currency_position',
285
-                        'name'    => __( 'Currency Position', 'invoicing' ),
286
-                        'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
285
+                        'name'    => __('Currency Position', 'invoicing'),
286
+                        'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
287 287
                         'type'    => 'select',
288 288
                         'options'  => array(
289
-                            'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
290
-                            'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
291
-                            'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
292
-                            'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
289
+                            'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
290
+                            'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
291
+                            'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
292
+                            'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
293 293
                         )
294 294
                     ),
295 295
                     'thousands_separator' => array(
296 296
                         'id'   => 'thousands_separator',
297
-                        'name' => __( 'Thousands Separator', 'invoicing' ),
298
-                        'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
297
+                        'name' => __('Thousands Separator', 'invoicing'),
298
+                        'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
299 299
                         'type' => 'text',
300 300
                         'size' => 'small',
301 301
                         'std'  => ',',
302 302
                     ),
303 303
                     'decimal_separator' => array(
304 304
                         'id'   => 'decimal_separator',
305
-                        'name' => __( 'Decimal Separator', 'invoicing' ),
306
-                        'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
305
+                        'name' => __('Decimal Separator', 'invoicing'),
306
+                        'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
307 307
                         'type' => 'text',
308 308
                         'size' => 'small',
309 309
                         'std'  => '.',
310 310
                     ),
311 311
                     'decimals' => array(
312 312
                         'id'   => 'decimals',
313
-                        'name' => __( 'Number of Decimals', 'invoicing' ),
314
-                        'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
313
+                        'name' => __('Number of Decimals', 'invoicing'),
314
+                        'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
315 315
                         'type' => 'number',
316 316
                         'size' => 'small',
317 317
                         'std'  => '2',
@@ -323,29 +323,29 @@  discard block
 block discarded – undo
323 323
                 'labels' => array(
324 324
                     'labels' => array(
325 325
                         'id'   => 'labels_settings',
326
-                        'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
326
+                        'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
327 327
                         'desc' => '',
328 328
                         'type' => 'header',
329 329
                     ),
330 330
                     'vat_name' => array(
331 331
                         'id' => 'vat_name',
332
-                        'name' => __( 'VAT Name', 'invoicing' ),
333
-                        'desc' => __( 'Enter the VAT name', 'invoicing' ),
332
+                        'name' => __('VAT Name', 'invoicing'),
333
+                        'desc' => __('Enter the VAT name', 'invoicing'),
334 334
                         'type' => 'text',
335 335
                         'size' => 'regular',
336 336
                         'std' => 'VAT'
337 337
                     ),
338 338
                     'vat_invoice_notice_label' => array(
339 339
                         'id' => 'vat_invoice_notice_label',
340
-                        'name' => __( 'Invoice Notice Label', 'invoicing' ),
341
-                        'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ),
340
+                        'name' => __('Invoice Notice Label', 'invoicing'),
341
+                        'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'),
342 342
                         'type' => 'text',
343 343
                         'size' => 'regular',
344 344
                     ),
345 345
                     'vat_invoice_notice' => array(
346 346
                         'id' => 'vat_invoice_notice',
347
-                        'name' => __( 'Invoice notice', 'invoicing' ),
348
-                        'desc' =>   __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ),
347
+                        'name' => __('Invoice notice', 'invoicing'),
348
+                        'desc' =>   __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'),
349 349
                         'type' => 'text',
350 350
                         'size' => 'regular',
351 351
                     )
@@ -357,22 +357,22 @@  discard block
 block discarded – undo
357 357
                 'main' => array(
358 358
                     'gateway_settings' => array(
359 359
                         'id'   => 'api_header',
360
-                        'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
360
+                        'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
361 361
                         'desc' => '',
362 362
                         'type' => 'header',
363 363
                     ),
364 364
                     'gateways' => array(
365 365
                         'id'      => 'gateways',
366
-                        'name'    => __( 'Payment Gateways', 'invoicing' ),
367
-                        'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
366
+                        'name'    => __('Payment Gateways', 'invoicing'),
367
+                        'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
368 368
                         'type'    => 'gateways',
369 369
                         'std'     => array('manual'=>1),
370 370
                         'options' => wpinv_get_payment_gateways(),
371 371
                     ),
372 372
                     'default_gateway' => array(
373 373
                         'id'      => 'default_gateway',
374
-                        'name'    => __( 'Default Gateway', 'invoicing' ),
375
-                        'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
374
+                        'name'    => __('Default Gateway', 'invoicing'),
375
+                        'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
376 376
                         'type'    => 'gateway_select',
377 377
                         'std'     => 'manual',
378 378
                         'options' => wpinv_get_payment_gateways(),
@@ -386,19 +386,19 @@  discard block
 block discarded – undo
386 386
                 'main' => array(
387 387
                     'tax_settings' => array(
388 388
                         'id'   => 'tax_settings',
389
-                        'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
389
+                        'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
390 390
                         'type' => 'header',
391 391
                     ),
392 392
                     'enable_taxes' => array(
393 393
                         'id'   => 'enable_taxes',
394
-                        'name' => __( 'Enable Taxes', 'invoicing' ),
395
-                        'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
394
+                        'name' => __('Enable Taxes', 'invoicing'),
395
+                        'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
396 396
                         'type' => 'checkbox',
397 397
                     ),
398 398
                     'tax_rate' => array(
399 399
                         'id'   => 'tax_rate',
400
-                        'name' => __( 'Fallback Tax Rate', 'invoicing' ),
401
-                        'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
400
+                        'name' => __('Fallback Tax Rate', 'invoicing'),
401
+                        'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
402 402
                         'type' => 'number',
403 403
                         'size' => 'small',
404 404
                         'min'  => '0',
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
                 'rates' => array(
411 411
                     'tax_rates' => array(
412 412
                         'id'   => 'tax_rates',
413
-                        'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
414
-                        'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
413
+                        'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
414
+                        'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
415 415
                         'type' => 'tax_rates',
416 416
                     ),
417 417
                 )
@@ -423,62 +423,62 @@  discard block
 block discarded – undo
423 423
                 'main' => array(
424 424
                     'email_settings_header' => array(
425 425
                         'id'   => 'email_settings_header',
426
-                        'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
426
+                        'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
427 427
                         'type' => 'header',
428 428
                     ),
429 429
                     'email_from_name' => array(
430 430
                         'id'   => 'email_from_name',
431
-                        'name' => __( 'From Name', 'invoicing' ),
432
-                        'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
433
-                        'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
431
+                        'name' => __('From Name', 'invoicing'),
432
+                        'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
433
+                        'std' => esc_attr(get_bloginfo('name', 'display')),
434 434
                         'type' => 'text',
435 435
                     ),
436 436
                     'email_from' => array(
437 437
                         'id'   => 'email_from',
438
-                        'name' => __( 'From Email', 'invoicing' ),
439
-                        '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),
440
-                        'std' => get_option( 'admin_email' ),
438
+                        'name' => __('From Email', 'invoicing'),
439
+                        '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),
440
+                        'std' => get_option('admin_email'),
441 441
                         'type' => 'text',
442 442
                     ),
443 443
                     'overdue_settings_header' => array(
444 444
                         'id'   => 'overdue_settings_header',
445
-                        'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
445
+                        'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
446 446
                         'type' => 'header',
447 447
                     ),
448 448
                     'overdue_active' => array(
449 449
                         'id'   => 'overdue_active',
450
-                        'name' => __( 'Enable Due Date', 'invoicing' ),
451
-                        'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
450
+                        'name' => __('Enable Due Date', 'invoicing'),
451
+                        'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
452 452
                         'type' => 'checkbox',
453 453
                         'std'  => false,
454 454
                     ),
455 455
                     'overdue_days' => array(
456 456
                         'id'          => 'overdue_days',
457
-                        'name'        => __( 'Default Due Date', 'invoicing' ),
458
-                        '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' ),
457
+                        'name'        => __('Default Due Date', 'invoicing'),
458
+                        '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'),
459 459
                         'type'        => 'select',
460 460
                         'options'     => $due_payment_options,
461 461
                         'chosen'      => true,
462 462
                         'std'         => 0,
463
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
463
+                        'placeholder' => __('Select a page', 'invoicing'),
464 464
                     ),
465 465
                     'email_template_header' => array(
466 466
                         'id'   => 'email_template_header',
467
-                        'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
467
+                        'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
468 468
                         'type' => 'header',
469 469
                     ),
470 470
                     'email_header_image' => array(
471 471
                         'id'   => 'email_header_image',
472
-                        'name' => __( 'Header Image', 'invoicing' ),
473
-                        'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
472
+                        'name' => __('Header Image', 'invoicing'),
473
+                        'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
474 474
                         'std' => '',
475 475
                         'type' => 'text',
476 476
                     ),
477 477
                     'email_footer_text' => array(
478 478
                         'id'   => 'email_footer_text',
479
-                        'name' => __( 'Footer Text', 'invoicing' ),
480
-                        'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
481
-                        'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
479
+                        'name' => __('Footer Text', 'invoicing'),
480
+                        'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
481
+                        'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
482 482
                         'type' => 'textarea',
483 483
                         'class' => 'regular-text',
484 484
                         'rows' => 2,
@@ -486,29 +486,29 @@  discard block
 block discarded – undo
486 486
                     ),
487 487
                     'email_base_color' => array(
488 488
                         'id'   => 'email_base_color',
489
-                        'name' => __( 'Base Color', 'invoicing' ),
490
-                        'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
489
+                        'name' => __('Base Color', 'invoicing'),
490
+                        'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
491 491
                         'std' => '#557da2',
492 492
                         'type' => 'color',
493 493
                     ),
494 494
                     'email_background_color' => array(
495 495
                         'id'   => 'email_background_color',
496
-                        'name' => __( 'Background Color', 'invoicing' ),
497
-                        'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
496
+                        'name' => __('Background Color', 'invoicing'),
497
+                        'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
498 498
                         'std' => '#f5f5f5',
499 499
                         'type' => 'color',
500 500
                     ),
501 501
                     'email_body_background_color' => array(
502 502
                         'id'   => 'email_body_background_color',
503
-                        'name' => __( 'Body Background Color', 'invoicing' ),
504
-                        'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
503
+                        'name' => __('Body Background Color', 'invoicing'),
504
+                        'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
505 505
                         'std' => '#fdfdfd',
506 506
                         'type' => 'color',
507 507
                     ),
508 508
                     'email_text_color' => array(
509 509
                         'id'   => 'email_text_color',
510
-                        'name' => __( 'Body Text Color', 'invoicing' ),
511
-                        'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
510
+                        'name' => __('Body Text Color', 'invoicing'),
511
+                        'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
512 512
                         'std' => '#505050',
513 513
                         'type' => 'color',
514 514
                     ),
@@ -527,73 +527,73 @@  discard block
 block discarded – undo
527 527
                 'main' => array(
528 528
                     'fields_settings' => array(
529 529
                         'id'   => 'fields_settings',
530
-                        'name' => '<h3>' . __( 'Fields Settings', 'invoicing' ) . '</h3>',
531
-                        'desc' => __( 'Tick fields which are mandatory in invoice address fields.', 'invoicing' ),
530
+                        'name' => '<h3>' . __('Fields Settings', 'invoicing') . '</h3>',
531
+                        'desc' => __('Tick fields which are mandatory in invoice address fields.', 'invoicing'),
532 532
                         'type' => 'header',
533 533
                     ),
534 534
                     'fname_mandatory' => array(
535 535
                         'id'   => 'fname_mandatory',
536
-                        'name' => __( 'First Name', 'invoicing' ),
536
+                        'name' => __('First Name', 'invoicing'),
537 537
                         'type' => 'checkbox',
538 538
                         'std'  => true,
539 539
                     ),
540 540
                     'lname_mandatory' => array(
541 541
                         'id'   => 'lname_mandatory',
542
-                        'name' => __( 'Last Name', 'invoicing' ),
542
+                        'name' => __('Last Name', 'invoicing'),
543 543
                         'type' => 'checkbox',
544 544
                         'std'  => true,
545 545
                     ),
546 546
                     'address_mandatory' => array(
547 547
                         'id'   => 'address_mandatory',
548
-                        'name' => __( 'Address', 'invoicing' ),
548
+                        'name' => __('Address', 'invoicing'),
549 549
                         'type' => 'checkbox',
550 550
                         'std'  => true,
551 551
                     ),
552 552
                     'city_mandatory' => array(
553 553
                         'id'   => 'city_mandatory',
554
-                        'name' => __( 'City', 'invoicing' ),
554
+                        'name' => __('City', 'invoicing'),
555 555
                         'type' => 'checkbox',
556 556
                         'std'  => true,
557 557
                     ),
558 558
                     'country_mandatory' => array(
559 559
                         'id'   => 'country_mandatory',
560
-                        'name' => __( 'Country', 'invoicing' ),
560
+                        'name' => __('Country', 'invoicing'),
561 561
                         'type' => 'checkbox',
562 562
                         'std'  => true,
563 563
                     ),
564 564
                     'state_mandatory' => array(
565 565
                         'id'   => 'state_mandatory',
566
-                        'name' => __( 'State / Province', 'invoicing' ),
566
+                        'name' => __('State / Province', 'invoicing'),
567 567
                         'type' => 'checkbox',
568 568
                         'std'  => true,
569 569
                     ),
570 570
                     'zip_mandatory' => array(
571 571
                         'id'   => 'zip_mandatory',
572
-                        'name' => __( 'ZIP / Postcode', 'invoicing' ),
572
+                        'name' => __('ZIP / Postcode', 'invoicing'),
573 573
                         'type' => 'checkbox',
574 574
                         'std'  => true,
575 575
                     ),
576 576
                     'phone_mandatory' => array(
577 577
                         'id'   => 'phone_mandatory',
578
-                        'name' => __( 'Phone Number', 'invoicing' ),
578
+                        'name' => __('Phone Number', 'invoicing'),
579 579
                         'type' => 'checkbox',
580 580
                         'std'  => true,
581 581
                     ),
582 582
                     'invoice_number_format_settings' => array(
583 583
                         'id'   => 'invoice_number_format_settings',
584
-                        'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
584
+                        'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
585 585
                         'type' => 'header',
586 586
                     ),
587 587
                     'sequential_invoice_number' => array(
588 588
                         'id'   => 'sequential_invoice_number',
589
-                        'name' => __( 'Sequential Invoice Numbers', 'invoicing' ),
590
-                        'desc' => __( 'Check this box to enable sequential invoice numbers.', 'invoicing' ),
589
+                        'name' => __('Sequential Invoice Numbers', 'invoicing'),
590
+                        'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing'),
591 591
                         'type' => 'checkbox',
592 592
                     ),
593 593
                     'invoice_sequence_start' => array(
594 594
                         'id'   => 'invoice_sequence_start',
595
-                        'name' => __( 'Sequential Starting Number', 'easy-digital-downloads' ),
596
-                        'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ),
595
+                        'name' => __('Sequential Starting Number', 'easy-digital-downloads'),
596
+                        'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing'),
597 597
                         'type' => 'number',
598 598
                         'size' => 'small',
599 599
                         'std'  => '1',
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
                     ),
602 602
                     'invoice_number_padd' => array(
603 603
                         'id'      => 'invoice_number_padd',
604
-                        'name'    => __( 'Minimum Digits', 'invoicing' ),
605
-                        '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' ),
604
+                        'name'    => __('Minimum Digits', 'invoicing'),
605
+                        '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'),
606 606
                         'type'    => 'select',
607 607
                         'options' => $invoice_number_padd_options,
608 608
                         'std'     => 5,
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
                     ),
611 611
                     'invoice_number_prefix' => array(
612 612
                         'id' => 'invoice_number_prefix',
613
-                        'name' => __( 'Invoice Number Prefix', 'invoicing' ),
614
-                        'desc' => __( 'Prefix for all invoice numbers. Ex: WPINV-', 'invoicing' ),
613
+                        'name' => __('Invoice Number Prefix', 'invoicing'),
614
+                        'desc' => __('Prefix for all invoice numbers. Ex: WPINV-', 'invoicing'),
615 615
                         'type' => 'text',
616 616
                         'size' => 'regular',
617 617
                         'std' => 'WPINV-',
@@ -619,25 +619,25 @@  discard block
 block discarded – undo
619 619
                     ),
620 620
                     'invoice_number_postfix' => array(
621 621
                         'id' => 'invoice_number_postfix',
622
-                        'name' => __( 'Invoice Number Postfix', 'invoicing' ),
623
-                        'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ),
622
+                        'name' => __('Invoice Number Postfix', 'invoicing'),
623
+                        'desc' => __('Postfix for all invoice numbers.', 'invoicing'),
624 624
                         'type' => 'text',
625 625
                         'size' => 'regular',
626 626
                         'std' => ''
627 627
                     ),
628 628
                     'guest_checkout_settings' => array(
629 629
                         'id'   => 'guest_checkout_settings',
630
-                        'name' => '<h3>' . __( 'Pay via Invoice Link', 'invoicing' ) . '</h3>',
630
+                        'name' => '<h3>' . __('Pay via Invoice Link', 'invoicing') . '</h3>',
631 631
                         'type' => 'header',
632 632
                     ),
633 633
                     'guest_checkout' => array(
634 634
                         'type'    => 'radio',
635 635
                         'id'      => 'guest_checkout',
636
-                        'name'    => __( 'Pay via Invoice Link for non logged in user', 'invoicing' ),
637
-                        'desc'    => __( 'Select how invoice should be paid when non logged in user clicks on the invoice link sent to them via email to pay for invoice.', 'invoicing' ),
636
+                        'name'    => __('Pay via Invoice Link for non logged in user', 'invoicing'),
637
+                        'desc'    => __('Select how invoice should be paid when non logged in user clicks on the invoice link sent to them via email to pay for invoice.', 'invoicing'),
638 638
                         'options' => array(
639
-                            0 => __( 'Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing' ),
640
-                            1 => __( 'Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing' ),
639
+                            0 => __('Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing'),
640
+                            1 => __('Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing'),
641 641
                         ),
642 642
                         'std'     => 0,
643 643
                     ),
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
                 'main' => array(
651 651
                     'tool_settings' => array(
652 652
                         'id'   => 'tool_settings',
653
-                        'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
654
-                        'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
653
+                        'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
654
+                        'desc' => __('Invoicing diagnostic tools', 'invoicing'),
655 655
                         'type' => 'tools',
656 656
                     ),
657 657
                 ),
@@ -659,135 +659,135 @@  discard block
 block discarded – undo
659 659
         )
660 660
     );
661 661
 
662
-    return apply_filters( 'wpinv_registered_settings', $wpinv_settings );
662
+    return apply_filters('wpinv_registered_settings', $wpinv_settings);
663 663
 }
664 664
 
665
-function wpinv_settings_sanitize( $input = array() ) {
665
+function wpinv_settings_sanitize($input = array()) {
666 666
     global $wpinv_options;
667 667
 
668
-    if ( empty( $_POST['_wp_http_referer'] ) ) {
668
+    if (empty($_POST['_wp_http_referer'])) {
669 669
         return $input;
670 670
     }
671 671
 
672
-    parse_str( $_POST['_wp_http_referer'], $referrer );
672
+    parse_str($_POST['_wp_http_referer'], $referrer);
673 673
 
674 674
     $settings = wpinv_get_registered_settings();
675
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
676
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
675
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
676
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
677 677
 
678 678
     $input = $input ? $input : array();
679
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
680
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
679
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
680
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
681 681
 
682 682
     // Loop through each setting being saved and pass it through a sanitization filter
683
-    foreach ( $input as $key => $value ) {
683
+    foreach ($input as $key => $value) {
684 684
         // Get the setting type (checkbox, select, etc)
685
-        $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
685
+        $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
686 686
 
687
-        if ( $type ) {
687
+        if ($type) {
688 688
             // Field type specific filter
689
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
689
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
690 690
         }
691 691
 
692 692
         // General filter
693
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
693
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
694 694
     }
695 695
 
696 696
     // Loop through the whitelist and unset any that are empty for the tab being saved
697
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
698
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
697
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
698
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
699 699
 
700
-    $found_settings = array_merge( $main_settings, $section_settings );
700
+    $found_settings = array_merge($main_settings, $section_settings);
701 701
 
702
-    if ( ! empty( $found_settings ) ) {
703
-        foreach ( $found_settings as $key => $value ) {
702
+    if (!empty($found_settings)) {
703
+        foreach ($found_settings as $key => $value) {
704 704
 
705 705
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
706
-            if ( is_numeric( $key ) ) {
706
+            if (is_numeric($key)) {
707 707
                 $key = $value['id'];
708 708
             }
709 709
 
710
-            if ( empty( $input[ $key ] ) ) {
711
-                unset( $wpinv_options[ $key ] );
710
+            if (empty($input[$key])) {
711
+                unset($wpinv_options[$key]);
712 712
             }
713 713
         }
714 714
     }
715 715
 
716 716
     // Merge our new settings with the existing
717
-    $output = array_merge( $wpinv_options, $input );
717
+    $output = array_merge($wpinv_options, $input);
718 718
 
719
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
719
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
720 720
 
721 721
     return $output;
722 722
 }
723 723
 
724
-function wpinv_settings_sanitize_misc_accounting( $input ) {
724
+function wpinv_settings_sanitize_misc_accounting($input) {
725 725
     global $wpinv_options, $wpi_session;
726 726
 
727
-    if ( !current_user_can( 'manage_options' ) ) {
727
+    if (!current_user_can('manage_options')) {
728 728
         return $input;
729 729
     }
730 730
 
731
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
731
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
732 732
         // Shows an admin notice about upgrading previous order numbers
733
-        $wpi_session->set( 'upgrade_sequential', '1' );
733
+        $wpi_session->set('upgrade_sequential', '1');
734 734
     }
735 735
 
736 736
     return $input;
737 737
 }
738
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
738
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
739 739
 
740
-function wpinv_settings_sanitize_tax_rates( $input ) {
741
-    if( !current_user_can( 'manage_options' ) ) {
740
+function wpinv_settings_sanitize_tax_rates($input) {
741
+    if (!current_user_can('manage_options')) {
742 742
         return $input;
743 743
     }
744 744
 
745
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
745
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
746 746
 
747 747
     $tax_rates = array();
748 748
 
749
-    if ( !empty( $new_rates ) ) {
750
-        foreach ( $new_rates as $rate ) {
751
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
749
+    if (!empty($new_rates)) {
750
+        foreach ($new_rates as $rate) {
751
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
752 752
                 continue;
753 753
             }
754 754
             
755
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
755
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
756 756
             
757 757
             $tax_rates[] = $rate;
758 758
         }
759 759
     }
760 760
 
761
-    update_option( 'wpinv_tax_rates', $tax_rates );
761
+    update_option('wpinv_tax_rates', $tax_rates);
762 762
 
763 763
     return $input;
764 764
 }
765
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
765
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
766 766
 
767
-function wpinv_sanitize_text_field( $input ) {
768
-    return trim( $input );
767
+function wpinv_sanitize_text_field($input) {
768
+    return trim($input);
769 769
 }
770
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
770
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
771 771
 
772 772
 function wpinv_get_settings_tabs() {
773 773
     $tabs             = array();
774
-    $tabs['general']  = __( 'General', 'invoicing' );
775
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
776
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
777
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
778
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
779
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
780
-
781
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
774
+    $tabs['general']  = __('General', 'invoicing');
775
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
776
+    $tabs['taxes']    = __('Taxes', 'invoicing');
777
+    $tabs['emails']   = __('Emails', 'invoicing');
778
+    $tabs['misc']     = __('Misc', 'invoicing');
779
+    $tabs['tools']    = __('Tools', 'invoicing');
780
+
781
+    return apply_filters('wpinv_settings_tabs', $tabs);
782 782
 }
783 783
 
784
-function wpinv_get_settings_tab_sections( $tab = false ) {
784
+function wpinv_get_settings_tab_sections($tab = false) {
785 785
     $tabs     = false;
786 786
     $sections = wpinv_get_registered_settings_sections();
787 787
 
788
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
789
-        $tabs = $sections[ $tab ];
790
-    } else if ( $tab ) {
788
+    if ($tab && !empty($sections[$tab])) {
789
+        $tabs = $sections[$tab];
790
+    } else if ($tab) {
791 791
         $tabs = false;
792 792
     }
793 793
 
@@ -797,135 +797,135 @@  discard block
 block discarded – undo
797 797
 function wpinv_get_registered_settings_sections() {
798 798
     static $sections = false;
799 799
 
800
-    if ( false !== $sections ) {
800
+    if (false !== $sections) {
801 801
         return $sections;
802 802
     }
803 803
 
804 804
     $sections = array(
805
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
806
-            'main' => __( 'General Settings', 'invoicing' ),
807
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
808
-            'labels' => __( 'Label Texts', 'invoicing' ),
809
-        ) ),
810
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
811
-            'main' => __( 'Gateway Settings', 'invoicing' ),
812
-        ) ),
813
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
814
-            'main' => __( 'Tax Settings', 'invoicing' ),
815
-            'rates' => __( 'Tax Rates', 'invoicing' ),
816
-        ) ),
817
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
818
-            'main' => __( 'Email Settings', 'invoicing' ),
819
-        ) ),
820
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
821
-            'main' => __( 'Misc Settings', 'invoicing' ),
822
-        ) ),
823
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
824
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
825
-        ) ),
805
+        'general' => apply_filters('wpinv_settings_sections_general', array(
806
+            'main' => __('General Settings', 'invoicing'),
807
+            'currency_section' => __('Currency Settings', 'invoicing'),
808
+            'labels' => __('Label Texts', 'invoicing'),
809
+        )),
810
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
811
+            'main' => __('Gateway Settings', 'invoicing'),
812
+        )),
813
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
814
+            'main' => __('Tax Settings', 'invoicing'),
815
+            'rates' => __('Tax Rates', 'invoicing'),
816
+        )),
817
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
818
+            'main' => __('Email Settings', 'invoicing'),
819
+        )),
820
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
821
+            'main' => __('Misc Settings', 'invoicing'),
822
+        )),
823
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
824
+            'main' => __('Diagnostic Tools', 'invoicing'),
825
+        )),
826 826
     );
827 827
 
828
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
828
+    $sections = apply_filters('wpinv_settings_sections', $sections);
829 829
 
830 830
     return $sections;
831 831
 }
832 832
 
833
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
833
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
834 834
 	$pages_options = array();
835 835
 
836
-	if( $default_label !== NULL && $default_label !== false ) {
837
-		$pages_options = array( '' => $default_label ); // Blank option
836
+	if ($default_label !== NULL && $default_label !== false) {
837
+		$pages_options = array('' => $default_label); // Blank option
838 838
 	}
839 839
 
840 840
 	$pages = get_pages();
841
-	if ( $pages ) {
842
-		foreach ( $pages as $page ) {
841
+	if ($pages) {
842
+		foreach ($pages as $page) {
843 843
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
844
-            $pages_options[ $page->ID ] = $title;
844
+            $pages_options[$page->ID] = $title;
845 845
 		}
846 846
 	}
847 847
 
848 848
 	return $pages_options;
849 849
 }
850 850
 
851
-function wpinv_header_callback( $args ) {
852
-	if ( !empty( $args['desc'] ) ) {
851
+function wpinv_header_callback($args) {
852
+	if (!empty($args['desc'])) {
853 853
         echo $args['desc'];
854 854
     }
855 855
 }
856 856
 
857
-function wpinv_hidden_callback( $args ) {
857
+function wpinv_hidden_callback($args) {
858 858
 	global $wpinv_options;
859 859
 
860
-	if ( isset( $args['set_value'] ) ) {
860
+	if (isset($args['set_value'])) {
861 861
 		$value = $args['set_value'];
862
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
863
-		$value = $wpinv_options[ $args['id'] ];
862
+	} elseif (isset($wpinv_options[$args['id']])) {
863
+		$value = $wpinv_options[$args['id']];
864 864
 	} else {
865
-		$value = isset( $args['std'] ) ? $args['std'] : '';
865
+		$value = isset($args['std']) ? $args['std'] : '';
866 866
 	}
867 867
 
868
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
868
+	if (isset($args['faux']) && true === $args['faux']) {
869 869
 		$args['readonly'] = true;
870
-		$value = isset( $args['std'] ) ? $args['std'] : '';
870
+		$value = isset($args['std']) ? $args['std'] : '';
871 871
 		$name  = '';
872 872
 	} else {
873
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
873
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
874 874
 	}
875 875
 
876
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
876
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
877 877
     
878 878
 	echo $html;
879 879
 }
880 880
 
881
-function wpinv_checkbox_callback( $args ) {
881
+function wpinv_checkbox_callback($args) {
882 882
 	global $wpinv_options;
883 883
     
884
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
884
+    $sanitize_id = wpinv_sanitize_key($args['id']);
885 885
 
886
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
886
+	if (isset($args['faux']) && true === $args['faux']) {
887 887
 		$name = '';
888 888
 	} else {
889 889
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
890 890
 	}
891 891
 
892
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
892
+	$checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : '';
893 893
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
894
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
894
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
895 895
 
896 896
 	echo $html;
897 897
 }
898 898
 
899
-function wpinv_multicheck_callback( $args ) {
899
+function wpinv_multicheck_callback($args) {
900 900
 	global $wpinv_options;
901 901
 	
902
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
902
+	$sanitize_id = wpinv_sanitize_key($args['id']);
903 903
 	
904
-	if ( ! empty( $args['options'] ) ) {
905
-		foreach( $args['options'] as $key => $option ):
906
-			$sanitize_key = wpinv_sanitize_key( $key );
907
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
904
+	if (!empty($args['options'])) {
905
+		foreach ($args['options'] as $key => $option):
906
+			$sanitize_key = wpinv_sanitize_key($key);
907
+			if (isset($wpinv_options[$args['id']][$sanitize_key])) { 
908 908
 				$enabled = $sanitize_key;
909 909
 			} else { 
910 910
 				$enabled = NULL; 
911 911
 			}
912
-			echo '<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;';
913
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>';
912
+			echo '<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;';
913
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label><br/>';
914 914
 		endforeach;
915 915
 		echo '<p class="description">' . $args['desc'] . '</p>';
916 916
 	}
917 917
 }
918 918
 
919
-function wpinv_payment_icons_callback( $args ) {
919
+function wpinv_payment_icons_callback($args) {
920 920
 	global $wpinv_options;
921 921
     
922
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
922
+    $sanitize_id = wpinv_sanitize_key($args['id']);
923 923
 
924
-	if ( ! empty( $args['options'] ) ) {
925
-		foreach( $args['options'] as $key => $option ) {
926
-            $sanitize_key = wpinv_sanitize_key( $key );
924
+	if (!empty($args['options'])) {
925
+		foreach ($args['options'] as $key => $option) {
926
+            $sanitize_key = wpinv_sanitize_key($key);
927 927
             
928
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
928
+			if (isset($wpinv_options[$args['id']][$key])) {
929 929
 				$enabled = $option;
930 930
 			} else {
931 931
 				$enabled = NULL;
@@ -933,196 +933,196 @@  discard block
 block discarded – undo
933 933
 
934 934
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
935 935
 
936
-				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;';
936
+				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;';
937 937
 
938
-				if ( wpinv_string_is_image_url( $key ) ) {
939
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
938
+				if (wpinv_string_is_image_url($key)) {
939
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
940 940
 				} else {
941
-					$card = strtolower( str_replace( ' ', '', $option ) );
941
+					$card = strtolower(str_replace(' ', '', $option));
942 942
 
943
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
944
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
943
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
944
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
945 945
 					} else {
946
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
946
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
947 947
 						$content_dir = WP_CONTENT_DIR;
948 948
 
949
-						if ( function_exists( 'wp_normalize_path' ) ) {
949
+						if (function_exists('wp_normalize_path')) {
950 950
 							// Replaces backslashes with forward slashes for Windows systems
951
-							$image = wp_normalize_path( $image );
952
-							$content_dir = wp_normalize_path( $content_dir );
951
+							$image = wp_normalize_path($image);
952
+							$content_dir = wp_normalize_path($content_dir);
953 953
 						}
954 954
 
955
-						$image = str_replace( $content_dir, content_url(), $image );
955
+						$image = str_replace($content_dir, content_url(), $image);
956 956
 					}
957 957
 
958
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
958
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
959 959
 				}
960 960
 			echo $option . '</label>';
961 961
 		}
962
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
962
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
963 963
 	}
964 964
 }
965 965
 
966
-function wpinv_radio_callback( $args ) {
966
+function wpinv_radio_callback($args) {
967 967
 	global $wpinv_options;
968 968
     
969
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
969
+    $sanitize_id = wpinv_sanitize_key($args['id']);
970 970
     
971
-    foreach ( $args['options'] as $key => $option ) :
972
-		$sanitize_key = wpinv_sanitize_key( $key );
971
+    foreach ($args['options'] as $key => $option) :
972
+		$sanitize_key = wpinv_sanitize_key($key);
973 973
         
974 974
         $checked = false;
975 975
 
976
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
976
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
977 977
 			$checked = true;
978
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
978
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
979 979
 			$checked = true;
980 980
 
981 981
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
982
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
982
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
983 983
 	endforeach;
984 984
 
985
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
985
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
986 986
 }
987 987
 
988
-function wpinv_gateways_callback( $args ) {
988
+function wpinv_gateways_callback($args) {
989 989
 	global $wpinv_options;
990 990
     
991
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
991
+    $sanitize_id = wpinv_sanitize_key($args['id']);
992 992
 
993
-	foreach ( $args['options'] as $key => $option ) :
994
-		$sanitize_key = wpinv_sanitize_key( $key );
993
+	foreach ($args['options'] as $key => $option) :
994
+		$sanitize_key = wpinv_sanitize_key($key);
995 995
         
996
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
996
+        if (isset($wpinv_options['gateways'][$key]))
997 997
 			$enabled = '1';
998 998
 		else
999 999
 			$enabled = null;
1000 1000
 
1001
-		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;';
1002
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
1001
+		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;';
1002
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
1003 1003
 	endforeach;
1004 1004
 }
1005 1005
 
1006 1006
 function wpinv_gateway_select_callback($args) {
1007 1007
 	global $wpinv_options;
1008 1008
     
1009
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1009
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1010 1010
 
1011 1011
 	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
1012 1012
 
1013
-	foreach ( $args['options'] as $key => $option ) :
1014
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1015
-            $selected = selected( $key, $args['selected'], false );
1013
+	foreach ($args['options'] as $key => $option) :
1014
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1015
+            $selected = selected($key, $args['selected'], false);
1016 1016
         } else {
1017
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
1017
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
1018 1018
         }
1019
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1019
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
1020 1020
 	endforeach;
1021 1021
 
1022 1022
 	echo '</select>';
1023
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1023
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1024 1024
 }
1025 1025
 
1026
-function wpinv_text_callback( $args ) {
1026
+function wpinv_text_callback($args) {
1027 1027
 	global $wpinv_options;
1028 1028
     
1029
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1029
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1030 1030
 
1031
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1032
-		$value = $wpinv_options[ $args['id'] ];
1031
+	if (isset($wpinv_options[$args['id']])) {
1032
+		$value = $wpinv_options[$args['id']];
1033 1033
 	} else {
1034
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1034
+		$value = isset($args['std']) ? $args['std'] : '';
1035 1035
 	}
1036 1036
 
1037
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1037
+	if (isset($args['faux']) && true === $args['faux']) {
1038 1038
 		$args['readonly'] = true;
1039
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1039
+		$value = isset($args['std']) ? $args['std'] : '';
1040 1040
 		$name  = '';
1041 1041
 	} else {
1042
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1042
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1043 1043
 	}
1044
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1044
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
1045 1045
 
1046 1046
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1047
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1048
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1049
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1047
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1048
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
1049
+	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1050 1050
 
1051 1051
 	echo $html;
1052 1052
 }
1053 1053
 
1054
-function wpinv_number_callback( $args ) {
1054
+function wpinv_number_callback($args) {
1055 1055
 	global $wpinv_options;
1056 1056
     
1057
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1057
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1058 1058
 
1059
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1060
-		$value = $wpinv_options[ $args['id'] ];
1059
+	if (isset($wpinv_options[$args['id']])) {
1060
+		$value = $wpinv_options[$args['id']];
1061 1061
 	} else {
1062
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1062
+		$value = isset($args['std']) ? $args['std'] : '';
1063 1063
 	}
1064 1064
 
1065
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1065
+	if (isset($args['faux']) && true === $args['faux']) {
1066 1066
 		$args['readonly'] = true;
1067
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1067
+		$value = isset($args['std']) ? $args['std'] : '';
1068 1068
 		$name  = '';
1069 1069
 	} else {
1070
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1070
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1071 1071
 	}
1072 1072
 
1073
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1074
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1075
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1076
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1073
+	$max  = isset($args['max']) ? $args['max'] : 999999;
1074
+	$min  = isset($args['min']) ? $args['min'] : 0;
1075
+	$step = isset($args['step']) ? $args['step'] : 1;
1076
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
1077 1077
 
1078
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1079
-	$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 ) ) . '"/>';
1080
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1078
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1079
+	$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)) . '"/>';
1080
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1081 1081
 
1082 1082
 	echo $html;
1083 1083
 }
1084 1084
 
1085
-function wpinv_textarea_callback( $args ) {
1085
+function wpinv_textarea_callback($args) {
1086 1086
 	global $wpinv_options;
1087 1087
     
1088
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1088
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1089 1089
 
1090
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1091
-		$value = $wpinv_options[ $args['id'] ];
1090
+	if (isset($wpinv_options[$args['id']])) {
1091
+		$value = $wpinv_options[$args['id']];
1092 1092
 	} else {
1093
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1093
+		$value = isset($args['std']) ? $args['std'] : '';
1094 1094
 	}
1095 1095
     
1096
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1097
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1096
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1097
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
1098 1098
 
1099
-	$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>';
1100
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1099
+	$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>';
1100
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1101 1101
 
1102 1102
 	echo $html;
1103 1103
 }
1104 1104
 
1105
-function wpinv_password_callback( $args ) {
1105
+function wpinv_password_callback($args) {
1106 1106
 	global $wpinv_options;
1107 1107
     
1108
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1108
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1109 1109
 
1110
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1111
-		$value = $wpinv_options[ $args['id'] ];
1110
+	if (isset($wpinv_options[$args['id']])) {
1111
+		$value = $wpinv_options[$args['id']];
1112 1112
 	} else {
1113
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1113
+		$value = isset($args['std']) ? $args['std'] : '';
1114 1114
 	}
1115 1115
 
1116
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1117
-	$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 ) . '"/>';
1118
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1116
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1117
+	$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) . '"/>';
1118
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1119 1119
 
1120 1120
 	echo $html;
1121 1121
 }
1122 1122
 
1123 1123
 function wpinv_missing_callback($args) {
1124 1124
 	printf(
1125
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1125
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
1126 1126
 		'<strong>' . $args['id'] . '</strong>'
1127 1127
 	);
1128 1128
 }
@@ -1130,137 +1130,137 @@  discard block
 block discarded – undo
1130 1130
 function wpinv_select_callback($args) {
1131 1131
 	global $wpinv_options;
1132 1132
     
1133
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1133
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1134 1134
 
1135
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1136
-		$value = $wpinv_options[ $args['id'] ];
1135
+	if (isset($wpinv_options[$args['id']])) {
1136
+		$value = $wpinv_options[$args['id']];
1137 1137
 	} else {
1138
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1138
+		$value = isset($args['std']) ? $args['std'] : '';
1139 1139
 	}
1140 1140
     
1141
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1141
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1142 1142
         $value = $args['selected'];
1143 1143
     }
1144 1144
 
1145
-	if ( isset( $args['placeholder'] ) ) {
1145
+	if (isset($args['placeholder'])) {
1146 1146
 		$placeholder = $args['placeholder'];
1147 1147
 	} else {
1148 1148
 		$placeholder = '';
1149 1149
 	}
1150 1150
 
1151
-	if ( isset( $args['chosen'] ) ) {
1151
+	if (isset($args['chosen'])) {
1152 1152
 		$chosen = 'class="wpinv-chosen"';
1153 1153
 	} else {
1154 1154
 		$chosen = '';
1155 1155
 	}
1156 1156
     
1157
-    if( !empty( $args['onchange'] ) ) {
1158
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
1157
+    if (!empty($args['onchange'])) {
1158
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
1159 1159
     } else {
1160 1160
         $onchange = '';
1161 1161
     }
1162 1162
 
1163
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $chosen . 'data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1163
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $chosen . 'data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
1164 1164
 
1165
-	foreach ( $args['options'] as $option => $name ) {
1166
-		$selected = selected( $option, $value, false );
1167
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1165
+	foreach ($args['options'] as $option => $name) {
1166
+		$selected = selected($option, $value, false);
1167
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1168 1168
 	}
1169 1169
 
1170 1170
 	$html .= '</select>';
1171
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1171
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1172 1172
 
1173 1173
 	echo $html;
1174 1174
 }
1175 1175
 
1176
-function wpinv_color_select_callback( $args ) {
1176
+function wpinv_color_select_callback($args) {
1177 1177
 	global $wpinv_options;
1178 1178
     
1179
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1179
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1180 1180
 
1181
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1182
-		$value = $wpinv_options[ $args['id'] ];
1181
+	if (isset($wpinv_options[$args['id']])) {
1182
+		$value = $wpinv_options[$args['id']];
1183 1183
 	} else {
1184
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1184
+		$value = isset($args['std']) ? $args['std'] : '';
1185 1185
 	}
1186 1186
 
1187
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1187
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
1188 1188
 
1189
-	foreach ( $args['options'] as $option => $color ) {
1190
-		$selected = selected( $option, $value, false );
1191
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1189
+	foreach ($args['options'] as $option => $color) {
1190
+		$selected = selected($option, $value, false);
1191
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
1192 1192
 	}
1193 1193
 
1194 1194
 	$html .= '</select>';
1195
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1195
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1196 1196
 
1197 1197
 	echo $html;
1198 1198
 }
1199 1199
 
1200
-function wpinv_rich_editor_callback( $args ) {
1200
+function wpinv_rich_editor_callback($args) {
1201 1201
 	global $wpinv_options, $wp_version;
1202 1202
     
1203
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1203
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1204 1204
 
1205
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1206
-		$value = $wpinv_options[ $args['id'] ];
1205
+	if (isset($wpinv_options[$args['id']])) {
1206
+		$value = $wpinv_options[$args['id']];
1207 1207
 
1208
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1209
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1208
+		if (empty($args['allow_blank']) && empty($value)) {
1209
+			$value = isset($args['std']) ? $args['std'] : '';
1210 1210
 		}
1211 1211
 	} else {
1212
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1212
+		$value = isset($args['std']) ? $args['std'] : '';
1213 1213
 	}
1214 1214
 
1215
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1215
+	$rows = isset($args['size']) ? $args['size'] : 20;
1216 1216
 
1217
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1217
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
1218 1218
 		ob_start();
1219
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) );
1219
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows)));
1220 1220
 		$html = ob_get_clean();
1221 1221
 	} else {
1222
-		$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>';
1222
+		$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>';
1223 1223
 	}
1224 1224
 
1225
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1225
+	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1226 1226
 
1227 1227
 	echo $html;
1228 1228
 }
1229 1229
 
1230
-function wpinv_upload_callback( $args ) {
1230
+function wpinv_upload_callback($args) {
1231 1231
 	global $wpinv_options;
1232 1232
     
1233
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1233
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1234 1234
 
1235
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1235
+	if (isset($wpinv_options[$args['id']])) {
1236 1236
 		$value = $wpinv_options[$args['id']];
1237 1237
 	} else {
1238 1238
 		$value = isset($args['std']) ? $args['std'] : '';
1239 1239
 	}
1240 1240
 
1241
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1242
-	$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 ) ) . '"/>';
1243
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1244
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1241
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1242
+	$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)) . '"/>';
1243
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
1244
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1245 1245
 
1246 1246
 	echo $html;
1247 1247
 }
1248 1248
 
1249
-function wpinv_color_callback( $args ) {
1249
+function wpinv_color_callback($args) {
1250 1250
 	global $wpinv_options;
1251 1251
     
1252
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1252
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1253 1253
 
1254
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1255
-		$value = $wpinv_options[ $args['id'] ];
1254
+	if (isset($wpinv_options[$args['id']])) {
1255
+		$value = $wpinv_options[$args['id']];
1256 1256
 	} else {
1257
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1257
+		$value = isset($args['std']) ? $args['std'] : '';
1258 1258
 	}
1259 1259
 
1260
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1260
+	$default = isset($args['std']) ? $args['std'] : '';
1261 1261
 
1262
-	$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 ) . '" />';
1263
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1262
+	$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) . '" />';
1263
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1264 1264
 
1265 1265
 	echo $html;
1266 1266
 }
@@ -1268,9 +1268,9 @@  discard block
 block discarded – undo
1268 1268
 function wpinv_country_states_callback($args) {
1269 1269
 	global $wpinv_options;
1270 1270
     
1271
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1271
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1272 1272
 
1273
-	if ( isset( $args['placeholder'] ) ) {
1273
+	if (isset($args['placeholder'])) {
1274 1274
 		$placeholder = $args['placeholder'];
1275 1275
 	} else {
1276 1276
 		$placeholder = '';
@@ -1278,17 +1278,17 @@  discard block
 block discarded – undo
1278 1278
 
1279 1279
 	$states = wpinv_get_country_states();
1280 1280
 
1281
-	$chosen = ( $args['chosen'] ? ' wpinv-chosen' : '' );
1282
-	$class = empty( $states ) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1283
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1281
+	$chosen = ($args['chosen'] ? ' wpinv-chosen' : '');
1282
+	$class = empty($states) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1283
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
1284 1284
 
1285
-	foreach ( $states as $option => $name ) {
1286
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1287
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1285
+	foreach ($states as $option => $name) {
1286
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
1287
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1288 1288
 	}
1289 1289
 
1290 1290
 	$html .= '</select>';
1291
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1291
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1292 1292
 
1293 1293
 	echo $html;
1294 1294
 }
@@ -1303,25 +1303,25 @@  discard block
 block discarded – undo
1303 1303
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
1304 1304
 		<thead>
1305 1305
 			<tr>
1306
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
1307
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
1308
-                <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>
1309
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
1310
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
1311
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
1306
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
1307
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
1308
+                <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>
1309
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
1310
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
1311
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
1312 1312
 			</tr>
1313 1313
 		</thead>
1314 1314
         <tbody>
1315
-		<?php if( !empty( $rates ) ) : ?>
1316
-			<?php foreach( $rates as $key => $rate ) : ?>
1315
+		<?php if (!empty($rates)) : ?>
1316
+			<?php foreach ($rates as $key => $rate) : ?>
1317 1317
             <?php 
1318
-            $sanitized_key = wpinv_sanitize_key( $key );
1318
+            $sanitized_key = wpinv_sanitize_key($key);
1319 1319
             ?>
1320 1320
 			<tr>
1321 1321
 				<td class="wpinv_tax_country">
1322 1322
 					<?php
1323
-					echo wpinv_html_select( array(
1324
-						'options'          => wpinv_get_country_list( true ),
1323
+					echo wpinv_html_select(array(
1324
+						'options'          => wpinv_get_country_list(true),
1325 1325
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1326 1326
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1327 1327
 						'selected'         => $rate['country'],
@@ -1329,72 +1329,72 @@  discard block
 block discarded – undo
1329 1329
 						'show_option_none' => false,
1330 1330
 						'class'            => 'wpinv-tax-country',
1331 1331
 						'chosen'           => false,
1332
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1333
-					) );
1332
+						'placeholder'      => __('Choose a country', 'invoicing')
1333
+					));
1334 1334
 					?>
1335 1335
 				</td>
1336 1336
 				<td class="wpinv_tax_state">
1337 1337
 					<?php
1338
-					$states = wpinv_get_country_states( $rate['country'] );
1339
-					if( !empty( $states ) ) {
1340
-						echo wpinv_html_select( array(
1341
-							'options'          => array_merge( array( '' => '' ), $states ),
1338
+					$states = wpinv_get_country_states($rate['country']);
1339
+					if (!empty($states)) {
1340
+						echo wpinv_html_select(array(
1341
+							'options'          => array_merge(array('' => ''), $states),
1342 1342
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1343 1343
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1344 1344
 							'selected'         => $rate['state'],
1345 1345
 							'show_option_all'  => false,
1346 1346
 							'show_option_none' => false,
1347 1347
 							'chosen'           => false,
1348
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1349
-						) );
1348
+							'placeholder'      => __('Choose a state', 'invoicing')
1349
+						));
1350 1350
 					} else {
1351
-						echo wpinv_html_text( array(
1351
+						echo wpinv_html_text(array(
1352 1352
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1353
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1353
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
1354 1354
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1355
-						) );
1355
+						));
1356 1356
 					}
1357 1357
 					?>
1358 1358
 				</td>
1359 1359
 				<td class="wpinv_tax_global">
1360
-					<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'] ) ); ?>/>
1361
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1360
+					<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'])); ?>/>
1361
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1362 1362
 				</td>
1363
-				<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>
1364
-                <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>
1365
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1363
+				<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>
1364
+                <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>
1365
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1366 1366
 			</tr>
1367 1367
 			<?php endforeach; ?>
1368 1368
 		<?php else : ?>
1369 1369
 			<tr>
1370 1370
 				<td class="wpinv_tax_country">
1371 1371
 					<?php
1372
-					echo wpinv_html_select( array(
1373
-						'options'          => wpinv_get_country_list( true ),
1372
+					echo wpinv_html_select(array(
1373
+						'options'          => wpinv_get_country_list(true),
1374 1374
 						'name'             => 'tax_rates[0][country]',
1375 1375
 						'show_option_all'  => false,
1376 1376
 						'show_option_none' => false,
1377 1377
 						'class'            => 'wpinv-tax-country',
1378 1378
 						'chosen'           => false,
1379
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1380
-					) ); ?>
1379
+						'placeholder'      => __('Choose a country', 'invoicing')
1380
+					)); ?>
1381 1381
 				</td>
1382 1382
 				<td class="wpinv_tax_state">
1383
-					<?php echo wpinv_html_text( array(
1383
+					<?php echo wpinv_html_text(array(
1384 1384
 						'name' => 'tax_rates[0][state]'
1385
-					) ); ?>
1385
+					)); ?>
1386 1386
 				</td>
1387 1387
 				<td class="wpinv_tax_global">
1388 1388
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
1389
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1389
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1390 1390
 				</td>
1391
-				<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>
1391
+				<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>
1392 1392
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
1393
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1393
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1394 1394
 			</tr>
1395 1395
 		<?php endif; ?>
1396 1396
         </tbody>
1397
-        <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>
1397
+        <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>
1398 1398
 	</table>
1399 1399
 	<?php
1400 1400
 	echo ob_get_clean();
@@ -1405,44 +1405,44 @@  discard block
 block discarded – undo
1405 1405
     ob_start(); ?>
1406 1406
     </td><tr>
1407 1407
     <td colspan="2" class="wpinv_tools_tdbox">
1408
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1409
-    <?php do_action( 'wpinv_tools_before' ); ?>
1408
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1409
+    <?php do_action('wpinv_tools_before'); ?>
1410 1410
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1411 1411
         <thead>
1412 1412
             <tr>
1413
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1414
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1415
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1413
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1414
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1415
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1416 1416
             </tr>
1417 1417
         </thead>
1418
-            <?php do_action( 'wpinv_tools_row' ); ?>
1418
+            <?php do_action('wpinv_tools_row'); ?>
1419 1419
         <tbody>
1420 1420
         </tbody>
1421 1421
     </table>
1422
-    <?php do_action( 'wpinv_tools_after' ); ?>
1422
+    <?php do_action('wpinv_tools_after'); ?>
1423 1423
     <?php
1424 1424
     echo ob_get_clean();
1425 1425
 }
1426 1426
 
1427
-function wpinv_descriptive_text_callback( $args ) {
1428
-	echo wp_kses_post( $args['desc'] );
1427
+function wpinv_descriptive_text_callback($args) {
1428
+	echo wp_kses_post($args['desc']);
1429 1429
 }
1430 1430
 
1431
-function wpinv_hook_callback( $args ) {
1432
-	do_action( 'wpinv_' . $args['id'], $args );
1431
+function wpinv_hook_callback($args) {
1432
+	do_action('wpinv_' . $args['id'], $args);
1433 1433
 }
1434 1434
 
1435 1435
 function wpinv_set_settings_cap() {
1436 1436
 	return 'manage_options';
1437 1437
 }
1438
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1438
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1439 1439
 
1440
-function wpinv_settings_sanitize_input( $value, $key ) {
1441
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1442
-        $value = wpinv_sanitize_amount( $value, 4 );
1440
+function wpinv_settings_sanitize_input($value, $key) {
1441
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1442
+        $value = wpinv_sanitize_amount($value, 4);
1443 1443
         $value = $value >= 100 ? 99 : $value;
1444 1444
     }
1445 1445
         
1446 1446
     return $value;
1447 1447
 }
1448
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1449 1448
\ No newline at end of file
1449
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1450 1450
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@  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
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) {
6
-    if ( empty( $user ) ) {
5
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') {
6
+    if (empty($user)) {
7 7
         $user = get_current_user_id();
8 8
     }
9 9
 
10
-    if ( 0 === $user ) {
10
+    if (0 === $user) {
11 11
         return false;
12 12
     }
13 13
 
14
-    if ( $pagination ) {
15
-        if ( get_query_var( 'paged' ) )
14
+    if ($pagination) {
15
+        if (get_query_var('paged'))
16 16
             $paged = get_query_var('paged');
17
-        else if ( get_query_var( 'page' ) )
18
-            $paged = get_query_var( 'page' );
17
+        else if (get_query_var('page'))
18
+            $paged = get_query_var('page');
19 19
         else
20 20
             $paged = 1;
21 21
     }
@@ -24,21 +24,21 @@  discard block
 block discarded – undo
24 24
         'post_type'      => 'wpi_invoice',
25 25
         'posts_per_page' => 20,
26 26
         'paged'          => null,
27
-        'post_status'    => array( 'publish', 'pending' ),
27
+        'post_status'    => array('publish', 'pending'),
28 28
         'user'           => $user,
29 29
         'order'          => 'date',
30 30
     );
31 31
 
32
-    $invoices = get_posts( $args );
32
+    $invoices = get_posts($args);
33 33
 
34 34
     // No invoices
35
-    if ( ! $invoices )
35
+    if (!$invoices)
36 36
         return false;
37 37
 
38 38
     return $invoices;
39 39
 }
40 40
 
41
-function wpinv_dropdown_users( $args = '' ) {
41
+function wpinv_dropdown_users($args = '') {
42 42
     $defaults = array(
43 43
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
44 44
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
         'option_none_value' => -1
50 50
     );
51 51
 
52
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
52
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
53 53
 
54
-    $r = wp_parse_args( $args, $defaults );
54
+    $r = wp_parse_args($args, $defaults);
55 55
 
56
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
56
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
57 57
 
58
-    $fields = array( 'ID', 'user_login', 'user_email' );
58
+    $fields = array('ID', 'user_login', 'user_email');
59 59
 
60
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
61
-    if ( 'display_name_with_login' === $show ) {
60
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
61
+    if ('display_name_with_login' === $show) {
62 62
         $fields[] = 'display_name';
63
-    } else if ( 'display_name_with_email' === $show ) {
63
+    } else if ('display_name_with_email' === $show) {
64 64
         $fields[] = 'display_name';
65 65
     } else {
66 66
         $fields[] = $show;
@@ -72,99 +72,99 @@  discard block
 block discarded – undo
72 72
     $show_option_none = $r['show_option_none'];
73 73
     $option_none_value = $r['option_none_value'];
74 74
 
75
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
75
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
76 76
 
77
-    $users = get_users( $query_args );
77
+    $users = get_users($query_args);
78 78
 
79 79
     $output = '';
80
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
81
-        $name = esc_attr( $r['name'] );
82
-        if ( $r['multi'] && ! $r['id'] ) {
80
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
81
+        $name = esc_attr($r['name']);
82
+        if ($r['multi'] && !$r['id']) {
83 83
             $id = '';
84 84
         } else {
85
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
85
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
86 86
         }
87 87
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
88 88
 
89
-        if ( $show_option_all ) {
89
+        if ($show_option_all) {
90 90
             $output .= "\t<option value='0'>$show_option_all</option>\n";
91 91
         }
92 92
 
93
-        if ( $show_option_none ) {
94
-            $_selected = selected( $option_none_value, $r['selected'], false );
95
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
93
+        if ($show_option_none) {
94
+            $_selected = selected($option_none_value, $r['selected'], false);
95
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
96 96
         }
97 97
 
98
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
98
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
99 99
             $found_selected = false;
100
-            $r['selected'] = (int) $r['selected'];
101
-            foreach ( (array) $users as $user ) {
102
-                $user->ID = (int) $user->ID;
103
-                if ( $user->ID === $r['selected'] ) {
100
+            $r['selected'] = (int)$r['selected'];
101
+            foreach ((array)$users as $user) {
102
+                $user->ID = (int)$user->ID;
103
+                if ($user->ID === $r['selected']) {
104 104
                     $found_selected = true;
105 105
                 }
106 106
             }
107 107
 
108
-            if ( ! $found_selected ) {
109
-                $users[] = get_userdata( $r['selected'] );
108
+            if (!$found_selected) {
109
+                $users[] = get_userdata($r['selected']);
110 110
             }
111 111
         }
112 112
 
113
-        foreach ( (array) $users as $user ) {
114
-            if ( 'display_name_with_login' === $show ) {
113
+        foreach ((array)$users as $user) {
114
+            if ('display_name_with_login' === $show) {
115 115
                 /* translators: 1: display name, 2: user_login */
116
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
117
-            } elseif ( 'display_name_with_email' === $show ) {
116
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
117
+            } elseif ('display_name_with_email' === $show) {
118 118
                 /* translators: 1: display name, 2: user_email */
119
-                if ( $user->display_name == $user->user_email ) {
119
+                if ($user->display_name == $user->user_email) {
120 120
                     $display = $user->display_name;
121 121
                 } else {
122
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
122
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
123 123
                 }
124
-            } elseif ( ! empty( $user->$show ) ) {
124
+            } elseif (!empty($user->$show)) {
125 125
                 $display = $user->$show;
126 126
             } else {
127 127
                 $display = '(' . $user->user_login . ')';
128 128
             }
129 129
 
130
-            $_selected = selected( $user->ID, $r['selected'], false );
131
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
130
+            $_selected = selected($user->ID, $r['selected'], false);
131
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
132 132
         }
133 133
 
134 134
         $output .= "</select>";
135 135
     }
136 136
 
137
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
137
+    $html = apply_filters('wpinv_dropdown_users', $output);
138 138
 
139
-    if ( $r['echo'] ) {
139
+    if ($r['echo']) {
140 140
         echo $html;
141 141
     }
142 142
     return $html;
143 143
 }
144 144
 
145
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
146
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
147
-        wpinv_login_user( $user_id );
145
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
146
+    if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) {
147
+        wpinv_login_user($user_id);
148 148
     } else {
149
-        $redirect_to = wp_login_url( $redirect_to );
149
+        $redirect_to = wp_login_url($redirect_to);
150 150
     }
151 151
     
152
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
152
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
153 153
     
154
-    wp_redirect( $redirect_to );
154
+    wp_redirect($redirect_to);
155 155
 }
156 156
 
157
-function wpinv_login_user( $user_id ) {
158
-    if ( is_user_logged_in() ) {
157
+function wpinv_login_user($user_id) {
158
+    if (is_user_logged_in()) {
159 159
         return true;
160 160
     }
161 161
     
162
-    $user = get_user_by( 'id', $user_id );
162
+    $user = get_user_by('id', $user_id);
163 163
     
164
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
165
-        wp_set_current_user( $user_id, $user->user_login );
166
-        wp_set_auth_cookie( $user_id );
167
-        do_action( 'wp_login', $user->user_login );
164
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
165
+        wp_set_current_user($user_id, $user->user_login);
166
+        wp_set_auth_cookie($user_id);
167
+        do_action('wp_login', $user->user_login);
168 168
         
169 169
         return true;
170 170
     }
Please login to merge, or discard this patch.
includes/wpinv-post-types.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -7,44 +7,44 @@  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
-add_action( 'init', 'wpinv_register_post_types', 1 );
14
+add_action('init', 'wpinv_register_post_types', 1);
15 15
 function wpinv_register_post_types() {    
16 16
     $labels = array(
17
-        'name'               => _x( 'Invoices', 'post type general name', 'invoicing' ),
18
-        'singular_name'      => _x( 'Invoice', 'post type singular name', 'invoicing' ),
19
-        'menu_name'          => _x( 'Invoices', 'admin menu', 'invoicing' ),
20
-        'name_admin_bar'     => _x( 'Invoice', 'add new on admin bar', 'invoicing' ),
21
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
22
-        'add_new_item'       => __( 'Add New Invoice', 'invoicing' ),
23
-        'new_item'           => __( 'New Invoice', 'invoicing' ),
24
-        'edit_item'          => __( 'Edit Invoice', 'invoicing' ),
25
-        'view_item'          => __( 'View Invoice', 'invoicing' ),
26
-        'all_items'          => __( 'Invoices', 'invoicing' ),
27
-        'search_items'       => __( 'Search Invoices', 'invoicing' ),
28
-        'parent_item_colon'  => __( 'Parent Invoices:', 'invoicing' ),
29
-        'not_found'          => __( 'No invoices found.', 'invoicing' ),
30
-        'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' )
17
+        'name'               => _x('Invoices', 'post type general name', 'invoicing'),
18
+        'singular_name'      => _x('Invoice', 'post type singular name', 'invoicing'),
19
+        'menu_name'          => _x('Invoices', 'admin menu', 'invoicing'),
20
+        'name_admin_bar'     => _x('Invoice', 'add new on admin bar', 'invoicing'),
21
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
22
+        'add_new_item'       => __('Add New Invoice', 'invoicing'),
23
+        'new_item'           => __('New Invoice', 'invoicing'),
24
+        'edit_item'          => __('Edit Invoice', 'invoicing'),
25
+        'view_item'          => __('View Invoice', 'invoicing'),
26
+        'all_items'          => __('Invoices', 'invoicing'),
27
+        'search_items'       => __('Search Invoices', 'invoicing'),
28
+        'parent_item_colon'  => __('Parent Invoices:', 'invoicing'),
29
+        'not_found'          => __('No invoices found.', 'invoicing'),
30
+        'not_found_in_trash' => __('No invoices found in trash.', 'invoicing')
31 31
     );
32
-    $labels = apply_filters( 'wpinv_labels', $labels );
32
+    $labels = apply_filters('wpinv_labels', $labels);
33 33
     
34 34
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
35
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
35
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
36 36
 
37 37
     $cap_type = 'wpi_invoice';
38 38
     $args = array(
39 39
         'labels'             => $labels,
40
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
40
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
41 41
         'public'             => true,
42 42
         'can_export'         => true,
43 43
         '_builtin'           => false,
44 44
         'publicly_queryable' => true,
45 45
         'exclude_from_search'=> true,
46 46
         'show_ui'            => true,
47
-        'show_in_menu'       => current_user_can( 'manage_invoicing' ) ? 'wpinv' : true,
47
+        'show_in_menu'       => current_user_can('manage_invoicing') ? 'wpinv' : true,
48 48
         'query_var'          => false,
49 49
         'rewrite'            => true,
50 50
         'capability_type'    => 'wpi_invoice',
@@ -68,38 +68,38 @@  discard block
 block discarded – undo
68 68
         'has_archive'        => false,
69 69
         'hierarchical'       => false,
70 70
         'menu_position'      => null,
71
-        'supports'           => array( 'title', 'author' ),
71
+        'supports'           => array('title', 'author'),
72 72
         'menu_icon'          => $menu_icon,
73 73
     );
74 74
             
75
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
75
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
76 76
     
77
-    register_post_type( 'wpi_invoice', $args );
77
+    register_post_type('wpi_invoice', $args);
78 78
     
79 79
     $items_labels = array(
80
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
81
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
82
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
83
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
84
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
85
-        'new_item'           => __( 'New Item', 'invoicing' ),
86
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
87
-        'view_item'          => __( 'View Item', 'invoicing' ),
88
-        'all_items'          => __( 'Items', 'invoicing' ),
89
-        'search_items'       => __( 'Search Items', 'invoicing' ),
80
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
81
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
82
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
83
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
84
+        'add_new_item'       => __('Add New Item', 'invoicing'),
85
+        'new_item'           => __('New Item', 'invoicing'),
86
+        'edit_item'          => __('Edit Item', 'invoicing'),
87
+        'view_item'          => __('View Item', 'invoicing'),
88
+        'all_items'          => __('Items', 'invoicing'),
89
+        'search_items'       => __('Search Items', 'invoicing'),
90 90
         'parent_item_colon'  => '',
91
-        'not_found'          => __( 'No items found.', 'invoicing' ),
92
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
91
+        'not_found'          => __('No items found.', 'invoicing'),
92
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
93 93
     );
94
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
94
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
95 95
 
96 96
     $cap_type = 'wpi_item';
97 97
     $invoice_item_args = array(
98 98
         'labels'                => $items_labels,
99 99
         'public'                => false,
100 100
         'show_ui'               => true,
101
-        'show_in_menu'          => current_user_can( 'manage_invoicing' ) ? 'wpinv' : false,
102
-        'supports'              => array( 'title', 'excerpt' ),
101
+        'show_in_menu'          => current_user_can('manage_invoicing') ? 'wpinv' : false,
102
+        'supports'              => array('title', 'excerpt'),
103 103
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
104 104
         'rewrite'               => false,
105 105
         'query_var'             => false,
@@ -123,40 +123,40 @@  discard block
 block discarded – undo
123 123
         ),
124 124
         'can_export'            => true,
125 125
     );
126
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
126
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
127 127
 
128
-    register_post_type( 'wpi_item', $invoice_item_args );
128
+    register_post_type('wpi_item', $invoice_item_args);
129 129
     
130 130
     $labels = array(
131
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
132
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
133
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
134
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
135
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
136
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
137
-        'new_item'           => __( 'New Discount', 'invoicing' ),
138
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
139
-        'view_item'          => __( 'View Discount', 'invoicing' ),
140
-        'all_items'          => __( 'Discounts', 'invoicing' ),
141
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
142
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
143
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
144
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
131
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
132
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
133
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
134
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
135
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
136
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
137
+        'new_item'           => __('New Discount', 'invoicing'),
138
+        'edit_item'          => __('Edit Discount', 'invoicing'),
139
+        'view_item'          => __('View Discount', 'invoicing'),
140
+        'all_items'          => __('Discounts', 'invoicing'),
141
+        'search_items'       => __('Search Discounts', 'invoicing'),
142
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
143
+        'not_found'          => __('No discounts found.', 'invoicing'),
144
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
145 145
     );
146
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
146
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
147 147
 
148 148
     $cap_type = 'wpi_discount';
149 149
     
150 150
     $args = array(
151 151
         'labels'             => $labels,
152
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
152
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
153 153
         'public'             => false,
154 154
         'can_export'         => true,
155 155
         '_builtin'           => false,
156 156
         'publicly_queryable' => false,
157 157
         'exclude_from_search'=> true,
158 158
         'show_ui'            => true,
159
-        'show_in_menu'       => current_user_can( 'manage_invoicing' ) ? 'wpinv' : false,
159
+        'show_in_menu'       => current_user_can('manage_invoicing') ? 'wpinv' : false,
160 160
         'query_var'          => false,
161 161
         'rewrite'            => false,
162 162
         'capability_type'    => $cap_type,
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         ),
180 180
         'has_archive'        => false,
181 181
         'hierarchical'       => false,
182
-        'supports'           => array( 'title', 'excerpt' ),
182
+        'supports'           => array('title', 'excerpt'),
183 183
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
184 184
         'show_in_nav_menus'  => false,
185 185
         'show_in_admin_bar'  => true,
@@ -187,99 +187,99 @@  discard block
 block discarded – undo
187 187
         'menu_position'      => null,
188 188
     );
189 189
             
190
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
190
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
191 191
     
192
-    register_post_type( 'wpi_discount', $args );
192
+    register_post_type('wpi_discount', $args);
193 193
 }
194 194
 
195 195
 function wpinv_get_default_labels() {
196 196
     $defaults = array(
197
-       'singular' => __( 'Invoice', 'invoicing' ),
198
-       'plural'   => __( 'Invoices', 'invoicing' )
197
+       'singular' => __('Invoice', 'invoicing'),
198
+       'plural'   => __('Invoices', 'invoicing')
199 199
     );
200 200
     
201
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
201
+    return apply_filters('wpinv_default_invoices_name', $defaults);
202 202
 }
203 203
 
204
-function wpinv_get_label_singular( $lowercase = false ) {
204
+function wpinv_get_label_singular($lowercase = false) {
205 205
     $defaults = wpinv_get_default_labels();
206 206
     
207
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
207
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
208 208
 }
209 209
 
210
-function wpinv_get_label_plural( $lowercase = false ) {
210
+function wpinv_get_label_plural($lowercase = false) {
211 211
     $defaults = wpinv_get_default_labels();
212 212
     
213
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
213
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
214 214
 }
215 215
 
216
-function wpinv_change_default_title( $title ) {
217
-     if ( !is_admin() ) {
216
+function wpinv_change_default_title($title) {
217
+     if (!is_admin()) {
218 218
         $label = wpinv_get_label_singular();
219
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
219
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
220 220
         return $title;
221 221
      }
222 222
 
223 223
      $screen = get_current_screen();
224 224
 
225
-     if ( 'wpi_invoice' == $screen->post_type ) {
225
+     if ('wpi_invoice' == $screen->post_type) {
226 226
         $label = wpinv_get_label_singular();
227
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
227
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
228 228
      }
229 229
 
230 230
      return $title;
231 231
 }
232
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
232
+add_filter('enter_title_here', 'wpinv_change_default_title');
233 233
 
234 234
 function wpinv_register_post_status() {
235
-    register_post_status( 'wpi-processing', array(
236
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
235
+    register_post_status('wpi-processing', array(
236
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
237 237
         'public'                    => true,
238 238
         'exclude_from_search'       => true,
239 239
         'show_in_admin_all_list'    => true,
240 240
         'show_in_admin_status_list' => true,
241
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
242
-    ) );
243
-    register_post_status( 'wpi-onhold', array(
244
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
241
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
242
+    ));
243
+    register_post_status('wpi-onhold', array(
244
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
245 245
         'public'                    => true,
246 246
         'exclude_from_search'       => true,
247 247
         'show_in_admin_all_list'    => true,
248 248
         'show_in_admin_status_list' => true,
249
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
250
-    ) );
251
-    register_post_status( 'wpi-cancelled', array(
252
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
249
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
250
+    ));
251
+    register_post_status('wpi-cancelled', array(
252
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
253 253
         'public'                    => true,
254 254
         'exclude_from_search'       => true,
255 255
         'show_in_admin_all_list'    => true,
256 256
         'show_in_admin_status_list' => true,
257
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
258
-    ) );
259
-    register_post_status( 'wpi-refunded', array(
260
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
257
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
258
+    ));
259
+    register_post_status('wpi-refunded', array(
260
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
261 261
         'public'                    => true,
262 262
         'exclude_from_search'       => true,
263 263
         'show_in_admin_all_list'    => true,
264 264
         'show_in_admin_status_list' => true,
265
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
266
-    ) );
267
-    register_post_status( 'wpi-failed', array(
268
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
265
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
266
+    ));
267
+    register_post_status('wpi-failed', array(
268
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
269 269
         'public'                    => true,
270 270
         'exclude_from_search'       => true,
271 271
         'show_in_admin_all_list'    => true,
272 272
         'show_in_admin_status_list' => true,
273
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
274
-    ) );
275
-    register_post_status( 'wpi-renewal', array(
276
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
273
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
274
+    ));
275
+    register_post_status('wpi-renewal', array(
276
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
277 277
         'public'                    => true,
278 278
         'exclude_from_search'       => true,
279 279
         'show_in_admin_all_list'    => true,
280 280
         'show_in_admin_status_list' => true,
281
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
282
-    ) );
281
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
282
+    ));
283 283
 }
284
-add_action( 'init', 'wpinv_register_post_status', 10 );
284
+add_action('init', 'wpinv_register_post_status', 10);
285 285
 
Please login to merge, or discard this patch.