Passed
Pull Request — master (#47)
by Kiran
04:17
created
includes/class-wpinv-item.php 1 patch
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -33,26 +33,26 @@  discard block
 block discarded – undo
33 33
     public $filter;
34 34
 
35 35
 
36
-    public function __construct( $_id = false, $_args = array() ) {
37
-        $item = WP_Post::get_instance( $_id );
38
-        return $this->setup_item( $item );
36
+    public function __construct($_id = false, $_args = array()) {
37
+        $item = WP_Post::get_instance($_id);
38
+        return $this->setup_item($item);
39 39
     }
40 40
 
41
-    private function setup_item( $item ) {
42
-        if( ! is_object( $item ) ) {
41
+    private function setup_item($item) {
42
+        if (!is_object($item)) {
43 43
             return false;
44 44
         }
45 45
 
46
-        if( ! is_a( $item, 'WP_Post' ) ) {
46
+        if (!is_a($item, 'WP_Post')) {
47 47
             return false;
48 48
         }
49 49
 
50
-        if( 'wpi_item' !== $item->post_type ) {
50
+        if ('wpi_item' !== $item->post_type) {
51 51
             return false;
52 52
         }
53 53
 
54
-        foreach ( $item as $key => $value ) {
55
-            switch ( $key ) {
54
+        foreach ($item as $key => $value) {
55
+            switch ($key) {
56 56
                 default:
57 57
                     $this->$key = $value;
58 58
                     break;
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
         return true;
63 63
     }
64 64
 
65
-    public function __get( $key ) {
66
-        if ( method_exists( $this, 'get_' . $key ) ) {
67
-            return call_user_func( array( $this, 'get_' . $key ) );
65
+    public function __get($key) {
66
+        if (method_exists($this, 'get_' . $key)) {
67
+            return call_user_func(array($this, 'get_' . $key));
68 68
         } else {
69
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
69
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
70 70
         }
71 71
     }
72 72
 
73
-    public function create( $data = array(), $wp_error = false ) {
74
-        if ( $this->ID != 0 ) {
73
+    public function create($data = array(), $wp_error = false) {
74
+        if ($this->ID != 0) {
75 75
             return false;
76 76
         }
77 77
 
78 78
         $defaults = array(
79 79
             'post_type'   => 'wpi_item',
80 80
             'post_status' => 'draft',
81
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
81
+            'post_title'  => __('New Invoice Item', 'invoicing')
82 82
         );
83 83
 
84
-        $args = wp_parse_args( $data, $defaults );
84
+        $args = wp_parse_args($data, $defaults);
85 85
 
86
-        do_action( 'wpinv_item_pre_create', $args );
86
+        do_action('wpinv_item_pre_create', $args);
87 87
 
88
-        $id = wp_insert_post( $args, $wp_error );
88
+        $id = wp_insert_post($args, $wp_error);
89 89
         if ($wp_error && is_wp_error($id)) {
90 90
             return $id;
91 91
         }
92
-        if ( !$id ) {
92
+        if (!$id) {
93 93
             return false;
94 94
         }
95 95
         
96
-        $item = WP_Post::get_instance( $id );
96
+        $item = WP_Post::get_instance($id);
97 97
         
98 98
         if (!empty($item) && !empty($data['meta'])) {
99 99
             $this->ID = $item->ID;
@@ -101,47 +101,47 @@  discard block
 block discarded – undo
101 101
         }
102 102
         
103 103
         // Set custom id if not set.
104
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
105
-            $item->save_metas( array( 'custom_id' => $id ) );
104
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
105
+            $item->save_metas(array('custom_id' => $id));
106 106
         }
107 107
 
108
-        do_action( 'wpinv_item_create', $id, $args );
108
+        do_action('wpinv_item_create', $id, $args);
109 109
 
110
-        return $this->setup_item( $item );
110
+        return $this->setup_item($item);
111 111
     }
112 112
     
113
-    public function update( $data = array(), $wp_error = false ) {
114
-        if ( !$this->ID > 0 ) {
113
+    public function update($data = array(), $wp_error = false) {
114
+        if (!$this->ID > 0) {
115 115
             return false;
116 116
         }
117 117
         
118 118
         $data['ID'] = $this->ID;
119 119
 
120
-        do_action( 'wpinv_item_pre_update', $data );
120
+        do_action('wpinv_item_pre_update', $data);
121 121
         
122
-        $id = wp_update_post( $data, $wp_error );
122
+        $id = wp_update_post($data, $wp_error);
123 123
         if ($wp_error && is_wp_error($id)) {
124 124
             return $id;
125 125
         }
126 126
         
127
-        if ( !$id ) {
127
+        if (!$id) {
128 128
             return false;
129 129
         }
130 130
 
131
-        $item = WP_Post::get_instance( $id );
131
+        $item = WP_Post::get_instance($id);
132 132
         if (!empty($item) && !empty($data['meta'])) {
133 133
             $this->ID = $item->ID;
134 134
             $this->save_metas($data['meta']);
135 135
         }
136 136
         
137 137
         // Set custom id if not set.
138
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
139
-            $item->save_metas( array( 'custom_id' => $id ) );
138
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
139
+            $item->save_metas(array('custom_id' => $id));
140 140
         }
141 141
 
142
-        do_action( 'wpinv_item_update', $id, $data );
142
+        do_action('wpinv_item_update', $id, $data);
143 143
 
144
-        return $this->setup_item( $item );
144
+        return $this->setup_item($item);
145 145
     }
146 146
 
147 147
     public function get_ID() {
@@ -149,105 +149,105 @@  discard block
 block discarded – undo
149 149
     }
150 150
 
151 151
     public function get_name() {
152
-        return get_the_title( $this->ID );
152
+        return get_the_title($this->ID);
153 153
     }
154 154
     
155 155
     public function get_summary() {
156
-        return get_the_excerpt( $this->ID );
156
+        return get_the_excerpt($this->ID);
157 157
     }
158 158
 
159 159
     public function get_price() {
160
-        if ( ! isset( $this->price ) ) {
161
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
160
+        if (!isset($this->price)) {
161
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
162 162
             
163
-            if ( $this->price ) {
164
-                $this->price = wpinv_sanitize_amount( $this->price );
163
+            if ($this->price) {
164
+                $this->price = wpinv_sanitize_amount($this->price);
165 165
             } else {
166 166
                 $this->price = 0;
167 167
             }
168 168
         }
169 169
         
170
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
170
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
171 171
     }
172 172
     
173 173
     public function get_the_price() {
174
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
174
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
175 175
         
176
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
176
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
177 177
     }
178 178
     
179 179
     public function get_vat_rule() {
180 180
         global $wpinv_euvat;
181 181
         
182
-        if( !isset( $this->vat_rule ) ) {
183
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
182
+        if (!isset($this->vat_rule)) {
183
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
184 184
 
185
-            if ( empty( $this->vat_rule ) ) {        
185
+            if (empty($this->vat_rule)) {        
186 186
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
187 187
             }
188 188
         }
189 189
         
190
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
190
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
191 191
     }
192 192
     
193 193
     public function get_vat_class() {
194
-        if( !isset( $this->vat_class ) ) {
195
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
194
+        if (!isset($this->vat_class)) {
195
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
196 196
 
197
-            if ( empty( $this->vat_class ) ) {        
197
+            if (empty($this->vat_class)) {        
198 198
                 $this->vat_class = '_standard';
199 199
             }
200 200
         }
201 201
         
202
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
202
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
203 203
     }
204 204
 
205 205
     public function get_type() {
206
-        if( ! isset( $this->type ) ) {
207
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
206
+        if (!isset($this->type)) {
207
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
208 208
 
209
-            if ( empty( $this->type ) ) {
209
+            if (empty($this->type)) {
210 210
                 $this->type = 'custom';
211 211
             }
212 212
         }
213 213
 
214
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
214
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
215 215
     }
216 216
     
217 217
     public function get_custom_id() {
218
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
218
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
219 219
 
220
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
220
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
221 221
     }
222 222
     
223 223
     public function get_custom_name() {
224
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
224
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
225 225
 
226
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
226
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
227 227
     }
228 228
     
229 229
     public function get_custom_singular_name() {
230
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
230
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
231 231
 
232
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
232
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
233 233
     }
234 234
     
235 235
     public function is_recurring() {
236
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
236
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
237 237
 
238
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
238
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
239 239
 
240 240
     }
241 241
     
242
-    public function get_recurring_period( $full = false ) {
243
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
242
+    public function get_recurring_period($full = false) {
243
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
244 244
         
245
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
245
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
246 246
             $period = 'D';
247 247
         }
248 248
         
249
-        if ( $full ) {
250
-            switch( $period ) {
249
+        if ($full) {
250
+            switch ($period) {
251 251
                 case 'D':
252 252
                     $period = 'day';
253 253
                 break;
@@ -263,45 +263,45 @@  discard block
 block discarded – undo
263 263
             }
264 264
         }
265 265
 
266
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
266
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
267 267
 
268 268
     }
269 269
     
270 270
     public function get_recurring_interval() {
271
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
271
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
272 272
         
273
-        if ( !$interval > 0 ) {
273
+        if (!$interval > 0) {
274 274
             $interval = 1;
275 275
         }
276 276
 
277
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
277
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
278 278
 
279 279
     }
280 280
     
281 281
     public function get_recurring_limit() {
282
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
282
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
283 283
 
284
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
284
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
285 285
 
286 286
     }
287 287
     
288 288
     public function has_free_trial() {
289
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
290
-        $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false;
289
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
290
+        $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false;
291 291
 
292
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
292
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
293 293
 
294 294
     }
295 295
     
296
-    public function get_trial_period( $full = false ) {
297
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
296
+    public function get_trial_period($full = false) {
297
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
298 298
         
299
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
299
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
300 300
             $period = 'D';
301 301
         }
302 302
         
303
-        if ( $full ) {
304
-            switch( $period ) {
303
+        if ($full) {
304
+            switch ($period) {
305 305
                 case 'D':
306 306
                     $period = 'day';
307 307
                 break;
@@ -317,47 +317,47 @@  discard block
 block discarded – undo
317 317
             }
318 318
         }
319 319
 
320
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
320
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
321 321
 
322 322
     }
323 323
     
324 324
     public function get_trial_interval() {
325
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
325
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
326 326
         
327
-        if ( !$interval > 0 ) {
327
+        if (!$interval > 0) {
328 328
             $interval = 1;
329 329
         }
330 330
 
331
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
331
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
332 332
 
333 333
     }
334 334
 
335 335
     public function is_free() {
336 336
         $is_free = false;
337 337
         
338
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
338
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
339 339
 
340
-        if ( (float)$price == 0 ) {
340
+        if ((float)$price == 0) {
341 341
             $is_free = true;
342 342
         }
343 343
 
344
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
344
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
345 345
 
346 346
     }
347 347
     
348 348
     public function is_package() {
349 349
         $is_package = $this->get_type() == 'package' ? true : false;
350 350
 
351
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
351
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
352 352
 
353 353
     }
354 354
     
355
-    public function save_metas( $metas = array() ) {
356
-        if ( empty( $metas ) ) {
355
+    public function save_metas($metas = array()) {
356
+        if (empty($metas)) {
357 357
             return false;
358 358
         }
359 359
         
360
-        foreach ( $metas as $meta_key => $meta_value ) {
360
+        foreach ($metas as $meta_key => $meta_value) {
361 361
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
362 362
             
363 363
             $this->update_meta($meta_key, $meta_value);
@@ -366,66 +366,66 @@  discard block
 block discarded – undo
366 366
         return true;
367 367
     }
368 368
 
369
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
370
-        if ( empty( $meta_key ) ) {
369
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
370
+        if (empty($meta_key)) {
371 371
             return false;
372 372
         }
373 373
         
374
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
374
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
375 375
 
376
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
376
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
377 377
     }
378 378
     
379
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
379
+    public function get_fees($type = 'fee', $item_id = 0) {
380 380
         global $wpi_session;
381 381
         
382
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
382
+        $fees = $wpi_session->get('wpi_cart_fees');
383 383
 
384
-        if ( ! wpinv_get_cart_contents() ) {
384
+        if (!wpinv_get_cart_contents()) {
385 385
             // We can only get item type fees when the cart is empty
386 386
             $type = 'custom';
387 387
         }
388 388
 
389
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
390
-            foreach( $fees as $key => $fee ) {
391
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
392
-                    unset( $fees[ $key ] );
389
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
390
+            foreach ($fees as $key => $fee) {
391
+                if (!empty($fee['type']) && $type != $fee['type']) {
392
+                    unset($fees[$key]);
393 393
                 }
394 394
             }
395 395
         }
396 396
 
397
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
397
+        if (!empty($fees) && !empty($item_id)) {
398 398
             // Remove fees that don't belong to the specified Item
399
-            foreach ( $fees as $key => $fee ) {
400
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
401
-                    unset( $fees[ $key ] );
399
+            foreach ($fees as $key => $fee) {
400
+                if ((int)$item_id !== (int)$fee['custom_id']) {
401
+                    unset($fees[$key]);
402 402
                 }
403 403
             }
404 404
         }
405 405
 
406
-        if ( ! empty( $fees ) ) {
406
+        if (!empty($fees)) {
407 407
             // Remove fees that belong to a specific item but are not in the cart
408
-            foreach( $fees as $key => $fee ) {
409
-                if( empty( $fee['custom_id'] ) ) {
408
+            foreach ($fees as $key => $fee) {
409
+                if (empty($fee['custom_id'])) {
410 410
                     continue;
411 411
                 }
412 412
 
413
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
414
-                    unset( $fees[ $key ] );
413
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
414
+                    unset($fees[$key]);
415 415
                 }
416 416
             }
417 417
         }
418 418
 
419
-        return ! empty( $fees ) ? $fees : array();
419
+        return !empty($fees) ? $fees : array();
420 420
     }
421 421
     
422 422
     public function can_purchase() {
423 423
         $can_purchase = true;
424 424
 
425
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
425
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
426 426
             $can_purchase = false;
427 427
         }
428 428
 
429
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
429
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
430 430
     }
431 431
 }
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,195 +7,195 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool)apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65
-function wpinv_send_to_success_page( $args = null ) {
65
+function wpinv_send_to_success_page($args = null) {
66 66
 	$redirect = wpinv_get_success_page_uri();
67 67
     
68
-    if ( !empty( $args ) ) {
68
+    if (!empty($args)) {
69 69
         // Check for backward compatibility
70
-        if ( is_string( $args ) )
71
-            $args = str_replace( '?', '', $args );
70
+        if (is_string($args))
71
+            $args = str_replace('?', '', $args);
72 72
 
73
-        $args = wp_parse_args( $args );
73
+        $args = wp_parse_args($args);
74 74
 
75
-        $redirect = add_query_arg( $args, $redirect );
75
+        $redirect = add_query_arg($args, $redirect);
76 76
     }
77 77
 
78
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
78
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
79 79
     
80
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
81
-    wp_redirect( $redirect );
80
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
81
+    wp_redirect($redirect);
82 82
     exit;
83 83
 }
84 84
 
85
-function wpinv_send_to_failed_page( $args = null ) {
85
+function wpinv_send_to_failed_page($args = null) {
86 86
 	$redirect = wpinv_get_failed_transaction_uri();
87 87
     
88
-    if ( !empty( $args ) ) {
88
+    if (!empty($args)) {
89 89
         // Check for backward compatibility
90
-        if ( is_string( $args ) )
91
-            $args = str_replace( '?', '', $args );
90
+        if (is_string($args))
91
+            $args = str_replace('?', '', $args);
92 92
 
93
-        $args = wp_parse_args( $args );
93
+        $args = wp_parse_args($args);
94 94
 
95
-        $redirect = add_query_arg( $args, $redirect );
95
+        $redirect = add_query_arg($args, $redirect);
96 96
     }
97 97
 
98
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
98
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
99 99
     
100
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
101
-    wp_redirect( $redirect );
100
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
101
+    wp_redirect($redirect);
102 102
     exit;
103 103
 }
104 104
 
105
-function wpinv_get_checkout_uri( $args = array() ) {
106
-	$uri = wpinv_get_option( 'checkout_page', false );
107
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
105
+function wpinv_get_checkout_uri($args = array()) {
106
+	$uri = wpinv_get_option('checkout_page', false);
107
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
108 108
 
109
-	if ( !empty( $args ) ) {
109
+	if (!empty($args)) {
110 110
 		// Check for backward compatibility
111
-		if ( is_string( $args ) )
112
-			$args = str_replace( '?', '', $args );
111
+		if (is_string($args))
112
+			$args = str_replace('?', '', $args);
113 113
 
114
-		$args = wp_parse_args( $args );
114
+		$args = wp_parse_args($args);
115 115
 
116
-		$uri = add_query_arg( $args, $uri );
116
+		$uri = add_query_arg($args, $uri);
117 117
 	}
118 118
 
119
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
119
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
120 120
 
121
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
121
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
122 122
 
123
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
124
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
123
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
124
+		$uri = preg_replace('/^http:/', 'https:', $uri);
125 125
 	}
126 126
 
127
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
127
+	return apply_filters('wpinv_get_checkout_uri', $uri);
128 128
 }
129 129
 
130
-function wpinv_send_back_to_checkout( $args = array() ) {
130
+function wpinv_send_back_to_checkout($args = array()) {
131 131
 	$redirect = wpinv_get_checkout_uri();
132 132
 
133
-	if ( ! empty( $args ) ) {
133
+	if (!empty($args)) {
134 134
 		// Check for backward compatibility
135
-		if ( is_string( $args ) )
136
-			$args = str_replace( '?', '', $args );
135
+		if (is_string($args))
136
+			$args = str_replace('?', '', $args);
137 137
 
138
-		$args = wp_parse_args( $args );
138
+		$args = wp_parse_args($args);
139 139
 
140
-		$redirect = add_query_arg( $args, $redirect );
140
+		$redirect = add_query_arg($args, $redirect);
141 141
 	}
142 142
 
143
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
143
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
144 144
 	exit;
145 145
 }
146 146
 
147
-function wpinv_get_success_page_url( $query_string = null ) {
148
-	$success_page = wpinv_get_option( 'success_page', 0 );
149
-	$success_page = get_permalink( $success_page );
147
+function wpinv_get_success_page_url($query_string = null) {
148
+	$success_page = wpinv_get_option('success_page', 0);
149
+	$success_page = get_permalink($success_page);
150 150
 
151
-	if ( $query_string )
151
+	if ($query_string)
152 152
 		$success_page .= $query_string;
153 153
 
154
-	return apply_filters( 'wpinv_success_page_url', $success_page );
154
+	return apply_filters('wpinv_success_page_url', $success_page);
155 155
 }
156 156
 
157
-function wpinv_get_failed_transaction_uri( $extras = false ) {
158
-	$uri = wpinv_get_option( 'failure_page', '' );
159
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
157
+function wpinv_get_failed_transaction_uri($extras = false) {
158
+	$uri = wpinv_get_option('failure_page', '');
159
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
160 160
 
161
-	if ( $extras )
161
+	if ($extras)
162 162
 		$uri .= $extras;
163 163
 
164
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
164
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
165 165
 }
166 166
 
167 167
 function wpinv_is_failed_transaction_page() {
168
-	$ret = wpinv_get_option( 'failure_page', false );
169
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
168
+	$ret = wpinv_get_option('failure_page', false);
169
+	$ret = isset($ret) ? is_page($ret) : false;
170 170
 
171
-	return apply_filters( 'wpinv_is_failure_page', $ret );
171
+	return apply_filters('wpinv_is_failure_page', $ret);
172 172
 }
173 173
 
174
-function wpinv_transaction_query( $type = 'start' ) {
174
+function wpinv_transaction_query($type = 'start') {
175 175
     global $wpdb;
176 176
 
177 177
     $wpdb->hide_errors();
178 178
 
179
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
180
-        define( 'WPINV_USE_TRANSACTIONS', true );
179
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
180
+        define('WPINV_USE_TRANSACTIONS', true);
181 181
     }
182 182
 
183
-    if ( WPINV_USE_TRANSACTIONS ) {
184
-        switch ( $type ) {
183
+    if (WPINV_USE_TRANSACTIONS) {
184
+        switch ($type) {
185 185
             case 'commit' :
186
-                $wpdb->query( 'COMMIT' );
186
+                $wpdb->query('COMMIT');
187 187
                 break;
188 188
             case 'rollback' :
189
-                $wpdb->query( 'ROLLBACK' );
189
+                $wpdb->query('ROLLBACK');
190 190
                 break;
191 191
             default :
192
-                $wpdb->query( 'START TRANSACTION' );
192
+                $wpdb->query('START TRANSACTION');
193 193
             break;
194 194
         }
195 195
     }
196 196
 }
197 197
 
198
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
198
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
199 199
     $default_args = array(
200 200
         'status'        => '',
201 201
         'user_id'       => null,
@@ -205,72 +205,72 @@  discard block
 block discarded – undo
205 205
         'parent'        => 0
206 206
     );
207 207
 
208
-    $args           = wp_parse_args( $args, $default_args );
208
+    $args           = wp_parse_args($args, $default_args);
209 209
     $invoice_data   = array();
210 210
 
211
-    if ( $args['invoice_id'] > 0 ) {
212
-        $updating           = true;
211
+    if ($args['invoice_id'] > 0) {
212
+        $updating = true;
213 213
         $invoice_data['post_type']  = 'wpi_invoice';
214 214
         $invoice_data['ID']         = $args['invoice_id'];
215 215
     } else {
216 216
         $updating                       = false;
217 217
         $invoice_data['post_type']      = 'wpi_invoice';
218
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'pending' );
218
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'pending');
219 219
         $invoice_data['ping_status']    = 'closed';
220
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
221
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
222
-        $invoice_data['post_parent']    = absint( $args['parent'] );
223
-        if ( !empty( $args['created_date'] ) ) {
220
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
221
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
222
+        $invoice_data['post_parent']    = absint($args['parent']);
223
+        if (!empty($args['created_date'])) {
224 224
             $invoice_data['post_date']      = $args['created_date'];
225
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
225
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
226 226
         }
227 227
     }
228 228
 
229
-    if ( $args['status'] ) {
230
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) {
231
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
229
+    if ($args['status']) {
230
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) {
231
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
232 232
         }
233
-        $invoice_data['post_status']    = $args['status'];
233
+        $invoice_data['post_status'] = $args['status'];
234 234
     }
235 235
 
236
-    if ( ! is_null( $args['user_note'] ) ) {
237
-        $invoice_data['post_excerpt']   = $args['user_note'];
236
+    if (!is_null($args['user_note'])) {
237
+        $invoice_data['post_excerpt'] = $args['user_note'];
238 238
     }
239 239
 
240
-    if ( $updating ) {
241
-        $invoice_id = wp_update_post( $invoice_data, true );
240
+    if ($updating) {
241
+        $invoice_id = wp_update_post($invoice_data, true);
242 242
     } else {
243
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
243
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
244 244
     }
245 245
 
246
-    if ( is_wp_error( $invoice_id ) ) {
246
+    if (is_wp_error($invoice_id)) {
247 247
         return $wp_error ? $invoice_id : 0;
248 248
     } else {
249
-        if ( !$updating ) {
250
-            $invoice_number = wpinv_format_invoice_number( $invoice_id );
249
+        if (!$updating) {
250
+            $invoice_number = wpinv_format_invoice_number($invoice_id);
251 251
             
252
-            $update = array( 'ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title( $invoice_number ) );
253
-            wp_update_post( $update );
252
+            $update = array('ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title($invoice_number));
253
+            wp_update_post($update);
254 254
             
255
-            update_post_meta( $invoice_id, '_wpinv_number', $invoice_number );
255
+            update_post_meta($invoice_id, '_wpinv_number', $invoice_number);
256 256
         }
257 257
     }
258 258
     
259
-    $invoice = wpinv_get_invoice( $invoice_id );
260
-
261
-    if ( !$updating ) {
262
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
263
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
264
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
265
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
266
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
267
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
259
+    $invoice = wpinv_get_invoice($invoice_id);
260
+
261
+    if (!$updating) {
262
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
263
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
264
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
265
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
266
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
267
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
268 268
         
269 269
         // Add invoice note
270
-        $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
270
+        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
271 271
     }
272 272
 
273
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
273
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
274 274
 
275 275
     return $invoice;
276 276
 }
@@ -278,118 +278,118 @@  discard block
 block discarded – undo
278 278
 function wpinv_get_prefix() {
279 279
     $invoice_prefix = 'INV-';
280 280
     
281
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
281
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
282 282
 }
283 283
 
284 284
 function wpinv_get_business_logo() {
285
-    $business_logo = wpinv_get_option( 'logo' );
286
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
285
+    $business_logo = wpinv_get_option('logo');
286
+    return apply_filters('wpinv_get_business_logo', $business_logo);
287 287
 }
288 288
 
289 289
 function wpinv_get_business_name() {
290 290
     $business_name = wpinv_get_option('store_name');
291
-    return apply_filters( 'wpinv_get_business_name', $business_name );
291
+    return apply_filters('wpinv_get_business_name', $business_name);
292 292
 }
293 293
 
294 294
 function wpinv_get_blogname() {
295
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
295
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
296 296
 }
297 297
 
298 298
 function wpinv_get_admin_email() {
299
-    $admin_email = get_option( 'admin_email' );
300
-    return apply_filters( 'wpinv_admin_email', $admin_email );
299
+    $admin_email = get_option('admin_email');
300
+    return apply_filters('wpinv_admin_email', $admin_email);
301 301
 }
302 302
 
303 303
 function wpinv_get_business_website() {
304
-    $business_website = home_url( '/' );
305
-    return apply_filters( 'wpinv_get_business_website', $business_website );
304
+    $business_website = home_url('/');
305
+    return apply_filters('wpinv_get_business_website', $business_website);
306 306
 }
307 307
 
308
-function wpinv_get_terms_text( $invoice_id = 0 ) {
308
+function wpinv_get_terms_text($invoice_id = 0) {
309 309
     $terms_text = '';
310
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
310
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
311 311
 }
312 312
 
313 313
 function wpinv_get_business_footer() {
314
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
315
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
316
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
314
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
315
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
316
+    return apply_filters('wpinv_get_business_footer', $business_footer);
317 317
 }
318 318
 
319 319
 function wpinv_checkout_required_fields() {
320 320
     $required_fields = array();
321 321
     
322 322
     // Let payment gateways and other extensions determine if address fields should be required
323
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
323
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
324 324
     
325
-    if ( $require_billing_details ) {
325
+    if ($require_billing_details) {
326 326
         ///$required_fields['email'] = array(
327 327
                 ///'error_id' => 'invalid_email',
328 328
                 ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )
329 329
             ///);
330 330
         $required_fields['first_name'] = array(
331 331
                 'error_id' => 'invalid_first_name',
332
-                'error_message' => __( 'Please enter your first name', 'invoicing' )
332
+                'error_message' => __('Please enter your first name', 'invoicing')
333 333
             );
334 334
         $required_fields['address'] = array(
335 335
                 'error_id' => 'invalid_address',
336
-                'error_message' => __( 'Please enter your address', 'invoicing' )
336
+                'error_message' => __('Please enter your address', 'invoicing')
337 337
             );
338 338
         $required_fields['city'] = array(
339 339
                 'error_id' => 'invalid_city',
340
-                'error_message' => __( 'Please enter your billing city', 'invoicing' )
340
+                'error_message' => __('Please enter your billing city', 'invoicing')
341 341
             );
342 342
         $required_fields['state'] = array(
343 343
                 'error_id' => 'invalid_state',
344
-                'error_message' => __( 'Please enter billing state / province', 'invoicing' )
344
+                'error_message' => __('Please enter billing state / province', 'invoicing')
345 345
             );
346 346
         $required_fields['country'] = array(
347 347
                 'error_id' => 'invalid_country',
348
-                'error_message' => __( 'Please select your billing country', 'invoicing' )
348
+                'error_message' => __('Please select your billing country', 'invoicing')
349 349
             );
350 350
     }
351 351
 
352
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
352
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
353 353
 }
354 354
 
355 355
 function wpinv_is_ssl_enforced() {
356
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
357
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
356
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
357
+    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
358 358
 }
359 359
 
360
-function wpinv_user_can_print_invoice( $post ) {
360
+function wpinv_user_can_print_invoice($post) {
361 361
     $allow = false;
362 362
     
363
-    if ( !( $user_id = get_current_user_id() ) ) {
363
+    if (!($user_id = get_current_user_id())) {
364 364
         return $allow;
365 365
     }
366 366
     
367
-    if ( is_int( $post ) ) {
368
-        $post = get_post( $post );
367
+    if (is_int($post)) {
368
+        $post = get_post($post);
369 369
     }
370 370
     
371 371
     // Allow to owner.
372
-    if ( is_object( $post ) && !empty( $post->post_author ) && $post->post_author == $user_id ) {
372
+    if (is_object($post) && !empty($post->post_author) && $post->post_author == $user_id) {
373 373
         $allow = true;
374 374
     }
375 375
     
376 376
     // Allow to admin user.
377
-    if ( current_user_can( 'manage_options' ) ) {
377
+    if (current_user_can('manage_options')) {
378 378
         $allow = true;
379 379
     }
380 380
     
381
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post );
381
+    return apply_filters('wpinv_can_print_invoice', $allow, $post);
382 382
 }
383 383
 
384 384
 function wpinv_schedule_events() {
385 385
     // hourly, daily and twicedaily
386
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
387
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
386
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
387
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
388 388
     }
389 389
 }
390
-add_action( 'wp', 'wpinv_schedule_events' );
390
+add_action('wp', 'wpinv_schedule_events');
391 391
 
392 392
 function wpinv_schedule_event_twicedaily() {
393 393
     wpinv_email_payment_reminders();
394 394
 }
395
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
396 395
\ No newline at end of file
396
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
397 397
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 1 patch
Spacing   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  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
 function wpinv_gd_active() {
8
-    return (bool)defined( 'GEODIRECTORY_VERSION' );
8
+    return (bool)defined('GEODIRECTORY_VERSION');
9 9
 }
10 10
 
11 11
 function wpinv_pm_active() {
12
-    return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' );
12
+    return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION');
13 13
 }
14 14
 
15
-function wpinv_is_gd_post_type( $post_type ) {
15
+function wpinv_is_gd_post_type($post_type) {
16 16
     global $gd_posttypes;
17 17
     
18
-    $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes();
18
+    $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes();
19 19
     
20
-    if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) {
20
+    if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) {
21 21
         return true;
22 22
     }
23 23
     
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
         return;
30 30
     }
31 31
     
32
-    if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
32
+    if (!(defined('DOING_AJAX') && DOING_AJAX)) {
33 33
         // Add  fields for force upgrade
34
-        if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) {
35
-            geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' );
34
+        if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) {
35
+            geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0');
36 36
             
37 37
             update_option('wpinv_gdp_column', '1');
38 38
         }
@@ -40,39 +40,39 @@  discard block
 block discarded – undo
40 40
         wpinv_merge_gd_packages_to_items();
41 41
     }
42 42
 }
43
-add_action( 'admin_init', 'wpinv_geodir_integration' );
43
+add_action('admin_init', 'wpinv_geodir_integration');
44 44
 
45
-function wpinv_get_gdp_package_type( $item_types ) {
46
-    if ( wpinv_pm_active() ) {
47
-        $item_types['package'] = __( 'Package', 'invoicing' );
45
+function wpinv_get_gdp_package_type($item_types) {
46
+    if (wpinv_pm_active()) {
47
+        $item_types['package'] = __('Package', 'invoicing');
48 48
     }
49 49
         
50 50
     return $item_types;
51 51
 }
52
-add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 );
52
+add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1);
53 53
 
54 54
 function wpinv_update_package_item($package_id) {
55 55
     return wpinv_merge_gd_package_to_item($package_id, true);
56 56
 }
57 57
 add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1);
58 58
 
59
-function wpinv_merge_gd_packages_to_items( $force = false ) {    
60
-    if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) {
59
+function wpinv_merge_gd_packages_to_items($force = false) {    
60
+    if ($merged = get_option('wpinv_merge_gd_packages') && !$force) {
61 61
         return true;
62 62
     }
63 63
 
64
-    if(!function_exists('geodir_package_list_info')){
64
+    if (!function_exists('geodir_package_list_info')) {
65 65
         return false;
66 66
     }
67 67
     
68 68
     $packages = geodir_package_list_info();
69 69
     
70
-    foreach ( $packages as $key => $package ) {
71
-        wpinv_merge_gd_package_to_item( $package->pid, $force, $package );
70
+    foreach ($packages as $key => $package) {
71
+        wpinv_merge_gd_package_to_item($package->pid, $force, $package);
72 72
     }
73 73
     
74
-    if ( !$merged ) {
75
-        update_option( 'wpinv_merge_gd_packages', 1 );
74
+    if (!$merged) {
75
+        update_option('wpinv_merge_gd_packages', 1);
76 76
     }
77 77
     
78 78
     return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package;
103 103
 
104
-    if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) {
104
+    if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) {
105 105
         return false;
106 106
     }
107 107
         
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
     $meta['custom_id']              = $package_id;
111 111
     $meta['custom_singular_name']   = get_post_type_singular_label($package->post_type);
112 112
     $meta['custom_name']            = get_post_type_plural_label($package->post_type);
113
-    $meta['price']                  = wpinv_round_amount( $package->amount );
113
+    $meta['price']                  = wpinv_round_amount($package->amount);
114 114
     $meta['vat_rule']               = 'digital';
115 115
     $meta['vat_class']              = '_standard';
116 116
     
117
-    if ( !empty( $package->sub_active ) ) {
118
-        $sub_num_trial_days = absint( $package->sub_num_trial_days );
117
+    if (!empty($package->sub_active)) {
118
+        $sub_num_trial_days = absint($package->sub_num_trial_days);
119 119
         
120 120
         $meta['is_recurring']       = 1;
121 121
         $meta['recurring_period']   = $package->sub_units;
122
-        $meta['recurring_interval'] = absint( $package->sub_units_num );
123
-        $meta['recurring_limit']    = absint( $package->sub_units_num_times );
122
+        $meta['recurring_interval'] = absint($package->sub_units_num);
123
+        $meta['recurring_limit']    = absint($package->sub_units_num_times);
124 124
         $meta['free_trial']         = $sub_num_trial_days > 0 ? 1 : 0;
125 125
         $meta['trial_period']       = $package->sub_num_trial_units;
126 126
         $meta['trial_interval']     = $sub_num_trial_days;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $meta['trial_interval']     = '';
135 135
     }
136 136
     
137
-    $data  = array( 
137
+    $data = array( 
138 138
         'post_title'    => $package->title,
139 139
         'post_excerpt'  => $package->title_desc,
140 140
         'post_status'   => $package->status == 1 ? 'publish' : 'pending',
@@ -151,48 +151,48 @@  discard block
 block discarded – undo
151 151
     return $item;
152 152
 }
153 153
 
154
-function wpinv_gdp_to_wpi_gateway( $payment_method ) {
155
-    switch( $payment_method ) {
154
+function wpinv_gdp_to_wpi_gateway($payment_method) {
155
+    switch ($payment_method) {
156 156
         case 'prebanktransfer':
157 157
             $gateway = 'bank_transfer';
158 158
         break;
159 159
         default:
160
-            $gateway = empty( $payment_method ) ? 'manual' : $payment_method;
160
+            $gateway = empty($payment_method) ? 'manual' : $payment_method;
161 161
         break;
162 162
     }
163 163
     
164
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method );
164
+    return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method);
165 165
 }
166 166
 
167
-function wpinv_gdp_to_wpi_gateway_title( $payment_method ) {
168
-    $gateway = wpinv_gdp_to_wpi_gateway( $payment_method );
167
+function wpinv_gdp_to_wpi_gateway_title($payment_method) {
168
+    $gateway = wpinv_gdp_to_wpi_gateway($payment_method);
169 169
     
170
-    $gateway_title = wpinv_get_gateway_checkout_label( $gateway );
170
+    $gateway_title = wpinv_get_gateway_checkout_label($gateway);
171 171
     
172
-    if ( $gateway == $gateway_title ) {
173
-        $gateway_title = geodir_payment_method_title( $gateway );
172
+    if ($gateway == $gateway_title) {
173
+        $gateway_title = geodir_payment_method_title($gateway);
174 174
     }
175 175
     
176
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method );
176
+    return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method);
177 177
 }
178 178
 
179 179
 function wpinv_print_checkout_errors() {
180 180
     global $wpi_session;
181 181
     wpinv_print_errors();
182 182
 }
183
-add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
183
+add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10);
184 184
 
185
-function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
185
+function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) {
186 186
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
187 187
     
188
-    $invoice_info = geodir_get_invoice( $invoice_id );
188
+    $invoice_info = geodir_get_invoice($invoice_id);
189 189
     
190
-    $wpi_invoice_id  = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0;
190
+    $wpi_invoice_id  = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0;
191 191
     
192 192
     if (!empty($invoice_info)) {
193
-        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL;
193
+        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL;
194 194
         
195
-        if ( !empty( $wpi_invoice ) ) { // update invoice
195
+        if (!empty($wpi_invoice)) { // update invoice
196 196
             $save = false;
197 197
             if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) {
198 198
                 $save = true;
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
             
203 203
             if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) {
204 204
                 $save = true;
205
-                $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
206
-                $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
207
-                $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway );
208
-                $wpi_invoice->set('gateway', $gateway );
209
-                $wpi_invoice->set('gateway_title', $gateway_title );
205
+                $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
206
+                $gateway = wpinv_gdp_to_wpi_gateway($gateway);
207
+                $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway);
208
+                $wpi_invoice->set('gateway', $gateway);
209
+                $wpi_invoice->set('gateway_title', $gateway_title);
210 210
             }
211 211
             
212
-            if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) {
212
+            if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) {
213 213
                 $save = true;
214
-                $wpi_invoice->set( 'status', $status );
214
+                $wpi_invoice->set('status', $status);
215 215
             }
216 216
             
217 217
             if ($save) {
@@ -222,16 +222,16 @@  discard block
 block discarded – undo
222 222
             
223 223
             return $wpi_invoice;
224 224
         } else { // create invoice
225
-            $user_info = get_userdata( $invoice_info->user_id );
225
+            $user_info = get_userdata($invoice_info->user_id);
226 226
             
227
-            if ( !empty( $pre_status ) ) {
227
+            if (!empty($pre_status)) {
228 228
                 $invoice_info->status = $pre_status;
229 229
             }
230
-            $status = wpinv_gdp_to_wpi_status( $invoice_info->status );
230
+            $status = wpinv_gdp_to_wpi_status($invoice_info->status);
231 231
             
232 232
             $wpi_zero_tax = false;
233 233
             
234
-            if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
234
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) {
235 235
                 $wpi_zero_tax = true;
236 236
             }
237 237
             
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
             $invoice_data['user_id']        = $invoice_info->user_id;
242 242
             $invoice_data['created_via']    = 'API';
243 243
             
244
-            if ( !empty( $invoice_info->date ) ) {
245
-                $invoice_data['created_date']   = $invoice_info->date;
244
+            if (!empty($invoice_info->date)) {
245
+                $invoice_data['created_date'] = $invoice_info->date;
246 246
             }
247 247
             
248
-            $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
249
-            $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod );
250
-            $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod );
248
+            $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
249
+            $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod);
250
+            $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod);
251 251
             
252 252
             $invoice_data['payment_details'] = array( 
253 253
                 'gateway'           => $paymentmethod, 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
                 'currency'          => geodir_get_currency_type(),
256 256
             );
257 257
             
258
-            $user_address = wpinv_get_user_address( $invoice_info->user_id, false );
258
+            $user_address = wpinv_get_user_address($invoice_info->user_id, false);
259 259
             
260 260
             $invoice_data['user_info'] = array( 
261 261
                 'user_id'       => $invoice_info->user_id, 
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
             
279 279
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
280 280
             
281
-            if ( !empty( $post_item ) ) {
282
-                $cart_details  = array();
281
+            if (!empty($post_item)) {
282
+                $cart_details = array();
283 283
                 $cart_details[] = array(
284 284
                     'id'            => $post_item->ID,
285 285
                     'name'          => $post_item->get_name(),
@@ -293,19 +293,19 @@  discard block
 block discarded – undo
293 293
                     ),
294 294
                 );
295 295
                 
296
-                $invoice_data['cart_details']  = $cart_details;
296
+                $invoice_data['cart_details'] = $cart_details;
297 297
             }
298 298
 
299
-            $data = array( 'invoice' => $invoice_data );
299
+            $data = array('invoice' => $invoice_data);
300 300
 
301 301
             $wpinv_api = new WPInv_API();
302
-            $data = $wpinv_api->insert_invoice( $data );
302
+            $data = $wpinv_api->insert_invoice($data);
303 303
             
304
-            if ( is_wp_error( $data ) ) {
305
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
304
+            if (is_wp_error($data)) {
305
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
306 306
             } else {
307
-                if ( !empty( $data ) ) {
308
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
307
+                if (!empty($data)) {
308
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
309 309
                     
310 310
                     $update_data = array();
311 311
                     $update_data['tax_amount'] = $data->get_tax();
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
                     $update_data['invoice_id'] = $data->ID;
314 314
                     
315 315
                     global $wpdb;
316
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
316
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
317 317
                     
318 318
                     return $data;
319 319
                 } else {
320
-                    if ( $update ) {
321
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
320
+                    if ($update) {
321
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
322 322
                     } else {
323
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
323
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
324 324
                     }
325 325
                 }
326 326
             }
@@ -331,59 +331,59 @@  discard block
 block discarded – undo
331 331
 }
332 332
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
333 333
 
334
-function wpinv_cpt_update( $invoice_id ) {
335
-    return wpinv_cpt_save( $invoice_id, true );
334
+function wpinv_cpt_update($invoice_id) {
335
+    return wpinv_cpt_save($invoice_id, true);
336 336
 }
337 337
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
338 338
 
339
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) {
340
-    $invoice_info = geodir_get_invoice( $invoice_id );
341
-    if ( empty( $invoice_info ) ) {
339
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) {
340
+    $invoice_info = geodir_get_invoice($invoice_id);
341
+    if (empty($invoice_info)) {
342 342
         return false;
343 343
     }
344 344
 
345
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
346
-    if ( !empty( $invoice ) ) {
345
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
346
+    if (!empty($invoice)) {
347 347
         $new_status = wpinv_gdp_to_wpi_status($new_status);
348
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
348
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
349 349
     } else {
350
-        $invoice = wpinv_cpt_save( $invoice_id );
350
+        $invoice = wpinv_cpt_save($invoice_id);
351 351
     }
352 352
     
353 353
     return $invoice;
354 354
 }
355
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
355
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
356 356
 
357
-function wpinv_transaction_details_note( $invoice_id, $html ) {
358
-    $invoice_info = geodir_get_invoice( $invoice_id );
359
-    if ( empty( $invoice_info ) ) {
357
+function wpinv_transaction_details_note($invoice_id, $html) {
358
+    $invoice_info = geodir_get_invoice($invoice_id);
359
+    if (empty($invoice_info)) {
360 360
         return false;
361 361
     }
362 362
 
363
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
363
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
364 364
     
365
-    if ( !$wpi_invoice_id ) {
366
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
365
+    if (!$wpi_invoice_id) {
366
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
367 367
         
368
-        if ( !empty( $invoice ) ) {
368
+        if (!empty($invoice)) {
369 369
             $wpi_invoice_id = $invoice->ID;
370 370
         }
371 371
     }
372 372
 
373
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
373
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
374 374
     
375
-    if ( empty( $invoice ) ) {
375
+    if (empty($invoice)) {
376 376
         return false;
377 377
     }
378 378
     
379
-    return $invoice->add_note( $html, true );
379
+    return $invoice->add_note($html, true);
380 380
 }
381
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
381
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
382 382
 
383
-function wpinv_gdp_to_wpi_status( $status ) {
383
+function wpinv_gdp_to_wpi_status($status) {
384 384
     $inv_status = $status ? $status : 'pending';
385 385
     
386
-    switch ( $status ) {
386
+    switch ($status) {
387 387
         case 'confirmed':
388 388
             $inv_status = 'publish';
389 389
         break;
@@ -403,10 +403,10 @@  discard block
 block discarded – undo
403 403
     return $inv_status;
404 404
 }
405 405
 
406
-function wpinv_wpi_to_gdp_status( $status ) {
406
+function wpinv_wpi_to_gdp_status($status) {
407 407
     $inv_status = $status ? $status : 'pending';
408 408
     
409
-    switch ( $status ) {
409
+    switch ($status) {
410 410
         case 'publish':
411 411
         case 'wpi-processing':
412 412
         case 'wpi-renewal':
@@ -429,72 +429,72 @@  discard block
 block discarded – undo
429 429
     return $inv_status;
430 430
 }
431 431
 
432
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
432
+function wpinv_wpi_to_gdp_id($invoice_id) {
433 433
     global $wpdb;
434 434
     
435
-    return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) );
435
+    return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id)));
436 436
 }
437 437
 
438
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
439
-    $invoice = geodir_get_invoice( $invoice_id );    
440
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
438
+function wpinv_gdp_to_wpi_id($invoice_id) {
439
+    $invoice = geodir_get_invoice($invoice_id);    
440
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
441 441
 }
442 442
 
443
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
443
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
444 444
     global $wpdb;
445 445
     
446
-    if ( !empty( $wpi_nosave ) ) {
446
+    if (!empty($wpi_nosave)) {
447 447
         return;
448 448
     }
449 449
     
450
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
450
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
451 451
     
452
-    if ( $gdp_invoice_id > 0 ) {
452
+    if ($gdp_invoice_id > 0) {
453 453
         $update_data = array();
454 454
         $update_data['tax_amount']      = $invoice->tax;
455 455
         $update_data['paied_amount']    = $invoice->total;
456 456
         $update_data['discount']        = $invoice->discount;
457 457
         $update_data['coupon_code']     = $invoice->discount_code;
458 458
         
459
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
459
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
460 460
     }
461 461
     
462 462
     return;
463 463
 }
464 464
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
465 465
 
466
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
467
-    $invoice = geodir_get_invoice( $invoice_id );
468
-    if ( empty( $invoice->invoice_id ) ) {
466
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
467
+    $invoice = geodir_get_invoice($invoice_id);
468
+    if (empty($invoice->invoice_id)) {
469 469
         return false;
470 470
     }
471 471
     
472
-    return wpinv_get_invoice( $invoice->invoice_id );
472
+    return wpinv_get_invoice($invoice->invoice_id);
473 473
 }
474 474
 
475
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
476
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
477
-    if ( empty( $invoice ) ) {
475
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
476
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
477
+    if (empty($invoice)) {
478 478
         return $status;
479 479
     }
480 480
 
481
-    if ( $status === 1 || $status === 0 ) {
482
-        if ( $status === 1 ) {
483
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
481
+    if ($status === 1 || $status === 0) {
482
+        if ($status === 1) {
483
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
484 484
         } else {
485 485
             $discount = '';
486 486
             $coupon_code = '';
487 487
         }
488 488
         
489
-        $invoice->set( 'discount', $discount );
490
-        $invoice->set( 'discount_code', $coupon_code );
489
+        $invoice->set('discount', $discount);
490
+        $invoice->set('discount_code', $coupon_code);
491 491
         $invoice->save();
492 492
         $invoice->recalculate_total();
493 493
     }
494 494
     
495 495
     return $status;
496 496
 }
497
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
497
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
498 498
 
499 499
 function wpinv_merge_gd_invoices() {
500 500
     if (!defined('GEODIRPAYMENT_VERSION')) {
@@ -502,157 +502,157 @@  discard block
 block discarded – undo
502 502
     }
503 503
     ?>
504 504
     <tr>
505
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
506
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
507
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
505
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
506
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
507
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
508 508
     </tr>
509 509
     <tr>
510
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
511
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
512
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
510
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
511
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
512
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
513 513
     </tr>
514 514
 	<tr>
515
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
516
-        <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td>
517
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
515
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
516
+        <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td>
517
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
518 518
     </tr>
519 519
     <tr>
520
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
521
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
522
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
520
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
521
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
522
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
523 523
     </tr>
524 524
     <?php
525 525
 }
526
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
526
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
527 527
 
528 528
 function wpinv_tool_merge_packages() {
529 529
     $packages = geodir_package_list_info();
530 530
     
531 531
     $count = 0;
532 532
     
533
-    if ( !empty( $packages ) ) {
533
+    if (!empty($packages)) {
534 534
         $success = true;
535 535
         
536
-        foreach ( $packages as $key => $package ) {
536
+        foreach ($packages as $key => $package) {
537 537
             $item = wpinv_get_item_by('custom_id', $package->pid, 'package');
538
-            if ( !empty( $item ) ) {
538
+            if (!empty($item)) {
539 539
                 continue;
540 540
             }
541 541
             
542
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
542
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
543 543
             
544
-            if ( !empty( $merged ) ) {
545
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
544
+            if (!empty($merged)) {
545
+                wpinv_error_log('Package merge S : ' . $package->pid);
546 546
                 $count++;
547 547
             } else {
548
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
548
+                wpinv_error_log('Package merge F : ' . $package->pid);
549 549
             }
550 550
         }
551 551
         
552
-        if ( $count > 0 ) {
553
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
552
+        if ($count > 0) {
553
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
554 554
         } else {
555
-            $message = __( 'No price packages merged.', 'invoicing' );
555
+            $message = __('No price packages merged.', 'invoicing');
556 556
         }
557 557
     } else {
558 558
         $success = false;
559
-        $message = __( 'No price packages found to merge!', 'invoicing' );
559
+        $message = __('No price packages found to merge!', 'invoicing');
560 560
     }
561 561
     
562 562
     $response = array();
563 563
     $response['success'] = $success;
564 564
     $response['data']['message'] = $message;
565
-    wp_send_json( $response );
565
+    wp_send_json($response);
566 566
 }
567
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
567
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
568 568
 
569 569
 function wpinv_tool_merge_invoices() {
570 570
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
571 571
     
572 572
     $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC";
573 573
 
574
-    $items = $wpdb->get_results( $sql );
574
+    $items = $wpdb->get_results($sql);
575 575
     
576 576
     $count = 0;
577 577
     
578
-    if ( !empty( $items ) ) {
578
+    if (!empty($items)) {
579 579
         $success = true;
580 580
         $wpi_gdp_inv_merge = true;
581 581
         
582
-        foreach ( $items as $item ) {
582
+        foreach ($items as $item) {
583 583
             $wpi_tax_rates = NULL;
584 584
             
585
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
585
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
586 586
             
587
-            $merged = wpinv_cpt_save( $item->id );
587
+            $merged = wpinv_cpt_save($item->id);
588 588
             
589
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
589
+            if (!empty($merged) && !empty($merged->ID)) {
590 590
                 $count++;
591 591
                 
592
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
593
-                $post_date_gmt = get_gmt_from_date( $post_date );
594
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
595
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
592
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
593
+                $post_date_gmt = get_gmt_from_date($post_date);
594
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
595
+                $post_modified_gmt = get_gmt_from_date($post_modified);
596 596
                 
597
-                $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) );
597
+                $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID));
598 598
                 
599
-                if ( $merged->is_paid() ) {
600
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
599
+                if ($merged->is_paid()) {
600
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
601 601
                 }
602 602
                 
603
-                clean_post_cache( $merged->ID );
603
+                clean_post_cache($merged->ID);
604 604
                 
605
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
605
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
606 606
             } else {
607
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
607
+                wpinv_error_log('Invoice merge F : ' . $item->id);
608 608
             }
609 609
         }
610 610
         
611 611
         $wpi_gdp_inv_merge = false;
612 612
         
613
-        if ( $count > 0 ) {
614
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
613
+        if ($count > 0) {
614
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
615 615
         } else {
616
-            $message = __( 'No invoices merged.', 'invoicing' );
616
+            $message = __('No invoices merged.', 'invoicing');
617 617
         }
618 618
     } else {
619 619
         $success = false;
620
-        $message = __( 'No invoices found to merge!', 'invoicing' );
620
+        $message = __('No invoices found to merge!', 'invoicing');
621 621
     }
622 622
     
623 623
     $response = array();
624 624
     $response['success'] = $success;
625 625
     $response['data']['message'] = $message;
626
-    wp_send_json( $response );
626
+    wp_send_json($response);
627 627
 }
628
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
628
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
629 629
 
630 630
 function wpinv_tool_merge_coupons() {
631 631
     global $wpdb;
632 632
     
633 633
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
634
-    $items = $wpdb->get_results( $sql );
634
+    $items = $wpdb->get_results($sql);
635 635
     $count = 0;
636 636
     
637
-    if ( !empty( $items ) ) {
637
+    if (!empty($items)) {
638 638
         $success = true;
639 639
         
640
-        foreach ( $items as $item ) {
641
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
640
+        foreach ($items as $item) {
641
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
642 642
                 continue;
643 643
             }
644 644
             
645 645
             $args = array(
646 646
                 'post_type'   => 'wpi_discount',
647 647
                 'post_title'  => $item->coupon_code,
648
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
648
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
649 649
             );
650 650
 
651
-            $merged = wp_insert_post( $args );
651
+            $merged = wp_insert_post($args);
652 652
             
653 653
             $item_id = $item->cid;
654 654
             
655
-            if ( $merged ) {
655
+            if ($merged) {
656 656
                 $meta = array(
657 657
                     'code'              => $item->coupon_code,
658 658
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -660,65 +660,65 @@  discard block
 block discarded – undo
660 660
                     'max_uses'          => (int)$item->usage_limit,
661 661
                     'uses'              => (int)$item->usage_count,
662 662
                 );
663
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
663
+                wpinv_store_discount($merged, $meta, get_post($merged));
664 664
                 
665 665
                 $count++;
666 666
                 
667
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
667
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
668 668
             } else {
669
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
669
+                wpinv_error_log('Coupon merge F : ' . $item_id);
670 670
             }
671 671
         }
672 672
         
673
-        if ( $count > 0 ) {
674
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
673
+        if ($count > 0) {
674
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
675 675
         } else {
676
-            $message = __( 'No coupons merged.', 'invoicing' );
676
+            $message = __('No coupons merged.', 'invoicing');
677 677
         }
678 678
     } else {
679 679
         $success = false;
680
-        $message = __( 'No coupons found to merge!', 'invoicing' );
680
+        $message = __('No coupons found to merge!', 'invoicing');
681 681
     }
682 682
     
683 683
     $response = array();
684 684
     $response['success'] = $success;
685 685
     $response['data']['message'] = $message;
686
-    wp_send_json( $response );
686
+    wp_send_json($response);
687 687
 }
688
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
688
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
689 689
 
690
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
690
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
691 691
     return wpinv_get_currency();
692 692
 }
693
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
693
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
694 694
 
695
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
695
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
696 696
     return wpinv_currency_symbol();
697 697
 }
698
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
698
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
699 699
 
700
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
701
-    if ( !$display ) {
702
-        $price = wpinv_round_amount( $amount );
700
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
701
+    if (!$display) {
702
+        $price = wpinv_round_amount($amount);
703 703
     } else {
704
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
704
+        $price = wpinv_price(wpinv_format_amount($amount));
705 705
     }
706 706
     
707 707
     return $price;
708 708
 }
709
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
709
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
710 710
 
711
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
711
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
712 712
     $invoice_id         = geodir_payment_cart_id();
713
-    $invoice_info       = geodir_get_invoice( $invoice_id );
714
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
713
+    $invoice_info       = geodir_get_invoice($invoice_id);
714
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
715 715
     
716
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
717
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
718
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
716
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
717
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
718
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
719 719
     }
720 720
     
721
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
721
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
722 722
         
723 723
         // Clear cart
724 724
         geodir_payment_clear_cart();
@@ -728,121 +728,121 @@  discard block
 block discarded – undo
728 728
     
729 729
     return $redirect_url;
730 730
 }
731
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
731
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
732 732
 
733
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
734
-    if ( get_current_user_id() ) {        
735
-        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>';
733
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
734
+    if (get_current_user_id()) {        
735
+        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>';
736 736
     }
737 737
 
738 738
     return $dashboard_links;
739 739
 }
740
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
741
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
740
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
741
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
742 742
 
743
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
743
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
744 744
     if (!defined('GEODIRPAYMENT_VERSION')) {
745 745
         return false;
746 746
     }
747 747
     
748
-    $invoice    = wpinv_get_invoice( $invoice_id );
749
-    if ( empty( $invoice ) ) {
748
+    $invoice = wpinv_get_invoice($invoice_id);
749
+    if (empty($invoice)) {
750 750
         return false;
751 751
     }
752 752
     
753
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
753
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
754 754
     
755
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
756
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
755
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
756
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
757 757
     
758
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
758
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
759 759
 }
760
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
760
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
761 761
 
762
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
763
-    $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' );
762
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
763
+    $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package');
764 764
     
765
-    if ( !empty( $item ) ) {
766
-        wpinv_remove_item( $item, true );
765
+    if (!empty($item)) {
766
+        wpinv_remove_item($item, true);
767 767
     }
768 768
 }
769
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
769
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
770 770
 
771
-function wpinv_can_delete_package_item( $return, $post_id ) {
772
-    if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
773
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
771
+function wpinv_can_delete_package_item($return, $post_id) {
772
+    if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_custom_id', true)) {
773
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
774 774
         
775
-        if ( !empty( $gd_package ) ) {
775
+        if (!empty($gd_package)) {
776 776
             $return = false;
777 777
         }
778 778
     }
779 779
 
780 780
     return $return;
781 781
 }
782
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
782
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
783 783
 
784
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
784
+function wpinv_package_item_classes($classes, $class, $post_id) {
785 785
     global $typenow;
786 786
 
787
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
788
-        if ( wpinv_item_in_use( $post_id ) ) {
787
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
788
+        if (wpinv_item_in_use($post_id)) {
789 789
             $classes[] = 'wpi-inuse-pkg';
790
-        } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_custom_id', true ), '' ) ) ) {
790
+        } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_custom_id', true), ''))) {
791 791
             $classes[] = 'wpi-delete-pkg';
792 792
         }
793 793
     }
794 794
 
795 795
     return $classes;
796 796
 }
797
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
797
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
798 798
 
799
-function wpinv_gdp_package_type_info( $post ) {
800
-    if ( wpinv_pm_active() ) {
801
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
799
+function wpinv_gdp_package_type_info($post) {
800
+    if (wpinv_pm_active()) {
801
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
802 802
         <?php
803 803
     }
804 804
 }
805
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
805
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
806 806
 
807
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
807
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
808 808
     global $wpi_zero_tax;
809 809
 
810
-    if ( $wpi_zero_tax ) {
810
+    if ($wpi_zero_tax) {
811 811
         $is_taxable = false;
812 812
     }
813 813
 
814 814
     return $is_taxable;
815 815
 }
816
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
816
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
817 817
 
818 818
 function wpinv_tool_merge_fix_taxes() {
819 819
     global $wpdb;
820 820
     
821 821
 	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
822
-	$items = $wpdb->get_results( $sql );
822
+	$items = $wpdb->get_results($sql);
823 823
 	
824
-	if ( !empty( $items ) ) {
825
-		foreach ( $items as $item ) {
826
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
827
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
824
+	if (!empty($items)) {
825
+		foreach ($items as $item) {
826
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
827
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
828 828
 			}
829 829
 		}
830 830
 	}
831 831
 		
832 832
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
833
-    $items = $wpdb->get_results( $sql );
833
+    $items = $wpdb->get_results($sql);
834 834
 	
835
-	if ( !empty( $items ) ) {
835
+	if (!empty($items)) {
836 836
 		$success = false;
837
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
837
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
838 838
 		
839 839
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
840 840
 		
841
-		foreach ( $items as $item ) {
841
+		foreach ($items as $item) {
842 842
 			$wpi_tax_rates = NULL;               
843 843
 			$data = wpinv_get_invoice($item->ID);
844 844
 
845
-			if ( empty( $data ) ) {
845
+			if (empty($data)) {
846 846
 				continue;
847 847
 			}
848 848
 			
@@ -850,51 +850,51 @@  discard block
 block discarded – undo
850 850
 			
851 851
 			$data_session                   = array();
852 852
 			$data_session['invoice_id']     = $data->ID;
853
-			$data_session['cart_discounts'] = $data->get_discounts( true );
853
+			$data_session['cart_discounts'] = $data->get_discounts(true);
854 854
 			
855
-			wpinv_set_checkout_session( $data_session );
855
+			wpinv_set_checkout_session($data_session);
856 856
 			
857 857
 			$wpi_userID         = (int)$data->get_user_id();
858 858
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
859 859
 				
860
-			$data->country      = sanitize_text_field( $_POST['country'] );
861
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
860
+			$data->country      = sanitize_text_field($_POST['country']);
861
+			$data->set('country', sanitize_text_field($_POST['country']));
862 862
 			
863 863
 			$wpinv_ip_address_country = $data->country;
864 864
 			
865 865
 			$data->recalculate_totals(true);
866 866
 			
867
-			wpinv_set_checkout_session( $checkout_session );
867
+			wpinv_set_checkout_session($checkout_session);
868 868
 			
869 869
 			$update_data = array();
870 870
 			$update_data['tax_amount'] = $data->get_tax();
871 871
 			$update_data['paied_amount'] = $data->get_total();
872 872
 			$update_data['invoice_id'] = $data->ID;
873 873
 			
874
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
874
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
875 875
 		}
876 876
 	} else {
877 877
         $success = false;
878
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
878
+        $message = __('No invoices found to fix taxes!', 'invoicing');
879 879
     }
880 880
 	
881 881
 	$response = array();
882 882
     $response['success'] = $success;
883 883
     $response['data']['message'] = $message;
884
-    wp_send_json( $response );
884
+    wp_send_json($response);
885 885
 }
886
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
887
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
886
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
887
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
888 888
 
889
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
890
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
891
-        if ( $invoice->is_renewal() ) {
889
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
890
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
891
+        if ($invoice->is_renewal()) {
892 892
             $invoice = $invoice->get_parent_payment();
893 893
         }
894 894
         
895
-        if ( !empty( $invoice ) ) {
896
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
895
+        if (!empty($invoice)) {
896
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
897 897
         }
898 898
     }
899 899
 }
900
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
901 900
\ No newline at end of file
901
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
902 902
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,73 +14,73 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27 27
         
28 28
         // Count comments
29
-        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );
29
+        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2);
30 30
         
31 31
         // Delete comments count cache whenever there is a new comment or a comment status changes
32
-        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
33
-        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
32
+        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
33
+        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
34 34
         
35
-        do_action( 'wpinv_class_notes_actions', $this );
35
+        do_action('wpinv_class_notes_actions', $this);
36 36
     }
37 37
         
38
-    public function set_invoice_note_type( $query ) {
39
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
38
+    public function set_invoice_note_type($query) {
39
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40 40
         
41
-        if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) {
41
+        if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) {
42 42
             $query->query_vars['type__in']      = $this->comment_type;
43 43
             $query->query_vars['type__not_in']  = '';
44 44
         } else {        
45
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
46
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
47
-                    $key = array_search( $this->comment_type, $type_in );
48
-                    unset( $query->query_vars['type__in'][$key] );
49
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
45
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
46
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
47
+                    $key = array_search($this->comment_type, $type_in);
48
+                    unset($query->query_vars['type__in'][$key]);
49
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
50 50
                     $query->query_vars['type__in'] = '';
51 51
                 }
52 52
             }
53 53
             
54
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
55
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
54
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
55
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
56 56
                     $query->query_vars['type__not_in'][] = $this->comment_type;
57
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
57
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
58 58
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
59 59
                     $query->query_vars['type__not_in'][] = $this->comment_type;
60 60
                 }
61 61
             } else {
62
-                $query->query_vars['type__not_in']  = $this->comment_type;
62
+                $query->query_vars['type__not_in'] = $this->comment_type;
63 63
             }
64 64
         }
65 65
         
66 66
         return $query;
67 67
     }
68 68
     
69
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
69
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
70 70
         $args = array( 
71 71
             'post_id'   => $invoice_id,
72 72
             'orderby'   => 'comment_ID',
73 73
             'order'     => 'DESC',
74 74
         );
75 75
         
76
-        if ( $type == 'customer' ) {
76
+        if ($type == 'customer') {
77 77
             $args['meta_key']   = '_wpi_customer_note';
78 78
             $args['meta_value'] = 1;
79 79
         }
80 80
         
81
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
82 82
         
83
-        return get_comments( $args );
83
+        return get_comments($args);
84 84
     }
85 85
     
86 86
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @return void
92 92
      */
93 93
     public function delete_comments_count_cache() {
94
-        delete_transient( 'wpinv_count_comments' );
94
+        delete_transient('wpinv_count_comments');
95 95
     }
96 96
     
97 97
     /**
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
      * @param  int    $post_id Post ID.
103 103
      * @return object
104 104
      */
105
-    public function wp_count_comments( $stats, $post_id ) {
105
+    public function wp_count_comments($stats, $post_id) {
106 106
         global $wpdb;
107 107
 
108
-        if ( 0 === $post_id ) {
109
-            $stats = get_transient( 'wpinv_count_comments' );
108
+        if (0 === $post_id) {
109
+            $stats = get_transient('wpinv_count_comments');
110 110
 
111
-            if ( ! $stats ) {
111
+            if (!$stats) {
112 112
                 $stats = array();
113 113
 
114
-                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A );
114
+                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A);
115 115
 
116 116
                 $total = 0;
117 117
                 $approved = array(
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
                     'post-trashed' => 'post-trashed',
123 123
                 );
124 124
 
125
-                foreach ( (array) $count as $row ) {
125
+                foreach ((array)$count as $row) {
126 126
                     // Do not count post-trashed toward totals.
127
-                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
127
+                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
128 128
                         $total += $row['num_comments'];
129 129
                     }
130
-                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
131
-                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
130
+                    if (isset($approved[$row['comment_approved']])) {
131
+                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
132 132
                     }
133 133
                 }
134 134
 
135 135
                 $stats['total_comments'] = $total;
136 136
                 $stats['all'] = $total;
137
-                foreach ( $approved as $key ) {
138
-                    if ( empty( $stats[ $key ] ) ) {
139
-                        $stats[ $key ] = 0;
137
+                foreach ($approved as $key) {
138
+                    if (empty($stats[$key])) {
139
+                        $stats[$key] = 0;
140 140
                     }
141 141
                 }
142 142
 
143
-                $stats = (object) $stats;
144
-                set_transient( 'wpinv_count_comments', $stats );
143
+                $stats = (object)$stats;
144
+                set_transient('wpinv_count_comments', $stats);
145 145
             }
146 146
         }
147 147
 
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,37 +11,37 @@
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
     
16
-    if ( $wpi_version == WPINV_VERSION ) {
16
+    if ($wpi_version == WPINV_VERSION) {
17 17
         return;
18 18
     }
19 19
     
20
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
20
+    if (version_compare($wpi_version, '0.0.5', '<')) {
21 21
         wpinv_v005_upgrades();
22 22
     }
23 23
     
24
-    update_option( 'wpinv_version', WPINV_VERSION );
24
+    update_option('wpinv_version', WPINV_VERSION);
25 25
 }
26
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
26
+add_action('admin_init', 'wpinv_automatic_upgrade');
27 27
 
28 28
 function wpinv_v005_upgrades() {
29 29
     global $wpdb;
30 30
     
31 31
     // Invoices status
32
-    $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
32
+    $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
33 33
     
34 34
     // Item meta key changes
35 35
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
36
-    $results = $wpdb->get_results( $query );
36
+    $results = $wpdb->get_results($query);
37 37
     
38
-    if ( !empty( $results ) ) {
39
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
40
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
41
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
38
+    if (!empty($results)) {
39
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
40
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
41
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
42 42
         
43
-        foreach ( $results as $row ) {
44
-            clean_post_cache( $row->post_id );
43
+        foreach ($results as $row) {
44
+            clean_post_cache($row->post_id);
45 45
         }
46 46
     }
47 47
 }
48 48
\ 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,22 +1,22 @@  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 22
         $item_types         = wpinv_get_item_types();
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
         }
30 30
         
31 31
         $cols = 5;
32
-        if ( $item_quantities ) {
32
+        if ($item_quantities) {
33 33
             $cols++;
34 34
         }
35
-        if ( $use_taxes ) {
35
+        if ($use_taxes) {
36 36
             $cols++;
37 37
         }
38 38
         $class = '';
39
-        if ( $invoice->is_paid() ) {
39
+        if ($invoice->is_paid()) {
40 40
             $class .= ' wpinv-paid';
41 41
         }
42
-        if ( $is_recurring ) {
42
+        if ($is_recurring) {
43 43
             $class .= ' wpi-recurring';
44 44
         }
45 45
         ?>
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
48 48
                 <thead>
49 49
                     <tr>
50
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
51
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
52
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
53
-                        <?php if ( $item_quantities ) { ?>
54
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
50
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
51
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
52
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
53
+                        <?php if ($item_quantities) { ?>
54
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
55 55
                         <?php } ?>
56
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
57
-                        <?php if ( $use_taxes ) { ?>
58
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
56
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
57
+                        <?php if ($use_taxes) { ?>
58
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
59 59
                         <?php } ?>
60 60
                         <th class="action"></th>
61 61
                     </tr>
62 62
                 </thead>
63 63
                 <tbody class="wpinv-line-items">
64
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
64
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
65 65
                 </tbody>
66 66
                 <tfoot class="wpinv-totals">
67 67
                     <tr>
@@ -73,44 +73,44 @@  discard block
 block discarded – undo
73 73
                                         </td>
74 74
                                         <td class="title">
75 75
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
76
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
76
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
77 77
                                             <div class="wp-clearfix">
78 78
                                                 <label class="wpi-vat-rule">
79
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
79
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
80 80
                                                     <span class="input-text-wrap">
81
-                                                        <?php echo wpinv_html_select( array(
81
+                                                        <?php echo wpinv_html_select(array(
82 82
                                                             'options'          => $wpinv_euvat->get_rules(),
83 83
                                                             'name'             => '_wpinv_quick[vat_rule]',
84 84
                                                             'id'               => '_wpinv_quick_vat_rule',
85 85
                                                             'show_option_all'  => false,
86 86
                                                             'show_option_none' => false,
87 87
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
88
-                                                        ) ); ?>
88
+                                                        )); ?>
89 89
                                                     </span>
90 90
                                                 </label>
91 91
                                             </div>
92
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
92
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
93 93
                                             <div class="wp-clearfix">
94 94
                                                 <label class="wpi-vat-class">
95
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
95
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
96 96
                                                     <span class="input-text-wrap">
97
-                                                        <?php echo wpinv_html_select( array(
97
+                                                        <?php echo wpinv_html_select(array(
98 98
                                                             'options'          => $wpinv_euvat->get_all_classes(),
99 99
                                                             'name'             => '_wpinv_quick[vat_class]',
100 100
                                                             'id'               => '_wpinv_quick_vat_class',
101 101
                                                             'show_option_all'  => false,
102 102
                                                             'show_option_none' => false,
103 103
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
104
-                                                        ) ); ?>
104
+                                                        )); ?>
105 105
                                                     </span>
106 106
                                                 </label>
107 107
                                             </div>
108 108
                                             <?php } ?>
109 109
                                             <div class="wp-clearfix">
110 110
                                                 <label class="wpi-item-type">
111
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
111
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
112 112
                                                     <span class="input-text-wrap">
113
-                                                        <?php echo wpinv_html_select( array(
113
+                                                        <?php echo wpinv_html_select(array(
114 114
                                                             'options'          => $item_types,
115 115
                                                             'name'             => '_wpinv_quick[type]',
116 116
                                                             'id'               => '_wpinv_quick_type',
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                                                             'show_option_all'  => false,
119 119
                                                             'show_option_none' => false,
120 120
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
121
-                                                        ) ); ?>
121
+                                                        )); ?>
122 122
                                                     </span>
123 123
                                                 </label>
124 124
                                             </div>
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
                                             </div>
132 132
                                         </td>
133 133
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
134
-                                        <?php if ( $item_quantities ) { ?>
134
+                                        <?php if ($item_quantities) { ?>
135 135
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
136 136
                                         <?php } ?>
137 137
                                         <td class="total"></td>
138
-                                        <?php if ( $use_taxes ) { ?>
138
+                                        <?php if ($use_taxes) { ?>
139 139
                                         <td class="tax"></td>
140 140
                                         <?php } ?>
141 141
                                         <td class="action"></td>
@@ -148,29 +148,29 @@  discard block
 block discarded – undo
148 148
                         <td colspan="<?php echo $cols; ?>"></td>
149 149
                     </tr>
150 150
                     <tr class="totals">
151
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
151
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
152 152
                         <td colspan="4">
153 153
                             <table cellspacing="0" cellpadding="0">
154 154
                                 <tr class="subtotal">
155
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
156
-                                    <td class="total"><?php echo $subtotal;?></td>
155
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
156
+                                    <td class="total"><?php echo $subtotal; ?></td>
157 157
                                     <td class="action"></td>
158 158
                                 </tr>
159 159
                                 <tr class="discount">
160
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
161
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
160
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
161
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
162 162
                                     <td class="action"></td>
163 163
                                 </tr>
164
-                                <?php if ( $use_taxes ) { ?>
164
+                                <?php if ($use_taxes) { ?>
165 165
                                 <tr class="tax">
166
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
167
-                                    <td class="total"><?php echo $tax;?></td>
166
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
167
+                                    <td class="total"><?php echo $tax; ?></td>
168 168
                                     <td class="action"></td>
169 169
                                 </tr>
170 170
                                 <?php } ?>
171 171
                                 <tr class="total">
172
-                                    <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td>
173
-                                    <td class="total"><?php echo $total;?></td>
172
+                                    <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td>
173
+                                    <td class="total"><?php echo $total; ?></td>
174 174
                                     <td class="action"></td>
175 175
                                 </tr>
176 176
                             </table>
@@ -180,89 +180,89 @@  discard block
 block discarded – undo
180 180
             </table>
181 181
             <div class="wpinv-actions">
182 182
                 <?php
183
-                    if ( !$invoice->is_paid() ) {
184
-                    if ( !$invoice->is_recurring() ) {
185
-                    echo wpinv_item_dropdown( array(
183
+                    if (!$invoice->is_paid()) {
184
+                    if (!$invoice->is_recurring()) {
185
+                    echo wpinv_item_dropdown(array(
186 186
                         'name'             => 'wpinv_invoice_item',
187 187
                         'id'               => 'wpinv_invoice_item',
188 188
                         'with_packages'    => false,
189 189
                         'show_recurring'   => true,
190
-                    ) );
190
+                    ));
191 191
                     ?>
192
-                <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">
192
+                <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">
193 193
                     <?php } ?>
194
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
194
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
195 195
             </div>
196 196
         </div>
197 197
         <?php
198 198
     }
199 199
     
200
-    public static function prices( $post ) {        
200
+    public static function prices($post) {        
201 201
         $symbol         = wpinv_currency_symbol();
202 202
         $position       = wpinv_currency_position();
203
-        $item           = new WPInv_Item( $post->ID );
203
+        $item           = new WPInv_Item($post->ID);
204 204
         
205 205
         $price          = $item->get_price();
206 206
         $is_recurring   = $item->is_recurring();
207 207
         $period         = $item->get_recurring_period();
208
-        $interval       = absint( $item->get_recurring_interval() );
209
-        $times          = absint( $item->get_recurring_limit() );
208
+        $interval       = absint($item->get_recurring_interval());
209
+        $times          = absint($item->get_recurring_limit());
210 210
         $free_trial     = $item->has_free_trial();
211 211
         $trial_interval = $item->get_trial_interval();
212 212
         $trial_period   = $item->get_trial_period();
213 213
         
214 214
         $intervals      = array();
215
-        for ( $i = 1; $i <= 90; $i++ ) {
215
+        for ($i = 1; $i <= 90; $i++) {
216 216
             $intervals[$i] = $i;
217 217
         }
218 218
         
219
-        $interval       = $interval > 0 ? $interval : 1;
219
+        $interval = $interval > 0 ? $interval : 1;
220 220
         
221 221
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
222 222
         ?>
223
-        <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_package(), true ); ?> /><?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' ) ;?>" />
224
-        <?php if ( $item->is_package() ) { ?>
225
-        <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>
223
+        <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_package(), true); ?> /><?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'); ?>" />
224
+        <?php if ($item->is_package()) { ?>
225
+        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span>
226 226
         <?php } ?>
227 227
         </p>
228 228
         <p class="wpinv-row-is-recurring">
229 229
             <label for="wpinv_is_recurring">
230
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
231
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
230
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
231
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
232 232
             </label>
233 233
         </p>
234
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
235
-                <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>
236
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
234
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
235
+                <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>
236
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
237 237
                     'options'          => $intervals,
238 238
                     'name'             => 'wpinv_recurring_interval',
239 239
                     'id'               => 'wpinv_recurring_interval',
240 240
                     'selected'         => $interval,
241 241
                     'show_option_all'  => false,
242 242
                     'show_option_none' => false
243
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
244
-                <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>
243
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
244
+                <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>
245 245
                 <span class="clear wpi-trial-clr"></span>
246 246
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
247
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
248
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
247
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
248
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
249 249
                 </label>
250 250
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
251
-                    <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>
251
+                    <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>
252 252
                 </label>
253 253
         </p>
254
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
255
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
254
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
255
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
256 256
         <?php
257 257
     }
258 258
     
259
-    public static function vat_rules( $post ) {
259
+    public static function vat_rules($post) {
260 260
         global $wpinv_euvat;
261 261
         
262
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
262
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
263 263
         ?>
264
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
265
-        <?php echo wpinv_html_select( array(
264
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
265
+        <?php echo wpinv_html_select(array(
266 266
                     'options'          => $wpinv_euvat->get_rules(),
267 267
                     'name'             => 'wpinv_vat_rules',
268 268
                     'id'               => 'wpinv_vat_rules',
@@ -270,19 +270,19 @@  discard block
 block discarded – undo
270 270
                     'show_option_all'  => false,
271 271
                     'show_option_none' => false,
272 272
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
273
-                ) ); ?>
273
+                )); ?>
274 274
         </p>
275
-        <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>
276
-        <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>
275
+        <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>
276
+        <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>
277 277
         <?php
278 278
     }
279 279
     
280
-    public static function vat_classes( $post ) {
280
+    public static function vat_classes($post) {
281 281
         global $wpinv_euvat;
282 282
         
283
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
283
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
284 284
         ?>
285
-        <p><?php echo wpinv_html_select( array(
285
+        <p><?php echo wpinv_html_select(array(
286 286
                     'options'          => $wpinv_euvat->get_all_classes(),
287 287
                     'name'             => 'wpinv_vat_class',
288 288
                     'id'               => 'wpinv_vat_class',
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
                     'show_option_all'  => false,
291 291
                     'show_option_none' => false,
292 292
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                ) ); ?>
293
+                )); ?>
294 294
         </p>
295
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
295
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
296 296
         <?php
297 297
     }
298 298
     
299
-    public static function item_info( $post ) {
300
-        $item_type = wpinv_get_item_type( $post->ID );
301
-        do_action( 'wpinv_item_info_metabox_before', $post );
299
+    public static function item_info($post) {
300
+        $item_type = wpinv_get_item_type($post->ID);
301
+        do_action('wpinv_item_info_metabox_before', $post);
302 302
         ?>
303
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
304
-        <?php echo wpinv_html_select( array(
303
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
304
+        <?php echo wpinv_html_select(array(
305 305
                     'options'          => wpinv_get_item_types(),
306 306
                     'name'             => 'wpinv_item_type',
307 307
                     'id'               => 'wpinv_item_type',
@@ -310,114 +310,114 @@  discard block
 block discarded – undo
310 310
                     'show_option_none' => false,
311 311
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
312 312
                     //'disabled'         => $item_type == 'package' ? true : false,
313
-                ) ); ?>
313
+                )); ?>
314 314
         </p>
315
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p>
315
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p>
316 316
         <?php
317
-        do_action( 'wpinv_item_info_metabox_after', $post );
317
+        do_action('wpinv_item_info_metabox_after', $post);
318 318
     }
319 319
     
320
-    public static function meta_values( $post ) {
321
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
320
+    public static function meta_values($post) {
321
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
322 322
             'type',
323 323
             'custom_id'
324
-        ) );
324
+        ));
325 325
         
326
-        if ( empty( $meta_keys ) ) {
326
+        if (empty($meta_keys)) {
327 327
             return;
328 328
         }
329 329
         
330
-        do_action( 'wpinv_meta_values_metabox_before', $post );
330
+        do_action('wpinv_meta_values_metabox_before', $post);
331 331
         
332
-        foreach ( $meta_keys as $meta_key ) {
332
+        foreach ($meta_keys as $meta_key) {
333 333
             ?>
334
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
334
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
335 335
             <?php 
336 336
         }
337 337
         
338
-        do_action( 'wpinv_meta_values_metabox_after', $post );
338
+        do_action('wpinv_meta_values_metabox_after', $post);
339 339
     }
340 340
     
341
-    public static function save( $post_id, $data, $post ) {
342
-        $invoice        = new WPInv_Invoice( $post_id );
341
+    public static function save($post_id, $data, $post) {
342
+        $invoice        = new WPInv_Invoice($post_id);
343 343
         
344 344
         // Billing
345
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
346
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
347
-        $company        = sanitize_text_field( $data['wpinv_company'] );
348
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
349
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
350
-        $address        = sanitize_text_field( $data['wpinv_address'] );
351
-        $city           = sanitize_text_field( $data['wpinv_city'] );
352
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
353
-        $country        = sanitize_text_field( $data['wpinv_country'] );
354
-        $state          = sanitize_text_field( $data['wpinv_state'] );
345
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
346
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
347
+        $company        = sanitize_text_field($data['wpinv_company']);
348
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
349
+        $phone          = sanitize_text_field($data['wpinv_phone']);
350
+        $address        = sanitize_text_field($data['wpinv_address']);
351
+        $city           = sanitize_text_field($data['wpinv_city']);
352
+        $zip            = sanitize_text_field($data['wpinv_zip']);
353
+        $country        = sanitize_text_field($data['wpinv_country']);
354
+        $state          = sanitize_text_field($data['wpinv_state']);
355 355
         
356 356
         // Details
357
-        $status         = sanitize_text_field( $data['wpinv_status'] );
358
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
359
-        $number         = sanitize_text_field( $data['wpinv_number'] );
360
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
357
+        $status         = sanitize_text_field($data['wpinv_status']);
358
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
359
+        $number         = sanitize_text_field($data['wpinv_number']);
360
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
361 361
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
362 362
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
363 363
         
364
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
364
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
365 365
         
366
-        $invoice->set( 'due_date', $due_date );
367
-        $invoice->set( 'first_name', $first_name );
368
-        $invoice->set( 'last_name', $last_name );
369
-        $invoice->set( 'company', $company );
370
-        $invoice->set( 'vat_number', $vat_number );
371
-        $invoice->set( 'phone', $phone );
372
-        $invoice->set( 'address', $address );
373
-        $invoice->set( 'city', $city );
374
-        $invoice->set( 'zip', $zip );
375
-        $invoice->set( 'country', $country );
376
-        $invoice->set( 'state', $state );
377
-        $invoice->set( 'status', $status );
378
-        $invoice->set( 'number', $number );
366
+        $invoice->set('due_date', $due_date);
367
+        $invoice->set('first_name', $first_name);
368
+        $invoice->set('last_name', $last_name);
369
+        $invoice->set('company', $company);
370
+        $invoice->set('vat_number', $vat_number);
371
+        $invoice->set('phone', $phone);
372
+        $invoice->set('address', $address);
373
+        $invoice->set('city', $city);
374
+        $invoice->set('zip', $zip);
375
+        $invoice->set('country', $country);
376
+        $invoice->set('state', $state);
377
+        $invoice->set('status', $status);
378
+        $invoice->set('number', $number);
379 379
         //$invoice->set( 'discounts', $discounts );
380 380
         //$invoice->set( 'discount', $discount );
381
-        $invoice->set( 'ip', $ip );
381
+        $invoice->set('ip', $ip);
382 382
         $invoice->old_status = $_POST['original_post_status'];
383 383
         $invoice->currency = wpinv_get_currency();
384
-        if ( !empty( $data['wpinv_gateway'] ) ) {
385
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
384
+        if (!empty($data['wpinv_gateway'])) {
385
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
386 386
         }
387 387
         $saved = $invoice->save();
388 388
         
389 389
         // Check for payment notes
390
-        if ( !empty( $data['invoice_note'] ) ) {
391
-            $note               = wp_kses( $data['invoice_note'], array() );
392
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
390
+        if (!empty($data['invoice_note'])) {
391
+            $note               = wp_kses($data['invoice_note'], array());
392
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
393 393
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
394 394
         
395
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
395
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
396 396
         }
397 397
         
398 398
         // Update user address if empty.
399
-        if ( $saved && !empty( $invoice ) ) {
400
-            if ( $user_id = $invoice->get_user_id() ) {
401
-                $user_address = wpinv_get_user_address( $user_id, false );
399
+        if ($saved && !empty($invoice)) {
400
+            if ($user_id = $invoice->get_user_id()) {
401
+                $user_address = wpinv_get_user_address($user_id, false);
402 402
                 
403 403
                 if (empty($user_address['first_name'])) {
404
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
405
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
404
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
405
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
406 406
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
407
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
407
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
408 408
                 }
409 409
                 
410 410
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
411
-                    update_user_meta( $user_id, '_wpinv_address', $address );
412
-                    update_user_meta( $user_id, '_wpinv_city', $city );
413
-                    update_user_meta( $user_id, '_wpinv_state', $state );
414
-                    update_user_meta( $user_id, '_wpinv_country', $country );
415
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
416
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
411
+                    update_user_meta($user_id, '_wpinv_address', $address);
412
+                    update_user_meta($user_id, '_wpinv_city', $city);
413
+                    update_user_meta($user_id, '_wpinv_state', $state);
414
+                    update_user_meta($user_id, '_wpinv_country', $country);
415
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
416
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
417 417
                 }
418 418
             }
419 419
             
420
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
420
+            do_action('wpinv_invoice_metabox_saved', $invoice);
421 421
         }
422 422
         
423 423
         return $saved;
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +141 added lines, -141 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,296 +72,296 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    if ( $field == '_wpinv_price' ) {
86
-                        if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) {
87
-                            $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price.
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    if ($field == '_wpinv_price') {
86
+                        if (get_post_meta($post_id, '_wpinv_type', true) === 'package') {
87
+                            $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price.
88 88
                         } else {
89
-                            $value = wpinv_sanitize_amount( $_POST[ $name ] );
89
+                            $value = wpinv_sanitize_amount($_POST[$name]);
90 90
                         }
91 91
                     } else {
92
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
92
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
93 93
                     }
94 94
                     
95
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
96
-                    update_post_meta( $post_id, $field, $value );
95
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
96
+                    update_post_meta($post_id, $field, $value);
97 97
                 }
98 98
             }
99 99
             
100
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
101
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
100
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
101
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
102 102
             }
103 103
         }
104 104
     }
105 105
 }
106
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
106
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
107 107
 
108
-function wpinv_bulk_and_quick_edit_save( $post_id, $post, $update = false ) {
109
-    if ( !( !empty( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) ) {
108
+function wpinv_bulk_and_quick_edit_save($post_id, $post, $update = false) {
109
+    if (!(!empty($_POST['action']) && $_POST['action'] == 'inline-save')) {
110 110
         return;
111 111
     }
112 112
     
113 113
     // $post_id and $post are required
114
-    if ( empty( $post_id ) || empty( $post ) ) {
114
+    if (empty($post_id) || empty($post)) {
115 115
         return;
116 116
     }
117 117
         
118
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
118
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
119 119
         return;
120 120
     }
121 121
     
122 122
     // Dont' save meta boxes for revisions or autosaves
123
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
123
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
124 124
         return;
125 125
     }
126 126
 
127
-    if ( $post->post_type == 'wpi_item' ) {
127
+    if ($post->post_type == 'wpi_item') {
128 128
         // verify nonce
129
-        if ( isset( $_POST['_wpinv_item_price'] ) && get_post_meta( $post->ID, '_wpinv_type', true ) !== 'package' ) {
130
-            update_post_meta( $post_id, '_wpinv_price', wpinv_sanitize_amount( $_POST['_wpinv_item_price'] ) );
129
+        if (isset($_POST['_wpinv_item_price']) && get_post_meta($post->ID, '_wpinv_type', true) !== 'package') {
130
+            update_post_meta($post_id, '_wpinv_price', wpinv_sanitize_amount($_POST['_wpinv_item_price']));
131 131
         }
132 132
         
133
-        if ( isset( $_POST['_wpinv_vat_class'] ) ) {
134
-            update_post_meta( $post_id, '_wpinv_vat_class', sanitize_text_field( $_POST['_wpinv_vat_class'] ) );
133
+        if (isset($_POST['_wpinv_vat_class'])) {
134
+            update_post_meta($post_id, '_wpinv_vat_class', sanitize_text_field($_POST['_wpinv_vat_class']));
135 135
         }
136 136
 
137
-        if ( isset( $_POST['_wpinv_vat_rules'] ) ) {
138
-            update_post_meta( $post_id, '_wpinv_vat_rule', sanitize_text_field( $_POST['_wpinv_vat_rules'] ) );
137
+        if (isset($_POST['_wpinv_vat_rules'])) {
138
+            update_post_meta($post_id, '_wpinv_vat_rule', sanitize_text_field($_POST['_wpinv_vat_rules']));
139 139
         }
140 140
         
141
-        if ( isset( $_POST['_wpinv_item_type'] ) ) {
142
-            update_post_meta( $post_id, '_wpinv_type', sanitize_text_field( $_POST['_wpinv_item_type'] ) );
141
+        if (isset($_POST['_wpinv_item_type'])) {
142
+            update_post_meta($post_id, '_wpinv_type', sanitize_text_field($_POST['_wpinv_item_type']));
143 143
         }
144 144
     }
145 145
 }
146
-add_action( 'save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3 );
146
+add_action('save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3);
147 147
 
148 148
 function wpinv_register_item_meta_boxes() {    
149 149
     global $wpinv_euvat;
150 150
     
151
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
151
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
152 152
 
153
-    if ( $wpinv_euvat->allow_vat_rules() ) {
154
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
153
+    if ($wpinv_euvat->allow_vat_rules()) {
154
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
155 155
     }
156 156
     
157
-    if ( $wpinv_euvat->allow_vat_classes() ) {
158
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
157
+    if ($wpinv_euvat->allow_vat_classes()) {
158
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
159 159
     }
160 160
     
161
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
162
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
161
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
162
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
163 163
 }
164 164
 
165 165
 function wpinv_register_discount_meta_boxes() {
166
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
166
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
167 167
 }
168 168
 
169
-function wpinv_discount_metabox_details( $post ) {
169
+function wpinv_discount_metabox_details($post) {
170 170
     $discount_id    = $post->ID;
171
-    $discount       = wpinv_get_discount( $discount_id );
171
+    $discount       = wpinv_get_discount($discount_id);
172 172
     
173
-    $type           = wpinv_get_discount_type( $discount_id );
174
-    $item_reqs      = wpinv_get_discount_item_reqs( $discount_id );
175
-    $excluded_items = wpinv_get_discount_excluded_items( $discount_id );
176
-    $min_total      = wpinv_get_discount_min_total( $discount_id );
177
-    $max_total      = wpinv_get_discount_max_total( $discount_id );
178
-    $max_uses       = wpinv_get_discount_max_uses( $discount_id );
179
-    $single_use     = wpinv_discount_is_single_use( $discount_id );
180
-    $recurring      = (bool)wpinv_discount_is_recurring( $discount_id );
173
+    $type           = wpinv_get_discount_type($discount_id);
174
+    $item_reqs      = wpinv_get_discount_item_reqs($discount_id);
175
+    $excluded_items = wpinv_get_discount_excluded_items($discount_id);
176
+    $min_total      = wpinv_get_discount_min_total($discount_id);
177
+    $max_total      = wpinv_get_discount_max_total($discount_id);
178
+    $max_uses       = wpinv_get_discount_max_uses($discount_id);
179
+    $single_use     = wpinv_discount_is_single_use($discount_id);
180
+    $recurring      = (bool)wpinv_discount_is_recurring($discount_id);
181 181
     
182 182
     $min_total      = $min_total > 0 ? $min_total : '';
183 183
     $max_total      = $max_total > 0 ? $max_total : '';
184 184
     $max_uses       = $max_uses > 0 ? $max_uses : '';
185 185
 ?>
186
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
187
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
186
+<?php do_action('wpinv_discount_form_top', $post); ?>
187
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
188 188
 <table class="form-table wpi-form-table">
189 189
     <tbody>
190
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
191
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
190
+        <?php do_action('wpinv_discount_form_first', $post); ?>
191
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
192 192
         <tr>
193 193
             <th valign="top" scope="row">
194
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
194
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
195 195
             </th>
196 196
             <td>
197
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
198
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
197
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
198
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
199 199
             </td>
200 200
         </tr>
201
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
201
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
202 202
         <tr>
203 203
             <th valign="top" scope="row">
204
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
204
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
205 205
             </th>
206 206
             <td>
207 207
                 <select id="wpinv_discount_type" name="type" class="medium-text">
208
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
209
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
208
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
209
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
210 210
                     <?php } ?>
211 211
                 </select>
212
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
212
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
213 213
             </td>
214 214
         </tr>
215
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
215
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
216 216
         <tr>
217 217
             <th valign="top" scope="row">
218
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
218
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
219 219
             </th>
220 220
             <td>
221
-                <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>
222
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
223
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
221
+                <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>
222
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
223
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
224 224
             </td>
225 225
         </tr>
226
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
226
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
227 227
         <tr>
228 228
             <th valign="top" scope="row">
229
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
229
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
230 230
             </th>
231 231
             <td>
232
-                <p><?php echo wpinv_item_dropdown( array(
232
+                <p><?php echo wpinv_item_dropdown(array(
233 233
                         'name'              => 'items[]',
234 234
                         'id'                => 'items',
235 235
                         'selected'          => $item_reqs,
236 236
                         'multiple'          => true,
237 237
                         'chosen'            => true,
238 238
                         'class'             => 'medium-text',
239
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
239
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
240 240
                         'show_recurring'    => true,
241
-                    ) ); ?>
241
+                    )); ?>
242 242
                 </p>
243
-                <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>
243
+                <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>
244 244
             </td>
245 245
         </tr>
246
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
246
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
247 247
         <tr>
248 248
             <th valign="top" scope="row">
249
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
249
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
250 250
             </th>
251 251
             <td>
252
-                <p><?php echo wpinv_item_dropdown( array(
252
+                <p><?php echo wpinv_item_dropdown(array(
253 253
                         'name'              => 'excluded_items[]',
254 254
                         'id'                => 'excluded_items',
255 255
                         'selected'          => $excluded_items,
256 256
                         'multiple'          => true,
257 257
                         'chosen'            => true,
258 258
                         'class'             => 'medium-text',
259
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
259
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
260 260
                         'show_recurring'    => true,
261
-                    ) ); ?>
261
+                    )); ?>
262 262
                 </p>
263
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_start"><?php _e( 'Start date', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_start"><?php _e('Start date', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272
-                <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 ) ); ?>">
273
-                <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>
272
+                <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)); ?>">
273
+                <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>
274 274
             </td>
275 275
         </tr>
276
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
276
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
277 277
         <tr>
278 278
             <th valign="top" scope="row">
279
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration date', 'invoicing' ); ?></label>
279
+                <label for="wpinv_discount_expiration"><?php _e('Expiration date', 'invoicing'); ?></label>
280 280
             </th>
281 281
             <td>
282
-                <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 ) ); ?>">
283
-                <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>
282
+                <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)); ?>">
283
+                <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>
284 284
             </td>
285 285
         </tr>
286
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
286
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
287 287
         <tr>
288 288
             <th valign="top" scope="row">
289
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
289
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
290 290
             </th>
291 291
             <td>
292 292
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
293
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
293
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
294 294
             </td>
295 295
         </tr>
296
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
296
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
297 297
         <tr>
298 298
             <th valign="top" scope="row">
299
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
299
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
300 300
             </th>
301 301
             <td>
302 302
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
303
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
303
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
304 304
             </td>
305 305
         </tr>
306
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
306
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
307 307
         <tr>
308 308
             <th valign="top" scope="row">
309
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
309
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
310 310
             </th>
311 311
             <td>
312 312
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
313
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
314
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
313
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
314
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
315 315
                 </select>
316
-                <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>
316
+                <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>
317 317
             </td>
318 318
         </tr>
319
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
319
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
320 320
         <tr>
321 321
             <th valign="top" scope="row">
322
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
322
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
323 323
             </th>
324 324
             <td>
325 325
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
326
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
326
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
327 327
             </td>
328 328
         </tr>
329
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
329
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
330 330
         <tr>
331 331
             <th valign="top" scope="row">
332
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
332
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
333 333
             </th>
334 334
             <td>
335
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
336
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
335
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
336
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
337 337
             </td>
338 338
         </tr>
339
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
339
+        <?php do_action('wpinv_discount_form_last', $post); ?>
340 340
     </tbody>
341 341
 </table>
342
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
342
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
343 343
     <?php
344 344
 }
345 345
 
346
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
347
-    $post_type = !empty( $post ) ? $post->post_type : '';
346
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
347
+    $post_type = !empty($post) ? $post->post_type : '';
348 348
     
349
-    if ( $post_type != 'wpi_discount' ) {
349
+    if ($post_type != 'wpi_discount') {
350 350
         return;
351 351
     }
352 352
     
353
-    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' ) ) ) {
353
+    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'))) {
354 354
         return;
355 355
     }
356 356
     
357
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
357
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
358 358
         return;
359 359
     }
360 360
     
361
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
361
+    if (!current_user_can('manage_options', $post_id)) {
362 362
         return;
363 363
     }
364 364
     
365
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
365
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
366 366
 }
367
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
368 367
\ No newline at end of file
368
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
369 369
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/paypal.php 1 patch
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
         'user_info'     => $purchase_data['user_info'],
22 22
         'cart_details'  => $purchase_data['cart_details'],
23 23
         'gateway'       => 'paypal',
24
-        'status'        => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending'
24
+        'status'        => !empty($purchase_data['buy_now']) ? 'private' : 'pending'
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
 	        'lc'            => 'US' // this will force paypal site to english
69 69
         );
@@ -79,57 +79,57 @@  discard block
 block discarded – undo
79 79
             'upload' => '1'
80 80
         );
81 81
 
82
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
82
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
83 83
 
84 84
         // Add cart items
85 85
         $i = 1;
86
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
87
-            foreach ( $purchase_data['cart_details'] as $item ) {
86
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
87
+            foreach ($purchase_data['cart_details'] as $item) {
88 88
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
89
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
89
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
90 90
 
91
-                if ( $item_amount <= 0 ) {
91
+                if ($item_amount <= 0) {
92 92
                     $item_amount = 0;
93 93
                 }
94 94
 
95
-                $paypal_args['item_number_' . $i ]      = $item['id'];
96
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
97
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
98
-                $paypal_args['amount_' . $i ]           = $item_amount;
99
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
95
+                $paypal_args['item_number_' . $i]      = $item['id'];
96
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
97
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
98
+                $paypal_args['amount_' . $i]           = $item_amount;
99
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
100 100
 
101 101
                 $i++;
102 102
             }
103 103
         }
104 104
 
105 105
         // Add taxes to the cart
106
-        if ( wpinv_use_taxes() ) {
107
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 );
106
+        if (wpinv_use_taxes()) {
107
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2);
108 108
         }
109 109
 
110
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
110
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
111 111
 
112 112
         // Build query
113
-        $paypal_redirect .= http_build_query( $paypal_args );
113
+        $paypal_redirect .= http_build_query($paypal_args);
114 114
 
115 115
         // Fix for some sites that encode the entities
116
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
116
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
117 117
 
118 118
         // Get rid of cart contents
119 119
         wpinv_empty_cart();
120 120
         
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
     }
125 125
 }
126
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
126
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
127 127
 
128
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
129
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
130
-        $item   = new WPInv_Item( $item_id );
128
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
129
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
130
+        $item = new WPInv_Item($item_id);
131 131
         
132
-        if ( empty( $item ) ) {
132
+        if (empty($item)) {
133 133
             return $paypal_args;
134 134
         }
135 135
 
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
         $interval           = $item->get_recurring_interval();
138 138
         $bill_times         = (int)$item->get_recurring_limit();
139 139
         
140
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
141
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
140
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
141
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
142 142
         
143 143
         $paypal_args['cmd'] = '_xclick-subscriptions';
144 144
         $paypal_args['sra'] = '1';
145 145
         $paypal_args['src'] = '1';
146 146
         
147 147
         // Set item description
148
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
148
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
149 149
         
150
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
150
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
151 151
             $paypal_args['a1']  = $initial_amount;
152 152
             $paypal_args['p1']  = $item->get_trial_interval();
153 153
             $paypal_args['t1']  = $item->get_trial_period();
154 154
             
155 155
             // Set the recurring amount
156 156
             $paypal_args['a3']  = $recurring_amount;
157
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
157
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
158 158
             $paypal_args['a1']  = $initial_amount;
159 159
             $paypal_args['p1']  = $interval;
160 160
             $paypal_args['t1']  = $period;
@@ -162,63 +162,63 @@  discard block
 block discarded – undo
162 162
             // Set the recurring amount
163 163
             $paypal_args['a3']  = $recurring_amount;
164 164
             
165
-            if ( $bill_times > 1 ) {
165
+            if ($bill_times > 1) {
166 166
                 $bill_times--;
167 167
             }
168 168
         } else {
169
-            $paypal_args['a3']  = $initial_amount;
169
+            $paypal_args['a3'] = $initial_amount;
170 170
         }
171 171
         
172 172
         $paypal_args['p3']  = $interval;
173 173
         $paypal_args['t3']  = $period;
174 174
         
175
-        if ( $bill_times > 1 ) {
175
+        if ($bill_times > 1) {
176 176
             // Make sure it's not over the max of 52
177
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
177
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
178 178
         }
179 179
                 
180 180
         // Remove cart items
181 181
         $i = 1;
182
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
183
-            foreach ( $purchase_data['cart_details'] as $item ) {                
184
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
185
-                    unset( $paypal_args['item_number_' . $i] );
182
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
183
+            foreach ($purchase_data['cart_details'] as $item) {                
184
+                if (isset($paypal_args['item_number_' . $i])) {
185
+                    unset($paypal_args['item_number_' . $i]);
186 186
                 }
187
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
188
-                    unset( $paypal_args['item_name_' . $i] );
187
+                if (isset($paypal_args['item_name_' . $i])) {
188
+                    unset($paypal_args['item_name_' . $i]);
189 189
                 }
190
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
191
-                    unset( $paypal_args['quantity_' . $i] );
190
+                if (isset($paypal_args['quantity_' . $i])) {
191
+                    unset($paypal_args['quantity_' . $i]);
192 192
                 }
193
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
194
-                    unset( $paypal_args['amount_' . $i] );
193
+                if (isset($paypal_args['amount_' . $i])) {
194
+                    unset($paypal_args['amount_' . $i]);
195 195
                 }
196
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
197
-                    unset( $paypal_args['discount_amount_' . $i] );
196
+                if (isset($paypal_args['discount_amount_' . $i])) {
197
+                    unset($paypal_args['discount_amount_' . $i]);
198 198
                 }
199 199
 
200 200
                 $i++;
201 201
             }
202 202
         }
203 203
         
204
-        if ( isset( $paypal_args['tax_cart'] ) ) {
205
-            unset( $paypal_args['tax_cart'] );
204
+        if (isset($paypal_args['tax_cart'])) {
205
+            unset($paypal_args['tax_cart']);
206 206
         }
207 207
                 
208
-        if ( isset( $paypal_args['upload'] ) ) {
209
-            unset( $paypal_args['upload'] );
208
+        if (isset($paypal_args['upload'])) {
209
+            unset($paypal_args['upload']);
210 210
         }
211 211
         
212
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
212
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
213 213
     }
214 214
     
215 215
     return $paypal_args;
216 216
 }
217
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
217
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
218 218
 
219 219
 function wpinv_process_paypal_ipn() {
220 220
 	// Check the request method is POST
221
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
221
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
222 222
 		return;
223 223
 	}
224 224
 
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	$post_data = '';
227 227
 
228 228
 	// Fallback just in case post_max_size is lower than needed
229
-	if ( ini_get( 'allow_url_fopen' ) ) {
230
-		$post_data = file_get_contents( 'php://input' );
229
+	if (ini_get('allow_url_fopen')) {
230
+		$post_data = file_get_contents('php://input');
231 231
 	} else {
232 232
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
233
-		ini_set( 'post_max_size', '12M' );
233
+		ini_set('post_max_size', '12M');
234 234
 	}
235 235
 	// Start the encoded data collection with notification command
236 236
 	$encoded_data = 'cmd=_notify-validate';
@@ -239,43 +239,43 @@  discard block
 block discarded – undo
239 239
 	$arg_separator = wpinv_get_php_arg_separator_output();
240 240
 
241 241
 	// Verify there is a post_data
242
-	if ( $post_data || strlen( $post_data ) > 0 ) {
242
+	if ($post_data || strlen($post_data) > 0) {
243 243
 		// Append the data
244
-		$encoded_data .= $arg_separator.$post_data;
244
+		$encoded_data .= $arg_separator . $post_data;
245 245
 	} else {
246 246
 		// Check if POST is empty
247
-		if ( empty( $_POST ) ) {
247
+		if (empty($_POST)) {
248 248
 			// Nothing to do
249 249
 			return;
250 250
 		} else {
251 251
 			// Loop through each POST
252
-			foreach ( $_POST as $key => $value ) {
252
+			foreach ($_POST as $key => $value) {
253 253
 				// Encode the value and append the data
254
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
254
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
255 255
 			}
256 256
 		}
257 257
 	}
258 258
 
259 259
 	// Convert collected post data to an array
260
-	parse_str( $encoded_data, $encoded_data_array );
260
+	parse_str($encoded_data, $encoded_data_array);
261 261
 
262
-	foreach ( $encoded_data_array as $key => $value ) {
263
-		if ( false !== strpos( $key, 'amp;' ) ) {
264
-			$new_key = str_replace( '&amp;', '&', $key );
265
-			$new_key = str_replace( 'amp;', '&' , $new_key );
262
+	foreach ($encoded_data_array as $key => $value) {
263
+		if (false !== strpos($key, 'amp;')) {
264
+			$new_key = str_replace('&amp;', '&', $key);
265
+			$new_key = str_replace('amp;', '&', $new_key);
266 266
 
267
-			unset( $encoded_data_array[ $key ] );
268
-			$encoded_data_array[ $new_key ] = $value;
267
+			unset($encoded_data_array[$key]);
268
+			$encoded_data_array[$new_key] = $value;
269 269
 		}
270 270
 	}
271 271
 
272 272
 	// Get the PayPal redirect uri
273
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
273
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
274 274
 
275
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
275
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
276 276
 		// Validate the IPN
277 277
 
278
-		$remote_post_vars      = array(
278
+		$remote_post_vars = array(
279 279
 			'method'           => 'POST',
280 280
 			'timeout'          => 45,
281 281
 			'redirection'      => 5,
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		);
294 294
 
295 295
 		// Get response
296
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
296
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
297 297
 
298
-		if ( is_wp_error( $api_response ) ) {
299
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
298
+		if (is_wp_error($api_response)) {
299
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
300 300
 			return; // Something went wrong
301 301
 		}
302 302
 
303
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
304
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
303
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
304
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
305 305
 			return; // Response not okay
306 306
 		}
307 307
 	}
308 308
 
309 309
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
310
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
311 311
 		return;
312 312
 
313 313
 	$defaults = array(
@@ -315,215 +315,215 @@  discard block
 block discarded – undo
315 315
 		'payment_status' => ''
316 316
 	);
317 317
 
318
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
318
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
319 319
 
320
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
320
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
321 321
     
322
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
322
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
323 323
 
324
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
324
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
325 325
 		// Allow PayPal IPN types to be processed separately
326
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
326
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
327 327
 	} else {
328 328
 		// Fallback to web accept just in case the txn_type isn't present
329
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
330 330
 	}
331 331
 	exit;
332 332
 }
333
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
333
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
334 334
 
335
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
336
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
335
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
336
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
337 337
 		return;
338 338
 	}
339 339
 
340
-	if( empty( $invoice_id ) ) {
340
+	if (empty($invoice_id)) {
341 341
 		return;
342 342
 	}
343 343
 
344 344
 	// Collect payment details
345
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
345
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
346 346
 	$paypal_amount  = $data['mc_gross'];
347
-	$payment_status = strtolower( $data['payment_status'] );
348
-	$currency_code  = strtolower( $data['mc_currency'] );
349
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
350
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
347
+	$payment_status = strtolower($data['payment_status']);
348
+	$currency_code  = strtolower($data['mc_currency']);
349
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
350
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
351 351
 
352
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
352
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
353 353
 		return; // this isn't a PayPal standard IPN
354 354
 	}
355 355
 
356 356
 	// Verify payment recipient
357
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
358
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
359
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
360
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
357
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
358
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
359
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
360
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'));
361 361
 		return;
362 362
 	}
363 363
 
364 364
 	// Verify payment currency
365
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
366
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
367
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
368
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
365
+	if ($currency_code != strtolower($payment_meta['currency'])) {
366
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
367
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
368
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'));
369 369
 		return;
370 370
 	}
371 371
 
372
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
372
+	if (!wpinv_get_payment_user_email($invoice_id)) {
373 373
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
374 374
 		// No email associated with purchase, so store from PayPal
375
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
375
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
376 376
 
377 377
 		// Setup and store the customer's details
378 378
 		$user_info = array(
379 379
 			'user_id'    => '-1',
380
-			'email'      => sanitize_text_field( $data['payer_email'] ),
381
-			'first_name' => sanitize_text_field( $data['first_name'] ),
382
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
380
+			'email'      => sanitize_text_field($data['payer_email']),
381
+			'first_name' => sanitize_text_field($data['first_name']),
382
+			'last_name'  => sanitize_text_field($data['last_name']),
383 383
 			'discount'   => '',
384 384
 		);
385
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
386
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
387
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
388
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
389
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
385
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
386
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
387
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
388
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
389
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
390 390
 
391 391
 		$payment_meta['user_info'] = $user_info;
392
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
392
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
393 393
 	}
394 394
 
395
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
395
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
396 396
 		// Process a refund
397
-		wpinv_process_paypal_refund( $data, $invoice_id );
397
+		wpinv_process_paypal_refund($data, $invoice_id);
398 398
 	} else {
399
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
399
+		if (get_post_status($invoice_id) == 'publish') {
400 400
 			return; // Only paid payments once
401 401
 		}
402 402
 
403 403
 		// Retrieve the total purchase amount (before PayPal)
404
-		$payment_amount = wpinv_payment_total( $invoice_id );
404
+		$payment_amount = wpinv_payment_total($invoice_id);
405 405
 
406
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
406
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
407 407
 			// The prices don't match
408
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
409
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
410
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
408
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
409
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
410
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'));
411 411
 			return;
412 412
 		}
413
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
413
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
414 414
 			// Purchase keys don't match
415
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
416
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
417
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
415
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
416
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
417
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'));
418 418
 			return;
419 419
 		}
420 420
 
421
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
422
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
423
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
424
-			wpinv_update_payment_status( $invoice_id, 'publish' );
425
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
421
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
422
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']));
423
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
424
+			wpinv_update_payment_status($invoice_id, 'publish');
425
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
426 426
 			// Look for possible pending reasons, such as an echeck
427 427
 			$note = '';
428 428
 
429
-			switch( strtolower( $data['pending_reason'] ) ) {
429
+			switch (strtolower($data['pending_reason'])) {
430 430
 				case 'echeck' :
431
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
431
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
432 432
 					break;
433 433
 				
434 434
                 case 'address' :
435
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
435
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
436 436
 					break;
437 437
 				
438 438
                 case 'intl' :
439
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
439
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
440 440
 					break;
441 441
 				
442 442
                 case 'multi-currency' :
443
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
443
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
444 444
 					break;
445 445
 				
446 446
                 case 'paymentreview' :
447 447
                 case 'regulatory_review' :
448
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
448
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
449 449
 					break;
450 450
 				
451 451
                 case 'unilateral' :
452
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
452
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
453 453
 					break;
454 454
 				
455 455
                 case 'upgrade' :
456
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
456
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
457 457
 					break;
458 458
 				
459 459
                 case 'verify' :
460
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
460
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
461 461
 					break;
462 462
 
463 463
 				case 'other' :
464
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
464
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
465 465
 					break;
466 466
 			}
467 467
 
468
-			if ( ! empty( $note ) ) {
469
-				wpinv_insert_payment_note( $invoice_id, $note );
468
+			if (!empty($note)) {
469
+				wpinv_insert_payment_note($invoice_id, $note);
470 470
 			}
471 471
 		} else {
472
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
472
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status));
473 473
 		}
474 474
 	}
475 475
 }
476
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
476
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
477 477
 
478 478
 // Process PayPal subscription sign ups
479
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
479
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
480 480
 
481 481
 // Process PayPal subscription payments
482
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
482
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
483 483
 
484 484
 // Process PayPal subscription cancellations
485
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
485
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
486 486
 
487 487
 // Process PayPal subscription end of term notices
488
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
488
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
489 489
 
490 490
 // Process PayPal payment failed
491
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
491
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
492 492
 
493 493
 
494 494
 /**
495 495
  * Process the subscription started IPN.
496 496
  */
497
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
498
-    $parent_invoice_id = absint( $ipn_data['custom'] );
499
-    if( empty( $parent_invoice_id ) ) {
497
+function wpinv_process_paypal_subscr_signup($ipn_data) {
498
+    $parent_invoice_id = absint($ipn_data['custom']);
499
+    if (empty($parent_invoice_id)) {
500 500
         return;
501 501
     }
502 502
 
503
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
504
-    if ( empty( $invoice ) ) {
503
+    $invoice = wpinv_get_invoice($parent_invoice_id);
504
+    if (empty($invoice)) {
505 505
         return;
506 506
     }
507 507
 
508
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
509
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) );
510
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] );
508
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
509
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']));
510
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']);
511 511
     }
512 512
     
513
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
513
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
514 514
     sleep(1);
515
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) );
515
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']));
516 516
     
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
 
522
-    $cart_details   = $invoice->cart_details;
522
+    $cart_details = $invoice->cart_details;
523 523
 
524
-    if ( !empty( $cart_details ) ) {
525
-        foreach ( $cart_details as $cart_item ) {
526
-            $item = new WPInv_Item( $cart_item['id'] );
524
+    if (!empty($cart_details)) {
525
+        foreach ($cart_details as $cart_item) {
526
+            $item = new WPInv_Item($cart_item['id']);
527 527
             
528 528
             $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active';
529 529
             
@@ -532,15 +532,15 @@  discard block
 block discarded – undo
532 532
                 'status'            => $status,
533 533
                 'period'            => $item->get_recurring_period(),
534 534
                 'initial_amount'    => $invoice->get_total(),
535
-                'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
535
+                'recurring_amount'  => $invoice->get_recurring_details('total'),
536 536
                 'interval'          => $item->get_recurring_interval(),
537 537
                 'bill_times'        => $item->get_recurring_limit(),
538
-                'expiration'        => $invoice->get_new_expiration( $cart_item['id'] ),
538
+                'expiration'        => $invoice->get_new_expiration($cart_item['id']),
539 539
                 'profile_id'        => $ipn_data['subscr_id'],
540
-                'created'           => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) )
540
+                'created'           => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date']))
541 541
             );
542 542
             
543
-            if ( $item->has_free_trial() ) {
543
+            if ($item->has_free_trial()) {
544 544
                 $args['trial_period']      = $item->get_trial_period();
545 545
                 $args['trial_interval']    = $item->get_trial_interval();
546 546
             } else {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             }
550 550
             
551 551
 
552
-            $subscription->update_subscription( $args );
552
+            $subscription->update_subscription($args);
553 553
         }
554 554
     }
555 555
 }
@@ -557,39 +557,39 @@  discard block
 block discarded – undo
557 557
 /**
558 558
  * Process the subscription payment received IPN.
559 559
  */
560
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
561
-    $parent_invoice_id = absint( $ipn_data['custom'] );
560
+function wpinv_process_paypal_subscr_payment($ipn_data) {
561
+    $parent_invoice_id = absint($ipn_data['custom']);
562 562
     
563
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
564
-    if ( false === $subscription ) {
563
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
564
+    if (false === $subscription) {
565 565
         return;
566 566
     }
567 567
     
568
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
569
-    $signup_date    = strtotime( $subscription->get_subscription_created() );
570
-    $today          = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) );
568
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
569
+    $signup_date    = strtotime($subscription->get_subscription_created());
570
+    $today          = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date']));
571 571
 
572 572
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
573
-    if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
574
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
573
+    if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
574
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
575 575
         sleep(1);
576 576
         
577 577
         // This is the very first payment
578
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
579
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
578
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
579
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
580 580
         return;
581 581
     }
582 582
     
583
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
583
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
584 584
         return; // Payment already recorded
585 585
     }
586 586
 
587
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
587
+    $currency_code = strtolower($ipn_data['mc_currency']);
588 588
 
589 589
     // verify details
590
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
590
+    if ($currency_code != strtolower(wpinv_get_currency())) {
591 591
         // the currency code is invalid
592
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
592
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
593 593
         return;
594 594
     }
595 595
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         'transaction_id' => $ipn_data['txn_id']
599 599
     );
600 600
     
601
-    $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args );
601
+    $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args);
602 602
     
603
-    if ( !empty( $invoice ) ) {
603
+    if (!empty($invoice)) {
604 604
         sleep(1);
605
-        wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
605
+        wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
606 606
 
607 607
         $invoice->renew_subscription();
608 608
     }
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription canceled IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription expired IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_eot($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
@@ -637,45 +637,45 @@  discard block
 block discarded – undo
637 637
 /**
638 638
  * Process the subscription payment failed IPN.
639 639
  */
640
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
641
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
640
+function wpinv_process_paypal_subscr_failed($ipn_data) {
641
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
642 642
 
643
-    if( false === $subscription ) {
643
+    if (false === $subscription) {
644 644
         return;
645 645
     }
646 646
 
647 647
     $subscription->failing_subscription();
648 648
 
649
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
649
+    do_action('wpinv_recurring_payment_failed', $subscription);
650 650
 }
651 651
 
652 652
 /**
653 653
  * Retrieve the subscription this IPN notice is for.
654 654
  */
655
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
656
-    $parent_invoice_id = absint( $ipn_data['custom'] );
655
+function wpinv_get_paypal_subscription($ipn_data = array()) {
656
+    $parent_invoice_id = absint($ipn_data['custom']);
657 657
 
658
-    if( empty( $parent_invoice_id ) ) {
658
+    if (empty($parent_invoice_id)) {
659 659
         return false;
660 660
     }
661 661
 
662
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
663
-    if ( empty( $invoice ) ) {
662
+    $invoice = wpinv_get_invoice($parent_invoice_id);
663
+    if (empty($invoice)) {
664 664
         return false;
665 665
     }
666 666
 
667
-    $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true );
667
+    $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true);
668 668
 
669
-    if ( empty( $subscription ) ) {
670
-        $subs         = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) );
671
-        $subscription = reset( $subs );
669
+    if (empty($subscription)) {
670
+        $subs         = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1));
671
+        $subscription = reset($subs);
672 672
 
673
-        if ( $subscription && $subscription->ID > 0 ) {
673
+        if ($subscription && $subscription->ID > 0) {
674 674
             // Update the profile ID so it is set for future renewals
675
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
675
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
676 676
         } else {
677 677
             $subscription = $invoice;
678
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
678
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
679 679
             // No subscription found with a matching payment ID, bail
680 680
             //return false;
681 681
         }
@@ -685,39 +685,39 @@  discard block
 block discarded – undo
685 685
 
686 686
 }
687 687
 
688
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
688
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
689 689
 	// Collect payment details
690 690
 
691
-	if( empty( $invoice_id ) ) {
691
+	if (empty($invoice_id)) {
692 692
 		return;
693 693
 	}
694 694
 
695
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
695
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
696 696
 		return; // Only refund payments once
697 697
 	}
698 698
 
699
-	$payment_amount = wpinv_payment_total( $invoice_id );
699
+	$payment_amount = wpinv_payment_total($invoice_id);
700 700
 	$refund_amount  = $data['mc_gross'] * -1;
701 701
 
702
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
703
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
702
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
703
+		wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id']));
704 704
 		return; // This is a partial refund
705 705
 	}
706 706
 
707
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
708
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
709
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
707
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']));
708
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']));
709
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
710 710
 }
711 711
 
712
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
713
-    if ( is_ssl() || ! $ssl_check ) {
712
+function wpinv_get_paypal_redirect($ssl_check = false) {
713
+    if (is_ssl() || !$ssl_check) {
714 714
         $protocol = 'https://';
715 715
     } else {
716 716
         $protocol = 'http://';
717 717
     }
718 718
 
719 719
     // Check the current payment mode
720
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
720
+    if (wpinv_is_test_mode('paypal')) {
721 721
         // Test mode
722 722
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
723 723
     } else {
@@ -725,67 +725,67 @@  discard block
 block discarded – undo
725 725
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
726 726
     }
727 727
 
728
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
728
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
729 729
 }
730 730
 
731
-function wpinv_paypal_success_page_content( $content ) {
731
+function wpinv_paypal_success_page_content($content) {
732 732
     global $wpi_invoice;
733 733
     
734 734
     $session = wpinv_get_checkout_session();
735 735
 
736
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
736
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
737 737
         return $content;
738 738
     }
739 739
 
740
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
740
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
741 741
 
742
-    if ( empty(  $invoice_id ) ) {
742
+    if (empty($invoice_id)) {
743 743
         return $content;
744 744
     }
745 745
 
746
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
746
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
747 747
     
748
-    if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) {
748
+    if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) {
749 749
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
750 750
         ob_start();
751
-        wpinv_get_template_part( 'wpinv-payment-processing' );
751
+        wpinv_get_template_part('wpinv-payment-processing');
752 752
         $content = ob_get_clean();
753 753
     }
754 754
 
755 755
     return $content;
756 756
 }
757
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
757
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
758 758
 
759
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
759
+function wpinv_paypal_get_transaction_id($invoice_id) {
760 760
     $transaction_id = '';
761
-    $notes = wpinv_get_invoice_notes( $invoice_id );
761
+    $notes = wpinv_get_invoice_notes($invoice_id);
762 762
 
763
-    foreach ( $notes as $note ) {
764
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
763
+    foreach ($notes as $note) {
764
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
765 765
             $transaction_id = $match[1];
766 766
             continue;
767 767
         }
768 768
     }
769 769
 
770
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
770
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
771 771
 }
772
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
772
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
773 773
 
774
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
775
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
774
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
775
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
776 776
         $transaction_url = $invoice->get_view_url();
777 777
     } else {
778
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
778
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
779 779
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
780 780
     }
781 781
 
782
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
782
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
783 783
 
784
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
784
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
785 785
 }
786
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
786
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
787 787
 
788 788
 function wpinv_gateway_paypal_button_label($label) {
789
-    return __( 'Proceed to PayPal', 'invoicing' );
789
+    return __('Proceed to PayPal', 'invoicing');
790 790
 }
791
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
792 791
\ No newline at end of file
792
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
793 793
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 1 patch
Spacing   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-8">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-8">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-2">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-8">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
     
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,174 +83,174 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
         
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
         
104 104
         $errors = wpinv_get_errors();
105 105
     
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
             
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
             
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
                 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
             
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
             
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
                 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
             
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
             
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
             
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
             
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
             
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
             
160 160
             try {
161
-                if ( $is_recurring ) {
161
+                if ($is_recurring) {
162 162
                     $response = $authorizeAIM->authorizeOnly();
163 163
                 } else {
164 164
                     $response = $authorizeAIM->authorizeAndCapture();
165 165
                 }
166 166
                 
167
-                if ( $response->approved || $response->held ) {
168
-                    if ( $response->approved ) {
169
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
167
+                if ($response->approved || $response->held) {
168
+                    if ($response->approved) {
169
+                        wpinv_update_payment_status($invoice_id, 'publish');
170 170
                     }
171
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
171
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
172 172
                     
173
-                    $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code );
173
+                    $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code);
174 174
                     
175
-                    wpinv_insert_payment_note( $invoice_id, $message );
175
+                    wpinv_insert_payment_note($invoice_id, $message);
176 176
                     
177
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
177
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
178 178
                     
179 179
                     wpinv_clear_errors();
180 180
                     wpinv_empty_cart();
181 181
                     
182
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
182
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
183 183
                 } else {
184
-                    if ( !empty( $response->response_reason_text ) ) {
185
-                        $error = __( $response->response_reason_text, 'invoicing' );
186
-                    } else if ( !empty( $response->error_message ) ) {
187
-                        $error = __( $response->error_message, 'invoicing' );
184
+                    if (!empty($response->response_reason_text)) {
185
+                        $error = __($response->response_reason_text, 'invoicing');
186
+                    } else if (!empty($response->error_message)) {
187
+                        $error = __($response->error_message, 'invoicing');
188 188
                     } else {
189
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
189
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
190 190
                     } 
191 191
                     
192
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
192
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
193 193
                     
194
-                    wpinv_set_error( 'payment_error', $error );
195
-                    wpinv_record_gateway_error( $error, $response );
196
-                    wpinv_insert_payment_note( $invoice_id, $error );
194
+                    wpinv_set_error('payment_error', $error);
195
+                    wpinv_record_gateway_error($error, $response);
196
+                    wpinv_insert_payment_note($invoice_id, $error);
197 197
                     
198
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
198
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
199 199
                 }
200
-            } catch ( AuthorizeNetException $e ) {
201
-                wpinv_set_error( 'request_error', $e->getMessage() );
202
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
203
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
200
+            } catch (AuthorizeNetException $e) {
201
+                wpinv_set_error('request_error', $e->getMessage());
202
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
203
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
204 204
             }
205 205
         } else {
206
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
206
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
207 207
         }
208 208
     } else {
209
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
210
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
209
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
210
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
211 211
     }
212 212
 }
213
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
213
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
214 214
 
215
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
216
-    if ( empty( $subscription_id ) ) {
215
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
216
+    if (empty($subscription_id)) {
217 217
         return false;
218 218
     }
219 219
     
220 220
     try {
221 221
         $authnetXML = wpinv_authorizenet_XML();
222
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
222
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
223 223
 
224 224
         return $authnetXML->isSuccessful();
225
-    } catch( Exception $e ) {
226
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
225
+    } catch (Exception $e) {
226
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
227 227
     }
228 228
     
229 229
     return false;
230 230
 }
231 231
 
232
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
233
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
234
-    if ( empty( $authorizenet_md5_hash ) ) {
232
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
233
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
234
+    if (empty($authorizenet_md5_hash)) {
235 235
         return true;
236 236
     }
237 237
     
238
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
238
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
239 239
     
240
-    return hash_equals( $compare_md5, $md5_hash );
240
+    return hash_equals($compare_md5, $md5_hash);
241 241
 }
242 242
 
243 243
 function wpinv_authorizenet_AIM() {
244
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
245
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
244
+    if (!class_exists('AuthorizeNetException')) {
245
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
246 246
     }
247 247
     
248
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
248
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
249 249
     
250
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
251
-        $authorizeAIM->setSandbox( true );
250
+    if (wpinv_is_test_mode('authorizenet')) {
251
+        $authorizeAIM->setSandbox(true);
252 252
     } else {
253
-        $authorizeAIM->setSandbox( false );
253
+        $authorizeAIM->setSandbox(false);
254 254
     }
255 255
     
256 256
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -259,164 +259,164 @@  discard block
 block discarded – undo
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_XML() {
262
-    if ( !class_exists( 'AuthnetXML' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
262
+    if (!class_exists('AuthnetXML')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
264 264
     }
265 265
     
266
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
266
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
267 267
     
268 268
     return $authnetXML;
269 269
 }
270 270
 
271
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
272
-    if ( empty( $response ) || empty( $invoice ) ) {
271
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
272
+    if (empty($response) || empty($invoice)) {
273 273
         return false;
274 274
     }
275 275
     
276
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
277
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
276
+    if ($invoice->is_recurring() && !empty($response->approved)) {
277
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
278 278
 
279
-        if ( !empty( $subscription ) && $subscription->isSuccessful() ) {
280
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
279
+        if (!empty($subscription) && $subscription->isSuccessful()) {
280
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
281 281
             
282
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
282
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
283 283
             
284
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
284
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
285 285
         } else {
286
-            if ( isset( $subscription->messages->message ) ) {
286
+            if (isset($subscription->messages->message)) {
287 287
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
288
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
288
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
289 289
             } else {
290
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
291
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
290
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
291
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
292 292
             }
293 293
             
294
-            wpinv_record_gateway_error( $error, $subscription );
294
+            wpinv_record_gateway_error($error, $subscription);
295 295
             
296
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) );
296
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error));
297 297
         }
298 298
     }
299 299
 }
300
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
300
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
301 301
 
302
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
303
-    if ( empty( $invoice ) ) {
302
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
303
+    if (empty($invoice)) {
304 304
         return false;
305 305
     }
306 306
     
307
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
307
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
308 308
     
309 309
     try {
310 310
         $authnetXML = wpinv_authorizenet_XML();
311
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
312
-    } catch( Exception $e ) {
311
+        $authnetXML->ARBCreateSubscriptionRequest($params);
312
+    } catch (Exception $e) {
313 313
         $authnetXML = array();
314
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
314
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
315 315
     }
316 316
     
317 317
     return $authnetXML;
318 318
 }
319 319
 
320
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
321
-    if ( empty( $invoice ) ) {
320
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
321
+    if (empty($invoice)) {
322 322
         return false;
323 323
     }
324 324
     
325
-    $subscription_item = $invoice->get_recurring( true );
326
-    if ( empty( $subscription_item ) ) {
325
+    $subscription_item = $invoice->get_recurring(true);
326
+    if (empty($subscription_item)) {
327 327
         return false;
328 328
     }
329 329
     
330
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
330
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
331 331
     $subscription_name  = $invoice->get_subscription_name();
332
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
333
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
332
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
333
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
334 334
     $interval           = $subscription_item->get_recurring_interval();
335 335
     $period             = $subscription_item->get_recurring_period();
336 336
     $bill_times         = (int)$subscription_item->get_recurring_limit();
337 337
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
338 338
     
339
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
339
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
340 340
     $interval           = $time_period['interval'];
341 341
     $period             = $time_period['period'];
342 342
     
343 343
     $current_tz = date_default_timezone_get();
344
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
-    $today = date( 'Y-m-d' );
346
-    date_default_timezone_set( $current_tz );
344
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
+    $today = date('Y-m-d');
346
+    date_default_timezone_set($current_tz);
347 347
     
348 348
     $free_trial = $invoice->is_free_trial();
349
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
349
+    if ($free_trial && $subscription_item->has_free_trial()) {
350 350
         $trial_interval    = $subscription_item->get_trial_interval();
351
-        $trial_period      = $subscription_item->get_trial_period( true );
351
+        $trial_period      = $subscription_item->get_trial_period(true);
352 352
     }
353 353
     
354 354
     $subscription = array();
355 355
     $subscription['name'] = $subscription_name;
356 356
     
357 357
     $subscription['paymentSchedule'] = array(
358
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
358
+        'interval'         => array('length' => $interval, 'unit' => $period),
359 359
         'startDate'        => $today,
360 360
         'totalOccurrences' => $bill_times,
361
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
361
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
362 362
     );
363 363
     
364 364
     $subscription['amount'] = $recurring_amount;
365 365
     $subscription['trialAmount'] = $initial_amount;
366
-    $subscription['payment'] = array( 'creditCard' => $card_details );
367
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
368
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
366
+    $subscription['payment'] = array('creditCard' => $card_details);
367
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
368
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
369 369
     
370 370
     $subscription['billTo'] = array(
371 371
         'firstName' => $invoice->get_first_name(),
372 372
         'lastName'  => $invoice->get_last_name(),
373 373
         'company'   => $invoice->company,
374
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
374
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
375 375
         'city'      => $invoice->city,
376 376
         'state'     => $invoice->state,
377 377
         'zip'       => $invoice->zip,
378 378
         'country'   => $invoice->country,
379 379
     );
380 380
     
381
-    $params = array( 'subscription' => $subscription );
381
+    $params = array('subscription' => $subscription);
382 382
     
383
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
383
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
384 384
 }
385 385
 
386
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
387
-    $card_defaults      = array(
386
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
387
+    $card_defaults = array(
388 388
         'cc_owner'          => null,
389 389
         'cc_number'         => null,
390 390
         'cc_expire_month'   => null,
391 391
         'cc_expire_year'    => null,
392 392
         'cc_cvv2'           => null,
393 393
     );
394
-    $card_info = wp_parse_args( $card_info, $card_defaults );
394
+    $card_info = wp_parse_args($card_info, $card_defaults);
395 395
         
396 396
     $card_details = array(
397
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
398
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
399
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
397
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
398
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
399
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
400 400
     );
401 401
 
402 402
     return $card_details;
403 403
 }
404 404
 
405
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
406
-    if ( empty( $invoice ) || empty( $subscription ) ) {
405
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
406
+    if (empty($invoice) || empty($subscription)) {
407 407
         return false;
408 408
     }
409 409
     
410
-    $subscription_item = $invoice->get_recurring( true );
411
-    if ( empty( $subscription_item ) ) {
410
+    $subscription_item = $invoice->get_recurring(true);
411
+    if (empty($subscription_item)) {
412 412
         return false;
413 413
     }
414 414
     
415 415
     $invoice_id         = $invoice->ID;
416 416
     $subscriptionId     = (array)$subscription->subscriptionId;
417
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id;
417
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id;
418 418
 
419
-    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) );
419
+    wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id));
420 420
     
421 421
     $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active';
422 422
     
@@ -424,16 +424,16 @@  discard block
 block discarded – undo
424 424
         'profile_id'        => $subscription_id,
425 425
         'item_id'           => $subscription_item->ID,
426 426
         'initial_amount'    => $invoice->get_total(),
427
-        'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
427
+        'recurring_amount'  => $invoice->get_recurring_details('total'),
428 428
         'period'            => $subscription_item->get_recurring_period(),
429 429
         'interval'          => $subscription_item->get_recurring_interval(),
430 430
         'bill_times'        => $subscription_item->get_recurring_limit(),
431
-        'expiration'        => $invoice->get_new_expiration( $subscription_item->ID ),
431
+        'expiration'        => $invoice->get_new_expiration($subscription_item->ID),
432 432
         'status'            => $status,
433
-        'created'           => current_time( 'mysql', 0 )
433
+        'created'           => current_time('mysql', 0)
434 434
     );
435 435
     
436
-    if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) {
436
+    if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) {
437 437
         $args['trial_period']      = $subscription_item->get_trial_period();
438 438
         $args['trial_interval']    = $subscription_item->get_trial_interval();
439 439
     } else {
@@ -441,58 +441,58 @@  discard block
 block discarded – undo
441 441
         $args['trial_interval']    = 0;
442 442
     }
443 443
     
444
-    return $invoice->update_subscription( $args );
444
+    return $invoice->update_subscription($args);
445 445
 }
446 446
 
447
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
448
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
447
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
448
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
449 449
         $error = false;
450 450
         
451
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
451
+        if (empty($post['authorizenet']['cc_owner'])) {
452 452
             $error = true;
453
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
453
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
454 454
         }
455
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
455
+        if (empty($post['authorizenet']['cc_number'])) {
456 456
             $error = true;
457
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
457
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
458 458
         }
459
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
459
+        if (empty($post['authorizenet']['cc_expire_month'])) {
460 460
             $error = true;
461
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
461
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
462 462
         }
463
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
463
+        if (empty($post['authorizenet']['cc_expire_year'])) {
464 464
             $error = true;
465
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
465
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
466 466
         }
467
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
467
+        if (empty($post['authorizenet']['cc_cvv2'])) {
468 468
             $error = true;
469
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
469
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
470 470
         }
471 471
         
472
-        if ( $error ) {
472
+        if ($error) {
473 473
             return;
474 474
         }
475 475
         
476 476
         $invoice = wpinv_get_invoice_cart();
477 477
         
478
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
479
-            $subscription_item = $invoice->get_recurring( true );
478
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
479
+            $subscription_item = $invoice->get_recurring(true);
480 480
             
481 481
             $interval   = $subscription_item->get_recurring_interval();
482 482
             $period     = $subscription_item->get_recurring_period();
483 483
             
484
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
485
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
484
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
485
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
486 486
             }
487 487
         }
488 488
     }
489 489
 }
490
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
490
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
491 491
 
492
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
493
-    $subscription_interval = absint( $subscription_interval );
492
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
493
+    $subscription_interval = absint($subscription_interval);
494 494
 
495
-    switch( $subscription_period ) {
495
+    switch ($subscription_period) {
496 496
         case 'W':
497 497
         case 'week':
498 498
         case 'weeks':
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
         case 'M':
503 503
         case 'month':
504 504
         case 'months':
505
-            if ( $subscription_interval > 12 ) {
505
+            if ($subscription_interval > 12) {
506 506
                 $subscription_interval = 12;
507 507
             }
508 508
             
509 509
             $interval = $subscription_interval;
510 510
             $period   = 'months';
511 511
             
512
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
512
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
513 513
                 $interval = $subscription_interval * 30;
514 514
                 $period   = 'days';
515 515
             }
@@ -526,40 +526,40 @@  discard block
 block discarded – undo
526 526
             break;
527 527
     }
528 528
 
529
-    return compact( 'interval', 'period' );
529
+    return compact('interval', 'period');
530 530
 }
531 531
 
532 532
 function wpinv_authorizenet_process_ipn() {
533
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
533
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
534 534
         return;
535 535
     }
536 536
     
537
-    $subscription_id = intval( $_POST['x_subscription_id'] );
537
+    $subscription_id = intval($_POST['x_subscription_id']);
538 538
     
539
-    if ( $subscription_id ) {
540
-        $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
541
-        $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
542
-        $response_code  = intval( $_POST['x_response_code'] );
543
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
539
+    if ($subscription_id) {
540
+        $transaction_id = sanitize_text_field($_POST['x_trans_id']);
541
+        $renewal_amount = sanitize_text_field($_POST['x_amount']);
542
+        $response_code  = intval($_POST['x_response_code']);
543
+        $reason_code    = intval($_POST['x_response_reason_code']);
544 544
 
545
-        if ( 1 == $response_code ) {
545
+        if (1 == $response_code) {
546 546
             // Approved
547
-            do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id );
548
-        } else if ( 2 == $response_code ) {
547
+            do_action('wpinv_authorizenet_renewal_payment', $transaction_id);
548
+        } else if (2 == $response_code) {
549 549
             // Declined
550
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
551
-            do_action( 'wpinv_authorizenet_renewal_error', $transaction_id );
552
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
550
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
551
+            do_action('wpinv_authorizenet_renewal_error', $transaction_id);
552
+        } else if (3 == $response_code || 8 == $reason_code) {
553 553
             // An expired card
554
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
555
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id );
554
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
555
+            do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id);
556 556
 
557 557
         } else {
558 558
             // Other Error
559
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
559
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
560 560
         }
561 561
         
562 562
         exit;
563 563
     }
564 564
 }
565
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
566 565
\ No newline at end of file
566
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
567 567
\ No newline at end of file
Please login to merge, or discard this patch.