Passed
Pull Request — master (#98)
by Kiran
04:35
created
includes/class-wpinv-item.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
     public $filter;
48 48
 
49 49
 
50
-    public function __construct( $_id = false, $_args = array() ) {
51
-        $item = WP_Post::get_instance( $_id );
52
-        return $this->setup_item( $item );
50
+    public function __construct($_id = false, $_args = array()) {
51
+        $item = WP_Post::get_instance($_id);
52
+        return $this->setup_item($item);
53 53
     }
54 54
 
55
-    private function setup_item( $item ) {
56
-        if( ! is_object( $item ) ) {
55
+    private function setup_item($item) {
56
+        if (!is_object($item)) {
57 57
             return false;
58 58
         }
59 59
 
60
-        if( ! is_a( $item, 'WP_Post' ) ) {
60
+        if (!is_a($item, 'WP_Post')) {
61 61
             return false;
62 62
         }
63 63
 
64
-        if( 'wpi_item' !== $item->post_type ) {
64
+        if ('wpi_item' !== $item->post_type) {
65 65
             return false;
66 66
         }
67 67
 
68
-        foreach ( $item as $key => $value ) {
69
-            switch ( $key ) {
68
+        foreach ($item as $key => $value) {
69
+            switch ($key) {
70 70
                 default:
71 71
                     $this->$key = $value;
72 72
                     break;
@@ -76,38 +76,38 @@  discard block
 block discarded – undo
76 76
         return true;
77 77
     }
78 78
 
79
-    public function __get( $key ) {
80
-        if ( method_exists( $this, 'get_' . $key ) ) {
81
-            return call_user_func( array( $this, 'get_' . $key ) );
79
+    public function __get($key) {
80
+        if (method_exists($this, 'get_' . $key)) {
81
+            return call_user_func(array($this, 'get_' . $key));
82 82
         } else {
83
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
83
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
84 84
         }
85 85
     }
86 86
 
87
-    public function create( $data = array(), $wp_error = false ) {
88
-        if ( $this->ID != 0 ) {
87
+    public function create($data = array(), $wp_error = false) {
88
+        if ($this->ID != 0) {
89 89
             return false;
90 90
         }
91 91
 
92 92
         $defaults = array(
93 93
             'post_type'   => 'wpi_item',
94 94
             'post_status' => 'draft',
95
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
95
+            'post_title'  => __('New Invoice Item', 'invoicing')
96 96
         );
97 97
 
98
-        $args = wp_parse_args( $data, $defaults );
98
+        $args = wp_parse_args($data, $defaults);
99 99
 
100
-        do_action( 'wpinv_item_pre_create', $args );
100
+        do_action('wpinv_item_pre_create', $args);
101 101
 
102
-        $id = wp_insert_post( $args, $wp_error );
102
+        $id = wp_insert_post($args, $wp_error);
103 103
         if ($wp_error && is_wp_error($id)) {
104 104
             return $id;
105 105
         }
106
-        if ( !$id ) {
106
+        if (!$id) {
107 107
             return false;
108 108
         }
109 109
         
110
-        $item = WP_Post::get_instance( $id );
110
+        $item = WP_Post::get_instance($id);
111 111
         
112 112
         if (!empty($item) && !empty($data['meta'])) {
113 113
             $this->ID = $item->ID;
@@ -115,47 +115,47 @@  discard block
 block discarded – undo
115 115
         }
116 116
         
117 117
         // Set custom id if not set.
118
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
119
-            $this->save_metas( array( 'custom_id' => $id ) );
118
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
119
+            $this->save_metas(array('custom_id' => $id));
120 120
         }
121 121
 
122
-        do_action( 'wpinv_item_create', $id, $args );
122
+        do_action('wpinv_item_create', $id, $args);
123 123
 
124
-        return $this->setup_item( $item );
124
+        return $this->setup_item($item);
125 125
     }
126 126
     
127
-    public function update( $data = array(), $wp_error = false ) {
128
-        if ( !$this->ID > 0 ) {
127
+    public function update($data = array(), $wp_error = false) {
128
+        if (!$this->ID > 0) {
129 129
             return false;
130 130
         }
131 131
         
132 132
         $data['ID'] = $this->ID;
133 133
 
134
-        do_action( 'wpinv_item_pre_update', $data );
134
+        do_action('wpinv_item_pre_update', $data);
135 135
         
136
-        $id = wp_update_post( $data, $wp_error );
136
+        $id = wp_update_post($data, $wp_error);
137 137
         if ($wp_error && is_wp_error($id)) {
138 138
             return $id;
139 139
         }
140 140
         
141
-        if ( !$id ) {
141
+        if (!$id) {
142 142
             return false;
143 143
         }
144 144
 
145
-        $item = WP_Post::get_instance( $id );
145
+        $item = WP_Post::get_instance($id);
146 146
         if (!empty($item) && !empty($data['meta'])) {
147 147
             $this->ID = $item->ID;
148 148
             $this->save_metas($data['meta']);
149 149
         }
150 150
         
151 151
         // Set custom id if not set.
152
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
153
-            $this->save_metas( array( 'custom_id' => $id ) );
152
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
153
+            $this->save_metas(array('custom_id' => $id));
154 154
         }
155 155
 
156
-        do_action( 'wpinv_item_update', $id, $data );
156
+        do_action('wpinv_item_update', $id, $data);
157 157
 
158
-        return $this->setup_item( $item );
158
+        return $this->setup_item($item);
159 159
     }
160 160
 
161 161
     public function get_ID() {
@@ -163,119 +163,119 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     public function get_name() {
166
-        return get_the_title( $this->ID );
166
+        return get_the_title($this->ID);
167 167
     }
168 168
     
169 169
     public function get_title() {
170
-        return get_the_title( $this->ID );
170
+        return get_the_title($this->ID);
171 171
     }
172 172
     
173 173
     public function get_status() {
174
-        return get_post_status( $this->ID );
174
+        return get_post_status($this->ID);
175 175
     }
176 176
     
177 177
     public function get_summary() {
178
-        return get_the_excerpt( $this->ID );
178
+        return get_the_excerpt($this->ID);
179 179
     }
180 180
 
181 181
     public function get_price() {
182
-        if ( ! isset( $this->price ) ) {
183
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
182
+        if (!isset($this->price)) {
183
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
184 184
             
185
-            if ( $this->price ) {
186
-                $this->price = wpinv_sanitize_amount( $this->price );
185
+            if ($this->price) {
186
+                $this->price = wpinv_sanitize_amount($this->price);
187 187
             } else {
188 188
                 $this->price = 0;
189 189
             }
190 190
         }
191 191
         
192
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
192
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
193 193
     }
194 194
     
195 195
     public function get_vat_rule() {
196 196
         global $wpinv_euvat;
197 197
         
198
-        if( !isset( $this->vat_rule ) ) {
199
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
198
+        if (!isset($this->vat_rule)) {
199
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
200 200
 
201
-            if ( empty( $this->vat_rule ) ) {        
201
+            if (empty($this->vat_rule)) {        
202 202
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
203 203
             }
204 204
         }
205 205
         
206
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
206
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
207 207
     }
208 208
     
209 209
     public function get_vat_class() {
210
-        if( !isset( $this->vat_class ) ) {
211
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
210
+        if (!isset($this->vat_class)) {
211
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
212 212
 
213
-            if ( empty( $this->vat_class ) ) {        
213
+            if (empty($this->vat_class)) {        
214 214
                 $this->vat_class = '_standard';
215 215
             }
216 216
         }
217 217
         
218
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
218
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
219 219
     }
220 220
 
221 221
     public function get_type() {
222
-        if( ! isset( $this->type ) ) {
223
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
222
+        if (!isset($this->type)) {
223
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
224 224
 
225
-            if ( empty( $this->type ) ) {
225
+            if (empty($this->type)) {
226 226
                 $this->type = 'custom';
227 227
             }
228 228
         }
229 229
 
230
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
230
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
231 231
     }
232 232
     
233 233
     public function get_custom_id() {
234
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
234
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
235 235
 
236
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
236
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
237 237
     }
238 238
     
239 239
     public function get_custom_name() {
240
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
240
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
241 241
 
242
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
242
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
243 243
     }
244 244
     
245 245
     public function get_custom_singular_name() {
246
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
246
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
247 247
 
248
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
248
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
249 249
     }
250 250
     
251 251
     public function get_editable() {
252
-        $editable = get_post_meta( $this->ID, '_wpinv_editable', true );
252
+        $editable = get_post_meta($this->ID, '_wpinv_editable', true);
253 253
 
254
-        return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID );
254
+        return apply_filters('wpinv_item_get_editable', $editable, $this->ID);
255 255
     }
256 256
     
257 257
     public function get_excerpt() {
258
-        $excerpt = get_the_excerpt( $this->ID );
258
+        $excerpt = get_the_excerpt($this->ID);
259 259
         
260
-        return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID );
260
+        return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID);
261 261
     }
262 262
     
263 263
     public function get_is_recurring() {
264
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
264
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
265 265
 
266
-        return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID );
266
+        return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID);
267 267
 
268 268
     }
269 269
     
270
-    public function get_recurring_period( $full = false ) {
271
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
270
+    public function get_recurring_period($full = false) {
271
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
272 272
         
273
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
273
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
274 274
             $period = 'D';
275 275
         }
276 276
         
277
-        if ( $full ) {
278
-            switch( $period ) {
277
+        if ($full) {
278
+            switch ($period) {
279 279
                 case 'D':
280 280
                     $period = 'day';
281 281
                 break;
@@ -291,40 +291,40 @@  discard block
 block discarded – undo
291 291
             }
292 292
         }
293 293
 
294
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
294
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
295 295
     }
296 296
     
297 297
     public function get_recurring_interval() {
298
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
298
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
299 299
         
300
-        if ( !$interval > 0 ) {
300
+        if (!$interval > 0) {
301 301
             $interval = 1;
302 302
         }
303 303
 
304
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
304
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
305 305
     }
306 306
     
307 307
     public function get_recurring_limit() {
308
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
308
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
309 309
 
310
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
310
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
311 311
     }
312 312
     
313 313
     public function get_free_trial() {
314
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
314
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
315 315
 
316
-        return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID );
316
+        return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID);
317 317
     }
318 318
     
319
-    public function get_trial_period( $full = false ) {
320
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
319
+    public function get_trial_period($full = false) {
320
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
321 321
         
322
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
322
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
323 323
             $period = 'D';
324 324
         }
325 325
         
326
-        if ( $full ) {
327
-            switch( $period ) {
326
+        if ($full) {
327
+            switch ($period) {
328 328
                 case 'D':
329 329
                     $period = 'day';
330 330
                 break;
@@ -340,54 +340,54 @@  discard block
 block discarded – undo
340 340
             }
341 341
         }
342 342
 
343
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
343
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
344 344
     }
345 345
     
346 346
     public function get_trial_interval() {
347
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
347
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
348 348
         
349
-        if ( !$interval > 0 ) {
349
+        if (!$interval > 0) {
350 350
             $interval = 1;
351 351
         }
352 352
 
353
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
353
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
354 354
     }
355 355
     
356 356
     public function get_the_price() {
357
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
357
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
358 358
         
359
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
359
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
360 360
     }
361 361
     
362 362
     public function is_recurring() {
363 363
         $is_recurring = $this->get_is_recurring();
364 364
 
365
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
365
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
366 366
     }
367 367
     
368 368
     public function has_free_trial() {
369 369
         $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false;
370 370
 
371
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
371
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
372 372
     }
373 373
 
374 374
     public function is_free() {
375 375
         $is_free = false;
376 376
         
377
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
377
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
378 378
 
379
-        if ( (float)$price == 0 ) {
379
+        if ((float)$price == 0) {
380 380
             $is_free = true;
381 381
         }
382 382
 
383
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
383
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
384 384
 
385 385
     }
386 386
     
387 387
     public function is_package() {
388 388
         $is_package = $this->get_type() == 'package' ? true : false;
389 389
 
390
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
390
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
391 391
 
392 392
     }
393 393
     
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 
397 397
         $is_editable = $editable === 0 || $editable === '0' ? false : true;
398 398
 
399
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
399
+        return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
400 400
     }
401 401
     
402
-    public function save_metas( $metas = array() ) {
403
-        if ( empty( $metas ) ) {
402
+    public function save_metas($metas = array()) {
403
+        if (empty($metas)) {
404 404
             return false;
405 405
         }
406 406
         
407
-        foreach ( $metas as $meta_key => $meta_value ) {
407
+        foreach ($metas as $meta_key => $meta_value) {
408 408
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
409 409
             
410 410
             $this->update_meta($meta_key, $meta_value);
@@ -413,66 +413,66 @@  discard block
 block discarded – undo
413 413
         return true;
414 414
     }
415 415
 
416
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
417
-        if ( empty( $meta_key ) ) {
416
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
417
+        if (empty($meta_key)) {
418 418
             return false;
419 419
         }
420 420
         
421
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
421
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
422 422
 
423
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
423
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
424 424
     }
425 425
     
426
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
426
+    public function get_fees($type = 'fee', $item_id = 0) {
427 427
         global $wpi_session;
428 428
         
429
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
429
+        $fees = $wpi_session->get('wpi_cart_fees');
430 430
 
431
-        if ( ! wpinv_get_cart_contents() ) {
431
+        if (!wpinv_get_cart_contents()) {
432 432
             // We can only get item type fees when the cart is empty
433 433
             $type = 'custom';
434 434
         }
435 435
 
436
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
437
-            foreach( $fees as $key => $fee ) {
438
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
439
-                    unset( $fees[ $key ] );
436
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
437
+            foreach ($fees as $key => $fee) {
438
+                if (!empty($fee['type']) && $type != $fee['type']) {
439
+                    unset($fees[$key]);
440 440
                 }
441 441
             }
442 442
         }
443 443
 
444
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
444
+        if (!empty($fees) && !empty($item_id)) {
445 445
             // Remove fees that don't belong to the specified Item
446
-            foreach ( $fees as $key => $fee ) {
447
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
448
-                    unset( $fees[ $key ] );
446
+            foreach ($fees as $key => $fee) {
447
+                if ((int)$item_id !== (int)$fee['custom_id']) {
448
+                    unset($fees[$key]);
449 449
                 }
450 450
             }
451 451
         }
452 452
 
453
-        if ( ! empty( $fees ) ) {
453
+        if (!empty($fees)) {
454 454
             // Remove fees that belong to a specific item but are not in the cart
455
-            foreach( $fees as $key => $fee ) {
456
-                if( empty( $fee['custom_id'] ) ) {
455
+            foreach ($fees as $key => $fee) {
456
+                if (empty($fee['custom_id'])) {
457 457
                     continue;
458 458
                 }
459 459
 
460
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
461
-                    unset( $fees[ $key ] );
460
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
461
+                    unset($fees[$key]);
462 462
                 }
463 463
             }
464 464
         }
465 465
 
466
-        return ! empty( $fees ) ? $fees : array();
466
+        return !empty($fees) ? $fees : array();
467 467
     }
468 468
     
469 469
     public function can_purchase() {
470 470
         $can_purchase = true;
471 471
 
472
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
472
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
473 473
             $can_purchase = false;
474 474
         }
475 475
 
476
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
476
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
477 477
     }
478 478
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = new WPInv_Item( $value );
14
+            $item = new WPInv_Item($value);
15 15
 
16
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
16
+            if (!empty($item) && $item->post_type == 'wpi_item') {
17 17
                 return $item;
18 18
             }
19 19
             return false;
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 
23 23
         case 'slug':
24 24
         case 'name':
25
-            $posts = get_posts( array(
25
+            $posts = get_posts(array(
26 26
                 'post_type'      => 'wpi_item',
27 27
                 'name'           => $value,
28 28
                 'posts_per_page' => 1,
29 29
                 'post_status'    => 'any'
30
-            ) );
30
+            ));
31 31
 
32 32
             break;
33 33
         case 'custom_id':
34
-            if ( empty( $value ) || empty( $type ) ) {
34
+            if (empty($value) || empty($type)) {
35 35
                 return false;
36 36
             }
37 37
             
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
                 'post_status'    => 'any',
52 52
                 'orderby'        => 'ID',
53 53
                 'order'          => 'ASC',
54
-                'meta_query'     => array( $meta_query )
54
+                'meta_query'     => array($meta_query)
55 55
             );
56 56
             
57
-            $posts = get_posts( $args );
57
+            $posts = get_posts($args);
58 58
 
59 59
             break;
60 60
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
             return false;
63 63
     }
64 64
     
65
-    if ( !empty( $posts[0] ) ) {
66
-        $item = new WPInv_Item( $posts[0]->ID );
65
+    if (!empty($posts[0])) {
66
+        $item = new WPInv_Item($posts[0]->ID);
67 67
 
68
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
68
+        if (!empty($item) && $item->post_type == 'wpi_item') {
69 69
             return $item;
70 70
         }
71 71
     }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
     return false;
74 74
 }
75 75
 
76
-function wpinv_get_item( $item = 0 ) {
77
-    if ( is_numeric( $item ) ) {
78
-        $item = get_post( $item );
79
-        if ( ! $item || 'wpi_item' !== $item->post_type )
76
+function wpinv_get_item($item = 0) {
77
+    if (is_numeric($item)) {
78
+        $item = get_post($item);
79
+        if (!$item || 'wpi_item' !== $item->post_type)
80 80
             return null;
81 81
         return $item;
82 82
     }
@@ -89,150 +89,150 @@  discard block
 block discarded – undo
89 89
 
90 90
     $item = get_posts($args);
91 91
 
92
-    if ( $item ) {
92
+    if ($item) {
93 93
         return $item[0];
94 94
     }
95 95
 
96 96
     return null;
97 97
 }
98 98
 
99
-function wpinv_is_free_item( $item_id = 0 ) {
100
-    if( empty( $item_id ) ) {
99
+function wpinv_is_free_item($item_id = 0) {
100
+    if (empty($item_id)) {
101 101
         return false;
102 102
     }
103 103
 
104
-    $item = new WPInv_Item( $item_id );
104
+    $item = new WPInv_Item($item_id);
105 105
     
106 106
     return $item->is_free();
107 107
 }
108 108
 
109
-function wpinv_item_is_editable( $item = 0 ) {
110
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
109
+function wpinv_item_is_editable($item = 0) {
110
+    if (!empty($item) && is_a($item, 'WP_Post')) {
111 111
         $item = $item->ID;
112 112
     }
113 113
         
114
-    if ( empty( $item ) ) {
114
+    if (empty($item)) {
115 115
         return true;
116 116
     }
117 117
 
118
-    $item = new WPInv_Item( $item );
118
+    $item = new WPInv_Item($item);
119 119
     
120
-    return (bool) $item->is_editable();
120
+    return (bool)$item->is_editable();
121 121
 }
122 122
 
123
-function wpinv_get_item_price( $item_id = 0 ) {
124
-    if( empty( $item_id ) ) {
123
+function wpinv_get_item_price($item_id = 0) {
124
+    if (empty($item_id)) {
125 125
         return false;
126 126
     }
127 127
 
128
-    $item = new WPInv_Item( $item_id );
128
+    $item = new WPInv_Item($item_id);
129 129
     
130 130
     return $item->get_price();
131 131
 }
132 132
 
133
-function wpinv_is_recurring_item( $item_id = 0 ) {
134
-    if( empty( $item_id ) ) {
133
+function wpinv_is_recurring_item($item_id = 0) {
134
+    if (empty($item_id)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $item = new WPInv_Item( $item_id );
138
+    $item = new WPInv_Item($item_id);
139 139
     
140 140
     return $item->is_recurring();
141 141
 }
142 142
 
143
-function wpinv_item_price( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_item_price($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $price = wpinv_get_item_price( $item_id );
149
-    $price = wpinv_price( wpinv_format_amount( $price ) );
148
+    $price = wpinv_get_item_price($item_id);
149
+    $price = wpinv_price(wpinv_format_amount($price));
150 150
     
151
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
151
+    return apply_filters('wpinv_item_price', $price, $item_id);
152 152
 }
153 153
 
154
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_item_show_price($item_id = 0, $echo = true) {
155
+    if (empty($item_id)) {
156 156
         $item_id = get_the_ID();
157 157
     }
158 158
 
159
-    $price = wpinv_item_price( $item_id );
159
+    $price = wpinv_item_price($item_id);
160 160
 
161
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
161
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
162 162
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
163
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
163
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
164 164
 
165
-    if ( $echo ) {
165
+    if ($echo) {
166 166
         echo $formatted_price;
167 167
     } else {
168 168
         return $formatted_price;
169 169
     }
170 170
 }
171 171
 
172
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
173
-    if ( is_null( $amount_override ) ) {
174
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
172
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
173
+    if (is_null($amount_override)) {
174
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
175 175
     } else {
176 176
         $original_price = $amount_override;
177 177
     }
178 178
     
179 179
     $price = $original_price;
180 180
 
181
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
181
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_custom_singular_name( $item_id ) {
185
-    if( empty( $item_id ) ) {
184
+function wpinv_item_custom_singular_name($item_id) {
185
+    if (empty($item_id)) {
186 186
         return false;
187 187
     }
188 188
 
189
-    $item = new WPInv_Item( $item_id );
189
+    $item = new WPInv_Item($item_id);
190 190
     
191 191
     return $item->get_custom_singular_name();
192 192
 }
193 193
 
194 194
 function wpinv_get_item_types() {
195 195
     $item_types = array(
196
-            'custom'    => __( 'Standard', 'invoicing' ),
197
-            'fee'       => __( 'Fee', 'invoicing' ),
196
+            'custom'    => __('Standard', 'invoicing'),
197
+            'fee'       => __('Fee', 'invoicing'),
198 198
         );
199
-    return apply_filters( 'wpinv_get_item_types', $item_types );
199
+    return apply_filters('wpinv_get_item_types', $item_types);
200 200
 }
201 201
 
202 202
 function wpinv_item_types() {
203 203
     $item_types = wpinv_get_item_types();
204 204
     
205
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
205
+    return (!empty($item_types) ? array_keys($item_types) : array());
206 206
 }
207 207
 
208
-function wpinv_get_item_type( $item_id ) {
209
-    if( empty( $item_id ) ) {
208
+function wpinv_get_item_type($item_id) {
209
+    if (empty($item_id)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    $item = new WPInv_Item( $item_id );
213
+    $item = new WPInv_Item($item_id);
214 214
     
215 215
     return $item->get_type();
216 216
 }
217 217
 
218
-function wpinv_item_type( $item_id ) {
218
+function wpinv_item_type($item_id) {
219 219
     $item_types = wpinv_get_item_types();
220 220
     
221
-    $item_type = wpinv_get_item_type( $item_id );
221
+    $item_type = wpinv_get_item_type($item_id);
222 222
     
223
-    if ( empty( $item_type ) ) {
223
+    if (empty($item_type)) {
224 224
         $item_type = '-';
225 225
     }
226 226
     
227
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
227
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
228 228
 
229
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
229
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
230 230
 }
231 231
 
232
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
232
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
233 233
     global $wpinv_logs;
234 234
     
235
-    if ( empty( $wpinv_logs ) ) {
235
+    if (empty($wpinv_logs)) {
236 236
         return false;
237 237
     }
238 238
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         'log_type'		=> 'wpi_item'
242 242
     );
243 243
 
244
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
244
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
245 245
 
246 246
     $log_meta = array(
247 247
         'user_info'	=> $user_info,
@@ -251,253 +251,253 @@  discard block
 block discarded – undo
251 251
         'invoice_id'=> $invoice_id,
252 252
     );
253 253
 
254
-    $wpinv_logs->insert_log( $log_data, $log_meta );
254
+    $wpinv_logs->insert_log($log_data, $log_meta);
255 255
 }
256 256
 
257
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
258
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
257
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
258
+    if ('wpi_item' !== get_post_type($item_id))
259 259
         return;
260 260
 
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
267 267
     // Remove all log entries related to this item
268
-    $wpinv_logs->delete_logs( $item_id );
268
+    $wpinv_logs->delete_logs($item_id);
269 269
 }
270
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
270
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
271 271
 
272
-function wpinv_get_random_item( $post_ids = true ) {
273
-    wpinv_get_random_items( 1, $post_ids );
272
+function wpinv_get_random_item($post_ids = true) {
273
+    wpinv_get_random_items(1, $post_ids);
274 274
 }
275 275
 
276
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
277
-    if ( $post_ids ) {
278
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
276
+function wpinv_get_random_items($num = 3, $post_ids = true) {
277
+    if ($post_ids) {
278
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
279 279
     } else {
280
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
280
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
281 281
     }
282 282
     
283
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
283
+    $args = apply_filters('wpinv_get_random_items', $args);
284 284
     
285
-    return get_posts( $args );
285
+    return get_posts($args);
286 286
 }
287 287
 
288
-function wpinv_get_item_token( $url = '' ) {
288
+function wpinv_get_item_token($url = '') {
289 289
     $args    = array();
290
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
291
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
290
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
291
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
292 292
 
293
-    $parts   = parse_url( $url );
293
+    $parts   = parse_url($url);
294 294
     $options = array();
295 295
 
296
-    if ( isset( $parts['query'] ) ) {
297
-        wp_parse_str( $parts['query'], $query_args );
296
+    if (isset($parts['query'])) {
297
+        wp_parse_str($parts['query'], $query_args);
298 298
 
299
-        if ( ! empty( $query_args['o'] ) ) {
300
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
299
+        if (!empty($query_args['o'])) {
300
+            $options = explode(':', rawurldecode($query_args['o']));
301 301
 
302
-            if ( in_array( 'ip', $options ) ) {
302
+            if (in_array('ip', $options)) {
303 303
                 $args['ip'] = wpinv_get_ip();
304 304
             }
305 305
 
306
-            if ( in_array( 'ua', $options ) ) {
306
+            if (in_array('ua', $options)) {
307 307
                 $ua = wpinv_get_user_agent();
308
-                $args['user_agent'] = rawurlencode( $ua );
308
+                $args['user_agent'] = rawurlencode($ua);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
313
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
314 314
 
315 315
     $args['secret'] = $secret;
316 316
     $args['token']  = false;
317 317
 
318
-    $url   = add_query_arg( $args, $url );
319
-    $parts = parse_url( $url );
318
+    $url   = add_query_arg($args, $url);
319
+    $parts = parse_url($url);
320 320
 
321
-    if ( ! isset( $parts['path'] ) ) {
321
+    if (!isset($parts['path'])) {
322 322
         $parts['path'] = '';
323 323
     }
324 324
 
325
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
325
+    $token = md5($parts['path'] . '?' . $parts['query']);
326 326
 
327 327
     return $token;
328 328
 }
329 329
 
330
-function wpinv_validate_url_token( $url = '' ) {
330
+function wpinv_validate_url_token($url = '') {
331 331
     $ret   = false;
332
-    $parts = parse_url( $url );
332
+    $parts = parse_url($url);
333 333
 
334
-    if ( isset( $parts['query'] ) ) {
335
-        wp_parse_str( $parts['query'], $query_args );
334
+    if (isset($parts['query'])) {
335
+        wp_parse_str($parts['query'], $query_args);
336 336
 
337
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
337
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
338 338
             'item',
339 339
             'ttl',
340 340
             'token'
341
-        ) );
341
+        ));
342 342
 
343 343
         $remove = array();
344 344
 
345
-        foreach( $query_args as $key => $value ) {
346
-            if( false === in_array( $key, $allowed ) ) {
345
+        foreach ($query_args as $key => $value) {
346
+            if (false === in_array($key, $allowed)) {
347 347
                 $remove[] = $key;
348 348
             }
349 349
         }
350 350
 
351
-        if( ! empty( $remove ) ) {
352
-            $url = remove_query_arg( $remove, $url );
351
+        if (!empty($remove)) {
352
+            $url = remove_query_arg($remove, $url);
353 353
         }
354 354
 
355
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
356
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
355
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
356
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
357 357
         }
358 358
 
359
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
359
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
360 360
             $ret = true;
361 361
         }
362 362
 
363 363
     }
364 364
 
365
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
365
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
366 366
 }
367 367
 
368
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
368
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
369 369
     $cart_items = wpinv_get_cart_contents();
370 370
 
371 371
     $ret = false;
372 372
 
373
-    if ( is_array( $cart_items ) ) {
374
-        foreach ( $cart_items as $item ) {
375
-            if ( $item['id'] == $item_id ) {
373
+    if (is_array($cart_items)) {
374
+        foreach ($cart_items as $item) {
375
+            if ($item['id'] == $item_id) {
376 376
                 $ret = true;
377 377
                 break;
378 378
             }
379 379
         }
380 380
     }
381 381
 
382
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
382
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
383 383
 }
384 384
 
385
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
385
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
386 386
     $tax = 0;
387
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
388
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
389
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
387
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
388
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
389
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
390 390
 
391
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
391
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
392 392
     }
393 393
 
394
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
394
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
395 395
 }
396 396
 
397
-function wpinv_cart_item_price( $item ) {
397
+function wpinv_cart_item_price($item) {
398 398
     $use_taxes  = wpinv_use_taxes();
399
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
400
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
401
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
402
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
403
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
404
-    
405
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
406
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
399
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
400
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
401
+    $options    = isset($item['options']) ? $item['options'] : array();
402
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
403
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
404
+    
405
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
406
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
407 407
             $price += $tax;
408 408
         }
409 409
         
410
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
410
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
411 411
             $price -= $tax;
412 412
         }        
413 413
     }
414 414
 
415
-    $price = wpinv_price( wpinv_format_amount( $price ) );
415
+    $price = wpinv_price(wpinv_format_amount($price));
416 416
 
417
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
417
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
418 418
 }
419 419
 
420
-function wpinv_cart_item_subtotal( $item ) {
421
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
422
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
420
+function wpinv_cart_item_subtotal($item) {
421
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
422
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
423 423
 
424
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
424
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
425 425
 }
426 426
 
427
-function wpinv_cart_item_tax( $item ) {
427
+function wpinv_cart_item_tax($item) {
428 428
     $tax        = '';
429 429
     $tax_rate   = '';
430 430
     
431
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
432
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
433
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
434
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
431
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
432
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
433
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
434
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
435 435
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
436 436
     }
437 437
     
438
-    $tax        = $tax . $tax_rate;
438
+    $tax = $tax . $tax_rate;
439 439
     
440
-    if ( $tax === '' ) {
440
+    if ($tax === '') {
441 441
         $tax = 0; // Zero tax
442 442
     }
443 443
 
444
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
444
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
445 445
 }
446 446
 
447
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
447
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
448 448
     $price = 0;
449 449
     
450 450
     // Set custom price
451
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
451
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
452 452
         $price = $cart_item['custom_price'];
453 453
     } else {
454
-        $variable_prices = wpinv_has_variable_prices( $item_id );
454
+        $variable_prices = wpinv_has_variable_prices($item_id);
455 455
 
456
-        if ( $variable_prices ) {
457
-            $prices = wpinv_get_variable_prices( $item_id );
456
+        if ($variable_prices) {
457
+            $prices = wpinv_get_variable_prices($item_id);
458 458
 
459
-            if ( $prices ) {
460
-                if( ! empty( $options ) ) {
461
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
459
+            if ($prices) {
460
+                if (!empty($options)) {
461
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
462 462
                 } else {
463 463
                     $price = false;
464 464
                 }
465 465
             }
466 466
         }
467 467
 
468
-        if( ! $variable_prices || false === $price ) {
468
+        if (!$variable_prices || false === $price) {
469 469
             // Get the standard Item price if not using variable prices
470
-            $price = wpinv_get_item_price( $item_id );
470
+            $price = wpinv_get_item_price($item_id);
471 471
         }
472 472
     }
473 473
 
474
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
475
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
474
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
475
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
476 476
     }
477 477
 
478
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
478
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
479 479
 }
480 480
 
481
-function wpinv_get_cart_item_price_id( $item = array() ) {
482
-    if( isset( $item['item_number'] ) ) {
483
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
481
+function wpinv_get_cart_item_price_id($item = array()) {
482
+    if (isset($item['item_number'])) {
483
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
484 484
     } else {
485
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
485
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
486 486
     }
487 487
     return $price_id;
488 488
 }
489 489
 
490
-function wpinv_get_cart_item_price_name( $item = array() ) {
491
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
492
-    $prices   = wpinv_get_variable_prices( $item['id'] );
493
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
494
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
490
+function wpinv_get_cart_item_price_name($item = array()) {
491
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
492
+    $prices   = wpinv_get_variable_prices($item['id']);
493
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
494
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
495 495
 }
496 496
 
497
-function wpinv_get_cart_item_name( $item = array() ) {
498
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
497
+function wpinv_get_cart_item_name($item = array()) {
498
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
499 499
 
500
-    if ( empty( $item_title ) ) {
500
+    if (empty($item_title)) {
501 501
         $item_title = $item['id'];
502 502
     }
503 503
 
@@ -507,23 +507,23 @@  discard block
 block discarded – undo
507 507
     }
508 508
     */
509 509
 
510
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
510
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
511 511
 }
512 512
 
513
-function wpinv_has_variable_prices( $item_id = 0 ) {
513
+function wpinv_has_variable_prices($item_id = 0) {
514 514
     return false;
515 515
 }
516 516
 
517
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
517
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
518 518
     $cart_items = wpinv_get_cart_contents();
519 519
 
520
-    if ( !is_array( $cart_items ) ) {
520
+    if (!is_array($cart_items)) {
521 521
         return false; // Empty cart
522 522
     } else {
523
-        foreach ( $cart_items as $position => $item ) {
524
-            if ( $item['id'] == $item_id ) {
525
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
526
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
523
+        foreach ($cart_items as $position => $item) {
524
+            if ($item['id'] == $item_id) {
525
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
526
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
527 527
                         return $position;
528 528
                     }
529 529
                 } else {
@@ -536,80 +536,80 @@  discard block
 block discarded – undo
536 536
     return false; // Not found
537 537
 }
538 538
 
539
-function wpinv_get_cart_item_quantity( $item ) {
540
-    if ( wpinv_item_quantities_enabled() ) {
541
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
539
+function wpinv_get_cart_item_quantity($item) {
540
+    if (wpinv_item_quantities_enabled()) {
541
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
542 542
     } else {
543 543
         $quantity = 1;
544 544
     }
545 545
     
546
-    if ( $quantity < 1 ) {
546
+    if ($quantity < 1) {
547 547
         $quantity = 1;
548 548
     }
549 549
     
550
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
550
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
551 551
 }
552 552
 
553
-function wpinv_get_item_suffix( $item, $html = true ) {
554
-    if ( empty( $item ) ) {
553
+function wpinv_get_item_suffix($item, $html = true) {
554
+    if (empty($item)) {
555 555
         return NULL;
556 556
     }
557 557
     
558
-    if ( is_int( $item ) ) {
559
-        $item = new WPInv_Item( $item );
558
+    if (is_int($item)) {
559
+        $item = new WPInv_Item($item);
560 560
     }
561 561
     
562
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
562
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
563 563
         return NULL;
564 564
     }
565 565
     
566
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
566
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
567 567
     
568
-    if ( !$html && $suffix ) {
569
-        $suffix = strip_tags( $suffix );
568
+    if (!$html && $suffix) {
569
+        $suffix = strip_tags($suffix);
570 570
     }
571 571
     
572
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
572
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
573 573
 }
574 574
 
575
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
576
-    if ( empty( $item ) ) {
575
+function wpinv_remove_item($item = 0, $force_delete = false) {
576
+    if (empty($item)) {
577 577
         return NULL;
578 578
     }
579 579
     
580
-    if ( is_int( $item ) ) {
581
-        $item = new WPInv_Item( $item );
580
+    if (is_int($item)) {
581
+        $item = new WPInv_Item($item);
582 582
     }
583 583
     
584
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
584
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
585 585
         return NULL;
586 586
     }
587 587
     
588
-    do_action( 'wpinv_pre_delete_item', $item );
588
+    do_action('wpinv_pre_delete_item', $item);
589 589
 
590
-    wp_delete_post( $item->ID, $force_delete );
590
+    wp_delete_post($item->ID, $force_delete);
591 591
 
592
-    do_action( 'wpinv_post_delete_item', $item );
592
+    do_action('wpinv_post_delete_item', $item);
593 593
 }
594 594
 
595
-function wpinv_can_delete_item( $post_id ) {
596
-    $return = current_user_can( 'manage_options' ) ? true : false;
595
+function wpinv_can_delete_item($post_id) {
596
+    $return = current_user_can('manage_options') ? true : false;
597 597
     
598
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
598
+    if ($return && wpinv_item_in_use($post_id)) {
599 599
         $return = false; // Don't delete item already use in invoices.
600 600
     }
601 601
     
602
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
602
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
603 603
 }
604 604
 
605 605
 function wpinv_admin_action_delete() {
606 606
     $screen = get_current_screen();
607 607
     
608
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
608
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
609 609
         $post_ids = array();
610 610
         
611
-        foreach ( $_REQUEST['post'] as $post_id ) {
612
-            if ( !wpinv_can_delete_item( $post_id ) ) {
611
+        foreach ($_REQUEST['post'] as $post_id) {
612
+            if (!wpinv_can_delete_item($post_id)) {
613 613
                 continue;
614 614
             }
615 615
             
@@ -619,86 +619,86 @@  discard block
 block discarded – undo
619 619
         $_REQUEST['post'] = $post_ids;
620 620
     }
621 621
 }
622
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
623
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
622
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
623
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
624 624
 
625
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
626
-    if ( $post->post_type == 'wpi_item' ) {
627
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
625
+function wpinv_check_delete_item($check, $post, $force_delete) {
626
+    if ($post->post_type == 'wpi_item') {
627
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
628 628
             return true;
629 629
         }
630 630
     }
631 631
     
632 632
     return $check;
633 633
 }
634
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
634
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
635 635
 
636
-function wpinv_item_in_use( $item_id ) {
636
+function wpinv_item_in_use($item_id) {
637 637
     global $wpdb, $wpi_items_in_use;
638 638
     
639
-    if ( !$item_id > 0 ) {
639
+    if (!$item_id > 0) {
640 640
         return false;
641 641
     }
642 642
     
643
-    if ( !empty( $wpi_items_in_use ) ) {
644
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
643
+    if (!empty($wpi_items_in_use)) {
644
+        if (isset($wpi_items_in_use[$item_id])) {
645 645
             return $wpi_items_in_use[$item_id];
646 646
         }
647 647
     } else {
648 648
         $wpi_items_in_use = array();
649 649
     }
650 650
     
651
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
651
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
652 652
     
653
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
653
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
655 655
     
656 656
     $wpi_items_in_use[$item_id] = $in_use;
657 657
     
658 658
     return $in_use;
659 659
 }
660 660
 
661
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
661
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
662 662
     // Set some defaults
663 663
     $defaults = array(
664
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
665
-        'title'                => '',                                                      // Required. Item title.
666
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
667
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
668
-        'status'               => 'pending',                                               // Optional. pending, publish
669
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
670
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
671
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
672
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
673
-        'excerpt'              => '',                                                      // Optional. Item short description
664
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
665
+        'title'                => '', // Required. Item title.
666
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
667
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
668
+        'status'               => 'pending', // Optional. pending, publish
669
+        'custom_name'          => '', // Optional. Plural sub title for item.
670
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
671
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
672
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
673
+        'excerpt'              => '', // Optional. Item short description
674 674
         /* Recurring item fields */
675
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
678
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
679
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
680
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
675
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
678
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
679
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
680
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
+        'trial_interval'       => 0, // Optional. Any integer number.
682 682
     );
683 683
 
684
-    $data = wp_parse_args( $args, $defaults );
684
+    $data = wp_parse_args($args, $defaults);
685 685
 
686
-    if ( empty( $data['type'] ) ) {
686
+    if (empty($data['type'])) {
687 687
         $data['type'] = 'custom';
688 688
     }
689 689
 
690
-    if ( !empty( $data['custom_id'] ) ) {
691
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
690
+    if (!empty($data['custom_id'])) {
691
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
692 692
     } else {
693 693
         $item = NULL;
694 694
     }
695 695
 
696
-    if ( !empty( $item ) ) {
697
-        if ( $force_update ) {
698
-            if ( empty( $args['ID'] ) ) {
696
+    if (!empty($item)) {
697
+        if ($force_update) {
698
+            if (empty($args['ID'])) {
699 699
                 $args['ID'] = $item->ID;
700 700
             }
701
-            return wpinv_update_item( $args, $wp_error );
701
+            return wpinv_update_item($args, $wp_error);
702 702
         }
703 703
 
704 704
         return $item;
@@ -709,19 +709,19 @@  discard block
 block discarded – undo
709 709
     $meta['custom_id']              = $data['custom_id'];
710 710
     $meta['custom_singular_name']   = $data['custom_singular_name'];
711 711
     $meta['custom_name']            = $data['custom_name'];
712
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
712
+    $meta['price']                  = wpinv_round_amount($data['price']);
713 713
     $meta['editable']               = (int)$data['editable'];
714 714
     $meta['vat_rule']               = $data['vat_rule'];
715 715
     $meta['vat_class']              = '_standard';
716 716
     
717
-    if ( !empty( $data['is_recurring'] ) ) {
717
+    if (!empty($data['is_recurring'])) {
718 718
         $meta['is_recurring']       = $data['is_recurring'];
719 719
         $meta['recurring_period']   = $data['recurring_period'];
720
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
721
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
720
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
721
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
722 722
         $meta['free_trial']         = $data['free_trial'];
723 723
         $meta['trial_period']       = $data['trial_period'];
724
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
724
+        $meta['trial_interval']     = absint($data['trial_interval']);
725 725
     } else {
726 726
         $meta['is_recurring']       = 0;
727 727
         $meta['recurring_period']   = '';
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         $meta['trial_interval']     = '';
733 733
     }
734 734
     
735
-    $post_data  = array( 
735
+    $post_data = array( 
736 736
         'post_title'    => $data['title'],
737 737
         'post_excerpt'  => $data['excerpt'],
738 738
         'post_status'   => $data['status'],
@@ -740,86 +740,86 @@  discard block
 block discarded – undo
740 740
     );
741 741
 
742 742
     $item = new WPInv_Item();
743
-    $return = $item->create( $post_data, $wp_error );
743
+    $return = $item->create($post_data, $wp_error);
744 744
 
745
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
745
+    if ($return && !empty($item) && !is_wp_error($return)) {
746 746
         return $item;
747 747
     }
748 748
 
749
-    if ( $wp_error && is_wp_error( $return ) ) {
749
+    if ($wp_error && is_wp_error($return)) {
750 750
         return $return;
751 751
     }
752 752
     return 0;
753 753
 }
754 754
 
755
-function wpinv_update_item( $args = array(), $wp_error = false ) {
756
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
755
+function wpinv_update_item($args = array(), $wp_error = false) {
756
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
757 757
 
758
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
759
-        if ( $wp_error ) {
760
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
758
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
759
+        if ($wp_error) {
760
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
761 761
         }
762 762
         return 0;
763 763
     }
764 764
     
765
-    if ( !empty( $args['custom_id'] ) ) {
766
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
765
+    if (!empty($args['custom_id'])) {
766
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
767 767
         
768
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
769
-            if ( $wp_error ) {
770
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
768
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
769
+            if ($wp_error) {
770
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
771 771
             }
772 772
             return 0;
773 773
         }
774 774
     }
775 775
 
776
-    $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' );
776
+    $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval');
777 777
 
778 778
     $post_data = array();
779
-    if ( isset( $args['title'] ) ) { 
779
+    if (isset($args['title'])) { 
780 780
         $post_data['post_title'] = $args['title'];
781 781
     }
782
-    if ( isset( $args['excerpt'] ) ) { 
782
+    if (isset($args['excerpt'])) { 
783 783
         $post_data['post_excerpt'] = $args['excerpt'];
784 784
     }
785
-    if ( isset( $args['status'] ) ) { 
785
+    if (isset($args['status'])) { 
786 786
         $post_data['post_status'] = $args['status'];
787 787
     }
788 788
     
789
-    foreach ( $meta_fields as $meta_field ) {
790
-        if ( isset( $args[ $meta_field ] ) ) { 
791
-            $value = $args[ $meta_field ];
789
+    foreach ($meta_fields as $meta_field) {
790
+        if (isset($args[$meta_field])) { 
791
+            $value = $args[$meta_field];
792 792
 
793
-            switch ( $meta_field ) {
793
+            switch ($meta_field) {
794 794
                 case 'price':
795
-                    $value = wpinv_round_amount( $value );
795
+                    $value = wpinv_round_amount($value);
796 796
                 break;
797 797
                 case 'recurring_interval':
798 798
                 case 'recurring_limit':
799 799
                 case 'trial_interval':
800
-                    $value = absint( $value );
800
+                    $value = absint($value);
801 801
                 break;
802 802
             }
803 803
 
804
-            $post_data['meta'][ $meta_field ] = $value;
804
+            $post_data['meta'][$meta_field] = $value;
805 805
         };
806 806
     }
807 807
 
808
-    if ( empty( $post_data ) ) {
809
-        if ( $wp_error ) {
810
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
808
+    if (empty($post_data)) {
809
+        if ($wp_error) {
810
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
811 811
         }
812 812
         return 0;
813 813
     }
814 814
     $post_data['ID'] = $args['ID'];
815 815
 
816
-    $return = $item->update( $post_data, $wp_error );
816
+    $return = $item->update($post_data, $wp_error);
817 817
 
818
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
818
+    if ($return && !empty($item) && !is_wp_error($return)) {
819 819
         return $item;
820 820
     }
821 821
 
822
-    if ( $wp_error && is_wp_error( $return ) ) {
822
+    if ($wp_error && is_wp_error($return)) {
823 823
         return $return;
824 824
     }
825 825
     return 0;
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -1,72 +1,72 @@  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
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
11
+    if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
12 12
         return;
13 13
     }
14 14
 
15
-    $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
15
+    $capability = apply_filters('invoicing_capability', 'manage_invoicing');
16 16
 
17
-    if ( current_user_can( 'manage_options' ) ) {
18
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
17
+    if (current_user_can('manage_options')) {
18
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
19 19
     }
20 20
 
21
-    $wpi_invoice = get_post_type_object( 'wpi_invoice' );
21
+    $wpi_invoice = get_post_type_object('wpi_invoice');
22 22
 
23
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
23
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
24 24
 
25
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' );
25
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page');
26 26
 }
27 27
 
28
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
28
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
29 29
 function wpinv_remove_admin_submenus() {
30
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
30
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
31 31
 }
32 32
 
33
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
34
-function wpinv_discount_columns( $existing_columns ) {
33
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
34
+function wpinv_discount_columns($existing_columns) {
35 35
     $columns                = array();
36 36
     $columns['cb']          = $existing_columns['cb'];
37
-    $columns['name']        = __( 'Name', 'invoicing' );
38
-    $columns['code']        = __( 'Code', 'invoicing' );
39
-    $columns['amount']      = __( 'Amount', 'invoicing' );
40
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
41
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
42
-    $columns['status']      = __( 'Status', 'invoicing' );
37
+    $columns['name']        = __('Name', 'invoicing');
38
+    $columns['code']        = __('Code', 'invoicing');
39
+    $columns['amount']      = __('Amount', 'invoicing');
40
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
41
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
42
+    $columns['status']      = __('Status', 'invoicing');
43 43
 
44 44
     return $columns;
45 45
 }
46 46
 
47
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
48
-function wpinv_discount_custom_column( $column ) {
47
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
48
+function wpinv_discount_custom_column($column) {
49 49
     global $post;
50 50
     
51 51
     $discount = $post;
52 52
 
53
-    switch ( $column ) {
53
+    switch ($column) {
54 54
         case 'name' :
55
-            echo get_the_title( $discount->ID );
55
+            echo get_the_title($discount->ID);
56 56
         break;
57 57
         case 'code' :
58
-            echo wpinv_get_discount_code( $discount->ID );
58
+            echo wpinv_get_discount_code($discount->ID);
59 59
         break;
60 60
         case 'amount' :
61
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
61
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
62 62
         break;
63 63
         case 'usage_limit' :
64
-            echo wpinv_get_discount_uses( $discount->ID );
64
+            echo wpinv_get_discount_uses($discount->ID);
65 65
         break;
66 66
         case 'usage' :
67
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
68
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
69
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
67
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
68
+            if (wpinv_get_discount_max_uses($discount->ID)) {
69
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
70 70
             } else {
71 71
                 $usage .= ' &infin;';
72 72
             }
@@ -74,162 +74,162 @@  discard block
 block discarded – undo
74 74
             echo $usage;
75 75
         break;
76 76
         case 'expiry_date' :
77
-            if ( wpinv_get_discount_expiration( $discount->ID ) ) {
78
-                $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) );
77
+            if (wpinv_get_discount_expiration($discount->ID)) {
78
+                $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID)));
79 79
             } else {
80
-                $expiration = __( 'Never', 'invoicing' );
80
+                $expiration = __('Never', 'invoicing');
81 81
             }
82 82
                 
83 83
             echo $expiration;
84 84
         break;
85 85
         case 'description' :
86
-            echo wp_kses_post( $post->post_excerpt );
86
+            echo wp_kses_post($post->post_excerpt);
87 87
         break;
88 88
         case 'status' :
89
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
89
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
90 90
             
91
-            echo wpinv_discount_status( $status );
91
+            echo wpinv_discount_status($status);
92 92
         break;
93 93
     }
94 94
 }
95 95
 
96
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
97
-function wpinv_post_row_actions( $actions, $post ) {
98
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
96
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
97
+function wpinv_post_row_actions($actions, $post) {
98
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
99 99
     
100
-    if ( $post_type == 'wpi_invoice' ) {
100
+    if ($post_type == 'wpi_invoice') {
101 101
         $actions = array();
102 102
     }
103 103
     
104
-    if ( $post_type == 'wpi_discount' ) {
105
-        $actions = wpinv_discount_row_actions( $post, $actions );
104
+    if ($post_type == 'wpi_discount') {
105
+        $actions = wpinv_discount_row_actions($post, $actions);
106 106
     }
107 107
     
108 108
     return $actions;
109 109
 }
110 110
 
111
-function wpinv_discount_row_actions( $discount, $row_actions ) {
112
-    $row_actions  = array();
113
-    $edit_link = get_edit_post_link( $discount->ID );
114
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
111
+function wpinv_discount_row_actions($discount, $row_actions) {
112
+    $row_actions = array();
113
+    $edit_link = get_edit_post_link($discount->ID);
114
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
115 115
 
116
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
117
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
118
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
119
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
116
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
117
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
118
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
119
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
120 120
     }
121 121
 
122
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
123
-        if ( isset( $row_actions['delete'] ) ) {
124
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
122
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
123
+        if (isset($row_actions['delete'])) {
124
+            unset($row_actions['delete']); // Don't delete used discounts.
125 125
         }
126 126
     } else {
127
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
127
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
128 128
     }
129 129
     
130 130
 
131
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
131
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
132 132
 
133 133
     return $row_actions;
134 134
 }
135 135
 
136
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
137
-function wpinv_table_primary_column( $default, $screen_id ) {
138
-    if ( 'edit-wpi_invoice' === $screen_id ) {
136
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
137
+function wpinv_table_primary_column($default, $screen_id) {
138
+    if ('edit-wpi_invoice' === $screen_id) {
139 139
         return 'name';
140 140
     }
141 141
     
142 142
     return $default;
143 143
 }
144 144
 
145
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
146
-    if ( !$display ) {
145
+function wpinv_discount_bulk_actions($actions, $display = false) {    
146
+    if (!$display) {
147 147
         return array();
148 148
     }
149 149
     
150 150
     $actions = array(
151
-        'activate'   => __( 'Activate', 'invoicing' ),
152
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
153
-        'delete'     => __( 'Delete', 'invoicing' ),
151
+        'activate'   => __('Activate', 'invoicing'),
152
+        'deactivate' => __('Deactivate', 'invoicing'),
153
+        'delete'     => __('Delete', 'invoicing'),
154 154
     );
155 155
     $two = '';
156 156
     $which = 'top';
157 157
     echo '</div><div class="alignleft actions bulkactions">';
158
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
159
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
160
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
158
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
159
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
160
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
161 161
 
162
-    foreach ( $actions as $name => $title ) {
162
+    foreach ($actions as $name => $title) {
163 163
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
164 164
 
165 165
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
166 166
     }
167 167
     echo "</select>";
168 168
 
169
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
169
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
170 170
     
171 171
     echo '</div><div class="alignleft actions">';
172 172
 }
173
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
173
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
174 174
 
175
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
176
-    if ( $post_type == 'wpi_discount' ) {
175
+function wpinv_disable_months_dropdown($disable, $post_type) {
176
+    if ($post_type == 'wpi_discount') {
177 177
         $disable = true;
178 178
     }
179 179
     
180 180
     return $disable;
181 181
 }
182
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
182
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
183 183
 
184 184
 function wpinv_restrict_manage_posts() {
185 185
     global $typenow;
186 186
 
187
-    if( 'wpi_discount' == $typenow ) {
187
+    if ('wpi_discount' == $typenow) {
188 188
         wpinv_discount_filters();
189 189
     }
190 190
 }
191
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
191
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
192 192
 
193 193
 function wpinv_discount_filters() {
194
-    echo wpinv_discount_bulk_actions( array(), true );
194
+    echo wpinv_discount_bulk_actions(array(), true);
195 195
     
196 196
     ?>
197 197
     <select name="discount_type" id="dropdown_wpinv_discount_type">
198
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
198
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
199 199
         <?php
200 200
             $types = wpinv_get_discount_types();
201 201
 
202
-            foreach ( $types as $name => $type ) {
203
-                echo '<option value="' . esc_attr( $name ) . '"';
202
+            foreach ($types as $name => $type) {
203
+                echo '<option value="' . esc_attr($name) . '"';
204 204
 
205
-                if ( isset( $_GET['discount_type'] ) )
206
-                    selected( $name, $_GET['discount_type'] );
205
+                if (isset($_GET['discount_type']))
206
+                    selected($name, $_GET['discount_type']);
207 207
 
208
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
208
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
209 209
             }
210 210
         ?>
211 211
     </select>
212 212
     <?php
213 213
 }
214 214
 
215
-function wpinv_request( $vars ) {
215
+function wpinv_request($vars) {
216 216
     global $typenow, $wp_query, $wp_post_statuses;
217 217
 
218
-    if ( 'wpi_invoice' === $typenow ) {
219
-        if ( !isset( $vars['post_status'] ) ) {
218
+    if ('wpi_invoice' === $typenow) {
219
+        if (!isset($vars['post_status'])) {
220 220
             $post_statuses = wpinv_get_invoice_statuses();
221 221
 
222
-            foreach ( $post_statuses as $status => $value ) {
223
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
224
-                    unset( $post_statuses[ $status ] );
222
+            foreach ($post_statuses as $status => $value) {
223
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
224
+                    unset($post_statuses[$status]);
225 225
                 }
226 226
             }
227 227
 
228
-            $vars['post_status'] = array_keys( $post_statuses );
228
+            $vars['post_status'] = array_keys($post_statuses);
229 229
         }
230 230
         
231
-        if ( isset( $vars['orderby'] ) ) {
232
-            if ( 'amount' == $vars['orderby'] ) {
231
+        if (isset($vars['orderby'])) {
232
+            if ('amount' == $vars['orderby']) {
233 233
                 $vars = array_merge(
234 234
                     $vars,
235 235
                     array(
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                         'orderby'  => 'meta_value_num'
238 238
                     )
239 239
                 );
240
-            } else if ( 'customer' == $vars['orderby'] ) {
240
+            } else if ('customer' == $vars['orderby']) {
241 241
                 $vars = array_merge(
242 242
                     $vars,
243 243
                     array(
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
                         'orderby'  => 'meta_value'
246 246
                     )
247 247
                 );
248
-            } else if ( 'number' == $vars['orderby'] ) {
248
+            } else if ('number' == $vars['orderby']) {
249 249
                 $vars = array_merge(
250 250
                     $vars,
251 251
                     array(
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
                 );
256 256
             }
257 257
         }
258
-    } else if ( 'wpi_item' == $typenow ) {
258
+    } else if ('wpi_item' == $typenow) {
259 259
         // Check if 'orderby' is set to "price"
260
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
260
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
261 261
             $vars = array_merge(
262 262
                 $vars,
263 263
                 array(
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
         }
269 269
 
270 270
         // Check if "orderby" is set to "vat_rule"
271
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
271
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
272 272
             $vars = array_merge(
273 273
                 $vars,
274 274
                 array(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         }
280 280
 
281 281
         // Check if "orderby" is set to "vat_class"
282
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
282
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
283 283
             $vars = array_merge(
284 284
                 $vars,
285 285
                 array(
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         }
291 291
         
292 292
         // Check if "orderby" is set to "type"
293
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
293
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
294 294
             $vars = array_merge(
295 295
                 $vars,
296 296
                 array(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         }
302 302
         
303 303
         // Check if "orderby" is set to "recurring"
304
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
304
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
305 305
             $vars = array_merge(
306 306
                 $vars,
307 307
                 array(
@@ -311,120 +311,120 @@  discard block
 block discarded – undo
311 311
             );
312 312
         }
313 313
 
314
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
314
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
315 315
         // Filter vat rule type
316
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
316
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
317 317
             $meta_query[] = array(
318 318
                     'key'   => '_wpinv_vat_rule',
319
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
319
+                    'value' => sanitize_text_field($_GET['vat_rule']),
320 320
                     'compare' => '='
321 321
                 );
322 322
         }
323 323
         
324 324
         // Filter vat class
325
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
325
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
326 326
             $meta_query[] = array(
327 327
                     'key'   => '_wpinv_vat_class',
328
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
328
+                    'value' => sanitize_text_field($_GET['vat_class']),
329 329
                     'compare' => '='
330 330
                 );
331 331
         }
332 332
         
333 333
         // Filter item type
334
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
334
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
335 335
             $meta_query[] = array(
336 336
                     'key'   => '_wpinv_type',
337
-                    'value' => sanitize_text_field( $_GET['type'] ),
337
+                    'value' => sanitize_text_field($_GET['type']),
338 338
                     'compare' => '='
339 339
                 );
340 340
         }
341 341
         
342
-        if ( !empty( $meta_query ) ) {
342
+        if (!empty($meta_query)) {
343 343
             $vars['meta_query'] = $meta_query;
344 344
         }
345
-    } else if ( 'wpi_discount' == $typenow ) {
346
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
345
+    } else if ('wpi_discount' == $typenow) {
346
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
347 347
         // Filter vat rule type
348
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
348
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
349 349
             $meta_query[] = array(
350 350
                     'key'   => '_wpi_discount_type',
351
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
351
+                    'value' => sanitize_text_field($_GET['discount_type']),
352 352
                     'compare' => '='
353 353
                 );
354 354
         }
355 355
         
356
-        if ( !empty( $meta_query ) ) {
356
+        if (!empty($meta_query)) {
357 357
             $vars['meta_query'] = $meta_query;
358 358
         }
359 359
     }
360 360
 
361 361
     return $vars;
362 362
 }
363
-add_filter( 'request', 'wpinv_request' );
363
+add_filter('request', 'wpinv_request');
364 364
 
365 365
 function wpinv_options_page() {
366
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
366
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
367 367
     
368
-    if ( $page !== 'wpinv-settings' ) {
368
+    if ($page !== 'wpinv-settings') {
369 369
         return;
370 370
     }
371 371
     
372 372
     $settings_tabs = wpinv_get_settings_tabs();
373 373
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
374
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
375
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
374
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
375
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
376 376
     $key           = 'main';
377 377
 
378
-    if ( is_array( $sections ) ) {
379
-        $key = key( $sections );
378
+    if (is_array($sections)) {
379
+        $key = key($sections);
380 380
     }
381 381
 
382
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
383
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
382
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
383
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
384 384
     ob_start();
385 385
     ?>
386 386
     <div class="wrap">
387 387
         <h1 class="nav-tab-wrapper">
388 388
             <?php
389
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
390
-                $tab_url = add_query_arg( array(
389
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
390
+                $tab_url = add_query_arg(array(
391 391
                     'settings-updated' => false,
392 392
                     'tab' => $tab_id,
393
-                ) );
393
+                ));
394 394
 
395 395
                 // Remove the section from the tabs so we always end up at the main section
396
-                $tab_url = remove_query_arg( 'section', $tab_url );
397
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
396
+                $tab_url = remove_query_arg('section', $tab_url);
397
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
398 398
 
399 399
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
400 400
 
401
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
402
-                    echo esc_html( $tab_name );
401
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
402
+                    echo esc_html($tab_name);
403 403
                 echo '</a>';
404 404
             }
405 405
             ?>
406 406
         </h1>
407 407
         <?php
408
-        $number_of_sections = count( $sections );
408
+        $number_of_sections = count($sections);
409 409
         $number = 0;
410
-        if ( $number_of_sections > 1 ) {
410
+        if ($number_of_sections > 1) {
411 411
             echo '<div><ul class="subsubsub">';
412
-            foreach( $sections as $section_id => $section_name ) {
412
+            foreach ($sections as $section_id => $section_name) {
413 413
                 echo '<li>';
414 414
                 $number++;
415
-                $tab_url = add_query_arg( array(
415
+                $tab_url = add_query_arg(array(
416 416
                     'settings-updated' => false,
417 417
                     'tab' => $active_tab,
418 418
                     'section' => $section_id
419
-                ) );
420
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
419
+                ));
420
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
421 421
                 $class = '';
422
-                if ( $section == $section_id ) {
422
+                if ($section == $section_id) {
423 423
                     $class = 'current';
424 424
                 }
425
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
425
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
426 426
 
427
-                if ( $number != $number_of_sections ) {
427
+                if ($number != $number_of_sections) {
428 428
                     echo ' | ';
429 429
                 }
430 430
                 echo '</li>';
@@ -436,19 +436,19 @@  discard block
 block discarded – undo
436 436
             <form method="post" action="options.php">
437 437
                 <table class="form-table">
438 438
                 <?php
439
-                settings_fields( 'wpinv_settings' );
439
+                settings_fields('wpinv_settings');
440 440
 
441
-                if ( 'main' === $section ) {
442
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
441
+                if ('main' === $section) {
442
+                    do_action('wpinv_settings_tab_top', $active_tab);
443 443
                 }
444 444
 
445
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section );
446
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section );
447
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section  );
445
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section);
446
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section);
447
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section);
448 448
 
449 449
                 // For backwards compatibility
450
-                if ( 'main' === $section ) {
451
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
450
+                if ('main' === $section) {
451
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
452 452
                 }
453 453
                 ?>
454 454
                 </table>
@@ -461,53 +461,53 @@  discard block
 block discarded – undo
461 461
     echo $content;
462 462
 }
463 463
 
464
-function wpinv_item_type_class( $classes, $class, $post_id ) {
464
+function wpinv_item_type_class($classes, $class, $post_id) {
465 465
     global $pagenow, $typenow;
466 466
 
467
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
468
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
469
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
467
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
468
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
469
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
470 470
         }
471 471
         
472
-        if ( !wpinv_item_is_editable( $post_id ) ) {
472
+        if (!wpinv_item_is_editable($post_id)) {
473 473
             $classes[] = 'wpi-editable-n';
474 474
         }
475 475
     }
476 476
     return $classes;
477 477
 }
478
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
478
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
479 479
 
480 480
 function wpinv_check_quick_edit() {
481 481
     global $pagenow, $current_screen, $wpinv_item_screen;
482 482
 
483
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
484
-        if ( empty( $wpinv_item_screen ) ) {
485
-            if ( $current_screen->post_type == 'wpi_item' ) {
483
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
484
+        if (empty($wpinv_item_screen)) {
485
+            if ($current_screen->post_type == 'wpi_item') {
486 486
                 $wpinv_item_screen = 'y';
487 487
             } else {
488 488
                 $wpinv_item_screen = 'n';
489 489
             }
490 490
         }
491 491
 
492
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
493
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
494
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
492
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
493
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
494
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
495 495
         }
496 496
     }
497 497
 }
498
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
498
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
499 499
 
500
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
501
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
502
-        unset( $actions['inline hide-if-no-js'] );
500
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
501
+    if (isset($actions['inline hide-if-no-js'])) {
502
+        unset($actions['inline hide-if-no-js']);
503 503
     }
504 504
     
505
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
506
-        if ( isset( $actions['trash'] ) ) {
507
-            unset( $actions['trash'] );
505
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
506
+        if (isset($actions['trash'])) {
507
+            unset($actions['trash']);
508 508
         }
509
-        if ( isset( $actions['delete'] ) ) {
510
-            unset( $actions['delete'] );
509
+        if (isset($actions['delete'])) {
510
+            unset($actions['delete']);
511 511
         }
512 512
     }
513 513
 
@@ -524,19 +524,19 @@  discard block
 block discarded – undo
524 524
  * @param int $post_parent (default: 0) Parent for the new page
525 525
  * @return int page ID
526 526
  */
527
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
527
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
528 528
     global $wpdb;
529 529
 
530
-    $option_value = wpinv_get_option( $option );
530
+    $option_value = wpinv_get_option($option);
531 531
 
532
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
533
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
532
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
533
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
534 534
             // Valid page is already in place
535 535
             return $page_object->ID;
536 536
         }
537 537
     }
538 538
 
539
-    if(!empty($post_parent)){
539
+    if (!empty($post_parent)) {
540 540
         $page = get_page_by_path($post_parent);
541 541
         if ($page) {
542 542
             $post_parent = $page->ID;
@@ -545,40 +545,40 @@  discard block
 block discarded – undo
545 545
         }
546 546
     }
547 547
 
548
-    if ( strlen( $page_content ) > 0 ) {
548
+    if (strlen($page_content) > 0) {
549 549
         // Search for an existing page with the specified page content (typically a shortcode)
550
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
550
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
551 551
     } else {
552 552
         // Search for an existing page with the specified page slug
553
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
553
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
554 554
     }
555 555
 
556
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
556
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
557 557
 
558
-    if ( $valid_page_found ) {
559
-        if ( $option ) {
560
-            wpinv_update_option( $option, $valid_page_found );
558
+    if ($valid_page_found) {
559
+        if ($option) {
560
+            wpinv_update_option($option, $valid_page_found);
561 561
         }
562 562
         return $valid_page_found;
563 563
     }
564 564
 
565 565
     // Search for a matching valid trashed page
566
-    if ( strlen( $page_content ) > 0 ) {
566
+    if (strlen($page_content) > 0) {
567 567
         // Search for an existing page with the specified page content (typically a shortcode)
568
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
568
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
569 569
     } else {
570 570
         // Search for an existing page with the specified page slug
571
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
571
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
572 572
     }
573 573
 
574
-    if ( $trashed_page_found ) {
574
+    if ($trashed_page_found) {
575 575
         $page_id   = $trashed_page_found;
576 576
         $page_data = array(
577 577
             'ID'             => $page_id,
578 578
             'post_status'    => 'publish',
579 579
             'post_parent'    => $post_parent,
580 580
         );
581
-        wp_update_post( $page_data );
581
+        wp_update_post($page_data);
582 582
     } else {
583 583
         $page_data = array(
584 584
             'post_status'    => 'publish',
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
             'post_parent'    => $post_parent,
591 591
             'comment_status' => 'closed',
592 592
         );
593
-        $page_id = wp_insert_post( $page_data );
593
+        $page_id = wp_insert_post($page_data);
594 594
     }
595 595
 
596
-    if ( $option ) {
597
-        wpinv_update_option( $option, (int)$page_id );
596
+    if ($option) {
597
+        wpinv_update_option($option, (int)$page_id);
598 598
     }
599 599
 
600 600
     return $page_id;
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,80 +1,80 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
49
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
48
+							<?php elseif ('invoice-status' === $column_id) : ?>
49
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
50 50
 
51
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
52
-								<?php echo $invoice->get_total( true ); ?>
51
+							<?php elseif ('invoice-total' === $column_id) : ?>
52
+								<?php echo $invoice->get_total(true); ?>
53 53
 
54
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
54
+							<?php elseif ('invoice-actions' === $column_id) : ?>
55 55
 								<?php
56 56
 									$actions = array(
57 57
 										'pay'    => array(
58 58
 											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
59
+											'name' => __('Pay Now', 'invoicing'),
60 60
                                             'class' => 'btn-success'
61 61
 										),
62 62
                                         'print'   => array(
63 63
 											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
64
+											'name' => __('Print', 'invoicing'),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67 67
 										)
68 68
 									);
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
70
+									if (!$invoice->needs_payment()) {
71
+										unset($actions['pay']);
72 72
 									}
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
74
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
75
+										foreach ($actions as $key => $action) {
76 76
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
77
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
78 78
 										}
79 79
 									}
80 80
 								?>
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 		</tbody>
87 87
 	</table>
88 88
 
89
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
89
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
90 90
 
91
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
91
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94 94
 			$big = 999999;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 			else
101 101
 				$current_page = 1;
102 102
 
103
-			echo paginate_links( array(
104
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
103
+			echo paginate_links(array(
104
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
105 105
 				'format'  => '?paged=%#%',
106
-				'current' => max( 1, $current_page ),
106
+				'current' => max(1, $current_page),
107 107
 				'total'   => $user_invoices->max_num_pages,
108
-			) );
108
+			));
109 109
 			?>
110 110
 		</div>
111 111
 	<?php endif; ?>
112 112
 
113 113
 <?php } else { ?>
114 114
 	<div class="wpinv-empty alert-info">
115
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
115
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
116 116
 	</div>
117 117
 <?php } ?>
118 118
 
119
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
119
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -11,45 +11,45 @@
 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
-    $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
33
-    if ( !empty( $results ) ) {
34
-        $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
32
+    $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
33
+    if (!empty($results)) {
34
+        $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
35 35
         
36 36
         // Clean post cache
37
-        foreach ( $results as $row ) {
38
-            clean_post_cache( $row->ID );
37
+        foreach ($results as $row) {
38
+            clean_post_cache($row->ID);
39 39
         }
40 40
     }
41 41
     
42 42
     // Item meta key changes
43 43
     $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' )";
44
-    $results = $wpdb->get_results( $query );
44
+    $results = $wpdb->get_results($query);
45 45
     
46
-    if ( !empty( $results ) ) {
47
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
48
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
49
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
46
+    if (!empty($results)) {
47
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
48
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
49
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
50 50
         
51
-        foreach ( $results as $row ) {
52
-            clean_post_cache( $row->post_id );
51
+        foreach ($results as $row) {
52
+            clean_post_cache($row->post_id);
53 53
         }
54 54
     }
55 55
 
Please login to merge, or discard this patch.
includes/wpinv-post-types.php 1 patch
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -7,44 +7,44 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-add_action( 'init', 'wpinv_register_post_types', 1 );
14
+add_action('init', 'wpinv_register_post_types', 1);
15 15
 function wpinv_register_post_types() {    
16 16
     $labels = array(
17
-        'name'               => _x( 'Invoices', 'post type general name', 'invoicing' ),
18
-        'singular_name'      => _x( 'Invoice', 'post type singular name', 'invoicing' ),
19
-        'menu_name'          => _x( 'Invoices', 'admin menu', 'invoicing' ),
20
-        'name_admin_bar'     => _x( 'Invoice', 'add new on admin bar', 'invoicing' ),
21
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
22
-        'add_new_item'       => __( 'Add New Invoice', 'invoicing' ),
23
-        'new_item'           => __( 'New Invoice', 'invoicing' ),
24
-        'edit_item'          => __( 'Edit Invoice', 'invoicing' ),
25
-        'view_item'          => __( 'View Invoice', 'invoicing' ),
26
-        'all_items'          => __( 'Invoices', 'invoicing' ),
27
-        'search_items'       => __( 'Search Invoices', 'invoicing' ),
28
-        'parent_item_colon'  => __( 'Parent Invoices:', 'invoicing' ),
29
-        'not_found'          => __( 'No invoices found.', 'invoicing' ),
30
-        'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' )
17
+        'name'               => _x('Invoices', 'post type general name', 'invoicing'),
18
+        'singular_name'      => _x('Invoice', 'post type singular name', 'invoicing'),
19
+        'menu_name'          => _x('Invoices', 'admin menu', 'invoicing'),
20
+        'name_admin_bar'     => _x('Invoice', 'add new on admin bar', 'invoicing'),
21
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
22
+        'add_new_item'       => __('Add New Invoice', 'invoicing'),
23
+        'new_item'           => __('New Invoice', 'invoicing'),
24
+        'edit_item'          => __('Edit Invoice', 'invoicing'),
25
+        'view_item'          => __('View Invoice', 'invoicing'),
26
+        'all_items'          => __('Invoices', 'invoicing'),
27
+        'search_items'       => __('Search Invoices', 'invoicing'),
28
+        'parent_item_colon'  => __('Parent Invoices:', 'invoicing'),
29
+        'not_found'          => __('No invoices found.', 'invoicing'),
30
+        'not_found_in_trash' => __('No invoices found in trash.', 'invoicing')
31 31
     );
32
-    $labels = apply_filters( 'wpinv_labels', $labels );
32
+    $labels = apply_filters('wpinv_labels', $labels);
33 33
     
34 34
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
35
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
35
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
36 36
 
37 37
     $cap_type = 'wpi_invoice';
38 38
     $args = array(
39 39
         'labels'             => $labels,
40
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
40
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
41 41
         'public'             => true,
42 42
         'can_export'         => true,
43 43
         '_builtin'           => false,
44 44
         'publicly_queryable' => true,
45 45
         'exclude_from_search'=> true,
46 46
         'show_ui'            => true,
47
-        'show_in_menu'       => current_user_can( 'manage_invoicing' ) ? 'wpinv' : true,
47
+        'show_in_menu'       => current_user_can('manage_invoicing') ? 'wpinv' : true,
48 48
         'query_var'          => false,
49 49
         'rewrite'            => true,
50 50
         'capability_type'    => 'wpi_invoice',
@@ -68,38 +68,38 @@  discard block
 block discarded – undo
68 68
         'has_archive'        => false,
69 69
         'hierarchical'       => false,
70 70
         'menu_position'      => null,
71
-        'supports'           => array( 'title', 'author' ),
71
+        'supports'           => array('title', 'author'),
72 72
         'menu_icon'          => $menu_icon,
73 73
     );
74 74
             
75
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
75
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
76 76
     
77
-    register_post_type( 'wpi_invoice', $args );
77
+    register_post_type('wpi_invoice', $args);
78 78
     
79 79
     $items_labels = array(
80
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
81
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
82
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
83
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
84
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
85
-        'new_item'           => __( 'New Item', 'invoicing' ),
86
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
87
-        'view_item'          => __( 'View Item', 'invoicing' ),
88
-        'all_items'          => __( 'Items', 'invoicing' ),
89
-        'search_items'       => __( 'Search Items', 'invoicing' ),
80
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
81
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
82
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
83
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
84
+        'add_new_item'       => __('Add New Item', 'invoicing'),
85
+        'new_item'           => __('New Item', 'invoicing'),
86
+        'edit_item'          => __('Edit Item', 'invoicing'),
87
+        'view_item'          => __('View Item', 'invoicing'),
88
+        'all_items'          => __('Items', 'invoicing'),
89
+        'search_items'       => __('Search Items', 'invoicing'),
90 90
         'parent_item_colon'  => '',
91
-        'not_found'          => __( 'No items found.', 'invoicing' ),
92
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
91
+        'not_found'          => __('No items found.', 'invoicing'),
92
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
93 93
     );
94
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
94
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
95 95
 
96 96
     $cap_type = 'wpi_item';
97 97
     $invoice_item_args = array(
98 98
         'labels'                => $items_labels,
99 99
         'public'                => false,
100 100
         'show_ui'               => true,
101
-        'show_in_menu'          => current_user_can( 'manage_invoicing' ) ? 'wpinv' : false,
102
-        'supports'              => array( 'title', 'excerpt' ),
101
+        'show_in_menu'          => current_user_can('manage_invoicing') ? 'wpinv' : false,
102
+        'supports'              => array('title', 'excerpt'),
103 103
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
104 104
         'rewrite'               => false,
105 105
         'query_var'             => false,
@@ -123,40 +123,40 @@  discard block
 block discarded – undo
123 123
         ),
124 124
         'can_export'            => true,
125 125
     );
126
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
126
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
127 127
 
128
-    register_post_type( 'wpi_item', $invoice_item_args );
128
+    register_post_type('wpi_item', $invoice_item_args);
129 129
     
130 130
     $labels = array(
131
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
132
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
133
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
134
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
135
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
136
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
137
-        'new_item'           => __( 'New Discount', 'invoicing' ),
138
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
139
-        'view_item'          => __( 'View Discount', 'invoicing' ),
140
-        'all_items'          => __( 'Discounts', 'invoicing' ),
141
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
142
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
143
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
144
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
131
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
132
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
133
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
134
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
135
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
136
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
137
+        'new_item'           => __('New Discount', 'invoicing'),
138
+        'edit_item'          => __('Edit Discount', 'invoicing'),
139
+        'view_item'          => __('View Discount', 'invoicing'),
140
+        'all_items'          => __('Discounts', 'invoicing'),
141
+        'search_items'       => __('Search Discounts', 'invoicing'),
142
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
143
+        'not_found'          => __('No discounts found.', 'invoicing'),
144
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
145 145
     );
146
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
146
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
147 147
 
148 148
     $cap_type = 'wpi_discount';
149 149
     
150 150
     $args = array(
151 151
         'labels'             => $labels,
152
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
152
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
153 153
         'public'             => false,
154 154
         'can_export'         => true,
155 155
         '_builtin'           => false,
156 156
         'publicly_queryable' => false,
157 157
         'exclude_from_search'=> true,
158 158
         'show_ui'            => true,
159
-        'show_in_menu'       => current_user_can( 'manage_invoicing' ) ? 'wpinv' : false,
159
+        'show_in_menu'       => current_user_can('manage_invoicing') ? 'wpinv' : false,
160 160
         'query_var'          => false,
161 161
         'rewrite'            => false,
162 162
         'capability_type'    => $cap_type,
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         ),
180 180
         'has_archive'        => false,
181 181
         'hierarchical'       => false,
182
-        'supports'           => array( 'title', 'excerpt' ),
182
+        'supports'           => array('title', 'excerpt'),
183 183
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
184 184
         'show_in_nav_menus'  => false,
185 185
         'show_in_admin_bar'  => true,
@@ -187,107 +187,107 @@  discard block
 block discarded – undo
187 187
         'menu_position'      => null,
188 188
     );
189 189
             
190
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
190
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
191 191
     
192
-    register_post_type( 'wpi_discount', $args );
192
+    register_post_type('wpi_discount', $args);
193 193
 }
194 194
 
195 195
 function wpinv_get_default_labels() {
196 196
     $defaults = array(
197
-       'singular' => __( 'Invoice', 'invoicing' ),
198
-       'plural'   => __( 'Invoices', 'invoicing' )
197
+       'singular' => __('Invoice', 'invoicing'),
198
+       'plural'   => __('Invoices', 'invoicing')
199 199
     );
200 200
     
201
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
201
+    return apply_filters('wpinv_default_invoices_name', $defaults);
202 202
 }
203 203
 
204
-function wpinv_get_label_singular( $lowercase = false ) {
204
+function wpinv_get_label_singular($lowercase = false) {
205 205
     $defaults = wpinv_get_default_labels();
206 206
     
207
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
207
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
208 208
 }
209 209
 
210
-function wpinv_get_label_plural( $lowercase = false ) {
210
+function wpinv_get_label_plural($lowercase = false) {
211 211
     $defaults = wpinv_get_default_labels();
212 212
     
213
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
213
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
214 214
 }
215 215
 
216
-function wpinv_change_default_title( $title ) {
217
-     if ( !is_admin() ) {
216
+function wpinv_change_default_title($title) {
217
+     if (!is_admin()) {
218 218
         $label = wpinv_get_label_singular();
219
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
219
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
220 220
         return $title;
221 221
      }
222 222
 
223 223
      $screen = get_current_screen();
224 224
 
225
-     if ( 'wpi_invoice' == $screen->post_type ) {
225
+     if ('wpi_invoice' == $screen->post_type) {
226 226
         $label = wpinv_get_label_singular();
227
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
227
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
228 228
      }
229 229
 
230 230
      return $title;
231 231
 }
232
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
232
+add_filter('enter_title_here', 'wpinv_change_default_title');
233 233
 
234 234
 function wpinv_register_post_status() {
235
-    register_post_status( 'wpi-pending', array(
236
-        'label'                     => _x( 'Pending', 'Invoice status', 'invoicing' ),
235
+    register_post_status('wpi-pending', array(
236
+        'label'                     => _x('Pending', 'Invoice status', 'invoicing'),
237 237
         'public'                    => true,
238 238
         'exclude_from_search'       => true,
239 239
         'show_in_admin_all_list'    => true,
240 240
         'show_in_admin_status_list' => true,
241
-        'label_count'               => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' )
242
-    ) );
243
-    register_post_status( 'wpi-processing', array(
244
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
241
+        'label_count'               => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing')
242
+    ));
243
+    register_post_status('wpi-processing', array(
244
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
245 245
         'public'                    => true,
246 246
         'exclude_from_search'       => true,
247 247
         'show_in_admin_all_list'    => true,
248 248
         'show_in_admin_status_list' => true,
249
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
250
-    ) );
251
-    register_post_status( 'wpi-onhold', array(
252
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
249
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
250
+    ));
251
+    register_post_status('wpi-onhold', array(
252
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
253 253
         'public'                    => true,
254 254
         'exclude_from_search'       => true,
255 255
         'show_in_admin_all_list'    => true,
256 256
         'show_in_admin_status_list' => true,
257
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
258
-    ) );
259
-    register_post_status( 'wpi-cancelled', array(
260
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
257
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
258
+    ));
259
+    register_post_status('wpi-cancelled', array(
260
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
261 261
         'public'                    => true,
262 262
         'exclude_from_search'       => true,
263 263
         'show_in_admin_all_list'    => true,
264 264
         'show_in_admin_status_list' => true,
265
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
266
-    ) );
267
-    register_post_status( 'wpi-refunded', array(
268
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
265
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
266
+    ));
267
+    register_post_status('wpi-refunded', array(
268
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
269 269
         'public'                    => true,
270 270
         'exclude_from_search'       => true,
271 271
         'show_in_admin_all_list'    => true,
272 272
         'show_in_admin_status_list' => true,
273
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
274
-    ) );
275
-    register_post_status( 'wpi-failed', array(
276
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
273
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
274
+    ));
275
+    register_post_status('wpi-failed', array(
276
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
277 277
         'public'                    => true,
278 278
         'exclude_from_search'       => true,
279 279
         'show_in_admin_all_list'    => true,
280 280
         'show_in_admin_status_list' => true,
281
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
282
-    ) );
283
-    register_post_status( 'wpi-renewal', array(
284
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
281
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
282
+    ));
283
+    register_post_status('wpi-renewal', array(
284
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
285 285
         'public'                    => true,
286 286
         'exclude_from_search'       => true,
287 287
         'show_in_admin_all_list'    => true,
288 288
         'show_in_admin_status_list' => true,
289
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
290
-    ) );
289
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
290
+    ));
291 291
 }
292
-add_action( 'init', 'wpinv_register_post_status', 10 );
292
+add_action('init', 'wpinv_register_post_status', 10);
293 293
 
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) {
6
-    if ( empty( $user ) ) {
5
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') {
6
+    if (empty($user)) {
7 7
         $user = get_current_user_id();
8 8
     }
9 9
 
10
-    if ( 0 === $user ) {
10
+    if (0 === $user) {
11 11
         return false;
12 12
     }
13 13
 
14
-    if ( $pagination ) {
15
-        if ( get_query_var( 'paged' ) )
14
+    if ($pagination) {
15
+        if (get_query_var('paged'))
16 16
             $paged = get_query_var('paged');
17
-        else if ( get_query_var( 'page' ) )
18
-            $paged = get_query_var( 'page' );
17
+        else if (get_query_var('page'))
18
+            $paged = get_query_var('page');
19 19
         else
20 20
             $paged = 1;
21 21
     }
@@ -24,21 +24,21 @@  discard block
 block discarded – undo
24 24
         'post_type'      => 'wpi_invoice',
25 25
         'posts_per_page' => 20,
26 26
         'paged'          => null,
27
-        'post_status'    => array( 'publish', 'wpi-pending' ),
27
+        'post_status'    => array('publish', 'wpi-pending'),
28 28
         'user'           => $user,
29 29
         'order'          => 'date',
30 30
     );
31 31
 
32
-    $invoices = get_posts( $args );
32
+    $invoices = get_posts($args);
33 33
 
34 34
     // No invoices
35
-    if ( ! $invoices )
35
+    if (!$invoices)
36 36
         return false;
37 37
 
38 38
     return $invoices;
39 39
 }
40 40
 
41
-function wpinv_dropdown_users( $args = '' ) {
41
+function wpinv_dropdown_users($args = '') {
42 42
     $defaults = array(
43 43
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
44 44
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
         'option_none_value' => -1
50 50
     );
51 51
 
52
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
52
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
53 53
 
54
-    $r = wp_parse_args( $args, $defaults );
54
+    $r = wp_parse_args($args, $defaults);
55 55
 
56
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
56
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
57 57
 
58
-    $fields = array( 'ID', 'user_login', 'user_email' );
58
+    $fields = array('ID', 'user_login', 'user_email');
59 59
 
60
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
61
-    if ( 'display_name_with_login' === $show ) {
60
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
61
+    if ('display_name_with_login' === $show) {
62 62
         $fields[] = 'display_name';
63
-    } else if ( 'display_name_with_email' === $show ) {
63
+    } else if ('display_name_with_email' === $show) {
64 64
         $fields[] = 'display_name';
65 65
     } else {
66 66
         $fields[] = $show;
@@ -72,99 +72,99 @@  discard block
 block discarded – undo
72 72
     $show_option_none = $r['show_option_none'];
73 73
     $option_none_value = $r['option_none_value'];
74 74
 
75
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
75
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
76 76
 
77
-    $users = get_users( $query_args );
77
+    $users = get_users($query_args);
78 78
 
79 79
     $output = '';
80
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
81
-        $name = esc_attr( $r['name'] );
82
-        if ( $r['multi'] && ! $r['id'] ) {
80
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
81
+        $name = esc_attr($r['name']);
82
+        if ($r['multi'] && !$r['id']) {
83 83
             $id = '';
84 84
         } else {
85
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
85
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
86 86
         }
87 87
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
88 88
 
89
-        if ( $show_option_all ) {
89
+        if ($show_option_all) {
90 90
             $output .= "\t<option value='0'>$show_option_all</option>\n";
91 91
         }
92 92
 
93
-        if ( $show_option_none ) {
94
-            $_selected = selected( $option_none_value, $r['selected'], false );
95
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
93
+        if ($show_option_none) {
94
+            $_selected = selected($option_none_value, $r['selected'], false);
95
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
96 96
         }
97 97
 
98
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
98
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
99 99
             $found_selected = false;
100
-            $r['selected'] = (int) $r['selected'];
101
-            foreach ( (array) $users as $user ) {
102
-                $user->ID = (int) $user->ID;
103
-                if ( $user->ID === $r['selected'] ) {
100
+            $r['selected'] = (int)$r['selected'];
101
+            foreach ((array)$users as $user) {
102
+                $user->ID = (int)$user->ID;
103
+                if ($user->ID === $r['selected']) {
104 104
                     $found_selected = true;
105 105
                 }
106 106
             }
107 107
 
108
-            if ( ! $found_selected ) {
109
-                $users[] = get_userdata( $r['selected'] );
108
+            if (!$found_selected) {
109
+                $users[] = get_userdata($r['selected']);
110 110
             }
111 111
         }
112 112
 
113
-        foreach ( (array) $users as $user ) {
114
-            if ( 'display_name_with_login' === $show ) {
113
+        foreach ((array)$users as $user) {
114
+            if ('display_name_with_login' === $show) {
115 115
                 /* translators: 1: display name, 2: user_login */
116
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
117
-            } elseif ( 'display_name_with_email' === $show ) {
116
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
117
+            } elseif ('display_name_with_email' === $show) {
118 118
                 /* translators: 1: display name, 2: user_email */
119
-                if ( $user->display_name == $user->user_email ) {
119
+                if ($user->display_name == $user->user_email) {
120 120
                     $display = $user->display_name;
121 121
                 } else {
122
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
122
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
123 123
                 }
124
-            } elseif ( ! empty( $user->$show ) ) {
124
+            } elseif (!empty($user->$show)) {
125 125
                 $display = $user->$show;
126 126
             } else {
127 127
                 $display = '(' . $user->user_login . ')';
128 128
             }
129 129
 
130
-            $_selected = selected( $user->ID, $r['selected'], false );
131
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
130
+            $_selected = selected($user->ID, $r['selected'], false);
131
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
132 132
         }
133 133
 
134 134
         $output .= "</select>";
135 135
     }
136 136
 
137
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
137
+    $html = apply_filters('wpinv_dropdown_users', $output);
138 138
 
139
-    if ( $r['echo'] ) {
139
+    if ($r['echo']) {
140 140
         echo $html;
141 141
     }
142 142
     return $html;
143 143
 }
144 144
 
145
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
146
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
147
-        wpinv_login_user( $user_id );
145
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
146
+    if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) {
147
+        wpinv_login_user($user_id);
148 148
     } else {
149
-        $redirect_to = wp_login_url( $redirect_to );
149
+        $redirect_to = wp_login_url($redirect_to);
150 150
     }
151 151
     
152
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
152
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
153 153
     
154
-    wp_redirect( $redirect_to );
154
+    wp_redirect($redirect_to);
155 155
 }
156 156
 
157
-function wpinv_login_user( $user_id ) {
158
-    if ( is_user_logged_in() ) {
157
+function wpinv_login_user($user_id) {
158
+    if (is_user_logged_in()) {
159 159
         return true;
160 160
     }
161 161
     
162
-    $user = get_user_by( 'id', $user_id );
162
+    $user = get_user_by('id', $user_id);
163 163
     
164
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
165
-        wp_set_current_user( $user_id, $user->user_login );
166
-        wp_set_auth_cookie( $user_id );
167
-        do_action( 'wp_login', $user->user_login );
164
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
165
+        wp_set_current_user($user_id, $user->user_login);
166
+        wp_set_auth_cookie($user_id);
167
+        do_action('wp_login', $user->user_login);
168 168
         
169 169
         return true;
170 170
     }
Please login to merge, or discard this patch.
includes/gateways/bank_transfer.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  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_bank_transfer_cc_form', '__return_false' );
5
+add_action('wpinv_bank_transfer_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_bank_transfer_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_bank_transfer_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     // Collect payment data
@@ -24,37 +24,37 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
30
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
31
-        wpinv_update_payment_status( $invoice, 'wpi-pending' );
29
+    if (!empty($invoice)) {
30
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
31
+        wpinv_update_payment_status($invoice, 'wpi-pending');
32 32
         
33 33
         // Empty the shopping cart
34 34
         wpinv_empty_cart();
35 35
         
36
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
36
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
37 37
     } else {
38
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
38
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
39 39
         // If errors are present, send the user back to the purchase page so they can be corrected
40
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
40
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
41 41
     }
42 42
 }
43
-add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' );
43
+add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment');
44 44
 
45
-function wpinv_show_bank_info( $invoice ) {
46
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
47
-        $bank_info = wpinv_get_bank_info( true );
45
+function wpinv_show_bank_info($invoice) {
46
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
47
+        $bank_info = wpinv_get_bank_info(true);
48 48
         ?>
49 49
         <div class="wpinv-bank-details">
50
-            <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?>
51
-            <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div>
50
+            <?php if ($instructions = wpinv_get_bank_instructions()) { ?>
51
+            <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div>
52 52
             <?php } ?>
53
-            <?php if ( !empty( $bank_info ) ) { ?>
54
-            <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3>
53
+            <?php if (!empty($bank_info)) { ?>
54
+            <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3>
55 55
             <table class="table table-bordered table-sm wpi-bank-details">
56
-                <?php foreach ( $bank_info as $key => $info ) { ?>
57
-                <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr>
56
+                <?php foreach ($bank_info as $key => $info) { ?>
57
+                <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr>
58 58
                 <?php } ?>
59 59
             </table>
60 60
             <?php } ?>
@@ -62,15 +62,15 @@  discard block
 block discarded – undo
62 62
         <?php
63 63
     }
64 64
 }
65
-add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 );
65
+add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1);
66 66
 
67
-function wpinv_invoice_print_bank_info( $invoice ) {
68
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
67
+function wpinv_invoice_print_bank_info($invoice) {
68
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
69 69
         ?>
70 70
         <div class="row wpinv-bank-info">
71
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
71
+            <?php echo wpinv_show_bank_info($invoice); ?>
72 72
         </div>
73 73
         <?php
74 74
     }
75 75
 }
76
-add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 );
77 76
\ No newline at end of file
77
+add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1);
78 78
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 1 patch
Spacing   +266 added lines, -266 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,14 +278,14 @@  discard block
 block discarded – undo
278 278
             
279 279
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
280 280
 
281
-            if ( $invoice_info->invoice_type == 'add_franchise' ) {
281
+            if ($invoice_info->invoice_type == 'add_franchise') {
282 282
                 $custom_price = $invoice_info->amount;
283 283
             } else {
284 284
                 $custom_price = '';
285 285
             }
286 286
 
287
-            if ( !empty( $post_item ) ) {
288
-                $cart_details  = array();
287
+            if (!empty($post_item)) {
288
+                $cart_details = array();
289 289
                 $cart_details[] = array(
290 290
                     'id'            => $post_item->ID,
291 291
                     'name'          => $post_item->get_name(),
@@ -299,19 +299,19 @@  discard block
 block discarded – undo
299 299
                     ),
300 300
                 );
301 301
                 
302
-                $invoice_data['cart_details']  = $cart_details;
302
+                $invoice_data['cart_details'] = $cart_details;
303 303
             }
304 304
 
305
-            $data = array( 'invoice' => $invoice_data );
305
+            $data = array('invoice' => $invoice_data);
306 306
 
307 307
             $wpinv_api = new WPInv_API();
308
-            $data = $wpinv_api->insert_invoice( $data );
308
+            $data = $wpinv_api->insert_invoice($data);
309 309
             
310
-            if ( is_wp_error( $data ) ) {
311
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
310
+            if (is_wp_error($data)) {
311
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
312 312
             } else {
313
-                if ( !empty( $data ) ) {
314
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
313
+                if (!empty($data)) {
314
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
315 315
                     
316 316
                     $update_data = array();
317 317
                     $update_data['tax_amount'] = $data->get_tax();
@@ -319,14 +319,14 @@  discard block
 block discarded – undo
319 319
                     $update_data['invoice_id'] = $data->ID;
320 320
                     
321 321
                     global $wpdb;
322
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
322
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
323 323
                     
324 324
                     return $data;
325 325
                 } else {
326
-                    if ( $update ) {
327
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
326
+                    if ($update) {
327
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
328 328
                     } else {
329
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
329
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
330 330
                     }
331 331
                 }
332 332
             }
@@ -337,59 +337,59 @@  discard block
 block discarded – undo
337 337
 }
338 338
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
339 339
 
340
-function wpinv_cpt_update( $invoice_id ) {
341
-    return wpinv_cpt_save( $invoice_id, true );
340
+function wpinv_cpt_update($invoice_id) {
341
+    return wpinv_cpt_save($invoice_id, true);
342 342
 }
343 343
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
344 344
 
345
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'wpi-pending', $subscription = false ) {
346
-    $invoice_info = geodir_get_invoice( $invoice_id );
347
-    if ( empty( $invoice_info ) ) {
345
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'wpi-pending', $subscription = false) {
346
+    $invoice_info = geodir_get_invoice($invoice_id);
347
+    if (empty($invoice_info)) {
348 348
         return false;
349 349
     }
350 350
 
351
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
352
-    if ( !empty( $invoice ) ) {
351
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
352
+    if (!empty($invoice)) {
353 353
         $new_status = wpinv_gdp_to_wpi_status($new_status);
354
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
354
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
355 355
     } else {
356
-        $invoice = wpinv_cpt_save( $invoice_id );
356
+        $invoice = wpinv_cpt_save($invoice_id);
357 357
     }
358 358
     
359 359
     return $invoice;
360 360
 }
361
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
361
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
362 362
 
363
-function wpinv_transaction_details_note( $invoice_id, $html ) {
364
-    $invoice_info = geodir_get_invoice( $invoice_id );
365
-    if ( empty( $invoice_info ) ) {
363
+function wpinv_transaction_details_note($invoice_id, $html) {
364
+    $invoice_info = geodir_get_invoice($invoice_id);
365
+    if (empty($invoice_info)) {
366 366
         return false;
367 367
     }
368 368
 
369
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
369
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
370 370
     
371
-    if ( !$wpi_invoice_id ) {
372
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
371
+    if (!$wpi_invoice_id) {
372
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
373 373
         
374
-        if ( !empty( $invoice ) ) {
374
+        if (!empty($invoice)) {
375 375
             $wpi_invoice_id = $invoice->ID;
376 376
         }
377 377
     }
378 378
 
379
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
379
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
380 380
     
381
-    if ( empty( $invoice ) ) {
381
+    if (empty($invoice)) {
382 382
         return false;
383 383
     }
384 384
     
385
-    return $invoice->add_note( $html, true );
385
+    return $invoice->add_note($html, true);
386 386
 }
387
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
387
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
388 388
 
389
-function wpinv_gdp_to_wpi_status( $status ) {
389
+function wpinv_gdp_to_wpi_status($status) {
390 390
     $inv_status = $status ? $status : 'wpi-pending';
391 391
     
392
-    switch ( $status ) {
392
+    switch ($status) {
393 393
         case 'pending':
394 394
             $inv_status = 'wpi-pending';
395 395
         break;
@@ -412,10 +412,10 @@  discard block
 block discarded – undo
412 412
     return $inv_status;
413 413
 }
414 414
 
415
-function wpinv_wpi_to_gdp_status( $status ) {
415
+function wpinv_wpi_to_gdp_status($status) {
416 416
     $inv_status = $status ? $status : 'pending';
417 417
     
418
-    switch ( $status ) {
418
+    switch ($status) {
419 419
         case 'wpi-pending':
420 420
             $inv_status = 'pending';
421 421
         break;
@@ -441,72 +441,72 @@  discard block
 block discarded – undo
441 441
     return $inv_status;
442 442
 }
443 443
 
444
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
444
+function wpinv_wpi_to_gdp_id($invoice_id) {
445 445
     global $wpdb;
446 446
     
447
-    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 ) ) );
447
+    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)));
448 448
 }
449 449
 
450
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
451
-    $invoice = geodir_get_invoice( $invoice_id );    
452
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
450
+function wpinv_gdp_to_wpi_id($invoice_id) {
451
+    $invoice = geodir_get_invoice($invoice_id);    
452
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
453 453
 }
454 454
 
455
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
455
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
456 456
     global $wpdb;
457 457
     
458
-    if ( !empty( $wpi_nosave ) ) {
458
+    if (!empty($wpi_nosave)) {
459 459
         return;
460 460
     }
461 461
     
462
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
462
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
463 463
     
464
-    if ( $gdp_invoice_id > 0 ) {
464
+    if ($gdp_invoice_id > 0) {
465 465
         $update_data = array();
466 466
         $update_data['tax_amount']      = $invoice->tax;
467 467
         $update_data['paied_amount']    = $invoice->total;
468 468
         $update_data['discount']        = $invoice->discount;
469 469
         $update_data['coupon_code']     = $invoice->discount_code;
470 470
         
471
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
471
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
472 472
     }
473 473
     
474 474
     return;
475 475
 }
476 476
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
477 477
 
478
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
479
-    $invoice = geodir_get_invoice( $invoice_id );
480
-    if ( empty( $invoice->invoice_id ) ) {
478
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
479
+    $invoice = geodir_get_invoice($invoice_id);
480
+    if (empty($invoice->invoice_id)) {
481 481
         return false;
482 482
     }
483 483
     
484
-    return wpinv_get_invoice( $invoice->invoice_id );
484
+    return wpinv_get_invoice($invoice->invoice_id);
485 485
 }
486 486
 
487
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
488
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
489
-    if ( empty( $invoice ) ) {
487
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
488
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
489
+    if (empty($invoice)) {
490 490
         return $status;
491 491
     }
492 492
 
493
-    if ( $status === 1 || $status === 0 ) {
494
-        if ( $status === 1 ) {
495
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
493
+    if ($status === 1 || $status === 0) {
494
+        if ($status === 1) {
495
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
496 496
         } else {
497 497
             $discount = '';
498 498
             $coupon_code = '';
499 499
         }
500 500
         
501
-        $invoice->set( 'discount', $discount );
502
-        $invoice->set( 'discount_code', $coupon_code );
501
+        $invoice->set('discount', $discount);
502
+        $invoice->set('discount_code', $coupon_code);
503 503
         $invoice->save();
504 504
         $invoice->recalculate_total();
505 505
     }
506 506
     
507 507
     return $status;
508 508
 }
509
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
509
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
510 510
 
511 511
 function wpinv_merge_gd_invoices() {
512 512
     if (!defined('GEODIRPAYMENT_VERSION')) {
@@ -514,157 +514,157 @@  discard block
 block discarded – undo
514 514
     }
515 515
     ?>
516 516
     <tr>
517
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
518
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
519
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
517
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
518
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
519
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
520 520
     </tr>
521 521
     <tr>
522
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
523
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
524
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
522
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
523
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
524
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
525 525
     </tr>
526 526
 	<tr>
527
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
528
-        <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>
529
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
527
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
528
+        <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>
529
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
530 530
     </tr>
531 531
     <tr>
532
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
533
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
534
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
532
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
533
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
534
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
535 535
     </tr>
536 536
     <?php
537 537
 }
538
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
538
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
539 539
 
540 540
 function wpinv_tool_merge_packages() {
541 541
     $packages = geodir_package_list_info();
542 542
     
543 543
     $count = 0;
544 544
     
545
-    if ( !empty( $packages ) ) {
545
+    if (!empty($packages)) {
546 546
         $success = true;
547 547
         
548
-        foreach ( $packages as $key => $package ) {
548
+        foreach ($packages as $key => $package) {
549 549
             $item = wpinv_get_item_by('custom_id', $package->pid, 'package');
550
-            if ( !empty( $item ) ) {
550
+            if (!empty($item)) {
551 551
                 continue;
552 552
             }
553 553
             
554
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
554
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
555 555
             
556
-            if ( !empty( $merged ) ) {
557
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
556
+            if (!empty($merged)) {
557
+                wpinv_error_log('Package merge S : ' . $package->pid);
558 558
                 $count++;
559 559
             } else {
560
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
560
+                wpinv_error_log('Package merge F : ' . $package->pid);
561 561
             }
562 562
         }
563 563
         
564
-        if ( $count > 0 ) {
565
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
564
+        if ($count > 0) {
565
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
566 566
         } else {
567
-            $message = __( 'No price packages merged.', 'invoicing' );
567
+            $message = __('No price packages merged.', 'invoicing');
568 568
         }
569 569
     } else {
570 570
         $success = false;
571
-        $message = __( 'No price packages found to merge!', 'invoicing' );
571
+        $message = __('No price packages found to merge!', 'invoicing');
572 572
     }
573 573
     
574 574
     $response = array();
575 575
     $response['success'] = $success;
576 576
     $response['data']['message'] = $message;
577
-    wp_send_json( $response );
577
+    wp_send_json($response);
578 578
 }
579
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
579
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
580 580
 
581 581
 function wpinv_tool_merge_invoices() {
582 582
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
583 583
     
584 584
     $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";
585 585
 
586
-    $items = $wpdb->get_results( $sql );
586
+    $items = $wpdb->get_results($sql);
587 587
     
588 588
     $count = 0;
589 589
     
590
-    if ( !empty( $items ) ) {
590
+    if (!empty($items)) {
591 591
         $success = true;
592 592
         $wpi_gdp_inv_merge = true;
593 593
         
594
-        foreach ( $items as $item ) {
594
+        foreach ($items as $item) {
595 595
             $wpi_tax_rates = NULL;
596 596
             
597
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
597
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
598 598
             
599
-            $merged = wpinv_cpt_save( $item->id );
599
+            $merged = wpinv_cpt_save($item->id);
600 600
             
601
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
601
+            if (!empty($merged) && !empty($merged->ID)) {
602 602
                 $count++;
603 603
                 
604
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
605
-                $post_date_gmt = get_gmt_from_date( $post_date );
606
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
607
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
604
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
605
+                $post_date_gmt = get_gmt_from_date($post_date);
606
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
607
+                $post_modified_gmt = get_gmt_from_date($post_modified);
608 608
                 
609
-                $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 ) );
609
+                $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));
610 610
                 
611
-                if ( $merged->is_paid() ) {
612
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
611
+                if ($merged->is_paid()) {
612
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
613 613
                 }
614 614
                 
615
-                clean_post_cache( $merged->ID );
615
+                clean_post_cache($merged->ID);
616 616
                 
617
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
617
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
618 618
             } else {
619
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
619
+                wpinv_error_log('Invoice merge F : ' . $item->id);
620 620
             }
621 621
         }
622 622
         
623 623
         $wpi_gdp_inv_merge = false;
624 624
         
625
-        if ( $count > 0 ) {
626
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
625
+        if ($count > 0) {
626
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
627 627
         } else {
628
-            $message = __( 'No invoices merged.', 'invoicing' );
628
+            $message = __('No invoices merged.', 'invoicing');
629 629
         }
630 630
     } else {
631 631
         $success = false;
632
-        $message = __( 'No invoices found to merge!', 'invoicing' );
632
+        $message = __('No invoices found to merge!', 'invoicing');
633 633
     }
634 634
     
635 635
     $response = array();
636 636
     $response['success'] = $success;
637 637
     $response['data']['message'] = $message;
638
-    wp_send_json( $response );
638
+    wp_send_json($response);
639 639
 }
640
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
640
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
641 641
 
642 642
 function wpinv_tool_merge_coupons() {
643 643
     global $wpdb;
644 644
     
645 645
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
646
-    $items = $wpdb->get_results( $sql );
646
+    $items = $wpdb->get_results($sql);
647 647
     $count = 0;
648 648
     
649
-    if ( !empty( $items ) ) {
649
+    if (!empty($items)) {
650 650
         $success = true;
651 651
         
652
-        foreach ( $items as $item ) {
653
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
652
+        foreach ($items as $item) {
653
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
654 654
                 continue;
655 655
             }
656 656
             
657 657
             $args = array(
658 658
                 'post_type'   => 'wpi_discount',
659 659
                 'post_title'  => $item->coupon_code,
660
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
660
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
661 661
             );
662 662
 
663
-            $merged = wp_insert_post( $args );
663
+            $merged = wp_insert_post($args);
664 664
             
665 665
             $item_id = $item->cid;
666 666
             
667
-            if ( $merged ) {
667
+            if ($merged) {
668 668
                 $meta = array(
669 669
                     'code'              => $item->coupon_code,
670 670
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -672,65 +672,65 @@  discard block
 block discarded – undo
672 672
                     'max_uses'          => (int)$item->usage_limit,
673 673
                     'uses'              => (int)$item->usage_count,
674 674
                 );
675
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
675
+                wpinv_store_discount($merged, $meta, get_post($merged));
676 676
                 
677 677
                 $count++;
678 678
                 
679
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
679
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
680 680
             } else {
681
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
681
+                wpinv_error_log('Coupon merge F : ' . $item_id);
682 682
             }
683 683
         }
684 684
         
685
-        if ( $count > 0 ) {
686
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
685
+        if ($count > 0) {
686
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
687 687
         } else {
688
-            $message = __( 'No coupons merged.', 'invoicing' );
688
+            $message = __('No coupons merged.', 'invoicing');
689 689
         }
690 690
     } else {
691 691
         $success = false;
692
-        $message = __( 'No coupons found to merge!', 'invoicing' );
692
+        $message = __('No coupons found to merge!', 'invoicing');
693 693
     }
694 694
     
695 695
     $response = array();
696 696
     $response['success'] = $success;
697 697
     $response['data']['message'] = $message;
698
-    wp_send_json( $response );
698
+    wp_send_json($response);
699 699
 }
700
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
700
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
701 701
 
702
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
702
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
703 703
     return wpinv_get_currency();
704 704
 }
705
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
705
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
706 706
 
707
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
707
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
708 708
     return wpinv_currency_symbol();
709 709
 }
710
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
710
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
711 711
 
712
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
713
-    if ( !$display ) {
714
-        $price = wpinv_round_amount( $amount );
712
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
713
+    if (!$display) {
714
+        $price = wpinv_round_amount($amount);
715 715
     } else {
716
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
716
+        $price = wpinv_price(wpinv_format_amount($amount));
717 717
     }
718 718
     
719 719
     return $price;
720 720
 }
721
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
721
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
722 722
 
723
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
723
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
724 724
     $invoice_id         = geodir_payment_cart_id();
725
-    $invoice_info       = geodir_get_invoice( $invoice_id );
726
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
725
+    $invoice_info       = geodir_get_invoice($invoice_id);
726
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
727 727
     
728
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
729
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
730
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
728
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
729
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
730
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
731 731
     }
732 732
     
733
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
733
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
734 734
         
735 735
         // Clear cart
736 736
         geodir_payment_clear_cart();
@@ -740,121 +740,121 @@  discard block
 block discarded – undo
740 740
     
741 741
     return $redirect_url;
742 742
 }
743
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
743
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
744 744
 
745
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
746
-    if ( get_current_user_id() ) {        
747
-        $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>';
745
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
746
+    if (get_current_user_id()) {        
747
+        $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>';
748 748
     }
749 749
 
750 750
     return $dashboard_links;
751 751
 }
752
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
753
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
752
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
753
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
754 754
 
755
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
755
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
756 756
     if (!defined('GEODIRPAYMENT_VERSION')) {
757 757
         return false;
758 758
     }
759 759
     
760
-    $invoice    = wpinv_get_invoice( $invoice_id );
761
-    if ( empty( $invoice ) ) {
760
+    $invoice = wpinv_get_invoice($invoice_id);
761
+    if (empty($invoice)) {
762 762
         return false;
763 763
     }
764 764
     
765
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
765
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
766 766
     
767
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
768
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
767
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
768
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
769 769
     
770
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
770
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
771 771
 }
772
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
772
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
773 773
 
774
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
775
-    $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' );
774
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
775
+    $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package');
776 776
     
777
-    if ( !empty( $item ) ) {
778
-        wpinv_remove_item( $item, true );
777
+    if (!empty($item)) {
778
+        wpinv_remove_item($item, true);
779 779
     }
780 780
 }
781
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
781
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
782 782
 
783
-function wpinv_can_delete_package_item( $return, $post_id ) {
784
-    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 ) ) {
785
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
783
+function wpinv_can_delete_package_item($return, $post_id) {
784
+    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)) {
785
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
786 786
         
787
-        if ( !empty( $gd_package ) ) {
787
+        if (!empty($gd_package)) {
788 788
             $return = false;
789 789
         }
790 790
     }
791 791
 
792 792
     return $return;
793 793
 }
794
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
794
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
795 795
 
796
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
796
+function wpinv_package_item_classes($classes, $class, $post_id) {
797 797
     global $typenow;
798 798
 
799
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
800
-        if ( wpinv_item_in_use( $post_id ) ) {
799
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
800
+        if (wpinv_item_in_use($post_id)) {
801 801
             $classes[] = 'wpi-inuse-pkg';
802
-        } 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 ), '' ) ) ) {
802
+        } 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), ''))) {
803 803
             $classes[] = 'wpi-delete-pkg';
804 804
         }
805 805
     }
806 806
 
807 807
     return $classes;
808 808
 }
809
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
809
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
810 810
 
811
-function wpinv_gdp_package_type_info( $post ) {
812
-    if ( wpinv_pm_active() ) {
813
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
811
+function wpinv_gdp_package_type_info($post) {
812
+    if (wpinv_pm_active()) {
813
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
814 814
         <?php
815 815
     }
816 816
 }
817
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
817
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
818 818
 
819
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
819
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
820 820
     global $wpi_zero_tax;
821 821
 
822
-    if ( $wpi_zero_tax ) {
822
+    if ($wpi_zero_tax) {
823 823
         $is_taxable = false;
824 824
     }
825 825
 
826 826
     return $is_taxable;
827 827
 }
828
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
828
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
829 829
 
830 830
 function wpinv_tool_merge_fix_taxes() {
831 831
     global $wpdb;
832 832
     
833 833
 	$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'";
834
-	$items = $wpdb->get_results( $sql );
834
+	$items = $wpdb->get_results($sql);
835 835
 	
836
-	if ( !empty( $items ) ) {
837
-		foreach ( $items as $item ) {
838
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
839
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
836
+	if (!empty($items)) {
837
+		foreach ($items as $item) {
838
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
839
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
840 840
 			}
841 841
 		}
842 842
 	}
843 843
 		
844 844
     $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";
845
-    $items = $wpdb->get_results( $sql );
845
+    $items = $wpdb->get_results($sql);
846 846
 	
847
-	if ( !empty( $items ) ) {
847
+	if (!empty($items)) {
848 848
 		$success = false;
849
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
849
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
850 850
 		
851 851
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
852 852
 		
853
-		foreach ( $items as $item ) {
853
+		foreach ($items as $item) {
854 854
 			$wpi_tax_rates = NULL;               
855 855
 			$data = wpinv_get_invoice($item->ID);
856 856
 
857
-			if ( empty( $data ) ) {
857
+			if (empty($data)) {
858 858
 				continue;
859 859
 			}
860 860
 			
@@ -862,51 +862,51 @@  discard block
 block discarded – undo
862 862
 			
863 863
 			$data_session                   = array();
864 864
 			$data_session['invoice_id']     = $data->ID;
865
-			$data_session['cart_discounts'] = $data->get_discounts( true );
865
+			$data_session['cart_discounts'] = $data->get_discounts(true);
866 866
 			
867
-			wpinv_set_checkout_session( $data_session );
867
+			wpinv_set_checkout_session($data_session);
868 868
 			
869 869
 			$wpi_userID         = (int)$data->get_user_id();
870 870
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
871 871
 				
872
-			$data->country      = sanitize_text_field( $_POST['country'] );
873
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
872
+			$data->country      = sanitize_text_field($_POST['country']);
873
+			$data->set('country', sanitize_text_field($_POST['country']));
874 874
 			
875 875
 			$wpinv_ip_address_country = $data->country;
876 876
 			
877 877
 			$data->recalculate_totals(true);
878 878
 			
879
-			wpinv_set_checkout_session( $checkout_session );
879
+			wpinv_set_checkout_session($checkout_session);
880 880
 			
881 881
 			$update_data = array();
882 882
 			$update_data['tax_amount'] = $data->get_tax();
883 883
 			$update_data['paied_amount'] = $data->get_total();
884 884
 			$update_data['invoice_id'] = $data->ID;
885 885
 			
886
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
886
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
887 887
 		}
888 888
 	} else {
889 889
         $success = false;
890
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
890
+        $message = __('No invoices found to fix taxes!', 'invoicing');
891 891
     }
892 892
 	
893 893
 	$response = array();
894 894
     $response['success'] = $success;
895 895
     $response['data']['message'] = $message;
896
-    wp_send_json( $response );
896
+    wp_send_json($response);
897 897
 }
898
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
899
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
898
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
899
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
900 900
 
901
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
902
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
903
-        if ( $invoice->is_renewal() ) {
901
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
902
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
903
+        if ($invoice->is_renewal()) {
904 904
             $invoice = $invoice->get_parent_payment();
905 905
         }
906 906
         
907
-        if ( !empty( $invoice ) ) {
908
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
907
+        if (!empty($invoice)) {
908
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
909 909
         }
910 910
     }
911 911
 }
912
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
913 912
\ No newline at end of file
913
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
914 914
\ No newline at end of file
Please login to merge, or discard this patch.