@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_item_by_id( $id ) { |
|
6 | - return wpinv_get_item_by( 'id', $id ); |
|
5 | +function wpinv_get_item_by_id($id) { |
|
6 | + return wpinv_get_item_by('id', $id); |
|
7 | 7 | } |
8 | 8 | |
9 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
10 | - if( empty( $field ) || empty( $value ) ) { |
|
9 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
10 | + if (empty($field) || empty($value)) { |
|
11 | 11 | return false; |
12 | 12 | } |
13 | 13 | |
14 | 14 | $posts = array(); |
15 | 15 | |
16 | - switch( strtolower( $field ) ) { |
|
16 | + switch (strtolower($field)) { |
|
17 | 17 | case 'id': |
18 | - $item = new WPInv_Item( $value ); |
|
18 | + $item = new WPInv_Item($value); |
|
19 | 19 | |
20 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
20 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
21 | 21 | return $item; |
22 | 22 | } |
23 | 23 | return false; |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | |
27 | 27 | case 'slug': |
28 | 28 | case 'name': |
29 | - $posts = get_posts( array( |
|
29 | + $posts = get_posts(array( |
|
30 | 30 | 'post_type' => 'wpi_item', |
31 | 31 | 'name' => $value, |
32 | 32 | 'posts_per_page' => 1, |
33 | 33 | 'post_status' => 'any' |
34 | - ) ); |
|
34 | + )); |
|
35 | 35 | |
36 | 36 | break; |
37 | 37 | case 'custom_id': |
38 | - if ( empty( $value ) || empty( $type ) ) { |
|
38 | + if (empty($value) || empty($type)) { |
|
39 | 39 | return false; |
40 | 40 | } |
41 | 41 | |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | 'post_status' => 'any', |
56 | 56 | 'orderby' => 'ID', |
57 | 57 | 'order' => 'ASC', |
58 | - 'meta_query' => array( $meta_query ) |
|
58 | + 'meta_query' => array($meta_query) |
|
59 | 59 | ); |
60 | 60 | |
61 | - $posts = get_posts( $args ); |
|
61 | + $posts = get_posts($args); |
|
62 | 62 | |
63 | 63 | break; |
64 | 64 | |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if ( !empty( $posts[0] ) ) { |
|
70 | - $item = new WPInv_Item( $posts[0]->ID ); |
|
69 | + if (!empty($posts[0])) { |
|
70 | + $item = new WPInv_Item($posts[0]->ID); |
|
71 | 71 | |
72 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
72 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
73 | 73 | return $item; |
74 | 74 | } |
75 | 75 | } |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | return false; |
78 | 78 | } |
79 | 79 | |
80 | -function wpinv_get_item( $item = 0 ) { |
|
81 | - if ( is_numeric( $item ) ) { |
|
82 | - $item = get_post( $item ); |
|
83 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
80 | +function wpinv_get_item($item = 0) { |
|
81 | + if (is_numeric($item)) { |
|
82 | + $item = get_post($item); |
|
83 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
84 | 84 | return null; |
85 | 85 | return $item; |
86 | 86 | } |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | |
94 | 94 | $item = get_posts($args); |
95 | 95 | |
96 | - if ( $item ) { |
|
96 | + if ($item) { |
|
97 | 97 | return $item[0]; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
103 | -function wpinv_get_all_items( $args = array() ) { |
|
103 | +function wpinv_get_all_items($args = array()) { |
|
104 | 104 | |
105 | - $args = wp_parse_args( $args, array( |
|
106 | - 'status' => array( 'publish' ), |
|
107 | - 'limit' => get_option( 'posts_per_page' ), |
|
105 | + $args = wp_parse_args($args, array( |
|
106 | + 'status' => array('publish'), |
|
107 | + 'limit' => get_option('posts_per_page'), |
|
108 | 108 | 'page' => 1, |
109 | 109 | 'exclude' => array(), |
110 | 110 | 'orderby' => 'date', |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | 'meta_query' => array(), |
114 | 114 | 'return' => 'objects', |
115 | 115 | 'paginate' => false, |
116 | - ) ); |
|
116 | + )); |
|
117 | 117 | |
118 | 118 | $wp_query_args = array( |
119 | 119 | 'post_type' => 'wpi_item', |
@@ -123,26 +123,26 @@ discard block |
||
123 | 123 | 'fields' => 'ids', |
124 | 124 | 'orderby' => $args['orderby'], |
125 | 125 | 'order' => $args['order'], |
126 | - 'paged' => absint( $args['page'] ), |
|
126 | + 'paged' => absint($args['page']), |
|
127 | 127 | ); |
128 | 128 | |
129 | - if ( ! empty( $args['exclude'] ) ) { |
|
130 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
129 | + if (!empty($args['exclude'])) { |
|
130 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( ! $args['paginate' ] ) { |
|
133 | + if (!$args['paginate']) { |
|
134 | 134 | $wp_query_args['no_found_rows'] = true; |
135 | 135 | } |
136 | 136 | |
137 | - if ( ! empty( $args['search'] ) ) { |
|
137 | + if (!empty($args['search'])) { |
|
138 | 138 | $wp_query_args['s'] = $args['search']; |
139 | 139 | } |
140 | 140 | |
141 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
142 | - $types = wpinv_parse_list( $args['type'] ); |
|
141 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
142 | + $types = wpinv_parse_list($args['type']); |
|
143 | 143 | $wp_query_args['meta_query'][] = array( |
144 | 144 | 'key' => '_wpinv_type', |
145 | - 'value' => implode( ',', $types ), |
|
145 | + 'value' => implode(',', $types), |
|
146 | 146 | 'compare' => 'IN', |
147 | 147 | ); |
148 | 148 | } |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
151 | 151 | |
152 | 152 | // Get results. |
153 | - $items = new WP_Query( $wp_query_args ); |
|
153 | + $items = new WP_Query($wp_query_args); |
|
154 | 154 | |
155 | - if ( 'objects' === $args['return'] ) { |
|
156 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
157 | - } elseif ( 'self' === $args['return'] ) { |
|
155 | + if ('objects' === $args['return']) { |
|
156 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
157 | + } elseif ('self' === $args['return']) { |
|
158 | 158 | return $items; |
159 | 159 | } else { |
160 | 160 | $return = $items->posts; |
161 | 161 | } |
162 | 162 | |
163 | - if ( $args['paginate' ] ) { |
|
163 | + if ($args['paginate']) { |
|
164 | 164 | return (object) array( |
165 | 165 | 'items' => $return, |
166 | 166 | 'total' => $items->found_posts, |
@@ -172,143 +172,143 @@ discard block |
||
172 | 172 | |
173 | 173 | } |
174 | 174 | |
175 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
176 | - if( empty( $item_id ) ) { |
|
175 | +function wpinv_is_free_item($item_id = 0) { |
|
176 | + if (empty($item_id)) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | - $item = new WPInv_Item( $item_id ); |
|
180 | + $item = new WPInv_Item($item_id); |
|
181 | 181 | |
182 | 182 | return $item->is_free(); |
183 | 183 | } |
184 | 184 | |
185 | -function wpinv_item_is_editable( $item = 0 ) { |
|
186 | - if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) { |
|
185 | +function wpinv_item_is_editable($item = 0) { |
|
186 | + if (!empty($item) && is_a($item, 'WP_Post')) { |
|
187 | 187 | $item = $item->ID; |
188 | 188 | } |
189 | 189 | |
190 | - if ( empty( $item ) ) { |
|
190 | + if (empty($item)) { |
|
191 | 191 | return true; |
192 | 192 | } |
193 | 193 | |
194 | - $item = new WPInv_Item( $item ); |
|
194 | + $item = new WPInv_Item($item); |
|
195 | 195 | |
196 | 196 | return (bool) $item->is_editable(); |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
200 | - if( empty( $item_id ) ) { |
|
199 | +function wpinv_get_item_price($item_id = 0) { |
|
200 | + if (empty($item_id)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - $item = new WPInv_Item( $item_id ); |
|
204 | + $item = new WPInv_Item($item_id); |
|
205 | 205 | |
206 | 206 | return $item->get_price(); |
207 | 207 | } |
208 | 208 | |
209 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
210 | - if( empty( $item_id ) ) { |
|
209 | +function wpinv_is_recurring_item($item_id = 0) { |
|
210 | + if (empty($item_id)) { |
|
211 | 211 | return false; |
212 | 212 | } |
213 | 213 | |
214 | - $item = new WPInv_Item( $item_id ); |
|
214 | + $item = new WPInv_Item($item_id); |
|
215 | 215 | |
216 | 216 | return $item->is_recurring(); |
217 | 217 | } |
218 | 218 | |
219 | -function wpinv_item_price( $item_id = 0 ) { |
|
220 | - if( empty( $item_id ) ) { |
|
219 | +function wpinv_item_price($item_id = 0) { |
|
220 | + if (empty($item_id)) { |
|
221 | 221 | return false; |
222 | 222 | } |
223 | 223 | |
224 | - $price = wpinv_get_item_price( $item_id ); |
|
225 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
224 | + $price = wpinv_get_item_price($item_id); |
|
225 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
226 | 226 | |
227 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
227 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
228 | 228 | } |
229 | 229 | |
230 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
231 | - if ( empty( $item_id ) ) { |
|
230 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
231 | + if (empty($item_id)) { |
|
232 | 232 | $item_id = get_the_ID(); |
233 | 233 | } |
234 | 234 | |
235 | - $price = wpinv_item_price( $item_id ); |
|
235 | + $price = wpinv_item_price($item_id); |
|
236 | 236 | |
237 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
237 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
238 | 238 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
239 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
239 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
240 | 240 | |
241 | - if ( $echo ) { |
|
241 | + if ($echo) { |
|
242 | 242 | echo $formatted_price; |
243 | 243 | } else { |
244 | 244 | return $formatted_price; |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
249 | - if ( is_null( $amount_override ) ) { |
|
250 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
248 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
249 | + if (is_null($amount_override)) { |
|
250 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
251 | 251 | } else { |
252 | 252 | $original_price = $amount_override; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $price = $original_price; |
256 | 256 | |
257 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
257 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
261 | - if( empty( $item_id ) ) { |
|
260 | +function wpinv_item_custom_singular_name($item_id) { |
|
261 | + if (empty($item_id)) { |
|
262 | 262 | return false; |
263 | 263 | } |
264 | 264 | |
265 | - $item = new WPInv_Item( $item_id ); |
|
265 | + $item = new WPInv_Item($item_id); |
|
266 | 266 | |
267 | 267 | return $item->get_custom_singular_name(); |
268 | 268 | } |
269 | 269 | |
270 | 270 | function wpinv_get_item_types() { |
271 | 271 | $item_types = array( |
272 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
273 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
272 | + 'custom' => __('Standard', 'invoicing'), |
|
273 | + 'fee' => __('Fee', 'invoicing'), |
|
274 | 274 | ); |
275 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
275 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | function wpinv_item_types() { |
279 | 279 | $item_types = wpinv_get_item_types(); |
280 | 280 | |
281 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
281 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
282 | 282 | } |
283 | 283 | |
284 | -function wpinv_get_item_type( $item_id ) { |
|
285 | - if( empty( $item_id ) ) { |
|
284 | +function wpinv_get_item_type($item_id) { |
|
285 | + if (empty($item_id)) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | 290 | |
291 | 291 | return $item->get_type(); |
292 | 292 | } |
293 | 293 | |
294 | -function wpinv_item_type( $item_id ) { |
|
294 | +function wpinv_item_type($item_id) { |
|
295 | 295 | $item_types = wpinv_get_item_types(); |
296 | 296 | |
297 | - $item_type = wpinv_get_item_type( $item_id ); |
|
297 | + $item_type = wpinv_get_item_type($item_id); |
|
298 | 298 | |
299 | - if ( empty( $item_type ) ) { |
|
299 | + if (empty($item_type)) { |
|
300 | 300 | $item_type = '-'; |
301 | 301 | } |
302 | 302 | |
303 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
303 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
304 | 304 | |
305 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
305 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
308 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
309 | 309 | global $wpinv_logs; |
310 | 310 | |
311 | - if ( empty( $wpinv_logs ) ) { |
|
311 | + if (empty($wpinv_logs)) { |
|
312 | 312 | return false; |
313 | 313 | } |
314 | 314 | |
@@ -317,278 +317,278 @@ discard block |
||
317 | 317 | 'log_type' => 'wpi_item' |
318 | 318 | ); |
319 | 319 | |
320 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
320 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
321 | 321 | |
322 | 322 | $log_meta = array( |
323 | 323 | 'user_info' => $user_info, |
324 | 324 | 'user_id' => $user_id, |
325 | - 'file_id' => (int)$file_id, |
|
325 | + 'file_id' => (int) $file_id, |
|
326 | 326 | 'ip' => $ip, |
327 | 327 | 'invoice_id'=> $invoice_id, |
328 | 328 | ); |
329 | 329 | |
330 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
330 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
331 | 331 | } |
332 | 332 | |
333 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
334 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
333 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
334 | + if ('wpi_item' !== get_post_type($item_id)) |
|
335 | 335 | return; |
336 | 336 | |
337 | 337 | global $wpinv_logs; |
338 | 338 | |
339 | - if ( empty( $wpinv_logs ) ) { |
|
339 | + if (empty($wpinv_logs)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | 343 | // Remove all log entries related to this item |
344 | - $wpinv_logs->delete_logs( $item_id ); |
|
344 | + $wpinv_logs->delete_logs($item_id); |
|
345 | 345 | } |
346 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
346 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
347 | 347 | |
348 | -function wpinv_get_random_item( $post_ids = true ) { |
|
349 | - wpinv_get_random_items( 1, $post_ids ); |
|
348 | +function wpinv_get_random_item($post_ids = true) { |
|
349 | + wpinv_get_random_items(1, $post_ids); |
|
350 | 350 | } |
351 | 351 | |
352 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
353 | - if ( $post_ids ) { |
|
354 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
352 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
353 | + if ($post_ids) { |
|
354 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
355 | 355 | } else { |
356 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
356 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
357 | 357 | } |
358 | 358 | |
359 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
359 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
360 | 360 | |
361 | - return get_posts( $args ); |
|
361 | + return get_posts($args); |
|
362 | 362 | } |
363 | 363 | |
364 | -function wpinv_get_item_token( $url = '' ) { |
|
364 | +function wpinv_get_item_token($url = '') { |
|
365 | 365 | $args = array(); |
366 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
367 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
366 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
367 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
368 | 368 | |
369 | - $parts = parse_url( $url ); |
|
369 | + $parts = parse_url($url); |
|
370 | 370 | $options = array(); |
371 | 371 | |
372 | - if ( isset( $parts['query'] ) ) { |
|
373 | - wp_parse_str( $parts['query'], $query_args ); |
|
372 | + if (isset($parts['query'])) { |
|
373 | + wp_parse_str($parts['query'], $query_args); |
|
374 | 374 | |
375 | - if ( ! empty( $query_args['o'] ) ) { |
|
376 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
375 | + if (!empty($query_args['o'])) { |
|
376 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
377 | 377 | |
378 | - if ( in_array( 'ip', $options ) ) { |
|
378 | + if (in_array('ip', $options)) { |
|
379 | 379 | $args['ip'] = wpinv_get_ip(); |
380 | 380 | } |
381 | 381 | |
382 | - if ( in_array( 'ua', $options ) ) { |
|
382 | + if (in_array('ua', $options)) { |
|
383 | 383 | $ua = wpinv_get_user_agent(); |
384 | - $args['user_agent'] = rawurlencode( $ua ); |
|
384 | + $args['user_agent'] = rawurlencode($ua); |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
389 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
390 | 390 | |
391 | 391 | $args['secret'] = $secret; |
392 | 392 | $args['token'] = false; |
393 | 393 | |
394 | - $url = add_query_arg( $args, $url ); |
|
395 | - $parts = parse_url( $url ); |
|
394 | + $url = add_query_arg($args, $url); |
|
395 | + $parts = parse_url($url); |
|
396 | 396 | |
397 | - if ( ! isset( $parts['path'] ) ) { |
|
397 | + if (!isset($parts['path'])) { |
|
398 | 398 | $parts['path'] = ''; |
399 | 399 | } |
400 | 400 | |
401 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
401 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
402 | 402 | |
403 | 403 | return $token; |
404 | 404 | } |
405 | 405 | |
406 | -function wpinv_validate_url_token( $url = '' ) { |
|
406 | +function wpinv_validate_url_token($url = '') { |
|
407 | 407 | $ret = false; |
408 | - $parts = parse_url( $url ); |
|
408 | + $parts = parse_url($url); |
|
409 | 409 | |
410 | - if ( isset( $parts['query'] ) ) { |
|
411 | - wp_parse_str( $parts['query'], $query_args ); |
|
410 | + if (isset($parts['query'])) { |
|
411 | + wp_parse_str($parts['query'], $query_args); |
|
412 | 412 | |
413 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
413 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
414 | 414 | 'item', |
415 | 415 | 'ttl', |
416 | 416 | 'token' |
417 | - ) ); |
|
417 | + )); |
|
418 | 418 | |
419 | 419 | $remove = array(); |
420 | 420 | |
421 | - foreach( $query_args as $key => $value ) { |
|
422 | - if( false === in_array( $key, $allowed ) ) { |
|
421 | + foreach ($query_args as $key => $value) { |
|
422 | + if (false === in_array($key, $allowed)) { |
|
423 | 423 | $remove[] = $key; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - if( ! empty( $remove ) ) { |
|
428 | - $url = remove_query_arg( $remove, $url ); |
|
427 | + if (!empty($remove)) { |
|
428 | + $url = remove_query_arg($remove, $url); |
|
429 | 429 | } |
430 | 430 | |
431 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
432 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
431 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
432 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
433 | 433 | } |
434 | 434 | |
435 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
435 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
436 | 436 | $ret = true; |
437 | 437 | } |
438 | 438 | |
439 | 439 | } |
440 | 440 | |
441 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
441 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
444 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
445 | 445 | $cart_items = wpinv_get_cart_contents(); |
446 | 446 | |
447 | 447 | $ret = false; |
448 | 448 | |
449 | - if ( is_array( $cart_items ) ) { |
|
450 | - foreach ( $cart_items as $item ) { |
|
451 | - if ( $item['id'] == $item_id ) { |
|
449 | + if (is_array($cart_items)) { |
|
450 | + foreach ($cart_items as $item) { |
|
451 | + if ($item['id'] == $item_id) { |
|
452 | 452 | $ret = true; |
453 | 453 | break; |
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
458 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
458 | + return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
459 | 459 | } |
460 | 460 | |
461 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
461 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
462 | 462 | $tax = 0; |
463 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
464 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
465 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
463 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
464 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
465 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
466 | 466 | |
467 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
467 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
468 | 468 | } |
469 | 469 | |
470 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
470 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_cart_item_price( $item, $currency = '' ) { |
|
473 | +function wpinv_cart_item_price($item, $currency = '') { |
|
474 | 474 | |
475 | - if( empty( $currency ) ) { |
|
475 | + if (empty($currency)) { |
|
476 | 476 | $currency = wpinv_get_currency(); |
477 | 477 | } |
478 | 478 | |
479 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
480 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
481 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
479 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
480 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
481 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
482 | 482 | |
483 | - if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
484 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
483 | + if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
484 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
485 | 485 | $price += $tax; |
486 | 486 | } |
487 | 487 | |
488 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
488 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
489 | 489 | $price -= $tax; |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - $price = wpinv_price( wpinv_format_amount( $price ), $currency ); |
|
493 | + $price = wpinv_price(wpinv_format_amount($price), $currency); |
|
494 | 494 | |
495 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
495 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
496 | 496 | } |
497 | 497 | |
498 | -function wpinv_cart_item_subtotal( $item, $currency = '' ) { |
|
498 | +function wpinv_cart_item_subtotal($item, $currency = '') { |
|
499 | 499 | |
500 | - if( empty( $currency ) ) { |
|
500 | + if (empty($currency)) { |
|
501 | 501 | $currency = wpinv_get_currency(); |
502 | 502 | } |
503 | 503 | |
504 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
505 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ), $currency ); |
|
504 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
505 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal), $currency); |
|
506 | 506 | |
507 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
507 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
508 | 508 | } |
509 | 509 | |
510 | -function wpinv_cart_item_tax( $item, $currency = '' ) { |
|
510 | +function wpinv_cart_item_tax($item, $currency = '') { |
|
511 | 511 | $tax = ''; |
512 | 512 | $tax_rate = ''; |
513 | 513 | |
514 | - if( empty( $currency ) ) { |
|
514 | + if (empty($currency)) { |
|
515 | 515 | $currency = wpinv_get_currency(); |
516 | 516 | } |
517 | 517 | |
518 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
519 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency ); |
|
520 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
521 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
518 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
519 | + $tax = wpinv_price(wpinv_format_amount($item['tax']), $currency); |
|
520 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
521 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
522 | 522 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
523 | 523 | } |
524 | 524 | |
525 | - $tax = $tax . $tax_rate; |
|
525 | + $tax = $tax . $tax_rate; |
|
526 | 526 | |
527 | - if ( $tax === '' ) { |
|
527 | + if ($tax === '') { |
|
528 | 528 | $tax = 0; // Zero tax |
529 | 529 | } |
530 | 530 | |
531 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
531 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
532 | 532 | } |
533 | 533 | |
534 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
534 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
535 | 535 | $price = 0; |
536 | 536 | |
537 | 537 | // Set custom price |
538 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
538 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
539 | 539 | $price = $cart_item['custom_price']; |
540 | 540 | } else { |
541 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
541 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
542 | 542 | |
543 | - if ( $variable_prices ) { |
|
544 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
543 | + if ($variable_prices) { |
|
544 | + $prices = wpinv_get_variable_prices($item_id); |
|
545 | 545 | |
546 | - if ( $prices ) { |
|
547 | - if( ! empty( $options ) ) { |
|
548 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
546 | + if ($prices) { |
|
547 | + if (!empty($options)) { |
|
548 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
549 | 549 | } else { |
550 | 550 | $price = false; |
551 | 551 | } |
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | - if( ! $variable_prices || false === $price ) { |
|
556 | - if($cart_item['item_price'] > 0){ |
|
555 | + if (!$variable_prices || false === $price) { |
|
556 | + if ($cart_item['item_price'] > 0) { |
|
557 | 557 | $price = $cart_item['item_price']; |
558 | 558 | } else { |
559 | 559 | // Get the standard Item price if not using variable prices |
560 | - $price = wpinv_get_item_price( $item_id ); |
|
560 | + $price = wpinv_get_item_price($item_id); |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 | } |
564 | 564 | |
565 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
566 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
565 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
566 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
567 | 567 | } |
568 | 568 | |
569 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
569 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
570 | 570 | } |
571 | 571 | |
572 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
573 | - if( isset( $item['item_number'] ) ) { |
|
574 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
572 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
573 | + if (isset($item['item_number'])) { |
|
574 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
575 | 575 | } else { |
576 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
576 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
577 | 577 | } |
578 | 578 | return $price_id; |
579 | 579 | } |
580 | 580 | |
581 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
582 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
583 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
584 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
585 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
581 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
582 | + $price_id = (int) wpinv_get_cart_item_price_id($item); |
|
583 | + $prices = wpinv_get_variable_prices($item['id']); |
|
584 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
585 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
586 | 586 | } |
587 | 587 | |
588 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
589 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
588 | +function wpinv_get_cart_item_name($item = array()) { |
|
589 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
590 | 590 | |
591 | - if ( empty( $item_title ) ) { |
|
591 | + if (empty($item_title)) { |
|
592 | 592 | $item_title = $item['id']; |
593 | 593 | } |
594 | 594 | |
@@ -598,23 +598,23 @@ discard block |
||
598 | 598 | } |
599 | 599 | */ |
600 | 600 | |
601 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
601 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
602 | 602 | } |
603 | 603 | |
604 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
604 | +function wpinv_has_variable_prices($item_id = 0) { |
|
605 | 605 | return false; |
606 | 606 | } |
607 | 607 | |
608 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
608 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
609 | 609 | $cart_items = wpinv_get_cart_contents(); |
610 | 610 | |
611 | - if ( !is_array( $cart_items ) ) { |
|
611 | + if (!is_array($cart_items)) { |
|
612 | 612 | return false; // Empty cart |
613 | 613 | } else { |
614 | - foreach ( $cart_items as $position => $item ) { |
|
615 | - if ( $item['id'] == $item_id ) { |
|
616 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
617 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
614 | + foreach ($cart_items as $position => $item) { |
|
615 | + if ($item['id'] == $item_id) { |
|
616 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
617 | + if ((int) $options['price_id'] == (int) $item['options']['price_id']) { |
|
618 | 618 | return $position; |
619 | 619 | } |
620 | 620 | } else { |
@@ -627,80 +627,80 @@ discard block |
||
627 | 627 | return false; // Not found |
628 | 628 | } |
629 | 629 | |
630 | -function wpinv_get_cart_item_quantity( $item ) { |
|
631 | - if ( wpinv_item_quantities_enabled() ) { |
|
632 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
630 | +function wpinv_get_cart_item_quantity($item) { |
|
631 | + if (wpinv_item_quantities_enabled()) { |
|
632 | + $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
633 | 633 | } else { |
634 | 634 | $quantity = 1; |
635 | 635 | } |
636 | 636 | |
637 | - if ( $quantity < 1 ) { |
|
637 | + if ($quantity < 1) { |
|
638 | 638 | $quantity = 1; |
639 | 639 | } |
640 | 640 | |
641 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
641 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
645 | - if ( empty( $item ) ) { |
|
644 | +function wpinv_get_item_suffix($item, $html = true) { |
|
645 | + if (empty($item)) { |
|
646 | 646 | return NULL; |
647 | 647 | } |
648 | 648 | |
649 | - if ( is_int( $item ) ) { |
|
650 | - $item = new WPInv_Item( $item ); |
|
649 | + if (is_int($item)) { |
|
650 | + $item = new WPInv_Item($item); |
|
651 | 651 | } |
652 | 652 | |
653 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
653 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
654 | 654 | return NULL; |
655 | 655 | } |
656 | 656 | |
657 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
657 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
658 | 658 | |
659 | - if ( !$html && $suffix ) { |
|
660 | - $suffix = strip_tags( $suffix ); |
|
659 | + if (!$html && $suffix) { |
|
660 | + $suffix = strip_tags($suffix); |
|
661 | 661 | } |
662 | 662 | |
663 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
663 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
664 | 664 | } |
665 | 665 | |
666 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
667 | - if ( empty( $item ) ) { |
|
666 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
667 | + if (empty($item)) { |
|
668 | 668 | return NULL; |
669 | 669 | } |
670 | 670 | |
671 | - if ( is_int( $item ) ) { |
|
672 | - $item = new WPInv_Item( $item ); |
|
671 | + if (is_int($item)) { |
|
672 | + $item = new WPInv_Item($item); |
|
673 | 673 | } |
674 | 674 | |
675 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
675 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
676 | 676 | return NULL; |
677 | 677 | } |
678 | 678 | |
679 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
679 | + do_action('wpinv_pre_delete_item', $item); |
|
680 | 680 | |
681 | - wp_delete_post( $item->ID, $force_delete ); |
|
681 | + wp_delete_post($item->ID, $force_delete); |
|
682 | 682 | |
683 | - do_action( 'wpinv_post_delete_item', $item ); |
|
683 | + do_action('wpinv_post_delete_item', $item); |
|
684 | 684 | } |
685 | 685 | |
686 | -function wpinv_can_delete_item( $post_id ) { |
|
686 | +function wpinv_can_delete_item($post_id) { |
|
687 | 687 | $return = wpinv_current_user_can_manage_invoicing() ? true : false; |
688 | 688 | |
689 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
689 | + if ($return && wpinv_item_in_use($post_id)) { |
|
690 | 690 | $return = false; // Don't delete item already use in invoices. |
691 | 691 | } |
692 | 692 | |
693 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
693 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | function wpinv_admin_action_delete() { |
697 | 697 | $screen = get_current_screen(); |
698 | 698 | |
699 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
699 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
700 | 700 | $post_ids = array(); |
701 | 701 | |
702 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
703 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
702 | + foreach ($_REQUEST['post'] as $post_id) { |
|
703 | + if (!wpinv_can_delete_item($post_id)) { |
|
704 | 704 | continue; |
705 | 705 | } |
706 | 706 | |
@@ -710,88 +710,88 @@ discard block |
||
710 | 710 | $_REQUEST['post'] = $post_ids; |
711 | 711 | } |
712 | 712 | } |
713 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
714 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
713 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
714 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
715 | 715 | |
716 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
717 | - if ( $post->post_type == 'wpi_item' ) { |
|
718 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
716 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
717 | + if ($post->post_type == 'wpi_item') { |
|
718 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
719 | 719 | return true; |
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
723 | 723 | return $check; |
724 | 724 | } |
725 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
725 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
726 | 726 | |
727 | -function wpinv_item_in_use( $item_id ) { |
|
727 | +function wpinv_item_in_use($item_id) { |
|
728 | 728 | global $wpdb, $wpi_items_in_use; |
729 | 729 | |
730 | - if ( !$item_id > 0 ) { |
|
730 | + if (!$item_id > 0) { |
|
731 | 731 | return false; |
732 | 732 | } |
733 | 733 | |
734 | - if ( !empty( $wpi_items_in_use ) ) { |
|
735 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
734 | + if (!empty($wpi_items_in_use)) { |
|
735 | + if (isset($wpi_items_in_use[$item_id])) { |
|
736 | 736 | return $wpi_items_in_use[$item_id]; |
737 | 737 | } |
738 | 738 | } else { |
739 | 739 | $wpi_items_in_use = array(); |
740 | 740 | } |
741 | 741 | |
742 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
742 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
743 | 743 | |
744 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
745 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
744 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )"; |
|
745 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
746 | 746 | |
747 | 747 | $wpi_items_in_use[$item_id] = $in_use; |
748 | 748 | |
749 | 749 | return $in_use; |
750 | 750 | } |
751 | 751 | |
752 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
752 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
753 | 753 | // Set some defaults |
754 | 754 | $defaults = array( |
755 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
756 | - 'title' => '', // Required. Item title. |
|
757 | - 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
758 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
759 | - 'status' => 'pending', // Optional. pending, publish |
|
760 | - 'custom_name' => '', // Optional. Plural sub title for item. |
|
761 | - 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
762 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
763 | - 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
764 | - 'excerpt' => '', // Optional. Item short description |
|
755 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
756 | + 'title' => '', // Required. Item title. |
|
757 | + 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
758 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
759 | + 'status' => 'pending', // Optional. pending, publish |
|
760 | + 'custom_name' => '', // Optional. Plural sub title for item. |
|
761 | + 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
762 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
763 | + 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
764 | + 'excerpt' => '', // Optional. Item short description |
|
765 | 765 | /* Recurring item fields */ |
766 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
767 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
768 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
769 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
770 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
771 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
772 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
773 | - 'minimum_price' => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing. |
|
774 | - 'dynamic_pricing' => 0, // Optional. Whether or not the item supports dynamic prices. |
|
766 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
767 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
768 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
769 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
770 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
771 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
772 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
773 | + 'minimum_price' => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing. |
|
774 | + 'dynamic_pricing' => 0, // Optional. Whether or not the item supports dynamic prices. |
|
775 | 775 | ); |
776 | 776 | |
777 | - $data = wp_parse_args( $args, $defaults ); |
|
777 | + $data = wp_parse_args($args, $defaults); |
|
778 | 778 | |
779 | - if ( empty( $data['type'] ) ) { |
|
779 | + if (empty($data['type'])) { |
|
780 | 780 | $data['type'] = 'custom'; |
781 | 781 | } |
782 | 782 | |
783 | - if ( !empty( $data['custom_id'] ) ) { |
|
784 | - $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] ); |
|
783 | + if (!empty($data['custom_id'])) { |
|
784 | + $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']); |
|
785 | 785 | } else { |
786 | 786 | $item = NULL; |
787 | 787 | } |
788 | 788 | |
789 | - if ( !empty( $item ) ) { |
|
790 | - if ( $force_update ) { |
|
791 | - if ( empty( $args['ID'] ) ) { |
|
789 | + if (!empty($item)) { |
|
790 | + if ($force_update) { |
|
791 | + if (empty($args['ID'])) { |
|
792 | 792 | $args['ID'] = $item->ID; |
793 | 793 | } |
794 | - return wpinv_update_item( $args, $wp_error ); |
|
794 | + return wpinv_update_item($args, $wp_error); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | return $item; |
@@ -802,21 +802,21 @@ discard block |
||
802 | 802 | $meta['custom_id'] = $data['custom_id']; |
803 | 803 | $meta['custom_singular_name'] = $data['custom_singular_name']; |
804 | 804 | $meta['custom_name'] = $data['custom_name']; |
805 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
806 | - $meta['editable'] = (int)$data['editable']; |
|
805 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
806 | + $meta['editable'] = (int) $data['editable']; |
|
807 | 807 | $meta['vat_rule'] = $data['vat_rule']; |
808 | 808 | $meta['vat_class'] = '_standard'; |
809 | 809 | $meta['dynamic_pricing'] = (int) $data['dynamic_pricing']; |
810 | - $meta['minimum_price'] = wpinv_round_amount( $data['minimum_price'] ); |
|
810 | + $meta['minimum_price'] = wpinv_round_amount($data['minimum_price']); |
|
811 | 811 | |
812 | - if ( !empty( $data['is_recurring'] ) ) { |
|
812 | + if (!empty($data['is_recurring'])) { |
|
813 | 813 | $meta['is_recurring'] = $data['is_recurring']; |
814 | 814 | $meta['recurring_period'] = $data['recurring_period']; |
815 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
816 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
815 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
816 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
817 | 817 | $meta['free_trial'] = $data['free_trial']; |
818 | 818 | $meta['trial_period'] = $data['trial_period']; |
819 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
819 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
820 | 820 | } else { |
821 | 821 | $meta['is_recurring'] = 0; |
822 | 822 | $meta['recurring_period'] = ''; |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | $meta['trial_interval'] = ''; |
828 | 828 | } |
829 | 829 | |
830 | - $post_data = array( |
|
830 | + $post_data = array( |
|
831 | 831 | 'post_title' => $data['title'], |
832 | 832 | 'post_excerpt' => $data['excerpt'], |
833 | 833 | 'post_status' => $data['status'], |
@@ -835,34 +835,34 @@ discard block |
||
835 | 835 | ); |
836 | 836 | |
837 | 837 | $item = new WPInv_Item(); |
838 | - $return = $item->create( $post_data, $wp_error ); |
|
838 | + $return = $item->create($post_data, $wp_error); |
|
839 | 839 | |
840 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
840 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
841 | 841 | return $item; |
842 | 842 | } |
843 | 843 | |
844 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
844 | + if ($wp_error && is_wp_error($return)) { |
|
845 | 845 | return $return; |
846 | 846 | } |
847 | 847 | return 0; |
848 | 848 | } |
849 | 849 | |
850 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
851 | - $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL; |
|
850 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
851 | + $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL; |
|
852 | 852 | |
853 | - if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) { |
|
854 | - if ( $wp_error ) { |
|
855 | - return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) ); |
|
853 | + if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) { |
|
854 | + if ($wp_error) { |
|
855 | + return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing')); |
|
856 | 856 | } |
857 | 857 | return 0; |
858 | 858 | } |
859 | 859 | |
860 | - if ( !empty( $args['custom_id'] ) ) { |
|
861 | - $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) ); |
|
860 | + if (!empty($args['custom_id'])) { |
|
861 | + $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type)); |
|
862 | 862 | |
863 | - if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) { |
|
864 | - if ( $wp_error ) { |
|
865 | - return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) ); |
|
863 | + if (!empty($item_exists) && $item_exists->ID != $args['ID']) { |
|
864 | + if ($wp_error) { |
|
865 | + return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing')); |
|
866 | 866 | } |
867 | 867 | return 0; |
868 | 868 | } |
@@ -889,54 +889,54 @@ discard block |
||
889 | 889 | ); |
890 | 890 | |
891 | 891 | $post_data = array(); |
892 | - if ( isset( $args['title'] ) ) { |
|
892 | + if (isset($args['title'])) { |
|
893 | 893 | $post_data['post_title'] = $args['title']; |
894 | 894 | } |
895 | - if ( isset( $args['excerpt'] ) ) { |
|
895 | + if (isset($args['excerpt'])) { |
|
896 | 896 | $post_data['post_excerpt'] = $args['excerpt']; |
897 | 897 | } |
898 | - if ( isset( $args['status'] ) ) { |
|
898 | + if (isset($args['status'])) { |
|
899 | 899 | $post_data['post_status'] = $args['status']; |
900 | 900 | } |
901 | 901 | |
902 | - foreach ( $meta_fields as $meta_field ) { |
|
903 | - if ( isset( $args[ $meta_field ] ) ) { |
|
904 | - $value = $args[ $meta_field ]; |
|
902 | + foreach ($meta_fields as $meta_field) { |
|
903 | + if (isset($args[$meta_field])) { |
|
904 | + $value = $args[$meta_field]; |
|
905 | 905 | |
906 | - switch ( $meta_field ) { |
|
906 | + switch ($meta_field) { |
|
907 | 907 | case 'price': |
908 | 908 | case 'minimum_price': |
909 | - $value = wpinv_round_amount( $value ); |
|
909 | + $value = wpinv_round_amount($value); |
|
910 | 910 | break; |
911 | 911 | case 'recurring_interval': |
912 | 912 | case 'recurring_limit': |
913 | 913 | case 'trial_interval': |
914 | - $value = absint( $value ); |
|
914 | + $value = absint($value); |
|
915 | 915 | break; |
916 | 916 | case 'editable': |
917 | 917 | $value = (int) $value; |
918 | 918 | break; |
919 | 919 | } |
920 | 920 | |
921 | - $post_data['meta'][ $meta_field ] = $value; |
|
921 | + $post_data['meta'][$meta_field] = $value; |
|
922 | 922 | }; |
923 | 923 | } |
924 | 924 | |
925 | - if ( empty( $post_data ) ) { |
|
926 | - if ( $wp_error ) { |
|
927 | - return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) ); |
|
925 | + if (empty($post_data)) { |
|
926 | + if ($wp_error) { |
|
927 | + return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing')); |
|
928 | 928 | } |
929 | 929 | return 0; |
930 | 930 | } |
931 | 931 | $post_data['ID'] = $args['ID']; |
932 | 932 | |
933 | - $return = $item->update( $post_data, $wp_error ); |
|
933 | + $return = $item->update($post_data, $wp_error); |
|
934 | 934 | |
935 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
935 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
936 | 936 | return $item; |
937 | 937 | } |
938 | 938 | |
939 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
939 | + if ($wp_error && is_wp_error($return)) { |
|
940 | 940 | return $return; |
941 | 941 | } |
942 | 942 | return 0; |
@@ -7,201 +7,201 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $is_checkout = is_page( wpinv_get_option( 'checkout_page' ) ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $is_checkout = is_page(wpinv_get_option('checkout_page')); |
|
20 | 20 | |
21 | - if ( !$is_object_set ) { |
|
22 | - unset( $wp_query->queried_object ); |
|
21 | + if (!$is_object_set) { |
|
22 | + unset($wp_query->queried_object); |
|
23 | 23 | } |
24 | 24 | |
25 | - if ( !$is_object_id_set ) { |
|
26 | - unset( $wp_query->queried_object_id ); |
|
25 | + if (!$is_object_id_set) { |
|
26 | + unset($wp_query->queried_object_id); |
|
27 | 27 | } |
28 | 28 | |
29 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
29 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function wpinv_can_checkout() { |
33 | 33 | $can_checkout = true; // Always true for now |
34 | 34 | |
35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
35 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function wpinv_get_success_page_uri() { |
39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
40 | - $page_id = absint( $page_id ); |
|
39 | + $page_id = wpinv_get_option('success_page', 0); |
|
40 | + $page_id = absint($page_id); |
|
41 | 41 | |
42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
42 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function wpinv_get_history_page_uri() { |
46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
47 | - $page_id = absint( $page_id ); |
|
46 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
47 | + $page_id = absint($page_id); |
|
48 | 48 | |
49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
49 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function wpinv_is_success_page() { |
53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
53 | + $is_success_page = wpinv_get_option('success_page', false); |
|
54 | + $is_success_page = isset($is_success_page) ? is_page($is_success_page) : false; |
|
55 | 55 | |
56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
56 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_invoice_history_page() { |
60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
61 | - $ret = $ret ? is_page( $ret ) : false; |
|
62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
60 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
61 | + $ret = $ret ? is_page($ret) : false; |
|
62 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | function wpinv_is_subscriptions_history_page() { |
66 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
67 | - $ret = $ret ? is_page( $ret ) : false; |
|
68 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
66 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
67 | + $ret = $ret ? is_page($ret) : false; |
|
68 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
69 | 69 | } |
70 | 70 | |
71 | -function wpinv_send_to_success_page( $args = null ) { |
|
71 | +function wpinv_send_to_success_page($args = null) { |
|
72 | 72 | $redirect = wpinv_get_success_page_uri(); |
73 | 73 | |
74 | - if ( !empty( $args ) ) { |
|
74 | + if (!empty($args)) { |
|
75 | 75 | // Check for backward compatibility |
76 | - if ( is_string( $args ) ) |
|
77 | - $args = str_replace( '?', '', $args ); |
|
76 | + if (is_string($args)) |
|
77 | + $args = str_replace('?', '', $args); |
|
78 | 78 | |
79 | - $args = wp_parse_args( $args ); |
|
79 | + $args = wp_parse_args($args); |
|
80 | 80 | |
81 | - $redirect = add_query_arg( $args, $redirect ); |
|
81 | + $redirect = add_query_arg($args, $redirect); |
|
82 | 82 | } |
83 | 83 | |
84 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
84 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
85 | 85 | |
86 | - $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args ); |
|
87 | - wp_redirect( $redirect ); |
|
86 | + $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args); |
|
87 | + wp_redirect($redirect); |
|
88 | 88 | exit; |
89 | 89 | } |
90 | 90 | |
91 | -function wpinv_send_to_failed_page( $args = null ) { |
|
91 | +function wpinv_send_to_failed_page($args = null) { |
|
92 | 92 | $redirect = wpinv_get_failed_transaction_uri(); |
93 | 93 | |
94 | - if ( !empty( $args ) ) { |
|
94 | + if (!empty($args)) { |
|
95 | 95 | // Check for backward compatibility |
96 | - if ( is_string( $args ) ) |
|
97 | - $args = str_replace( '?', '', $args ); |
|
96 | + if (is_string($args)) |
|
97 | + $args = str_replace('?', '', $args); |
|
98 | 98 | |
99 | - $args = wp_parse_args( $args ); |
|
99 | + $args = wp_parse_args($args); |
|
100 | 100 | |
101 | - $redirect = add_query_arg( $args, $redirect ); |
|
101 | + $redirect = add_query_arg($args, $redirect); |
|
102 | 102 | } |
103 | 103 | |
104 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
104 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
105 | 105 | |
106 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
107 | - wp_redirect( $redirect ); |
|
106 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
107 | + wp_redirect($redirect); |
|
108 | 108 | exit; |
109 | 109 | } |
110 | 110 | |
111 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
111 | +function wpinv_get_checkout_uri($args = array()) { |
|
112 | + $uri = wpinv_get_option('checkout_page', false); |
|
113 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
115 | + if (!empty($args)) { |
|
116 | 116 | // Check for backward compatibility |
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
117 | + if (is_string($args)) |
|
118 | + $args = str_replace('?', '', $args); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args($args); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
122 | + $uri = add_query_arg($args, $uri); |
|
123 | 123 | } |
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
129 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
130 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
131 | 131 | } |
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_send_back_to_checkout( $args = array() ) { |
|
136 | +function wpinv_send_back_to_checkout($args = array()) { |
|
137 | 137 | $redirect = wpinv_get_checkout_uri(); |
138 | 138 | |
139 | - if ( ! empty( $args ) ) { |
|
139 | + if (!empty($args)) { |
|
140 | 140 | // Check for backward compatibility |
141 | - if ( is_string( $args ) ) |
|
142 | - $args = str_replace( '?', '', $args ); |
|
141 | + if (is_string($args)) |
|
142 | + $args = str_replace('?', '', $args); |
|
143 | 143 | |
144 | - $args = wp_parse_args( $args ); |
|
144 | + $args = wp_parse_args($args); |
|
145 | 145 | |
146 | - $redirect = add_query_arg( $args, $redirect ); |
|
146 | + $redirect = add_query_arg($args, $redirect); |
|
147 | 147 | } |
148 | 148 | |
149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
149 | + wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args)); |
|
150 | 150 | exit; |
151 | 151 | } |
152 | 152 | |
153 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
155 | - $success_page = get_permalink( $success_page ); |
|
153 | +function wpinv_get_success_page_url($query_string = null) { |
|
154 | + $success_page = wpinv_get_option('success_page', 0); |
|
155 | + $success_page = get_permalink($success_page); |
|
156 | 156 | |
157 | - if ( $query_string ) |
|
157 | + if ($query_string) |
|
158 | 158 | $success_page .= $query_string; |
159 | 159 | |
160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
160 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
161 | 161 | } |
162 | 162 | |
163 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
163 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
164 | + $uri = wpinv_get_option('failure_page', ''); |
|
165 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
166 | 166 | |
167 | - if ( $extras ) |
|
167 | + if ($extras) |
|
168 | 168 | $uri .= $extras; |
169 | 169 | |
170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
170 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_is_failed_transaction_page() { |
174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
174 | + $ret = wpinv_get_option('failure_page', false); |
|
175 | + $ret = isset($ret) ? is_page($ret) : false; |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
177 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_transaction_query( $type = 'start' ) { |
|
180 | +function wpinv_transaction_query($type = 'start') { |
|
181 | 181 | global $wpdb; |
182 | 182 | |
183 | 183 | $wpdb->hide_errors(); |
184 | 184 | |
185 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
186 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
185 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
186 | + define('WPINV_USE_TRANSACTIONS', true); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
190 | - switch ( $type ) { |
|
189 | + if (WPINV_USE_TRANSACTIONS) { |
|
190 | + switch ($type) { |
|
191 | 191 | case 'commit' : |
192 | - $wpdb->query( 'COMMIT' ); |
|
192 | + $wpdb->query('COMMIT'); |
|
193 | 193 | break; |
194 | 194 | case 'rollback' : |
195 | - $wpdb->query( 'ROLLBACK' ); |
|
195 | + $wpdb->query('ROLLBACK'); |
|
196 | 196 | break; |
197 | 197 | default : |
198 | - $wpdb->query( 'START TRANSACTION' ); |
|
198 | + $wpdb->query('START TRANSACTION'); |
|
199 | 199 | break; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | -function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) { |
|
204 | +function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) { |
|
205 | 205 | $default_args = array( |
206 | 206 | 'status' => '', |
207 | 207 | 'user_id' => null, |
@@ -212,66 +212,66 @@ discard block |
||
212 | 212 | 'post_type' => 'wpi_invoice' |
213 | 213 | ); |
214 | 214 | |
215 | - $args = wp_parse_args( $args, $default_args ); |
|
215 | + $args = wp_parse_args($args, $default_args); |
|
216 | 216 | $invoice_data = array(); |
217 | 217 | |
218 | - if ( $args['invoice_id'] > 0 ) { |
|
219 | - $updating = true; |
|
218 | + if ($args['invoice_id'] > 0) { |
|
219 | + $updating = true; |
|
220 | 220 | $invoice_data['post_type'] = $args['post_type']; |
221 | 221 | $invoice_data['ID'] = $args['invoice_id']; |
222 | 222 | } else { |
223 | 223 | $updating = false; |
224 | 224 | $invoice_data['post_type'] = $args['post_type']; |
225 | - $invoice_data['post_status'] = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' ); |
|
225 | + $invoice_data['post_status'] = apply_filters('wpinv_default_invoice_status', 'wpi-pending'); |
|
226 | 226 | $invoice_data['ping_status'] = 'closed'; |
227 | - $invoice_data['post_author'] = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); |
|
228 | - $invoice_data['post_title'] = wpinv_format_invoice_number( '0' ); |
|
229 | - $invoice_data['post_parent'] = absint( $args['parent'] ); |
|
230 | - if ( !empty( $args['created_date'] ) ) { |
|
227 | + $invoice_data['post_author'] = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id(); |
|
228 | + $invoice_data['post_title'] = wpinv_format_invoice_number('0'); |
|
229 | + $invoice_data['post_parent'] = absint($args['parent']); |
|
230 | + if (!empty($args['created_date'])) { |
|
231 | 231 | $invoice_data['post_date'] = $args['created_date']; |
232 | - $invoice_data['post_date_gmt'] = get_gmt_from_date( $args['created_date'] ); |
|
232 | + $invoice_data['post_date_gmt'] = get_gmt_from_date($args['created_date']); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - if ( $args['status'] ) { |
|
237 | - if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) && 'wpi_invoice' === $invoice_data['post_type'] ) { |
|
238 | - return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) ); |
|
236 | + if ($args['status']) { |
|
237 | + if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses())) && 'wpi_invoice' === $invoice_data['post_type']) { |
|
238 | + return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status'])); |
|
239 | 239 | } |
240 | - $invoice_data['post_status'] = $args['status']; |
|
240 | + $invoice_data['post_status'] = $args['status']; |
|
241 | 241 | } |
242 | 242 | |
243 | - if ( ! is_null( $args['user_note'] ) ) { |
|
244 | - $invoice_data['post_excerpt'] = $args['user_note']; |
|
243 | + if (!is_null($args['user_note'])) { |
|
244 | + $invoice_data['post_excerpt'] = $args['user_note']; |
|
245 | 245 | } |
246 | 246 | |
247 | - if ( $updating ) { |
|
248 | - $invoice_id = wp_update_post( $invoice_data, true ); |
|
247 | + if ($updating) { |
|
248 | + $invoice_id = wp_update_post($invoice_data, true); |
|
249 | 249 | } else { |
250 | - $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true ); |
|
250 | + $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true); |
|
251 | 251 | } |
252 | 252 | |
253 | - if ( is_wp_error( $invoice_id ) ) { |
|
253 | + if (is_wp_error($invoice_id)) { |
|
254 | 254 | return $wp_error ? $invoice_id : 0; |
255 | 255 | } |
256 | 256 | |
257 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
258 | - |
|
259 | - if ( !$updating ) { |
|
260 | - update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) ); |
|
261 | - update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() ); |
|
262 | - update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) ); |
|
263 | - update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() ); |
|
264 | - update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() ); |
|
265 | - update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) ); |
|
257 | + $invoice = wpinv_get_invoice($invoice_id); |
|
258 | + |
|
259 | + if (!$updating) { |
|
260 | + update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_'))); |
|
261 | + update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency()); |
|
262 | + update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax')); |
|
263 | + update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip()); |
|
264 | + update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent()); |
|
265 | + update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via'])); |
|
266 | 266 | |
267 | 267 | // Add invoice note |
268 | - if ( ! $invoice->is_quote() ) { |
|
269 | - $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
|
268 | + if (!$invoice->is_quote()) { |
|
269 | + $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status))); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | } |
273 | 273 | |
274 | - update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION ); |
|
274 | + update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION); |
|
275 | 275 | |
276 | 276 | return $invoice; |
277 | 277 | } |
@@ -279,184 +279,184 @@ discard block |
||
279 | 279 | function wpinv_get_prefix() { |
280 | 280 | $invoice_prefix = 'INV-'; |
281 | 281 | |
282 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
282 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | function wpinv_get_business_logo() { |
286 | - $business_logo = wpinv_get_option( 'logo' ); |
|
287 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
286 | + $business_logo = wpinv_get_option('logo'); |
|
287 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | function wpinv_get_business_name() { |
291 | 291 | $business_name = wpinv_get_option('store_name'); |
292 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
292 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | function wpinv_get_blogname() { |
296 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
296 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | function wpinv_get_admin_email() { |
300 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
301 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
300 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
301 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | function wpinv_get_business_website() { |
305 | - $business_website = home_url( '/' ); |
|
306 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
305 | + $business_website = home_url('/'); |
|
306 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
307 | 307 | } |
308 | 308 | |
309 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
309 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
310 | 310 | $terms_text = ''; |
311 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
311 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | function wpinv_get_business_footer() { |
315 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
316 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
317 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
315 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
316 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
317 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | function wpinv_checkout_required_fields() { |
321 | 321 | $required_fields = array(); |
322 | 322 | |
323 | 323 | // Let payment gateways and other extensions determine if address fields should be required |
324 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
324 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
325 | 325 | |
326 | - if ( $require_billing_details ) { |
|
327 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
326 | + if ($require_billing_details) { |
|
327 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
328 | 328 | $required_fields['first_name'] = array( |
329 | 329 | 'error_id' => 'invalid_first_name', |
330 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
330 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
331 | 331 | ); |
332 | 332 | } |
333 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
333 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
334 | 334 | $required_fields['address'] = array( |
335 | 335 | 'error_id' => 'invalid_address', |
336 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
336 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
337 | 337 | ); |
338 | 338 | } |
339 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
339 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
340 | 340 | $required_fields['city'] = array( |
341 | 341 | 'error_id' => 'invalid_city', |
342 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
342 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
343 | 343 | ); |
344 | 344 | } |
345 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
345 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
346 | 346 | $required_fields['state'] = array( |
347 | 347 | 'error_id' => 'invalid_state', |
348 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
348 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
349 | 349 | ); |
350 | 350 | } |
351 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
351 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
352 | 352 | $required_fields['country'] = array( |
353 | 353 | 'error_id' => 'invalid_country', |
354 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
354 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
355 | 355 | ); |
356 | 356 | } |
357 | 357 | } |
358 | 358 | |
359 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
359 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | function wpinv_is_ssl_enforced() { |
363 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
364 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
363 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
364 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
365 | 365 | } |
366 | 366 | |
367 | -function wpinv_user_can_view_invoice( $post ) { |
|
367 | +function wpinv_user_can_view_invoice($post) { |
|
368 | 368 | $allow = false; |
369 | 369 | |
370 | - $post = get_post( $post ); |
|
370 | + $post = get_post($post); |
|
371 | 371 | |
372 | - if ( empty( $post->ID ) ) { |
|
372 | + if (empty($post->ID)) { |
|
373 | 373 | return $allow; |
374 | 374 | } |
375 | 375 | |
376 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
377 | - if ( empty( $invoice->ID ) ) { |
|
376 | + $invoice = wpinv_get_invoice($post->ID); |
|
377 | + if (empty($invoice->ID)) { |
|
378 | 378 | return $allow; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Don't allow trash, draft status |
382 | - if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
383 | - if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->ID ) ) { // Admin user |
|
382 | + if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
383 | + if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->ID)) { // Admin user |
|
384 | 384 | $allow = true; |
385 | 385 | } else { |
386 | - if ( is_user_logged_in() ) { |
|
387 | - if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) { |
|
386 | + if (is_user_logged_in()) { |
|
387 | + if ((int) $invoice->get_user_id() === (int) get_current_user_id()) { |
|
388 | 388 | $allow = true; |
389 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
389 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
390 | 390 | $allow = true; |
391 | 391 | } |
392 | 392 | } else { |
393 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
393 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
394 | 394 | $allow = true; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice ); |
|
400 | + return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | function wpinv_schedule_events() { |
404 | 404 | // hourly, daily and twicedaily |
405 | - if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) { |
|
406 | - wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' ); |
|
405 | + if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) { |
|
406 | + wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily'); |
|
407 | 407 | } |
408 | 408 | } |
409 | -add_action( 'wp', 'wpinv_schedule_events' ); |
|
409 | +add_action('wp', 'wpinv_schedule_events'); |
|
410 | 410 | |
411 | 411 | function wpinv_schedule_event_twicedaily() { |
412 | 412 | wpinv_email_payment_reminders(); |
413 | 413 | } |
414 | -add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' ); |
|
414 | +add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily'); |
|
415 | 415 | |
416 | 416 | function wpinv_require_login_to_checkout() { |
417 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
418 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
417 | + $return = wpinv_get_option('login_to_checkout', false); |
|
418 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_sequential_number_active( $type = '' ) { |
|
422 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
423 | - if ( null !== $check ) { |
|
421 | +function wpinv_sequential_number_active($type = '') { |
|
422 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
423 | + if (null !== $check) { |
|
424 | 424 | return $check; |
425 | 425 | } |
426 | 426 | |
427 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
427 | + return wpinv_get_option('sequential_invoice_number'); |
|
428 | 428 | } |
429 | 429 | |
430 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
430 | +function wpinv_switch_to_locale($locale = NULL) { |
|
431 | 431 | global $invoicing, $wpi_switch_locale; |
432 | 432 | |
433 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
434 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
433 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
434 | + $locale = empty($locale) ? get_locale() : $locale; |
|
435 | 435 | |
436 | - switch_to_locale( $locale ); |
|
436 | + switch_to_locale($locale); |
|
437 | 437 | |
438 | 438 | $wpi_switch_locale = $locale; |
439 | 439 | |
440 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
440 | + add_filter('plugin_locale', 'get_locale'); |
|
441 | 441 | |
442 | 442 | $invoicing->load_textdomain(); |
443 | 443 | |
444 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
444 | + do_action('wpinv_switch_to_locale', $locale); |
|
445 | 445 | } |
446 | 446 | } |
447 | 447 | |
448 | 448 | function wpinv_restore_locale() { |
449 | 449 | global $invoicing, $wpi_switch_locale; |
450 | 450 | |
451 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
451 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
452 | 452 | restore_previous_locale(); |
453 | 453 | |
454 | 454 | $wpi_switch_locale = NULL; |
455 | 455 | |
456 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
456 | + remove_filter('plugin_locale', 'get_locale'); |
|
457 | 457 | |
458 | 458 | $invoicing->load_textdomain(); |
459 | 459 | |
460 | - do_action( 'wpinv_restore_locale' ); |
|
460 | + do_action('wpinv_restore_locale'); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | \ No newline at end of file |
@@ -1,47 +1,47 @@ discard block |
||
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 |
||
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> |
@@ -74,45 +74,45 @@ discard block |
||
74 | 74 | <td class="id"> |
75 | 75 | </td> |
76 | 76 | <td class="title"> |
77 | - <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
|
78 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
77 | + <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]"> |
|
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 wpi_select2', |
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 wpi_select2', |
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,37 +120,37 @@ discard block |
||
120 | 120 | 'show_option_all' => false, |
121 | 121 | 'show_option_none' => false, |
122 | 122 | 'class' => 'gdmbx2-text-medium wpinv-quick-type wpi_select2', |
123 | - ) ); ?> |
|
123 | + )); ?> |
|
124 | 124 | </span> |
125 | 125 | </label> |
126 | 126 | </div> |
127 | 127 | |
128 | 128 | <div class="wp-clearfix"> |
129 | 129 | <?php |
130 | - echo wpinv_html_textarea( array( |
|
130 | + echo wpinv_html_textarea(array( |
|
131 | 131 | 'name' => '_wpinv_quick[excerpt]', |
132 | 132 | 'id' => '_wpinv_quick_excerpt', |
133 | 133 | 'value' => '', |
134 | 134 | 'class' => 'large-text', |
135 | - 'label' => __( 'Item description', 'invoicing' ), |
|
136 | - ) ); |
|
135 | + 'label' => __('Item description', 'invoicing'), |
|
136 | + )); |
|
137 | 137 | ?> |
138 | 138 | </div> |
139 | 139 | |
140 | 140 | <div class="wp-clearfix"> |
141 | 141 | <label class="wpi-item-actions"> |
142 | 142 | <span class="input-text-wrap"> |
143 | - <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
143 | + <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
144 | 144 | </span> |
145 | 145 | </label> |
146 | 146 | </div> |
147 | 147 | </td> |
148 | 148 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
149 | - <?php if ( $item_quantities ) { ?> |
|
149 | + <?php if ($item_quantities) { ?> |
|
150 | 150 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
151 | 151 | <?php } ?> |
152 | 152 | <td class="total"></td> |
153 | - <?php if ( $use_taxes ) { ?> |
|
153 | + <?php if ($use_taxes) { ?> |
|
154 | 154 | <td class="tax"></td> |
155 | 155 | <?php } ?> |
156 | 156 | <td class="action"></td> |
@@ -163,29 +163,29 @@ discard block |
||
163 | 163 | <td colspan="<?php echo $cols; ?>"></td> |
164 | 164 | </tr> |
165 | 165 | <tr class="totals"> |
166 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
166 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
167 | 167 | <td colspan="4"> |
168 | 168 | <table cellspacing="0" cellpadding="0"> |
169 | 169 | <tr class="subtotal"> |
170 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
171 | - <td class="total"><?php echo $subtotal;?></td> |
|
170 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
171 | + <td class="total"><?php echo $subtotal; ?></td> |
|
172 | 172 | <td class="action"></td> |
173 | 173 | </tr> |
174 | 174 | <tr class="discount"> |
175 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
176 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
175 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
176 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
177 | 177 | <td class="action"></td> |
178 | 178 | </tr> |
179 | - <?php if ( $use_taxes ) { ?> |
|
179 | + <?php if ($use_taxes) { ?> |
|
180 | 180 | <tr class="tax"> |
181 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
182 | - <td class="total"><?php echo $tax;?></td> |
|
181 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
182 | + <td class="total"><?php echo $tax; ?></td> |
|
183 | 183 | <td class="action"></td> |
184 | 184 | </tr> |
185 | 185 | <?php } ?> |
186 | 186 | <tr class="total"> |
187 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
188 | - <td class="total"><?php echo $total;?></td> |
|
187 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
188 | + <td class="total"><?php echo $total; ?></td> |
|
189 | 189 | <td class="action"></td> |
190 | 190 | </tr> |
191 | 191 | </table> |
@@ -196,90 +196,90 @@ discard block |
||
196 | 196 | <div class="wpinv-actions"> |
197 | 197 | <?php ob_start(); ?> |
198 | 198 | <?php |
199 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
200 | - if ( !$invoice->is_recurring() ) { |
|
201 | - echo wpinv_item_dropdown( array( |
|
199 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
200 | + if (!$invoice->is_recurring()) { |
|
201 | + echo wpinv_item_dropdown(array( |
|
202 | 202 | 'name' => 'wpinv_invoice_item', |
203 | 203 | 'id' => 'wpinv_invoice_item', |
204 | 204 | 'show_recurring' => true, |
205 | 205 | 'class' => 'wpi_select2', |
206 | - ) ); |
|
206 | + )); |
|
207 | 207 | ?> |
208 | - <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"> |
|
208 | + <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"> |
|
209 | 209 | <?php } ?> |
210 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
211 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
210 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
211 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
212 | 212 | </div> |
213 | 213 | </div> |
214 | 214 | <?php |
215 | 215 | } |
216 | 216 | |
217 | - public static function prices( $post ) { |
|
217 | + public static function prices($post) { |
|
218 | 218 | $symbol = wpinv_currency_symbol(); |
219 | 219 | $position = wpinv_currency_position(); |
220 | - $item = new WPInv_Item( $post->ID ); |
|
220 | + $item = new WPInv_Item($post->ID); |
|
221 | 221 | |
222 | 222 | $price = $item->get_price(); |
223 | 223 | $is_dynamic_pricing = $item->get_is_dynamic_pricing(); |
224 | 224 | $minimum_price = $item->get_minimum_price(); |
225 | 225 | $is_recurring = $item->is_recurring(); |
226 | 226 | $period = $item->get_recurring_period(); |
227 | - $interval = absint( $item->get_recurring_interval() ); |
|
228 | - $times = absint( $item->get_recurring_limit() ); |
|
227 | + $interval = absint($item->get_recurring_interval()); |
|
228 | + $times = absint($item->get_recurring_limit()); |
|
229 | 229 | $free_trial = $item->has_free_trial(); |
230 | 230 | $trial_interval = $item->get_trial_interval(); |
231 | 231 | $trial_period = $item->get_trial_period(); |
232 | 232 | |
233 | 233 | $intervals = array(); |
234 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
234 | + for ($i = 1; $i <= 90; $i++) { |
|
235 | 235 | $intervals[$i] = $i; |
236 | 236 | } |
237 | 237 | |
238 | - $interval = $interval > 0 ? $interval : 1; |
|
238 | + $interval = $interval > 0 ? $interval : 1; |
|
239 | 239 | |
240 | 240 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
241 | 241 | |
242 | 242 | $minimum_price_style = 'margin-left: 24px;'; |
243 | - if(! $is_dynamic_pricing ) { |
|
243 | + if (!$is_dynamic_pricing) { |
|
244 | 244 | $minimum_price_style .= 'display: none;'; |
245 | 245 | } |
246 | 246 | |
247 | 247 | ?> |
248 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><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' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
249 | - <?php do_action( 'wpinv_prices_metabox_price', $item ); ?> |
|
248 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><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' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
249 | + <?php do_action('wpinv_prices_metabox_price', $item); ?> |
|
250 | 250 | </p> |
251 | 251 | |
252 | - <?php if( $item->supports_dynamic_pricing() ) { ?> |
|
252 | + <?php if ($item->supports_dynamic_pricing()) { ?> |
|
253 | 253 | |
254 | 254 | <p class="wpinv-row-name-your-price"> |
255 | 255 | <label> |
256 | - <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> /> |
|
257 | - <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?> |
|
256 | + <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> /> |
|
257 | + <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?> |
|
258 | 258 | </label> |
259 | - <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?> |
|
259 | + <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?> |
|
260 | 260 | </p> |
261 | 261 | |
262 | 262 | <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>"> |
263 | 263 | <label> |
264 | - <?php _e( 'Minimum Price', 'invoicing' ); ?> |
|
265 | - <?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?> |
|
264 | + <?php _e('Minimum Price', 'invoicing'); ?> |
|
265 | + <?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?> |
|
266 | 266 | </label> |
267 | 267 | |
268 | - <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?> |
|
268 | + <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?> |
|
269 | 269 | </p> |
270 | 270 | |
271 | 271 | <?php } ?> |
272 | 272 | |
273 | 273 | <p class="wpinv-row-is-recurring"> |
274 | 274 | <label for="wpinv_is_recurring"> |
275 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
276 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
275 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
276 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
277 | 277 | </label> |
278 | - <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?> |
|
278 | + <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?> |
|
279 | 279 | </p> |
280 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
281 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" 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> |
|
282 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
280 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
281 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" 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> |
|
282 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
283 | 283 | 'options' => $intervals, |
284 | 284 | 'name' => 'wpinv_recurring_interval', |
285 | 285 | 'id' => 'wpinv_recurring_interval', |
@@ -287,30 +287,30 @@ discard block |
||
287 | 287 | 'show_option_all' => false, |
288 | 288 | 'show_option_none' => false, |
289 | 289 | 'class' => 'wpi_select2', |
290 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
291 | - <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> |
|
290 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
291 | + <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> |
|
292 | 292 | <span class="clear wpi-trial-clr"></span> |
293 | 293 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
294 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
295 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
294 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> |
|
295 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
296 | 296 | </label> |
297 | 297 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
298 | - <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 wpi_select2" 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> |
|
298 | + <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 wpi_select2" 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> |
|
299 | 299 | </label> |
300 | - <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?> |
|
300 | + <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?> |
|
301 | 301 | </p> |
302 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
303 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
302 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
303 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
304 | 304 | <?php |
305 | 305 | } |
306 | 306 | |
307 | - public static function vat_rules( $post ) { |
|
307 | + public static function vat_rules($post) { |
|
308 | 308 | global $wpinv_euvat; |
309 | 309 | |
310 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
310 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
311 | 311 | ?> |
312 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
313 | - <?php echo wpinv_html_select( array( |
|
312 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
313 | + <?php echo wpinv_html_select(array( |
|
314 | 314 | 'options' => $wpinv_euvat->get_rules(), |
315 | 315 | 'name' => 'wpinv_vat_rules', |
316 | 316 | 'id' => 'wpinv_vat_rules', |
@@ -318,19 +318,19 @@ discard block |
||
318 | 318 | 'show_option_all' => false, |
319 | 319 | 'show_option_none' => false, |
320 | 320 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2', |
321 | - ) ); ?> |
|
321 | + )); ?> |
|
322 | 322 | </p> |
323 | - <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> |
|
324 | - <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> |
|
323 | + <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> |
|
324 | + <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> |
|
325 | 325 | <?php |
326 | 326 | } |
327 | 327 | |
328 | - public static function vat_classes( $post ) { |
|
328 | + public static function vat_classes($post) { |
|
329 | 329 | global $wpinv_euvat; |
330 | 330 | |
331 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
331 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
332 | 332 | ?> |
333 | - <p><?php echo wpinv_html_select( array( |
|
333 | + <p><?php echo wpinv_html_select(array( |
|
334 | 334 | 'options' => $wpinv_euvat->get_all_classes(), |
335 | 335 | 'name' => 'wpinv_vat_class', |
336 | 336 | 'id' => 'wpinv_vat_class', |
@@ -338,18 +338,18 @@ discard block |
||
338 | 338 | 'show_option_all' => false, |
339 | 339 | 'show_option_none' => false, |
340 | 340 | 'class' => 'gdmbx2-text-medium wpinv-vat-class wpi_select2', |
341 | - ) ); ?> |
|
341 | + )); ?> |
|
342 | 342 | </p> |
343 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
343 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
344 | 344 | <?php |
345 | 345 | } |
346 | 346 | |
347 | - public static function item_info( $post ) { |
|
348 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
349 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
347 | + public static function item_info($post) { |
|
348 | + $item_type = wpinv_get_item_type($post->ID); |
|
349 | + do_action('wpinv_item_info_metabox_before', $post); |
|
350 | 350 | ?> |
351 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
352 | - <?php echo wpinv_html_select( array( |
|
351 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
352 | + <?php echo wpinv_html_select(array( |
|
353 | 353 | 'options' => wpinv_get_item_types(), |
354 | 354 | 'name' => 'wpinv_item_type', |
355 | 355 | 'id' => 'wpinv_item_type', |
@@ -357,127 +357,127 @@ discard block |
||
357 | 357 | 'show_option_all' => false, |
358 | 358 | 'show_option_none' => false, |
359 | 359 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
360 | - ) ); ?> |
|
360 | + )); ?> |
|
361 | 361 | </p> |
362 | - <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> |
|
362 | + <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> |
|
363 | 363 | <?php |
364 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
364 | + do_action('wpinv_item_info_metabox_after', $post); |
|
365 | 365 | } |
366 | 366 | |
367 | - public static function meta_values( $post ) { |
|
368 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
367 | + public static function meta_values($post) { |
|
368 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
369 | 369 | 'type', |
370 | 370 | 'custom_id' |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | |
373 | - if ( empty( $meta_keys ) ) { |
|
373 | + if (empty($meta_keys)) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
377 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
378 | 378 | |
379 | - foreach ( $meta_keys as $meta_key ) { |
|
379 | + foreach ($meta_keys as $meta_key) { |
|
380 | 380 | ?> |
381 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
381 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
382 | 382 | <?php |
383 | 383 | } |
384 | 384 | |
385 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
385 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
386 | 386 | } |
387 | 387 | |
388 | - public static function save( $post_id, $data, $post ) { |
|
389 | - $invoice = new WPInv_Invoice( $post_id ); |
|
388 | + public static function save($post_id, $data, $post) { |
|
389 | + $invoice = new WPInv_Invoice($post_id); |
|
390 | 390 | |
391 | 391 | // Billing |
392 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
393 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
394 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
395 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
396 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
397 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
398 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
399 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
400 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
401 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
392 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
393 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
394 | + $company = sanitize_text_field($data['wpinv_company']); |
|
395 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
396 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
397 | + $address = sanitize_text_field($data['wpinv_address']); |
|
398 | + $city = sanitize_text_field($data['wpinv_city']); |
|
399 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
400 | + $country = sanitize_text_field($data['wpinv_country']); |
|
401 | + $state = sanitize_text_field($data['wpinv_state']); |
|
402 | 402 | |
403 | 403 | // Details |
404 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
405 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
406 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
407 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
404 | + $status = sanitize_text_field($data['wpinv_status']); |
|
405 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
406 | + $number = sanitize_text_field($data['wpinv_number']); |
|
407 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
408 | 408 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
409 | 409 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
410 | 410 | |
411 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
412 | - |
|
413 | - $invoice->set( 'due_date', $due_date ); |
|
414 | - $invoice->set( 'first_name', $first_name ); |
|
415 | - $invoice->set( 'last_name', $last_name ); |
|
416 | - $invoice->set( 'company', $company ); |
|
417 | - $invoice->set( 'vat_number', $vat_number ); |
|
418 | - $invoice->set( 'phone', $phone ); |
|
419 | - $invoice->set( 'address', $address ); |
|
420 | - $invoice->set( 'city', $city ); |
|
421 | - $invoice->set( 'zip', $zip ); |
|
422 | - $invoice->set( 'country', $country ); |
|
423 | - $invoice->set( 'state', $state ); |
|
424 | - $invoice->set( 'status', $status ); |
|
411 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
412 | + |
|
413 | + $invoice->set('due_date', $due_date); |
|
414 | + $invoice->set('first_name', $first_name); |
|
415 | + $invoice->set('last_name', $last_name); |
|
416 | + $invoice->set('company', $company); |
|
417 | + $invoice->set('vat_number', $vat_number); |
|
418 | + $invoice->set('phone', $phone); |
|
419 | + $invoice->set('address', $address); |
|
420 | + $invoice->set('city', $city); |
|
421 | + $invoice->set('zip', $zip); |
|
422 | + $invoice->set('country', $country); |
|
423 | + $invoice->set('state', $state); |
|
424 | + $invoice->set('status', $status); |
|
425 | 425 | //$invoice->set( 'number', $number ); |
426 | 426 | //$invoice->set( 'discounts', $discounts ); |
427 | 427 | //$invoice->set( 'discount', $discount ); |
428 | - $invoice->set( 'ip', $ip ); |
|
428 | + $invoice->set('ip', $ip); |
|
429 | 429 | $invoice->old_status = $_POST['original_post_status']; |
430 | 430 | |
431 | 431 | $currency = $invoice->get_currency(); |
432 | - if ( ! empty( sanitize_text_field( $data['wpinv_currency'] ) ) ) { |
|
433 | - $currency = sanitize_text_field( $data['wpinv_currency'] ); |
|
432 | + if (!empty(sanitize_text_field($data['wpinv_currency']))) { |
|
433 | + $currency = sanitize_text_field($data['wpinv_currency']); |
|
434 | 434 | } |
435 | 435 | |
436 | - if ( empty( $currency ) ) { |
|
436 | + if (empty($currency)) { |
|
437 | 437 | $currency = wpinv_get_currency(); |
438 | 438 | } |
439 | 439 | |
440 | - if ( ! $invoice->is_paid() ) { |
|
440 | + if (!$invoice->is_paid()) { |
|
441 | 441 | $invoice->currency = $currency; |
442 | 442 | } |
443 | 443 | |
444 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
445 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
444 | + if (!empty($data['wpinv_gateway'])) { |
|
445 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
446 | 446 | } |
447 | 447 | $saved = $invoice->save(); |
448 | 448 | |
449 | 449 | // Check for payment notes |
450 | - if ( !empty( $data['invoice_note'] ) ) { |
|
451 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
452 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
450 | + if (!empty($data['invoice_note'])) { |
|
451 | + $note = wp_kses($data['invoice_note'], array()); |
|
452 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
453 | 453 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
454 | 454 | |
455 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
455 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // Update user address if empty. |
459 | - if ( $saved && !empty( $invoice ) ) { |
|
460 | - if ( $user_id = $invoice->get_user_id() ) { |
|
461 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
459 | + if ($saved && !empty($invoice)) { |
|
460 | + if ($user_id = $invoice->get_user_id()) { |
|
461 | + $user_address = wpinv_get_user_address($user_id, false); |
|
462 | 462 | |
463 | 463 | if (empty($user_address['first_name'])) { |
464 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
465 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
464 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
465 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
466 | 466 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
467 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
467 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
471 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
472 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
473 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
474 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
475 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
476 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
471 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
472 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
473 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
474 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
475 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
476 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
480 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | return $saved; |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -77,39 +77,39 @@ discard block |
||
77 | 77 | 'buy_items' => true, |
78 | 78 | ); |
79 | 79 | |
80 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
80 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
81 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
82 | 82 | |
83 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
83 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
84 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( $nopriv ) { |
|
88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
87 | + if ($nopriv) { |
|
88 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
89 | 89 | |
90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
90 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | public static function add_note() { |
96 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
96 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
97 | 97 | |
98 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
98 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
99 | 99 | die(-1); |
100 | 100 | } |
101 | 101 | |
102 | - $post_id = absint( $_POST['post_id'] ); |
|
103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
104 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
102 | + $post_id = absint($_POST['post_id']); |
|
103 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
104 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
105 | 105 | |
106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
107 | 107 | |
108 | - if ( $post_id > 0 ) { |
|
109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
108 | + if ($post_id > 0) { |
|
109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
110 | 110 | |
111 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
112 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
111 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
112 | + wpinv_get_invoice_note_line_item($note_id); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | public static function delete_note() { |
120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
120 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
121 | 121 | |
122 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
122 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
123 | 123 | die(-1); |
124 | 124 | } |
125 | 125 | |
126 | - $note_id = (int)$_POST['note_id']; |
|
126 | + $note_id = (int) $_POST['note_id']; |
|
127 | 127 | |
128 | - if ( $note_id > 0 ) { |
|
129 | - wp_delete_comment( $note_id, true ); |
|
128 | + if ($note_id > 0) { |
|
129 | + wp_delete_comment($note_id, true); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | die(); |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function checkout() { |
142 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
143 | - define( 'WPINV_CHECKOUT', true ); |
|
142 | + if (!defined('WPINV_CHECKOUT')) { |
|
143 | + define('WPINV_CHECKOUT', true); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | wpinv_process_checkout(); |
@@ -149,53 +149,53 @@ discard block |
||
149 | 149 | |
150 | 150 | public static function add_invoice_item() { |
151 | 151 | global $wpi_userID, $wpinv_ip_address_country; |
152 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
153 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
152 | + check_ajax_referer('invoice-item', '_nonce'); |
|
153 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
154 | 154 | die(-1); |
155 | 155 | } |
156 | 156 | |
157 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
158 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
157 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
158 | + $invoice_id = absint($_POST['invoice_id']); |
|
159 | 159 | |
160 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
160 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
161 | 161 | die(); |
162 | 162 | } |
163 | 163 | |
164 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
165 | - if ( empty( $invoice ) ) { |
|
164 | + $invoice = wpinv_get_invoice($invoice_id); |
|
165 | + if (empty($invoice)) { |
|
166 | 166 | die(); |
167 | 167 | } |
168 | 168 | |
169 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
169 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
170 | 170 | die(); // Don't allow modify items for paid invoice. |
171 | 171 | } |
172 | 172 | |
173 | - if ( !empty( $_POST['user_id'] ) ) { |
|
174 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
173 | + if (!empty($_POST['user_id'])) { |
|
174 | + $wpi_userID = absint($_POST['user_id']); |
|
175 | 175 | } |
176 | 176 | |
177 | - $item = new WPInv_Item( $item_id ); |
|
178 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
177 | + $item = new WPInv_Item($item_id); |
|
178 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
179 | 179 | die(); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually. |
183 | - if ( !empty( $invoice->cart_details ) ) { |
|
183 | + if (!empty($invoice->cart_details)) { |
|
184 | 184 | $valid = true; |
185 | 185 | |
186 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
187 | - if ( $recurring_item != $item_id ) { |
|
186 | + if ($recurring_item = $invoice->get_recurring()) { |
|
187 | + if ($recurring_item != $item_id) { |
|
188 | 188 | $valid = false; |
189 | 189 | } |
190 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
190 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
191 | 191 | $valid = false; |
192 | 192 | } |
193 | 193 | |
194 | - if ( !$valid ) { |
|
194 | + if (!$valid) { |
|
195 | 195 | $response = array(); |
196 | 196 | $response['success'] = false; |
197 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
198 | - wp_send_json( $response ); |
|
197 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
198 | + wp_send_json($response); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | |
204 | 204 | $data = array(); |
205 | 205 | $data['invoice_id'] = $invoice_id; |
206 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
206 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
207 | 207 | |
208 | - wpinv_set_checkout_session( $data ); |
|
208 | + wpinv_set_checkout_session($data); |
|
209 | 209 | |
210 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
210 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
211 | 211 | |
212 | 212 | $args = array( |
213 | 213 | 'id' => $item_id, |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | 'fees' => array() |
221 | 221 | ); |
222 | 222 | |
223 | - $invoice->add_item( $item_id, $args ); |
|
223 | + $invoice->add_item($item_id, $args); |
|
224 | 224 | $invoice->save(); |
225 | 225 | |
226 | - if ( empty( $_POST['country'] ) ) { |
|
226 | + if (empty($_POST['country'])) { |
|
227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
228 | 228 | } |
229 | - if ( empty( $_POST['state'] ) ) { |
|
229 | + if (empty($_POST['state'])) { |
|
230 | 230 | $_POST['state'] = $invoice->state; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
234 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
233 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
234 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
235 | 235 | |
236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
236 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
237 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
238 | 238 | |
239 | 239 | $wpinv_ip_address_country = $invoice->country; |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $response = array(); |
244 | 244 | $response['success'] = true; |
245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
248 | 248 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -254,40 +254,40 @@ discard block |
||
254 | 254 | |
255 | 255 | wpinv_set_checkout_session($checkout_session); |
256 | 256 | |
257 | - wp_send_json( $response ); |
|
257 | + wp_send_json($response); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | public static function remove_invoice_item() { |
261 | 261 | global $wpi_userID, $wpinv_ip_address_country; |
262 | 262 | |
263 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
264 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
263 | + check_ajax_referer('invoice-item', '_nonce'); |
|
264 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
265 | 265 | die(-1); |
266 | 266 | } |
267 | 267 | |
268 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
269 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
268 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
269 | + $invoice_id = absint($_POST['invoice_id']); |
|
270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
271 | 271 | |
272 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
272 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
273 | 273 | die(); |
274 | 274 | } |
275 | 275 | |
276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
277 | - if ( empty( $invoice ) ) { |
|
276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
277 | + if (empty($invoice)) { |
|
278 | 278 | die(); |
279 | 279 | } |
280 | 280 | |
281 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
281 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
282 | 282 | die(); // Don't allow modify items for paid invoice. |
283 | 283 | } |
284 | 284 | |
285 | - if ( !empty( $_POST['user_id'] ) ) { |
|
286 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
285 | + if (!empty($_POST['user_id'])) { |
|
286 | + $wpi_userID = absint($_POST['user_id']); |
|
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
290 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
291 | 291 | die(); |
292 | 292 | } |
293 | 293 | |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | |
296 | 296 | $data = array(); |
297 | 297 | $data['invoice_id'] = $invoice_id; |
298 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
298 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
299 | 299 | |
300 | - wpinv_set_checkout_session( $data ); |
|
300 | + wpinv_set_checkout_session($data); |
|
301 | 301 | |
302 | 302 | $args = array( |
303 | 303 | 'id' => $item_id, |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | 'cart_index' => $cart_index |
306 | 306 | ); |
307 | 307 | |
308 | - $invoice->remove_item( $item_id, $args ); |
|
308 | + $invoice->remove_item($item_id, $args); |
|
309 | 309 | $invoice->save(); |
310 | 310 | |
311 | - if ( empty( $_POST['country'] ) ) { |
|
311 | + if (empty($_POST['country'])) { |
|
312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
313 | 313 | } |
314 | - if ( empty( $_POST['state'] ) ) { |
|
314 | + if (empty($_POST['state'])) { |
|
315 | 315 | $_POST['state'] = $invoice->state; |
316 | 316 | } |
317 | 317 | |
318 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
319 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
318 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
319 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
320 | 320 | |
321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
321 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
322 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
323 | 323 | |
324 | 324 | $wpinv_ip_address_country = $invoice->country; |
325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $response = array(); |
329 | 329 | $response['success'] = true; |
330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
333 | 333 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -339,55 +339,55 @@ discard block |
||
339 | 339 | |
340 | 340 | wpinv_set_checkout_session($checkout_session); |
341 | 341 | |
342 | - wp_send_json( $response ); |
|
342 | + wp_send_json($response); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | public static function create_invoice_item() { |
346 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
347 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
346 | + check_ajax_referer('invoice-item', '_nonce'); |
|
347 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
348 | 348 | die(-1); |
349 | 349 | } |
350 | 350 | |
351 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
351 | + $invoice_id = absint($_POST['invoice_id']); |
|
352 | 352 | |
353 | 353 | // Find the item |
354 | - if ( !is_numeric( $invoice_id ) ) { |
|
354 | + if (!is_numeric($invoice_id)) { |
|
355 | 355 | die(); |
356 | 356 | } |
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - if ( empty( $invoice ) ) { |
|
358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
359 | + if (empty($invoice)) { |
|
360 | 360 | die(); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually. |
364 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
364 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
365 | 365 | $response = array(); |
366 | 366 | $response['success'] = false; |
367 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
368 | - wp_send_json( $response ); |
|
367 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
368 | + wp_send_json($response); |
|
369 | 369 | } |
370 | 370 | |
371 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
371 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
372 | 372 | |
373 | 373 | $meta = array(); |
374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
378 | 378 | |
379 | 379 | $data = array(); |
380 | 380 | $data['post_title'] = sanitize_text_field($save_item['name']); |
381 | 381 | $data['post_status'] = 'publish'; |
382 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
382 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
383 | 383 | $data['meta'] = $meta; |
384 | 384 | |
385 | 385 | $item = new WPInv_Item(); |
386 | - $item->create( $data ); |
|
386 | + $item->create($data); |
|
387 | 387 | |
388 | - if ( !empty( $item ) ) { |
|
388 | + if (!empty($item)) { |
|
389 | 389 | $_POST['item_id'] = $item->ID; |
390 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
390 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
391 | 391 | |
392 | 392 | self::add_invoice_item(); |
393 | 393 | } |
@@ -395,15 +395,15 @@ discard block |
||
395 | 395 | } |
396 | 396 | |
397 | 397 | public static function get_billing_details() { |
398 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
398 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
399 | 399 | |
400 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
400 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
401 | 401 | die(-1); |
402 | 402 | } |
403 | 403 | |
404 | - $user_id = (int)$_POST['user_id']; |
|
404 | + $user_id = (int) $_POST['user_id']; |
|
405 | 405 | $billing_details = wpinv_get_user_address($user_id); |
406 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
406 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
407 | 407 | |
408 | 408 | if (isset($billing_details['user_id'])) { |
409 | 409 | unset($billing_details['user_id']); |
@@ -417,20 +417,20 @@ discard block |
||
417 | 417 | $response['success'] = true; |
418 | 418 | $response['data']['billing_details'] = $billing_details; |
419 | 419 | |
420 | - wp_send_json( $response ); |
|
420 | + wp_send_json($response); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | public static function admin_recalculate_totals() { |
424 | 424 | global $wpi_userID, $wpinv_ip_address_country; |
425 | 425 | |
426 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
427 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
426 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
427 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
428 | 428 | die(-1); |
429 | 429 | } |
430 | 430 | |
431 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
432 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
433 | - if ( empty( $invoice ) ) { |
|
431 | + $invoice_id = absint($_POST['invoice_id']); |
|
432 | + $invoice = wpinv_get_invoice($invoice_id); |
|
433 | + if (empty($invoice)) { |
|
434 | 434 | die(); |
435 | 435 | } |
436 | 436 | |
@@ -438,23 +438,23 @@ discard block |
||
438 | 438 | |
439 | 439 | $data = array(); |
440 | 440 | $data['invoice_id'] = $invoice_id; |
441 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
441 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
442 | 442 | |
443 | - wpinv_set_checkout_session( $data ); |
|
443 | + wpinv_set_checkout_session($data); |
|
444 | 444 | |
445 | - if ( !empty( $_POST['user_id'] ) ) { |
|
446 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
445 | + if (!empty($_POST['user_id'])) { |
|
446 | + $wpi_userID = absint($_POST['user_id']); |
|
447 | 447 | } |
448 | 448 | |
449 | - if ( empty( $_POST['country'] ) ) { |
|
449 | + if (empty($_POST['country'])) { |
|
450 | 450 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
451 | 451 | } |
452 | 452 | |
453 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
454 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
455 | - if ( isset( $_POST['state'] ) ) { |
|
456 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
457 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
453 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
454 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
455 | + if (isset($_POST['state'])) { |
|
456 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
457 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | $wpinv_ip_address_country = $invoice->country; |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | |
464 | 464 | $response = array(); |
465 | 465 | $response['success'] = true; |
466 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
466 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
467 | 467 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
468 | 468 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
469 | 469 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -475,25 +475,25 @@ discard block |
||
475 | 475 | |
476 | 476 | wpinv_set_checkout_session($checkout_session); |
477 | 477 | |
478 | - wp_send_json( $response ); |
|
478 | + wp_send_json($response); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | public static function admin_apply_discount() { |
482 | 482 | global $wpi_userID; |
483 | 483 | |
484 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
485 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
484 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
485 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
486 | 486 | die(-1); |
487 | 487 | } |
488 | 488 | |
489 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
490 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
491 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
489 | + $invoice_id = absint($_POST['invoice_id']); |
|
490 | + $discount_code = sanitize_text_field($_POST['code']); |
|
491 | + if (empty($invoice_id) || empty($discount_code)) { |
|
492 | 492 | die(); |
493 | 493 | } |
494 | 494 | |
495 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
496 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
495 | + $invoice = wpinv_get_invoice($invoice_id); |
|
496 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
497 | 497 | die(); |
498 | 498 | } |
499 | 499 | |
@@ -501,49 +501,49 @@ discard block |
||
501 | 501 | |
502 | 502 | $data = array(); |
503 | 503 | $data['invoice_id'] = $invoice_id; |
504 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
504 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
505 | 505 | |
506 | - wpinv_set_checkout_session( $data ); |
|
506 | + wpinv_set_checkout_session($data); |
|
507 | 507 | |
508 | 508 | $response = array(); |
509 | 509 | $response['success'] = false; |
510 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
510 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
511 | 511 | $response['data']['code'] = $discount_code; |
512 | 512 | |
513 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
514 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
513 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
514 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
515 | 515 | |
516 | 516 | $response['success'] = true; |
517 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
518 | - } else { |
|
517 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
518 | + } else { |
|
519 | 519 | $errors = wpinv_get_errors(); |
520 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
520 | + if (!empty($errors['wpinv-discount-error'])) { |
|
521 | 521 | $response['msg'] = $errors['wpinv-discount-error']; |
522 | 522 | } |
523 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
523 | + wpinv_unset_error('wpinv-discount-error'); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | wpinv_set_checkout_session($checkout_session); |
527 | 527 | |
528 | - wp_send_json( $response ); |
|
528 | + wp_send_json($response); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | public static function admin_remove_discount() { |
532 | 532 | global $wpi_userID; |
533 | 533 | |
534 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
535 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
534 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
535 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
536 | 536 | die(-1); |
537 | 537 | } |
538 | 538 | |
539 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
540 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
541 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
539 | + $invoice_id = absint($_POST['invoice_id']); |
|
540 | + $discount_code = sanitize_text_field($_POST['code']); |
|
541 | + if (empty($invoice_id) || empty($discount_code)) { |
|
542 | 542 | die(); |
543 | 543 | } |
544 | 544 | |
545 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
546 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
545 | + $invoice = wpinv_get_invoice($invoice_id); |
|
546 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
547 | 547 | die(); |
548 | 548 | } |
549 | 549 | |
@@ -551,38 +551,38 @@ discard block |
||
551 | 551 | |
552 | 552 | $data = array(); |
553 | 553 | $data['invoice_id'] = $invoice_id; |
554 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
554 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
555 | 555 | |
556 | - wpinv_set_checkout_session( $data ); |
|
556 | + wpinv_set_checkout_session($data); |
|
557 | 557 | |
558 | 558 | $response = array(); |
559 | 559 | $response['success'] = false; |
560 | 560 | $response['msg'] = NULL; |
561 | 561 | |
562 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
562 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
563 | 563 | $response['success'] = true; |
564 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
564 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
565 | 565 | |
566 | 566 | wpinv_set_checkout_session($checkout_session); |
567 | 567 | |
568 | - wp_send_json( $response ); |
|
568 | + wp_send_json($response); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | public static function check_email() { |
572 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
573 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
572 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
573 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
574 | 574 | die(-1); |
575 | 575 | } |
576 | 576 | |
577 | - $email = sanitize_text_field( $_POST['email'] ); |
|
577 | + $email = sanitize_text_field($_POST['email']); |
|
578 | 578 | |
579 | 579 | $response = array(); |
580 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
580 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
581 | 581 | $user_id = $user_data->ID; |
582 | 582 | $user_login = $user_data->user_login; |
583 | 583 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
584 | 584 | $billing_details = wpinv_get_user_address($user_id); |
585 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
585 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
586 | 586 | |
587 | 587 | if (isset($billing_details['user_id'])) { |
588 | 588 | unset($billing_details['user_id']); |
@@ -598,54 +598,54 @@ discard block |
||
598 | 598 | $response['data']['billing_details'] = $billing_details; |
599 | 599 | } |
600 | 600 | |
601 | - wp_send_json( $response ); |
|
601 | + wp_send_json($response); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | public static function run_tool() { |
605 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
606 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
605 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
606 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
607 | 607 | die(-1); |
608 | 608 | } |
609 | 609 | |
610 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
610 | + $tool = sanitize_text_field($_POST['tool']); |
|
611 | 611 | |
612 | - do_action( 'wpinv_run_tool' ); |
|
612 | + do_action('wpinv_run_tool'); |
|
613 | 613 | |
614 | - if ( !empty( $tool ) ) { |
|
615 | - do_action( 'wpinv_tool_' . $tool ); |
|
614 | + if (!empty($tool)) { |
|
615 | + do_action('wpinv_tool_' . $tool); |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
619 | 619 | public static function apply_discount() { |
620 | 620 | global $wpi_userID; |
621 | 621 | |
622 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
622 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
623 | 623 | |
624 | 624 | $response = array(); |
625 | 625 | |
626 | - if ( isset( $_POST['code'] ) ) { |
|
627 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
626 | + if (isset($_POST['code'])) { |
|
627 | + $discount_code = sanitize_text_field($_POST['code']); |
|
628 | 628 | |
629 | 629 | $response['success'] = false; |
630 | 630 | $response['msg'] = ''; |
631 | 631 | $response['data']['code'] = $discount_code; |
632 | 632 | |
633 | 633 | $invoice = wpinv_get_invoice_cart(); |
634 | - if ( empty( $invoice->ID ) ) { |
|
635 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
636 | - wp_send_json( $response ); |
|
634 | + if (empty($invoice->ID)) { |
|
635 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
636 | + wp_send_json($response); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | $wpi_userID = $invoice->get_user_id(); |
640 | 640 | |
641 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
642 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
643 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
644 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
645 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
646 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
641 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
642 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
643 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
644 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
645 | + $total = wpinv_get_cart_total(null, $discounts); |
|
646 | + $cart_totals = wpinv_recalculate_tax(true); |
|
647 | 647 | |
648 | - if ( !empty( $cart_totals ) ) { |
|
648 | + if (!empty($cart_totals)) { |
|
649 | 649 | $response['success'] = true; |
650 | 650 | $response['data'] = $cart_totals; |
651 | 651 | $response['data']['code'] = $discount_code; |
@@ -654,29 +654,29 @@ discard block |
||
654 | 654 | } |
655 | 655 | } else { |
656 | 656 | $errors = wpinv_get_errors(); |
657 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
658 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
657 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
658 | + wpinv_unset_error('wpinv-discount-error'); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | // Allow for custom discount code handling |
662 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
662 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
663 | 663 | } |
664 | 664 | |
665 | - wp_send_json( $response ); |
|
665 | + wp_send_json($response); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | public static function remove_discount() { |
669 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
669 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
670 | 670 | |
671 | 671 | $response = array(); |
672 | 672 | |
673 | - if ( isset( $_POST['code'] ) ) { |
|
674 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
675 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
676 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
677 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
673 | + if (isset($_POST['code'])) { |
|
674 | + $discount_code = sanitize_text_field($_POST['code']); |
|
675 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
676 | + $total = wpinv_get_cart_total(null, $discounts); |
|
677 | + $cart_totals = wpinv_recalculate_tax(true); |
|
678 | 678 | |
679 | - if ( !empty( $cart_totals ) ) { |
|
679 | + if (!empty($cart_totals)) { |
|
680 | 680 | $response['success'] = true; |
681 | 681 | $response['data'] = $cart_totals; |
682 | 682 | $response['data']['code'] = $discount_code; |
@@ -685,10 +685,10 @@ discard block |
||
685 | 685 | } |
686 | 686 | |
687 | 687 | // Allow for custom discount code handling |
688 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
688 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
689 | 689 | } |
690 | 690 | |
691 | - wp_send_json( $response ); |
|
691 | + wp_send_json($response); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | |
@@ -700,53 +700,53 @@ discard block |
||
700 | 700 | public static function buy_items() { |
701 | 701 | $user_id = get_current_user_id(); |
702 | 702 | |
703 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
704 | - wp_send_json( array( |
|
705 | - 'success' => wp_login_url( wp_get_referer() ) |
|
706 | - ) ); |
|
703 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
704 | + wp_send_json(array( |
|
705 | + 'success' => wp_login_url(wp_get_referer()) |
|
706 | + )); |
|
707 | 707 | } else { |
708 | 708 | // Only check nonce if logged in as it could be cached when logged out. |
709 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
710 | - wp_send_json( array( |
|
711 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
712 | - ) ); |
|
709 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
710 | + wp_send_json(array( |
|
711 | + 'error' => __('Security checks failed.', 'invoicing') |
|
712 | + )); |
|
713 | 713 | wp_die(); |
714 | 714 | } |
715 | 715 | |
716 | 716 | // allow to set a custom price through post_id |
717 | 717 | $items = $_POST['items']; |
718 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
719 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
718 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
719 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
720 | 720 | |
721 | 721 | $cart_items = array(); |
722 | - if ( $items ) { |
|
723 | - $items = explode( ',', $items ); |
|
722 | + if ($items) { |
|
723 | + $items = explode(',', $items); |
|
724 | 724 | |
725 | - foreach( $items as $item ) { |
|
725 | + foreach ($items as $item) { |
|
726 | 726 | $item_id = $item; |
727 | 727 | $quantity = 1; |
728 | 728 | |
729 | - if ( strpos( $item, '|' ) !== false ) { |
|
730 | - $item_parts = explode( '|', $item ); |
|
729 | + if (strpos($item, '|') !== false) { |
|
730 | + $item_parts = explode('|', $item); |
|
731 | 731 | $item_id = $item_parts[0]; |
732 | 732 | $quantity = $item_parts[1]; |
733 | 733 | } |
734 | 734 | |
735 | - if ( $item_id && $quantity ) { |
|
735 | + if ($item_id && $quantity) { |
|
736 | 736 | $cart_items_arr = array( |
737 | - 'id' => (int)$item_id, |
|
738 | - 'quantity' => (int)$quantity |
|
737 | + 'id' => (int) $item_id, |
|
738 | + 'quantity' => (int) $quantity |
|
739 | 739 | ); |
740 | 740 | |
741 | 741 | // If there is a related post id then add it to meta |
742 | - if ( $related_post_id ) { |
|
742 | + if ($related_post_id) { |
|
743 | 743 | $cart_items_arr['meta'] = array( |
744 | 744 | 'post_id' => $related_post_id |
745 | 745 | ); |
746 | 746 | } |
747 | 747 | |
748 | 748 | // If there is a custom price then set it. |
749 | - if ( $custom_item_price ) { |
|
749 | + if ($custom_item_price) { |
|
750 | 750 | $cart_items_arr['custom_price'] = $custom_item_price; |
751 | 751 | } |
752 | 752 | |
@@ -762,37 +762,37 @@ discard block |
||
762 | 762 | * @param int $related_post_id The related post id if any. |
763 | 763 | * @since 1.0.0 |
764 | 764 | */ |
765 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
765 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
766 | 766 | |
767 | 767 | // Make sure its not in the cart already, if it is then redirect to checkout. |
768 | 768 | $cart_invoice = wpinv_get_invoice_cart(); |
769 | 769 | |
770 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
771 | - wp_send_json( array( |
|
770 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
771 | + wp_send_json(array( |
|
772 | 772 | 'success' => $cart_invoice->get_checkout_payment_url() |
773 | - ) ); |
|
773 | + )); |
|
774 | 774 | wp_die(); |
775 | 775 | } |
776 | 776 | |
777 | 777 | // Check if user has invoice with same items waiting to be paid. |
778 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
779 | - if ( !empty( $user_invoices ) ) { |
|
780 | - foreach( $user_invoices as $user_invoice ) { |
|
778 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
779 | + if (!empty($user_invoices)) { |
|
780 | + foreach ($user_invoices as $user_invoice) { |
|
781 | 781 | $user_cart_details = array(); |
782 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
782 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
783 | 783 | $cart_details = $invoice->get_cart_details(); |
784 | 784 | |
785 | - if ( !empty( $cart_details ) ) { |
|
786 | - foreach ( $cart_details as $invoice_item ) { |
|
785 | + if (!empty($cart_details)) { |
|
786 | + foreach ($cart_details as $invoice_item) { |
|
787 | 787 | $ii_arr = array(); |
788 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
789 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
788 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
789 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
790 | 790 | |
791 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
791 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
792 | 792 | $ii_arr['meta'] = $invoice_item['meta']; |
793 | 793 | } |
794 | 794 | |
795 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
795 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
796 | 796 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
797 | 797 | } |
798 | 798 | |
@@ -800,17 +800,17 @@ discard block |
||
800 | 800 | } |
801 | 801 | } |
802 | 802 | |
803 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
804 | - wp_send_json( array( |
|
803 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
804 | + wp_send_json(array( |
|
805 | 805 | 'success' => $invoice->get_checkout_payment_url() |
806 | - ) ); |
|
806 | + )); |
|
807 | 807 | wp_die(); |
808 | 808 | } |
809 | 809 | } |
810 | 810 | } |
811 | 811 | |
812 | 812 | // Create invoice and send user to checkout |
813 | - if ( !empty( $cart_items ) ) { |
|
813 | + if (!empty($cart_items)) { |
|
814 | 814 | $invoice_data = array( |
815 | 815 | 'status' => 'wpi-pending', |
816 | 816 | 'created_via' => 'wpi', |
@@ -818,21 +818,21 @@ discard block |
||
818 | 818 | 'cart_details' => $cart_items, |
819 | 819 | ); |
820 | 820 | |
821 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
821 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
822 | 822 | |
823 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
824 | - wp_send_json( array( |
|
823 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
824 | + wp_send_json(array( |
|
825 | 825 | 'success' => $invoice->get_checkout_payment_url() |
826 | - ) ); |
|
826 | + )); |
|
827 | 827 | } else { |
828 | - wp_send_json( array( |
|
829 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
830 | - ) ); |
|
828 | + wp_send_json(array( |
|
829 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
830 | + )); |
|
831 | 831 | } |
832 | 832 | } else { |
833 | - wp_send_json( array( |
|
834 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
835 | - ) ); |
|
833 | + wp_send_json(array( |
|
834 | + 'error' => __('Items not valid.', 'invoicing') |
|
835 | + )); |
|
836 | 836 | } |
837 | 837 | } |
838 | 838 |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | * @param string $group The group to assign this job to. |
13 | 13 | * @return string The action ID. |
14 | 14 | */ |
15 | -function as_enqueue_async_action( $hook, $args = array(), $group = '' ) { |
|
16 | - return ActionScheduler::factory()->async( $hook, $args, $group ); |
|
15 | +function as_enqueue_async_action($hook, $args = array(), $group = '') { |
|
16 | + return ActionScheduler::factory()->async($hook, $args, $group); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string The job ID |
28 | 28 | */ |
29 | -function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) { |
|
30 | - return ActionScheduler::factory()->single( $hook, $args, $timestamp, $group ); |
|
29 | +function as_schedule_single_action($timestamp, $hook, $args = array(), $group = '') { |
|
30 | + return ActionScheduler::factory()->single($hook, $args, $timestamp, $group); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return string The job ID |
43 | 43 | */ |
44 | -function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
|
45 | - return ActionScheduler::factory()->recurring( $hook, $args, $timestamp, $interval_in_seconds, $group ); |
|
44 | +function as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') { |
|
45 | + return ActionScheduler::factory()->recurring($hook, $args, $timestamp, $interval_in_seconds, $group); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return string The job ID |
70 | 70 | */ |
71 | -function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) { |
|
72 | - return ActionScheduler::factory()->cron( $hook, $args, $timestamp, $schedule, $group ); |
|
71 | +function as_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '') { |
|
72 | + return ActionScheduler::factory()->cron($hook, $args, $timestamp, $schedule, $group); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string The scheduled action ID if a scheduled action was found, or empty string if no matching action found. |
90 | 90 | */ |
91 | -function as_unschedule_action( $hook, $args = array(), $group = '' ) { |
|
91 | +function as_unschedule_action($hook, $args = array(), $group = '') { |
|
92 | 92 | $params = array(); |
93 | - if ( is_array($args) ) { |
|
93 | + if (is_array($args)) { |
|
94 | 94 | $params['args'] = $args; |
95 | 95 | } |
96 | - if ( !empty($group) ) { |
|
96 | + if (!empty($group)) { |
|
97 | 97 | $params['group'] = $group; |
98 | 98 | } |
99 | - $job_id = ActionScheduler::store()->find_action( $hook, $params ); |
|
99 | + $job_id = ActionScheduler::store()->find_action($hook, $params); |
|
100 | 100 | |
101 | - if ( ! empty( $job_id ) ) { |
|
102 | - ActionScheduler::store()->cancel_action( $job_id ); |
|
101 | + if (!empty($job_id)) { |
|
102 | + ActionScheduler::store()->cancel_action($job_id); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $job_id; |
@@ -112,20 +112,20 @@ discard block |
||
112 | 112 | * @param array $args Args that would have been passed to the job |
113 | 113 | * @param string $group |
114 | 114 | */ |
115 | -function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) { |
|
116 | - if ( empty( $args ) ) { |
|
117 | - if ( ! empty( $hook ) && empty( $group ) ) { |
|
118 | - ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook ); |
|
115 | +function as_unschedule_all_actions($hook, $args = array(), $group = '') { |
|
116 | + if (empty($args)) { |
|
117 | + if (!empty($hook) && empty($group)) { |
|
118 | + ActionScheduler_Store::instance()->cancel_actions_by_hook($hook); |
|
119 | 119 | return; |
120 | 120 | } |
121 | - if ( ! empty( $group ) && empty( $hook ) ) { |
|
122 | - ActionScheduler_Store::instance()->cancel_actions_by_group( $group ); |
|
121 | + if (!empty($group) && empty($hook)) { |
|
122 | + ActionScheduler_Store::instance()->cancel_actions_by_group($group); |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | do { |
127 | - $unscheduled_action = as_unschedule_action( $hook, $args, $group ); |
|
128 | - } while ( ! empty( $unscheduled_action ) ); |
|
127 | + $unscheduled_action = as_unschedule_action($hook, $args, $group); |
|
128 | + } while (!empty($unscheduled_action)); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -143,31 +143,31 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action. |
145 | 145 | */ |
146 | -function as_next_scheduled_action( $hook, $args = NULL, $group = '' ) { |
|
146 | +function as_next_scheduled_action($hook, $args = NULL, $group = '') { |
|
147 | 147 | $params = array(); |
148 | - if ( is_array($args) ) { |
|
148 | + if (is_array($args)) { |
|
149 | 149 | $params['args'] = $args; |
150 | 150 | } |
151 | - if ( !empty($group) ) { |
|
151 | + if (!empty($group)) { |
|
152 | 152 | $params['group'] = $group; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $params['status'] = ActionScheduler_Store::STATUS_RUNNING; |
156 | - $job_id = ActionScheduler::store()->find_action( $hook, $params ); |
|
157 | - if ( ! empty( $job_id ) ) { |
|
156 | + $job_id = ActionScheduler::store()->find_action($hook, $params); |
|
157 | + if (!empty($job_id)) { |
|
158 | 158 | return true; |
159 | 159 | } |
160 | 160 | |
161 | 161 | $params['status'] = ActionScheduler_Store::STATUS_PENDING; |
162 | - $job_id = ActionScheduler::store()->find_action( $hook, $params ); |
|
163 | - if ( empty($job_id) ) { |
|
162 | + $job_id = ActionScheduler::store()->find_action($hook, $params); |
|
163 | + if (empty($job_id)) { |
|
164 | 164 | return false; |
165 | 165 | } |
166 | - $job = ActionScheduler::store()->fetch_action( $job_id ); |
|
166 | + $job = ActionScheduler::store()->fetch_action($job_id); |
|
167 | 167 | $scheduled_date = $job->get_schedule()->get_date(); |
168 | - if ( $scheduled_date ) { |
|
169 | - return (int) $scheduled_date->format( 'U' ); |
|
170 | - } elseif ( NULL === $scheduled_date ) { // pending async action with NullSchedule |
|
168 | + if ($scheduled_date) { |
|
169 | + return (int) $scheduled_date->format('U'); |
|
170 | + } elseif (NULL === $scheduled_date) { // pending async action with NullSchedule |
|
171 | 171 | return true; |
172 | 172 | } |
173 | 173 | return false; |
@@ -195,26 +195,26 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @return array |
197 | 197 | */ |
198 | -function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
|
198 | +function as_get_scheduled_actions($args = array(), $return_format = OBJECT) { |
|
199 | 199 | $store = ActionScheduler::store(); |
200 | - foreach ( array('date', 'modified') as $key ) { |
|
201 | - if ( isset($args[$key]) ) { |
|
200 | + foreach (array('date', 'modified') as $key) { |
|
201 | + if (isset($args[$key])) { |
|
202 | 202 | $args[$key] = as_get_datetime_object($args[$key]); |
203 | 203 | } |
204 | 204 | } |
205 | - $ids = $store->query_actions( $args ); |
|
205 | + $ids = $store->query_actions($args); |
|
206 | 206 | |
207 | - if ( $return_format == 'ids' || $return_format == 'int' ) { |
|
207 | + if ($return_format == 'ids' || $return_format == 'int') { |
|
208 | 208 | return $ids; |
209 | 209 | } |
210 | 210 | |
211 | 211 | $actions = array(); |
212 | - foreach ( $ids as $action_id ) { |
|
213 | - $actions[$action_id] = $store->fetch_action( $action_id ); |
|
212 | + foreach ($ids as $action_id) { |
|
213 | + $actions[$action_id] = $store->fetch_action($action_id); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( $return_format == ARRAY_A ) { |
|
217 | - foreach ( $actions as $action_id => $action_object ) { |
|
216 | + if ($return_format == ARRAY_A) { |
|
217 | + foreach ($actions as $action_id => $action_object) { |
|
218 | 218 | $actions[$action_id] = get_object_vars($action_object); |
219 | 219 | } |
220 | 220 | } |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return ActionScheduler_DateTime |
241 | 241 | */ |
242 | -function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) { |
|
243 | - if ( is_object( $date_string ) && $date_string instanceof DateTime ) { |
|
244 | - $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) ); |
|
245 | - } elseif ( is_numeric( $date_string ) ) { |
|
246 | - $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) ); |
|
242 | +function as_get_datetime_object($date_string = null, $timezone = 'UTC') { |
|
243 | + if (is_object($date_string) && $date_string instanceof DateTime) { |
|
244 | + $date = new ActionScheduler_DateTime($date_string->format('Y-m-d H:i:s'), new DateTimeZone($timezone)); |
|
245 | + } elseif (is_numeric($date_string)) { |
|
246 | + $date = new ActionScheduler_DateTime('@' . $date_string, new DateTimeZone($timezone)); |
|
247 | 247 | } else { |
248 | - $date = new ActionScheduler_DateTime( $date_string, new DateTimeZone( $timezone ) ); |
|
248 | + $date = new ActionScheduler_DateTime($date_string, new DateTimeZone($timezone)); |
|
249 | 249 | } |
250 | 250 | return $date; |
251 | 251 | } |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ActionScheduler_AdminView_Deprecated { |
12 | 12 | |
13 | - public function action_scheduler_post_type_args( $args ) { |
|
14 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
13 | + public function action_scheduler_post_type_args($args) { |
|
14 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
15 | 15 | return $args; |
16 | 16 | } |
17 | 17 | |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * @param array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
22 | 22 | * @return array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
23 | 23 | */ |
24 | - public function list_table_views( $views ) { |
|
25 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
24 | + public function list_table_views($views) { |
|
25 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
26 | 26 | return $views; |
27 | 27 | } |
28 | 28 | |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
35 | 35 | * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
36 | 36 | */ |
37 | - public function bulk_actions( $actions ) { |
|
38 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
37 | + public function bulk_actions($actions) { |
|
38 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
39 | 39 | return $actions; |
40 | 40 | } |
41 | 41 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @param array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
49 | 49 | * @return array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
50 | 50 | */ |
51 | - public function list_table_columns( $columns ) { |
|
52 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
51 | + public function list_table_columns($columns) { |
|
52 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
53 | 53 | return $columns; |
54 | 54 | } |
55 | 55 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
60 | 60 | * @return array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
61 | 61 | */ |
62 | - public static function list_table_sortable_columns( $columns ) { |
|
63 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
62 | + public static function list_table_sortable_columns($columns) { |
|
63 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
64 | 64 | return $columns; |
65 | 65 | } |
66 | 66 | |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * @param string $column_name The key for the column for which we should output our content. |
71 | 71 | * @param int $post_id The ID of the 'scheduled-action' post for which this row relates. |
72 | 72 | */ |
73 | - public static function list_table_column_content( $column_name, $post_id ) { |
|
74 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
73 | + public static function list_table_column_content($column_name, $post_id) { |
|
74 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
83 | 83 | * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
84 | 84 | */ |
85 | - public static function row_actions( $actions, $post ) { |
|
86 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
85 | + public static function row_actions($actions, $post) { |
|
86 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
87 | 87 | return $actions; |
88 | 88 | } |
89 | 89 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @codeCoverageIgnore |
94 | 94 | */ |
95 | 95 | public static function maybe_execute_action() { |
96 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
96 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return string A human friendly string representation of the interval. |
110 | 110 | */ |
111 | 111 | public static function admin_notices() { |
112 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
112 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param WP_Query $query Instance of a WP_Query object |
120 | 120 | * @return string MySQL orderby string. |
121 | 121 | */ |
122 | - public function custom_orderby( $orderby, $query ){ |
|
123 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
122 | + public function custom_orderby($orderby, $query) { |
|
123 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @param WP_Query $query Instance of a WP_Query object |
131 | 131 | * @return string MySQL search string. |
132 | 132 | */ |
133 | - public function search_post_password( $search, $query ) { |
|
134 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
133 | + public function search_post_password($search, $query) { |
|
134 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param array $messages |
141 | 141 | * @return array |
142 | 142 | */ |
143 | - public function post_updated_messages( $messages ) { |
|
144 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
143 | + public function post_updated_messages($messages) { |
|
144 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
145 | 145 | return $messages; |
146 | 146 | } |
147 | 147 | } |
148 | 148 | \ No newline at end of file |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string The job ID |
20 | 20 | */ |
21 | -function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) { |
|
22 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
23 | - return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
21 | +function wc_schedule_single_action($timestamp, $hook, $args = array(), $group = '') { |
|
22 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_single_action()'); |
|
23 | + return as_schedule_single_action($timestamp, $hook, $args, $group); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return string The job ID |
38 | 38 | */ |
39 | -function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
|
40 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
41 | - return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
39 | +function wc_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') { |
|
40 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_recurring_action()'); |
|
41 | + return as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, $group); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string The job ID |
66 | 66 | */ |
67 | -function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) { |
|
68 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
69 | - return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
67 | +function wc_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '') { |
|
68 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_cron_action()'); |
|
69 | + return as_schedule_cron_action($timestamp, $schedule, $hook, $args, $group); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @deprecated 2.1.0 |
80 | 80 | */ |
81 | -function wc_unschedule_action( $hook, $args = array(), $group = '' ) { |
|
82 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
83 | - as_unschedule_action( $hook, $args, $group ); |
|
81 | +function wc_unschedule_action($hook, $args = array(), $group = '') { |
|
82 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_unschedule_action()'); |
|
83 | + as_unschedule_action($hook, $args, $group); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return int|bool The timestamp for the next occurrence, or false if nothing was found |
94 | 94 | */ |
95 | -function wc_next_scheduled_action( $hook, $args = NULL, $group = '' ) { |
|
96 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
97 | - return as_next_scheduled_action( $hook, $args, $group ); |
|
95 | +function wc_next_scheduled_action($hook, $args = NULL, $group = '') { |
|
96 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_next_scheduled_action()'); |
|
97 | + return as_next_scheduled_action($hook, $args, $group); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array |
122 | 122 | */ |
123 | -function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
|
124 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
125 | - return as_get_scheduled_actions( $args, $return_format ); |
|
123 | +function wc_get_scheduled_actions($args = array(), $return_format = OBJECT) { |
|
124 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_get_scheduled_actions()'); |
|
125 | + return as_get_scheduled_actions($args, $return_format); |
|
126 | 126 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | * |
14 | 14 | * @return DateTime|null |
15 | 15 | */ |
16 | - public function next( DateTime $after = NULL ) { |
|
17 | - if ( empty( $after ) ) { |
|
16 | + public function next(DateTime $after = NULL) { |
|
17 | + if (empty($after)) { |
|
18 | 18 | $return_value = $this->get_date(); |
19 | 19 | $replacement_method = 'get_date()'; |
20 | 20 | } else { |
21 | - $return_value = $this->get_next( $after ); |
|
21 | + $return_value = $this->get_next($after); |
|
22 | 22 | $replacement_method = 'get_next( $after )'; |
23 | 23 | } |
24 | 24 | |
25 | - _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); |
|
25 | + _deprecated_function(__METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method); |
|
26 | 26 | |
27 | 27 | return $return_value; |
28 | 28 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @param int $action_id The ID of the action. |
15 | 15 | */ |
16 | - public function mark_failed_fetch_action( $action_id ) { |
|
17 | - _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | - self::$store->mark_failure( $action_id ); |
|
16 | + public function mark_failed_fetch_action($action_id) { |
|
17 | + _deprecated_function(__METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()'); |
|
18 | + self::$store->mark_failure($action_id); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @since 2.2.6 |
25 | 25 | */ |
26 | 26 | protected static function hook() { |
27 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
27 | + _deprecated_function(__METHOD__, '3.0.0'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @since 2.2.6 |
34 | 34 | */ |
35 | 35 | protected static function unhook() { |
36 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
36 | + _deprecated_function(__METHOD__, '3.0.0'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return DateTimeZone |
44 | 44 | */ |
45 | 45 | protected function get_local_timezone() { |
46 | - _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
46 | + _deprecated_function(__FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()'); |
|
47 | 47 | return ActionScheduler_TimezoneHelper::get_local_timezone(); |
48 | 48 | } |
49 | 49 | } |