Passed
Pull Request — master (#153)
by Kiran
04:27
created
includes/wpinv-discount-functions.php 1 patch
Spacing   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,96 +189,96 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
 
216
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
216
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
217 217
         $meta['amount'] = 100;
218 218
     }
219 219
 
220
-    if ( !empty( $meta['start'] ) ) {
221
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
220
+    if (!empty($meta['start'])) {
221
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
222 222
     }
223 223
 
224
-    if ( !empty( $meta['expiration'] ) ) {
225
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
224
+    if (!empty($meta['expiration'])) {
225
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
226 226
 
227
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
227
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
228 228
             $meta['expiration'] = $meta['start'];
229 229
         }
230 230
     }
231 231
     
232
-    if ( $meta['uses'] === false ) {
233
-        unset( $meta['uses'] );
232
+    if ($meta['uses'] === false) {
233
+        unset($meta['uses']);
234 234
     }
235 235
     
236
-    if ( ! empty( $meta['items'] ) ) {
237
-        foreach ( $meta['items'] as $key => $item ) {
238
-            if ( 0 === intval( $item ) ) {
239
-                unset( $meta['items'][ $key ] );
236
+    if (!empty($meta['items'])) {
237
+        foreach ($meta['items'] as $key => $item) {
238
+            if (0 === intval($item)) {
239
+                unset($meta['items'][$key]);
240 240
             }
241 241
         }
242 242
     }
243 243
     
244
-    if ( ! empty( $meta['excluded_items'] ) ) {
245
-        foreach ( $meta['excluded_items'] as $key => $item ) {
246
-            if ( 0 === intval( $item ) ) {
247
-                unset( $meta['excluded_items'][ $key ] );
244
+    if (!empty($meta['excluded_items'])) {
245
+        foreach ($meta['excluded_items'] as $key => $item) {
246
+            if (0 === intval($item)) {
247
+                unset($meta['excluded_items'][$key]);
248 248
             }
249 249
         }
250 250
     }
251 251
     
252
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
252
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
253 253
     
254
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
254
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
255 255
     
256
-    foreach( $meta as $key => $value ) {
257
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
256
+    foreach ($meta as $key => $value) {
257
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
258 258
     }
259 259
     
260
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
260
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
261 261
     
262 262
     return $post_id;
263 263
 }
264 264
 
265
-function wpinv_remove_discount( $discount_id = 0 ) {
266
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
265
+function wpinv_remove_discount($discount_id = 0) {
266
+    do_action('wpinv_pre_delete_discount', $discount_id);
267 267
 
268
-    wp_delete_post( $discount_id, true );
268
+    wp_delete_post($discount_id, true);
269 269
 
270
-    do_action( 'wpinv_post_delete_discount', $discount_id );
270
+    do_action('wpinv_post_delete_discount', $discount_id);
271 271
 }
272 272
 
273
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
274
-    $discount = wpinv_get_discount(  $code_id );
273
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
274
+    $discount = wpinv_get_discount($code_id);
275 275
 
276
-    if ( $discount ) {
277
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
276
+    if ($discount) {
277
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
278 278
 
279
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
279
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
280 280
 
281
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
281
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
282 282
 
283 283
         return true;
284 284
     }
@@ -286,173 +286,173 @@  discard block
 block discarded – undo
286 286
     return false;
287 287
 }
288 288
 
289
-function wpinv_discount_exists( $code_id ) {
290
-    if ( wpinv_get_discount(  $code_id ) ) {
289
+function wpinv_discount_exists($code_id) {
290
+    if (wpinv_get_discount($code_id)) {
291 291
         return true;
292 292
     }
293 293
 
294 294
     return false;
295 295
 }
296 296
 
297
-function wpinv_is_discount_active( $code_id = null ) {
298
-    $discount = wpinv_get_discount(  $code_id );
297
+function wpinv_is_discount_active($code_id = null) {
298
+    $discount = wpinv_get_discount($code_id);
299 299
     $return   = false;
300 300
 
301
-    if ( $discount ) {
302
-        if ( wpinv_is_discount_expired( $code_id ) ) {
303
-            if( defined( 'DOING_AJAX' ) ) {
304
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
301
+    if ($discount) {
302
+        if (wpinv_is_discount_expired($code_id)) {
303
+            if (defined('DOING_AJAX')) {
304
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
305 305
             }
306
-        } elseif ( $discount->post_status == 'publish' ) {
306
+        } elseif ($discount->post_status == 'publish') {
307 307
             $return = true;
308 308
         } else {
309
-            if( defined( 'DOING_AJAX' ) ) {
310
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
309
+            if (defined('DOING_AJAX')) {
310
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
311 311
             }
312 312
         }
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
315
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
316 316
 }
317 317
 
318
-function wpinv_get_discount_code( $code_id = null ) {
319
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
318
+function wpinv_get_discount_code($code_id = null) {
319
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
320 320
 
321
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
321
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
322 322
 }
323 323
 
324
-function wpinv_get_discount_start_date( $code_id = null ) {
325
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
324
+function wpinv_get_discount_start_date($code_id = null) {
325
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
326 326
 
327
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
327
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
328 328
 }
329 329
 
330
-function wpinv_get_discount_expiration( $code_id = null ) {
331
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
330
+function wpinv_get_discount_expiration($code_id = null) {
331
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
332 332
 
333
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
333
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
334 334
 }
335 335
 
336
-function wpinv_get_discount_max_uses( $code_id = null ) {
337
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
336
+function wpinv_get_discount_max_uses($code_id = null) {
337
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
338 338
 
339
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
339
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
340 340
 }
341 341
 
342
-function wpinv_get_discount_uses( $code_id = null ) {
343
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
342
+function wpinv_get_discount_uses($code_id = null) {
343
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
344 344
 
345
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
345
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
346 346
 }
347 347
 
348
-function wpinv_get_discount_min_total( $code_id = null ) {
349
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
348
+function wpinv_get_discount_min_total($code_id = null) {
349
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
350 350
 
351
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
351
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
352 352
 }
353 353
 
354
-function wpinv_get_discount_max_total( $code_id = null ) {
355
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
354
+function wpinv_get_discount_max_total($code_id = null) {
355
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
356 356
 
357
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
357
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
358 358
 }
359 359
 
360
-function wpinv_get_discount_amount( $code_id = null ) {
361
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
360
+function wpinv_get_discount_amount($code_id = null) {
361
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
362 362
 
363
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
363
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
364 364
 }
365 365
 
366
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
367
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
366
+function wpinv_get_discount_type($code_id = null, $name = false) {
367
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
368 368
     
369
-    if ( $name ) {
370
-        $name = wpinv_get_discount_type_name( $type );
369
+    if ($name) {
370
+        $name = wpinv_get_discount_type_name($type);
371 371
         
372
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
372
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
375
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
376 376
 }
377 377
 
378
-function wpinv_discount_status( $status ) {
379
-    switch( $status ){
378
+function wpinv_discount_status($status) {
379
+    switch ($status) {
380 380
         case 'expired' :
381
-            $name = __( 'Expired', 'invoicing' );
381
+            $name = __('Expired', 'invoicing');
382 382
             break;
383 383
         case 'publish' :
384 384
         case 'active' :
385
-            $name = __( 'Active', 'invoicing' );
385
+            $name = __('Active', 'invoicing');
386 386
             break;
387 387
         default :
388
-            $name = __( 'Inactive', 'invoicing' );
388
+            $name = __('Inactive', 'invoicing');
389 389
             break;
390 390
     }
391 391
     return $name;
392 392
 }
393 393
 
394
-function wpinv_get_discount_excluded_items( $code_id = null ) {
395
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
394
+function wpinv_get_discount_excluded_items($code_id = null) {
395
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
396 396
 
397
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
397
+    if (empty($excluded_items) || !is_array($excluded_items)) {
398 398
         $excluded_items = array();
399 399
     }
400 400
 
401
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
401
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
402 402
 }
403 403
 
404
-function wpinv_get_discount_item_reqs( $code_id = null ) {
405
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
404
+function wpinv_get_discount_item_reqs($code_id = null) {
405
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
406 406
 
407
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
407
+    if (empty($item_reqs) || !is_array($item_reqs)) {
408 408
         $item_reqs = array();
409 409
     }
410 410
 
411
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
411
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
415
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
414
+function wpinv_get_discount_item_condition($code_id = 0) {
415
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
416 416
 }
417 417
 
418
-function wpinv_is_discount_not_global( $code_id = 0 ) {
419
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
418
+function wpinv_is_discount_not_global($code_id = 0) {
419
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
420 420
 }
421 421
 
422
-function wpinv_is_discount_expired( $code_id = null ) {
423
-    $discount = wpinv_get_discount(  $code_id );
422
+function wpinv_is_discount_expired($code_id = null) {
423
+    $discount = wpinv_get_discount($code_id);
424 424
     $return   = false;
425 425
 
426
-    if ( $discount ) {
427
-        $expiration = wpinv_get_discount_expiration( $code_id );
428
-        if ( $expiration ) {
429
-            $expiration = strtotime( $expiration );
430
-            if ( $expiration < current_time( 'timestamp' ) ) {
426
+    if ($discount) {
427
+        $expiration = wpinv_get_discount_expiration($code_id);
428
+        if ($expiration) {
429
+            $expiration = strtotime($expiration);
430
+            if ($expiration < current_time('timestamp')) {
431 431
                 // Discount is expired
432
-                wpinv_update_discount_status( $code_id, 'pending' );
432
+                wpinv_update_discount_status($code_id, 'pending');
433 433
                 $return = true;
434 434
             }
435 435
         }
436 436
     }
437 437
 
438
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
438
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
439 439
 }
440 440
 
441
-function wpinv_is_discount_started( $code_id = null ) {
442
-    $discount = wpinv_get_discount(  $code_id );
441
+function wpinv_is_discount_started($code_id = null) {
442
+    $discount = wpinv_get_discount($code_id);
443 443
     $return   = false;
444 444
 
445
-    if ( $discount ) {
446
-        $start_date = wpinv_get_discount_start_date( $code_id );
445
+    if ($discount) {
446
+        $start_date = wpinv_get_discount_start_date($code_id);
447 447
 
448
-        if ( $start_date ) {
449
-            $start_date = strtotime( $start_date );
448
+        if ($start_date) {
449
+            $start_date = strtotime($start_date);
450 450
 
451
-            if ( $start_date < current_time( 'timestamp' ) ) {
451
+            if ($start_date < current_time('timestamp')) {
452 452
                 // Discount has past the start date
453 453
                 $return = true;
454 454
             } else {
455
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
455
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
456 456
             }
457 457
         } else {
458 458
             // No start date for this discount, so has to be true
@@ -460,159 +460,159 @@  discard block
 block discarded – undo
460 460
         }
461 461
     }
462 462
 
463
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
463
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
464 464
 }
465 465
 
466
-function wpinv_check_discount_dates( $code_id = null ) {
467
-    $discount = wpinv_get_discount(  $code_id );
466
+function wpinv_check_discount_dates($code_id = null) {
467
+    $discount = wpinv_get_discount($code_id);
468 468
     $return   = false;
469 469
 
470
-    if ( $discount ) {
471
-        $start_date = wpinv_get_discount_start_date( $code_id );
470
+    if ($discount) {
471
+        $start_date = wpinv_get_discount_start_date($code_id);
472 472
 
473
-        if ( $start_date ) {
474
-            $start_date = strtotime( $start_date );
473
+        if ($start_date) {
474
+            $start_date = strtotime($start_date);
475 475
 
476
-            if ( $start_date < current_time( 'timestamp' ) ) {
476
+            if ($start_date < current_time('timestamp')) {
477 477
                 // Discount has past the start date
478 478
                 $return = true;
479 479
             } else {
480
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
480
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
481 481
             }
482 482
         } else {
483 483
             // No start date for this discount, so has to be true
484 484
             $return = true;
485 485
         }
486 486
         
487
-        if ( $return ) {
488
-            $expiration = wpinv_get_discount_expiration( $code_id );
487
+        if ($return) {
488
+            $expiration = wpinv_get_discount_expiration($code_id);
489 489
             
490
-            if ( $expiration ) {
491
-                $expiration = strtotime( $expiration );
492
-                if ( $expiration < current_time( 'timestamp' ) ) {
490
+            if ($expiration) {
491
+                $expiration = strtotime($expiration);
492
+                if ($expiration < current_time('timestamp')) {
493 493
                     // Discount is expired
494
-                    wpinv_update_discount_status( $code_id, 'pending' );
494
+                    wpinv_update_discount_status($code_id, 'pending');
495 495
                     $return = true;
496 496
                 }
497 497
             }
498 498
         }
499 499
     }
500 500
     
501
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
501
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
502 502
 }
503 503
 
504
-function wpinv_is_discount_maxed_out( $code_id = null ) {
505
-    $discount = wpinv_get_discount(  $code_id );
504
+function wpinv_is_discount_maxed_out($code_id = null) {
505
+    $discount = wpinv_get_discount($code_id);
506 506
     $return   = false;
507 507
 
508
-    if ( $discount ) {
509
-        $uses = wpinv_get_discount_uses( $code_id );
508
+    if ($discount) {
509
+        $uses = wpinv_get_discount_uses($code_id);
510 510
         // Large number that will never be reached
511
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
511
+        $max_uses = wpinv_get_discount_max_uses($code_id);
512 512
         // Should never be greater than, but just in case
513
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
513
+        if ($uses >= $max_uses && !empty($max_uses)) {
514 514
             // Discount is maxed out
515
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
515
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
516 516
             $return = true;
517 517
         }
518 518
     }
519 519
 
520
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
520
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
521 521
 }
522 522
 
523
-function wpinv_discount_is_min_met( $code_id = null ) {
524
-    $discount = wpinv_get_discount( $code_id );
523
+function wpinv_discount_is_min_met($code_id = null) {
524
+    $discount = wpinv_get_discount($code_id);
525 525
     $return   = false;
526 526
 
527
-    if ( $discount ) {
528
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
529
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
527
+    if ($discount) {
528
+        $min         = (float)wpinv_get_discount_min_total($code_id);
529
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
530 530
 
531
-        if ( !$min > 0 || $cart_amount >= $min ) {
531
+        if (!$min > 0 || $cart_amount >= $min) {
532 532
             // Minimum has been met
533 533
             $return = true;
534 534
         } else {
535
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
535
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
536 536
         }
537 537
     }
538 538
 
539
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
539
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
540 540
 }
541 541
 
542
-function wpinv_discount_is_max_met( $code_id = null ) {
543
-    $discount = wpinv_get_discount( $code_id );
542
+function wpinv_discount_is_max_met($code_id = null) {
543
+    $discount = wpinv_get_discount($code_id);
544 544
     $return   = false;
545 545
 
546
-    if ( $discount ) {
547
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
548
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
546
+    if ($discount) {
547
+        $max         = (float)wpinv_get_discount_max_total($code_id);
548
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
549 549
 
550
-        if ( !$max > 0 || $cart_amount <= $max ) {
550
+        if (!$max > 0 || $cart_amount <= $max) {
551 551
             // Minimum has been met
552 552
             $return = true;
553 553
         } else {
554
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
554
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
555 555
         }
556 556
     }
557 557
 
558
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
558
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
559 559
 }
560 560
 
561
-function wpinv_discount_is_single_use( $code_id = 0 ) {
562
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
563
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
561
+function wpinv_discount_is_single_use($code_id = 0) {
562
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
563
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
564 564
 }
565 565
 
566
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
567
-    if ( $code ) {
568
-        $discount = wpinv_get_discount_by_code( $code_id );
566
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
567
+    if ($code) {
568
+        $discount = wpinv_get_discount_by_code($code_id);
569 569
         
570
-        if ( !empty( $discount ) ) {
570
+        if (!empty($discount)) {
571 571
             $code_id = $discount->ID;
572 572
         }
573 573
     }
574 574
     
575
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
575
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
576 576
     
577
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
577
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
578 578
 }
579 579
 
580
-function wpinv_discount_item_reqs_met( $code_id = null ) {
581
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
582
-    $condition    = wpinv_get_discount_item_condition( $code_id );
583
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
580
+function wpinv_discount_item_reqs_met($code_id = null) {
581
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
582
+    $condition    = wpinv_get_discount_item_condition($code_id);
583
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
584 584
     $cart_items   = wpinv_get_cart_contents();
585
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
585
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
586 586
     $ret          = false;
587 587
 
588
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
588
+    if (empty($item_reqs) && empty($excluded_ps)) {
589 589
         $ret = true;
590 590
     }
591 591
 
592 592
     // Normalize our data for item requirements, exclusions and cart data
593 593
     // First absint the items, then sort, and reset the array keys
594
-    $item_reqs = array_map( 'absint', $item_reqs );
595
-    asort( $item_reqs );
596
-    $item_reqs = array_values( $item_reqs );
594
+    $item_reqs = array_map('absint', $item_reqs);
595
+    asort($item_reqs);
596
+    $item_reqs = array_values($item_reqs);
597 597
 
598
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
599
-    asort( $excluded_ps );
600
-    $excluded_ps  = array_values( $excluded_ps );
598
+    $excluded_ps  = array_map('absint', $excluded_ps);
599
+    asort($excluded_ps);
600
+    $excluded_ps  = array_values($excluded_ps);
601 601
 
602
-    $cart_ids     = array_map( 'absint', $cart_ids );
603
-    asort( $cart_ids );
604
-    $cart_ids     = array_values( $cart_ids );
602
+    $cart_ids     = array_map('absint', $cart_ids);
603
+    asort($cart_ids);
604
+    $cart_ids     = array_values($cart_ids);
605 605
 
606 606
     // Ensure we have requirements before proceeding
607
-    if ( !$ret && ! empty( $item_reqs ) ) {
608
-        switch( $condition ) {
607
+    if (!$ret && !empty($item_reqs)) {
608
+        switch ($condition) {
609 609
             case 'all' :
610 610
                 // Default back to true
611 611
                 $ret = true;
612 612
 
613
-                foreach ( $item_reqs as $item_id ) {
614
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
615
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
613
+                foreach ($item_reqs as $item_id) {
614
+                    if (!wpinv_item_in_cart($item_id)) {
615
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
616 616
                         $ret = false;
617 617
                         break;
618 618
                     }
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 break;
622 622
 
623 623
             default : // Any
624
-                foreach ( $item_reqs as $item_id ) {
625
-                    if ( wpinv_item_in_cart( $item_id ) ) {
624
+                foreach ($item_reqs as $item_id) {
625
+                    if (wpinv_item_in_cart($item_id)) {
626 626
                         $ret = true;
627 627
                         break;
628 628
                     }
629 629
                 }
630 630
 
631
-                if( ! $ret ) {
632
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
631
+                if (!$ret) {
632
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
633 633
                 }
634 634
 
635 635
                 break;
@@ -638,70 +638,70 @@  discard block
 block discarded – undo
638 638
         $ret = true;
639 639
     }
640 640
 
641
-    if( ! empty( $excluded_ps ) ) {
641
+    if (!empty($excluded_ps)) {
642 642
         // Check that there are items other than excluded ones in the cart
643
-        if( $cart_ids == $excluded_ps ) {
644
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
643
+        if ($cart_ids == $excluded_ps) {
644
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
645 645
             $ret = false;
646 646
         }
647 647
     }
648 648
 
649
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
649
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
650 650
 }
651 651
 
652
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
652
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
653 653
     global $wpi_checkout_id;
654 654
     
655 655
     $return = false;
656 656
 
657
-    if ( empty( $code_id ) ) {
658
-        $code_id = wpinv_get_discount_id_by_code( $code );
657
+    if (empty($code_id)) {
658
+        $code_id = wpinv_get_discount_id_by_code($code);
659 659
         
660
-        if( empty( $code_id ) ) {
660
+        if (empty($code_id)) {
661 661
             return false; // No discount was found
662 662
         }
663 663
     }
664 664
 
665
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
665
+    if (wpinv_discount_is_single_use($code_id)) {
666 666
         $payments = array();
667 667
 
668 668
         $user_id = 0;
669
-        if ( is_int( $user ) ) {
670
-            $user_id = absint( $user );
671
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
669
+        if (is_int($user)) {
670
+            $user_id = absint($user);
671
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
672 672
             $user_id = $user_data->ID;
673
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
673
+        } else if ($user_data = get_user_by('login', $user)) {
674 674
             $user_id = $user_data->ID;
675
-        } else if ( absint( $user ) > 0 ) {
676
-            $user_id = absint( $user );
675
+        } else if (absint($user) > 0) {
676
+            $user_id = absint($user);
677 677
         }
678 678
 
679
-        if ( !empty( $user_id ) ) {
680
-            $query    = array( 'user' => $user_id, 'limit' => false );
681
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
679
+        if (!empty($user_id)) {
680
+            $query    = array('user' => $user_id, 'limit' => false);
681
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
682 682
         }
683 683
 
684
-        if ( $payments ) {
685
-            foreach ( $payments as $payment ) {
684
+        if ($payments) {
685
+            foreach ($payments as $payment) {
686 686
                 // Don't count discount used for current invoice chekcout.
687
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
687
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
688 688
                     continue;
689 689
                 }
690 690
                 
691
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
691
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
692 692
                     continue;
693 693
                 }
694 694
 
695
-                $discounts = $payment->get_discounts( true );
696
-                if ( empty( $discounts ) ) {
695
+                $discounts = $payment->get_discounts(true);
696
+                if (empty($discounts)) {
697 697
                     continue;
698 698
                 }
699 699
 
700
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
700
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
701 701
 
702
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
703
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
704
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
702
+                if (!empty($discounts) && is_array($discounts)) {
703
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
704
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
705 705
                         $return = true;
706 706
                         break;
707 707
                     }
@@ -710,61 +710,61 @@  discard block
 block discarded – undo
710 710
         }
711 711
     }
712 712
 
713
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
713
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
714 714
 }
715 715
 
716
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
716
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
717 717
     $return      = false;
718
-    $discount_id = wpinv_get_discount_id_by_code( $code );
719
-    $user        = trim( $user );
718
+    $discount_id = wpinv_get_discount_id_by_code($code);
719
+    $user        = trim($user);
720 720
 
721
-    if ( wpinv_get_cart_contents() ) {
722
-        if ( $discount_id ) {
721
+    if (wpinv_get_cart_contents()) {
722
+        if ($discount_id) {
723 723
             if (
724
-                wpinv_is_discount_active( $discount_id ) &&
725
-                wpinv_check_discount_dates( $discount_id ) &&
726
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
727
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
728
-                wpinv_discount_is_min_met( $discount_id ) &&
729
-                wpinv_discount_is_max_met( $discount_id ) &&
730
-                wpinv_discount_item_reqs_met( $discount_id )
724
+                wpinv_is_discount_active($discount_id) &&
725
+                wpinv_check_discount_dates($discount_id) &&
726
+                !wpinv_is_discount_maxed_out($discount_id) &&
727
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
728
+                wpinv_discount_is_min_met($discount_id) &&
729
+                wpinv_discount_is_max_met($discount_id) &&
730
+                wpinv_discount_item_reqs_met($discount_id)
731 731
             ) {
732 732
                 $return = true;
733 733
             }
734
-        } elseif( $set_error ) {
735
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
734
+        } elseif ($set_error) {
735
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
736 736
         }
737 737
     }
738 738
 
739
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
739
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
740 740
 }
741 741
 
742
-function wpinv_get_discount_id_by_code( $code ) {
743
-    $discount = wpinv_get_discount_by_code( $code );
744
-    if( $discount ) {
742
+function wpinv_get_discount_id_by_code($code) {
743
+    $discount = wpinv_get_discount_by_code($code);
744
+    if ($discount) {
745 745
         return $discount->ID;
746 746
     }
747 747
     return false;
748 748
 }
749 749
 
750
-function wpinv_get_discounted_amount( $code, $base_price ) {
750
+function wpinv_get_discounted_amount($code, $base_price) {
751 751
     $amount      = $base_price;
752
-    $discount_id = wpinv_get_discount_id_by_code( $code );
752
+    $discount_id = wpinv_get_discount_id_by_code($code);
753 753
 
754
-    if( $discount_id ) {
755
-        $type        = wpinv_get_discount_type( $discount_id );
756
-        $rate        = wpinv_get_discount_amount( $discount_id );
754
+    if ($discount_id) {
755
+        $type        = wpinv_get_discount_type($discount_id);
756
+        $rate        = wpinv_get_discount_amount($discount_id);
757 757
 
758
-        if ( $type == 'flat' ) {
758
+        if ($type == 'flat') {
759 759
             // Set amount
760 760
             $amount = $base_price - $rate;
761
-            if ( $amount < 0 ) {
761
+            if ($amount < 0) {
762 762
                 $amount = 0;
763 763
             }
764 764
 
765 765
         } else {
766 766
             // Percentage discount
767
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
767
+            $amount = $base_price - ($base_price * ($rate / 100));
768 768
         }
769 769
 
770 770
     } else {
@@ -773,108 +773,108 @@  discard block
 block discarded – undo
773 773
 
774 774
     }
775 775
 
776
-    return apply_filters( 'wpinv_discounted_amount', $amount );
776
+    return apply_filters('wpinv_discounted_amount', $amount);
777 777
 }
778 778
 
779
-function wpinv_increase_discount_usage( $code ) {
779
+function wpinv_increase_discount_usage($code) {
780 780
 
781
-    $id   = wpinv_get_discount_id_by_code( $code );
782
-    $uses = wpinv_get_discount_uses( $id );
781
+    $id   = wpinv_get_discount_id_by_code($code);
782
+    $uses = wpinv_get_discount_uses($id);
783 783
 
784
-    if ( $uses ) {
784
+    if ($uses) {
785 785
         $uses++;
786 786
     } else {
787 787
         $uses = 1;
788 788
     }
789 789
 
790
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
790
+    update_post_meta($id, '_wpi_discount_uses', $uses);
791 791
 
792
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
792
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
793 793
 
794 794
     return $uses;
795 795
 
796 796
 }
797 797
 
798
-function wpinv_decrease_discount_usage( $code ) {
798
+function wpinv_decrease_discount_usage($code) {
799 799
 
800
-    $id   = wpinv_get_discount_id_by_code( $code );
801
-    $uses = wpinv_get_discount_uses( $id );
800
+    $id   = wpinv_get_discount_id_by_code($code);
801
+    $uses = wpinv_get_discount_uses($id);
802 802
 
803
-    if ( $uses ) {
803
+    if ($uses) {
804 804
         $uses--;
805 805
     }
806 806
 
807
-    if ( $uses < 0 ) {
807
+    if ($uses < 0) {
808 808
         $uses = 0;
809 809
     }
810 810
 
811
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
811
+    update_post_meta($id, '_wpi_discount_uses', $uses);
812 812
 
813
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
813
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
814 814
 
815 815
     return $uses;
816 816
 
817 817
 }
818 818
 
819
-function wpinv_format_discount_rate( $type, $amount ) {
820
-    if ( $type == 'flat' ) {
821
-        return wpinv_price( wpinv_format_amount( $amount ) );
819
+function wpinv_format_discount_rate($type, $amount) {
820
+    if ($type == 'flat') {
821
+        return wpinv_price(wpinv_format_amount($amount));
822 822
     } else {
823 823
         return $amount . '%';
824 824
     }
825 825
 }
826 826
 
827
-function wpinv_set_cart_discount( $code = '' ) {    
828
-    if ( wpinv_multiple_discounts_allowed() ) {
827
+function wpinv_set_cart_discount($code = '') {    
828
+    if (wpinv_multiple_discounts_allowed()) {
829 829
         // Get all active cart discounts
830 830
         $discounts = wpinv_get_cart_discounts();
831 831
     } else {
832 832
         $discounts = false; // Only one discount allowed per purchase, so override any existing
833 833
     }
834 834
 
835
-    if ( $discounts ) {
836
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
837
-        if( false !== $key ) {
838
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
835
+    if ($discounts) {
836
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
837
+        if (false !== $key) {
838
+            unset($discounts[$key]); // Can't set the same discount more than once
839 839
         }
840 840
         $discounts[] = $code;
841 841
     } else {
842 842
         $discounts = array();
843 843
         $discounts[] = $code;
844 844
     }
845
-    $discounts = array_values( $discounts );
845
+    $discounts = array_values($discounts);
846 846
     
847 847
     $data = wpinv_get_checkout_session();
848
-    if ( empty( $data ) ) {
848
+    if (empty($data)) {
849 849
         $data = array();
850 850
     } else {
851
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
852
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
853
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
851
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
852
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
853
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
854 854
         }
855 855
     }
856 856
     $data['cart_discounts'] = $discounts;
857 857
     
858
-    wpinv_set_checkout_session( $data );
858
+    wpinv_set_checkout_session($data);
859 859
     
860 860
     return $discounts;
861 861
 }
862 862
 
863
-function wpinv_unset_cart_discount( $code = '' ) {    
863
+function wpinv_unset_cart_discount($code = '') {    
864 864
     $discounts = wpinv_get_cart_discounts();
865 865
 
866
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
867
-        $key = array_search( $code, $discounts );
868
-        unset( $discounts[ $key ] );
866
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
867
+        $key = array_search($code, $discounts);
868
+        unset($discounts[$key]);
869 869
             
870 870
         $data = wpinv_get_checkout_session();
871 871
         $data['cart_discounts'] = $discounts;
872
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
873
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
874
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
872
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
873
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
874
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
875 875
         }
876 876
         
877
-        wpinv_set_checkout_session( $data );
877
+        wpinv_set_checkout_session($data);
878 878
     }
879 879
 
880 880
     return $discounts;
@@ -883,27 +883,27 @@  discard block
 block discarded – undo
883 883
 function wpinv_unset_all_cart_discounts() {
884 884
     $data = wpinv_get_checkout_session();
885 885
     
886
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
887
-        unset( $data['cart_discounts'] );
886
+    if (!empty($data) && isset($data['cart_discounts'])) {
887
+        unset($data['cart_discounts']);
888 888
         
889
-         wpinv_set_checkout_session( $data );
889
+         wpinv_set_checkout_session($data);
890 890
          return true;
891 891
     }
892 892
     
893 893
     return false;
894 894
 }
895 895
 
896
-function wpinv_get_cart_discounts( $items = array() ) {
896
+function wpinv_get_cart_discounts($items = array()) {
897 897
     $session = wpinv_get_checkout_session();
898 898
     
899
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
899
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
900 900
     return $discounts;
901 901
 }
902 902
 
903
-function wpinv_cart_has_discounts( $items = array() ) {
903
+function wpinv_cart_has_discounts($items = array()) {
904 904
     $ret = false;
905 905
 
906
-    if ( wpinv_get_cart_discounts( $items ) ) {
906
+    if (wpinv_get_cart_discounts($items)) {
907 907
         $ret = true;
908 908
     }
909 909
     
@@ -914,131 +914,131 @@  discard block
 block discarded – undo
914 914
     }
915 915
     */
916 916
 
917
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
917
+    return apply_filters('wpinv_cart_has_discounts', $ret);
918 918
 }
919 919
 
920
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
920
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
921 921
     $amount = 0.00;
922
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
922
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
923 923
 
924
-    if ( $items ) {
925
-        $discounts = wp_list_pluck( $items, 'discount' );
924
+    if ($items) {
925
+        $discounts = wp_list_pluck($items, 'discount');
926 926
 
927
-        if ( is_array( $discounts ) ) {
928
-            $discounts = array_map( 'floatval', $discounts );
929
-            $amount    = array_sum( $discounts );
927
+        if (is_array($discounts)) {
928
+            $discounts = array_map('floatval', $discounts);
929
+            $amount    = array_sum($discounts);
930 930
         }
931 931
     }
932 932
 
933
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
933
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
934 934
 }
935 935
 
936
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
937
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
936
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
937
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
938 938
     
939
-    if ( empty( $discount ) || empty( $items ) ) {
939
+    if (empty($discount) || empty($items)) {
940 940
         return 0;
941 941
     }
942 942
 
943 943
     $amount = 0;
944 944
     
945
-    foreach ( $items as $item ) {
946
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
945
+    foreach ($items as $item) {
946
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
947 947
     }
948 948
     
949
-    $amount = wpinv_round_amount( $amount );
949
+    $amount = wpinv_round_amount($amount);
950 950
 
951 951
     return $amount;
952 952
 }
953 953
 
954
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
954
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
955 955
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
956 956
     
957 957
     $amount = 0;
958 958
 
959
-    if ( empty( $item ) || empty( $item['id'] ) ) {
959
+    if (empty($item) || empty($item['id'])) {
960 960
         return $amount;
961 961
     }
962 962
 
963
-    if ( empty( $item['quantity'] ) ) {
963
+    if (empty($item['quantity'])) {
964 964
         return $amount;
965 965
     }
966 966
 
967
-    if ( empty( $item['options'] ) ) {
967
+    if (empty($item['options'])) {
968 968
         $item['options'] = array();
969 969
     }
970 970
 
971
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
971
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
972 972
     $discounted_price = $price;
973 973
 
974 974
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
975
-    if ( empty( $discounts ) ) {
975
+    if (empty($discounts)) {
976 976
         return $amount;
977 977
     }
978 978
 
979
-    if ( $discounts ) {
980
-        if ( is_array( $discounts ) ) {
981
-            $discounts = array_values( $discounts );
979
+    if ($discounts) {
980
+        if (is_array($discounts)) {
981
+            $discounts = array_values($discounts);
982 982
         } else {
983
-            $discounts = explode( ',', $discounts );
983
+            $discounts = explode(',', $discounts);
984 984
         }
985 985
     }
986 986
 
987
-    if( $discounts ) {
988
-        foreach ( $discounts as $discount ) {
989
-            $code_id = wpinv_get_discount_id_by_code( $discount );
987
+    if ($discounts) {
988
+        foreach ($discounts as $discount) {
989
+            $code_id = wpinv_get_discount_id_by_code($discount);
990 990
 
991 991
             // Check discount exists
992
-            if( ! $code_id ) {
992
+            if (!$code_id) {
993 993
                 continue;
994 994
             }
995 995
 
996
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
997
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
996
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
997
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
998 998
 
999 999
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1000
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1001
-                foreach ( $reqs as $item_id ) {
1002
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1003
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1000
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1001
+                foreach ($reqs as $item_id) {
1002
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1003
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1004 1004
                     }
1005 1005
                 }
1006 1006
             } else {
1007 1007
                 // This is a global cart discount
1008
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1009
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1008
+                if (!in_array($item['id'], $excluded_items)) {
1009
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1010 1010
                         $items_subtotal    = 0.00;
1011 1011
                         $cart_items        = wpinv_get_cart_contents();
1012 1012
                         
1013
-                        foreach ( $cart_items as $cart_item ) {
1014
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1015
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1016
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1013
+                        foreach ($cart_items as $cart_item) {
1014
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1015
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1016
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1017 1017
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1018 1018
                             }
1019 1019
                         }
1020 1020
 
1021
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1022
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1021
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1022
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1023 1023
                         $discounted_amount = $code_amount * $subtotal_percent;
1024 1024
                         $discounted_price -= $discounted_amount;
1025 1025
 
1026
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1026
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1027 1027
 
1028
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1028
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1029 1029
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1030 1030
                             $discounted_price -= $adjustment;
1031 1031
                         }
1032 1032
                     } else {
1033
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1033
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1034 1034
                     }
1035 1035
                 }
1036 1036
             }
1037 1037
         }
1038 1038
 
1039
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1039
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1040 1040
 
1041
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1041
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1042 1042
             $amount = $amount * $item['quantity'];
1043 1043
         }
1044 1044
     }
@@ -1046,59 +1046,59 @@  discard block
 block discarded – undo
1046 1046
     return $amount;
1047 1047
 }
1048 1048
 
1049
-function wpinv_cart_discounts_html( $items = array() ) {
1050
-    echo wpinv_get_cart_discounts_html( $items );
1049
+function wpinv_cart_discounts_html($items = array()) {
1050
+    echo wpinv_get_cart_discounts_html($items);
1051 1051
 }
1052 1052
 
1053
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1053
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1054 1054
     global $wpi_cart_columns;
1055 1055
     
1056
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1056
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1057 1057
     
1058
-    if ( !$discounts ) {
1059
-        $discounts = wpinv_get_cart_discounts( $items );
1058
+    if (!$discounts) {
1059
+        $discounts = wpinv_get_cart_discounts($items);
1060 1060
     }
1061 1061
 
1062
-    if ( !$discounts ) {
1062
+    if (!$discounts) {
1063 1063
         return;
1064 1064
     }
1065 1065
     
1066
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1066
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1067 1067
     
1068 1068
     $html = '';
1069 1069
 
1070
-    foreach ( $discounts as $discount ) {
1071
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1072
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1073
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1074
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1075
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1070
+    foreach ($discounts as $discount) {
1071
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1072
+        $discount_value = wpinv_get_discount_amount($discount_id);
1073
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1074
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1075
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1076 1076
         
1077 1077
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1078 1078
         ob_start();
1079
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1079
+        do_action('wpinv_checkout_table_discount_first', $items);
1080 1080
         $html .= ob_get_clean();
1081
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1081
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1082 1082
         ob_start();
1083
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1083
+        do_action('wpinv_checkout_table_discount_last', $items);
1084 1084
         $html .= ob_get_clean();
1085 1085
         $html .= '</tr>';
1086 1086
     }
1087 1087
 
1088
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1088
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1089 1089
 }
1090 1090
 
1091
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1091
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1092 1092
     $discounts = wpinv_get_cart_discounts();
1093 1093
 
1094
-    if ( empty( $discounts ) ) {
1094
+    if (empty($discounts)) {
1095 1095
         return false;
1096 1096
     }
1097 1097
 
1098
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1099
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1098
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1099
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1100 1100
 
1101
-    if ( $echo ) {
1101
+    if ($echo) {
1102 1102
         echo $amount;
1103 1103
     }
1104 1104
 
@@ -1106,135 +1106,135 @@  discard block
 block discarded – undo
1106 1106
 }
1107 1107
 
1108 1108
 function wpinv_remove_cart_discount() {
1109
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1109
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1110 1110
         return;
1111 1111
     }
1112 1112
 
1113
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1113
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1114 1114
 
1115
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1115
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1116 1116
 
1117
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1117
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1118 1118
 
1119
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1119
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1120 1120
 }
1121
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1121
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1122 1122
 
1123
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1123
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1124 1124
     $discounts = wpinv_get_cart_discounts();
1125 1125
 
1126
-    if ( !$discounts ) {
1126
+    if (!$discounts) {
1127 1127
         return;
1128 1128
     }
1129 1129
 
1130
-    foreach ( $discounts as $discount ) {
1131
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1132
-            wpinv_unset_cart_discount( $discount );
1130
+    foreach ($discounts as $discount) {
1131
+        if (!wpinv_is_discount_valid($discount)) {
1132
+            wpinv_unset_cart_discount($discount);
1133 1133
         }
1134 1134
     }
1135 1135
 }
1136
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1136
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1137 1137
 
1138 1138
 function wpinv_multiple_discounts_allowed() {
1139
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1140
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1139
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1140
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1141 1141
 }
1142 1142
 
1143 1143
 function wpinv_listen_for_cart_discount() {
1144 1144
     global $wpi_session;
1145 1145
     
1146
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1146
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1147 1147
         return;
1148 1148
     }
1149 1149
 
1150
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1150
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1151 1151
 
1152
-    $wpi_session->set( 'preset_discount', $code );
1152
+    $wpi_session->set('preset_discount', $code);
1153 1153
 }
1154 1154
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1155 1155
 
1156 1156
 function wpinv_apply_preset_discount() {
1157 1157
     global $wpi_session;
1158 1158
     
1159
-    $code = $wpi_session->get( 'preset_discount' );
1159
+    $code = $wpi_session->get('preset_discount');
1160 1160
 
1161
-    if ( !$code ) {
1161
+    if (!$code) {
1162 1162
         return;
1163 1163
     }
1164 1164
 
1165
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1165
+    if (!wpinv_is_discount_valid($code, '', false)) {
1166 1166
         return;
1167 1167
     }
1168 1168
     
1169
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1169
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1170 1170
 
1171
-    wpinv_set_cart_discount( $code );
1171
+    wpinv_set_cart_discount($code);
1172 1172
 
1173
-    $wpi_session->set( 'preset_discount', null );
1173
+    $wpi_session->set('preset_discount', null);
1174 1174
 }
1175 1175
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1176 1176
 
1177
-function wpinv_get_discount_label( $code, $echo = true ) {
1178
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1179
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1177
+function wpinv_get_discount_label($code, $echo = true) {
1178
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1179
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1180 1180
 
1181
-    if ( $echo ) {
1181
+    if ($echo) {
1182 1182
         echo $label;
1183 1183
     } else {
1184 1184
         return $label;
1185 1185
     }
1186 1186
 }
1187 1187
 
1188
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1189
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1190
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1188
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1189
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1190
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1191 1191
 
1192
-    if ( $echo ) {
1192
+    if ($echo) {
1193 1193
         echo $label;
1194 1194
     } else {
1195 1195
         return $label;
1196 1196
     }
1197 1197
 }
1198 1198
 
1199
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1200
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1199
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1200
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1201 1201
         return true;
1202 1202
     }
1203 1203
     
1204 1204
     return $check;
1205 1205
 }
1206
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1206
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1207 1207
 
1208 1208
 function wpinv_checkout_form_validate_discounts() {
1209 1209
     global $wpi_checkout_id;
1210 1210
     
1211 1211
     $discounts = wpinv_get_cart_discounts();
1212 1212
     
1213
-    if ( !empty( $discounts ) ) {
1213
+    if (!empty($discounts)) {
1214 1214
         $invalid = false;
1215 1215
         
1216
-        foreach ( $discounts as $key => $code ) {
1217
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1216
+        foreach ($discounts as $key => $code) {
1217
+            if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) {
1218 1218
                 $invalid = true;
1219 1219
                 
1220
-                wpinv_unset_cart_discount( $code );
1220
+                wpinv_unset_cart_discount($code);
1221 1221
             }
1222 1222
         }
1223 1223
         
1224
-        if ( $invalid ) {
1224
+        if ($invalid) {
1225 1225
             $errors = wpinv_get_errors();
1226
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1228
-            wpinv_set_error( 'wpinv-discount-error', $error );
1226
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1228
+            wpinv_set_error('wpinv-discount-error', $error);
1229 1229
             
1230
-            wpinv_recalculate_tax( true );
1230
+            wpinv_recalculate_tax(true);
1231 1231
         }
1232 1232
     }
1233 1233
 }
1234
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1234
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1235 1235
 
1236 1236
 function wpinv_discount_amount() {
1237 1237
     $output = 0.00;
1238 1238
     
1239
-    return apply_filters( 'wpinv_discount_amount', $output );
1239
+    return apply_filters('wpinv_discount_amount', $output);
1240 1240
 }
1241 1241
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/manual.php 1 patch
Spacing   +14 added lines, -14 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_manual_cc_form', '__return_false' );
5
+add_action('wpinv_manual_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_manual_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_manual_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
     /*
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     // Record the pending payment
44
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
44
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
45 45
     
46
-    if ( !empty( $invoice ) ) {        
47
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
48
-        wpinv_update_payment_status( $invoice, 'publish' );
46
+    if (!empty($invoice)) {        
47
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
48
+        wpinv_update_payment_status($invoice, 'publish');
49 49
         
50 50
         // Empty the shopping cart
51 51
         wpinv_empty_cart();
52 52
         
53
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
53
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
54 54
         
55
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
55
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
56 56
     } else {
57
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
57
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
58 58
         // If errors are present, send the user back to the purchase page so they can be corrected
59
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
59
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
60 60
     }
61 61
 }
62
-add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' );
63 62
\ No newline at end of file
63
+add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment');
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/worldpay.php 1 patch
Spacing   +65 added lines, -65 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_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_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_worldpay_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,132 +24,132 @@  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 ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
143
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
144 144
 
145 145
 function wpinv_is_worldpay_valid_for_use() {
146
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' )));
146
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR')));
147 147
 }
148 148
 
149
-function wpinv_check_worldpay_currency_support( $gateway_list ) {
150
-    if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) {
151
-        unset( $gateway_list['worldpay'] );
149
+function wpinv_check_worldpay_currency_support($gateway_list) {
150
+    if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) {
151
+        unset($gateway_list['worldpay']);
152 152
     }
153 153
     return $gateway_list;
154 154
 }
155
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 );
156 155
\ No newline at end of file
156
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1);
157 157
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions-db.php 1 patch
Spacing   +154 added lines, -154 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
 /**
6 6
  * The Subscriptions DB Class
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
             'transaction_id'    => '',
69 69
             'parent_payment_id' => 0,
70 70
             'product_id'        => 0,
71
-            'created'           => date( 'Y-m-d H:i:s' ),
72
-            'expiration'        => date( 'Y-m-d H:i:s' ),
71
+            'created'           => date('Y-m-d H:i:s'),
72
+            'expiration'        => date('Y-m-d H:i:s'),
73 73
             'trial_period'      => '',
74 74
             'status'            => '',
75 75
             'profile_id'        => '',
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
      * @access  public
83 83
      * @since   1.0.0
84 84
      */
85
-    public function get_subscriptions( $args = array() ) {
85
+    public function get_subscriptions($args = array()) {
86 86
         global $wpdb;
87 87
 
88 88
         $defaults = array(
89
-            'number'       => get_option( 'posts_per_page' ),
89
+            'number'       => get_option('posts_per_page'),
90 90
             'offset'       => 0,
91 91
             'search'       => '',
92 92
             'customer_id'  => 0,
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
             'order'        => 'DESC'
95 95
         );
96 96
 
97
-        $args  = wp_parse_args( $args, $defaults );
97
+        $args = wp_parse_args($args, $defaults);
98 98
 
99
-        if( $args['number'] < 1 ) {
99
+        if ($args['number'] < 1) {
100 100
             $args['number'] = 999999999999;
101 101
         }
102 102
 
103 103
         $where = ' WHERE 1=1 ';
104 104
 
105 105
         // specific customers
106
-        if( ! empty( $args['id'] ) ) {
106
+        if (!empty($args['id'])) {
107 107
 
108
-            if( is_array( $args['id'] ) ) {
109
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
108
+            if (is_array($args['id'])) {
109
+                $ids = implode(',', array_map('intval', $args['id']));
110 110
             } else {
111
-                $ids = intval( $args['id'] );
111
+                $ids = intval($args['id']);
112 112
             }
113 113
 
114 114
             $where .= " AND `id` IN( {$ids} ) ";
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         // Specific products
119
-        if( ! empty( $args['product_id'] ) ) {
119
+        if (!empty($args['product_id'])) {
120 120
 
121
-            if( is_array( $args['product_id'] ) ) {
122
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
121
+            if (is_array($args['product_id'])) {
122
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
123 123
             } else {
124
-                $product_ids = intval( $args['product_id'] );
124
+                $product_ids = intval($args['product_id']);
125 125
             }
126 126
 
127 127
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         }
130 130
 
131 131
         // Specific parent payments
132
-        if( ! empty( $args['parent_payment_id'] ) ) {
132
+        if (!empty($args['parent_payment_id'])) {
133 133
 
134
-            if( is_array( $args['parent_payment_id'] ) ) {
135
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
134
+            if (is_array($args['parent_payment_id'])) {
135
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
136 136
             } else {
137
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
137
+                $parent_payment_ids = intval($args['parent_payment_id']);
138 138
             }
139 139
 
140 140
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
         }
143 143
 
144 144
         // Specific transaction IDs
145
-        if( ! empty( $args['transaction_id'] ) ) {
145
+        if (!empty($args['transaction_id'])) {
146 146
 
147
-            if( is_array( $args['transaction_id'] ) ) {
148
-                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) );
147
+            if (is_array($args['transaction_id'])) {
148
+                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id']));
149 149
             } else {
150
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
150
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
151 151
             }
152 152
 
153 153
             $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) ";
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
         }
156 156
 
157 157
         // Subscriptoins for specific customers
158
-        if( ! empty( $args['customer_id'] ) ) {
158
+        if (!empty($args['customer_id'])) {
159 159
 
160
-            if( is_array( $args['customer_id'] ) ) {
161
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
160
+            if (is_array($args['customer_id'])) {
161
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
162 162
             } else {
163
-                $customer_ids = intval( $args['customer_id'] );
163
+                $customer_ids = intval($args['customer_id']);
164 164
             }
165 165
 
166 166
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
         }
169 169
 
170 170
         // Subscriptions for specific profile IDs
171
-        if( ! empty( $args['profile_id'] ) ) {
171
+        if (!empty($args['profile_id'])) {
172 172
 
173
-            if( is_array( $args['profile_id'] ) ) {
174
-                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) );
173
+            if (is_array($args['profile_id'])) {
174
+                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id']));
175 175
             } else {
176
-                $profile_ids = sanitize_text_field( $args['profile_id'] );
176
+                $profile_ids = sanitize_text_field($args['profile_id']);
177 177
             }
178 178
 
179 179
             $where .= " AND `profile_id` IN( '{$profile_ids}' ) ";
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
         }
182 182
 
183 183
         // Subscriptions for specific statuses
184
-        if( ! empty( $args['status'] ) ) {
184
+        if (!empty($args['status'])) {
185 185
 
186
-            if( is_array( $args['status'] ) ) {
187
-                $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );
186
+            if (is_array($args['status'])) {
187
+                $statuses = implode("','", array_map('sanitize_text_field', $args['status']));
188 188
             } else {
189
-                $statuses = sanitize_text_field( $args['status'] );
189
+                $statuses = sanitize_text_field($args['status']);
190 190
             }
191 191
 
192 192
             $where .= " AND `status` IN( '{$statuses}' ) ";
@@ -194,21 +194,21 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Subscriptions created for a specific date or in a date range
197
-        if( ! empty( $args['date'] ) ) {
197
+        if (!empty($args['date'])) {
198 198
 
199
-            if( is_array( $args['date'] ) ) {
199
+            if (is_array($args['date'])) {
200 200
 
201
-                if( ! empty( $args['date']['start'] ) ) {
201
+                if (!empty($args['date']['start'])) {
202 202
 
203
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
203
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
204 204
 
205 205
                     $where .= " AND `created` >= '{$start}'";
206 206
 
207 207
                 }
208 208
 
209
-                if( ! empty( $args['date']['end'] ) ) {
209
+                if (!empty($args['date']['end'])) {
210 210
 
211
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
211
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
212 212
 
213 213
                     $where .= " AND `created` <= '{$end}'";
214 214
 
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 
217 217
             } else {
218 218
 
219
-                $year  = date( 'Y', strtotime( $args['date'] ) );
220
-                $month = date( 'm', strtotime( $args['date'] ) );
221
-                $day   = date( 'd', strtotime( $args['date'] ) );
219
+                $year  = date('Y', strtotime($args['date']));
220
+                $month = date('m', strtotime($args['date']));
221
+                $day   = date('d', strtotime($args['date']));
222 222
 
223 223
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
224 224
             }
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
         }
227 227
 
228 228
         // Subscriptions with a specific expiration date or in an expiration date range
229
-        if( ! empty( $args['expiration'] ) ) {
229
+        if (!empty($args['expiration'])) {
230 230
 
231
-            if( is_array( $args['expiration'] ) ) {
231
+            if (is_array($args['expiration'])) {
232 232
 
233
-                if( ! empty( $args['expiration']['start'] ) ) {
233
+                if (!empty($args['expiration']['start'])) {
234 234
 
235
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
235
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
236 236
 
237 237
                     $where .= " AND `expiration` >= '{$start}'";
238 238
 
239 239
                 }
240 240
 
241
-                if( ! empty( $args['expiration']['end'] ) ) {
241
+                if (!empty($args['expiration']['end'])) {
242 242
 
243
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
243
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
244 244
 
245 245
                     $where .= " AND `expiration` <= '{$end}'";
246 246
 
@@ -248,73 +248,73 @@  discard block
 block discarded – undo
248 248
 
249 249
             } else {
250 250
 
251
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
252
-                $month = date( 'm', strtotime( $args['expiration'] ) );
253
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
251
+                $year  = date('Y', strtotime($args['expiration']));
252
+                $month = date('m', strtotime($args['expiration']));
253
+                $day   = date('d', strtotime($args['expiration']));
254 254
 
255 255
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
256 256
             }
257 257
 
258 258
         }
259 259
 
260
-        if ( ! empty( $args['search'] ) ) {
260
+        if (!empty($args['search'])) {
261 261
 
262
-            if( false !== strpos( 'id:', $args['search'] ) ) {
262
+            if (false !== strpos('id:', $args['search'])) {
263 263
 
264
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
265
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
264
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
265
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
266 266
 
267
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
267
+            } else if (false !== strpos($args['search'], 'txn:')) {
268 268
 
269
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
270
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
269
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
270
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
271 271
 
272
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
272
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
273 273
 
274
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
275
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
274
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
275
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
276 276
 
277
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
277
+            } else if (false !== strpos($args['search'], 'product_id:')) {
278 278
 
279
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
280
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
279
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
280
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
281 281
 
282
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
282
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
283 283
 
284
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
285
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
284
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
285
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
286 286
 
287 287
             } else {
288 288
 
289
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
289
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
290 290
 
291 291
             }
292 292
 
293 293
         }
294 294
 
295
-        $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
295
+        $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
296 296
 
297
-        if( 'amount' == $args['orderby'] ) {
297
+        if ('amount' == $args['orderby']) {
298 298
             $args['orderby'] = 'amount+0';
299 299
         }
300 300
 
301
-        $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) );
301
+        $cache_key = md5('wpinv_subscriptions_' . serialize($args));
302 302
 
303
-        $subscriptions = wp_cache_get( $cache_key, 'subscriptions' );
303
+        $subscriptions = wp_cache_get($cache_key, 'subscriptions');
304 304
 
305
-        $args['orderby'] = esc_sql( $args['orderby'] );
306
-        $args['order']   = esc_sql( $args['order'] );
305
+        $args['orderby'] = esc_sql($args['orderby']);
306
+        $args['order']   = esc_sql($args['order']);
307 307
 
308
-        if( $subscriptions === false ) {
309
-            $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT );
308
+        if ($subscriptions === false) {
309
+            $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT);
310 310
 
311
-            if( ! empty( $subscriptions ) ) {
311
+            if (!empty($subscriptions)) {
312 312
 
313
-                foreach( $subscriptions as $key => $subscription ) {
314
-                    $subscriptions[ $key ] = new WPInv_Subscription( $subscription );
313
+                foreach ($subscriptions as $key => $subscription) {
314
+                    $subscriptions[$key] = new WPInv_Subscription($subscription);
315 315
                 }
316 316
 
317
-                wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 );
317
+                wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600);
318 318
 
319 319
             }
320 320
 
@@ -329,19 +329,19 @@  discard block
 block discarded – undo
329 329
      * @access  public
330 330
      * @since   1.0.0
331 331
      */
332
-    public function count( $args = array() ) {
332
+    public function count($args = array()) {
333 333
 
334 334
         global $wpdb;
335 335
 
336 336
         $where = ' WHERE 1=1 ';
337 337
 
338 338
         // specific customers
339
-        if( ! empty( $args['id'] ) ) {
339
+        if (!empty($args['id'])) {
340 340
 
341
-            if( is_array( $args['id'] ) ) {
342
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
341
+            if (is_array($args['id'])) {
342
+                $ids = implode(',', array_map('intval', $args['id']));
343 343
             } else {
344
-                $ids = intval( $args['id'] );
344
+                $ids = intval($args['id']);
345 345
             }
346 346
 
347 347
             $where .= " AND `id` IN( {$ids} ) ";
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
         }
350 350
 
351 351
         // Specific products
352
-        if( ! empty( $args['product_id'] ) ) {
352
+        if (!empty($args['product_id'])) {
353 353
 
354
-            if( is_array( $args['product_id'] ) ) {
355
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
354
+            if (is_array($args['product_id'])) {
355
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
356 356
             } else {
357
-                $product_ids = intval( $args['product_id'] );
357
+                $product_ids = intval($args['product_id']);
358 358
             }
359 359
 
360 360
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -362,12 +362,12 @@  discard block
 block discarded – undo
362 362
         }
363 363
 
364 364
         // Specific parent payments
365
-        if( ! empty( $args['parent_payment_id'] ) ) {
365
+        if (!empty($args['parent_payment_id'])) {
366 366
 
367
-            if( is_array( $args['parent_payment_id'] ) ) {
368
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
367
+            if (is_array($args['parent_payment_id'])) {
368
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
369 369
             } else {
370
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
370
+                $parent_payment_ids = intval($args['parent_payment_id']);
371 371
             }
372 372
 
373 373
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
         }
376 376
 
377 377
         // Subscriptoins for specific customers
378
-        if( ! empty( $args['customer_id'] ) ) {
378
+        if (!empty($args['customer_id'])) {
379 379
 
380
-            if( is_array( $args['customer_id'] ) ) {
381
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
380
+            if (is_array($args['customer_id'])) {
381
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
382 382
             } else {
383
-                $customer_ids = intval( $args['customer_id'] );
383
+                $customer_ids = intval($args['customer_id']);
384 384
             }
385 385
 
386 386
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -388,12 +388,12 @@  discard block
 block discarded – undo
388 388
         }
389 389
 
390 390
         // Subscriptions for specific profile IDs
391
-        if( ! empty( $args['profile_id'] ) ) {
391
+        if (!empty($args['profile_id'])) {
392 392
 
393
-            if( is_array( $args['profile_id'] ) ) {
394
-                $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) );
393
+            if (is_array($args['profile_id'])) {
394
+                $profile_ids = implode(',', array_map('intval', $args['profile_id']));
395 395
             } else {
396
-                $profile_ids = intval( $args['profile_id'] );
396
+                $profile_ids = intval($args['profile_id']);
397 397
             }
398 398
 
399 399
             $where .= " AND `profile_id` IN( {$profile_ids} ) ";
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
         }
402 402
 
403 403
         // Specific transaction IDs
404
-        if( ! empty( $args['transaction_id'] ) ) {
404
+        if (!empty($args['transaction_id'])) {
405 405
 
406
-            if( is_array( $args['transaction_id'] ) ) {
407
-                $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) );
406
+            if (is_array($args['transaction_id'])) {
407
+                $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id']));
408 408
             } else {
409
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
409
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
410 410
             }
411 411
 
412 412
             $where .= " AND `transaction_id` IN( {$transaction_ids} ) ";
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
         }
415 415
 
416 416
         // Subscriptions for specific statuses
417
-        if( ! empty( $args['status'] ) ) {
417
+        if (!empty($args['status'])) {
418 418
 
419
-            if( is_array( $args['status'] ) ) {
420
-                $statuses = implode( ',', $args['status'] );
419
+            if (is_array($args['status'])) {
420
+                $statuses = implode(',', $args['status']);
421 421
                 $where  .= " AND `status` IN( {$statuses} ) ";
422 422
             } else {
423 423
                 $statuses = $args['status'];
@@ -429,21 +429,21 @@  discard block
 block discarded – undo
429 429
         }
430 430
 
431 431
         // Subscriptions created for a specific date or in a date range
432
-        if( ! empty( $args['date'] ) ) {
432
+        if (!empty($args['date'])) {
433 433
 
434
-            if( is_array( $args['date'] ) ) {
434
+            if (is_array($args['date'])) {
435 435
 
436
-                if( ! empty( $args['date']['start'] ) ) {
436
+                if (!empty($args['date']['start'])) {
437 437
 
438
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
438
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
439 439
 
440 440
                     $where .= " AND `created` >= '{$start}'";
441 441
 
442 442
                 }
443 443
 
444
-                if( ! empty( $args['date']['end'] ) ) {
444
+                if (!empty($args['date']['end'])) {
445 445
 
446
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
446
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
447 447
 
448 448
                     $where .= " AND `created` <= '{$end}'";
449 449
 
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
 
452 452
             } else {
453 453
 
454
-                $year  = date( 'Y', strtotime( $args['date'] ) );
455
-                $month = date( 'm', strtotime( $args['date'] ) );
456
-                $day   = date( 'd', strtotime( $args['date'] ) );
454
+                $year  = date('Y', strtotime($args['date']));
455
+                $month = date('m', strtotime($args['date']));
456
+                $day   = date('d', strtotime($args['date']));
457 457
 
458 458
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
459 459
             }
@@ -461,21 +461,21 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         // Subscriptions with a specific expiration date or in an expiration date range
464
-        if( ! empty( $args['expiration'] ) ) {
464
+        if (!empty($args['expiration'])) {
465 465
 
466
-            if( is_array( $args['expiration'] ) ) {
466
+            if (is_array($args['expiration'])) {
467 467
 
468
-                if( ! empty( $args['expiration']['start'] ) ) {
468
+                if (!empty($args['expiration']['start'])) {
469 469
 
470
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
470
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
471 471
 
472 472
                     $where .= " AND `expiration` >= '{$start}'";
473 473
 
474 474
                 }
475 475
 
476
-                if( ! empty( $args['expiration']['end'] ) ) {
476
+                if (!empty($args['expiration']['end'])) {
477 477
 
478
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
478
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
479 479
 
480 480
                     $where .= " AND `expiration` <= '{$end}'";
481 481
 
@@ -483,64 +483,64 @@  discard block
 block discarded – undo
483 483
 
484 484
             } else {
485 485
 
486
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
487
-                $month = date( 'm', strtotime( $args['expiration'] ) );
488
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
486
+                $year  = date('Y', strtotime($args['expiration']));
487
+                $month = date('m', strtotime($args['expiration']));
488
+                $day   = date('d', strtotime($args['expiration']));
489 489
 
490 490
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
491 491
             }
492 492
 
493 493
         }
494 494
 
495
-        if ( ! empty( $args['search'] ) ) {
495
+        if (!empty($args['search'])) {
496 496
 
497
-            if( false !== strpos( 'id:', $args['search'] ) ) {
497
+            if (false !== strpos('id:', $args['search'])) {
498 498
 
499
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
500
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
499
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
500
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
501 501
 
502
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
502
+            } else if (false !== strpos($args['search'], 'txn:')) {
503 503
 
504
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
505
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
504
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
505
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
506 506
 
507
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
507
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
508 508
 
509
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
510
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
509
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
510
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
511 511
 
512
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
512
+            } else if (false !== strpos($args['search'], 'product_id:')) {
513 513
 
514
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
515
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
514
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
515
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
516 516
 
517
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
517
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
518 518
 
519
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
520
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
519
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
520
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
521 521
 
522 522
             } else {
523 523
 
524
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
524
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
525 525
 
526 526
             }
527 527
 
528 528
         }
529 529
 
530
-        $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) );
530
+        $cache_key = md5('wpinv_subscriptions_count' . serialize($args));
531 531
 
532
-        $count = wp_cache_get( $cache_key, 'subscriptions' );
532
+        $count = wp_cache_get($cache_key, 'subscriptions');
533 533
 
534
-        if( $count === false ) {
534
+        if ($count === false) {
535 535
 
536 536
             $sql   = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};";
537
-            $count = $wpdb->get_var( $sql );
537
+            $count = $wpdb->get_var($sql);
538 538
 
539
-            wp_cache_set( $cache_key, $count, 'subscriptions', 3600 );
539
+            wp_cache_set($cache_key, $count, 'subscriptions', 3600);
540 540
 
541 541
         }
542 542
 
543
-        return absint( $count );
543
+        return absint($count);
544 544
 
545 545
     }
546 546
 
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
     public function create_table() {
554 554
         global $wpdb;
555 555
 
556
-        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
556
+        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
557 557
 
558 558
         $sql = "CREATE TABLE " . $this->table_name . " (
559 559
         id bigint(20) NOT NULL AUTO_INCREMENT,
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
         KEY customer_and_status ( customer_id, status)
579 579
         ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
580 580
 
581
-        dbDelta( $sql );
581
+        dbDelta($sql);
582 582
 
583
-        update_option( $this->table_name . '_db_version', $this->version );
583
+        update_option($this->table_name . '_db_version', $this->version);
584 584
     }
585 585
 
586 586
 }
587 587
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  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
 function wpinv_subscription_init() {
6 6
     return WPInv_Subscriptions::instance();
7 7
 }
8
-add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 );
8
+add_action('plugins_loaded', 'wpinv_subscription_init', 100);
9 9
 
10 10
 /**
11 11
  * WPInv_Subscriptions Class.
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      * Main WPInv_Subscriptions Instance
21 21
      */
22 22
     public static function instance() {
23
-        if ( ! isset( self::$instance ) ) {
23
+        if (!isset(self::$instance)) {
24 24
             self::$instance = new WPInv_Subscriptions;
25 25
 
26 26
             self::$instance->init();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @since 1.0.0
36 36
      */
37
-    private function __construct(){
37
+    private function __construct() {
38 38
 
39 39
     }
40 40
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
     private function setup_constants() {
64 64
 
65 65
         // Make sure CAL_GREGORIAN is defined.
66
-        if ( ! defined( 'CAL_GREGORIAN' ) ) {
67
-            define( 'CAL_GREGORIAN', 1 );
66
+        if (!defined('CAL_GREGORIAN')) {
67
+            define('CAL_GREGORIAN', 1);
68 68
         }
69 69
     }
70 70
 
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
      */
77 77
     private function actions() {
78 78
 
79
-        add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 10 );
80
-        add_action( 'admin_notices', array( $this, 'notices' ) );
81
-        add_action( 'init', array( $this, 'wpinv_post_actions' ) );
82
-        add_action( 'init', array( $this, 'wpinv_get_actions' ) );
83
-        add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) );
84
-        add_action( 'wpi-pending_wpi_invoice', array( $this, 'wpinv_add_update_subscription' ), 10, 2 );
85
-        add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) );
79
+        add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 10);
80
+        add_action('admin_notices', array($this, 'notices'));
81
+        add_action('init', array($this, 'wpinv_post_actions'));
82
+        add_action('init', array($this, 'wpinv_get_actions'));
83
+        add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation'));
84
+        add_action('wpi-pending_wpi_invoice', array($this, 'wpinv_add_update_subscription'), 10, 2);
85
+        add_action('wpinv_subscriptions_front_notices', array($this, 'notices'));
86 86
     }
87 87
 
88 88
     /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
     public function wpinv_subscriptions_list() {
105 105
         add_submenu_page(
106 106
             'wpinv',
107
-            __( 'Subscriptions', 'invoicing' ),
108
-            __( 'Subscriptions', 'invoicing' ),
107
+            __('Subscriptions', 'invoicing'),
108
+            __('Subscriptions', 'invoicing'),
109 109
             'manage_invoicing',
110 110
             'wpinv-subscriptions',
111 111
             'wpinv_subscriptions_page'
@@ -114,37 +114,37 @@  discard block
 block discarded – undo
114 114
 
115 115
     public function notices() {
116 116
 
117
-        if( empty( $_GET['wpinv-message'] ) ) {
117
+        if (empty($_GET['wpinv-message'])) {
118 118
             return;
119 119
         }
120 120
 
121 121
         $type    = 'updated';
122 122
         $message = '';
123 123
 
124
-        switch( strtolower( $_GET['wpinv-message'] ) ) {
124
+        switch (strtolower($_GET['wpinv-message'])) {
125 125
 
126 126
             case 'updated' :
127 127
 
128
-                $message = __( 'Subscription updated successfully.', 'invoicing' );
128
+                $message = __('Subscription updated successfully.', 'invoicing');
129 129
 
130 130
                 break;
131 131
 
132 132
             case 'deleted' :
133 133
 
134
-                $message = __( 'Subscription deleted successfully.', 'invoicing' );
134
+                $message = __('Subscription deleted successfully.', 'invoicing');
135 135
 
136 136
                 break;
137 137
 
138 138
             case 'cancelled' :
139 139
 
140
-                $message = __( 'Subscription cancelled successfully.', 'invoicing' );
140
+                $message = __('Subscription cancelled successfully.', 'invoicing');
141 141
 
142 142
                 break;
143 143
 
144 144
         }
145 145
 
146
-        if ( ! empty( $message ) ) {
147
-            echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>';
146
+        if (!empty($message)) {
147
+            echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>';
148 148
         }
149 149
 
150 150
     }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
      * @return void
158 158
      */
159 159
     function wpinv_get_actions() {
160
-        if ( isset( $_GET['wpinv_action'] ) ) {
161
-            do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET );
160
+        if (isset($_GET['wpinv_action'])) {
161
+            do_action('wpinv_' . $_GET['wpinv_action'], $_GET);
162 162
         }
163 163
     }
164 164
 
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
      * @return void
171 171
      */
172 172
     function wpinv_post_actions() {
173
-        if ( isset( $_POST['wpinv_action'] ) ) {
174
-            do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST );
173
+        if (isset($_POST['wpinv_action'])) {
174
+            do_action('wpinv_' . $_POST['wpinv_action'], $_POST);
175 175
         }
176 176
     }
177 177
 
@@ -182,24 +182,24 @@  discard block
 block discarded – undo
182 182
      * @param int $frequency_count The frequency of the period.
183 183
      * @return mixed|string|void
184 184
      */
185
-    public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) {
185
+    public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) {
186 186
         $frequency = '';
187 187
         //Format period details
188
-        switch ( $period ) {
188
+        switch ($period) {
189 189
             case 'day' :
190
-                $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
190
+                $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
191 191
                 break;
192 192
             case 'week' :
193
-                $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
193
+                $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
194 194
                 break;
195 195
             case 'month' :
196
-                $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
196
+                $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
197 197
                 break;
198 198
             case 'year' :
199
-                $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
199
+                $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
200 200
                 break;
201 201
             default :
202
-                $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count );
202
+                $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count);
203 203
                 break;
204 204
         }
205 205
 
@@ -214,50 +214,50 @@  discard block
 block discarded – undo
214 214
      * @since       1.0.0
215 215
      * @return      void
216 216
      */
217
-    public function wpinv_process_cancellation( $data ) {
217
+    public function wpinv_process_cancellation($data) {
218 218
 
219 219
 
220
-        if( empty( $data['sub_id'] ) ) {
220
+        if (empty($data['sub_id'])) {
221 221
             return;
222 222
         }
223 223
 
224
-        if( ! is_user_logged_in() ) {
224
+        if (!is_user_logged_in()) {
225 225
             return;
226 226
         }
227 227
 
228
-        if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) {
229
-            wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) );
228
+        if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) {
229
+            wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403));
230 230
         }
231 231
 
232
-        $data['sub_id'] = absint( $data['sub_id'] );
233
-        $subscription   = new WPInv_Subscription( $data['sub_id'] );
232
+        $data['sub_id'] = absint($data['sub_id']);
233
+        $subscription   = new WPInv_Subscription($data['sub_id']);
234 234
 
235
-        if( ! $subscription->can_cancel() ) {
236
-            wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) );
235
+        if (!$subscription->can_cancel()) {
236
+            wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403));
237 237
         }
238 238
 
239 239
         try {
240 240
 
241
-            do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true );
241
+            do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true);
242 242
 
243 243
             $subscription->cancel();
244 244
 
245
-            if( is_admin() ) {
245
+            if (is_admin()) {
246 246
 
247
-                wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) );
247
+                wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id));
248 248
                 exit;
249 249
 
250 250
             } else {
251 251
 
252
-                $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) );
253
-                $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription );
254
-                wp_safe_redirect( $redirect );
252
+                $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled')));
253
+                $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription);
254
+                wp_safe_redirect($redirect);
255 255
                 exit;
256 256
 
257 257
             }
258 258
 
259
-        } catch ( Exception $e ) {
260
-            wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) );
259
+        } catch (Exception $e) {
260
+            wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403));
261 261
         }
262 262
 
263 263
     }
@@ -269,51 +269,51 @@  discard block
 block discarded – undo
269 269
      * @since       1.0.0
270 270
      * @return      void
271 271
      */
272
-    public function wpinv_add_update_subscription( $invoice_id, $post ) {
273
-        remove_action( 'save_post', __FUNCTION__ );
272
+    public function wpinv_add_update_subscription($invoice_id, $post) {
273
+        remove_action('save_post', __FUNCTION__);
274 274
 
275
-        if ( ! ( ! empty( $invoice_id ) && 'wpi_invoice' == get_post_type( $invoice_id ) ) ) {
275
+        if (!(!empty($invoice_id) && 'wpi_invoice' == get_post_type($invoice_id))) {
276 276
             return;
277 277
         }
278 278
 
279
-        if ( defined( 'DOING_AUTOSAVE' ) ) {
279
+        if (defined('DOING_AUTOSAVE')) {
280 280
             return;
281 281
         }
282 282
 
283
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
283
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
284 284
             return;
285 285
         }
286 286
 
287
-        $invoice = new WPInv_Invoice( $invoice_id );
287
+        $invoice = new WPInv_Invoice($invoice_id);
288 288
 
289
-        if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
289
+        if (!(!empty($invoice->ID) && $invoice->is_recurring())) {
290 290
             return;
291 291
         }
292 292
 
293
-        $item    = $invoice->get_recurring( true );
294
-        if ( empty( $item ) ) {
293
+        $item = $invoice->get_recurring(true);
294
+        if (empty($item)) {
295 295
             return;
296 296
         }
297 297
 
298
-        $invoice_date       = $invoice->get_invoice_date( false );
298
+        $invoice_date       = $invoice->get_invoice_date(false);
299 299
         $status             = 'pending';
300 300
 
301
-        $period             = $item->get_recurring_period( true );
301
+        $period             = $item->get_recurring_period(true);
302 302
         $interval           = $item->get_recurring_interval();
303 303
         $bill_times         = (int)$item->get_recurring_limit();
304 304
         $add_period         = $interval . ' ' . $period;
305 305
         $trial_period       = '';
306 306
 
307
-        if ( $invoice->is_free_trial() ) {
307
+        if ($invoice->is_free_trial()) {
308 308
             $status         = 'trialling';
309
-            $trial_period   = $item->get_trial_period( true );
309
+            $trial_period   = $item->get_trial_period(true);
310 310
             $free_interval  = $item->get_trial_interval();
311 311
             $trial_period   = $free_interval . ' ' . $trial_period;
312 312
 
313 313
             $add_period     = $trial_period;
314 314
         }
315 315
 
316
-        $expiration         = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period  . ' 23:59:59', strtotime( $invoice_date ) ) );
316
+        $expiration         = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date)));
317 317
 
318 318
         $args = array(
319 319
             'product_id'        => $item->ID,
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
             'frequency'         => $interval,
324 324
             'period'            => $period,
325 325
             'initial_amount'    => $invoice->get_total(),
326
-            'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
326
+            'recurring_amount'  => $invoice->get_recurring_details('total'),
327 327
             'bill_times'        => $bill_times,
328 328
             'created'           => $invoice_date,
329 329
             'expiration'        => $expiration,
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
         );
334 334
 
335 335
         $subs_db      = new WPInv_Subscriptions_DB;
336
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) );
337
-        $subscription = reset( $subs );
336
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1));
337
+        $subscription = reset($subs);
338 338
 
339
-        if ( empty( $subscription ) || $subscription->id <= 0 ) {
339
+        if (empty($subscription) || $subscription->id <= 0) {
340 340
             $subscription = new WPInv_Subscription();
341
-            $subscription->create( $args );
341
+            $subscription->create($args);
342 342
         }
343 343
     }
344 344
 }
345 345
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Exit if accessed directly
4
-if ( ! defined( 'ABSPATH' ) ) {
4
+if (!defined('ABSPATH')) {
5 5
 	exit;
6 6
 }
7 7
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 	 * @since  1.0.0
39 39
 	 * @return void
40 40
 	 */
41
-	function __construct( $_id_or_object = 0, $_by_profile_id = false ) {
41
+	function __construct($_id_or_object = 0, $_by_profile_id = false) {
42 42
 
43 43
 		$this->subs_db = new WPInv_Subscriptions_DB;
44 44
 
45
-		if( $_by_profile_id ) {
45
+		if ($_by_profile_id) {
46 46
 
47
-			$_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object );
47
+			$_sub = $this->subs_db->get_by('profile_id', $_id_or_object);
48 48
 
49
-			if( empty( $_sub ) ) {
49
+			if (empty($_sub)) {
50 50
 				return false;
51 51
 			}
52 52
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
 		}
56 56
 
57
-		return $this->setup_subscription( $_id_or_object );
57
+		return $this->setup_subscription($_id_or_object);
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,34 +63,34 @@  discard block
 block discarded – undo
63 63
 	 * @since  1.0.0
64 64
 	 * @return void
65 65
 	 */
66
-	private function setup_subscription( $id_or_object = 0 ) {
66
+	private function setup_subscription($id_or_object = 0) {
67 67
 
68
-		if( empty( $id_or_object ) ) {
68
+		if (empty($id_or_object)) {
69 69
 			return false;
70 70
 		}
71 71
 
72
-		if( is_numeric( $id_or_object ) ) {
72
+		if (is_numeric($id_or_object)) {
73 73
 
74
-			$sub = $this->subs_db->get( $id_or_object );
74
+			$sub = $this->subs_db->get($id_or_object);
75 75
 
76
-		} elseif( is_object( $id_or_object ) ) {
76
+		} elseif (is_object($id_or_object)) {
77 77
 
78 78
 			$sub = $id_or_object;
79 79
 
80 80
 		}
81 81
 
82
-		if( empty( $sub ) ) {
82
+		if (empty($sub)) {
83 83
 			return false;
84 84
 		}
85 85
 
86
-		foreach( $sub as $key => $value ) {
86
+		foreach ($sub as $key => $value) {
87 87
 			$this->$key = $value;
88 88
 		}
89 89
 
90
-		$this->customer = get_userdata( $this->customer_id );
91
-		$this->gateway  = wpinv_get_payment_gateway( $this->parent_payment_id );
90
+		$this->customer = get_userdata($this->customer_id);
91
+		$this->gateway  = wpinv_get_payment_gateway($this->parent_payment_id);
92 92
 
93
-		do_action( 'wpinv_recurring_setup_subscription', $this );
93
+		do_action('wpinv_recurring_setup_subscription', $this);
94 94
 
95 95
 		return $this;
96 96
 	}
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @since 1.0.0
102 102
 	 */
103
-	public function __get( $key ) {
103
+	public function __get($key) {
104 104
 
105
-		if( method_exists( $this, 'get_' . $key ) ) {
105
+		if (method_exists($this, 'get_' . $key)) {
106 106
 
107
-			return call_user_func( array( $this, 'get_' . $key ) );
107
+			return call_user_func(array($this, 'get_' . $key));
108 108
 
109 109
 		} else {
110 110
 
111
-			return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
111
+			return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
112 112
 
113 113
 		}
114 114
 
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 * @param  array  $data Array of attributes for a subscription
122 122
 	 * @return mixed  false if data isn't passed and class not instantiated for creation
123 123
 	 */
124
-	public function create( $data = array() ) {
124
+	public function create($data = array()) {
125 125
 
126
-		if ( $this->id != 0 ) {
126
+		if ($this->id != 0) {
127 127
 			return false;
128 128
 		}
129 129
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 			'profile_id'        => '',
143 143
 		);
144 144
 
145
-		$args = wp_parse_args( $data, $defaults );
145
+		$args = wp_parse_args($data, $defaults);
146 146
 
147
-		if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
147
+		if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
148 148
 
149
-			if( 'active' == $args['status'] || 'trialling' == $args['status'] ) {
149
+			if ('active' == $args['status'] || 'trialling' == $args['status']) {
150 150
 
151 151
 				// Force an active subscription to expired if expiration date is in the past
152 152
 				$args['status'] = 'expired';
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 			}
155 155
 		}
156 156
 
157
-		do_action( 'wpinv_subscription_pre_create', $args );
157
+		do_action('wpinv_subscription_pre_create', $args);
158 158
 
159
-		$id = $this->subs_db->insert( $args, 'subscription' );
159
+		$id = $this->subs_db->insert($args, 'subscription');
160 160
 
161
-		do_action( 'wpinv_subscription_post_create', $id, $args );
161
+		do_action('wpinv_subscription_post_create', $id, $args);
162 162
 
163
-		return $this->setup_subscription( $id );
163
+		return $this->setup_subscription($id);
164 164
 
165 165
 	}
166 166
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 	 * @param  array $args Array of fields to update
172 172
 	 * @return bool
173 173
 	 */
174
-	public function update( $args = array() ) {
174
+	public function update($args = array()) {
175 175
 
176
-		$ret = $this->subs_db->update( $this->id, $args );
176
+		$ret = $this->subs_db->update($this->id, $args);
177 177
 
178
-		do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this );
178
+		do_action('wpinv_recurring_update_subscription', $this->id, $args, $this);
179 179
 
180 180
 		return $ret;
181 181
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @return bool
189 189
 	 */
190 190
 	public function delete() {
191
-		return $this->subs_db->delete( $this->id );
191
+		return $this->subs_db->delete($this->id);
192 192
 	}
193 193
 
194 194
     /**
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
      * @return array
209 209
      */
210 210
     public function get_child_payments() {
211
-        $payments = get_posts( array(
212
-            'post_parent'    => (int) $this->parent_payment_id,
211
+        $payments = get_posts(array(
212
+            'post_parent'    => (int)$this->parent_payment_id,
213 213
             'posts_per_page' => '999',
214
-            'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
214
+            'post_status'    => array('publish', 'wpi-processing', 'wpi-renewal'),
215 215
             'orderby'           => 'ID',
216 216
             'order'             => 'DESC',
217 217
             'post_type'      => 'wpi_invoice'
218
-        ) );
218
+        ));
219 219
 
220 220
         return $payments;
221 221
     }
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function get_total_payments() {
230 230
         $child_payments = $this->get_child_payments();
231
-        $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0;
231
+        $total_payments = !empty($child_payments) ? count($child_payments) : 0;
232 232
 
233
-        if ( 'pending' != $this->status ) {
233
+        if ('pending' != $this->status) {
234 234
                 $total_payments++;
235 235
         }
236 236
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     public function get_times_billed() {
247 247
         $times_billed = (int)$this->get_total_payments();
248 248
 
249
-        if ( ! empty( $this->trial_period ) && $times_billed > 0 ) {
249
+        if (!empty($this->trial_period) && $times_billed > 0) {
250 250
             $times_billed--;
251 251
         }
252 252
 
@@ -260,51 +260,51 @@  discard block
 block discarded – undo
260 260
      * @param  array $args Array of values for the payment, including amount and transaction ID
261 261
      * @return bool
262 262
      */
263
-    public function add_payment( $args = array() ) {
264
-        if ( ! $this->parent_payment_id ) {
263
+    public function add_payment($args = array()) {
264
+        if (!$this->parent_payment_id) {
265 265
             return false;
266 266
         }
267 267
 
268
-        $args = wp_parse_args( $args, array(
268
+        $args = wp_parse_args($args, array(
269 269
             'amount'         => '',
270 270
             'transaction_id' => '',
271 271
             'gateway'        => ''
272
-        ) );
272
+        ));
273 273
         
274
-        if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) {
274
+        if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) {
275 275
             return false;
276 276
         }
277 277
         
278
-        $parent_invoice = wpinv_get_invoice( $this->parent_payment_id );
279
-        if ( empty( $parent_invoice->ID ) ) {
278
+        $parent_invoice = wpinv_get_invoice($this->parent_payment_id);
279
+        if (empty($parent_invoice->ID)) {
280 280
             return false;
281 281
         }
282 282
 
283 283
         $invoice = new WPInv_Invoice();
284
-        $invoice->set( 'post_type', 'wpi_invoice' );
285
-        $invoice->set( 'parent_invoice', $this->parent_payment_id );
286
-        $invoice->set( 'currency', $parent_invoice->get_currency() );
287
-        $invoice->set( 'transaction_id', $args['transaction_id'] );
288
-        $invoice->set( 'key', $parent_invoice->generate_key() );
289
-        $invoice->set( 'ip', $parent_invoice->ip );
290
-        $invoice->set( 'user_id', $parent_invoice->get_user_id() );
291
-        $invoice->set( 'first_name', $parent_invoice->get_first_name() );
292
-        $invoice->set( 'last_name', $parent_invoice->get_last_name() );
293
-        $invoice->set( 'phone', $parent_invoice->phone );
294
-        $invoice->set( 'address', $parent_invoice->address );
295
-        $invoice->set( 'city', $parent_invoice->city );
296
-        $invoice->set( 'country', $parent_invoice->country );
297
-        $invoice->set( 'state', $parent_invoice->state );
298
-        $invoice->set( 'zip', $parent_invoice->zip );
299
-        $invoice->set( 'company', $parent_invoice->company );
300
-        $invoice->set( 'vat_number', $parent_invoice->vat_number );
301
-        $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
302
-        $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
303
-
304
-        if ( empty( $args['gateway'] ) ) {
305
-            $invoice->set( 'gateway', $parent_invoice->get_gateway() );
284
+        $invoice->set('post_type', 'wpi_invoice');
285
+        $invoice->set('parent_invoice', $this->parent_payment_id);
286
+        $invoice->set('currency', $parent_invoice->get_currency());
287
+        $invoice->set('transaction_id', $args['transaction_id']);
288
+        $invoice->set('key', $parent_invoice->generate_key());
289
+        $invoice->set('ip', $parent_invoice->ip);
290
+        $invoice->set('user_id', $parent_invoice->get_user_id());
291
+        $invoice->set('first_name', $parent_invoice->get_first_name());
292
+        $invoice->set('last_name', $parent_invoice->get_last_name());
293
+        $invoice->set('phone', $parent_invoice->phone);
294
+        $invoice->set('address', $parent_invoice->address);
295
+        $invoice->set('city', $parent_invoice->city);
296
+        $invoice->set('country', $parent_invoice->country);
297
+        $invoice->set('state', $parent_invoice->state);
298
+        $invoice->set('zip', $parent_invoice->zip);
299
+        $invoice->set('company', $parent_invoice->company);
300
+        $invoice->set('vat_number', $parent_invoice->vat_number);
301
+        $invoice->set('vat_rate', $parent_invoice->vat_rate);
302
+        $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
303
+
304
+        if (empty($args['gateway'])) {
305
+            $invoice->set('gateway', $parent_invoice->get_gateway());
306 306
         } else {
307
-            $invoice->set( 'gateway', $args['gateway'] );
307
+            $invoice->set('gateway', $args['gateway']);
308 308
         }
309 309
         
310 310
         $recurring_details = $parent_invoice->get_recurring_details();
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
         // increase the earnings for each item in the subscription
313 313
         $items = $recurring_details['cart_details'];
314 314
         
315
-        if ( $items ) {        
315
+        if ($items) {        
316 316
             $add_items      = array();
317 317
             $cart_details   = array();
318 318
             
319
-            foreach ( $items as $item ) {
319
+            foreach ($items as $item) {
320 320
                 $add_item             = array();
321 321
                 $add_item['id']       = $item['id'];
322 322
                 $add_item['quantity'] = $item['quantity'];
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                 break;
327 327
             }
328 328
             
329
-            $invoice->set( 'items', $add_items );
329
+            $invoice->set('items', $add_items);
330 330
             $invoice->cart_details = $cart_details;
331 331
         }
332 332
         
@@ -336,29 +336,29 @@  discard block
 block discarded – undo
336 336
         $tax                = $recurring_details['tax'];
337 337
         $discount           = $recurring_details['discount'];
338 338
         
339
-        if ( $discount > 0 ) {
340
-            $invoice->set( 'discount_code', $parent_invoice->discount_code );
339
+        if ($discount > 0) {
340
+            $invoice->set('discount_code', $parent_invoice->discount_code);
341 341
         }
342 342
         
343
-        $invoice->subtotal = wpinv_round_amount( $subtotal );
344
-        $invoice->tax      = wpinv_round_amount( $tax );
345
-        $invoice->discount = wpinv_round_amount( $discount );
346
-        $invoice->total    = wpinv_round_amount( $total );
343
+        $invoice->subtotal = wpinv_round_amount($subtotal);
344
+        $invoice->tax      = wpinv_round_amount($tax);
345
+        $invoice->discount = wpinv_round_amount($discount);
346
+        $invoice->total    = wpinv_round_amount($total);
347 347
 
348
-        $invoice  = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args );
348
+        $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args);
349 349
 
350 350
         $invoice->save();
351
-        $invoice->update_meta( '_wpinv_subscription_id', $this->id );
351
+        $invoice->update_meta('_wpinv_subscription_id', $this->id);
352 352
         
353
-        if ( !empty( $invoice->ID ) ) {
354
-            wpinv_update_payment_status( $invoice->ID, 'publish' );
353
+        if (!empty($invoice->ID)) {
354
+            wpinv_update_payment_status($invoice->ID, 'publish');
355 355
             sleep(1);
356
-            wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
356
+            wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
357 357
             
358
-            $invoice = wpinv_get_invoice( $invoice->ID );
358
+            $invoice = wpinv_get_invoice($invoice->ID);
359 359
 
360
-            do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
361
-            do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] );
360
+            do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
361
+            do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']);
362 362
             
363 363
             return $invoice->ID;
364 364
         }
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	public function get_transaction_id() {
376 376
 
377
-		if( empty( $this->transaction_id ) ) {
377
+		if (empty($this->transaction_id)) {
378 378
 
379
-			$txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id );
379
+			$txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id);
380 380
 
381
-			if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) {
382
-				$this->set_transaction_id( $txn_id );
381
+			if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) {
382
+				$this->set_transaction_id($txn_id);
383 383
 			}
384 384
 
385 385
 		}
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	 * @since  1.0.0.4
395 395
 	 * @return bool
396 396
 	 */
397
-	public function set_transaction_id( $txn_id = '' ) {
398
-		$this->update( array( 'transaction_id' => $txn_id ) );
397
+	public function set_transaction_id($txn_id = '') {
398
+		$this->update(array('transaction_id' => $txn_id));
399 399
 		$this->transaction_id = $txn_id;
400 400
 	}
401 401
 
@@ -411,35 +411,35 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 		// Determine what date to use as the start for the new expiration calculation
414
-		if( $expires > current_time( 'timestamp' ) && $this->is_active() ) {
414
+		if ($expires > current_time('timestamp') && $this->is_active()) {
415 415
 
416
-			$base_date  = $expires;
416
+			$base_date = $expires;
417 417
 
418 418
 		} else {
419 419
 
420
-			$base_date  = current_time( 'timestamp' );
420
+			$base_date = current_time('timestamp');
421 421
 
422 422
 		}
423 423
 
424
-		$last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) );
424
+		$last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date));
425 425
 
426 426
 
427 427
 		$frequency = isset($this->frequency) ? $this->frequency : 1;
428
-		$expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period  . ' 23:59:59', $base_date ) );
428
+		$expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date));
429 429
 
430
-		if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) {
431
-			$expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) );
430
+		if (date('j', $base_date) == $last_day && 'day' != $this->period) {
431
+			$expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days'));
432 432
 		}
433 433
 
434
-		$expiration  = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this );
434
+		$expiration  = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this);
435 435
 
436
-		do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this );
436
+		do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this);
437 437
 
438 438
 		$this->status = 'active';
439 439
 		$times_billed = $this->get_times_billed();
440 440
 
441 441
 		// Complete subscription if applicable
442
-		if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) {
442
+		if ($this->bill_times > 0 && $times_billed >= $this->bill_times) {
443 443
 			$this->complete();
444 444
 			$this->status = 'completed';
445 445
 		}
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
 			'status'     => $this->status,
450 450
 		);
451 451
 
452
-        $this->subs_db->update( $this->id, $args );
452
+        $this->subs_db->update($this->id, $args);
453 453
 
454
-		do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this );
455
-		do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this );
454
+		do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this);
455
+		do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this);
456 456
 
457 457
 	}
458 458
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	public function complete() {
468 468
 
469 469
 		// Only mark a subscription as complete if it's not already cancelled.
470
-		if ( 'cancelled' === $this->status ) {
470
+		if ('cancelled' === $this->status) {
471 471
 			return;
472 472
 		}
473 473
 
@@ -475,11 +475,11 @@  discard block
 block discarded – undo
475 475
 			'status' => 'completed'
476 476
 		);
477 477
 
478
-		if( $this->subs_db->update( $this->id, $args ) ) {
478
+		if ($this->subs_db->update($this->id, $args)) {
479 479
 
480 480
 			$this->status = 'completed';
481 481
 
482
-			do_action( 'wpinv_subscription_completed', $this->id, $this );
482
+			do_action('wpinv_subscription_completed', $this->id, $this);
483 483
 
484 484
 		}
485 485
 
@@ -494,15 +494,15 @@  discard block
 block discarded – undo
494 494
 	 * @param  $check_expiration bool True if expiration date should be checked with merchant processor before expiring
495 495
 	 * @return void
496 496
 	 */
497
-	public function expire( $check_expiration = false ) {
497
+	public function expire($check_expiration = false) {
498 498
 
499 499
 		$expiration = $this->expiration;
500 500
 
501
-		if( $check_expiration ) {
501
+		if ($check_expiration) {
502 502
 
503 503
 			// check_expiration() updates $this->expiration so compare to $expiration above
504 504
 
505
-			if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) {
505
+			if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) {
506 506
 
507 507
 				return false; // Do not mark as expired since real expiration date is in the future
508 508
 			}
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
 			'status' => 'expired'
514 514
 		);
515 515
 
516
-		if( $this->subs_db->update( $this->id, $args ) ) {
516
+		if ($this->subs_db->update($this->id, $args)) {
517 517
 
518 518
 			$this->status = 'expired';
519 519
 
520
-			do_action( 'wpinv_subscription_expired', $this->id, $this );
520
+			do_action('wpinv_subscription_expired', $this->id, $this);
521 521
 
522 522
 		}
523 523
 
@@ -535,11 +535,11 @@  discard block
 block discarded – undo
535 535
 			'status' => 'failing'
536 536
 		);
537 537
 
538
-		if( $this->subs_db->update( $this->id, $args ) ) {
538
+		if ($this->subs_db->update($this->id, $args)) {
539 539
 
540 540
 			$this->status = 'failing';
541 541
 
542
-			do_action( 'wpinv_subscription_failing', $this->id, $this );
542
+			do_action('wpinv_subscription_failing', $this->id, $this);
543 543
 
544 544
 
545 545
 		}
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
      * @return void
554 554
      */
555 555
     public function cancel() {
556
-        if ( 'cancelled' === $this->status ) {
556
+        if ('cancelled' === $this->status) {
557 557
             return; // Already cancelled
558 558
         }
559 559
 
@@ -561,20 +561,20 @@  discard block
 block discarded – undo
561 561
             'status' => 'cancelled'
562 562
         );
563 563
 
564
-        if ( $this->subs_db->update( $this->id, $args ) ) {
565
-            if ( is_user_logged_in() ) {
566
-                $userdata = get_userdata( get_current_user_id() );
564
+        if ($this->subs_db->update($this->id, $args)) {
565
+            if (is_user_logged_in()) {
566
+                $userdata = get_userdata(get_current_user_id());
567 567
                 $user     = $userdata->display_name;
568 568
             } else {
569
-                $user = __( 'gateway', 'invoicing' );
569
+                $user = __('gateway', 'invoicing');
570 570
             }
571 571
 
572
-            $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $this->parent_payment_id, $user );
573
-            wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true );
572
+            $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $this->parent_payment_id, $user);
573
+            wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true);
574 574
 
575 575
             $this->status = 'cancelled';
576 576
 
577
-            do_action( 'wpinv_subscription_cancelled', $this->id, $this );
577
+            do_action('wpinv_subscription_cancelled', $this->id, $this);
578 578
         }
579 579
     }
580 580
 
@@ -589,10 +589,10 @@  discard block
 block discarded – undo
589 589
 	 */
590 590
 	public function can_cancel() {
591 591
         $ret = false;
592
-	    if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) {
592
+	    if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) {
593 593
             $ret = true;
594 594
         }
595
-		return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this );
595
+		return apply_filters('wpinv_subscription_can_cancel', $ret, $this);
596 596
 	}
597 597
 
598 598
     /**
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      * @return      array
604 604
      */
605 605
     public function get_cancellable_statuses() {
606
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
606
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
607 607
     }
608 608
 
609 609
 	/**
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	 */
615 615
 	public function get_cancel_url() {
616 616
 
617
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' );
617
+		$url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel');
618 618
 
619
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
619
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
620 620
 	}
621 621
 
622 622
 	/**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 */
631 631
 	public function can_renew() {
632 632
 
633
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
633
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
634 634
 	}
635 635
 
636 636
 	/**
@@ -641,9 +641,9 @@  discard block
 block discarded – undo
641 641
 	 */
642 642
 	public function get_renew_url() {
643 643
 
644
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' );
644
+		$url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew');
645 645
 
646
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
646
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
647 647
 	}
648 648
 
649 649
 	/**
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	 * @return bool
654 654
 	 */
655 655
 	public function can_update() {
656
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
656
+		return apply_filters('wpinv_subscription_can_update', false, $this);
657 657
 	}
658 658
 
659 659
 	/**
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 	 */
665 665
 	public function get_update_url() {
666 666
 
667
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) );
667
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id));
668 668
 
669
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
669
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
670 670
 	}
671 671
 
672 672
 	/**
@@ -679,11 +679,11 @@  discard block
 block discarded – undo
679 679
 
680 680
 		$ret = false;
681 681
 
682
-		if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) {
682
+		if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) {
683 683
 			$ret = true;
684 684
 		}
685 685
 
686
-		return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this );
686
+		return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this);
687 687
 
688 688
 	}
689 689
 
@@ -697,26 +697,26 @@  discard block
 block discarded – undo
697 697
 
698 698
 		$ret = false;
699 699
 
700
-		if ( $this->status == 'expired' ) {
700
+		if ($this->status == 'expired') {
701 701
 
702 702
 			$ret = true;
703 703
 
704
-		} elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling'  ) {
704
+		} elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') {
705 705
 
706 706
 			$ret        = false;
707 707
 			$expiration = $this->get_expiration_time();
708 708
 
709
-			if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
709
+			if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
710 710
 				$ret = true;
711 711
 
712
-				if ( 'active' === $this->status || $this->status == 'trialling'  ) {
712
+				if ('active' === $this->status || $this->status == 'trialling') {
713 713
 					$this->expire();
714 714
 				}
715 715
 			}
716 716
 
717 717
 		}
718 718
 
719
-		return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this );
719
+		return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this);
720 720
 
721 721
 	}
722 722
 
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 	 * @return int
738 738
 	 */
739 739
 	public function get_expiration_time() {
740
-		return strtotime( $this->expiration, current_time( 'timestamp' ) );
740
+		return strtotime($this->expiration, current_time('timestamp'));
741 741
 	}
742 742
 
743 743
 	/**
@@ -761,37 +761,37 @@  discard block
 block discarded – undo
761 761
 	 */
762 762
 	public function get_status_label() {
763 763
 
764
-		switch( $this->get_status() ) {
764
+		switch ($this->get_status()) {
765 765
 			case 'active' :
766
-				$status = __( 'Active', 'invoicing' );
766
+				$status = __('Active', 'invoicing');
767 767
 				break;
768 768
 
769 769
 			case 'cancelled' :
770
-				$status = __( 'Cancelled', 'invoicing' );
770
+				$status = __('Cancelled', 'invoicing');
771 771
 				break;
772 772
 
773 773
 			case 'expired' :
774
-				$status = __( 'Expired', 'invoicing' );
774
+				$status = __('Expired', 'invoicing');
775 775
 				break;
776 776
 
777 777
 			case 'pending' :
778
-				$status = __( 'Pending', 'invoicing' );
778
+				$status = __('Pending', 'invoicing');
779 779
 				break;
780 780
 
781 781
 			case 'failing' :
782
-				$status = __( 'Failing', 'invoicing' );
782
+				$status = __('Failing', 'invoicing');
783 783
 				break;
784 784
 
785 785
 			case 'trialling' :
786
-				$status = __( 'Trialling', 'invoicing' );
786
+				$status = __('Trialling', 'invoicing');
787 787
 				break;
788 788
 
789 789
 			case 'completed' :
790
-				$status = __( 'Completed', 'invoicing' );
790
+				$status = __('Completed', 'invoicing');
791 791
 				break;
792 792
 
793 793
 			default:
794
-				$status = ucfirst( $this->get_status() );
794
+				$status = ucfirst($this->get_status());
795 795
 				break;
796 796
 		}
797 797
 
@@ -806,51 +806,51 @@  discard block
 block discarded – undo
806 806
      */
807 807
     public function get_status_label_html() {
808 808
 
809
-        switch( $get_status = $this->get_status() ) {
809
+        switch ($get_status = $this->get_status()) {
810 810
             case 'active' :
811
-                $status = __( 'Active', 'invoicing' );
811
+                $status = __('Active', 'invoicing');
812 812
                 $class = 'label-info';
813 813
                 break;
814 814
 
815 815
             case 'cancelled' :
816
-                $status = __( 'Cancelled', 'invoicing' );
816
+                $status = __('Cancelled', 'invoicing');
817 817
                 $class = 'label-danger';
818 818
                 break;
819 819
 
820 820
             case 'expired' :
821
-                $status = __( 'Expired', 'invoicing' );
821
+                $status = __('Expired', 'invoicing');
822 822
                 $class = 'label-default';
823 823
                 break;
824 824
 
825 825
             case 'pending' :
826
-                $status = __( 'Pending', 'invoicing' );
826
+                $status = __('Pending', 'invoicing');
827 827
                 $class = 'label-primary';
828 828
                 break;
829 829
 
830 830
             case 'failing' :
831
-                $status = __( 'Failing', 'invoicing' );
831
+                $status = __('Failing', 'invoicing');
832 832
                 $class = 'label-danger';
833 833
                 break;
834 834
 
835 835
             case 'trialling' :
836
-                $status = __( 'Trialling', 'invoicing' );
836
+                $status = __('Trialling', 'invoicing');
837 837
                 $class = 'label-info';
838 838
                 break;
839 839
 
840 840
             case 'completed' :
841
-                $status = __( 'Completed', 'invoicing' );
841
+                $status = __('Completed', 'invoicing');
842 842
                 $class = 'label-success';
843 843
                 break;
844 844
 
845 845
             default:
846
-                $status = ucfirst( $this->get_status() );
846
+                $status = ucfirst($this->get_status());
847 847
                 $class = 'label-default';
848 848
                 break;
849 849
         }
850 850
 
851 851
         $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>';
852 852
 
853
-        return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status );
853
+        return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status);
854 854
     }
855 855
 
856 856
     /**
@@ -860,18 +860,18 @@  discard block
 block discarded – undo
860 860
      * @param  string $txn_id The transaction ID from the merchant processor
861 861
      * @return bool
862 862
      */
863
-    public function payment_exists( $txn_id = '' ) {
863
+    public function payment_exists($txn_id = '') {
864 864
         global $wpdb;
865 865
 
866
-        if ( empty( $txn_id ) ) {
866
+        if (empty($txn_id)) {
867 867
             return false;
868 868
         }
869 869
 
870
-        $txn_id = esc_sql( $txn_id );
870
+        $txn_id = esc_sql($txn_id);
871 871
 
872
-        $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
872
+        $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
873 873
 
874
-        if ( $purchase != null ) {
874
+        if ($purchase != null) {
875 875
             return true;
876 876
         }
877 877
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -1,73 +1,73 @@  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['start_date']  = __( 'Start Date', 'invoicing' );
42
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
43
-    $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['start_date']  = __('Start Date', 'invoicing');
42
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
43
+    $columns['status']      = __('Status', 'invoicing');
44 44
 
45 45
     return $columns;
46 46
 }
47 47
 
48
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
49
-function wpinv_discount_custom_column( $column ) {
48
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
49
+function wpinv_discount_custom_column($column) {
50 50
     global $post;
51 51
     
52 52
     $discount = $post;
53 53
 
54
-    switch ( $column ) {
54
+    switch ($column) {
55 55
         case 'name' :
56
-            echo get_the_title( $discount->ID );
56
+            echo get_the_title($discount->ID);
57 57
         break;
58 58
         case 'code' :
59
-            echo wpinv_get_discount_code( $discount->ID );
59
+            echo wpinv_get_discount_code($discount->ID);
60 60
         break;
61 61
         case 'amount' :
62
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
62
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
63 63
         break;
64 64
         case 'usage_limit' :
65
-            echo wpinv_get_discount_uses( $discount->ID );
65
+            echo wpinv_get_discount_uses($discount->ID);
66 66
         break;
67 67
         case 'usage' :
68
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
69
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
70
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
68
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
69
+            if (wpinv_get_discount_max_uses($discount->ID)) {
70
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
71 71
             } else {
72 72
                 $usage .= ' &infin;';
73 73
             }
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
             echo $usage;
76 76
         break;
77 77
         case 'start_date' :
78
-            if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) {
79
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) );
78
+            if ($start_date = wpinv_get_discount_start_date($discount->ID)) {
79
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date));
80 80
             } else {
81 81
                 $value = '-';
82 82
             }
@@ -84,163 +84,163 @@  discard block
 block discarded – undo
84 84
             echo $value;
85 85
         break;
86 86
         case 'expiry_date' :
87
-            if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) {
88
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) );
87
+            if ($expiration = wpinv_get_discount_expiration($discount->ID)) {
88
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration));
89 89
             } else {
90
-                $value = __( 'Never', 'invoicing' );
90
+                $value = __('Never', 'invoicing');
91 91
             }
92 92
                 
93 93
             echo $value;
94 94
         break;
95 95
         break;
96 96
         case 'description' :
97
-            echo wp_kses_post( $post->post_excerpt );
97
+            echo wp_kses_post($post->post_excerpt);
98 98
         break;
99 99
         case 'status' :
100
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
100
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
101 101
             
102
-            echo wpinv_discount_status( $status );
102
+            echo wpinv_discount_status($status);
103 103
         break;
104 104
     }
105 105
 }
106 106
 
107
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
108
-function wpinv_post_row_actions( $actions, $post ) {
109
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
107
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
108
+function wpinv_post_row_actions($actions, $post) {
109
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
110 110
     
111
-    if ( $post_type == 'wpi_invoice' ) {
111
+    if ($post_type == 'wpi_invoice') {
112 112
         $actions = array();
113 113
     }
114 114
     
115
-    if ( $post_type == 'wpi_discount' ) {
116
-        $actions = wpinv_discount_row_actions( $post, $actions );
115
+    if ($post_type == 'wpi_discount') {
116
+        $actions = wpinv_discount_row_actions($post, $actions);
117 117
     }
118 118
     
119 119
     return $actions;
120 120
 }
121 121
 
122
-function wpinv_discount_row_actions( $discount, $row_actions ) {
123
-    $row_actions  = array();
124
-    $edit_link = get_edit_post_link( $discount->ID );
125
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
122
+function wpinv_discount_row_actions($discount, $row_actions) {
123
+    $row_actions = array();
124
+    $edit_link = get_edit_post_link($discount->ID);
125
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
126 126
 
127
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
128
-        $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>';
129
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
130
-        $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>';
127
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
128
+        $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>';
129
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
130
+        $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>';
131 131
     }
132 132
 
133
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
134
-        if ( isset( $row_actions['delete'] ) ) {
135
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
133
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
134
+        if (isset($row_actions['delete'])) {
135
+            unset($row_actions['delete']); // Don't delete used discounts.
136 136
         }
137 137
     } else {
138
-        $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>';
138
+        $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>';
139 139
     }
140 140
     
141 141
 
142
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
142
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
143 143
 
144 144
     return $row_actions;
145 145
 }
146 146
 
147
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
148
-function wpinv_table_primary_column( $default, $screen_id ) {
149
-    if ( 'edit-wpi_invoice' === $screen_id ) {
147
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
148
+function wpinv_table_primary_column($default, $screen_id) {
149
+    if ('edit-wpi_invoice' === $screen_id) {
150 150
         return 'name';
151 151
     }
152 152
     
153 153
     return $default;
154 154
 }
155 155
 
156
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
157
-    if ( !$display ) {
156
+function wpinv_discount_bulk_actions($actions, $display = false) {    
157
+    if (!$display) {
158 158
         return array();
159 159
     }
160 160
     
161 161
     $actions = array(
162
-        'activate'   => __( 'Activate', 'invoicing' ),
163
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
164
-        'delete'     => __( 'Delete', 'invoicing' ),
162
+        'activate'   => __('Activate', 'invoicing'),
163
+        'deactivate' => __('Deactivate', 'invoicing'),
164
+        'delete'     => __('Delete', 'invoicing'),
165 165
     );
166 166
     $two = '';
167 167
     $which = 'top';
168 168
     echo '</div><div class="alignleft actions bulkactions">';
169
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
170
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
171
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
169
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
170
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
171
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
172 172
 
173
-    foreach ( $actions as $name => $title ) {
173
+    foreach ($actions as $name => $title) {
174 174
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
175 175
 
176 176
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
177 177
     }
178 178
     echo "</select>";
179 179
 
180
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
180
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
181 181
     
182 182
     echo '</div><div class="alignleft actions">';
183 183
 }
184
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
184
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
185 185
 
186
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
187
-    if ( $post_type == 'wpi_discount' ) {
186
+function wpinv_disable_months_dropdown($disable, $post_type) {
187
+    if ($post_type == 'wpi_discount') {
188 188
         $disable = true;
189 189
     }
190 190
     
191 191
     return $disable;
192 192
 }
193
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
193
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
194 194
 
195 195
 function wpinv_restrict_manage_posts() {
196 196
     global $typenow;
197 197
 
198
-    if( 'wpi_discount' == $typenow ) {
198
+    if ('wpi_discount' == $typenow) {
199 199
         wpinv_discount_filters();
200 200
     }
201 201
 }
202
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
202
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
203 203
 
204 204
 function wpinv_discount_filters() {
205
-    echo wpinv_discount_bulk_actions( array(), true );
205
+    echo wpinv_discount_bulk_actions(array(), true);
206 206
     
207 207
     ?>
208 208
     <select name="discount_type" id="dropdown_wpinv_discount_type">
209
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
209
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
210 210
         <?php
211 211
             $types = wpinv_get_discount_types();
212 212
 
213
-            foreach ( $types as $name => $type ) {
214
-                echo '<option value="' . esc_attr( $name ) . '"';
213
+            foreach ($types as $name => $type) {
214
+                echo '<option value="' . esc_attr($name) . '"';
215 215
 
216
-                if ( isset( $_GET['discount_type'] ) )
217
-                    selected( $name, $_GET['discount_type'] );
216
+                if (isset($_GET['discount_type']))
217
+                    selected($name, $_GET['discount_type']);
218 218
 
219
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
219
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
220 220
             }
221 221
         ?>
222 222
     </select>
223 223
     <?php
224 224
 }
225 225
 
226
-function wpinv_request( $vars ) {
226
+function wpinv_request($vars) {
227 227
     global $typenow, $wp_query, $wp_post_statuses;
228 228
 
229
-    if ( 'wpi_invoice' === $typenow ) {
230
-        if ( !isset( $vars['post_status'] ) ) {
229
+    if ('wpi_invoice' === $typenow) {
230
+        if (!isset($vars['post_status'])) {
231 231
             $post_statuses = wpinv_get_invoice_statuses();
232 232
 
233
-            foreach ( $post_statuses as $status => $value ) {
234
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
235
-                    unset( $post_statuses[ $status ] );
233
+            foreach ($post_statuses as $status => $value) {
234
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
235
+                    unset($post_statuses[$status]);
236 236
                 }
237 237
             }
238 238
 
239
-            $vars['post_status'] = array_keys( $post_statuses );
239
+            $vars['post_status'] = array_keys($post_statuses);
240 240
         }
241 241
         
242
-        if ( isset( $vars['orderby'] ) ) {
243
-            if ( 'amount' == $vars['orderby'] ) {
242
+        if (isset($vars['orderby'])) {
243
+            if ('amount' == $vars['orderby']) {
244 244
                 $vars = array_merge(
245 245
                     $vars,
246 246
                     array(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                         'orderby'  => 'meta_value_num'
249 249
                     )
250 250
                 );
251
-            } else if ( 'customer' == $vars['orderby'] ) {
251
+            } else if ('customer' == $vars['orderby']) {
252 252
                 $vars = array_merge(
253 253
                     $vars,
254 254
                     array(
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
                         'orderby'  => 'meta_value'
257 257
                     )
258 258
                 );
259
-            } else if ( 'number' == $vars['orderby'] ) {
259
+            } else if ('number' == $vars['orderby']) {
260 260
                 $vars = array_merge(
261 261
                     $vars,
262 262
                     array(
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                         'orderby'  => 'meta_value'
265 265
                     )
266 266
                 );
267
-            } else if ( 'payment_date' == $vars['orderby'] ) {
267
+            } else if ('payment_date' == $vars['orderby']) {
268 268
                 $vars = array_merge(
269 269
                     $vars,
270 270
                     array(
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
                 );
275 275
             }
276 276
         }
277
-    } else if ( 'wpi_item' == $typenow ) {
277
+    } else if ('wpi_item' == $typenow) {
278 278
         // Check if 'orderby' is set to "price"
279
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
279
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
280 280
             $vars = array_merge(
281 281
                 $vars,
282 282
                 array(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         }
288 288
 
289 289
         // Check if "orderby" is set to "vat_rule"
290
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
290
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
291 291
             $vars = array_merge(
292 292
                 $vars,
293 293
                 array(
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         }
299 299
 
300 300
         // Check if "orderby" is set to "vat_class"
301
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
301
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
302 302
             $vars = array_merge(
303 303
                 $vars,
304 304
                 array(
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         }
310 310
         
311 311
         // Check if "orderby" is set to "type"
312
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
312
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
313 313
             $vars = array_merge(
314 314
                 $vars,
315 315
                 array(
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         }
321 321
         
322 322
         // Check if "orderby" is set to "recurring"
323
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
323
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
324 324
             $vars = array_merge(
325 325
                 $vars,
326 326
                 array(
@@ -330,120 +330,120 @@  discard block
 block discarded – undo
330 330
             );
331 331
         }
332 332
 
333
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
333
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
334 334
         // Filter vat rule type
335
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
335
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
336 336
             $meta_query[] = array(
337 337
                     'key'   => '_wpinv_vat_rule',
338
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
338
+                    'value' => sanitize_text_field($_GET['vat_rule']),
339 339
                     'compare' => '='
340 340
                 );
341 341
         }
342 342
         
343 343
         // Filter vat class
344
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
344
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
345 345
             $meta_query[] = array(
346 346
                     'key'   => '_wpinv_vat_class',
347
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
347
+                    'value' => sanitize_text_field($_GET['vat_class']),
348 348
                     'compare' => '='
349 349
                 );
350 350
         }
351 351
         
352 352
         // Filter item type
353
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
353
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
354 354
             $meta_query[] = array(
355 355
                     'key'   => '_wpinv_type',
356
-                    'value' => sanitize_text_field( $_GET['type'] ),
356
+                    'value' => sanitize_text_field($_GET['type']),
357 357
                     'compare' => '='
358 358
                 );
359 359
         }
360 360
         
361
-        if ( !empty( $meta_query ) ) {
361
+        if (!empty($meta_query)) {
362 362
             $vars['meta_query'] = $meta_query;
363 363
         }
364
-    } else if ( 'wpi_discount' == $typenow ) {
365
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
364
+    } else if ('wpi_discount' == $typenow) {
365
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
366 366
         // Filter vat rule type
367
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
367
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
368 368
             $meta_query[] = array(
369 369
                     'key'   => '_wpi_discount_type',
370
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
370
+                    'value' => sanitize_text_field($_GET['discount_type']),
371 371
                     'compare' => '='
372 372
                 );
373 373
         }
374 374
         
375
-        if ( !empty( $meta_query ) ) {
375
+        if (!empty($meta_query)) {
376 376
             $vars['meta_query'] = $meta_query;
377 377
         }
378 378
     }
379 379
 
380 380
     return $vars;
381 381
 }
382
-add_filter( 'request', 'wpinv_request' );
382
+add_filter('request', 'wpinv_request');
383 383
 
384 384
 function wpinv_options_page() {
385
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
385
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
386 386
     
387
-    if ( $page !== 'wpinv-settings' ) {
387
+    if ($page !== 'wpinv-settings') {
388 388
         return;
389 389
     }
390 390
     
391 391
     $settings_tabs = wpinv_get_settings_tabs();
392 392
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
393
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
394
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
393
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
394
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
395 395
     $key           = 'main';
396 396
 
397
-    if ( is_array( $sections ) ) {
398
-        $key = key( $sections );
397
+    if (is_array($sections)) {
398
+        $key = key($sections);
399 399
     }
400 400
 
401
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
402
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
401
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
402
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
403 403
     ob_start();
404 404
     ?>
405 405
     <div class="wrap">
406 406
         <h1 class="nav-tab-wrapper">
407 407
             <?php
408
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
409
-                $tab_url = add_query_arg( array(
408
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
409
+                $tab_url = add_query_arg(array(
410 410
                     'settings-updated' => false,
411 411
                     'tab' => $tab_id,
412
-                ) );
412
+                ));
413 413
 
414 414
                 // Remove the section from the tabs so we always end up at the main section
415
-                $tab_url = remove_query_arg( 'section', $tab_url );
416
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
415
+                $tab_url = remove_query_arg('section', $tab_url);
416
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
417 417
 
418 418
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
419 419
 
420
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
421
-                    echo esc_html( $tab_name );
420
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
421
+                    echo esc_html($tab_name);
422 422
                 echo '</a>';
423 423
             }
424 424
             ?>
425 425
         </h1>
426 426
         <?php
427
-        $number_of_sections = count( $sections );
427
+        $number_of_sections = count($sections);
428 428
         $number = 0;
429
-        if ( $number_of_sections > 1 ) {
429
+        if ($number_of_sections > 1) {
430 430
             echo '<div><ul class="subsubsub">';
431
-            foreach( $sections as $section_id => $section_name ) {
431
+            foreach ($sections as $section_id => $section_name) {
432 432
                 echo '<li>';
433 433
                 $number++;
434
-                $tab_url = add_query_arg( array(
434
+                $tab_url = add_query_arg(array(
435 435
                     'settings-updated' => false,
436 436
                     'tab' => $active_tab,
437 437
                     'section' => $section_id
438
-                ) );
439
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
438
+                ));
439
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
440 440
                 $class = '';
441
-                if ( $section == $section_id ) {
441
+                if ($section == $section_id) {
442 442
                     $class = 'current';
443 443
                 }
444
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
444
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
445 445
 
446
-                if ( $number != $number_of_sections ) {
446
+                if ($number != $number_of_sections) {
447 447
                     echo ' | ';
448 448
                 }
449 449
                 echo '</li>';
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
             <form method="post" action="options.php">
456 456
                 <table class="form-table">
457 457
                 <?php
458
-                settings_fields( 'wpinv_settings' );
458
+                settings_fields('wpinv_settings');
459 459
 
460
-                if ( 'main' === $section ) {
461
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
460
+                if ('main' === $section) {
461
+                    do_action('wpinv_settings_tab_top', $active_tab);
462 462
                 }
463 463
 
464
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
465
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
466
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
464
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
465
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
466
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
467 467
 
468 468
                 // For backwards compatibility
469
-                if ( 'main' === $section ) {
470
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
469
+                if ('main' === $section) {
470
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
471 471
                 }
472 472
                 ?>
473 473
                 </table>
@@ -480,53 +480,53 @@  discard block
 block discarded – undo
480 480
     echo $content;
481 481
 }
482 482
 
483
-function wpinv_item_type_class( $classes, $class, $post_id ) {
483
+function wpinv_item_type_class($classes, $class, $post_id) {
484 484
     global $pagenow, $typenow;
485 485
 
486
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
487
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
488
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
486
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
487
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
488
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
489 489
         }
490 490
         
491
-        if ( !wpinv_item_is_editable( $post_id ) ) {
491
+        if (!wpinv_item_is_editable($post_id)) {
492 492
             $classes[] = 'wpi-editable-n';
493 493
         }
494 494
     }
495 495
     return $classes;
496 496
 }
497
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
497
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
498 498
 
499 499
 function wpinv_check_quick_edit() {
500 500
     global $pagenow, $current_screen, $wpinv_item_screen;
501 501
 
502
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
503
-        if ( empty( $wpinv_item_screen ) ) {
504
-            if ( $current_screen->post_type == 'wpi_item' ) {
502
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
503
+        if (empty($wpinv_item_screen)) {
504
+            if ($current_screen->post_type == 'wpi_item') {
505 505
                 $wpinv_item_screen = 'y';
506 506
             } else {
507 507
                 $wpinv_item_screen = 'n';
508 508
             }
509 509
         }
510 510
 
511
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
512
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
513
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
511
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
512
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
513
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
514 514
         }
515 515
     }
516 516
 }
517
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
517
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
518 518
 
519
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
520
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
521
-        unset( $actions['inline hide-if-no-js'] );
519
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
520
+    if (isset($actions['inline hide-if-no-js'])) {
521
+        unset($actions['inline hide-if-no-js']);
522 522
     }
523 523
     
524
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
525
-        if ( isset( $actions['trash'] ) ) {
526
-            unset( $actions['trash'] );
524
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
525
+        if (isset($actions['trash'])) {
526
+            unset($actions['trash']);
527 527
         }
528
-        if ( isset( $actions['delete'] ) ) {
529
-            unset( $actions['delete'] );
528
+        if (isset($actions['delete'])) {
529
+            unset($actions['delete']);
530 530
         }
531 531
     }
532 532
 
@@ -543,19 +543,19 @@  discard block
 block discarded – undo
543 543
  * @param int $post_parent (default: 0) Parent for the new page
544 544
  * @return int page ID
545 545
  */
546
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
546
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
547 547
     global $wpdb;
548 548
 
549
-    $option_value = wpinv_get_option( $option );
549
+    $option_value = wpinv_get_option($option);
550 550
 
551
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
552
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
551
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
552
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
553 553
             // Valid page is already in place
554 554
             return $page_object->ID;
555 555
         }
556 556
     }
557 557
 
558
-    if(!empty($post_parent)){
558
+    if (!empty($post_parent)) {
559 559
         $page = get_page_by_path($post_parent);
560 560
         if ($page) {
561 561
             $post_parent = $page->ID;
@@ -564,40 +564,40 @@  discard block
 block discarded – undo
564 564
         }
565 565
     }
566 566
 
567
-    if ( strlen( $page_content ) > 0 ) {
567
+    if (strlen($page_content) > 0) {
568 568
         // Search for an existing page with the specified page content (typically a shortcode)
569
-        $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}%" ) );
569
+        $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}%"));
570 570
     } else {
571 571
         // Search for an existing page with the specified page slug
572
-        $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 ) );
572
+        $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));
573 573
     }
574 574
 
575
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
575
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
576 576
 
577
-    if ( $valid_page_found ) {
578
-        if ( $option ) {
579
-            wpinv_update_option( $option, $valid_page_found );
577
+    if ($valid_page_found) {
578
+        if ($option) {
579
+            wpinv_update_option($option, $valid_page_found);
580 580
         }
581 581
         return $valid_page_found;
582 582
     }
583 583
 
584 584
     // Search for a matching valid trashed page
585
-    if ( strlen( $page_content ) > 0 ) {
585
+    if (strlen($page_content) > 0) {
586 586
         // Search for an existing page with the specified page content (typically a shortcode)
587
-        $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}%" ) );
587
+        $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}%"));
588 588
     } else {
589 589
         // Search for an existing page with the specified page slug
590
-        $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 ) );
590
+        $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));
591 591
     }
592 592
 
593
-    if ( $trashed_page_found ) {
593
+    if ($trashed_page_found) {
594 594
         $page_id   = $trashed_page_found;
595 595
         $page_data = array(
596 596
             'ID'             => $page_id,
597 597
             'post_status'    => 'publish',
598 598
             'post_parent'    => $post_parent,
599 599
         );
600
-        wp_update_post( $page_data );
600
+        wp_update_post($page_data);
601 601
     } else {
602 602
         $page_data = array(
603 603
             'post_status'    => 'publish',
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
             'post_parent'    => $post_parent,
610 610
             'comment_status' => 'closed',
611 611
         );
612
-        $page_id = wp_insert_post( $page_data );
612
+        $page_id = wp_insert_post($page_data);
613 613
     }
614 614
 
615
-    if ( $option ) {
616
-        wpinv_update_option( $option, (int)$page_id );
615
+    if ($option) {
616
+        wpinv_update_option($option, (int)$page_id);
617 617
     }
618 618
 
619 619
     return $page_id;
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
 
9 9
 
10 10
 // Exit if accessed directly
11
-if ( ! defined( 'ABSPATH' ) ) exit;
11
+if (!defined('ABSPATH')) exit;
12 12
 
13 13
 
14 14
 // Load WP_List_Table if not loaded
15
-if( ! class_exists( 'WP_List_Table' ) ) {
15
+if (!class_exists('WP_List_Table')) {
16 16
 	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
17 17
 }
18 18
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	public $pending_count   = 0;
36 36
 	public $expired_count   = 0;
37 37
 	public $completed_count = 0;
38
-	public $trialling_count  = 0;
38
+	public $trialling_count = 0;
39 39
 	public $cancelled_count = 0;
40 40
 	public $failing_count   = 0;
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 * @since       1.0.0
47 47
 	 * @return      void
48 48
 	 */
49
-	function __construct(){
49
+	function __construct() {
50 50
 		global $status, $page;
51 51
 
52 52
 		// Set parent defaults
53
-		parent::__construct( array(
53
+		parent::__construct(array(
54 54
 			'singular'  => 'subscription',
55 55
 			'plural'    => 'subscriptions',
56 56
 			'ajax'      => false
57
-		) );
57
+		));
58 58
 
59 59
 		$this->get_subscription_counts();
60 60
 
@@ -69,28 +69,28 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function get_views() {
71 71
 
72
-		$current         = isset( $_GET['status'] ) ? $_GET['status'] : '';
73
-		$total_count     = '&nbsp;<span class="count">(' . $this->total_count    . ')</span>';
72
+		$current         = isset($_GET['status']) ? $_GET['status'] : '';
73
+		$total_count     = '&nbsp;<span class="count">(' . $this->total_count . ')</span>';
74 74
 		$active_count    = '&nbsp;<span class="count">(' . $this->active_count . ')</span>';
75 75
 		$pending_count   = '&nbsp;<span class="count">(' . $this->pending_count . ')</span>';
76
-		$expired_count   = '&nbsp;<span class="count">(' . $this->expired_count  . ')</span>';
76
+		$expired_count   = '&nbsp;<span class="count">(' . $this->expired_count . ')</span>';
77 77
 		$completed_count = '&nbsp;<span class="count">(' . $this->completed_count . ')</span>';
78
-		$trialling_count  = '&nbsp;<span class="count">(' . $this->trialling_count   . ')</span>';
79
-		$cancelled_count = '&nbsp;<span class="count">(' . $this->cancelled_count   . ')</span>';
80
-		$failing_count   = '&nbsp;<span class="count">(' . $this->failing_count   . ')</span>';
78
+		$trialling_count = '&nbsp;<span class="count">(' . $this->trialling_count . ')</span>';
79
+		$cancelled_count = '&nbsp;<span class="count">(' . $this->cancelled_count . ')</span>';
80
+		$failing_count   = '&nbsp;<span class="count">(' . $this->failing_count . ')</span>';
81 81
 
82 82
 		$views = array(
83
-			'all'       => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ),
84
-			'active'    => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ),
85
-			'pending'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ),
86
-			'expired'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ),
87
-			'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ),
88
-			'trialling'  => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ),
89
-			'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ),
90
-			'failing'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ),
83
+			'all'       => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count),
84
+			'active'    => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count),
85
+			'pending'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count),
86
+			'expired'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count),
87
+			'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count),
88
+			'trialling'  => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count),
89
+			'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count),
90
+			'failing'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count),
91 91
 		);
92 92
 
93
-		return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views );
93
+		return apply_filters('wpinv_recurring_subscriptions_table_views', $views);
94 94
 	}
95 95
 
96 96
 	/**
@@ -104,27 +104,27 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @return void
106 106
 	 */
107
-	public function search_box( $text, $input_id ) {
107
+	public function search_box($text, $input_id) {
108 108
 
109
-		if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
109
+		if (empty($_REQUEST['s']) && !$this->has_items()) {
110 110
 			return;
111 111
 		}
112 112
 
113 113
 		$input_id = $input_id . '-search-input';
114 114
 
115
-		if ( ! empty( $_REQUEST['orderby'] ) ) {
116
-			echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
115
+		if (!empty($_REQUEST['orderby'])) {
116
+			echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
117 117
 		}
118 118
 
119
-		if ( ! empty( $_REQUEST['order'] ) ) {
120
-			echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
119
+		if (!empty($_REQUEST['order'])) {
120
+			echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
121 121
 		}
122 122
 ?>
123 123
 		<p class="search-box">
124
-			<?php do_action( 'wpinv_recurring_subscription_search_box' ); ?>
124
+			<?php do_action('wpinv_recurring_subscription_search_box'); ?>
125 125
 			<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
126 126
 			<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
127
-			<?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/>
127
+			<?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/>
128 128
 		</p>
129 129
 <?php
130 130
 	}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 * @since       1.0.0
137 137
 	 * @return      string
138 138
 	 */
139
-	function column_default( $item, $column_name ) {
139
+	function column_default($item, $column_name) {
140 140
 		return $item->$column_name;
141 141
 	}
142 142
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
      * @since       1.0.0
148 148
      * @return      string
149 149
      */
150
-    function column_sub_id( $item ) {
151
-        return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>';
150
+    function column_sub_id($item) {
151
+        return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>';
152 152
     }
153 153
 
154 154
 	/**
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 	 * @since       1.0.0
159 159
 	 * @return      string
160 160
 	 */
161
-	function column_customer_id( $item ) {
162
-		$subscriber = get_userdata( $item->customer_id );
163
-		$customer   = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email;
161
+	function column_customer_id($item) {
162
+		$subscriber = get_userdata($item->customer_id);
163
+		$customer   = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email;
164 164
 
165
-		return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>';
165
+		return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>';
166 166
 	}
167 167
 
168 168
 	/**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @since       1.0.0
173 173
 	 * @return      string
174 174
 	 */
175
-	function column_status( $item ) {
175
+	function column_status($item) {
176 176
 		return $item->get_status_label();
177 177
 	}
178 178
 
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	 * @since       1.0.0
184 184
 	 * @return      string
185 185
 	 */
186
-	function column_period( $item ) {
186
+	function column_period($item) {
187 187
 
188
-		$period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency );
188
+		$period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency);
189 189
 
190
-		return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period;
190
+		return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period;
191 191
 	}
192 192
 
193 193
 	/**
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 	 * @since       1.0.0
198 198
 	 * @return      string
199 199
 	 */
200
-	function column_bill_times( $item ) {
201
-		return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times );
200
+	function column_bill_times($item) {
201
+		return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times);
202 202
 	}
203 203
 
204 204
 	/**
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @since       1.0.0
209 209
 	 * @return      string
210 210
 	 */
211
-	function column_initial_amount( $item ) {
212
-		return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) );
211
+	function column_initial_amount($item) {
212
+		return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id));
213 213
 	}
214 214
 
215 215
 	/**
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 * @since       1.0.0
220 220
 	 * @return      string
221 221
 	 */
222
-	function column_renewal_date( $item ) {
223
-		return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' );
222
+	function column_renewal_date($item) {
223
+		return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing');
224 224
 	}
225 225
 
226 226
 	/**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 	 * @since       1.0.0
231 231
 	 * @return      string
232 232
 	 */
233
-	function column_parent_payment_id( $item ) {
234
-		return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>';
233
+	function column_parent_payment_id($item) {
234
+		return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>';
235 235
 	}
236 236
 
237 237
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @since       1.0.0
242 242
 	 * @return      string
243 243
 	 */
244
-	function column_product_id( $item ) {
245
-		return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>';
244
+	function column_product_id($item) {
245
+		return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>';
246 246
 	}
247 247
 
248 248
 	/**
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @since       2.0
253 253
 	 * @return      string
254 254
 	 */
255
-	function column_actions( $item ) {
256
-		return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>';
255
+	function column_actions($item) {
256
+		return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>';
257 257
 	}
258 258
 
259 259
 
@@ -265,21 +265,21 @@  discard block
 block discarded – undo
265 265
 	 * @return      array
266 266
 	 */
267 267
 
268
-	function get_columns(){
268
+	function get_columns() {
269 269
 		$columns = array(
270
-			'sub_id'            => __( 'ID', 'invoicing' ),
271
-			'customer_id'       => __( 'Customer', 'invoicing' ),
272
-			'status'            => __( 'Status', 'invoicing' ),
273
-			'period'            => __( 'Billing Cycle', 'invoicing' ),
274
-			'initial_amount'    => __( 'Initial Amount', 'invoicing' ),
275
-			'bill_times'        => __( 'Times Billed', 'invoicing' ),
276
-			'renewal_date'      => __( 'Renewal Date', 'invoicing' ),
277
-			'parent_payment_id' => __( 'Invoice', 'invoicing' ),
278
-			'product_id'        => __( 'Item', 'invoicing' ),
279
-			'actions'           => __( 'Actions', 'invoicing' ),
270
+			'sub_id'            => __('ID', 'invoicing'),
271
+			'customer_id'       => __('Customer', 'invoicing'),
272
+			'status'            => __('Status', 'invoicing'),
273
+			'period'            => __('Billing Cycle', 'invoicing'),
274
+			'initial_amount'    => __('Initial Amount', 'invoicing'),
275
+			'bill_times'        => __('Times Billed', 'invoicing'),
276
+			'renewal_date'      => __('Renewal Date', 'invoicing'),
277
+			'parent_payment_id' => __('Invoice', 'invoicing'),
278
+			'product_id'        => __('Item', 'invoicing'),
279
+			'actions'           => __('Actions', 'invoicing'),
280 280
 		);
281 281
 
282
-		return apply_filters( 'wpinv_report_subscription_columns', $columns );
282
+		return apply_filters('wpinv_report_subscription_columns', $columns);
283 283
 	}
284 284
 
285 285
 	/**
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @return      int
291 291
 	 */
292 292
 	function get_paged() {
293
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
293
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
294 294
 	}
295 295
 
296 296
 	/**
@@ -306,16 +306,16 @@  discard block
 block discarded – undo
306 306
 
307 307
 		$db = new WPInv_Subscriptions_DB;
308 308
 
309
-		$search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
309
+		$search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
310 310
 
311 311
 		$this->total_count     = $db->count();
312
-		$this->active_count    = $db->count( array( 'status' => 'active', 'search' => $search ) );
313
-		$this->pending_count   = $db->count( array( 'status' => 'pending', 'search' => $search ) );
314
-		$this->expired_count   = $db->count( array( 'status' => 'expired', 'search' => $search ) );
315
-		$this->trialling_count  = $db->count( array( 'status' => 'trialling', 'search' => $search ) );
316
-		$this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) );
317
-		$this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) );
318
-		$this->failing_count   = $db->count( array( 'status' => 'failing', 'search' => $search ) );
312
+		$this->active_count    = $db->count(array('status' => 'active', 'search' => $search));
313
+		$this->pending_count   = $db->count(array('status' => 'pending', 'search' => $search));
314
+		$this->expired_count   = $db->count(array('status' => 'expired', 'search' => $search));
315
+		$this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search));
316
+		$this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search));
317
+		$this->completed_count = $db->count(array('status' => 'completed', 'search' => $search));
318
+		$this->failing_count   = $db->count(array('status' => 'failing', 'search' => $search));
319 319
 
320 320
 	}
321 321
 
@@ -336,28 +336,28 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$columns  = $this->get_columns();
338 338
 		$hidden   = array(); // No hidden columns
339
-		$status   = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
339
+		$status   = isset($_GET['status']) ? $_GET['status'] : 'any';
340 340
 		$sortable = $this->get_sortable_columns();
341 341
 
342
-		$this->_column_headers = array( $columns, $hidden, $sortable );
342
+		$this->_column_headers = array($columns, $hidden, $sortable);
343 343
 
344 344
 		$current_page = $this->get_pagenum();
345 345
 
346 346
 		$db     = new WPInv_Subscriptions_DB;
347
-		$search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
347
+		$search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
348 348
 		$args   = array(
349 349
 			'number' => $this->per_page,
350
-			'offset' => $this->per_page * ( $this->get_paged() - 1 ),
350
+			'offset' => $this->per_page * ($this->get_paged() - 1),
351 351
 			'search' => $search
352 352
 		);
353 353
 
354
-		if ( 'any' !== $status ) {
354
+		if ('any' !== $status) {
355 355
 			$args['status'] = $status;
356 356
 		}
357 357
 
358
-		$this->items = $db->get_subscriptions( $args );
358
+		$this->items = $db->get_subscriptions($args);
359 359
 
360
-		switch ( $status ) {
360
+		switch ($status) {
361 361
 			case 'active':
362 362
 				$total_items = $this->active_count;
363 363
 				break;
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 				break;
386 386
 		}
387 387
 
388
-		$this->set_pagination_args( array(
388
+		$this->set_pagination_args(array(
389 389
 			'total_items' => $total_items,
390 390
 			'per_page'    => $this->per_page,
391
-			'total_pages' => ceil( $total_items / $this->per_page )
392
-		) );
391
+			'total_pages' => ceil($total_items / $this->per_page)
392
+		));
393 393
 	}
394 394
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
 
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
22
+        if (!$use_taxes && (float)$invoice->get_tax() > 0) {
23 23
             $use_taxes = true;
24 24
         }
25
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
25
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
26 26
         $is_recurring       = $invoice->is_recurring();
27 27
         $post_type_object   = get_post_type_object($invoice->post_type);
28 28
         $type_title         = $post_type_object->labels->singular_name;
29 29
 
30 30
         $cols = 5;
31
-        if ( $item_quantities ) {
31
+        if ($item_quantities) {
32 32
             $cols++;
33 33
         }
34
-        if ( $use_taxes ) {
34
+        if ($use_taxes) {
35 35
             $cols++;
36 36
         }
37 37
         $class = '';
38
-        if ( $invoice->is_paid() ) {
38
+        if ($invoice->is_paid()) {
39 39
             $class .= ' wpinv-paid';
40 40
         }
41
-        if ( $invoice->is_refunded() ) {
41
+        if ($invoice->is_refunded()) {
42 42
             $class .= ' wpinv-refunded';
43 43
         }
44
-        if ( $is_recurring ) {
44
+        if ($is_recurring) {
45 45
             $class .= ' wpi-recurring';
46 46
         }
47 47
         ?>
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
50 50
                 <thead>
51 51
                     <tr>
52
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
53
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
54
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
55
-                        <?php if ( $item_quantities ) { ?>
56
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
52
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
53
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
54
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
55
+                        <?php if ($item_quantities) { ?>
56
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
59
-                        <?php if ( $use_taxes ) { ?>
60
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
58
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
59
+                        <?php if ($use_taxes) { ?>
60
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
61 61
                         <?php } ?>
62 62
                         <th class="action"></th>
63 63
                     </tr>
64 64
                 </thead>
65 65
                 <tbody class="wpinv-line-items">
66
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
66
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
67 67
                 </tbody>
68 68
                 <tfoot class="wpinv-totals">
69 69
                     <tr>
@@ -75,44 +75,44 @@  discard block
 block discarded – undo
75 75
                                         </td>
76 76
                                         <td class="title">
77 77
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
78
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
78
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
79 79
                                             <div class="wp-clearfix">
80 80
                                                 <label class="wpi-vat-rule">
81
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
81
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
82 82
                                                     <span class="input-text-wrap">
83
-                                                        <?php echo wpinv_html_select( array(
83
+                                                        <?php echo wpinv_html_select(array(
84 84
                                                             'options'          => $wpinv_euvat->get_rules(),
85 85
                                                             'name'             => '_wpinv_quick[vat_rule]',
86 86
                                                             'id'               => '_wpinv_quick_vat_rule',
87 87
                                                             'show_option_all'  => false,
88 88
                                                             'show_option_none' => false,
89 89
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
90
-                                                        ) ); ?>
90
+                                                        )); ?>
91 91
                                                     </span>
92 92
                                                 </label>
93 93
                                             </div>
94
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
94
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-class">
97
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_all_classes(),
101 101
                                                             'name'             => '_wpinv_quick[vat_class]',
102 102
                                                             'id'               => '_wpinv_quick_vat_class',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110 110
                                             <?php } ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-item-type">
113
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $item_types,
117 117
                                                             'name'             => '_wpinv_quick[type]',
118 118
                                                             'id'               => '_wpinv_quick_type',
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                                                             'show_option_all'  => false,
121 121
                                                             'show_option_none' => false,
122 122
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
123
-                                                        ) ); ?>
123
+                                                        )); ?>
124 124
                                                     </span>
125 125
                                                 </label>
126 126
                                             </div>
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
                                             </div>
134 134
                                         </td>
135 135
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
136
-                                        <?php if ( $item_quantities ) { ?>
136
+                                        <?php if ($item_quantities) { ?>
137 137
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
138 138
                                         <?php } ?>
139 139
                                         <td class="total"></td>
140
-                                        <?php if ( $use_taxes ) { ?>
140
+                                        <?php if ($use_taxes) { ?>
141 141
                                         <td class="tax"></td>
142 142
                                         <?php } ?>
143 143
                                         <td class="action"></td>
@@ -150,29 +150,29 @@  discard block
 block discarded – undo
150 150
                         <td colspan="<?php echo $cols; ?>"></td>
151 151
                     </tr>
152 152
                     <tr class="totals">
153
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
153
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
154 154
                         <td colspan="4">
155 155
                             <table cellspacing="0" cellpadding="0">
156 156
                                 <tr class="subtotal">
157
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
158
-                                    <td class="total"><?php echo $subtotal;?></td>
157
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
158
+                                    <td class="total"><?php echo $subtotal; ?></td>
159 159
                                     <td class="action"></td>
160 160
                                 </tr>
161 161
                                 <tr class="discount">
162
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
163
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
162
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
163
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
164 164
                                     <td class="action"></td>
165 165
                                 </tr>
166
-                                <?php if ( $use_taxes ) { ?>
166
+                                <?php if ($use_taxes) { ?>
167 167
                                 <tr class="tax">
168
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
169
-                                    <td class="total"><?php echo $tax;?></td>
168
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
169
+                                    <td class="total"><?php echo $tax; ?></td>
170 170
                                     <td class="action"></td>
171 171
                                 </tr>
172 172
                                 <?php } ?>
173 173
                                 <tr class="total">
174
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
175
-                                    <td class="total"><?php echo $total;?></td>
174
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
175
+                                    <td class="total"><?php echo $total; ?></td>
176 176
                                     <td class="action"></td>
177 177
                                 </tr>
178 178
                             </table>
@@ -183,89 +183,89 @@  discard block
 block discarded – undo
183 183
             <div class="wpinv-actions">
184 184
                 <?php ob_start(); ?>
185 185
                 <?php
186
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
187
-                        if ( !$invoice->is_recurring() ) {
188
-                            echo wpinv_item_dropdown( array(
186
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
187
+                        if (!$invoice->is_recurring()) {
188
+                            echo wpinv_item_dropdown(array(
189 189
                                 'name'             => 'wpinv_invoice_item',
190 190
                                 'id'               => 'wpinv_invoice_item',
191 191
                                 'show_recurring'   => true,
192
-                            ) );
192
+                            ));
193 193
                     ?>
194
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
194
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
195 195
                     <?php } ?>
196
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
197
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
196
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
197
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
198 198
             </div>
199 199
         </div>
200 200
         <?php
201 201
     }
202 202
 
203
-    public static function prices( $post ) {        
203
+    public static function prices($post) {        
204 204
         $symbol         = wpinv_currency_symbol();
205 205
         $position       = wpinv_currency_position();
206
-        $item           = new WPInv_Item( $post->ID );
206
+        $item           = new WPInv_Item($post->ID);
207 207
 
208 208
         $price          = $item->get_price();
209 209
         $is_recurring   = $item->is_recurring();
210 210
         $period         = $item->get_recurring_period();
211
-        $interval       = absint( $item->get_recurring_interval() );
212
-        $times          = absint( $item->get_recurring_limit() );
211
+        $interval       = absint($item->get_recurring_interval());
212
+        $times          = absint($item->get_recurring_limit());
213 213
         $free_trial     = $item->has_free_trial();
214 214
         $trial_interval = $item->get_trial_interval();
215 215
         $trial_period   = $item->get_trial_period();
216 216
 
217 217
         $intervals      = array();
218
-        for ( $i = 1; $i <= 90; $i++ ) {
218
+        for ($i = 1; $i <= 90; $i++) {
219 219
             $intervals[$i] = $i;
220 220
         }
221 221
 
222
-        $interval       = $interval > 0 ? $interval : 1;
222
+        $interval = $interval > 0 ? $interval : 1;
223 223
 
224 224
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
225 225
         ?>
226
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
227
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
226
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
227
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
228 228
         </p>
229 229
         <p class="wpinv-row-is-recurring">
230 230
             <label for="wpinv_is_recurring">
231
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
232
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
231
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
232
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
233 233
             </label>
234
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
234
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
235 235
         </p>
236
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
237
-            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
238
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
236
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
237
+            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
238
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
239 239
                 'options'          => $intervals,
240 240
                 'name'             => 'wpinv_recurring_interval',
241 241
                 'id'               => 'wpinv_recurring_interval',
242 242
                 'selected'         => $interval,
243 243
                 'show_option_all'  => false,
244 244
                 'show_option_none' => false
245
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
246
-            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
245
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
246
+            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
247 247
             <span class="clear wpi-trial-clr"></span>
248 248
             <label class="wpinv-free-trial" for="wpinv_free_trial">
249
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
250
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
249
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
250
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
251 251
             </label>
252 252
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
253
-                <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
253
+                <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
254 254
             </label>
255
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
255
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
256 256
         </p>
257
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
258
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
257
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
258
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
259 259
         <?php
260 260
     }
261 261
 
262
-    public static function vat_rules( $post ) {
262
+    public static function vat_rules($post) {
263 263
         global $wpinv_euvat;
264 264
 
265
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
265
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
266 266
         ?>
267
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
268
-        <?php echo wpinv_html_select( array(
267
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
268
+        <?php echo wpinv_html_select(array(
269 269
                     'options'          => $wpinv_euvat->get_rules(),
270 270
                     'name'             => 'wpinv_vat_rules',
271 271
                     'id'               => 'wpinv_vat_rules',
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
                     'show_option_all'  => false,
274 274
                     'show_option_none' => false,
275 275
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                ) ); ?>
276
+                )); ?>
277 277
         </p>
278
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
279
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
278
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
279
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
280 280
         <?php
281 281
     }
282 282
 
283
-    public static function vat_classes( $post ) {
283
+    public static function vat_classes($post) {
284 284
         global $wpinv_euvat;
285 285
         
286
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
286
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
287 287
         ?>
288
-        <p><?php echo wpinv_html_select( array(
288
+        <p><?php echo wpinv_html_select(array(
289 289
                     'options'          => $wpinv_euvat->get_all_classes(),
290 290
                     'name'             => 'wpinv_vat_class',
291 291
                     'id'               => 'wpinv_vat_class',
@@ -293,18 +293,18 @@  discard block
 block discarded – undo
293 293
                     'show_option_all'  => false,
294 294
                     'show_option_none' => false,
295 295
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
296
-                ) ); ?>
296
+                )); ?>
297 297
         </p>
298
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
298
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
299 299
         <?php
300 300
     }
301 301
 
302
-    public static function item_info( $post ) {
303
-        $item_type = wpinv_get_item_type( $post->ID );
304
-        do_action( 'wpinv_item_info_metabox_before', $post );
302
+    public static function item_info($post) {
303
+        $item_type = wpinv_get_item_type($post->ID);
304
+        do_action('wpinv_item_info_metabox_before', $post);
305 305
         ?>
306
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
307
-        <?php echo wpinv_html_select( array(
306
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
307
+        <?php echo wpinv_html_select(array(
308 308
                     'options'          => wpinv_get_item_types(),
309 309
                     'name'             => 'wpinv_item_type',
310 310
                     'id'               => 'wpinv_item_type',
@@ -312,114 +312,114 @@  discard block
 block discarded – undo
312 312
                     'show_option_all'  => false,
313 313
                     'show_option_none' => false,
314 314
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
315
-                ) ); ?>
315
+                )); ?>
316 316
         </p>
317
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
317
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
318 318
         <?php
319
-        do_action( 'wpinv_item_info_metabox_after', $post );
319
+        do_action('wpinv_item_info_metabox_after', $post);
320 320
     }
321 321
 
322
-    public static function meta_values( $post ) {
323
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
322
+    public static function meta_values($post) {
323
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
324 324
             'type',
325 325
             'custom_id'
326
-        ) );
326
+        ));
327 327
 
328
-        if ( empty( $meta_keys ) ) {
328
+        if (empty($meta_keys)) {
329 329
             return;
330 330
         }
331 331
 
332
-        do_action( 'wpinv_meta_values_metabox_before', $post );
332
+        do_action('wpinv_meta_values_metabox_before', $post);
333 333
 
334
-        foreach ( $meta_keys as $meta_key ) {
334
+        foreach ($meta_keys as $meta_key) {
335 335
             ?>
336
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
336
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
337 337
             <?php 
338 338
         }
339 339
 
340
-        do_action( 'wpinv_meta_values_metabox_after', $post );
340
+        do_action('wpinv_meta_values_metabox_after', $post);
341 341
     }
342 342
 
343
-    public static function save( $post_id, $data, $post ) {
344
-        $invoice        = new WPInv_Invoice( $post_id );
343
+    public static function save($post_id, $data, $post) {
344
+        $invoice        = new WPInv_Invoice($post_id);
345 345
 
346 346
         // Billing
347
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
348
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
349
-        $company        = sanitize_text_field( $data['wpinv_company'] );
350
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
351
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
352
-        $address        = sanitize_text_field( $data['wpinv_address'] );
353
-        $city           = sanitize_text_field( $data['wpinv_city'] );
354
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
355
-        $country        = sanitize_text_field( $data['wpinv_country'] );
356
-        $state          = sanitize_text_field( $data['wpinv_state'] );
347
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
348
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
349
+        $company        = sanitize_text_field($data['wpinv_company']);
350
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
351
+        $phone          = sanitize_text_field($data['wpinv_phone']);
352
+        $address        = sanitize_text_field($data['wpinv_address']);
353
+        $city           = sanitize_text_field($data['wpinv_city']);
354
+        $zip            = sanitize_text_field($data['wpinv_zip']);
355
+        $country        = sanitize_text_field($data['wpinv_country']);
356
+        $state          = sanitize_text_field($data['wpinv_state']);
357 357
 
358 358
         // Details
359
-        $status         = sanitize_text_field( $data['wpinv_status'] );
360
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
361
-        $number         = sanitize_text_field( $data['wpinv_number'] );
362
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
359
+        $status         = sanitize_text_field($data['wpinv_status']);
360
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
361
+        $number         = sanitize_text_field($data['wpinv_number']);
362
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
363 363
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
364 364
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
365 365
 
366
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
366
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
367 367
 
368
-        $invoice->set( 'due_date', $due_date );
369
-        $invoice->set( 'first_name', $first_name );
370
-        $invoice->set( 'last_name', $last_name );
371
-        $invoice->set( 'company', $company );
372
-        $invoice->set( 'vat_number', $vat_number );
373
-        $invoice->set( 'phone', $phone );
374
-        $invoice->set( 'address', $address );
375
-        $invoice->set( 'city', $city );
376
-        $invoice->set( 'zip', $zip );
377
-        $invoice->set( 'country', $country );
378
-        $invoice->set( 'state', $state );
379
-        $invoice->set( 'status', $status );
368
+        $invoice->set('due_date', $due_date);
369
+        $invoice->set('first_name', $first_name);
370
+        $invoice->set('last_name', $last_name);
371
+        $invoice->set('company', $company);
372
+        $invoice->set('vat_number', $vat_number);
373
+        $invoice->set('phone', $phone);
374
+        $invoice->set('address', $address);
375
+        $invoice->set('city', $city);
376
+        $invoice->set('zip', $zip);
377
+        $invoice->set('country', $country);
378
+        $invoice->set('state', $state);
379
+        $invoice->set('status', $status);
380 380
         //$invoice->set( 'number', $number );
381 381
         //$invoice->set( 'discounts', $discounts );
382 382
         //$invoice->set( 'discount', $discount );
383
-        $invoice->set( 'ip', $ip );
383
+        $invoice->set('ip', $ip);
384 384
         $invoice->old_status = $_POST['original_post_status'];
385 385
         $invoice->currency = wpinv_get_currency();
386
-        if ( !empty( $data['wpinv_gateway'] ) ) {
387
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
386
+        if (!empty($data['wpinv_gateway'])) {
387
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
388 388
         }
389 389
         $saved = $invoice->save();
390 390
 
391 391
         // Check for payment notes
392
-        if ( !empty( $data['invoice_note'] ) ) {
393
-            $note               = wp_kses( $data['invoice_note'], array() );
394
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
392
+        if (!empty($data['invoice_note'])) {
393
+            $note               = wp_kses($data['invoice_note'], array());
394
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
395 395
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
396 396
 
397
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
397
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
398 398
         }
399 399
 
400 400
         // Update user address if empty.
401
-        if ( $saved && !empty( $invoice ) ) {
402
-            if ( $user_id = $invoice->get_user_id() ) {
403
-                $user_address = wpinv_get_user_address( $user_id, false );
401
+        if ($saved && !empty($invoice)) {
402
+            if ($user_id = $invoice->get_user_id()) {
403
+                $user_address = wpinv_get_user_address($user_id, false);
404 404
 
405 405
                 if (empty($user_address['first_name'])) {
406
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
407
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
406
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
407
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
408 408
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
409
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
409
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
410 410
                 }
411 411
 
412 412
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
413
-                    update_user_meta( $user_id, '_wpinv_address', $address );
414
-                    update_user_meta( $user_id, '_wpinv_city', $city );
415
-                    update_user_meta( $user_id, '_wpinv_state', $state );
416
-                    update_user_meta( $user_id, '_wpinv_country', $country );
417
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
418
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
413
+                    update_user_meta($user_id, '_wpinv_address', $address);
414
+                    update_user_meta($user_id, '_wpinv_city', $city);
415
+                    update_user_meta($user_id, '_wpinv_state', $state);
416
+                    update_user_meta($user_id, '_wpinv_country', $country);
417
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
418
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
419 419
                 }
420 420
             }
421 421
 
422
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
422
+            do_action('wpinv_invoice_metabox_saved', $invoice);
423 423
         }
424 424
 
425 425
         return $saved;
Please login to merge, or discard this patch.