Completed
Push — master ( fe4649...9700bf )
by Stiofan
14s
created
includes/wpinv-payment-functions.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_get_subscriptions( $args = array() ) {
3
-    if ( empty( $args['parent_invoice_id'] ) ) {
2
+function wpinv_get_subscriptions($args = array()) {
3
+    if (empty($args['parent_invoice_id'])) {
4 4
         return false;
5 5
     }
6 6
     
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
     );
15 15
 
16 16
     $args['post_parent']    = $args['parent_invoice_id'];
17
-    $args                   = wp_parse_args( $args, $defaults );
17
+    $args                   = wp_parse_args($args, $defaults);
18 18
 
19
-    if( $args['numberposts'] < 1 ) {
19
+    if ($args['numberposts'] < 1) {
20 20
         $args['numberposts'] = 999999999999;
21 21
     }
22 22
 
23
-    $posts          = get_posts( $args );
23
+    $posts          = get_posts($args);
24 24
     $subscriptions  = array();
25
-    if ( !empty( $posts ) ) {
26
-        foreach ( $posts as $post ) {
27
-            if ( !empty( $post->ID ) ) {
28
-                $subscriptions[] = wpinv_get_invoice( $post->ID );
25
+    if (!empty($posts)) {
26
+        foreach ($posts as $post) {
27
+            if (!empty($post->ID)) {
28
+                $subscriptions[] = wpinv_get_invoice($post->ID);
29 29
             }
30 30
         }
31 31
     }
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
     
34 34
     return $subscriptions;
35 35
 }
36
-function wpinv_get_subscription( $id = 0, $by_profile_id = false ) {
36
+function wpinv_get_subscription($id = 0, $by_profile_id = false) {
37 37
     global $wpdb;
38 38
 
39
-    if ( empty( $id ) ) {
39
+    if (empty($id)) {
40 40
         return false;
41 41
     }
42 42
 
43
-    $id = esc_sql( $id );
43
+    $id = esc_sql($id);
44 44
 
45
-    $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" );
45
+    $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1");
46 46
 
47
-    if ( $invoice_id != null ) {
48
-        return wpinv_get_invoice( $invoice_id );
47
+    if ($invoice_id != null) {
48
+        return wpinv_get_invoice($invoice_id);
49 49
     }
50 50
 
51 51
     return false;
@@ -55,47 +55,47 @@  discard block
 block discarded – undo
55 55
  * Records a new payment on the subscription
56 56
  * 
57 57
  */
58
-function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) {    
59
-    $args = wp_parse_args( $subscription_args, array(
58
+function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) {    
59
+    $args = wp_parse_args($subscription_args, array(
60 60
         'amount'         => '',
61 61
         'transaction_id' => '',
62 62
         'gateway'        => ''
63
-    ) );
63
+    ));
64 64
 
65
-    if ( wpinv_payment_exists( $args['transaction_id'] ) ) {
65
+    if (wpinv_payment_exists($args['transaction_id'])) {
66 66
         return false;
67 67
     }
68 68
     
69
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
70
-    if ( empty( $parent_invoice ) ) {
69
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
70
+    if (empty($parent_invoice)) {
71 71
         return;
72 72
     }
73 73
 
74 74
     $invoice = new WPInv_Invoice();
75
-    $invoice->set( 'post_type', 'wpi_invoice' );
76
-    $invoice->set( 'parent_invoice', $parent_invoice_id );
77
-    $invoice->set( 'currency', $parent_invoice->get_currency() );
78
-    $invoice->set( 'transaction_id', $args['transaction_id'] );
79
-    $invoice->set( 'key', $parent_invoice->generate_key() );
80
-    $invoice->set( 'ip', $parent_invoice->ip );
81
-    $invoice->set( 'user_id', $parent_invoice->get_user_id() );
82
-    $invoice->set( 'first_name', $parent_invoice->get_first_name() );
83
-    $invoice->set( 'last_name', $parent_invoice->get_last_name() );
84
-    $invoice->set( 'phone', $parent_invoice->phone );
85
-    $invoice->set( 'address', $parent_invoice->address );
86
-    $invoice->set( 'city', $parent_invoice->city );
87
-    $invoice->set( 'country', $parent_invoice->country );
88
-    $invoice->set( 'state', $parent_invoice->state );
89
-    $invoice->set( 'zip', $parent_invoice->zip );
90
-    $invoice->set( 'company', $parent_invoice->company );
91
-    $invoice->set( 'vat_number', $parent_invoice->vat_number );
92
-    $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
93
-    $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
94
-
95
-    if ( empty( $args['gateway'] ) ) {
96
-        $invoice->set( 'gateway', $parent_invoice->get_gateway() );
75
+    $invoice->set('post_type', 'wpi_invoice');
76
+    $invoice->set('parent_invoice', $parent_invoice_id);
77
+    $invoice->set('currency', $parent_invoice->get_currency());
78
+    $invoice->set('transaction_id', $args['transaction_id']);
79
+    $invoice->set('key', $parent_invoice->generate_key());
80
+    $invoice->set('ip', $parent_invoice->ip);
81
+    $invoice->set('user_id', $parent_invoice->get_user_id());
82
+    $invoice->set('first_name', $parent_invoice->get_first_name());
83
+    $invoice->set('last_name', $parent_invoice->get_last_name());
84
+    $invoice->set('phone', $parent_invoice->phone);
85
+    $invoice->set('address', $parent_invoice->address);
86
+    $invoice->set('city', $parent_invoice->city);
87
+    $invoice->set('country', $parent_invoice->country);
88
+    $invoice->set('state', $parent_invoice->state);
89
+    $invoice->set('zip', $parent_invoice->zip);
90
+    $invoice->set('company', $parent_invoice->company);
91
+    $invoice->set('vat_number', $parent_invoice->vat_number);
92
+    $invoice->set('vat_rate', $parent_invoice->vat_rate);
93
+    $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
94
+
95
+    if (empty($args['gateway'])) {
96
+        $invoice->set('gateway', $parent_invoice->get_gateway());
97 97
     } else {
98
-        $invoice->set( 'gateway', $args['gateway'] );
98
+        $invoice->set('gateway', $args['gateway']);
99 99
     }
100 100
     
101 101
     $recurring_details = $parent_invoice->get_recurring_details();
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
     // increase the earnings for each item in the subscription
104 104
     $items = $recurring_details['cart_details'];
105 105
     
106
-    if ( $items ) {        
106
+    if ($items) {        
107 107
         $add_items      = array();
108 108
         $cart_details   = array();
109 109
         
110
-        foreach ( $items as $item ) {
110
+        foreach ($items as $item) {
111 111
             $add_item             = array();
112 112
             $add_item['id']       = $item['id'];
113 113
             $add_item['quantity'] = $item['quantity'];
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             break;
118 118
         }
119 119
         
120
-        $invoice->set( 'items', $add_items );
120
+        $invoice->set('items', $add_items);
121 121
         $invoice->cart_details = $cart_details;
122 122
     }
123 123
     
@@ -127,277 +127,277 @@  discard block
 block discarded – undo
127 127
     $tax                = $recurring_details['tax'];
128 128
     $discount           = $recurring_details['discount'];
129 129
     
130
-    if ( $discount > 0 ) {
131
-        $invoice->set( 'discount_code', $parent_invoice->discount_code );
130
+    if ($discount > 0) {
131
+        $invoice->set('discount_code', $parent_invoice->discount_code);
132 132
     }
133 133
     
134
-    $invoice->subtotal = wpinv_round_amount( $subtotal );
135
-    $invoice->tax      = wpinv_round_amount( $tax );
136
-    $invoice->discount = wpinv_round_amount( $discount );
137
-    $invoice->total    = wpinv_round_amount( $total );
134
+    $invoice->subtotal = wpinv_round_amount($subtotal);
135
+    $invoice->tax      = wpinv_round_amount($tax);
136
+    $invoice->discount = wpinv_round_amount($discount);
137
+    $invoice->total    = wpinv_round_amount($total);
138 138
     $invoice->save();
139 139
     
140
-    wpinv_update_payment_status( $invoice->ID, 'publish' );
140
+    wpinv_update_payment_status($invoice->ID, 'publish');
141 141
     sleep(1);
142
-    wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
142
+    wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
143 143
     
144
-    $invoice = wpinv_get_invoice( $invoice->ID );
144
+    $invoice = wpinv_get_invoice($invoice->ID);
145 145
     
146
-    $subscription_data                      = wpinv_payment_subscription_data( $parent_invoice );
146
+    $subscription_data                      = wpinv_payment_subscription_data($parent_invoice);
147 147
     $subscription_data['recurring_amount']  = $invoice->get_total();
148
-    $subscription_data['created']           = current_time( 'mysql', 0 );
149
-    $subscription_data['expiration']        = $invoice->get_new_expiration( $subscription_data['item_id'] );
148
+    $subscription_data['created']           = current_time('mysql', 0);
149
+    $subscription_data['expiration']        = $invoice->get_new_expiration($subscription_data['item_id']);
150 150
     
151 151
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
152
-    $invoice->update_subscription( $subscription_data );
152
+    $invoice->update_subscription($subscription_data);
153 153
 
154
-    do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args );
155
-    do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args );
154
+    do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args);
155
+    do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args);
156 156
 
157 157
     return $invoice;
158 158
 }
159 159
 
160
-function wpinv_payment_exists( $txn_id = '' ) {
160
+function wpinv_payment_exists($txn_id = '') {
161 161
     global $wpdb;
162 162
 
163
-    if ( empty( $txn_id ) ) {
163
+    if (empty($txn_id)) {
164 164
         return false;
165 165
     }
166 166
 
167
-    $txn_id = esc_sql( $txn_id );
167
+    $txn_id = esc_sql($txn_id);
168 168
 
169
-    $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
169
+    $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
170 170
 
171
-    if ( $invoice != null ) {
171
+    if ($invoice != null) {
172 172
         return true;
173 173
     }
174 174
 
175 175
     return false;
176 176
 }
177 177
 
178
-function wpinv_is_subscription_payment( $invoice = '' ) {
179
-    if ( empty( $invoice ) ) {
178
+function wpinv_is_subscription_payment($invoice = '') {
179
+    if (empty($invoice)) {
180 180
         return false;
181 181
     }
182 182
     
183
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
184
-        $invoice = wpinv_get_invoice( $invoice );
183
+    if (!is_object($invoice) && is_scalar($invoice)) {
184
+        $invoice = wpinv_get_invoice($invoice);
185 185
     }
186 186
     
187
-    if ( empty( $invoice ) ) {
187
+    if (empty($invoice)) {
188 188
         return false;
189 189
     }
190 190
         
191
-    if ( $invoice->is_renewal() ) {
191
+    if ($invoice->is_renewal()) {
192 192
         return true;
193 193
     }
194 194
 
195 195
     return false;
196 196
 }
197 197
 
198
-function wpinv_payment_subscription_data( $invoice = '' ) {
199
-    if ( empty( $invoice ) ) {
198
+function wpinv_payment_subscription_data($invoice = '') {
199
+    if (empty($invoice)) {
200 200
         return false;
201 201
     }
202 202
     
203
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
204
-        $invoice = wpinv_get_invoice( $invoice );
203
+    if (!is_object($invoice) && is_scalar($invoice)) {
204
+        $invoice = wpinv_get_invoice($invoice);
205 205
     }
206 206
     
207
-    if ( empty( $invoice ) ) {
207
+    if (empty($invoice)) {
208 208
         return false;
209 209
     }    
210 210
 
211 211
     return $invoice->get_subscription_data();
212 212
 }
213 213
 
214
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
215
-    if ( empty( $invoice ) ) {
214
+function wpinv_payment_link_transaction_id($invoice = '') {
215
+    if (empty($invoice)) {
216 216
         return false;
217 217
     }
218 218
     
219
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
220
-        $invoice = wpinv_get_invoice( $invoice );
219
+    if (!is_object($invoice) && is_scalar($invoice)) {
220
+        $invoice = wpinv_get_invoice($invoice);
221 221
     }
222 222
     
223
-    if ( empty( $invoice ) ) {
223
+    if (empty($invoice)) {
224 224
         return false;
225 225
     }
226 226
 
227
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
227
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
228 228
 }
229 229
 
230
-function wpinv_get_pretty_subscription_period( $period ) {
230
+function wpinv_get_pretty_subscription_period($period) {
231 231
     $frequency = '';
232 232
     //Format period details
233
-    switch ( $period ) {
233
+    switch ($period) {
234 234
         case 'D' :
235 235
         case 'day' :
236
-            $frequency = __( 'Daily', 'invoicing' );
236
+            $frequency = __('Daily', 'invoicing');
237 237
             break;
238 238
         case 'W' :
239 239
         case 'week' :
240
-            $frequency = __( 'Weekly', 'invoicing' );
240
+            $frequency = __('Weekly', 'invoicing');
241 241
             break;
242 242
         case 'M' :
243 243
         case 'month' :
244
-            $frequency = __( 'Monthly', 'invoicing' );
244
+            $frequency = __('Monthly', 'invoicing');
245 245
             break;
246 246
         case 'Y' :
247 247
         case 'year' :
248
-            $frequency = __( 'Yearly', 'invoicing' );
248
+            $frequency = __('Yearly', 'invoicing');
249 249
             break;
250 250
         default :
251
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period );
251
+            $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period);
252 252
             break;
253 253
     }
254 254
 
255 255
     return $frequency;
256 256
 }
257 257
 
258
-function wpinv_get_pretty_subscription_period_name( $period ) {
258
+function wpinv_get_pretty_subscription_period_name($period) {
259 259
     $frequency = '';
260 260
     //Format period details
261
-    switch ( $period ) {
261
+    switch ($period) {
262 262
         case 'D' :
263 263
         case 'day' :
264
-            $frequency = __( 'Day', 'invoicing' );
264
+            $frequency = __('Day', 'invoicing');
265 265
             break;
266 266
         case 'W' :
267 267
         case 'week' :
268
-            $frequency = __( 'Week', 'invoicing' );
268
+            $frequency = __('Week', 'invoicing');
269 269
             break;
270 270
         case 'M' :
271 271
         case 'month' :
272
-            $frequency = __( 'Month', 'invoicing' );
272
+            $frequency = __('Month', 'invoicing');
273 273
             break;
274 274
         case 'Y' :
275 275
         case 'year' :
276
-            $frequency = __( 'Year', 'invoicing' );
276
+            $frequency = __('Year', 'invoicing');
277 277
             break;
278 278
         default :
279
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period );
279
+            $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period);
280 280
             break;
281 281
     }
282 282
 
283 283
     return $frequency;
284 284
 }
285 285
 
286
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
286
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
287 287
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
288 288
     
289
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
290
-        $amount = __( 'Free', 'invoicing' );
289
+    if ($trial_interval > 0 && !empty($trial_period)) {
290
+        $amount = __('Free', 'invoicing');
291 291
         $interval = $trial_interval;
292 292
         $period = $trial_period;
293 293
     }
294 294
     
295 295
     $description = '';
296
-    switch ( $period ) {
296
+    switch ($period) {
297 297
         case 'D' :
298 298
         case 'day' :
299
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
299
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
300 300
             break;
301 301
         case 'W' :
302 302
         case 'week' :
303
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
303
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
304 304
             break;
305 305
         case 'M' :
306 306
         case 'month' :
307
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
307
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
308 308
             break;
309 309
         case 'Y' :
310 310
         case 'year' :
311
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
311
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
312 312
             break;
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
315
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
316 316
 }
317 317
 
318
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
318
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
319 319
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
320 320
     $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
321 321
     
322 322
     $description = '';
323
-    switch ( $period ) {
323
+    switch ($period) {
324 324
         case 'D' :
325 325
         case 'day' :            
326
-            if ( (int)$bill_times > 0 ) {
327
-                if ( $interval > 1 ) {
328
-                    if ( $bill_times > 1 ) {
329
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
326
+            if ((int)$bill_times > 0) {
327
+                if ($interval > 1) {
328
+                    if ($bill_times > 1) {
329
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
330 330
                     } else {
331
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
331
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
332 332
                     }
333 333
                 } else {
334
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
334
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
335 335
                 }
336 336
             } else {
337
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
337
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
338 338
             }
339 339
             break;
340 340
         case 'W' :
341 341
         case 'week' :            
342
-            if ( (int)$bill_times > 0 ) {
343
-                if ( $interval > 1 ) {
344
-                    if ( $bill_times > 1 ) {
345
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
342
+            if ((int)$bill_times > 0) {
343
+                if ($interval > 1) {
344
+                    if ($bill_times > 1) {
345
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
346 346
                     } else {
347
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
347
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
348 348
                     }
349 349
                 } else {
350
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
350
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
351 351
                 }
352 352
             } else {
353
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
353
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
354 354
             }
355 355
             break;
356 356
         case 'M' :
357 357
         case 'month' :            
358
-            if ( (int)$bill_times > 0 ) {
359
-                if ( $interval > 1 ) {
360
-                    if ( $bill_times > 1 ) {
361
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
358
+            if ((int)$bill_times > 0) {
359
+                if ($interval > 1) {
360
+                    if ($bill_times > 1) {
361
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
362 362
                     } else {
363
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
363
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
364 364
                     }
365 365
                 } else {
366
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
366
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
367 367
                 }
368 368
             } else {
369
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
369
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
370 370
             }
371 371
             break;
372 372
         case 'Y' :
373 373
         case 'year' :            
374
-            if ( (int)$bill_times > 0 ) {
375
-                if ( $interval > 1 ) {
376
-                    if ( $bill_times > 1 ) {
377
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
374
+            if ((int)$bill_times > 0) {
375
+                if ($interval > 1) {
376
+                    if ($bill_times > 1) {
377
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
378 378
                     } else {
379
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
379
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
380 380
                     }
381 381
                 } else {
382
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
382
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
383 383
                 }
384 384
             } else {
385
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
385
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
386 386
             }
387 387
             break;
388 388
     }
389 389
 
390
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
390
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
391 391
 }
392 392
 
393
-function wpinv_subscription_payment_desc( $invoice ) {
394
-    if ( empty( $invoice ) ) {
393
+function wpinv_subscription_payment_desc($invoice) {
394
+    if (empty($invoice)) {
395 395
         return NULL;
396 396
     }
397 397
     
398 398
     $description = '';
399
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
400
-        if ( $item->has_free_trial() ) {
399
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
400
+        if ($item->has_free_trial()) {
401 401
             $trial_period = $item->get_trial_period();
402 402
             $trial_interval = $item->get_trial_interval();
403 403
         } else {
@@ -405,45 +405,45 @@  discard block
 block discarded – undo
405 405
             $trial_interval = 0;
406 406
         }
407 407
         
408
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
408
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
409 409
     }
410 410
     
411
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
411
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
412 412
 }
413 413
 
414
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
415
-    $initial_total      = wpinv_round_amount( $initial );
416
-    $recurring_total    = wpinv_round_amount( $recurring );
414
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
415
+    $initial_total      = wpinv_round_amount($initial);
416
+    $recurring_total    = wpinv_round_amount($recurring);
417 417
     
418
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
418
+    if ($trial_interval > 0 && !empty($trial_period)) {
419 419
         // Free trial
420 420
     } else {
421
-        if ( $bill_times == 1 ) {
421
+        if ($bill_times == 1) {
422 422
             $recurring_total = $initial_total;
423
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
423
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
424 424
             $bill_times--;
425 425
         }
426 426
     }
427 427
     
428
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
429
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
428
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
429
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
430 430
     
431
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
431
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
432 432
         
433
-    if ( $initial_total != $recurring_total ) {
434
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
433
+    if ($initial_total != $recurring_total) {
434
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
435 435
         
436
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
436
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
437 437
     } else {
438 438
         $description    = $recurring;
439 439
     }
440 440
     
441
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
441
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
442 442
 }
443 443
 
444
-function wpinv_recurring_send_payment_failed( $invoice ) {
445
-    if ( !empty( $invoice->ID ) ) {
446
-        wpinv_failed_invoice_notification( $invoice->ID );
444
+function wpinv_recurring_send_payment_failed($invoice) {
445
+    if (!empty($invoice->ID)) {
446
+        wpinv_failed_invoice_notification($invoice->ID);
447 447
     }
448 448
 }
449
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
450 449
\ No newline at end of file
450
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
451 451
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,189 +83,189 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
117 117
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
118 118
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
119
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
119
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
120 120
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
121
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
128
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
129
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
121
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
128
+        if (!class_exists('WPInv_EUVat')) {
129
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
130 130
         }
131 131
         
132
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
133
-        if ( !empty( $gateways ) ) {
134
-            foreach ( $gateways as $gateway ) {
135
-                if ( $gateway == 'manual' ) {
132
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
133
+        if (!empty($gateways)) {
134
+            foreach ($gateways as $gateway) {
135
+                if ($gateway == 'manual') {
136 136
                     continue;
137 137
                 }
138 138
                 
139 139
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
140 140
                 
141
-                if ( file_exists( $gateway_file ) ) {
142
-                    require_once( $gateway_file );
141
+                if (file_exists($gateway_file)) {
142
+                    require_once($gateway_file);
143 143
                 }
144 144
             }
145 145
         }
146
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
146
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
147 147
         
148
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
149
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
148
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
149
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
152 152
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
153
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
153
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
158 158
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
159 159
         }
160 160
         
161 161
         // include css inliner
162
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
163
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
162
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
163
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
164 164
         }
165 165
         
166
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
166
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
167 167
     }
168 168
     
169 169
     public function init() {
170 170
     }
171 171
     
172 172
     public function admin_init() {
173
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
173
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
174 174
         }
175 175
         
176
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
176
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
177 177
     }
178 178
 
179 179
     public function activation_redirect() {
180 180
         // Bail if no activation redirect
181
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
181
+        if (!get_transient('_wpinv_activation_redirect')) {
182 182
             return;
183 183
         }
184 184
 
185 185
         // Delete the redirect transient
186
-        delete_transient( '_wpinv_activation_redirect' );
186
+        delete_transient('_wpinv_activation_redirect');
187 187
 
188 188
         // Bail if activating from network, or bulk
189
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
189
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
190 190
             return;
191 191
         }
192 192
 
193
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
193
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
194 194
         exit;
195 195
     }
196 196
     
197 197
     public function enqueue_scripts() {
198
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
198
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199 199
         
200
-        wp_deregister_style( 'font-awesome' );
201
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
202
-        wp_enqueue_style( 'font-awesome' );
200
+        wp_deregister_style('font-awesome');
201
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
202
+        wp_enqueue_style('font-awesome');
203 203
         
204
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
205
-        wp_enqueue_style( 'wpinv_front_style' );
204
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
205
+        wp_enqueue_style('wpinv_front_style');
206 206
                
207 207
         // Register scripts
208
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
209
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
208
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
209
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
210 210
         
211 211
         $localize                         = array();
212
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
213
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
212
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
213
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
214 214
         $localize['currency_symbol']      = wpinv_currency_symbol();
215 215
         $localize['currency_pos']         = wpinv_currency_position();
216 216
         $localize['thousand_sep']         = wpinv_thousands_separator();
217 217
         $localize['decimal_sep']          = wpinv_decimal_separator();
218 218
         $localize['decimals']             = wpinv_decimals();
219 219
         
220
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
220
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
221 221
         
222
-        wp_enqueue_script( 'jquery-blockui' );
222
+        wp_enqueue_script('jquery-blockui');
223 223
         $autofill_api = wpinv_get_option('address_autofill_api');
224 224
         $autofill_active = wpinv_get_option('address_autofill_active');
225
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
226
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
227
-                wp_dequeue_script( 'google-maps-api' );
225
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
226
+            if (wp_script_is('google-maps-api', 'enqueued')) {
227
+                wp_dequeue_script('google-maps-api');
228 228
             }
229
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
230
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
229
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
230
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
231 231
         }
232
-        wp_enqueue_script( 'wpinv-front-script' );
233
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
232
+        wp_enqueue_script('wpinv-front-script');
233
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
234 234
     }
235 235
 
236 236
     public function admin_enqueue_scripts() {
237 237
         global $post, $pagenow;
238 238
         
239 239
         $post_type  = wpinv_admin_post_type();
240
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
240
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
241 241
         
242
-        wp_deregister_style( 'font-awesome' );
243
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
244
-        wp_enqueue_style( 'font-awesome' );
242
+        wp_deregister_style('font-awesome');
243
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
244
+        wp_enqueue_style('font-awesome');
245 245
         
246
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
247
-        wp_enqueue_style( 'jquery-ui-css' );
246
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
247
+        wp_enqueue_style('jquery-ui-css');
248 248
         
249
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
250
-        wp_enqueue_style( 'jquery-chosen' );
249
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
250
+        wp_enqueue_style('jquery-chosen');
251 251
 
252
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
253
-        wp_enqueue_script( 'jquery-chosen' );
252
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
253
+        wp_enqueue_script('jquery-chosen');
254 254
         
255
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
256
-        wp_enqueue_style( 'wpinv_meta_box_style' );
255
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
256
+        wp_enqueue_style('wpinv_meta_box_style');
257 257
         
258
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
259
-        wp_enqueue_style( 'wpinv_admin_style' );
258
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
259
+        wp_enqueue_style('wpinv_admin_style');
260 260
         
261
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
262
-            wp_enqueue_script( 'jquery-ui-datepicker' );
261
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
262
+            wp_enqueue_script('jquery-ui-datepicker');
263 263
         }
264 264
 
265
-        wp_enqueue_style( 'wp-color-picker' );
266
-        wp_enqueue_script( 'wp-color-picker' );
265
+        wp_enqueue_style('wp-color-picker');
266
+        wp_enqueue_script('wp-color-picker');
267 267
         
268
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
268
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
269 269
 
270 270
         if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
271 271
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -276,17 +276,17 @@  discard block
 block discarded – undo
276 276
             }
277 277
         }
278 278
 
279
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  WPINV_VERSION );
280
-        wp_enqueue_script( 'wpinv-admin-script' );
279
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION);
280
+        wp_enqueue_script('wpinv-admin-script');
281 281
         
282 282
         $localize                               = array();
283
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
284
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
285
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
286
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
287
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
288
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
289
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
283
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
284
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
285
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
286
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
287
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
288
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
289
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
290 290
         $localize['tax']                        = wpinv_tax_amount();
291 291
         $localize['discount']                   = wpinv_discount_amount();
292 292
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -294,60 +294,60 @@  discard block
 block discarded – undo
294 294
         $localize['thousand_sep']               = wpinv_thousands_separator();
295 295
         $localize['decimal_sep']                = wpinv_decimal_separator();
296 296
         $localize['decimals']                   = wpinv_decimals();
297
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
298
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
299
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
300
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
301
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
302
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
303
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
304
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
305
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
306
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
297
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
298
+        $localize['status_publish']             = wpinv_status_nicename('publish');
299
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
300
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
301
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
302
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
303
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
304
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
305
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
306
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
307 307
 
308
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
308
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
309 309
 
310
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
310
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
311 311
     }
312 312
     
313
-    public function admin_body_class( $classes ) {
313
+    public function admin_body_class($classes) {
314 314
         global $pagenow, $post, $current_screen;
315 315
         
316
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) {
316
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) {
317 317
             $classes .= ' wpinv-cpt';
318 318
         }
319 319
         
320
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
320
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
321 321
 
322 322
         $add_class = false;
323
-        if ( $pagenow == 'admin.php' && $page ) {
324
-            $add_class = strpos( $page, 'wpinv-' );
323
+        if ($pagenow == 'admin.php' && $page) {
324
+            $add_class = strpos($page, 'wpinv-');
325 325
         }
326 326
         
327 327
         $settings_class = array();
328
-        if ( $page == 'wpinv-settings' ) {
329
-            if ( !empty( $_REQUEST['tab'] ) ) {
330
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
328
+        if ($page == 'wpinv-settings') {
329
+            if (!empty($_REQUEST['tab'])) {
330
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
331 331
             }
332 332
             
333
-            if ( !empty( $_REQUEST['section'] ) ) {
334
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
333
+            if (!empty($_REQUEST['section'])) {
334
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
335 335
             }
336 336
             
337
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
337
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
338 338
         }
339 339
         
340
-        if ( !empty( $settings_class ) ) {
341
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
340
+        if (!empty($settings_class)) {
341
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
342 342
         }
343 343
         
344 344
         $post_type = wpinv_admin_post_type();
345 345
 
346
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
346
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
347 347
             return $classes .= ' wpinv';
348 348
         }
349 349
         
350
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
350
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
351 351
             $classes .= ' wpi-editable-n';
352 352
         }
353 353
 
@@ -359,20 +359,20 @@  discard block
 block discarded – undo
359 359
     }
360 360
     
361 361
     public function wpinv_actions() {
362
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
363
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
362
+        if (isset($_REQUEST['wpi_action'])) {
363
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
364 364
         }
365 365
     }
366 366
     
367
-    public function pre_get_posts( $wp_query ) {
368
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
369
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
367
+    public function pre_get_posts($wp_query) {
368
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
369
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
370 370
         }
371 371
         
372 372
         return $wp_query;
373 373
     }
374 374
     
375 375
     public function bp_invoicing_init() {
376
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
376
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
377 377
     }
378 378
 }
379 379
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -1,44 +1,44 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
22
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
23 23
         $is_recurring       = $invoice->is_recurring();
24 24
         $post_type_object   = get_post_type_object($invoice->post_type);
25 25
         $type_title         = $post_type_object->labels->singular_name;
26 26
         
27 27
         $cols = 5;
28
-        if ( $item_quantities ) {
28
+        if ($item_quantities) {
29 29
             $cols++;
30 30
         }
31
-        if ( $use_taxes ) {
31
+        if ($use_taxes) {
32 32
             $cols++;
33 33
         }
34 34
         $class = '';
35
-        if ( $invoice->is_paid() ) {
35
+        if ($invoice->is_paid()) {
36 36
             $class .= ' wpinv-paid';
37 37
         }
38
-        if ( $invoice->is_refunded() ) {
38
+        if ($invoice->is_refunded()) {
39 39
             $class .= ' wpinv-refunded';
40 40
         }
41
-        if ( $is_recurring ) {
41
+        if ($is_recurring) {
42 42
             $class .= ' wpi-recurring';
43 43
         }
44 44
         ?>
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
47 47
                 <thead>
48 48
                     <tr>
49
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
50
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
51
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
52
-                        <?php if ( $item_quantities ) { ?>
53
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
49
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
50
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
51
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
52
+                        <?php if ($item_quantities) { ?>
53
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
54 54
                         <?php } ?>
55
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
56
-                        <?php if ( $use_taxes ) { ?>
57
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
55
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
56
+                        <?php if ($use_taxes) { ?>
57
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
58 58
                         <?php } ?>
59 59
                         <th class="action"></th>
60 60
                     </tr>
61 61
                 </thead>
62 62
                 <tbody class="wpinv-line-items">
63
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
63
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
64 64
                 </tbody>
65 65
                 <tfoot class="wpinv-totals">
66 66
                     <tr>
@@ -72,44 +72,44 @@  discard block
 block discarded – undo
72 72
                                         </td>
73 73
                                         <td class="title">
74 74
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
75
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
75
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
76 76
                                             <div class="wp-clearfix">
77 77
                                                 <label class="wpi-vat-rule">
78
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
78
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
79 79
                                                     <span class="input-text-wrap">
80
-                                                        <?php echo wpinv_html_select( array(
80
+                                                        <?php echo wpinv_html_select(array(
81 81
                                                             'options'          => $wpinv_euvat->get_rules(),
82 82
                                                             'name'             => '_wpinv_quick[vat_rule]',
83 83
                                                             'id'               => '_wpinv_quick_vat_rule',
84 84
                                                             'show_option_all'  => false,
85 85
                                                             'show_option_none' => false,
86 86
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
87
-                                                        ) ); ?>
87
+                                                        )); ?>
88 88
                                                     </span>
89 89
                                                 </label>
90 90
                                             </div>
91
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
91
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
92 92
                                             <div class="wp-clearfix">
93 93
                                                 <label class="wpi-vat-class">
94
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
94
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
95 95
                                                     <span class="input-text-wrap">
96
-                                                        <?php echo wpinv_html_select( array(
96
+                                                        <?php echo wpinv_html_select(array(
97 97
                                                             'options'          => $wpinv_euvat->get_all_classes(),
98 98
                                                             'name'             => '_wpinv_quick[vat_class]',
99 99
                                                             'id'               => '_wpinv_quick_vat_class',
100 100
                                                             'show_option_all'  => false,
101 101
                                                             'show_option_none' => false,
102 102
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
103
-                                                        ) ); ?>
103
+                                                        )); ?>
104 104
                                                     </span>
105 105
                                                 </label>
106 106
                                             </div>
107 107
                                             <?php } ?>
108 108
                                             <div class="wp-clearfix">
109 109
                                                 <label class="wpi-item-type">
110
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
110
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
111 111
                                                     <span class="input-text-wrap">
112
-                                                        <?php echo wpinv_html_select( array(
112
+                                                        <?php echo wpinv_html_select(array(
113 113
                                                             'options'          => $item_types,
114 114
                                                             'name'             => '_wpinv_quick[type]',
115 115
                                                             'id'               => '_wpinv_quick_type',
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                                                             'show_option_all'  => false,
118 118
                                                             'show_option_none' => false,
119 119
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
120
-                                                        ) ); ?>
120
+                                                        )); ?>
121 121
                                                     </span>
122 122
                                                 </label>
123 123
                                             </div>
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
                                             </div>
131 131
                                         </td>
132 132
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
133
-                                        <?php if ( $item_quantities ) { ?>
133
+                                        <?php if ($item_quantities) { ?>
134 134
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
135 135
                                         <?php } ?>
136 136
                                         <td class="total"></td>
137
-                                        <?php if ( $use_taxes ) { ?>
137
+                                        <?php if ($use_taxes) { ?>
138 138
                                         <td class="tax"></td>
139 139
                                         <?php } ?>
140 140
                                         <td class="action"></td>
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
                         <td colspan="<?php echo $cols; ?>"></td>
148 148
                     </tr>
149 149
                     <tr class="totals">
150
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
150
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
151 151
                         <td colspan="4">
152 152
                             <table cellspacing="0" cellpadding="0">
153 153
                                 <tr class="subtotal">
154
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
155
-                                    <td class="total"><?php echo $subtotal;?></td>
154
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
155
+                                    <td class="total"><?php echo $subtotal; ?></td>
156 156
                                     <td class="action"></td>
157 157
                                 </tr>
158 158
                                 <tr class="discount">
159
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
160
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
159
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
160
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
161 161
                                     <td class="action"></td>
162 162
                                 </tr>
163
-                                <?php if ( $use_taxes ) { ?>
163
+                                <?php if ($use_taxes) { ?>
164 164
                                 <tr class="tax">
165
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
166
-                                    <td class="total"><?php echo $tax;?></td>
165
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
166
+                                    <td class="total"><?php echo $tax; ?></td>
167 167
                                     <td class="action"></td>
168 168
                                 </tr>
169 169
                                 <?php } ?>
170 170
                                 <tr class="total">
171
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
172
-                                    <td class="total"><?php echo $total;?></td>
171
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
172
+                                    <td class="total"><?php echo $total; ?></td>
173 173
                                     <td class="action"></td>
174 174
                                 </tr>
175 175
                             </table>
@@ -179,86 +179,86 @@  discard block
 block discarded – undo
179 179
             </table>
180 180
             <div class="wpinv-actions">
181 181
                 <?php
182
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
183
-                    if ( !$invoice->is_recurring() ) {
184
-                    echo wpinv_item_dropdown( array(
182
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
183
+                    if (!$invoice->is_recurring()) {
184
+                    echo wpinv_item_dropdown(array(
185 185
                         'name'             => 'wpinv_invoice_item',
186 186
                         'id'               => 'wpinv_invoice_item',
187 187
                         'show_recurring'   => true,
188
-                    ) );
188
+                    ));
189 189
                     ?>
190
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
190
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
191 191
                     <?php } ?>
192
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
192
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
193 193
             </div>
194 194
         </div>
195 195
         <?php
196 196
     }
197 197
     
198
-    public static function prices( $post ) {        
198
+    public static function prices($post) {        
199 199
         $symbol         = wpinv_currency_symbol();
200 200
         $position       = wpinv_currency_position();
201
-        $item           = new WPInv_Item( $post->ID );
201
+        $item           = new WPInv_Item($post->ID);
202 202
         
203 203
         $price          = $item->get_price();
204 204
         $is_recurring   = $item->is_recurring();
205 205
         $period         = $item->get_recurring_period();
206
-        $interval       = absint( $item->get_recurring_interval() );
207
-        $times          = absint( $item->get_recurring_limit() );
206
+        $interval       = absint($item->get_recurring_interval());
207
+        $times          = absint($item->get_recurring_limit());
208 208
         $free_trial     = $item->has_free_trial();
209 209
         $trial_interval = $item->get_trial_interval();
210 210
         $trial_period   = $item->get_trial_period();
211 211
         
212 212
         $intervals      = array();
213
-        for ( $i = 1; $i <= 90; $i++ ) {
213
+        for ($i = 1; $i <= 90; $i++) {
214 214
             $intervals[$i] = $i;
215 215
         }
216 216
         
217
-        $interval       = $interval > 0 ? $interval : 1;
217
+        $interval = $interval > 0 ? $interval : 1;
218 218
         
219 219
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
220 220
         ?>
221
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
222
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
221
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
222
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
223 223
         </p>
224 224
         <p class="wpinv-row-is-recurring">
225 225
             <label for="wpinv_is_recurring">
226
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
227
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
226
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
227
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
228 228
             </label>
229 229
         </p>
230
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
231
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
232
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
230
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
231
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
232
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
233 233
                     'options'          => $intervals,
234 234
                     'name'             => 'wpinv_recurring_interval',
235 235
                     'id'               => 'wpinv_recurring_interval',
236 236
                     'selected'         => $interval,
237 237
                     'show_option_all'  => false,
238 238
                     'show_option_none' => false
239
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
240
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
239
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
240
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
241 241
                 <span class="clear wpi-trial-clr"></span>
242 242
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
243
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
244
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
243
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
244
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
245 245
                 </label>
246 246
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
247
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
247
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
248 248
                 </label>
249 249
         </p>
250
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
251
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
250
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
251
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
252 252
         <?php
253 253
     }
254 254
     
255
-    public static function vat_rules( $post ) {
255
+    public static function vat_rules($post) {
256 256
         global $wpinv_euvat;
257 257
         
258
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
258
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
259 259
         ?>
260
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
261
-        <?php echo wpinv_html_select( array(
260
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
261
+        <?php echo wpinv_html_select(array(
262 262
                     'options'          => $wpinv_euvat->get_rules(),
263 263
                     'name'             => 'wpinv_vat_rules',
264 264
                     'id'               => 'wpinv_vat_rules',
@@ -266,19 +266,19 @@  discard block
 block discarded – undo
266 266
                     'show_option_all'  => false,
267 267
                     'show_option_none' => false,
268 268
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
269
-                ) ); ?>
269
+                )); ?>
270 270
         </p>
271
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
272
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
271
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
272
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
273 273
         <?php
274 274
     }
275 275
     
276
-    public static function vat_classes( $post ) {
276
+    public static function vat_classes($post) {
277 277
         global $wpinv_euvat;
278 278
         
279
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
279
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
280 280
         ?>
281
-        <p><?php echo wpinv_html_select( array(
281
+        <p><?php echo wpinv_html_select(array(
282 282
                     'options'          => $wpinv_euvat->get_all_classes(),
283 283
                     'name'             => 'wpinv_vat_class',
284 284
                     'id'               => 'wpinv_vat_class',
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
                     'show_option_all'  => false,
287 287
                     'show_option_none' => false,
288 288
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
289
-                ) ); ?>
289
+                )); ?>
290 290
         </p>
291
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
291
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
292 292
         <?php
293 293
     }
294 294
     
295
-    public static function item_info( $post ) {
296
-        $item_type = wpinv_get_item_type( $post->ID );
297
-        do_action( 'wpinv_item_info_metabox_before', $post );
295
+    public static function item_info($post) {
296
+        $item_type = wpinv_get_item_type($post->ID);
297
+        do_action('wpinv_item_info_metabox_before', $post);
298 298
         ?>
299
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
300
-        <?php echo wpinv_html_select( array(
299
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
300
+        <?php echo wpinv_html_select(array(
301 301
                     'options'          => wpinv_get_item_types(),
302 302
                     'name'             => 'wpinv_item_type',
303 303
                     'id'               => 'wpinv_item_type',
@@ -305,114 +305,114 @@  discard block
 block discarded – undo
305 305
                     'show_option_all'  => false,
306 306
                     'show_option_none' => false,
307 307
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
308
-                ) ); ?>
308
+                )); ?>
309 309
         </p>
310
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
310
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
311 311
         <?php
312
-        do_action( 'wpinv_item_info_metabox_after', $post );
312
+        do_action('wpinv_item_info_metabox_after', $post);
313 313
     }
314 314
     
315
-    public static function meta_values( $post ) {
316
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
315
+    public static function meta_values($post) {
316
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
317 317
             'type',
318 318
             'custom_id'
319
-        ) );
319
+        ));
320 320
         
321
-        if ( empty( $meta_keys ) ) {
321
+        if (empty($meta_keys)) {
322 322
             return;
323 323
         }
324 324
         
325
-        do_action( 'wpinv_meta_values_metabox_before', $post );
325
+        do_action('wpinv_meta_values_metabox_before', $post);
326 326
         
327
-        foreach ( $meta_keys as $meta_key ) {
327
+        foreach ($meta_keys as $meta_key) {
328 328
             ?>
329
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
329
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
330 330
             <?php 
331 331
         }
332 332
         
333
-        do_action( 'wpinv_meta_values_metabox_after', $post );
333
+        do_action('wpinv_meta_values_metabox_after', $post);
334 334
     }
335 335
     
336
-    public static function save( $post_id, $data, $post ) {
337
-        $invoice        = new WPInv_Invoice( $post_id );
336
+    public static function save($post_id, $data, $post) {
337
+        $invoice        = new WPInv_Invoice($post_id);
338 338
         
339 339
         // Billing
340
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
341
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
342
-        $company        = sanitize_text_field( $data['wpinv_company'] );
343
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
344
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
345
-        $address        = sanitize_text_field( $data['wpinv_address'] );
346
-        $city           = sanitize_text_field( $data['wpinv_city'] );
347
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
348
-        $country        = sanitize_text_field( $data['wpinv_country'] );
349
-        $state          = sanitize_text_field( $data['wpinv_state'] );
340
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
341
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
342
+        $company        = sanitize_text_field($data['wpinv_company']);
343
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
344
+        $phone          = sanitize_text_field($data['wpinv_phone']);
345
+        $address        = sanitize_text_field($data['wpinv_address']);
346
+        $city           = sanitize_text_field($data['wpinv_city']);
347
+        $zip            = sanitize_text_field($data['wpinv_zip']);
348
+        $country        = sanitize_text_field($data['wpinv_country']);
349
+        $state          = sanitize_text_field($data['wpinv_state']);
350 350
         
351 351
         // Details
352
-        $status         = sanitize_text_field( $data['wpinv_status'] );
353
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
354
-        $number         = sanitize_text_field( $data['wpinv_number'] );
355
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
352
+        $status         = sanitize_text_field($data['wpinv_status']);
353
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
354
+        $number         = sanitize_text_field($data['wpinv_number']);
355
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
356 356
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
357 357
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
358 358
         
359
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
359
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
360 360
         
361
-        $invoice->set( 'due_date', $due_date );
362
-        $invoice->set( 'first_name', $first_name );
363
-        $invoice->set( 'last_name', $last_name );
364
-        $invoice->set( 'company', $company );
365
-        $invoice->set( 'vat_number', $vat_number );
366
-        $invoice->set( 'phone', $phone );
367
-        $invoice->set( 'address', $address );
368
-        $invoice->set( 'city', $city );
369
-        $invoice->set( 'zip', $zip );
370
-        $invoice->set( 'country', $country );
371
-        $invoice->set( 'state', $state );
372
-        $invoice->set( 'status', $status );
361
+        $invoice->set('due_date', $due_date);
362
+        $invoice->set('first_name', $first_name);
363
+        $invoice->set('last_name', $last_name);
364
+        $invoice->set('company', $company);
365
+        $invoice->set('vat_number', $vat_number);
366
+        $invoice->set('phone', $phone);
367
+        $invoice->set('address', $address);
368
+        $invoice->set('city', $city);
369
+        $invoice->set('zip', $zip);
370
+        $invoice->set('country', $country);
371
+        $invoice->set('state', $state);
372
+        $invoice->set('status', $status);
373 373
         //$invoice->set( 'number', $number );
374 374
         //$invoice->set( 'discounts', $discounts );
375 375
         //$invoice->set( 'discount', $discount );
376
-        $invoice->set( 'ip', $ip );
376
+        $invoice->set('ip', $ip);
377 377
         $invoice->old_status = $_POST['original_post_status'];
378 378
         $invoice->currency = wpinv_get_currency();
379
-        if ( !empty( $data['wpinv_gateway'] ) ) {
380
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
379
+        if (!empty($data['wpinv_gateway'])) {
380
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
381 381
         }
382 382
         $saved = $invoice->save();
383 383
         
384 384
         // Check for payment notes
385
-        if ( !empty( $data['invoice_note'] ) ) {
386
-            $note               = wp_kses( $data['invoice_note'], array() );
387
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
385
+        if (!empty($data['invoice_note'])) {
386
+            $note               = wp_kses($data['invoice_note'], array());
387
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
388 388
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
389 389
         
390
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
390
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
391 391
         }
392 392
         
393 393
         // Update user address if empty.
394
-        if ( $saved && !empty( $invoice ) ) {
395
-            if ( $user_id = $invoice->get_user_id() ) {
396
-                $user_address = wpinv_get_user_address( $user_id, false );
394
+        if ($saved && !empty($invoice)) {
395
+            if ($user_id = $invoice->get_user_id()) {
396
+                $user_address = wpinv_get_user_address($user_id, false);
397 397
                 
398 398
                 if (empty($user_address['first_name'])) {
399
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
400
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
399
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
400
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
401 401
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
402
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
402
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
403 403
                 }
404 404
                 
405 405
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
406
-                    update_user_meta( $user_id, '_wpinv_address', $address );
407
-                    update_user_meta( $user_id, '_wpinv_city', $city );
408
-                    update_user_meta( $user_id, '_wpinv_state', $state );
409
-                    update_user_meta( $user_id, '_wpinv_country', $country );
410
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
411
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
406
+                    update_user_meta($user_id, '_wpinv_address', $address);
407
+                    update_user_meta($user_id, '_wpinv_city', $city);
408
+                    update_user_meta($user_id, '_wpinv_state', $state);
409
+                    update_user_meta($user_id, '_wpinv_country', $country);
410
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
411
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
412 412
                 }
413 413
             }
414 414
             
415
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
415
+            do_action('wpinv_invoice_metabox_saved', $invoice);
416 416
         }
417 417
         
418 418
         return $saved;
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-function wpinv_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,258 +72,258 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id );
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id);
86 86
 
87
-                    if ( !$allowed ) {
87
+                    if (!$allowed) {
88 88
                         continue;
89 89
                     }
90 90
 
91
-                    if ( $field == '_wpinv_price' ) {
92
-                        $value = wpinv_sanitize_amount( $_POST[ $name ] );
91
+                    if ($field == '_wpinv_price') {
92
+                        $value = wpinv_sanitize_amount($_POST[$name]);
93 93
                     } else {
94
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
94
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
95 95
                     }
96 96
                     
97
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
98
-                    update_post_meta( $post_id, $field, $value );
97
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
98
+                    update_post_meta($post_id, $field, $value);
99 99
                 }
100 100
             }
101 101
             
102
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
103
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
102
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
103
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
104 104
             }
105 105
         }
106 106
     }
107 107
 }
108
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
108
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
109 109
 
110 110
 function wpinv_register_item_meta_boxes() {    
111 111
     global $wpinv_euvat;
112 112
     
113
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
113
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
114 114
 
115
-    if ( $wpinv_euvat->allow_vat_rules() ) {
116
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
115
+    if ($wpinv_euvat->allow_vat_rules()) {
116
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
117 117
     }
118 118
     
119
-    if ( $wpinv_euvat->allow_vat_classes() ) {
120
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
119
+    if ($wpinv_euvat->allow_vat_classes()) {
120
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
121 121
     }
122 122
     
123
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
124
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
123
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
124
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
125 125
 }
126 126
 
127 127
 function wpinv_register_discount_meta_boxes() {
128
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
128
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
129 129
 }
130 130
 
131
-function wpinv_discount_metabox_details( $post ) {
131
+function wpinv_discount_metabox_details($post) {
132 132
     $discount_id    = $post->ID;
133
-    $discount       = wpinv_get_discount( $discount_id );
133
+    $discount       = wpinv_get_discount($discount_id);
134 134
     
135
-    $type           = wpinv_get_discount_type( $discount_id );
136
-    $item_reqs      = wpinv_get_discount_item_reqs( $discount_id );
137
-    $excluded_items = wpinv_get_discount_excluded_items( $discount_id );
138
-    $min_total      = wpinv_get_discount_min_total( $discount_id );
139
-    $max_total      = wpinv_get_discount_max_total( $discount_id );
140
-    $max_uses       = wpinv_get_discount_max_uses( $discount_id );
141
-    $single_use     = wpinv_discount_is_single_use( $discount_id );
142
-    $recurring      = (bool)wpinv_discount_is_recurring( $discount_id );
135
+    $type           = wpinv_get_discount_type($discount_id);
136
+    $item_reqs      = wpinv_get_discount_item_reqs($discount_id);
137
+    $excluded_items = wpinv_get_discount_excluded_items($discount_id);
138
+    $min_total      = wpinv_get_discount_min_total($discount_id);
139
+    $max_total      = wpinv_get_discount_max_total($discount_id);
140
+    $max_uses       = wpinv_get_discount_max_uses($discount_id);
141
+    $single_use     = wpinv_discount_is_single_use($discount_id);
142
+    $recurring      = (bool)wpinv_discount_is_recurring($discount_id);
143 143
     
144 144
     $min_total      = $min_total > 0 ? $min_total : '';
145 145
     $max_total      = $max_total > 0 ? $max_total : '';
146 146
     $max_uses       = $max_uses > 0 ? $max_uses : '';
147 147
 ?>
148
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
149
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
148
+<?php do_action('wpinv_discount_form_top', $post); ?>
149
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
150 150
 <table class="form-table wpi-form-table">
151 151
     <tbody>
152
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
153
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
152
+        <?php do_action('wpinv_discount_form_first', $post); ?>
153
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
154 154
         <tr>
155 155
             <th valign="top" scope="row">
156
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
156
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
157 157
             </th>
158 158
             <td>
159
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
160
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
159
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
160
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
161 161
             </td>
162 162
         </tr>
163
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
163
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
164 164
         <tr>
165 165
             <th valign="top" scope="row">
166
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
166
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
167 167
             </th>
168 168
             <td>
169 169
                 <select id="wpinv_discount_type" name="type" class="medium-text">
170
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
171
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
170
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
171
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
172 172
                     <?php } ?>
173 173
                 </select>
174
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
174
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
175 175
             </td>
176 176
         </tr>
177
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
177
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
178 178
         <tr>
179 179
             <th valign="top" scope="row">
180
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
180
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
181 181
             </th>
182 182
             <td>
183
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
184
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
185
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
183
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
184
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
185
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
186 186
             </td>
187 187
         </tr>
188
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
188
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
189 189
         <tr>
190 190
             <th valign="top" scope="row">
191
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
191
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
192 192
             </th>
193 193
             <td>
194
-                <p><?php echo wpinv_item_dropdown( array(
194
+                <p><?php echo wpinv_item_dropdown(array(
195 195
                         'name'              => 'items[]',
196 196
                         'id'                => 'items',
197 197
                         'selected'          => $item_reqs,
198 198
                         'multiple'          => true,
199 199
                         'chosen'            => true,
200 200
                         'class'             => 'medium-text',
201
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
201
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
202 202
                         'show_recurring'    => true,
203
-                    ) ); ?>
203
+                    )); ?>
204 204
                 </p>
205
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
205
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
206 206
             </td>
207 207
         </tr>
208
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
208
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
209 209
         <tr>
210 210
             <th valign="top" scope="row">
211
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
211
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
212 212
             </th>
213 213
             <td>
214
-                <p><?php echo wpinv_item_dropdown( array(
214
+                <p><?php echo wpinv_item_dropdown(array(
215 215
                         'name'              => 'excluded_items[]',
216 216
                         'id'                => 'excluded_items',
217 217
                         'selected'          => $excluded_items,
218 218
                         'multiple'          => true,
219 219
                         'chosen'            => true,
220 220
                         'class'             => 'medium-text',
221
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
221
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
222 222
                         'show_recurring'    => true,
223
-                    ) ); ?>
223
+                    )); ?>
224 224
                 </p>
225
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
225
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
226 226
             </td>
227 227
         </tr>
228
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
228
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
229 229
         <tr>
230 230
             <th valign="top" scope="row">
231
-                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
231
+                <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label>
232 232
             </th>
233 233
             <td>
234
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>">
235
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
234
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>">
235
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
236 236
             </td>
237 237
         </tr>
238
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
238
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
239 239
         <tr>
240 240
             <th valign="top" scope="row">
241
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
241
+                <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label>
242 242
             </th>
243 243
             <td>
244
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>">
245
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
244
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>">
245
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
246 246
             </td>
247 247
         </tr>
248
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
248
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
249 249
         <tr>
250 250
             <th valign="top" scope="row">
251
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
251
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
252 252
             </th>
253 253
             <td>
254 254
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
255
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
255
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
256 256
             </td>
257 257
         </tr>
258
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
258
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
259 259
         <tr>
260 260
             <th valign="top" scope="row">
261
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
261
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
262 262
             </th>
263 263
             <td>
264 264
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
265
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
265
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
266 266
             </td>
267 267
         </tr>
268
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
268
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
269 269
         <tr>
270 270
             <th valign="top" scope="row">
271
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
271
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
272 272
             </th>
273 273
             <td>
274 274
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
275
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
276
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
275
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
276
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
277 277
                 </select>
278
-                <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
278
+                <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
279 279
             </td>
280 280
         </tr>
281
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
281
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
282 282
         <tr>
283 283
             <th valign="top" scope="row">
284
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
284
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
285 285
             </th>
286 286
             <td>
287 287
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
288
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
288
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
289 289
             </td>
290 290
         </tr>
291
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
291
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
292 292
         <tr>
293 293
             <th valign="top" scope="row">
294
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
294
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
295 295
             </th>
296 296
             <td>
297
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
298
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
297
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
298
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
299 299
             </td>
300 300
         </tr>
301
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
301
+        <?php do_action('wpinv_discount_form_last', $post); ?>
302 302
     </tbody>
303 303
 </table>
304
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
304
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
305 305
     <?php
306 306
 }
307 307
 
308
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
309
-    $post_type = !empty( $post ) ? $post->post_type : '';
308
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
309
+    $post_type = !empty($post) ? $post->post_type : '';
310 310
     
311
-    if ( $post_type != 'wpi_discount' ) {
311
+    if ($post_type != 'wpi_discount') {
312 312
         return;
313 313
     }
314 314
     
315
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
315
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
316 316
         return;
317 317
     }
318 318
     
319
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
319
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
320 320
         return;
321 321
     }
322 322
     
323
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
323
+    if (!current_user_can('manage_options', $post_id)) {
324 324
         return;
325 325
     }
326 326
     
327
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
327
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
328 328
 }
329
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
330 329
\ No newline at end of file
330
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
331 331
\ No newline at end of file
Please login to merge, or discard this patch.