Passed
Pull Request — master (#33)
by Kiran
03:50
created
includes/wpinv-post-types.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@  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
     $args = array(
38 38
         'labels'             => $labels,
39
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
39
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
40 40
         'public'             => true,
41 41
         'can_export'         => true,
42 42
         '_builtin'           => false,
@@ -50,68 +50,68 @@  discard block
 block discarded – undo
50 50
         'has_archive'        => false,
51 51
         'hierarchical'       => false,
52 52
         'menu_position'      => null,
53
-        'supports'           => array( 'title', 'author' ),
53
+        'supports'           => array('title', 'author'),
54 54
         'menu_icon'          => $menu_icon,
55 55
     );
56 56
             
57
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
57
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
58 58
     
59
-    register_post_type( 'wpi_invoice', $args );
59
+    register_post_type('wpi_invoice', $args);
60 60
     
61 61
     $items_labels = array(
62
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
63
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
64
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
65
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
66
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
67
-        'new_item'           => __( 'New Item', 'invoicing' ),
68
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
69
-        'view_item'          => __( 'View Item', 'invoicing' ),
70
-        'all_items'          => __( 'Items', 'invoicing' ),
71
-        'search_items'       => __( 'Search Items', 'invoicing' ),
62
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
63
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
64
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
65
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
66
+        'add_new_item'       => __('Add New Item', 'invoicing'),
67
+        'new_item'           => __('New Item', 'invoicing'),
68
+        'edit_item'          => __('Edit Item', 'invoicing'),
69
+        'view_item'          => __('View Item', 'invoicing'),
70
+        'all_items'          => __('Items', 'invoicing'),
71
+        'search_items'       => __('Search Items', 'invoicing'),
72 72
         'parent_item_colon'  => '',
73
-        'not_found'          => __( 'No items found.', 'invoicing' ),
74
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
73
+        'not_found'          => __('No items found.', 'invoicing'),
74
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
75 75
     );
76
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
76
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
77 77
     
78 78
     $invoice_item_args = array(
79 79
         'labels'                => $items_labels,
80 80
         'public'                => false,
81 81
         'show_ui'               => true,
82 82
         'show_in_menu'          => 'wpinv',
83
-        'supports'              => array( 'title', 'excerpt' ),
83
+        'supports'              => array('title', 'excerpt'),
84 84
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
85 85
         'rewrite'               => false,
86 86
         'query_var'             => false,
87 87
         'map_meta_cap'          => true,
88 88
         'can_export'            => true,
89 89
     );
90
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
90
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
91 91
 
92
-    register_post_type( 'wpi_item', $invoice_item_args );
92
+    register_post_type('wpi_item', $invoice_item_args);
93 93
     
94 94
     $labels = array(
95
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
96
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
97
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
98
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
99
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
100
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
101
-        'new_item'           => __( 'New Discount', 'invoicing' ),
102
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
103
-        'view_item'          => __( 'View Discount', 'invoicing' ),
104
-        'all_items'          => __( 'Discounts', 'invoicing' ),
105
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
106
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
107
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
108
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
95
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
96
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
97
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
98
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
99
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
100
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
101
+        'new_item'           => __('New Discount', 'invoicing'),
102
+        'edit_item'          => __('Edit Discount', 'invoicing'),
103
+        'view_item'          => __('View Discount', 'invoicing'),
104
+        'all_items'          => __('Discounts', 'invoicing'),
105
+        'search_items'       => __('Search Discounts', 'invoicing'),
106
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
107
+        'not_found'          => __('No discounts found.', 'invoicing'),
108
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
109 109
     );
110
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
110
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
111 111
     
112 112
     $args = array(
113 113
         'labels'             => $labels,
114
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
114
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
115 115
         'public'             => false,
116 116
         'can_export'         => true,
117 117
         '_builtin'           => false,
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         'map_meta_cap'       => true,
126 126
         'has_archive'        => false,
127 127
         'hierarchical'       => false,
128
-        'supports'           => array( 'title', 'excerpt' ),
128
+        'supports'           => array('title', 'excerpt'),
129 129
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
130 130
         'show_in_nav_menus'  => false,
131 131
         'show_in_admin_bar'  => true,
@@ -133,99 +133,99 @@  discard block
 block discarded – undo
133 133
         'menu_position'      => null,
134 134
     );
135 135
             
136
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
136
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
137 137
     
138
-    register_post_type( 'wpi_discount', $args );
138
+    register_post_type('wpi_discount', $args);
139 139
 }
140 140
 
141 141
 function wpinv_get_default_labels() {
142 142
     $defaults = array(
143
-       'singular' => __( 'Invoice', 'invoicing' ),
144
-       'plural'   => __( 'Invoices', 'invoicing' )
143
+       'singular' => __('Invoice', 'invoicing'),
144
+       'plural'   => __('Invoices', 'invoicing')
145 145
     );
146 146
     
147
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
147
+    return apply_filters('wpinv_default_invoices_name', $defaults);
148 148
 }
149 149
 
150
-function wpinv_get_label_singular( $lowercase = false ) {
150
+function wpinv_get_label_singular($lowercase = false) {
151 151
     $defaults = wpinv_get_default_labels();
152 152
     
153
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
153
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
154 154
 }
155 155
 
156
-function wpinv_get_label_plural( $lowercase = false ) {
156
+function wpinv_get_label_plural($lowercase = false) {
157 157
     $defaults = wpinv_get_default_labels();
158 158
     
159
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
159
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
160 160
 }
161 161
 
162
-function wpinv_change_default_title( $title ) {
163
-     if ( !is_admin() ) {
162
+function wpinv_change_default_title($title) {
163
+     if (!is_admin()) {
164 164
         $label = wpinv_get_label_singular();
165
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
165
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
166 166
         return $title;
167 167
      }
168 168
 
169 169
      $screen = get_current_screen();
170 170
 
171
-     if ( 'wpi_invoice' == $screen->post_type ) {
171
+     if ('wpi_invoice' == $screen->post_type) {
172 172
         $label = wpinv_get_label_singular();
173
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
173
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
174 174
      }
175 175
 
176 176
      return $title;
177 177
 }
178
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
178
+add_filter('enter_title_here', 'wpinv_change_default_title');
179 179
 
180 180
 function wpinv_register_post_status() {
181
-    register_post_status( 'processing', array(
182
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
181
+    register_post_status('processing', array(
182
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
183 183
         'public'                    => true,
184 184
         'exclude_from_search'       => true,
185 185
         'show_in_admin_all_list'    => true,
186 186
         'show_in_admin_status_list' => true,
187
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
188
-    ) );
189
-    register_post_status( 'onhold', array(
190
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
187
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
188
+    ));
189
+    register_post_status('onhold', array(
190
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
191 191
         'public'                    => true,
192 192
         'exclude_from_search'       => true,
193 193
         'show_in_admin_all_list'    => true,
194 194
         'show_in_admin_status_list' => true,
195
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
196
-    ) );
197
-    register_post_status( 'cancelled', array(
198
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
195
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
196
+    ));
197
+    register_post_status('cancelled', array(
198
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
199 199
         'public'                    => true,
200 200
         'exclude_from_search'       => true,
201 201
         'show_in_admin_all_list'    => true,
202 202
         'show_in_admin_status_list' => true,
203
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
204
-    ) );
205
-    register_post_status( 'refunded', array(
206
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
203
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
204
+    ));
205
+    register_post_status('refunded', array(
206
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
207 207
         'public'                    => true,
208 208
         'exclude_from_search'       => true,
209 209
         'show_in_admin_all_list'    => true,
210 210
         'show_in_admin_status_list' => true,
211
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
212
-    ) );
213
-    register_post_status( 'failed', array(
214
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
211
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
212
+    ));
213
+    register_post_status('failed', array(
214
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
215 215
         'public'                    => true,
216 216
         'exclude_from_search'       => true,
217 217
         'show_in_admin_all_list'    => true,
218 218
         'show_in_admin_status_list' => true,
219
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
220
-    ) );
221
-    register_post_status( 'renewal', array(
222
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
219
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
220
+    ));
221
+    register_post_status('renewal', array(
222
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
223 223
         'public'                    => true,
224 224
         'exclude_from_search'       => true,
225 225
         'show_in_admin_all_list'    => true,
226 226
         'show_in_admin_status_list' => true,
227
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
228
-    ) );
227
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
228
+    ));
229 229
 }
230
-add_action( 'init', 'wpinv_register_post_status', 10 );
230
+add_action('init', 'wpinv_register_post_status', 10);
231 231
 
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +21 added lines, -21 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,65 +14,65 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27 27
         
28
-        do_action( 'wpinv_class_notes_actions', $this );
28
+        do_action('wpinv_class_notes_actions', $this);
29 29
     }
30 30
         
31
-    public function set_invoice_note_type( $query ) {
32
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
31
+    public function set_invoice_note_type($query) {
32
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
33 33
         
34
-        if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) {
34
+        if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) {
35 35
             $query->query_vars['type__in']      = $this->comment_type;
36 36
             $query->query_vars['type__not_in']  = '';
37 37
         } else {        
38
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
39
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
40
-                    $key = array_search( $this->comment_type, $type_in );
41
-                    unset( $query->query_vars['type__in'][$key] );
42
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
38
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
39
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
40
+                    $key = array_search($this->comment_type, $type_in);
41
+                    unset($query->query_vars['type__in'][$key]);
42
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
43 43
                     $query->query_vars['type__in'] = '';
44 44
                 }
45 45
             }
46 46
             
47
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
48
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
47
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
48
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
49 49
                     $query->query_vars['type__not_in'][] = $this->comment_type;
50
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
50
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
51 51
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
52 52
                     $query->query_vars['type__not_in'][] = $this->comment_type;
53 53
                 }
54 54
             } else {
55
-                $query->query_vars['type__not_in']  = $this->comment_type;
55
+                $query->query_vars['type__not_in'] = $this->comment_type;
56 56
             }
57 57
         }
58 58
         
59 59
         return $query;
60 60
     }
61 61
     
62
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
62
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
63 63
         $args = array( 
64 64
             'post_id'   => $invoice_id,
65 65
             'order'     => 'comment_date_gmt',
66 66
             'order'     => 'DESC',
67 67
         );
68 68
         
69
-        if ( $type == 'customer' ) {
69
+        if ($type == 'customer') {
70 70
             $args['meta_key']   = '_wpi_customer_note';
71 71
             $args['meta_value'] = 1;
72 72
         }
73 73
         
74
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
74
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
75 75
         
76
-        return get_comments( $args );
76
+        return get_comments($args);
77 77
     }
78 78
 }
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -7,112 +7,112 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount ) {
44
+function wpinv_sanitize_amount($amount) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_seperator();
47 47
     $decimal_sep   = wpinv_decimal_seperator();
48 48
 
49 49
     // Sanitize the amount
50
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
51
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
52
-            $amount = str_replace( $thousands_sep, '', $amount );
53
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
54
-            $amount = str_replace( '.', '', $amount );
50
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
51
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
52
+            $amount = str_replace($thousands_sep, '', $amount);
53
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
54
+            $amount = str_replace('.', '', $amount);
55 55
         }
56 56
 
57
-        $amount = str_replace( $decimal_sep, '.', $amount );
58
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
59
-        $amount = str_replace( $thousands_sep, '', $amount );
57
+        $amount = str_replace($decimal_sep, '.', $amount);
58
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
59
+        $amount = str_replace($thousands_sep, '', $amount);
60 60
     }
61 61
 
62
-    if( $amount < 0 ) {
62
+    if ($amount < 0) {
63 63
         $is_negative = true;
64 64
     }
65 65
 
66
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
66
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
67 67
 
68
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount );
69
-    $amount   = number_format( (double) $amount, $decimals, '.', '' );
68
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount);
69
+    $amount   = number_format((double)$amount, $decimals, '.', '');
70 70
 
71
-    if( $is_negative ) {
71
+    if ($is_negative) {
72 72
         $amount *= -1;
73 73
     }
74 74
 
75
-    return apply_filters( 'wpinv_sanitize_amount', $amount );
75
+    return apply_filters('wpinv_sanitize_amount', $amount);
76 76
 }
77 77
 
78
-function wpinv_get_invoice_statuses( $trashed = false ) {
78
+function wpinv_get_invoice_statuses($trashed = false) {
79 79
     $invoice_statuses = array(
80
-        'pending'       => __( 'Pending Payment', 'invoicing' ),
81
-        'publish'       => __( 'Paid', 'invoicing' ),
82
-        'processing'    => __( 'Processing', 'invoicing' ),
83
-        'onhold'        => __( 'On Hold', 'invoicing' ),
84
-        'refunded'      => __( 'Refunded', 'invoicing' ),
85
-        'cancelled'     => __( 'Cancelled', 'invoicing' ),
86
-        'failed'        => __( 'Failed', 'invoicing' ),
87
-        'renewal'       => __( 'Renewal Payment', 'invoicing' )
80
+        'pending'       => __('Pending Payment', 'invoicing'),
81
+        'publish'       => __('Paid', 'invoicing'),
82
+        'processing'    => __('Processing', 'invoicing'),
83
+        'onhold'        => __('On Hold', 'invoicing'),
84
+        'refunded'      => __('Refunded', 'invoicing'),
85
+        'cancelled'     => __('Cancelled', 'invoicing'),
86
+        'failed'        => __('Failed', 'invoicing'),
87
+        'renewal'       => __('Renewal Payment', 'invoicing')
88 88
     );
89 89
     
90
-    if ( $trashed ) {
91
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
90
+    if ($trashed) {
91
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
92 92
     }
93 93
 
94
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
94
+    return apply_filters('wpinv_statuses', $invoice_statuses);
95 95
 }
96 96
 
97
-function wpinv_status_nicename( $status ) {
97
+function wpinv_status_nicename($status) {
98 98
     $statuses = wpinv_get_invoice_statuses();
99
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
99
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
100 100
 
101 101
     return $status;
102 102
 }
103 103
 
104 104
 function wpinv_get_currency() {
105
-    $currency = wpinv_get_option( 'currency', 'USD' );
105
+    $currency = wpinv_get_option('currency', 'USD');
106 106
     
107
-    return apply_filters( 'wpinv_currency', $currency );
107
+    return apply_filters('wpinv_currency', $currency);
108 108
 }
109 109
 
110
-function wpinv_currency_symbol( $currency = '' ) {
111
-    if ( empty( $currency ) ) {
110
+function wpinv_currency_symbol($currency = '') {
111
+    if (empty($currency)) {
112 112
         $currency = wpinv_get_currency();
113 113
     }
114 114
     
115
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
115
+    $symbols = apply_filters('wpinv_currency_symbols', array(
116 116
         'AED' => 'د.إ',
117 117
         'ARS' => '&#36;',
118 118
         'AUD' => '&#36;',
@@ -164,78 +164,78 @@  discard block
 block discarded – undo
164 164
         'USD' => '&#36;',
165 165
         'VND' => '&#8363;',
166 166
         'ZAR' => '&#82;',
167
-    ) );
167
+    ));
168 168
 
169
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
169
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
170 170
 
171
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
171
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
172 172
 }
173 173
 
174 174
 function wpinv_currency_position() {
175
-    $position = wpinv_get_option( 'currency_position', 'left' );
175
+    $position = wpinv_get_option('currency_position', 'left');
176 176
     
177
-    return apply_filters( 'wpinv_currency_position', $position );
177
+    return apply_filters('wpinv_currency_position', $position);
178 178
 }
179 179
 
180 180
 function wpinv_thousands_seperator() {
181
-    $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' );
181
+    $thousand_sep = wpinv_get_option('thousands_seperator', ',');
182 182
     
183
-    return apply_filters( 'wpinv_thousands_seperator', $thousand_sep );
183
+    return apply_filters('wpinv_thousands_seperator', $thousand_sep);
184 184
 }
185 185
 
186 186
 function wpinv_decimal_seperator() {
187
-    $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' );
187
+    $decimal_sep = wpinv_get_option('decimal_seperator', '.');
188 188
     
189
-    return apply_filters( 'wpinv_decimal_seperator', $decimal_sep );
189
+    return apply_filters('wpinv_decimal_seperator', $decimal_sep);
190 190
 }
191 191
 
192 192
 function wpinv_decimals() {
193
-    $decimals = wpinv_get_option( 'decimals', 2 );
193
+    $decimals = wpinv_get_option('decimals', 2);
194 194
     
195
-    return apply_filters( 'wpinv_decimals', $decimals );
195
+    return apply_filters('wpinv_decimals', $decimals);
196 196
 }
197 197
 
198 198
 function wpinv_get_currencies() {
199 199
     $currencies = array(
200
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
201
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
202
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
203
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
204
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
205
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
206
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
207
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
208
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
209
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
210
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
211
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
212
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
213
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
214
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
215
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
216
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
217
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
218
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
219
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
220
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
221
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
222
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
223
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
224
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
225
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
226
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
227
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
228
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
229
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
200
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
201
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
202
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
203
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
204
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
205
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
206
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
207
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
208
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
209
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
210
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
211
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
212
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
213
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
214
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
215
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
216
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
217
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
218
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
219
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
220
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
221
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
222
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
223
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
224
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
225
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
226
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
227
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
228
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
229
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
230 230
     );
231 231
     
232
-    asort( $currencies );
232
+    asort($currencies);
233 233
 
234
-    return apply_filters( 'wpinv_currencies', $currencies );
234
+    return apply_filters('wpinv_currencies', $currencies);
235 235
 }
236 236
 
237
-function wpinv_price( $amount = '', $currency = '' ) {
238
-    if( empty( $currency ) ) {
237
+function wpinv_price($amount = '', $currency = '') {
238
+    if (empty($currency)) {
239 239
         $currency = wpinv_get_currency();
240 240
     }
241 241
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
     $negative = $amount < 0;
245 245
 
246
-    if ( $negative ) {
247
-        $amount = substr( $amount, 1 );
246
+    if ($negative) {
247
+        $amount = substr($amount, 1);
248 248
     }
249 249
 
250
-    $symbol = wpinv_currency_symbol( $currency );
250
+    $symbol = wpinv_currency_symbol($currency);
251 251
 
252
-    if ( $position == 'left' || $position == 'left_space' ) {
253
-        switch ( $currency ) {
252
+    if ($position == 'left' || $position == 'left_space') {
253
+        switch ($currency) {
254 254
             case "GBP" :
255 255
             case "BRL" :
256 256
             case "EUR" :
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
             case "NZD" :
263 263
             case "SGD" :
264 264
             case "JPY" :
265
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
265
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
266 266
                 break;
267 267
             default :
268 268
                 //$price = $currency . ' ' . $amount;
269
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
269
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
270 270
                 break;
271 271
         }
272 272
     } else {
273
-        switch ( $currency ) {
273
+        switch ($currency) {
274 274
             case "GBP" :
275 275
             case "BRL" :
276 276
             case "EUR" :
@@ -281,82 +281,82 @@  discard block
 block discarded – undo
281 281
             case "MXN" :
282 282
             case "SGD" :
283 283
             case "JPY" :
284
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
284
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
285 285
                 break;
286 286
             default :
287 287
                 //$price = $amount . ' ' . $currency;
288
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
288
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
289 289
                 break;
290 290
         }
291 291
     }
292 292
     
293
-    if ( $negative ) {
293
+    if ($negative) {
294 294
         $price = '-' . $price;
295 295
     }
296 296
     
297
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
297
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
298 298
 
299 299
     return $price;
300 300
 }
301 301
 
302
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
302
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
303 303
     $thousands_sep = wpinv_thousands_seperator();
304 304
     $decimal_sep   = wpinv_decimal_seperator();
305 305
 
306
-    if ( $decimals === NULL ) {
306
+    if ($decimals === NULL) {
307 307
         $decimals = wpinv_decimals();
308 308
     }
309 309
 
310
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
311
-        $whole = substr( $amount, 0, $sep_found );
312
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
310
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
311
+        $whole = substr($amount, 0, $sep_found);
312
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
313 313
         $amount = $whole . '.' . $part;
314 314
     }
315 315
 
316
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
317
-        $amount = str_replace( ',', '', $amount );
316
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
317
+        $amount = str_replace(',', '', $amount);
318 318
     }
319 319
 
320
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
321
-        $amount = str_replace( ' ', '', $amount );
320
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
321
+        $amount = str_replace(' ', '', $amount);
322 322
     }
323 323
 
324
-    if ( empty( $amount ) ) {
324
+    if (empty($amount)) {
325 325
         $amount = 0;
326 326
     }
327 327
     
328
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
329
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
328
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
329
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
330 330
     
331
-    if ( $calculate ) {
332
-        if ( $thousands_sep === "," ) {
333
-            $formatted = str_replace( ",", "", $formatted );
331
+    if ($calculate) {
332
+        if ($thousands_sep === ",") {
333
+            $formatted = str_replace(",", "", $formatted);
334 334
         }
335 335
         
336
-        if ( $decimal_sep === "," ) {
337
-            $formatted = str_replace( ",", ".", $formatted );
336
+        if ($decimal_sep === ",") {
337
+            $formatted = str_replace(",", ".", $formatted);
338 338
         }
339 339
     }
340 340
 
341
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
341
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
342 342
 }
343 343
 
344
-function wpinv_sanitize_key( $key ) {
344
+function wpinv_sanitize_key($key) {
345 345
     $raw_key = $key;
346
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
346
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
347 347
 
348
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
348
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
349 349
 }
350 350
 
351
-function wpinv_get_file_extension( $str ) {
352
-    $parts = explode( '.', $str );
353
-    return end( $parts );
351
+function wpinv_get_file_extension($str) {
352
+    $parts = explode('.', $str);
353
+    return end($parts);
354 354
 }
355 355
 
356
-function wpinv_string_is_image_url( $str ) {
357
-    $ext = wpinv_get_file_extension( $str );
356
+function wpinv_string_is_image_url($str) {
357
+    $ext = wpinv_get_file_extension($str);
358 358
 
359
-    switch ( strtolower( $ext ) ) {
359
+    switch (strtolower($ext)) {
360 360
         case 'jpeg';
361 361
         case 'jpg';
362 362
             $return = true;
@@ -372,32 +372,32 @@  discard block
 block discarded – undo
372 372
             break;
373 373
     }
374 374
 
375
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
375
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
376 376
 }
377 377
 
378
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
379
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
378
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
379
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
380 380
     
381
-    if ( true === $should_log ) {
381
+    if (true === $should_log) {
382 382
         $label = '';
383
-        if ( $file && $file !== '' ) {
384
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
383
+        if ($file && $file !== '') {
384
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
385 385
         }
386 386
         
387
-        if ( $title && $title !== '' ) {
387
+        if ($title && $title !== '') {
388 388
             $label = $label !== '' ? $label . ' ' : '';
389 389
             $label .= $title . ' ';
390 390
         }
391 391
         
392
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
392
+        $label = $label !== '' ? trim($label) . ' : ' : '';
393 393
         
394
-        if ( is_array( $log ) || is_object( $log ) ) {
395
-            error_log( $label . print_r( $log, true ) );
394
+        if (is_array($log) || is_object($log)) {
395
+            error_log($label . print_r($log, true));
396 396
         } else {
397
-            error_log( $label . $log );
397
+            error_log($label . $log);
398 398
         }
399 399
         
400
-        if ( $exit ) {
400
+        if ($exit) {
401 401
             exit;
402 402
         }
403 403
     }
@@ -405,65 +405,65 @@  discard block
 block discarded – undo
405 405
 
406 406
 function wpinv_is_ajax_disabled() {
407 407
     $retval = false;
408
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
408
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
409 409
 }
410 410
 
411
-function wpinv_get_current_page_url( $nocache = false ) {
411
+function wpinv_get_current_page_url($nocache = false) {
412 412
     global $wp;
413 413
 
414
-    if ( get_option( 'permalink_structure' ) ) {
415
-        $base = trailingslashit( home_url( $wp->request ) );
414
+    if (get_option('permalink_structure')) {
415
+        $base = trailingslashit(home_url($wp->request));
416 416
     } else {
417
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
418
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
417
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
418
+        $base = remove_query_arg(array('post_type', 'name'), $base);
419 419
     }
420 420
 
421 421
     $scheme = is_ssl() ? 'https' : 'http';
422
-    $uri    = set_url_scheme( $base, $scheme );
422
+    $uri    = set_url_scheme($base, $scheme);
423 423
 
424
-    if ( is_front_page() ) {
425
-        $uri = home_url( '/' );
426
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
424
+    if (is_front_page()) {
425
+        $uri = home_url('/');
426
+    } elseif (wpinv_is_checkout(array(), false)) {
427 427
         $uri = wpinv_get_checkout_uri();
428 428
     }
429 429
 
430
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
430
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
431 431
 
432
-    if ( $nocache ) {
433
-        $uri = wpinv_add_cache_busting( $uri );
432
+    if ($nocache) {
433
+        $uri = wpinv_add_cache_busting($uri);
434 434
     }
435 435
 
436 436
     return $uri;
437 437
 }
438 438
 
439 439
 function wpinv_get_php_arg_separator_output() {
440
-	return ini_get( 'arg_separator.output' );
440
+	return ini_get('arg_separator.output');
441 441
 }
442 442
 
443
-function wpinv_rgb_from_hex( $color ) {
444
-    $color = str_replace( '#', '', $color );
443
+function wpinv_rgb_from_hex($color) {
444
+    $color = str_replace('#', '', $color);
445 445
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
446
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
446
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
447 447
 
448 448
     $rgb      = array();
449
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
450
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
451
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
449
+    $rgb['R'] = hexdec($color{0} . $color{1} );
450
+    $rgb['G'] = hexdec($color{2} . $color{3} );
451
+    $rgb['B'] = hexdec($color{4} . $color{5} );
452 452
 
453 453
     return $rgb;
454 454
 }
455 455
 
456
-function wpinv_hex_darker( $color, $factor = 30 ) {
457
-    $base  = wpinv_rgb_from_hex( $color );
456
+function wpinv_hex_darker($color, $factor = 30) {
457
+    $base  = wpinv_rgb_from_hex($color);
458 458
     $color = '#';
459 459
 
460
-    foreach ( $base as $k => $v ) {
460
+    foreach ($base as $k => $v) {
461 461
         $amount      = $v / 100;
462
-        $amount      = round( $amount * $factor );
462
+        $amount      = round($amount * $factor);
463 463
         $new_decimal = $v - $amount;
464 464
 
465
-        $new_hex_component = dechex( $new_decimal );
466
-        if ( strlen( $new_hex_component ) < 2 ) {
465
+        $new_hex_component = dechex($new_decimal);
466
+        if (strlen($new_hex_component) < 2) {
467 467
             $new_hex_component = "0" . $new_hex_component;
468 468
         }
469 469
         $color .= $new_hex_component;
@@ -472,18 +472,18 @@  discard block
 block discarded – undo
472 472
     return $color;
473 473
 }
474 474
 
475
-function wpinv_hex_lighter( $color, $factor = 30 ) {
476
-    $base  = wpinv_rgb_from_hex( $color );
475
+function wpinv_hex_lighter($color, $factor = 30) {
476
+    $base  = wpinv_rgb_from_hex($color);
477 477
     $color = '#';
478 478
 
479
-    foreach ( $base as $k => $v ) {
479
+    foreach ($base as $k => $v) {
480 480
         $amount      = 255 - $v;
481 481
         $amount      = $amount / 100;
482
-        $amount      = round( $amount * $factor );
482
+        $amount      = round($amount * $factor);
483 483
         $new_decimal = $v + $amount;
484 484
 
485
-        $new_hex_component = dechex( $new_decimal );
486
-        if ( strlen( $new_hex_component ) < 2 ) {
485
+        $new_hex_component = dechex($new_decimal);
486
+        if (strlen($new_hex_component) < 2) {
487 487
             $new_hex_component = "0" . $new_hex_component;
488 488
         }
489 489
         $color .= $new_hex_component;
@@ -492,22 +492,22 @@  discard block
 block discarded – undo
492 492
     return $color;
493 493
 }
494 494
 
495
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
496
-    $hex = str_replace( '#', '', $color );
495
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
496
+    $hex = str_replace('#', '', $color);
497 497
 
498
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
499
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
500
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
498
+    $c_r = hexdec(substr($hex, 0, 2));
499
+    $c_g = hexdec(substr($hex, 2, 2));
500
+    $c_b = hexdec(substr($hex, 4, 2));
501 501
 
502
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
502
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
503 503
 
504 504
     return $brightness > 155 ? $dark : $light;
505 505
 }
506 506
 
507
-function wpinv_format_hex( $hex ) {
508
-    $hex = trim( str_replace( '#', '', $hex ) );
507
+function wpinv_format_hex($hex) {
508
+    $hex = trim(str_replace('#', '', $hex));
509 509
 
510
-    if ( strlen( $hex ) == 3 ) {
510
+    if (strlen($hex) == 3) {
511 511
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
512 512
     }
513 513
 
@@ -527,12 +527,12 @@  discard block
 block discarded – undo
527 527
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
528 528
  * @return string
529 529
  */
530
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
531
-    if ( function_exists( 'mb_strimwidth' ) ) {
532
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
530
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
531
+    if (function_exists('mb_strimwidth')) {
532
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
533 533
     }
534 534
     
535
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
535
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
536 536
 }
537 537
 
538 538
 /**
@@ -544,28 +544,28 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return int Returns the number of characters in string.
546 546
  */
547
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strlen' ) ) {
549
-        return mb_strlen( $str, $encoding );
547
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strlen')) {
549
+        return mb_strlen($str, $encoding);
550 550
     }
551 551
         
552
-    return strlen( $str );
552
+    return strlen($str);
553 553
 }
554 554
 
555
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
556
-    if ( function_exists( 'mb_strtolower' ) ) {
557
-        return mb_strtolower( $str, $encoding );
555
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
556
+    if (function_exists('mb_strtolower')) {
557
+        return mb_strtolower($str, $encoding);
558 558
     }
559 559
     
560
-    return strtolower( $str );
560
+    return strtolower($str);
561 561
 }
562 562
 
563
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
564
-    if ( function_exists( 'mb_strtoupper' ) ) {
565
-        return mb_strtoupper( $str, $encoding );
563
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
564
+    if (function_exists('mb_strtoupper')) {
565
+        return mb_strtoupper($str, $encoding);
566 566
     }
567 567
     
568
-    return strtoupper( $str );
568
+    return strtoupper($str);
569 569
 }
570 570
 
571 571
 /**
@@ -579,12 +579,12 @@  discard block
 block discarded – undo
579 579
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
580 580
  * @return int Returns the position of the first occurrence of search in the string.
581 581
  */
582
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
583
-    if ( function_exists( 'mb_strpos' ) ) {
584
-        return mb_strpos( $str, $find, $offset, $encoding );
582
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
583
+    if (function_exists('mb_strpos')) {
584
+        return mb_strpos($str, $find, $offset, $encoding);
585 585
     }
586 586
         
587
-    return strpos( $str, $find, $offset );
587
+    return strpos($str, $find, $offset);
588 588
 }
589 589
 
590 590
 /**
@@ -598,12 +598,12 @@  discard block
 block discarded – undo
598 598
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
599 599
  * @return int Returns the position of the last occurrence of search.
600 600
  */
601
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
602
-    if ( function_exists( 'mb_strrpos' ) ) {
603
-        return mb_strrpos( $str, $find, $offset, $encoding );
601
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
602
+    if (function_exists('mb_strrpos')) {
603
+        return mb_strrpos($str, $find, $offset, $encoding);
604 604
     }
605 605
         
606
-    return strrpos( $str, $find, $offset );
606
+    return strrpos($str, $find, $offset);
607 607
 }
608 608
 
609 609
 /**
@@ -618,16 +618,16 @@  discard block
 block discarded – undo
618 618
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
619 619
  * @return string
620 620
  */
621
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
622
-    if ( function_exists( 'mb_substr' ) ) {
623
-        if ( $length === null ) {
624
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
621
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
622
+    if (function_exists('mb_substr')) {
623
+        if ($length === null) {
624
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
625 625
         } else {
626
-            return mb_substr( $str, $start, $length, $encoding );
626
+            return mb_substr($str, $start, $length, $encoding);
627 627
         }
628 628
     }
629 629
         
630
-    return substr( $str, $start, $length );
630
+    return substr($str, $start, $length);
631 631
 }
632 632
 
633 633
 /**
@@ -639,48 +639,48 @@  discard block
 block discarded – undo
639 639
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
640 640
  * @return string The width of string.
641 641
  */
642
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
643
-    if ( function_exists( 'mb_strwidth' ) ) {
644
-        return mb_strwidth( $str, $encoding );
642
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
643
+    if (function_exists('mb_strwidth')) {
644
+        return mb_strwidth($str, $encoding);
645 645
     }
646 646
     
647
-    return wpinv_utf8_strlen( $str, $encoding );
647
+    return wpinv_utf8_strlen($str, $encoding);
648 648
 }
649 649
 
650
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
651
-    if ( function_exists( 'mb_strlen' ) ) {
652
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
650
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
651
+    if (function_exists('mb_strlen')) {
652
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
653 653
         $str_end = "";
654 654
         
655
-        if ( $lower_str_end ) {
656
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
655
+        if ($lower_str_end) {
656
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
657 657
         } else {
658
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
658
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
659 659
         }
660 660
 
661 661
         return $first_letter . $str_end;
662 662
     }
663 663
     
664
-    return ucfirst( $str );
664
+    return ucfirst($str);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_convert_case' ) ) {
669
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
667
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_convert_case')) {
669
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
670 670
     }
671 671
     
672
-    return ucwords( $str );
672
+    return ucwords($str);
673 673
 }
674 674
 
675
-function wpinv_period_in_days( $period, $unit ) {
676
-    $period = absint( $period );
675
+function wpinv_period_in_days($period, $unit) {
676
+    $period = absint($period);
677 677
     
678
-    if ( $period > 0 ) {
679
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
678
+    if ($period > 0) {
679
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
680 680
             $period = $period * 7;
681
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
681
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
682 682
             $period = $period * 30;
683
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
683
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
684 684
             $period = $period * 365;
685 685
         }
686 686
     }
Please login to merge, or discard this patch.
includes/libraries/GeoIp2/Model/City.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,6 @@
 block discarded – undo
130 130
     private function mostSpecificSubdivision()
131 131
     {
132 132
         return empty($this->subdivisions) ?
133
-            new \GeoIp2\Record\Subdivision(array(), $this->locales) :
134
-            end($this->subdivisions);
133
+            new \GeoIp2\Record\Subdivision(array(), $this->locales) : end($this->subdivisions);
135 134
     }
136 135
 }
Please login to merge, or discard this patch.
includes/libraries/GeoIp2/WebService/Client.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
         // This is for backwards compatibility. Do not remove except for a
77 77
         // major version bump.
78 78
         if (is_string($options)) {
79
-            $options = array( 'host' => $options );
79
+            $options = array('host' => $options);
80 80
         }
81 81
 
82 82
         if (!isset($options['host'])) {
Please login to merge, or discard this patch.
includes/libraries/class-emogrifier.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		if ($nodesWithStyleAttributes !== false) {
239 239
 			/** @var $nodeWithStyleAttribute DOMNode */
240 240
 			foreach ($nodesWithStyleAttributes as $node) {
241
-				$normalizedOriginalStyle = preg_replace_callback( '/[A-z\\-]+(?=\\:)/S', array( $this, 'strtolower' ), $node->getAttribute('style') );
241
+				$normalizedOriginalStyle = preg_replace_callback('/[A-z\\-]+(?=\\:)/S', array($this, 'strtolower'), $node->getAttribute('style'));
242 242
 
243 243
 				// in order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles
244 244
 				$nodePath = $node->getNodePath();
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 			}
290 290
 
291 291
 			// now sort the selectors by precedence
292
-			usort($allSelectors, array($this,'sortBySelectorPrecedence'));
292
+			usort($allSelectors, array($this, 'sortBySelectorPrecedence'));
293 293
 
294 294
 			$this->caches[self::CACHE_KEY_CSS][$cssKey] = $allSelectors;
295 295
 		}
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		if ($nodesWithStyleDisplayNone->length > 0) {
330 330
 			/** @var $node \DOMNode */
331 331
 			foreach ($nodesWithStyleDisplayNone as $node) {
332
-				if ($node->parentNode && is_callable(array($node->parentNode,'removeChild'))) {
332
+				if ($node->parentNode && is_callable(array($node->parentNode, 'removeChild'))) {
333 333
 					$node->parentNode->removeChild($node);
334 334
 				}
335 335
 			}
@@ -338,10 +338,10 @@  discard block
 block discarded – undo
338 338
 		$this->copyCssWithMediaToStyleNode($cssParts, $xmlDocument);
339 339
 
340 340
 		if ($this->preserveEncoding) {
341
-			if ( function_exists( 'mb_convert_encoding' ) ) {
342
-				return mb_convert_encoding( $xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES' );
341
+			if (function_exists('mb_convert_encoding')) {
342
+				return mb_convert_encoding($xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES');
343 343
 			} else {
344
-				return htmlspecialchars_decode( utf8_encode( html_entity_decode( $xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING ) ) );
344
+				return htmlspecialchars_decode(utf8_encode(html_entity_decode($xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING)));
345 345
 			}
346 346
 		} else {
347 347
 			return $xmlDocument->saveHTML();
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 * @return array
463 463
 	 */
464 464
 	private function splitCssAndMediaQuery($css) {
465
-		$css = preg_replace_callback( '#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array( $this, '_media_concat' ), $css );
465
+		$css = preg_replace_callback('#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array($this, '_media_concat'), $css);
466 466
 
467 467
 		// filter the CSS
468 468
 		$search = array(
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 		return array('css' => $css, 'media' => self::$_media);
487 487
 	}
488 488
 
489
-	private function _media_concat( $matches ) {
489
+	private function _media_concat($matches) {
490 490
 		self::$_media .= $matches[0];
491 491
 	}
492 492
 
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 			$bodyWithoutUnprocessableTags = $this->html;
525 525
 		}
526 526
 
527
-		if ( function_exists( 'mb_convert_encoding' ) ) {
528
-			return mb_convert_encoding( $bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING );
527
+		if (function_exists('mb_convert_encoding')) {
528
+			return mb_convert_encoding($bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING);
529 529
 		} else {
530
-			return htmlspecialchars_decode( utf8_decode( htmlentities( $bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false ) ) );
530
+			return htmlspecialchars_decode(utf8_decode(htmlentities($bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false)));
531 531
 		}
532 532
 	}
533 533
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 			$precedence = 0;
563 563
 			$value = 100;
564 564
 			// ids: worth 100, classes: worth 10, elements: worth 1
565
-			$search = array('\\#','\\.','');
565
+			$search = array('\\#', '\\.', '');
566 566
 
567 567
 			foreach ($search as $s) {
568 568
 				if (trim($selector == '')) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 	 */
591 591
 	private function translateCssToXpath($paramCssSelector) {
592 592
 		$cssSelector = ' ' . $paramCssSelector . ' ';
593
-		$cssSelector = preg_replace_callback( '/\s+\w+\s+/', array( $this, 'strtolower' ), $cssSelector );
593
+		$cssSelector = preg_replace_callback('/\s+\w+\s+/', array($this, 'strtolower'), $cssSelector);
594 594
 		$cssSelector = trim($cssSelector);
595 595
 		$xpathKey = md5($cssSelector);
596 596
 		if (!isset($this->caches[self::CACHE_KEY_XPATH][$xpathKey])) {
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 	 * @return array
714 714
 	 */
715 715
 	private function parseNth(array $match) {
716
-		if (in_array(strtolower($match[2]), array('even','odd'))) {
716
+		if (in_array(strtolower($match[2]), array('even', 'odd'))) {
717 717
 			$index = strtolower($match[2]) == 'even' ? 0 : 1;
718 718
 			return array(self::MULTIPLIER => 2, self::INDEX => $index);
719 719
 		} elseif (stripos($match[2], 'n') === false) {
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +707 added lines, -707 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,126 +17,126 @@  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_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
45
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
47
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
49
-        add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
50
-        add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
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_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
45
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
47
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
49
+        add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
50
+        add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
52 52
     }        
53 53
     
54
-    public static function get_eu_states( $sort = true ) {
55
-        $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' );
56
-        if ( $sort ) {
57
-            $sort = sort( $eu_states );
54
+    public static function get_eu_states($sort = true) {
55
+        $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');
56
+        if ($sort) {
57
+            $sort = sort($eu_states);
58 58
         }
59 59
         
60
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
60
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
61 61
     }
62 62
     
63
-    public static function get_gst_countries( $sort = true ) {
64
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
63
+    public static function get_gst_countries($sort = true) {
64
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
65 65
         
66
-        if ( $sort ) {
67
-            $sort = sort( $gst_countries );
66
+        if ($sort) {
67
+            $sort = sort($gst_countries);
68 68
         }
69 69
         
70
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
70
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
71 71
     }
72 72
     
73
-    public static function is_eu_state( $country_code ) {
74
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
73
+    public static function is_eu_state($country_code) {
74
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
75 75
                 
76
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
76
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
77 77
     }
78 78
     
79
-    public static function is_gst_country( $country_code ) {
80
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
79
+    public static function is_gst_country($country_code) {
80
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
81 81
                 
82
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
82
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
83 83
     }
84 84
     
85 85
     public static function enqueue_vat_scripts() {
86
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
86
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
87 87
         
88
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
89
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
88
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
89
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
90 90
         
91
-        $vat_name   = self::get_vat_name();
91
+        $vat_name = self::get_vat_name();
92 92
         
93 93
         $vars = array();
94 94
         $vars['EUStates'] = self::get_eu_states();
95
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
96
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
97
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
98
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
99
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
100
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
101
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
102
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
95
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
96
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
97
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
98
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
99
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
100
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
101
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
102
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
103 103
         $vars['ApplyVATRules'] = self::allow_vat_rules();
104
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
105
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
106
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
107
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
108
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
109
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
110
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
111
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
112
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
113
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
114
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
115
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
116
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
104
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
105
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
106
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
107
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
108
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
109
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
110
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
111
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
112
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
113
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
114
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
115
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
116
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
117 117
         $vars['isFront'] = is_admin() ? false : true;
118
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
118
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
119 119
         $vars['baseCountry'] = wpinv_get_default_country();
120
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
121
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
120
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
121
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
122 122
         
123
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
124
-        wp_enqueue_script( 'wpinv-vat-script' );
125
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
123
+        wp_enqueue_script('wpinv-vat-validation-script');
124
+        wp_enqueue_script('wpinv-vat-script');
125
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
126 126
     }
127 127
 
128 128
     public static function enqueue_admin_scripts() {
129
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
129
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
130 130
             self::enqueue_vat_scripts();
131 131
         }
132 132
     }
133 133
     
134
-    public static function section_vat_settings( $sections ) {
135
-        if ( !empty( $sections ) ) {
136
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
134
+    public static function section_vat_settings($sections) {
135
+        if (!empty($sections)) {
136
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
137 137
             
138
-            if ( self::allow_vat_classes() ) {
139
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
138
+            if (self::allow_vat_classes()) {
139
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
140 140
             }
141 141
         }
142 142
         return $sections;
@@ -145,52 +145,52 @@  discard block
 block discarded – undo
145 145
     public static function vat_rates_settings() {
146 146
         $vat_classes = self::get_rate_classes();
147 147
         $vat_rates = array();
148
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
149
-        $current_url = remove_query_arg( 'wpi_sub' );
148
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
149
+        $current_url = remove_query_arg('wpi_sub');
150 150
         
151 151
         $vat_rates['vat_rates_header'] = array(
152 152
             'id' => 'vat_rates_header',
153
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
153
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
154 154
             'desc' => '',
155 155
             'type' => 'header',
156 156
             'size' => 'regular'
157 157
         );
158 158
         $vat_rates['vat_rates_class'] = array(
159 159
             'id'          => 'vat_rates_class',
160
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
161
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
160
+            'name'        => __('Edit VAT Rates', 'invoicing'),
161
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
162 162
             'type'        => 'select',
163
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
163
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
164 164
             'chosen'      => true,
165
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
165
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
166 166
             'selected'    => $vat_class,
167 167
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
168 168
         );
169 169
         
170
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
170
+        if ($vat_class != '_standard' && $vat_class != '_new') {
171 171
             $vat_rates['vat_rate_delete'] = array(
172 172
                 'id'   => 'vat_rate_delete',
173 173
                 'type' => 'vat_rate_delete',
174 174
             );
175 175
         }
176 176
                     
177
-        if ( $vat_class == '_new' ) {
177
+        if ($vat_class == '_new') {
178 178
             $vat_rates['vat_rates_settings'] = array(
179 179
                 'id' => 'vat_rates_settings',
180
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
180
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
181 181
                 'type' => 'header',
182 182
             );
183 183
             $vat_rates['vat_rate_name'] = array(
184 184
                 'id'   => 'vat_rate_name',
185
-                'name' => __( 'Name', 'invoicing' ),
186
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
185
+                'name' => __('Name', 'invoicing'),
186
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
187 187
                 'type' => 'text',
188 188
                 'size' => 'regular',
189 189
             );
190 190
             $vat_rates['vat_rate_desc'] = array(
191 191
                 'id'   => 'vat_rate_desc',
192
-                'name' => __( 'Description', 'invoicing' ),
193
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
192
+                'name' => __('Description', 'invoicing'),
193
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
194 194
                 'type' => 'text',
195 195
                 'size' => 'regular',
196 196
             );
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $vat_rates['vat_rates'] = array(
203 203
                 'id'   => 'vat_rates',
204 204
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
205
-                'desc' => self::get_class_desc( $vat_class ),
205
+                'desc' => self::get_class_desc($vat_class),
206 206
                 'type' => 'vat_rates',
207 207
             );
208 208
         }
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
         return $vat_rates;
211 211
     }
212 212
     
213
-    public static function vat_settings( $settings ) {
214
-        if ( !empty( $settings ) ) {    
213
+    public static function vat_settings($settings) {
214
+        if (!empty($settings)) {    
215 215
             $vat_settings = array();
216 216
             $vat_settings['vat_company_title'] = array(
217 217
                 'id' => 'vat_company_title',
218
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
218
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
219 219
                 'desc' => '',
220 220
                 'type' => 'header',
221 221
                 'size' => 'regular'
@@ -223,22 +223,22 @@  discard block
 block discarded – undo
223 223
             
224 224
             $vat_settings['vat_company_name'] = array(
225 225
                 'id' => 'vat_company_name',
226
-                'name' => __( 'Your Company Name', 'invoicing' ),
227
-                '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>' ),
226
+                'name' => __('Your Company Name', 'invoicing'),
227
+                '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>'),
228 228
                 'type' => 'text',
229 229
                 'size' => 'regular',
230 230
             );
231 231
             
232 232
             $vat_settings['vat_number'] = array(
233 233
                 'id'   => 'vat_number',
234
-                'name' => __( 'Your VAT Number', 'invoicing' ),
234
+                'name' => __('Your VAT Number', 'invoicing'),
235 235
                 'type' => 'vat_number',
236 236
                 'size' => 'regular',
237 237
             );
238 238
 
239 239
             $vat_settings['vat_settings_title'] = array(
240 240
                 'id' => 'vat_settings_title',
241
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
241
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
242 242
                 'desc' => '',
243 243
                 'type' => 'header',
244 244
                 'size' => 'regular'
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 
247 247
             $vat_settings['apply_vat_rules'] = array(
248 248
                 'id' => 'apply_vat_rules',
249
-                'name' => __( 'Enable VAT rules', 'invoicing' ),
250
-                '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>',
249
+                'name' => __('Enable VAT rules', 'invoicing'),
250
+                '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>',
251 251
                 'type' => 'checkbox',
252 252
                 'std' => '1'
253 253
             );
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 
264 264
             $vat_settings['vat_prevent_b2c_purchase'] = array(
265 265
                 'id' => 'vat_prevent_b2c_purchase',
266
-                'name' => __( 'Prevent EU B2C sales', 'invoicing' ),
267
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
266
+                'name' => __('Prevent EU B2C sales', 'invoicing'),
267
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
268 268
                 'type' => 'checkbox'
269 269
             );
270 270
 
@@ -272,21 +272,21 @@  discard block
 block discarded – undo
272 272
 
273 273
             $vat_settings['vat_same_country_rule'] = array(
274 274
                 'id'          => 'vat_same_country_rule',
275
-                'name'        => __( 'Same country rule', 'invoicing' ),
276
-                'desc'        => __( 'Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
275
+                'name'        => __('Same country rule', 'invoicing'),
276
+                'desc'        => __('Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
277 277
                 'type'        => 'select',
278 278
                 'options'     => array(
279
-                    ''          => __( 'Normal', 'invoicing' ),
280
-                    'no'        => __( 'No VAT', 'invoicing' ),
281
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
279
+                    ''          => __('Normal', 'invoicing'),
280
+                    'no'        => __('No VAT', 'invoicing'),
281
+                    'always'    => __('Always apply VAT', 'invoicing'),
282 282
                 ),
283
-                'placeholder' => __( 'Select a option', 'invoicing' ),
283
+                'placeholder' => __('Select a option', 'invoicing'),
284 284
                 'std'         => ''
285 285
             );
286 286
 
287 287
             $vat_settings['vat_checkout_title'] = array(
288 288
                 'id' => 'vat_checkout_title',
289
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
289
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
290 290
                 'desc' => '',
291 291
                 'type' => 'header',
292 292
                 'size' => 'regular'
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
 
295 295
             $vat_settings['vat_disable_fields'] = array(
296 296
                 'id' => 'vat_disable_fields',
297
-                'name' => __( 'Disable VAT fields', 'invoicing' ),
298
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ),
297
+                'name' => __('Disable VAT fields', 'invoicing'),
298
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing'),
299 299
                 'type' => 'checkbox'
300 300
             );
301 301
 
302 302
             $vat_settings['vat_ip_lookup'] = array(
303 303
                 'id'   => 'vat_ip_lookup',
304
-                'name' => __( 'IP Country lookup', 'invoicing' ),
304
+                'name' => __('IP Country lookup', 'invoicing'),
305 305
                 'type' => 'vat_ip_lookup',
306 306
                 'size' => 'regular',
307 307
                 'std' => 'default'
@@ -309,21 +309,21 @@  discard block
 block discarded – undo
309 309
 
310 310
             $vat_settings['hide_ip_address'] = array(
311 311
                 'id' => 'hide_ip_address',
312
-                'name' => __( 'Hide IP info at checkout', 'invoicing' ),
313
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
312
+                'name' => __('Hide IP info at checkout', 'invoicing'),
313
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
314 314
                 'type' => 'checkbox'
315 315
             );
316 316
 
317 317
             $vat_settings['vat_ip_country_default'] = array(
318 318
                 'id' => 'vat_ip_country_default',
319
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
320
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
319
+                'name' => __('Enable IP Country as Default', 'invoicing'),
320
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
321 321
                 'type' => 'checkbox'
322 322
             );
323 323
 
324 324
             $vat_settings['vies_validation_title'] = array(
325 325
                 'id' => 'vies_validation_title',
326
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
326
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
327 327
                 'desc' => '',
328 328
                 'type' => 'header',
329 329
                 'size' => 'regular'
@@ -331,37 +331,37 @@  discard block
 block discarded – undo
331 331
 
332 332
             $vat_settings['vat_vies_check'] = array(
333 333
                 'id' => 'vat_vies_check',
334
-                'name' => __( 'Disable VIES VAT ID check', 'invoicing' ),
335
-                '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>' ),
334
+                'name' => __('Disable VIES VAT ID check', 'invoicing'),
335
+                '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>'),
336 336
                 'type' => 'checkbox'
337 337
             );
338 338
 
339 339
             $vat_settings['vat_disable_company_name_check'] = array(
340 340
                 'id' => 'vat_disable_company_name_check',
341
-                'name' => __( 'Disable VIES name check', 'invoicing' ),
342
-                '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>' ),
341
+                'name' => __('Disable VIES name check', 'invoicing'),
342
+                '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>'),
343 343
                 'type' => 'checkbox'
344 344
             );
345 345
 
346 346
             $vat_settings['vat_offline_check'] = array(
347 347
                 'id' => 'vat_offline_check',
348
-                'name' => __( 'Disable basic checks', 'invoicing' ),
349
-                'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ),
348
+                'name' => __('Disable basic checks', 'invoicing'),
349
+                'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'),
350 350
                 'type' => 'checkbox'
351 351
             );
352 352
             
353 353
 
354 354
             $settings['vat'] = $vat_settings;
355 355
             
356
-            if ( self::allow_vat_classes() ) {
356
+            if (self::allow_vat_classes()) {
357 357
                 $settings['vat_rates'] = self::vat_rates_settings();
358 358
             }
359 359
             
360 360
             $eu_fallback_rate = array(
361 361
                 'id'   => 'eu_fallback_rate',
362
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
362
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
363 363
                 'type' => 'eu_fallback_rate',
364
-                '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' ),
364
+                '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'),
365 365
                 'std'  => '20',
366 366
                 'size' => 'small'
367 367
             );
@@ -377,11 +377,11 @@  discard block
 block discarded – undo
377 377
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
378 378
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
379 379
         
380
-        if ( !is_dir( $destination_dir ) ) { 
381
-            mkdir( $destination_dir );
380
+        if (!is_dir($destination_dir)) { 
381
+            mkdir($destination_dir);
382 382
         }
383 383
         
384
-        $database_files     = array(
384
+        $database_files = array(
385 385
             'country'   => array(
386 386
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
387 387
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -392,57 +392,57 @@  discard block
 block discarded – undo
392 392
             )
393 393
         );
394 394
 
395
-        foreach( $database_files as $database => $files ) {
396
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
395
+        foreach ($database_files as $database => $files) {
396
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
397 397
             
398
-            if ( empty( $result['success'] ) ) {
398
+            if (empty($result['success'])) {
399 399
                 echo $result['message'];
400 400
                 exit;
401 401
             }
402 402
             
403
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
404
-            echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
403
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
404
+            echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' ';
405 405
         }
406 406
         
407 407
         exit;
408 408
     }
409 409
     
410
-    public static function geoip2_download_file( $source_url, $destination_file ) {
410
+    public static function geoip2_download_file($source_url, $destination_file) {
411 411
         $success    = false;
412 412
         $message    = '';
413 413
         
414
-        if ( !function_exists( 'download_url' ) ) {
415
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
414
+        if (!function_exists('download_url')) {
415
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
416 416
         }
417 417
 
418
-        $temp_file  = download_url( $source_url );
418
+        $temp_file = download_url($source_url);
419 419
         
420
-        if ( is_wp_error( $temp_file ) ) {
421
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
420
+        if (is_wp_error($temp_file)) {
421
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
422 422
         } else {
423
-            $handle = gzopen( $temp_file, 'rb' );
423
+            $handle = gzopen($temp_file, 'rb');
424 424
             
425
-            if ( $handle ) {
426
-                $fopen  = fopen( $destination_file, 'wb' );
427
-                if ( $fopen ) {
428
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
429
-                        fwrite( $fopen, $data );
425
+            if ($handle) {
426
+                $fopen = fopen($destination_file, 'wb');
427
+                if ($fopen) {
428
+                    while (($data = gzread($handle, 4096)) != false) {
429
+                        fwrite($fopen, $data);
430 430
                     }
431 431
 
432
-                    gzclose( $handle );
433
-                    fclose( $fopen );
432
+                    gzclose($handle);
433
+                    fclose($fopen);
434 434
                         
435 435
                     $success = true;
436 436
                 } else {
437
-                    gzclose( $handle );
438
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
437
+                    gzclose($handle);
438
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
439 439
                 }
440 440
             } else {
441
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
441
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
442 442
             }
443 443
             
444
-            if ( file_exists( $temp_file ) ) {
445
-                unlink( $temp_file );
444
+            if (file_exists($temp_file)) {
445
+                unlink($temp_file);
446 446
             }
447 447
         }
448 448
         
@@ -454,11 +454,11 @@  discard block
 block discarded – undo
454 454
     }
455 455
     
456 456
     public static function load_geoip2() {
457
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
457
+        if (defined('WPINV_GEOIP2_LODDED')) {
458 458
             return;
459 459
         }
460 460
         
461
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
461
+        if (!class_exists('\MaxMind\Db\Reader')) {
462 462
             $maxmind_db_files = array(
463 463
                 'Reader/Decoder.php',
464 464
                 'Reader/InvalidDatabaseException.php',
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
                 'Reader.php',
468 468
             );
469 469
             
470
-            foreach ( $maxmind_db_files as $key => $file ) {
471
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
470
+            foreach ($maxmind_db_files as $key => $file) {
471
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
472 472
             }
473 473
         }
474 474
         
475
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
475
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
476 476
             $geoip2_files = array(
477 477
                 'ProviderInterface.php',
478 478
                 'Compat/JsonSerializable.php',
@@ -506,23 +506,23 @@  discard block
 block discarded – undo
506 506
                 'WebService/Client.php',
507 507
             );
508 508
             
509
-            foreach ( $geoip2_files as $key => $file ) {
510
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
509
+            foreach ($geoip2_files as $key => $file) {
510
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
511 511
             }
512 512
         }
513 513
 
514
-        define( 'WPINV_GEOIP2_LODDED', true );
514
+        define('WPINV_GEOIP2_LODDED', true);
515 515
     }
516 516
 
517 517
     public static function geoip2_country_dbfile() {
518 518
         $upload_dir = wp_upload_dir();
519 519
 
520
-        if ( !isset( $upload_dir['basedir'] ) ) {
520
+        if (!isset($upload_dir['basedir'])) {
521 521
             return false;
522 522
         }
523 523
 
524 524
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
525
-        if ( !file_exists( $filename ) ) {
525
+        if (!file_exists($filename)) {
526 526
             return false;
527 527
         }
528 528
         
@@ -532,12 +532,12 @@  discard block
 block discarded – undo
532 532
     public static function geoip2_city_dbfile() {
533 533
         $upload_dir = wp_upload_dir();
534 534
 
535
-        if ( !isset( $upload_dir['basedir'] ) ) {
535
+        if (!isset($upload_dir['basedir'])) {
536 536
             return false;
537 537
         }
538 538
 
539 539
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
540
-        if ( !file_exists( $filename ) ) {
540
+        if (!file_exists($filename)) {
541 541
             return false;
542 542
         }
543 543
         
@@ -548,10 +548,10 @@  discard block
 block discarded – undo
548 548
         try {
549 549
             self::load_geoip2();
550 550
 
551
-            if ( $filename = self::geoip2_country_dbfile() ) {
552
-                return new \GeoIp2\Database\Reader( $filename );
551
+            if ($filename = self::geoip2_country_dbfile()) {
552
+                return new \GeoIp2\Database\Reader($filename);
553 553
             }
554
-        } catch( Exception $e ) {
554
+        } catch (Exception $e) {
555 555
             return false;
556 556
         }
557 557
         
@@ -562,173 +562,173 @@  discard block
 block discarded – undo
562 562
         try {
563 563
             self::load_geoip2();
564 564
 
565
-            if ( $filename = self::geoip2_city_dbfile() ) {
566
-                return new \GeoIp2\Database\Reader( $filename );
565
+            if ($filename = self::geoip2_city_dbfile()) {
566
+                return new \GeoIp2\Database\Reader($filename);
567 567
             }
568
-        } catch( Exception $e ) {
568
+        } catch (Exception $e) {
569 569
             return false;
570 570
         }
571 571
         
572 572
         return false;
573 573
     }
574 574
 
575
-    public static function geoip2_country_record( $ip_address ) {
575
+    public static function geoip2_country_record($ip_address) {
576 576
         try {
577 577
             $reader = self::geoip2_country_reader();
578 578
 
579
-            if ( $reader ) {
580
-                $record = $reader->country( $ip_address );
579
+            if ($reader) {
580
+                $record = $reader->country($ip_address);
581 581
                 
582
-                if ( !empty( $record->country->isoCode ) ) {
582
+                if (!empty($record->country->isoCode)) {
583 583
                     return $record;
584 584
                 }
585 585
             }
586
-        } catch(\InvalidArgumentException $e) {
587
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
586
+        } catch (\InvalidArgumentException $e) {
587
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
588 588
             
589 589
             return false;
590
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
591
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
590
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
591
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
592 592
             
593 593
             return false;
594
-        } catch( Exception $e ) {
594
+        } catch (Exception $e) {
595 595
             return false;
596 596
         }
597 597
         
598 598
         return false;
599 599
     }
600 600
 
601
-    public static function geoip2_city_record( $ip_address ) {
601
+    public static function geoip2_city_record($ip_address) {
602 602
         try {
603 603
             $reader = self::geoip2_city_reader();
604 604
 
605
-            if ( $reader ) {
606
-                $record = $reader->city( $ip_address );
605
+            if ($reader) {
606
+                $record = $reader->city($ip_address);
607 607
                 
608
-                if ( !empty( $record->country->isoCode ) ) {
608
+                if (!empty($record->country->isoCode)) {
609 609
                     return $record;
610 610
                 }
611 611
             }
612
-        } catch(\InvalidArgumentException $e) {
613
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
612
+        } catch (\InvalidArgumentException $e) {
613
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
614 614
             
615 615
             return false;
616
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
617
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
616
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
617
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
618 618
             
619 619
             return false;
620
-        } catch( Exception $e ) {
620
+        } catch (Exception $e) {
621 621
             return false;
622 622
         }
623 623
         
624 624
         return false;
625 625
     }
626 626
 
627
-    public static function geoip2_country_code( $ip_address ) {
628
-        $record = self::geoip2_country_record( $ip_address );
629
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
627
+    public static function geoip2_country_code($ip_address) {
628
+        $record = self::geoip2_country_record($ip_address);
629
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
630 630
     }
631 631
 
632 632
     // Find country by IP address.
633
-    public static function get_country_by_ip( $ip = '' ) {
633
+    public static function get_country_by_ip($ip = '') {
634 634
         global $wpinv_ip_address_country;
635 635
         
636
-        if ( !empty( $wpinv_ip_address_country ) ) {
636
+        if (!empty($wpinv_ip_address_country)) {
637 637
             return $wpinv_ip_address_country;
638 638
         }
639 639
         
640
-        if ( empty( $ip ) ) {
640
+        if (empty($ip)) {
641 641
             $ip = wpinv_get_ip();
642 642
         }
643 643
 
644
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
645
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
644
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
645
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
646 646
 
647
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
648
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
647
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
648
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
649 649
                 try {
650
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
651
-                } catch( Exception $e ) {
652
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
650
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
651
+                } catch (Exception $e) {
652
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
653 653
                 }
654
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
655
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
656
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
657
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
654
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
655
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
656
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
657
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
658 658
                 
659
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
659
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
660 660
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
661 661
                 }
662 662
             }
663 663
         }
664 664
 
665
-        if ( empty( $wpinv_ip_address_country ) ) {
665
+        if (empty($wpinv_ip_address_country)) {
666 666
             $wpinv_ip_address_country = wpinv_get_default_country();
667 667
         }
668 668
 
669 669
         return $wpinv_ip_address_country;
670 670
     }
671 671
     
672
-    public static function sanitize_vat_settings( $input ) {
672
+    public static function sanitize_vat_settings($input) {
673 673
         global $wpinv_options;
674 674
         
675 675
         $valid      = false;
676 676
         $message    = '';
677 677
         
678
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
679
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
680
-                $valid = self::offline_check( $input['vat_number'] );
678
+        if (!empty($wpinv_options['vat_vies_check'])) {
679
+            if (empty($wpinv_options['vat_offline_check'])) {
680
+                $valid = self::offline_check($input['vat_number']);
681 681
             } else {
682 682
                 $valid = true;
683 683
             }
684 684
             
685
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
685
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
686 686
         } else {
687
-            $result = self::check_vat( $input['vat_number'] );
687
+            $result = self::check_vat($input['vat_number']);
688 688
             
689
-            if ( empty( $result['valid'] ) ) {
689
+            if (empty($result['valid'])) {
690 690
                 $valid      = false;
691 691
                 $message    = $result['message'];
692 692
             } else {
693
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
694
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
693
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
694
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
695 695
             }
696 696
         }
697 697
 
698
-        if ( $message && self::is_vat_validated() != $valid ) {
699
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
698
+        if ($message && self::is_vat_validated() != $valid) {
699
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
700 700
         }
701 701
 
702 702
         $input['vat_valid'] = $valid;
703 703
         return $input;
704 704
     }
705 705
     
706
-    public static function sanitize_vat_rates( $input ) {
707
-        if( !current_user_can( 'manage_options' ) ) {
708
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
706
+    public static function sanitize_vat_rates($input) {
707
+        if (!current_user_can('manage_options')) {
708
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
709 709
             return $input;
710 710
         }
711 711
         
712 712
         $vat_classes = self::get_rate_classes();
713
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
713
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
714 714
         
715
-        if ( empty( $vat_class ) ) {
716
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
715
+        if (empty($vat_class)) {
716
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
717 717
             
718 718
             return $input;
719 719
         }
720 720
 
721
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
721
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
722 722
 
723
-        if ( $vat_class === '_standard' ) {
723
+        if ($vat_class === '_standard') {
724 724
             // Save the active rates in the invoice settings
725
-            update_option( 'wpinv_tax_rates', $new_rates );
725
+            update_option('wpinv_tax_rates', $new_rates);
726 726
         } else {
727 727
             // Get the existing set of rates
728 728
             $rates = self::get_non_standard_rates();
729 729
             $rates[$vat_class] = $new_rates;
730 730
 
731
-            update_option( 'wpinv_vat_rates', $rates );
731
+            update_option('wpinv_vat_rates', $rates);
732 732
         }
733 733
         
734 734
         return $input;
@@ -738,71 +738,71 @@  discard block
 block discarded – undo
738 738
         $response = array();
739 739
         $response['success'] = false;
740 740
         
741
-        if ( !current_user_can( 'manage_options' ) ) {
742
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
743
-            wp_send_json( $response );
741
+        if (!current_user_can('manage_options')) {
742
+            $response['error'] = __('Invalid access!', 'invoicing');
743
+            wp_send_json($response);
744 744
         }
745 745
         
746
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
747
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
746
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
747
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
748 748
         
749
-        if ( empty( $vat_class_name ) ) {
750
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
751
-            wp_send_json( $response );
749
+        if (empty($vat_class_name)) {
750
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
751
+            wp_send_json($response);
752 752
         }
753 753
         
754 754
         $vat_classes = (array)self::get_rate_classes();
755 755
 
756
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
757
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
758
-            wp_send_json( $response );
756
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
757
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
758
+            wp_send_json($response);
759 759
         }
760 760
         
761
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
762
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
761
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
762
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
763 763
         
764
-        $vat_classes = (array)self::get_rate_classes( true );
765
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
764
+        $vat_classes = (array)self::get_rate_classes(true);
765
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
766 766
         
767
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
767
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
768 768
         
769 769
         $response['success'] = true;
770
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
770
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
771 771
         
772
-        wp_send_json( $response );
772
+        wp_send_json($response);
773 773
     }
774 774
     
775 775
     public static function delete_class() {
776 776
         $response = array();
777 777
         $response['success'] = false;
778 778
         
779
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
780
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
781
-            wp_send_json( $response );
779
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
780
+            $response['error'] = __('Invalid access!', 'invoicing');
781
+            wp_send_json($response);
782 782
         }
783 783
         
784
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
784
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
785 785
         $vat_classes = (array)self::get_rate_classes();
786 786
 
787
-        if ( !isset( $vat_classes[$vat_class] ) ) {
788
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
789
-            wp_send_json( $response );
787
+        if (!isset($vat_classes[$vat_class])) {
788
+            $response['error'] = __('Requested class does not exists', 'invoicing');
789
+            wp_send_json($response);
790 790
         }
791 791
         
792
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
793
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
794
-            wp_send_json( $response );
792
+        if ($vat_class == '_new' || $vat_class == '_standard') {
793
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
794
+            wp_send_json($response);
795 795
         }
796 796
             
797
-        $vat_classes = (array)self::get_rate_classes( true );
798
-        unset( $vat_classes[$vat_class] );
797
+        $vat_classes = (array)self::get_rate_classes(true);
798
+        unset($vat_classes[$vat_class]);
799 799
         
800
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
800
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
801 801
         
802 802
         $response['success'] = true;
803
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
803
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
804 804
         
805
-        wp_send_json( $response );
805
+        wp_send_json($response);
806 806
     }
807 807
     
808 808
     public static function update_eu_rates() {        
@@ -811,72 +811,72 @@  discard block
 block discarded – undo
811 811
         $response['error']      = null;
812 812
         $response['data']       = null;
813 813
         
814
-        if ( !current_user_can( 'manage_options' ) ) {
815
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
816
-            wp_send_json( $response );
814
+        if (!current_user_can('manage_options')) {
815
+            $response['error'] = __('Invalid access!', 'invoicing');
816
+            wp_send_json($response);
817 817
         }
818 818
         
819
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
820
-        $euvatrates = self::request_euvatrates( $group );
819
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
820
+        $euvatrates = self::request_euvatrates($group);
821 821
         
822
-        if ( !empty( $euvatrates ) ) {
823
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
822
+        if (!empty($euvatrates)) {
823
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
824 824
                 $response['success']        = true;
825 825
                 $response['data']['rates']  = $euvatrates['rates'];
826
-            } else if ( !empty( $euvatrates['error'] ) ) {
826
+            } else if (!empty($euvatrates['error'])) {
827 827
                 $response['error']          = $euvatrates['error'];
828 828
             }
829 829
         }
830 830
             
831
-        wp_send_json( $response );
831
+        wp_send_json($response);
832 832
     }
833 833
     
834 834
     public static function hide_vat_fields() {
835
-        $hide = wpinv_get_option( 'vat_disable_fields' );
835
+        $hide = wpinv_get_option('vat_disable_fields');
836 836
         
837
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
837
+        return apply_filters('wpinv_hide_vat_fields', $hide);
838 838
     }
839 839
     
840 840
     public static function same_country_rule() {
841
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
841
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
842 842
         
843
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
843
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
844 844
     }
845 845
     
846 846
     public static function get_vat_name() {
847
-        $vat_name   = wpinv_get_option( 'vat_name' );
848
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
847
+        $vat_name   = wpinv_get_option('vat_name');
848
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
849 849
         
850
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
850
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
851 851
     }
852 852
     
853 853
     public static function get_company_name() {
854
-        $company_name = wpinv_get_option( 'vat_company_name' );
854
+        $company_name = wpinv_get_option('vat_company_name');
855 855
         
856
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
856
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
857 857
     }
858 858
     
859 859
     public static function get_vat_number() {
860
-        $vat_number = wpinv_get_option( 'vat_number' );
860
+        $vat_number = wpinv_get_option('vat_number');
861 861
         
862
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
862
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
863 863
     }
864 864
     
865 865
     public static function is_vat_validated() {
866
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
866
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
867 867
         
868
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
868
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
869 869
     }
870 870
     
871
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
872
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
871
+    public static function sanitize_vat($vat_number, $country_code = '') {        
872
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
873 873
         
874
-        if ( empty( $country_code ) ) {
875
-            $country_code = substr( $vat_number, 0, 2 );
874
+        if (empty($country_code)) {
875
+            $country_code = substr($vat_number, 0, 2);
876 876
         }
877 877
         
878
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
879
-            $vat = str_replace( $country_code, '', $vat_number );
878
+        if (strpos($vat_number, $country_code) === 0) {
879
+            $vat = str_replace($country_code, '', $vat_number);
880 880
         } else {
881 881
             $vat = $country_code . $vat_number;
882 882
         }
@@ -889,140 +889,140 @@  discard block
 block discarded – undo
889 889
         return $return;
890 890
     }
891 891
     
892
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
893
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
892
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
893
+        $vat            = self::sanitize_vat($vat_number, $country_code);
894 894
         $vat_number     = $vat['vat_number'];
895 895
         $country_code   = $vat['iso'];
896 896
         $regex          = array();
897 897
         
898
-        switch ( $country_code ) {
898
+        switch ($country_code) {
899 899
             case 'AT':
900
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
900
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
901 901
                 break;
902 902
             case 'BE':
903
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
903
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
904 904
                 break;
905 905
             case 'BG':
906
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
906
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
907 907
                 break;
908 908
             case 'CH':
909 909
             case 'CHE':
910
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
910
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
911 911
                 break;
912 912
             case 'CY':
913
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
913
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
914 914
                 break;
915 915
             case 'CZ':
916
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
916
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
917 917
                 break;
918 918
             case 'DE':
919
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
919
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
920 920
                 break;
921 921
             case 'DK':
922
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
922
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
923 923
                 break;
924 924
             case 'EE':
925
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
925
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
926 926
                 break;
927 927
             case 'EL':
928
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
928
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
929 929
                 break;
930 930
             case 'ES':
931
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
932
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
933
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
934
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
931
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
932
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
933
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
934
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
935 935
                 break;
936 936
             case 'EU':
937
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
937
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
938 938
                 break;
939 939
             case 'FI':
940
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
940
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
941 941
                 break;
942 942
             case 'FR':
943
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
944
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
945
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
946
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
943
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
944
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
945
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
946
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
947 947
                 break;
948 948
             case 'GB':
949
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
950
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
951
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
952
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
949
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
950
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
951
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
952
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
953 953
                 break;
954 954
             case 'GR':
955
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
955
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
956 956
                 break;
957 957
             case 'HR':
958
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
958
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
959 959
                 break;
960 960
             case 'HU':
961
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
961
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
962 962
                 break;
963 963
             case 'IE':
964
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
965
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
966
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
964
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
965
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
966
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
967 967
                 break;
968 968
             case 'IT':
969
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
969
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
970 970
                 break;
971 971
             case 'LV':
972
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
972
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
973 973
                 break;
974 974
             case 'LT':
975
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
975
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
976 976
                 break;
977 977
             case 'LU':
978
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
978
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
979 979
                 break;
980 980
             case 'MT':
981
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
981
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
982 982
                 break;
983 983
             case 'NL':
984
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
984
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
985 985
                 break;
986 986
             case 'NO':
987
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
987
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
988 988
                 break;
989 989
             case 'PL':
990
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
990
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
991 991
                 break;
992 992
             case 'PT':
993
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
993
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
994 994
                 break;
995 995
             case 'RO':
996
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
996
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
997 997
                 break;
998 998
             case 'RS':
999
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
999
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1000 1000
                 break;
1001 1001
             case 'SI':
1002
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1002
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1003 1003
                 break;
1004 1004
             case 'SK':
1005
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1005
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1006 1006
                 break;
1007 1007
             case 'SE':
1008
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1008
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1009 1009
                 break;
1010 1010
             default:
1011 1011
                 $regex = array();
1012 1012
             break;
1013 1013
         }
1014 1014
         
1015
-        if ( empty( $regex ) ) {
1015
+        if (empty($regex)) {
1016 1016
             return false;
1017 1017
         }
1018 1018
         
1019
-        foreach ( $regex as $pattern ) {
1019
+        foreach ($regex as $pattern) {
1020 1020
             $matches = null;
1021
-            preg_match_all( $pattern, $vat_number, $matches );
1021
+            preg_match_all($pattern, $vat_number, $matches);
1022 1022
             
1023
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1024
-                if ( $formatted ) {
1025
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1023
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1024
+                if ($formatted) {
1025
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1026 1026
                 } else {
1027 1027
                     return true;
1028 1028
                 }
@@ -1032,75 +1032,75 @@  discard block
 block discarded – undo
1032 1032
         return false;
1033 1033
     }
1034 1034
     
1035
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1036
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1035
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1036
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1037 1037
         $vat_number     = $vat['vat'];
1038 1038
         $iso            = $vat['iso'];
1039 1039
         
1040
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1040
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1041 1041
         
1042
-        if ( ini_get( 'allow_url_fopen' ) ) {
1043
-            $response = file_get_contents( $url );
1044
-        } else if ( function_exists( 'curl_init' ) ) {
1042
+        if (ini_get('allow_url_fopen')) {
1043
+            $response = file_get_contents($url);
1044
+        } else if (function_exists('curl_init')) {
1045 1045
             $ch = curl_init();
1046 1046
             
1047
-            curl_setopt( $ch, CURLOPT_URL, $url );
1048
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1049
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1050
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1051
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1047
+            curl_setopt($ch, CURLOPT_URL, $url);
1048
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1049
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1050
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1051
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1052 1052
             
1053
-            $response = curl_exec( $ch );
1053
+            $response = curl_exec($ch);
1054 1054
             
1055
-            if ( curl_errno( $ch ) ) {
1056
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1055
+            if (curl_errno($ch)) {
1056
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1057 1057
                 $response = '';
1058 1058
             }
1059 1059
             
1060
-            curl_close( $ch );
1060
+            curl_close($ch);
1061 1061
         } else {
1062
-            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' );
1062
+            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');
1063 1063
         }
1064 1064
         
1065
-        if ( empty( $response ) ) {
1065
+        if (empty($response)) {
1066 1066
             return $result;
1067 1067
         }
1068 1068
 
1069
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1069
+        if (preg_match('/invalid VAT number/i', $response)) {
1070 1070
             return false;
1071
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1072
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1071
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1072
+            $content = explode("valid VAT number", htmlentities($response));
1073 1073
             
1074
-            if ( !empty( $content[1] ) ) {
1075
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1074
+            if (!empty($content[1])) {
1075
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1076 1076
                 
1077
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1077
+                if (!empty($matches[2]) && $matches[3]) {
1078 1078
                     $return = array();
1079 1079
                     
1080
-                    foreach ( $matches[2] as $key => $label ) {
1081
-                        $label = trim( $label );
1080
+                    foreach ($matches[2] as $key => $label) {
1081
+                        $label = trim($label);
1082 1082
                         
1083
-                        switch ( strtolower( $label ) ) {
1083
+                        switch (strtolower($label)) {
1084 1084
                             case 'member state':
1085
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1085
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1086 1086
                             break;
1087 1087
                             case 'vat number':
1088
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1088
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1089 1089
                             break;
1090 1090
                             case 'name':
1091
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1091
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1092 1092
                             break;
1093 1093
                             case 'address':
1094
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1095
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1094
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1095
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1096 1096
                             break;
1097 1097
                             case 'consultation number':
1098
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1098
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1099 1099
                             break;
1100 1100
                         }
1101 1101
                     }
1102 1102
                     
1103
-                    if ( !empty( $return ) ) {
1103
+                    if (!empty($return)) {
1104 1104
                         return $return;
1105 1105
                     }
1106 1106
                 }
@@ -1112,55 +1112,55 @@  discard block
 block discarded – undo
1112 1112
         }
1113 1113
     }
1114 1114
     
1115
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1115
+    public static function check_vat($vat_number, $country_code = '') {        
1116 1116
         $vat_name           = self::get_vat_name();
1117 1117
         
1118 1118
         $return             = array();
1119 1119
         $return['valid']    = false;
1120
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1120
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1121 1121
                 
1122
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1122
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1123 1123
             return $return;
1124 1124
         }
1125 1125
             
1126
-        $response = self::vies_check( $vat_number, $country_code );
1126
+        $response = self::vies_check($vat_number, $country_code);
1127 1127
         
1128
-        if ( $response ) {
1129
-            $return['valid']    = true;
1128
+        if ($response) {
1129
+            $return['valid'] = true;
1130 1130
             
1131
-            if ( is_array( $response ) ) {
1132
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1133
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1131
+            if (is_array($response)) {
1132
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1133
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1134 1134
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1135 1135
             }
1136 1136
         } else {
1137 1137
             $return['valid']    = false;
1138
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1138
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1139 1139
         }
1140 1140
         
1141 1141
         return $return;
1142 1142
     }
1143 1143
     
1144
-    public static function request_euvatrates( $group ) {
1144
+    public static function request_euvatrates($group) {
1145 1145
         $response               = array();
1146 1146
         $response['success']    = false;
1147 1147
         $response['error']      = null;
1148 1148
         $response['eurates']    = null;
1149 1149
         
1150 1150
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1151
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1152
-        $api_response   = wp_remote_get( $euvatrates_url );
1151
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1152
+        $api_response   = wp_remote_get($euvatrates_url);
1153 1153
     
1154 1154
         try {
1155
-            if ( is_wp_error( $api_response ) ) {
1156
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1155
+            if (is_wp_error($api_response)) {
1156
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1157 1157
             } else {
1158
-                $body = json_decode( $api_response['body'] );
1158
+                $body = json_decode($api_response['body']);
1159 1159
                 
1160
-                if ( isset( $body->rates ) ) {
1160
+                if (isset($body->rates)) {
1161 1161
                     $rates = array();
1162 1162
                     
1163
-                    foreach ( $body->rates as $country_code => $rate ) {
1163
+                    foreach ($body->rates as $country_code => $rate) {
1164 1164
                         $vat_rate = array();
1165 1165
                         $vat_rate['country']        = $rate->country;
1166 1166
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1168,7 +1168,7 @@  discard block
 block discarded – undo
1168 1168
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1169 1169
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1170 1170
                         
1171
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1171
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1172 1172
                             $vat_rate_group = array();
1173 1173
                             $vat_rate_group['country'] = $rate->country;
1174 1174
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1180,79 +1180,79 @@  discard block
 block discarded – undo
1180 1180
                     }
1181 1181
                     
1182 1182
                     $response['success']    = true;                                
1183
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1183
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1184 1184
                 } else {
1185
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1185
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1186 1186
                 }
1187 1187
             }
1188
-        } catch ( Exception $e ) {
1189
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1188
+        } catch (Exception $e) {
1189
+            $response['error'] = __($e->getMessage(), 'invoicing');
1190 1190
         }
1191 1191
         
1192
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1192
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1193 1193
     }    
1194 1194
     
1195
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1195
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1196 1196
         global $wpi_item_id, $wpi_country;
1197 1197
         
1198
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1199
-            $country_code = trim( $_POST['wpinv_country'] );
1200
-        } else if ( !empty( $_POST['country'] ) ) {
1201
-            $country_code = trim( $_POST['country'] );
1202
-        } else if ( !empty( $wpi_country ) ) {
1198
+        if (!empty($_POST['wpinv_country'])) {
1199
+            $country_code = trim($_POST['wpinv_country']);
1200
+        } else if (!empty($_POST['country'])) {
1201
+            $country_code = trim($_POST['country']);
1202
+        } else if (!empty($wpi_country)) {
1203 1203
             $country_code = $wpi_country;
1204 1204
         } else {
1205
-            $country_code = self::get_user_country( '', $user_id );
1205
+            $country_code = self::get_user_country('', $user_id);
1206 1206
         }
1207 1207
         
1208
-        if ( $is_digital === null && $wpi_item_id ) {
1209
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1208
+        if ($is_digital === null && $wpi_item_id) {
1209
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1210 1210
         }
1211 1211
         
1212
-        if ( !empty( $country_code ) ) {
1213
-            $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 ) );
1212
+        if (!empty($country_code)) {
1213
+            $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));
1214 1214
         }
1215 1215
         
1216
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1216
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1217 1217
     }
1218 1218
     
1219
-    public static function tax_label( $label = '' ) {
1219
+    public static function tax_label($label = '') {
1220 1220
         global $wpi_requires_vat;
1221 1221
         
1222
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1223
-            $wpi_requires_vat = self::requires_vat( 0, false );
1222
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1223
+            $wpi_requires_vat = self::requires_vat(0, false);
1224 1224
         }
1225 1225
         
1226
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1226
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1227 1227
     }
1228 1228
     
1229 1229
     public static function standard_rates_label() {
1230
-        return __( 'Standard Rates', 'invoicing' );
1230
+        return __('Standard Rates', 'invoicing');
1231 1231
     }
1232 1232
     
1233
-    public static function get_rate_classes( $with_desc = false ) {        
1234
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1235
-        $classes = maybe_unserialize( $rate_classes_option );
1233
+    public static function get_rate_classes($with_desc = false) {        
1234
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1235
+        $classes = maybe_unserialize($rate_classes_option);
1236 1236
         
1237
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1237
+        if (empty($classes) || !is_array($classes)) {
1238 1238
             $classes = array();
1239 1239
         }
1240 1240
 
1241 1241
         $rate_classes = array();
1242
-        if ( !array_key_exists( '_standard', $classes ) ) {
1243
-            if ( $with_desc ) {
1244
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1242
+        if (!array_key_exists('_standard', $classes)) {
1243
+            if ($with_desc) {
1244
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1245 1245
             } else {
1246 1246
                 $rate_classes['_standard'] = self::standard_rates_label();
1247 1247
             }
1248 1248
         }
1249 1249
         
1250
-        foreach ( $classes as $key => $class ) {
1251
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1252
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1250
+        foreach ($classes as $key => $class) {
1251
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1252
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1253 1253
             
1254
-            if ( $with_desc ) {
1255
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1254
+            if ($with_desc) {
1255
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1256 1256
             } else {
1257 1257
                 $rate_classes[$key] = $name;
1258 1258
             }
@@ -1263,15 +1263,15 @@  discard block
 block discarded – undo
1263 1263
     
1264 1264
     public static function get_all_classes() {        
1265 1265
         $classes            = self::get_rate_classes();
1266
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1266
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1267 1267
         
1268
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1268
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1269 1269
     }
1270 1270
     
1271
-    public static function get_class_desc( $rate_class ) {        
1272
-        $rate_classes = self::get_rate_classes( true );
1271
+    public static function get_class_desc($rate_class) {        
1272
+        $rate_classes = self::get_rate_classes(true);
1273 1273
 
1274
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1274
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1275 1275
             return $rate_classes[$rate_class]['desc'];
1276 1276
         }
1277 1277
         
@@ -1287,106 +1287,106 @@  discard block
 block discarded – undo
1287 1287
             'increased'     => 'Increased'
1288 1288
         );
1289 1289
         
1290
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1290
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1291 1291
     }
1292 1292
 
1293 1293
     public static function get_rules() {
1294 1294
         $vat_rules = array(
1295
-            'digital' => __( 'Digital Product', 'invoicing' ),
1296
-            'physical' => __( 'Physical Product', 'invoicing' )
1295
+            'digital' => __('Digital Product', 'invoicing'),
1296
+            'physical' => __('Physical Product', 'invoicing')
1297 1297
         );
1298
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1298
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1299 1299
     }
1300 1300
 
1301
-    public static function get_vat_rates( $class ) {
1302
-        if ( $class === '_standard' ) {
1301
+    public static function get_vat_rates($class) {
1302
+        if ($class === '_standard') {
1303 1303
             return wpinv_get_tax_rates();
1304 1304
         }
1305 1305
 
1306 1306
         $rates = self::get_non_standard_rates();
1307 1307
 
1308
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1308
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1309 1309
     }
1310 1310
 
1311 1311
     public static function get_non_standard_rates() {
1312
-        $option = get_option( 'wpinv_vat_rates', array());
1313
-        return is_array( $option ) ? $option : array();
1312
+        $option = get_option('wpinv_vat_rates', array());
1313
+        return is_array($option) ? $option : array();
1314 1314
     }
1315 1315
     
1316 1316
     public static function allow_vat_rules() {
1317
-        return ( wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1317
+        return (wpinv_get_option('apply_vat_rules') ? true : false);
1318 1318
     }
1319 1319
     
1320 1320
     public static function allow_vat_classes() {
1321 1321
         return false; // TODO
1322
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1322
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1323 1323
     }
1324 1324
     
1325
-    public static function get_item_class( $postID ) {
1326
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1325
+    public static function get_item_class($postID) {
1326
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1327 1327
 
1328
-        if ( empty( $class ) ) {
1328
+        if (empty($class)) {
1329 1329
             $class = '_standard';
1330 1330
         }
1331 1331
         
1332
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1332
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1333 1333
     }
1334 1334
     
1335
-    public static function item_class_label( $postID ) {        
1335
+    public static function item_class_label($postID) {        
1336 1336
         $vat_classes = self::get_all_classes();
1337 1337
         
1338
-        $class = self::get_item_class( $postID );
1339
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1338
+        $class = self::get_item_class($postID);
1339
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1340 1340
         
1341
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1341
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1342 1342
     }
1343 1343
     
1344
-    public static function get_item_rule( $postID ) {        
1345
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1344
+    public static function get_item_rule($postID) {        
1345
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1346 1346
         
1347
-        if ( empty( $rule_type ) ) {        
1347
+        if (empty($rule_type)) {        
1348 1348
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1349 1349
         }
1350 1350
         
1351
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1351
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1352 1352
     }
1353 1353
     
1354
-    public static function item_rule_label( $postID ) {
1354
+    public static function item_rule_label($postID) {
1355 1355
         $vat_rules  = self::get_rules();
1356
-        $vat_rule   = self::get_item_rule( $postID );
1357
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1356
+        $vat_rule   = self::get_item_rule($postID);
1357
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1358 1358
         
1359
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1359
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1360 1360
     }
1361 1361
     
1362
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1363
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1362
+    public static function item_has_digital_rule($item_id = 0) {        
1363
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1364 1364
     }
1365 1365
     
1366
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1367
-        if ( !self::allow_vat_rules() ) {
1366
+    public static function invoice_has_digital_rule($invoice = 0) {        
1367
+        if (!self::allow_vat_rules()) {
1368 1368
             return false;
1369 1369
         }
1370 1370
         
1371
-        if ( empty( $invoice ) ) {
1371
+        if (empty($invoice)) {
1372 1372
             return true;
1373 1373
         }
1374 1374
         
1375
-        if ( is_int( $invoice ) ) {
1376
-            $invoice = new WPInv_Invoice( $invoice );
1375
+        if (is_int($invoice)) {
1376
+            $invoice = new WPInv_Invoice($invoice);
1377 1377
         }
1378 1378
         
1379
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1379
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1380 1380
             return true;
1381 1381
         }
1382 1382
         
1383
-        $cart_items  = $invoice->get_cart_details();
1383
+        $cart_items = $invoice->get_cart_details();
1384 1384
         
1385
-        if ( !empty( $cart_items ) ) {
1385
+        if (!empty($cart_items)) {
1386 1386
             $has_digital_rule = false;
1387 1387
             
1388
-            foreach ( $cart_items as $key => $item ) {
1389
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1388
+            foreach ($cart_items as $key => $item) {
1389
+                if (self::item_has_digital_rule($item['id'])) {
1390 1390
                     $has_digital_rule = true;
1391 1391
                     break;
1392 1392
                 }
@@ -1398,67 +1398,67 @@  discard block
 block discarded – undo
1398 1398
         return $has_digital_rule;
1399 1399
     }
1400 1400
     
1401
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1402
-        if ( !wpinv_use_taxes() ) {
1401
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1402
+        if (!wpinv_use_taxes()) {
1403 1403
             return false;
1404 1404
         }
1405 1405
         
1406 1406
         $is_taxable = true;
1407 1407
 
1408
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1408
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1409 1409
             $is_taxable = false;
1410 1410
         }
1411 1411
         
1412
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1412
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1413 1413
     }
1414 1414
     
1415
-    public static function find_rate( $country, $state, $rate, $class ) {
1415
+    public static function find_rate($country, $state, $rate, $class) {
1416 1416
         global $wpi_zero_tax;
1417 1417
 
1418
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1418
+        if ($class === '_exempt' || $wpi_zero_tax) {
1419 1419
             return 0;
1420 1420
         }
1421 1421
 
1422
-        $tax_rates   = wpinv_get_tax_rates();
1422
+        $tax_rates = wpinv_get_tax_rates();
1423 1423
         
1424
-        if ( $class !== '_standard' ) {
1425
-            $class_rates = self::get_vat_rates( $class );
1424
+        if ($class !== '_standard') {
1425
+            $class_rates = self::get_vat_rates($class);
1426 1426
             
1427
-            if ( is_array( $class_rates ) ) {
1427
+            if (is_array($class_rates)) {
1428 1428
                 $indexed_class_rates = array();
1429 1429
                 
1430
-                foreach ( $class_rates as $key => $cr ) {
1430
+                foreach ($class_rates as $key => $cr) {
1431 1431
                     $indexed_class_rates[$cr['country']] = $cr;
1432 1432
                 }
1433 1433
 
1434
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1434
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1435 1435
                     $tr_country = $tr['country'];
1436
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1436
+                    if (!isset($indexed_class_rates[$tr_country])) {
1437 1437
                         return $tr;
1438 1438
                     }
1439 1439
                     $icr = $indexed_class_rates[$tr_country];
1440
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1440
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1441 1441
 
1442
-                }, $tax_rates, $class_rates );
1442
+                }, $tax_rates, $class_rates);
1443 1443
             }
1444 1444
         }
1445 1445
 
1446
-        if ( !empty( $tax_rates ) ) {
1447
-            foreach ( $tax_rates as $key => $tax_rate ) {
1448
-                if ( $country != $tax_rate['country'] )
1446
+        if (!empty($tax_rates)) {
1447
+            foreach ($tax_rates as $key => $tax_rate) {
1448
+                if ($country != $tax_rate['country'])
1449 1449
                     continue;
1450 1450
 
1451
-                if ( !empty( $tax_rate['global'] ) ) {
1452
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1453
-                        $rate = number_format( $tax_rate['rate'], 4 );
1451
+                if (!empty($tax_rate['global'])) {
1452
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1453
+                        $rate = number_format($tax_rate['rate'], 4);
1454 1454
                     }
1455 1455
                 } else {
1456
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1456
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1457 1457
                         continue;
1458 1458
 
1459 1459
                     $state_rate = $tax_rate['rate'];
1460
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1461
-                        $rate = number_format( $state_rate, 4 );
1460
+                    if (0 !== $state_rate || !empty($state_rate)) {
1461
+                        $rate = number_format($state_rate, 4);
1462 1462
                     }
1463 1463
                 }
1464 1464
             }
@@ -1467,84 +1467,84 @@  discard block
 block discarded – undo
1467 1467
         return $rate;
1468 1468
     }
1469 1469
     
1470
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1470
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1471 1471
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1472 1472
         
1473 1473
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1474 1474
         $allow_vat_classes = self::allow_vat_classes();
1475
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1475
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1476 1476
 
1477
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1477
+        if ($class === '_exempt' || $wpi_zero_tax) {
1478 1478
             return 0;
1479
-        } else if ( !$allow_vat_classes ) {
1479
+        } else if (!$allow_vat_classes) {
1480 1480
             $class = '_standard';
1481 1481
         }
1482 1482
 
1483
-        if( !empty( $_POST['wpinv_country'] ) ) {
1483
+        if (!empty($_POST['wpinv_country'])) {
1484 1484
             $post_country = $_POST['wpinv_country'];
1485
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1485
+        } elseif (!empty($_POST['wpinv_country'])) {
1486 1486
             $post_country = $_POST['wpinv_country'];
1487
-        } elseif( !empty( $_POST['country'] ) ) {
1487
+        } elseif (!empty($_POST['country'])) {
1488 1488
             $post_country = $_POST['country'];
1489 1489
         } else {
1490 1490
             $post_country = '';
1491 1491
         }
1492 1492
 
1493
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1494
-        $base_country   = wpinv_is_base_country( $country );
1493
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1494
+        $base_country   = wpinv_is_base_country($country);
1495 1495
         
1496
-        $requires_vat   = self::requires_vat( 0, false );
1497
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1498
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1496
+        $requires_vat   = self::requires_vat(0, false);
1497
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1498
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1499 1499
           
1500
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1500
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1501 1501
             $rate = 0;
1502
-        } else if ( $requires_vat ) {
1503
-            $vat_number = self::get_user_vat_number( '', 0, true );
1502
+        } else if ($requires_vat) {
1503
+            $vat_number = self::get_user_vat_number('', 0, true);
1504 1504
             $vat_info   = self::current_vat_data();
1505 1505
             
1506
-            if ( is_array( $vat_info ) ) {
1507
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1506
+            if (is_array($vat_info)) {
1507
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1508 1508
             }
1509 1509
             
1510
-            if ( $country == 'UK' ) {
1510
+            if ($country == 'UK') {
1511 1511
                 $country = 'GB';
1512 1512
             }
1513 1513
 
1514
-            if ( !empty( $vat_number ) ) {
1514
+            if (!empty($vat_number)) {
1515 1515
                 $rate = 0;
1516 1516
             } else {
1517
-                $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
1517
+                $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
1518 1518
             }
1519 1519
 
1520
-            if ( empty( $vat_number ) && !$is_digital ) {
1521
-                if ( $base_country ) {
1522
-                    $rate = self::find_rate( $country, null, $rate, $class );
1520
+            if (empty($vat_number) && !$is_digital) {
1521
+                if ($base_country) {
1522
+                    $rate = self::find_rate($country, null, $rate, $class);
1523 1523
                 } else {
1524
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1524
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1525 1525
                         $rate = $wpinv_options['eu_fallback_rate'];
1526
-                    } else if( !empty( $country ) ) {
1527
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1526
+                    } else if (!empty($country)) {
1527
+                        $rate = self::find_rate($country, $state, $rate, $class);
1528 1528
                     }
1529 1529
                 }
1530
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1531
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1530
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1531
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1532 1532
                     $rate = $wpinv_options['eu_fallback_rate'];
1533
-                } else if( !empty( $country ) ) {
1534
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1533
+                } else if (!empty($country)) {
1534
+                    $rate = self::find_rate($country, $state, $rate, $class);
1535 1535
                 }
1536 1536
             }
1537 1537
         } else {
1538
-            if ( $is_digital ) {
1538
+            if ($is_digital) {
1539 1539
                 $ip_country_code = self::get_country_by_ip();
1540 1540
                 
1541
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1542
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1541
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1542
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1543 1543
                 } else {
1544
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1544
+                    $rate = self::find_rate($country, $state, $rate, $class);
1545 1545
                 }
1546 1546
             } else {
1547
-                $rate = self::find_rate( $country, $state, $rate, $class );
1547
+                $rate = self::find_rate($country, $state, $rate, $class);
1548 1548
             }
1549 1549
         }
1550 1550
 
@@ -1554,48 +1554,48 @@  discard block
 block discarded – undo
1554 1554
     public static function current_vat_data() {
1555 1555
         global $wpi_session;
1556 1556
         
1557
-        return $wpi_session->get( 'user_vat_data' );
1557
+        return $wpi_session->get('user_vat_data');
1558 1558
     }
1559 1559
     
1560
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1561
-        $user_address = wpinv_get_user_address( $user_id, false );
1560
+    public static function get_user_country($country = '', $user_id = 0) {
1561
+        $user_address = wpinv_get_user_address($user_id, false);
1562 1562
         
1563
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1563
+        if (wpinv_get_option('vat_ip_country_default')) {
1564 1564
             $country = '';
1565 1565
         }
1566 1566
         
1567
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1568
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1567
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1568
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1569 1569
 
1570
-        if ( empty( $result ) ) {
1570
+        if (empty($result)) {
1571 1571
             $result = self::get_country_by_ip();
1572 1572
         }
1573 1573
 
1574 1574
         return $result;
1575 1575
     }
1576 1576
     
1577
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1577
+    public static function set_user_country($country = '', $user_id = 0) {
1578 1578
         global $wpi_userID;
1579 1579
         
1580
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1580
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1581 1581
             $country = wpinv_get_default_country();
1582 1582
         }
1583 1583
         
1584 1584
         return $country;
1585 1585
     }
1586 1586
     
1587
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1587
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1588 1588
         global $wpi_current_id, $wpi_userID;
1589 1589
         
1590
-        if ( !empty( $_POST['new_user'] ) ) {
1590
+        if (!empty($_POST['new_user'])) {
1591 1591
             return '';
1592 1592
         }
1593 1593
         
1594
-        if ( empty( $user_id ) ) {
1595
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1594
+        if (empty($user_id)) {
1595
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1596 1596
         }
1597 1597
 
1598
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1598
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1599 1599
         
1600 1600
         /* TODO
1601 1601
         if ( $is_valid && $vat_number ) {
@@ -1606,36 +1606,36 @@  discard block
 block discarded – undo
1606 1606
         }
1607 1607
         */
1608 1608
 
1609
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1609
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1610 1610
     }
1611 1611
     
1612
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1613
-        if ( empty( $user_id ) ) {
1612
+    public static function get_user_company($company = '', $user_id = 0) {
1613
+        if (empty($user_id)) {
1614 1614
             $user_id = get_current_user_id();
1615 1615
         }
1616 1616
 
1617
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1617
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1618 1618
 
1619
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1619
+        return apply_filters('wpinv_user_company', $company, $user_id);
1620 1620
     }
1621 1621
     
1622
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1623
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1622
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1623
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1624 1624
 
1625
-        if ( is_user_logged_in() && $save ) {
1625
+        if (is_user_logged_in() && $save) {
1626 1626
             $user_id = get_current_user_id();
1627 1627
 
1628
-            if ( !empty( $vat_number ) ) {
1629
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1628
+            if (!empty($vat_number)) {
1629
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1630 1630
             } else {
1631
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1631
+                delete_user_meta($user_id, '_wpinv_vat_number');
1632 1632
             }
1633 1633
 
1634
-            if ( !empty( $company ) ) {
1635
-                update_user_meta( $user_id, '_wpinv_company', $company );
1634
+            if (!empty($company)) {
1635
+                update_user_meta($user_id, '_wpinv_company', $company);
1636 1636
             } else {
1637
-                delete_user_meta( $user_id, '_wpinv_company');
1638
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1637
+                delete_user_meta($user_id, '_wpinv_company');
1638
+                delete_user_meta($user_id, '_wpinv_vat_number');
1639 1639
             }
1640 1640
         }
1641 1641
 
@@ -1645,113 +1645,113 @@  discard block
 block discarded – undo
1645 1645
     public static function ajax_vat_validate() {
1646 1646
         global $wpinv_options, $wpi_session;
1647 1647
         
1648
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1648
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1649 1649
         $response               = array();
1650 1650
         $response['success']    = false;
1651 1651
         
1652
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1653
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1654
-            wp_send_json( $response );
1652
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1653
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1654
+            wp_send_json($response);
1655 1655
         }
1656 1656
         
1657
-        $vat_name   = self::get_vat_name();
1657
+        $vat_name = self::get_vat_name();
1658 1658
         
1659
-        if ( $is_checkout ) {
1659
+        if ($is_checkout) {
1660 1660
             $invoice = wpinv_get_invoice_cart();
1661 1661
             
1662
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1662
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1663 1663
                 $vat_info = array();
1664
-                $wpi_session->set( 'user_vat_data', $vat_info );
1664
+                $wpi_session->set('user_vat_data', $vat_info);
1665 1665
 
1666 1666
                 self::save_user_vat_details();
1667 1667
                 
1668 1668
                 $response['success'] = true;
1669
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1670
-                wp_send_json( $response );
1669
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1670
+                wp_send_json($response);
1671 1671
             }
1672 1672
         }
1673 1673
         
1674
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1675
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1674
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1675
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1676 1676
         
1677
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1678
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1679
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1677
+        $vat_info = $wpi_session->get('user_vat_data');
1678
+        if (!is_array($vat_info) || empty($vat_info)) {
1679
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1680 1680
         }
1681 1681
         
1682
-        if ( empty( $vat_number ) ) {
1683
-            if ( $is_checkout ) {
1682
+        if (empty($vat_number)) {
1683
+            if ($is_checkout) {
1684 1684
                 $response['success'] = true;
1685
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1685
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1686 1686
                 
1687
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1687
+                $vat_info = $wpi_session->get('user_vat_data');
1688 1688
                 $vat_info['number'] = "";
1689 1689
                 $vat_info['valid'] = true;
1690 1690
                 
1691
-                self::save_user_vat_details( $company );
1691
+                self::save_user_vat_details($company);
1692 1692
             } else {
1693
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1693
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1694 1694
                 
1695 1695
                 $vat_info['valid'] = false;
1696 1696
             }
1697 1697
 
1698
-            $wpi_session->set( 'user_vat_data', $vat_info );
1699
-            wp_send_json( $response );
1698
+            $wpi_session->set('user_vat_data', $vat_info);
1699
+            wp_send_json($response);
1700 1700
         }
1701 1701
         
1702
-        if ( empty( $company ) ) {
1702
+        if (empty($company)) {
1703 1703
             $vat_info['valid'] = false;
1704
-            $wpi_session->set( 'user_vat_data', $vat_info );
1704
+            $wpi_session->set('user_vat_data', $vat_info);
1705 1705
             
1706
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1707
-            wp_send_json( $response );
1706
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1707
+            wp_send_json($response);
1708 1708
         }
1709 1709
         
1710
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1711
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1710
+        if (!empty($wpinv_options['vat_vies_check'])) {
1711
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1712 1712
                 $vat_info['valid'] = false;
1713
-                $wpi_session->set( 'user_vat_data', $vat_info );
1713
+                $wpi_session->set('user_vat_data', $vat_info);
1714 1714
                 
1715
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1716
-                wp_send_json( $response );
1715
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1716
+                wp_send_json($response);
1717 1717
             }
1718 1718
             
1719 1719
             $response['success'] = true;
1720
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1720
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1721 1721
         } else {
1722
-            $result = self::check_vat( $vat_number );
1722
+            $result = self::check_vat($vat_number);
1723 1723
             
1724
-            if ( empty( $result['valid'] ) ) {
1724
+            if (empty($result['valid'])) {
1725 1725
                 $response['error'] = $result['message'];
1726
-                wp_send_json( $response );
1726
+                wp_send_json($response);
1727 1727
             }
1728 1728
             
1729
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1730
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1729
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1730
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1731 1731
             
1732
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1732
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1733 1733
 
1734
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1734
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1735 1735
                 $response['success'] = true;
1736
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1736
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1737 1737
             } else {           
1738 1738
                 $vat_info['valid'] = false;
1739
-                $wpi_session->set( 'user_vat_data', $vat_info );
1739
+                $wpi_session->set('user_vat_data', $vat_info);
1740 1740
                 
1741 1741
                 $response['success'] = false;
1742
-                $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 );
1743
-                wp_send_json( $response );
1742
+                $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);
1743
+                wp_send_json($response);
1744 1744
             }
1745 1745
         }
1746 1746
         
1747
-        if ( $is_checkout ) {
1748
-            self::save_user_vat_details( $company, $vat_number );
1747
+        if ($is_checkout) {
1748
+            self::save_user_vat_details($company, $vat_number);
1749 1749
 
1750
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1751
-            $wpi_session->set( 'user_vat_data', $vat_info );
1750
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1751
+            $wpi_session->set('user_vat_data', $vat_info);
1752 1752
         }
1753 1753
 
1754
-        wp_send_json( $response );
1754
+        wp_send_json($response);
1755 1755
     }
1756 1756
     
1757 1757
     public static function ajax_vat_reset() {
@@ -1760,161 +1760,161 @@  discard block
 block discarded – undo
1760 1760
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1761 1761
         $vat_number = self::get_user_vat_number();
1762 1762
         
1763
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1764
-        $wpi_session->set( 'user_vat_data', $vat_info );
1763
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1764
+        $wpi_session->set('user_vat_data', $vat_info);
1765 1765
         
1766 1766
         $response                       = array();
1767 1767
         $response['success']            = true;
1768 1768
         $response['data']['company']    = $company;
1769 1769
         $response['data']['number']     = $vat_number;
1770 1770
         
1771
-        wp_send_json( $response );
1771
+        wp_send_json($response);
1772 1772
     }
1773 1773
     
1774
-    public static function checkout_vat_validate( $valid_data, $post ) {
1774
+    public static function checkout_vat_validate($valid_data, $post) {
1775 1775
         global $wpinv_options, $wpi_session;
1776 1776
         
1777
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1777
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1778 1778
         
1779
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1780
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1779
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1780
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1781 1781
             return;
1782 1782
         }
1783 1783
         
1784
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1785
-        $wpi_session->set( 'user_vat_data', null );
1784
+        $vat_saved = $wpi_session->get('user_vat_data');
1785
+        $wpi_session->set('user_vat_data', null);
1786 1786
         
1787 1787
         $invoice        = wpinv_get_invoice_cart();
1788 1788
         $amount         = $invoice->get_total();
1789
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1790
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1789
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1790
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1791 1791
         
1792
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1793
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1794
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1795
-        if ( empty( $country ) ) {
1792
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1793
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1794
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1795
+        if (empty($country)) {
1796 1796
             $country = wpinv_default_billing_country();
1797 1797
         }
1798 1798
         
1799
-        if ( !$is_digital && $no_vat ) {
1799
+        if (!$is_digital && $no_vat) {
1800 1800
             return;
1801 1801
         }
1802 1802
             
1803
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1803
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1804 1804
         
1805 1805
         $ip_country_code    = self::get_country_by_ip();
1806
-        $is_eu_state        = self::is_eu_state( $country );
1807
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1806
+        $is_eu_state        = self::is_eu_state($country);
1807
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1808 1808
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1809 1809
         
1810
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1810
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1811 1811
             $vat_data['adddress_confirmed'] = false;
1812 1812
             
1813
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1814
-                if ( $ip_country_code != $country ) {
1815
-                    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>' ) );
1813
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1814
+                if ($ip_country_code != $country) {
1815
+                    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>'));
1816 1816
                 }
1817 1817
             } else {
1818 1818
                 $vat_data['adddress_confirmed'] = true;
1819 1819
             }
1820 1820
         }
1821 1821
         
1822
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1823
-            if ( $is_eu_state ) {
1824
-                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 ) );
1825
-            } else if ( $is_digital && $is_eu_state_ip ) {
1826
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1822
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1823
+            if ($is_eu_state) {
1824
+                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));
1825
+            } else if ($is_digital && $is_eu_state_ip) {
1826
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1827 1827
             }
1828 1828
         }
1829 1829
         
1830
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1830
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1831 1831
             return;
1832 1832
         }
1833 1833
 
1834
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1835
-            $vat_data['valid']  = $vat_saved['valid'];
1834
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1835
+            $vat_data['valid'] = $vat_saved['valid'];
1836 1836
         }
1837 1837
             
1838
-        if ( $company !== null ) {
1838
+        if ($company !== null) {
1839 1839
             $vat_data['company'] = $company;
1840 1840
         }
1841 1841
 
1842 1842
         $message = '';
1843
-        if ( $vat_number !== null ) {
1843
+        if ($vat_number !== null) {
1844 1844
             $vat_data['number'] = $vat_number;
1845 1845
             
1846
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1847
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1848
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1846
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1847
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1848
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1849 1849
                         $vat_data['valid'] = false;
1850 1850
                     }
1851 1851
                 } else {
1852
-                    $result = self::check_vat( $vat_number );
1852
+                    $result = self::check_vat($vat_number);
1853 1853
                     
1854
-                    if ( !empty( $result['valid'] ) ) {                
1854
+                    if (!empty($result['valid'])) {                
1855 1855
                         $vat_data['valid'] = true;
1856
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1857
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1856
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1857
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1858 1858
                     
1859
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1859
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1860 1860
 
1861
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1861
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1862 1862
                             $vat_data['valid'] = false;
1863 1863
                             
1864
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1864
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1865 1865
                         }
1866 1866
                     } else {
1867
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1867
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1868 1868
                     }
1869 1869
                 }
1870 1870
                 
1871
-                if ( !$vat_data['valid'] ) {
1872
-                    $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 . ' )' : '' );
1873
-                    wpinv_set_error( 'vat_validation', $error );
1871
+                if (!$vat_data['valid']) {
1872
+                    $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 . ' )' : '');
1873
+                    wpinv_set_error('vat_validation', $error);
1874 1874
                 }
1875 1875
             }
1876 1876
         }
1877 1877
 
1878
-        $wpi_session->set( 'user_vat_data', $vat_data );
1878
+        $wpi_session->set('user_vat_data', $vat_data);
1879 1879
     }
1880 1880
     
1881
-    public static function checkout_vat_fields( $billing_details ) {
1881
+    public static function checkout_vat_fields($billing_details) {
1882 1882
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1883 1883
         
1884 1884
         $ip_address         = wpinv_get_ip();
1885 1885
         $ip_country_code    = self::get_country_by_ip();
1886 1886
         
1887
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1887
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1888 1888
         $invoice            = wpinv_get_invoice_cart();
1889
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1889
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1890 1890
         $wpi_country        = $invoice->country;
1891 1891
         
1892
-        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital );
1892
+        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital);
1893 1893
         $wpi_requires_vat   = $requires_vat;
1894 1894
         
1895 1895
         $company            = is_user_logged_in() ? self::get_user_company() : '';
1896 1896
         $vat_number         = self::get_user_vat_number();
1897 1897
         
1898
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1899
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1898
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1899
+        $vat_info           = $wpi_session->get('user_vat_data');
1900 1900
 
1901
-        if ( is_array( $vat_info ) ) {
1902
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1903
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1904
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1901
+        if (is_array($vat_info)) {
1902
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1903
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1904
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1905 1905
         }
1906 1906
         
1907 1907
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1908 1908
 
1909
-        if ( $ip_country_code == 'UK' ) {
1909
+        if ($ip_country_code == 'UK') {
1910 1910
             $ip_country_code = 'GB';
1911 1911
         }
1912 1912
         
1913
-        if ( $selected_country == 'UK' ) {
1913
+        if ($selected_country == 'UK') {
1914 1914
             $selected_country = 'GB';
1915 1915
         }
1916 1916
         
1917
-        if ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) ) {
1917
+        if (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country)) {
1918 1918
             $requires_vat       = false;
1919 1919
         }
1920 1920
 
@@ -1922,52 +1922,52 @@  discard block
 block discarded – undo
1922 1922
         $display_validate_btn   = 'none';
1923 1923
         $display_reset_btn      = 'none';
1924 1924
         
1925
-        if ( !empty( $vat_number ) && $validated ) {
1926
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1925
+        if (!empty($vat_number) && $validated) {
1926
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1927 1927
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1928 1928
             $display_reset_btn      = 'block';
1929 1929
         } else {
1930
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1931
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1930
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1931
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1932 1932
             $display_validate_btn   = 'block';
1933 1933
         }
1934 1934
         
1935
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1935
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1936 1936
         ?>
1937 1937
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1938 1938
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1939
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1939
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1940 1940
                 <div id="wpinv-fields-box" class="panel-body">
1941 1941
                     <p id="wpi_show_vat_note">
1942
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1942
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1943 1943
                     </p>
1944 1944
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1945 1945
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1946
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1946
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1947 1947
                             <?php
1948
-                            echo wpinv_html_text( array(
1948
+                            echo wpinv_html_text(array(
1949 1949
                                     'id'            => 'wpinv_company',
1950 1950
                                     'name'          => 'wpinv_company',
1951 1951
                                     'value'         => $company,
1952 1952
                                     'class'         => 'wpi-input form-control',
1953
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1954
-                                ) );
1953
+                                    'placeholder'   => __('Company name', 'invoicing'),
1954
+                                ));
1955 1955
                             ?>
1956 1956
                         </p>
1957 1957
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1958
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1958
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1959 1959
                             <span id="wpinv_vat_number-wrap">
1960 1960
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1961
-                                <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">
1962
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1961
+                                <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">
1962
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1963 1963
                             </span>
1964 1964
                         </p>
1965 1965
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1966
-                            <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>
1967
-                            <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>
1966
+                            <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>
1967
+                            <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>
1968 1968
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1969 1969
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1970
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1970
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1971 1971
                         </p>
1972 1972
                     </div>
1973 1973
                 </div>
@@ -1981,32 +1981,32 @@  discard block
 block discarded – undo
1981 1981
                 </span>
1982 1982
             </div>
1983 1983
         </div>
1984
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1985
-            $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>';
1984
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1985
+            $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>';
1986 1986
         ?>
1987 1987
         <div class="wpi-ip-info clearfix panel panel-info">
1988 1988
             <div id="wpinv-fields-box" class="panel-body">
1989
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
1989
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
1990 1990
             </div>
1991 1991
         </div>
1992 1992
         <?php }
1993 1993
     }
1994 1994
     
1995
-    public static function show_vat_notice( $invoice ) {
1996
-        if ( empty( $invoice ) ) {
1995
+    public static function show_vat_notice($invoice) {
1996
+        if (empty($invoice)) {
1997 1997
             return NULL;
1998 1998
         }
1999 1999
         
2000
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2001
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2002
-        if ( $label || $notice ) {
2000
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2001
+        $notice     = wpinv_get_option('vat_invoice_notice');
2002
+        if ($label || $notice) {
2003 2003
         ?>
2004 2004
         <div class="row wpinv-vat-notice">
2005 2005
             <div class="col-sm-12">
2006
-                <?php if ( $label ) { ?>
2007
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2008
-                <?php } if ( $notice ) { ?>
2009
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2006
+                <?php if ($label) { ?>
2007
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2008
+                <?php } if ($notice) { ?>
2009
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2010 2010
                 <?php } ?>
2011 2011
             </div>
2012 2012
         </div>
Please login to merge, or discard this patch.
includes/libraries/wp-session/wp-cli.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 	 * @param array $args
22 22
 	 * @param array $assoc_args
23 23
 	 */
24
-	public function count( $args, $assoc_args ) {
24
+	public function count($args, $assoc_args) {
25 25
 		$sessions = WP_Session_Utils::count_sessions();
26 26
 
27
-		\WP_CLI::line( sprintf( '%d sessions currently exist.', absint( $sessions ) ) );
27
+		\WP_CLI::line(sprintf('%d sessions currently exist.', absint($sessions)));
28 28
 	}
29 29
 
30 30
 	/**
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 	 * @param array $args
54 54
 	 * @param array $assoc_args
55 55
 	 */
56
-	public function delete( $args, $assoc_args ) {
57
-		if ( isset( $assoc_args['limit'] ) ) {
58
-			$limit = absint( $assoc_args['limit'] );
56
+	public function delete($args, $assoc_args) {
57
+		if (isset($assoc_args['limit'])) {
58
+			$limit = absint($assoc_args['limit']);
59 59
 
60
-			$count = WP_Session_Utils::delete_old_sessions( $limit );
60
+			$count = WP_Session_Utils::delete_old_sessions($limit);
61 61
 
62
-			if ( $count > 0 ) {
63
-				\WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) );
62
+			if ($count > 0) {
63
+				\WP_CLI::line(sprintf('Deleted %d sessions.', $count));
64 64
 			}
65 65
 
66 66
 			// Clear memory
@@ -69,32 +69,32 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 
71 71
 		// Determine if we're deleting all sessions or just a subset.
72
-		$all = isset( $assoc_args['all'] );
72
+		$all = isset($assoc_args['all']);
73 73
 
74 74
 		/**
75 75
 		 * Determine the size of each batch for deletion.
76 76
 		 *
77 77
 		 * @param int
78 78
 		 */
79
-		$batch = isset( $assoc_args['batch'] ) ? absint( $assoc_args['batch'] ) : apply_filters( 'wp_session_delete_batch_size', 1000 );
79
+		$batch = isset($assoc_args['batch']) ? absint($assoc_args['batch']) : apply_filters('wp_session_delete_batch_size', 1000);
80 80
 
81
-		switch ( $all ) {
81
+		switch ($all) {
82 82
 			case true:
83 83
 				$count = WP_Session_Utils::delete_all_sessions();
84 84
 
85
-				\WP_CLI::line( sprintf( 'Deleted all %d sessions.', $count ) );
85
+				\WP_CLI::line(sprintf('Deleted all %d sessions.', $count));
86 86
 				break;
87 87
 			case false:
88 88
 				do {
89
-					$count = WP_Session_Utils::delete_old_sessions( $batch );
89
+					$count = WP_Session_Utils::delete_old_sessions($batch);
90 90
 
91
-					if ( $count > 0 ) {
92
-						\WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) );
91
+					if ($count > 0) {
92
+						\WP_CLI::line(sprintf('Deleted %d sessions.', $count));
93 93
 					}
94 94
 
95 95
 					// Clear memory
96 96
 					self::free_up_memory();
97
-				} while ( $count > 0 );
97
+				} while ($count > 0);
98 98
 				break;
99 99
 		}
100 100
 	}
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @param array $args
121 121
 	 * @param array $assoc_args
122 122
 	 */
123
-	public function generate( $args, $assoc_args ) {
124
-		$count = absint( $args[0] );
125
-		$date  = isset( $assoc_args['expires'] ) ? $assoc_args['expires'] : null;
123
+	public function generate($args, $assoc_args) {
124
+		$count = absint($args[0]);
125
+		$date  = isset($assoc_args['expires']) ? $assoc_args['expires'] : null;
126 126
 
127
-		$notify = \WP_CLI\Utils\make_progress_bar( 'Generating sessions', $count );
127
+		$notify = \WP_CLI\Utils\make_progress_bar('Generating sessions', $count);
128 128
 
129
-		for ( $i = 0; $i < $count; $i ++ ) {
130
-			WP_Session_Utils::create_dummy_session( $date );
129
+		for ($i = 0; $i < $count; $i++) {
130
+			WP_Session_Utils::create_dummy_session($date);
131 131
 			$notify->tick();
132 132
 		}
133 133
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		global $wp_object_cache, $wpdb;
145 145
 		$wpdb->queries = array();
146 146
 
147
-		if ( ! is_object( $wp_object_cache ) ) {
147
+		if (!is_object($wp_object_cache)) {
148 148
 			return;
149 149
 		}
150 150
 
@@ -155,4 +155,4 @@  discard block
 block discarded – undo
155 155
 	}
156 156
 }
157 157
 
158
-\WP_CLI::add_command( 'session', 'WP_Session_Command' );
159 158
\ No newline at end of file
159
+\WP_CLI::add_command('session', 'WP_Session_Command');
160 160
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/wp-session/wp-session.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
  *
34 34
  * @param string $data
35 35
  */
36
-function wp_session_decode( $data ) {
36
+function wp_session_decode($data) {
37 37
 	$wp_session = WP_Session::get_instance();
38 38
 
39
-	return $wp_session->json_in( $data );
39
+	return $wp_session->json_in($data);
40 40
 }
41 41
 
42 42
 /**
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
  *
58 58
  * @return bool
59 59
  */
60
-function wp_session_regenerate_id( $delete_old_session = false ) {
60
+function wp_session_regenerate_id($delete_old_session = false) {
61 61
 	$wp_session = WP_Session::get_instance();
62 62
 
63
-	$wp_session->regenerate_id( $delete_old_session );
63
+	$wp_session->regenerate_id($delete_old_session);
64 64
 
65 65
 	return true;
66 66
 }
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
  */
75 75
 function wp_session_start() {
76 76
 	$wp_session = WP_Session::get_instance();
77
-	do_action( 'wp_session_start' );
77
+	do_action('wp_session_start');
78 78
 
79 79
 	return $wp_session->session_started();
80 80
 }
81
-if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) {
82
-	add_action( 'plugins_loaded', 'wp_session_start' );
81
+if (!defined('WP_CLI') || false === WP_CLI) {
82
+	add_action('plugins_loaded', 'wp_session_start');
83 83
 }
84 84
 
85 85
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 function wp_session_status() {
91 91
 	$wp_session = WP_Session::get_instance();
92 92
 
93
-	if ( $wp_session->session_started() ) {
93
+	if ($wp_session->session_started()) {
94 94
 		return PHP_SESSION_ACTIVE;
95 95
 	}
96 96
 
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 	$wp_session = WP_Session::get_instance();
114 114
 
115 115
 	$wp_session->write_data();
116
-	do_action( 'wp_session_commit' );
116
+	do_action('wp_session_commit');
117 117
 }
118
-if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) {
119
-	add_action( 'shutdown', 'wp_session_write_close' );
118
+if (!defined('WP_CLI') || false === WP_CLI) {
119
+	add_action('shutdown', 'wp_session_write_close');
120 120
 }
121 121
 
122 122
 /**
@@ -127,33 +127,33 @@  discard block
 block discarded – undo
127 127
  * of a scheduled task or cron job.
128 128
  */
129 129
 function wp_session_cleanup() {
130
-	if ( defined( 'WP_SETUP_CONFIG' ) ) {
130
+	if (defined('WP_SETUP_CONFIG')) {
131 131
 		return;
132 132
 	}
133 133
 
134
-	if ( ! defined( 'WP_INSTALLING' ) ) {
134
+	if (!defined('WP_INSTALLING')) {
135 135
 		/**
136 136
 		 * Determine the size of each batch for deletion.
137 137
 		 *
138 138
 		 * @param int
139 139
 		 */
140
-		$batch_size = apply_filters( 'wp_session_delete_batch_size', 1000 );
140
+		$batch_size = apply_filters('wp_session_delete_batch_size', 1000);
141 141
 
142 142
 		// Delete a batch of old sessions
143
-		WP_Session_Utils::delete_old_sessions( $batch_size );
143
+		WP_Session_Utils::delete_old_sessions($batch_size);
144 144
 	}
145 145
 
146 146
 	// Allow other plugins to hook in to the garbage collection process.
147
-	do_action( 'wp_session_cleanup' );
147
+	do_action('wp_session_cleanup');
148 148
 }
149
-add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' );
149
+add_action('wp_session_garbage_collection', 'wp_session_cleanup');
150 150
 
151 151
 /**
152 152
  * Register the garbage collector as a twice daily event.
153 153
  */
154 154
 function wp_session_register_garbage_collection() {
155
-	if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) {
156
-		wp_schedule_event( time(), 'hourly', 'wp_session_garbage_collection' );
155
+	if (!wp_next_scheduled('wp_session_garbage_collection')) {
156
+		wp_schedule_event(time(), 'hourly', 'wp_session_garbage_collection');
157 157
 	}
158 158
 }
159
-add_action( 'wp', 'wp_session_register_garbage_collection' );
159
+add_action('wp', 'wp_session_register_garbage_collection');
Please login to merge, or discard this patch.