@@ -7,110 +7,110 @@ 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_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array) apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | |
100 | -function wpinv_get_all_discounts( $args = array() ) { |
|
100 | +function wpinv_get_all_discounts($args = array()) { |
|
101 | 101 | |
102 | - $args = wp_parse_args( $args, array( |
|
103 | - 'status' => array( 'publish' ), |
|
104 | - 'limit' => get_option( 'posts_per_page' ), |
|
102 | + $args = wp_parse_args($args, array( |
|
103 | + 'status' => array('publish'), |
|
104 | + 'limit' => get_option('posts_per_page'), |
|
105 | 105 | 'page' => 1, |
106 | 106 | 'exclude' => array(), |
107 | 107 | 'orderby' => 'date', |
108 | 108 | 'order' => 'DESC', |
109 | - 'type' => array_keys( wpinv_get_discount_types() ), |
|
109 | + 'type' => array_keys(wpinv_get_discount_types()), |
|
110 | 110 | 'meta_query' => array(), |
111 | 111 | 'return' => 'objects', |
112 | 112 | 'paginate' => false, |
113 | - ) ); |
|
113 | + )); |
|
114 | 114 | |
115 | 115 | $wp_query_args = array( |
116 | 116 | 'post_type' => 'wpi_discount', |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | 'fields' => 'ids', |
121 | 121 | 'orderby' => $args['orderby'], |
122 | 122 | 'order' => $args['order'], |
123 | - 'paged' => absint( $args['page'] ), |
|
123 | + 'paged' => absint($args['page']), |
|
124 | 124 | ); |
125 | 125 | |
126 | - if ( ! empty( $args['exclude'] ) ) { |
|
127 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
126 | + if (!empty($args['exclude'])) { |
|
127 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( ! $args['paginate' ] ) { |
|
130 | + if (!$args['paginate']) { |
|
131 | 131 | $wp_query_args['no_found_rows'] = true; |
132 | 132 | } |
133 | 133 | |
134 | - if ( ! empty( $args['search'] ) ) { |
|
134 | + if (!empty($args['search'])) { |
|
135 | 135 | |
136 | 136 | $wp_query_args['meta_query'][] = array( |
137 | 137 | 'key' => '_wpi_discount_code', |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | |
142 | 142 | } |
143 | 143 | |
144 | - if ( ! empty( $args['type'] ) ) { |
|
145 | - $types = wpinv_parse_list( $args['type'] ); |
|
144 | + if (!empty($args['type'])) { |
|
145 | + $types = wpinv_parse_list($args['type']); |
|
146 | 146 | $wp_query_args['meta_query'][] = array( |
147 | 147 | 'key' => '_wpi_discount_type', |
148 | - 'value' => implode( ',', $types ), |
|
148 | + 'value' => implode(',', $types), |
|
149 | 149 | 'compare' => 'IN', |
150 | 150 | ); |
151 | 151 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args); |
154 | 154 | |
155 | 155 | // Get results. |
156 | - $discounts = new WP_Query( $wp_query_args ); |
|
156 | + $discounts = new WP_Query($wp_query_args); |
|
157 | 157 | |
158 | - if ( 'objects' === $args['return'] ) { |
|
159 | - $return = array_map( 'get_post', $discounts->posts ); |
|
160 | - } elseif ( 'self' === $args['return'] ) { |
|
158 | + if ('objects' === $args['return']) { |
|
159 | + $return = array_map('get_post', $discounts->posts); |
|
160 | + } elseif ('self' === $args['return']) { |
|
161 | 161 | return $discounts; |
162 | 162 | } else { |
163 | 163 | $return = $discounts->posts; |
164 | 164 | } |
165 | 165 | |
166 | - if ( $args['paginate' ] ) { |
|
166 | + if ($args['paginate']) { |
|
167 | 167 | return (object) array( |
168 | 168 | 'discounts' => $return, |
169 | 169 | 'total' => $discounts->found_posts, |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | |
181 | 181 | $discounts = wpinv_get_discounts(); |
182 | 182 | |
183 | - if ( $discounts) { |
|
184 | - foreach ( $discounts as $discount ) { |
|
185 | - if ( wpinv_is_discount_active( $discount->ID, true ) ) { |
|
183 | + if ($discounts) { |
|
184 | + foreach ($discounts as $discount) { |
|
185 | + if (wpinv_is_discount_active($discount->ID, true)) { |
|
186 | 186 | $has_active = true; |
187 | 187 | break; |
188 | 188 | } |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | return $has_active; |
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
195 | - if( empty( $discount_id ) ) { |
|
194 | +function wpinv_get_discount($discount_id = 0) { |
|
195 | + if (empty($discount_id)) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
199 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | |
203 | - $discount = get_post( $discount_id ); |
|
203 | + $discount = get_post($discount_id); |
|
204 | 204 | |
205 | 205 | return $discount; |
206 | 206 | } |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @since 1.0.15 |
213 | 213 | * @return WPInv_Discount |
214 | 214 | */ |
215 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
216 | - return new WPInv_Discount( $discount ); |
|
215 | +function wpinv_get_discount_obj($discount = 0) { |
|
216 | + return new WPInv_Discount($discount); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @param string $code The discount code. |
223 | 223 | * @return bool|WP_Post |
224 | 224 | */ |
225 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
226 | - return wpinv_get_discount_by( 'code', $code ); |
|
225 | +function wpinv_get_discount_by_code($code = '') { |
|
226 | + return wpinv_get_discount_by('code', $code); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | * @param string|int $value The field value |
234 | 234 | * @return bool|WP_Post |
235 | 235 | */ |
236 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
237 | - $data = WPInv_Discount::get_data_by( $field, $value ); |
|
238 | - if( empty( $data ) ) { |
|
236 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
237 | + $data = WPInv_Discount::get_data_by($field, $value); |
|
238 | + if (empty($data)) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
242 | - return get_post( $data['ID'] ); |
|
242 | + return get_post($data['ID']); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -249,68 +249,68 @@ discard block |
||
249 | 249 | * @param array $data The discount's properties. |
250 | 250 | * @return bool |
251 | 251 | */ |
252 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
252 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
253 | 253 | $meta = array( |
254 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
255 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
256 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
257 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
258 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
259 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
260 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
261 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
262 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
263 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
264 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
265 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
266 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
254 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
255 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
256 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
257 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
258 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
259 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
260 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
261 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
262 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
263 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
264 | + 'is_recurring' => isset($data['recurring']) ? (bool) $data['recurring'] : false, |
|
265 | + 'is_single_use' => isset($data['single_use']) ? (bool) $data['single_use'] : false, |
|
266 | + 'uses' => isset($data['uses']) ? (int) $data['uses'] : false, |
|
267 | 267 | ); |
268 | 268 | |
269 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
269 | + if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) { |
|
270 | 270 | $meta['amount'] = 100; |
271 | 271 | } |
272 | 272 | |
273 | - if ( !empty( $meta['start'] ) ) { |
|
274 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
273 | + if (!empty($meta['start'])) { |
|
274 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
275 | 275 | } |
276 | 276 | |
277 | - if ( !empty( $meta['expiration'] ) ) { |
|
278 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
277 | + if (!empty($meta['expiration'])) { |
|
278 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
279 | 279 | |
280 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
280 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
281 | 281 | $meta['expiration'] = $meta['start']; |
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - if ( $meta['uses'] === false ) { |
|
286 | - unset( $meta['uses'] ); |
|
285 | + if ($meta['uses'] === false) { |
|
286 | + unset($meta['uses']); |
|
287 | 287 | } |
288 | 288 | |
289 | - if ( ! empty( $meta['items'] ) ) { |
|
290 | - foreach ( $meta['items'] as $key => $item ) { |
|
291 | - if ( 0 === intval( $item ) ) { |
|
292 | - unset( $meta['items'][ $key ] ); |
|
289 | + if (!empty($meta['items'])) { |
|
290 | + foreach ($meta['items'] as $key => $item) { |
|
291 | + if (0 === intval($item)) { |
|
292 | + unset($meta['items'][$key]); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
298 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
299 | - if ( 0 === intval( $item ) ) { |
|
300 | - unset( $meta['excluded_items'][ $key ] ); |
|
297 | + if (!empty($meta['excluded_items'])) { |
|
298 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
299 | + if (0 === intval($item)) { |
|
300 | + unset($meta['excluded_items'][$key]); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
305 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
306 | 306 | |
307 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
307 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
308 | 308 | |
309 | - foreach( $meta as $key => $value ) { |
|
310 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
309 | + foreach ($meta as $key => $value) { |
|
310 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
311 | 311 | } |
312 | 312 | |
313 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
313 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
314 | 314 | |
315 | 315 | return $post_id; |
316 | 316 | } |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
322 | 322 | * @return bool |
323 | 323 | */ |
324 | -function wpinv_remove_discount( $discount = 0 ) { |
|
324 | +function wpinv_remove_discount($discount = 0) { |
|
325 | 325 | |
326 | - $discount = wpinv_get_discount_obj( $discount ); |
|
327 | - if( ! $discount->exists() ) { |
|
326 | + $discount = wpinv_get_discount_obj($discount); |
|
327 | + if (!$discount->exists()) { |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | * @param string $new_status |
340 | 340 | * @return bool |
341 | 341 | */ |
342 | -function wpinv_update_discount_status( $discount = 0, $new_status = 'publish' ) { |
|
343 | - $discount = wpinv_get_discount_obj( $discount ); |
|
344 | - return $discount->update_status( $new_status ); |
|
342 | +function wpinv_update_discount_status($discount = 0, $new_status = 'publish') { |
|
343 | + $discount = wpinv_get_discount_obj($discount); |
|
344 | + return $discount->update_status($new_status); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -350,48 +350,48 @@ discard block |
||
350 | 350 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
351 | 351 | * @return bool |
352 | 352 | */ |
353 | -function wpinv_discount_exists( $discount ) { |
|
354 | - $discount = wpinv_get_discount_obj( $discount ); |
|
353 | +function wpinv_discount_exists($discount) { |
|
354 | + $discount = wpinv_get_discount_obj($discount); |
|
355 | 355 | return $discount->exists(); |
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_is_discount_active( $code_id = null, $silent = false ) { |
|
359 | - $discount = wpinv_get_discount( $code_id ); |
|
358 | +function wpinv_is_discount_active($code_id = null, $silent = false) { |
|
359 | + $discount = wpinv_get_discount($code_id); |
|
360 | 360 | $return = false; |
361 | 361 | |
362 | - if ( $discount ) { |
|
363 | - if ( wpinv_is_discount_expired( $code_id, $silent ) ) { |
|
364 | - if( defined( 'DOING_AJAX' ) && ! $silent ) { |
|
365 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
362 | + if ($discount) { |
|
363 | + if (wpinv_is_discount_expired($code_id, $silent)) { |
|
364 | + if (defined('DOING_AJAX') && !$silent) { |
|
365 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
366 | 366 | } |
367 | - } elseif ( $discount->post_status == 'publish' ) { |
|
367 | + } elseif ($discount->post_status == 'publish') { |
|
368 | 368 | $return = true; |
369 | 369 | } else { |
370 | - if( defined( 'DOING_AJAX' ) && ! $silent ) { |
|
371 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
370 | + if (defined('DOING_AJAX') && !$silent) { |
|
371 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | } |
375 | 375 | |
376 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
376 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_get_discount_code( $code_id = null ) { |
|
380 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
379 | +function wpinv_get_discount_code($code_id = null) { |
|
380 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
381 | 381 | |
382 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
382 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
383 | 383 | } |
384 | 384 | |
385 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
386 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
385 | +function wpinv_get_discount_start_date($code_id = null) { |
|
386 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
387 | 387 | |
388 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
388 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
389 | 389 | } |
390 | 390 | |
391 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
392 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
391 | +function wpinv_get_discount_expiration($code_id = null) { |
|
392 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
393 | 393 | |
394 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
394 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
401 | 401 | * @return int |
402 | 402 | */ |
403 | -function wpinv_get_discount_max_uses( $discount = array() ) { |
|
404 | - $discount = wpinv_get_discount_obj( $discount ); |
|
403 | +function wpinv_get_discount_max_uses($discount = array()) { |
|
404 | + $discount = wpinv_get_discount_obj($discount); |
|
405 | 405 | return (int) $discount->max_uses; |
406 | 406 | } |
407 | 407 | |
@@ -411,8 +411,8 @@ discard block |
||
411 | 411 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
412 | 412 | * @return int |
413 | 413 | */ |
414 | -function wpinv_get_discount_uses( $discount = array() ) { |
|
415 | - $discount = wpinv_get_discount_obj( $discount ); |
|
414 | +function wpinv_get_discount_uses($discount = array()) { |
|
415 | + $discount = wpinv_get_discount_obj($discount); |
|
416 | 416 | return (int) $discount->uses; |
417 | 417 | } |
418 | 418 | |
@@ -422,8 +422,8 @@ discard block |
||
422 | 422 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
423 | 423 | * @return float |
424 | 424 | */ |
425 | -function wpinv_get_discount_min_total( $discount = array() ) { |
|
426 | - $discount = wpinv_get_discount_obj( $discount ); |
|
425 | +function wpinv_get_discount_min_total($discount = array()) { |
|
426 | + $discount = wpinv_get_discount_obj($discount); |
|
427 | 427 | return (float) $discount->min_total; |
428 | 428 | } |
429 | 429 | |
@@ -433,8 +433,8 @@ discard block |
||
433 | 433 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
434 | 434 | * @return float |
435 | 435 | */ |
436 | -function wpinv_get_discount_max_total( $discount = array() ) { |
|
437 | - $discount = wpinv_get_discount_obj( $discount ); |
|
436 | +function wpinv_get_discount_max_total($discount = array()) { |
|
437 | + $discount = wpinv_get_discount_obj($discount); |
|
438 | 438 | return (float) $discount->max_total; |
439 | 439 | } |
440 | 440 | |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
445 | 445 | * @return float |
446 | 446 | */ |
447 | -function wpinv_get_discount_amount( $discount = array() ) { |
|
448 | - $discount = wpinv_get_discount_obj( $discount ); |
|
447 | +function wpinv_get_discount_amount($discount = array()) { |
|
448 | + $discount = wpinv_get_discount_obj($discount); |
|
449 | 449 | return (float) $discount->amount; |
450 | 450 | } |
451 | 451 | |
@@ -456,28 +456,28 @@ discard block |
||
456 | 456 | * @param bool $name |
457 | 457 | * @return string |
458 | 458 | */ |
459 | -function wpinv_get_discount_type( $discount = array(), $name = false ) { |
|
460 | - $discount = wpinv_get_discount_obj( $discount ); |
|
459 | +function wpinv_get_discount_type($discount = array(), $name = false) { |
|
460 | + $discount = wpinv_get_discount_obj($discount); |
|
461 | 461 | |
462 | 462 | // Are we returning the name or just the type. |
463 | - if( $name ) { |
|
463 | + if ($name) { |
|
464 | 464 | return $discount->type_name; |
465 | 465 | } |
466 | 466 | |
467 | 467 | return $discount->type; |
468 | 468 | } |
469 | 469 | |
470 | -function wpinv_discount_status( $status ) { |
|
471 | - switch( $status ){ |
|
470 | +function wpinv_discount_status($status) { |
|
471 | + switch ($status) { |
|
472 | 472 | case 'expired' : |
473 | - $name = __( 'Expired', 'invoicing' ); |
|
473 | + $name = __('Expired', 'invoicing'); |
|
474 | 474 | break; |
475 | 475 | case 'publish' : |
476 | 476 | case 'active' : |
477 | - $name = __( 'Active', 'invoicing' ); |
|
477 | + $name = __('Active', 'invoicing'); |
|
478 | 478 | break; |
479 | 479 | default : |
480 | - $name = __( 'Inactive', 'invoicing' ); |
|
480 | + $name = __('Inactive', 'invoicing'); |
|
481 | 481 | break; |
482 | 482 | } |
483 | 483 | return $name; |
@@ -489,8 +489,8 @@ discard block |
||
489 | 489 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
490 | 490 | * @return array |
491 | 491 | */ |
492 | -function wpinv_get_discount_excluded_items( $discount = array() ) { |
|
493 | - $discount = wpinv_get_discount_obj( $discount ); |
|
492 | +function wpinv_get_discount_excluded_items($discount = array()) { |
|
493 | + $discount = wpinv_get_discount_obj($discount); |
|
494 | 494 | return $discount->excluded_items; |
495 | 495 | } |
496 | 496 | |
@@ -500,17 +500,17 @@ discard block |
||
500 | 500 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
501 | 501 | * @return array |
502 | 502 | */ |
503 | -function wpinv_get_discount_item_reqs( $discount = array() ) { |
|
504 | - $discount = wpinv_get_discount_obj( $discount ); |
|
503 | +function wpinv_get_discount_item_reqs($discount = array()) { |
|
504 | + $discount = wpinv_get_discount_obj($discount); |
|
505 | 505 | return $discount->items; |
506 | 506 | } |
507 | 507 | |
508 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
509 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
508 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
509 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
510 | 510 | } |
511 | 511 | |
512 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
513 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
512 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
513 | + return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -519,14 +519,14 @@ discard block |
||
519 | 519 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
520 | 520 | * @return bool |
521 | 521 | */ |
522 | -function wpinv_is_discount_expired( $discount = array(), $silent = false ) { |
|
523 | - $discount = wpinv_get_discount_obj( $discount ); |
|
522 | +function wpinv_is_discount_expired($discount = array(), $silent = false) { |
|
523 | + $discount = wpinv_get_discount_obj($discount); |
|
524 | 524 | |
525 | - if ( $discount->is_expired() ) { |
|
526 | - $discount->update_status( 'pending' ); |
|
525 | + if ($discount->is_expired()) { |
|
526 | + $discount->update_status('pending'); |
|
527 | 527 | |
528 | - if( empty( $silent ) ) { |
|
529 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has expired.', 'invoicing' ) ); |
|
528 | + if (empty($silent)) { |
|
529 | + wpinv_set_error('wpinv-discount-error', __('This discount has expired.', 'invoicing')); |
|
530 | 530 | } |
531 | 531 | return true; |
532 | 532 | } |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
541 | 541 | * @return bool |
542 | 542 | */ |
543 | -function wpinv_is_discount_started( $discount = array() ) { |
|
544 | - $discount = wpinv_get_discount_obj( $discount ); |
|
543 | +function wpinv_is_discount_started($discount = array()) { |
|
544 | + $discount = wpinv_get_discount_obj($discount); |
|
545 | 545 | $started = $discount->has_started(); |
546 | 546 | |
547 | - if( empty( $started ) ) { |
|
548 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
547 | + if (empty($started)) { |
|
548 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | return $started; |
@@ -557,10 +557,10 @@ discard block |
||
557 | 557 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
558 | 558 | * @return bool |
559 | 559 | */ |
560 | -function wpinv_check_discount_dates( $discount ) { |
|
561 | - $discount = wpinv_get_discount_obj( $discount ); |
|
562 | - $return = wpinv_is_discount_started( $discount ) && ! wpinv_is_discount_expired( $discount ); |
|
563 | - return apply_filters( 'wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code ); |
|
560 | +function wpinv_check_discount_dates($discount) { |
|
561 | + $discount = wpinv_get_discount_obj($discount); |
|
562 | + $return = wpinv_is_discount_started($discount) && !wpinv_is_discount_expired($discount); |
|
563 | + return apply_filters('wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -569,12 +569,12 @@ discard block |
||
569 | 569 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
570 | 570 | * @return bool |
571 | 571 | */ |
572 | -function wpinv_is_discount_maxed_out( $discount ) { |
|
573 | - $discount = wpinv_get_discount_obj( $discount ); |
|
572 | +function wpinv_is_discount_maxed_out($discount) { |
|
573 | + $discount = wpinv_get_discount_obj($discount); |
|
574 | 574 | $maxed_out = $discount->has_exceeded_limit(); |
575 | 575 | |
576 | - if ( $maxed_out ) { |
|
577 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
576 | + if ($maxed_out) { |
|
577 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | return $maxed_out; |
@@ -586,13 +586,13 @@ discard block |
||
586 | 586 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
587 | 587 | * @return bool |
588 | 588 | */ |
589 | -function wpinv_discount_is_min_met( $discount ) { |
|
590 | - $discount = wpinv_get_discount_obj( $discount ); |
|
591 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID ); |
|
592 | - $min_met = $discount->is_minimum_amount_met( $cart_amount ); |
|
589 | +function wpinv_discount_is_min_met($discount) { |
|
590 | + $discount = wpinv_get_discount_obj($discount); |
|
591 | + $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID); |
|
592 | + $min_met = $discount->is_minimum_amount_met($cart_amount); |
|
593 | 593 | |
594 | - if ( ! $min_met ) { |
|
595 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->min_total ) ) ) ); |
|
594 | + if (!$min_met) { |
|
595 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->min_total)))); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | return $min_met; |
@@ -604,13 +604,13 @@ discard block |
||
604 | 604 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
605 | 605 | * @return bool |
606 | 606 | */ |
607 | -function wpinv_discount_is_max_met( $discount ) { |
|
608 | - $discount = wpinv_get_discount_obj( $discount ); |
|
609 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID ); |
|
610 | - $max_met = $discount->is_maximum_amount_met( $cart_amount ); |
|
607 | +function wpinv_discount_is_max_met($discount) { |
|
608 | + $discount = wpinv_get_discount_obj($discount); |
|
609 | + $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID); |
|
610 | + $max_met = $discount->is_maximum_amount_met($cart_amount); |
|
611 | 611 | |
612 | - if ( ! $max_met ) { |
|
613 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->max_total ) ) ) ); |
|
612 | + if (!$max_met) { |
|
613 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->max_total)))); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | return $max_met; |
@@ -622,8 +622,8 @@ discard block |
||
622 | 622 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
623 | 623 | * @return bool |
624 | 624 | */ |
625 | -function wpinv_discount_is_single_use( $discount ) { |
|
626 | - $discount = wpinv_get_discount_obj( $discount ); |
|
625 | +function wpinv_discount_is_single_use($discount) { |
|
626 | + $discount = wpinv_get_discount_obj($discount); |
|
627 | 627 | return $discount->is_single_use; |
628 | 628 | } |
629 | 629 | |
@@ -634,53 +634,53 @@ discard block |
||
634 | 634 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
635 | 635 | * @return bool |
636 | 636 | */ |
637 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
637 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
638 | 638 | |
639 | - if( ! empty( $discount ) ) { |
|
640 | - $discount = wpinv_get_discount_obj( $discount ); |
|
639 | + if (!empty($discount)) { |
|
640 | + $discount = wpinv_get_discount_obj($discount); |
|
641 | 641 | } else { |
642 | - $discount = wpinv_get_discount_obj( $code ); |
|
642 | + $discount = wpinv_get_discount_obj($code); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | return $discount->get_is_recurring(); |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
649 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
650 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
651 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
648 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
649 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
650 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
651 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
652 | 652 | $cart_items = wpinv_get_cart_contents(); |
653 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
653 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
654 | 654 | $ret = false; |
655 | 655 | |
656 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
656 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
657 | 657 | $ret = true; |
658 | 658 | } |
659 | 659 | |
660 | 660 | // Normalize our data for item requirements, exclusions and cart data |
661 | 661 | // First absint the items, then sort, and reset the array keys |
662 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
663 | - asort( $item_reqs ); |
|
664 | - $item_reqs = array_values( $item_reqs ); |
|
662 | + $item_reqs = array_map('absint', $item_reqs); |
|
663 | + asort($item_reqs); |
|
664 | + $item_reqs = array_values($item_reqs); |
|
665 | 665 | |
666 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
667 | - asort( $excluded_ps ); |
|
668 | - $excluded_ps = array_values( $excluded_ps ); |
|
666 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
667 | + asort($excluded_ps); |
|
668 | + $excluded_ps = array_values($excluded_ps); |
|
669 | 669 | |
670 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
671 | - asort( $cart_ids ); |
|
672 | - $cart_ids = array_values( $cart_ids ); |
|
670 | + $cart_ids = array_map('absint', $cart_ids); |
|
671 | + asort($cart_ids); |
|
672 | + $cart_ids = array_values($cart_ids); |
|
673 | 673 | |
674 | 674 | // Ensure we have requirements before proceeding |
675 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
676 | - switch( $condition ) { |
|
675 | + if (!$ret && !empty($item_reqs)) { |
|
676 | + switch ($condition) { |
|
677 | 677 | case 'all' : |
678 | 678 | // Default back to true |
679 | 679 | $ret = true; |
680 | 680 | |
681 | - foreach ( $item_reqs as $item_id ) { |
|
682 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
683 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
681 | + foreach ($item_reqs as $item_id) { |
|
682 | + if (!wpinv_item_in_cart($item_id)) { |
|
683 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
684 | 684 | $ret = false; |
685 | 685 | break; |
686 | 686 | } |
@@ -689,15 +689,15 @@ discard block |
||
689 | 689 | break; |
690 | 690 | |
691 | 691 | default : // Any |
692 | - foreach ( $item_reqs as $item_id ) { |
|
693 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
692 | + foreach ($item_reqs as $item_id) { |
|
693 | + if (wpinv_item_in_cart($item_id)) { |
|
694 | 694 | $ret = true; |
695 | 695 | break; |
696 | 696 | } |
697 | 697 | } |
698 | 698 | |
699 | - if( ! $ret ) { |
|
700 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
699 | + if (!$ret) { |
|
700 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | break; |
@@ -706,15 +706,15 @@ discard block |
||
706 | 706 | $ret = true; |
707 | 707 | } |
708 | 708 | |
709 | - if( ! empty( $excluded_ps ) ) { |
|
709 | + if (!empty($excluded_ps)) { |
|
710 | 710 | // Check that there are items other than excluded ones in the cart |
711 | - if( $cart_ids == $excluded_ps ) { |
|
712 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
711 | + if ($cart_ids == $excluded_ps) { |
|
712 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
713 | 713 | $ret = false; |
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
717 | + return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -725,59 +725,59 @@ discard block |
||
725 | 725 | * @param int|array|string|WPInv_Discount $code_id discount data, object, ID or code. |
726 | 726 | * @return bool |
727 | 727 | */ |
728 | -function wpinv_is_discount_used( $discount = array(), $user = '', $code_id = array() ) { |
|
728 | +function wpinv_is_discount_used($discount = array(), $user = '', $code_id = array()) { |
|
729 | 729 | |
730 | - if( ! empty( $discount ) ) { |
|
731 | - $discount = wpinv_get_discount_obj( $discount ); |
|
730 | + if (!empty($discount)) { |
|
731 | + $discount = wpinv_get_discount_obj($discount); |
|
732 | 732 | } else { |
733 | - $discount = wpinv_get_discount_obj( $code_id ); |
|
733 | + $discount = wpinv_get_discount_obj($code_id); |
|
734 | 734 | } |
735 | 735 | |
736 | - $is_used = ! $discount->is_valid_for_user( $user ); |
|
737 | - $is_used = apply_filters( 'wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount ); |
|
736 | + $is_used = !$discount->is_valid_for_user($user); |
|
737 | + $is_used = apply_filters('wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount); |
|
738 | 738 | |
739 | - if( $is_used ) { |
|
740 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
739 | + if ($is_used) { |
|
740 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | return $is_used; |
744 | 744 | } |
745 | 745 | |
746 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
746 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
747 | 747 | |
748 | 748 | // Abort early if there is no discount code. |
749 | - if ( empty( $code ) ) { |
|
749 | + if (empty($code)) { |
|
750 | 750 | return false; |
751 | 751 | } |
752 | 752 | |
753 | 753 | $return = false; |
754 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
755 | - $user = trim( $user ); |
|
754 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
755 | + $user = trim($user); |
|
756 | 756 | |
757 | - if ( wpinv_get_cart_contents() ) { |
|
758 | - if ( $discount_id !== false ) { |
|
757 | + if (wpinv_get_cart_contents()) { |
|
758 | + if ($discount_id !== false) { |
|
759 | 759 | if ( |
760 | - wpinv_is_discount_active( $discount_id ) && |
|
761 | - wpinv_check_discount_dates( $discount_id ) && |
|
762 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
763 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
764 | - wpinv_discount_is_min_met( $discount_id ) && |
|
765 | - wpinv_discount_is_max_met( $discount_id ) && |
|
766 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
760 | + wpinv_is_discount_active($discount_id) && |
|
761 | + wpinv_check_discount_dates($discount_id) && |
|
762 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
763 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
764 | + wpinv_discount_is_min_met($discount_id) && |
|
765 | + wpinv_discount_is_max_met($discount_id) && |
|
766 | + wpinv_discount_item_reqs_met($discount_id) |
|
767 | 767 | ) { |
768 | 768 | $return = true; |
769 | 769 | } |
770 | - } elseif( $set_error ) { |
|
771 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
770 | + } elseif ($set_error) { |
|
771 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
775 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
776 | 776 | } |
777 | 777 | |
778 | -function wpinv_get_discount_id_by_code( $code ) { |
|
779 | - $discount = wpinv_get_discount_by_code( $code ); |
|
780 | - if( $discount ) { |
|
778 | +function wpinv_get_discount_id_by_code($code) { |
|
779 | + $discount = wpinv_get_discount_by_code($code); |
|
780 | + if ($discount) { |
|
781 | 781 | return $discount->ID; |
782 | 782 | } |
783 | 783 | return false; |
@@ -790,9 +790,9 @@ discard block |
||
790 | 790 | * @param float $base_price The number of usages to increase by |
791 | 791 | * @return float |
792 | 792 | */ |
793 | -function wpinv_get_discounted_amount( $discount, $base_price ) { |
|
794 | - $discount = wpinv_get_discount_obj( $discount ); |
|
795 | - return $discount->get_discounted_amount( $base_price ); |
|
793 | +function wpinv_get_discounted_amount($discount, $base_price) { |
|
794 | + $discount = wpinv_get_discount_obj($discount); |
|
795 | + return $discount->get_discounted_amount($base_price); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | /** |
@@ -802,9 +802,9 @@ discard block |
||
802 | 802 | * @param int $by The number of usages to increase by. |
803 | 803 | * @return int the new number of uses. |
804 | 804 | */ |
805 | -function wpinv_increase_discount_usage( $discount, $by = 1 ) { |
|
806 | - $discount = wpinv_get_discount_obj( $discount ); |
|
807 | - return $discount->increase_usage( $by ); |
|
805 | +function wpinv_increase_discount_usage($discount, $by = 1) { |
|
806 | + $discount = wpinv_get_discount_obj($discount); |
|
807 | + return $discount->increase_usage($by); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
@@ -814,72 +814,72 @@ discard block |
||
814 | 814 | * @param int $by The number of usages to decrease by. |
815 | 815 | * @return int the new number of uses. |
816 | 816 | */ |
817 | -function wpinv_decrease_discount_usage( $discount, $by = 1 ) { |
|
818 | - $discount = wpinv_get_discount_obj( $discount ); |
|
819 | - return $discount->increase_usage( 0 - $by ); |
|
817 | +function wpinv_decrease_discount_usage($discount, $by = 1) { |
|
818 | + $discount = wpinv_get_discount_obj($discount); |
|
819 | + return $discount->increase_usage(0 - $by); |
|
820 | 820 | } |
821 | 821 | |
822 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
823 | - if ( $type == 'flat' ) { |
|
824 | - $rate = wpinv_price( wpinv_format_amount( $amount ) ); |
|
822 | +function wpinv_format_discount_rate($type, $amount) { |
|
823 | + if ($type == 'flat') { |
|
824 | + $rate = wpinv_price(wpinv_format_amount($amount)); |
|
825 | 825 | } else { |
826 | 826 | $rate = $amount . '%'; |
827 | 827 | } |
828 | 828 | |
829 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount ); |
|
829 | + return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount); |
|
830 | 830 | } |
831 | 831 | |
832 | -function wpinv_set_cart_discount( $code = '' ) { |
|
833 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
832 | +function wpinv_set_cart_discount($code = '') { |
|
833 | + if (wpinv_multiple_discounts_allowed()) { |
|
834 | 834 | // Get all active cart discounts |
835 | 835 | $discounts = wpinv_get_cart_discounts(); |
836 | 836 | } else { |
837 | 837 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
838 | 838 | } |
839 | 839 | |
840 | - if ( $discounts ) { |
|
841 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
842 | - if( false !== $key ) { |
|
843 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
840 | + if ($discounts) { |
|
841 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
842 | + if (false !== $key) { |
|
843 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
844 | 844 | } |
845 | 845 | $discounts[] = $code; |
846 | 846 | } else { |
847 | 847 | $discounts = array(); |
848 | 848 | $discounts[] = $code; |
849 | 849 | } |
850 | - $discounts = array_values( $discounts ); |
|
850 | + $discounts = array_values($discounts); |
|
851 | 851 | |
852 | 852 | $data = wpinv_get_checkout_session(); |
853 | - if ( empty( $data ) ) { |
|
853 | + if (empty($data)) { |
|
854 | 854 | $data = array(); |
855 | 855 | } else { |
856 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
857 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
858 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
856 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
857 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
858 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
859 | 859 | } |
860 | 860 | } |
861 | 861 | $data['cart_discounts'] = $discounts; |
862 | 862 | |
863 | - wpinv_set_checkout_session( $data ); |
|
863 | + wpinv_set_checkout_session($data); |
|
864 | 864 | |
865 | 865 | return $discounts; |
866 | 866 | } |
867 | 867 | |
868 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
868 | +function wpinv_unset_cart_discount($code = '') { |
|
869 | 869 | $discounts = wpinv_get_cart_discounts(); |
870 | 870 | |
871 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
872 | - $key = array_search( $code, $discounts ); |
|
873 | - unset( $discounts[ $key ] ); |
|
871 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
872 | + $key = array_search($code, $discounts); |
|
873 | + unset($discounts[$key]); |
|
874 | 874 | |
875 | 875 | $data = wpinv_get_checkout_session(); |
876 | 876 | $data['cart_discounts'] = $discounts; |
877 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
878 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
879 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
877 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
878 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
879 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
880 | 880 | } |
881 | 881 | |
882 | - wpinv_set_checkout_session( $data ); |
|
882 | + wpinv_set_checkout_session($data); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | return $discounts; |
@@ -888,10 +888,10 @@ discard block |
||
888 | 888 | function wpinv_unset_all_cart_discounts() { |
889 | 889 | $data = wpinv_get_checkout_session(); |
890 | 890 | |
891 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
892 | - unset( $data['cart_discounts'] ); |
|
891 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
892 | + unset($data['cart_discounts']); |
|
893 | 893 | |
894 | - wpinv_set_checkout_session( $data ); |
|
894 | + wpinv_set_checkout_session($data); |
|
895 | 895 | return true; |
896 | 896 | } |
897 | 897 | |
@@ -900,13 +900,13 @@ discard block |
||
900 | 900 | |
901 | 901 | function wpinv_get_cart_discounts() { |
902 | 902 | $session = wpinv_get_checkout_session(); |
903 | - return empty( $session['cart_discounts'] ) ? false : $session['cart_discounts']; |
|
903 | + return empty($session['cart_discounts']) ? false : $session['cart_discounts']; |
|
904 | 904 | } |
905 | 905 | |
906 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
906 | +function wpinv_cart_has_discounts($items = array()) { |
|
907 | 907 | $ret = false; |
908 | 908 | |
909 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
909 | + if (wpinv_get_cart_discounts($items)) { |
|
910 | 910 | $ret = true; |
911 | 911 | } |
912 | 912 | |
@@ -917,131 +917,131 @@ discard block |
||
917 | 917 | } |
918 | 918 | */ |
919 | 919 | |
920 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
920 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
921 | 921 | } |
922 | 922 | |
923 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
923 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
924 | 924 | $amount = 0.00; |
925 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
925 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
926 | 926 | |
927 | - if ( $items ) { |
|
928 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
927 | + if ($items) { |
|
928 | + $discounts = wp_list_pluck($items, 'discount'); |
|
929 | 929 | |
930 | - if ( is_array( $discounts ) ) { |
|
931 | - $discounts = array_map( 'floatval', $discounts ); |
|
932 | - $amount = array_sum( $discounts ); |
|
930 | + if (is_array($discounts)) { |
|
931 | + $discounts = array_map('floatval', $discounts); |
|
932 | + $amount = array_sum($discounts); |
|
933 | 933 | } |
934 | 934 | } |
935 | 935 | |
936 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
936 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
937 | 937 | } |
938 | 938 | |
939 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
940 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
939 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
940 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
941 | 941 | |
942 | - if ( empty( $discount ) || empty( $items ) ) { |
|
942 | + if (empty($discount) || empty($items)) { |
|
943 | 943 | return 0; |
944 | 944 | } |
945 | 945 | |
946 | 946 | $amount = 0; |
947 | 947 | |
948 | - foreach ( $items as $item ) { |
|
949 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
948 | + foreach ($items as $item) { |
|
949 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
950 | 950 | } |
951 | 951 | |
952 | - $amount = wpinv_round_amount( $amount ); |
|
952 | + $amount = wpinv_round_amount($amount); |
|
953 | 953 | |
954 | 954 | return $amount; |
955 | 955 | } |
956 | 956 | |
957 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
957 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
958 | 958 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
959 | 959 | |
960 | 960 | $amount = 0; |
961 | 961 | |
962 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
962 | + if (empty($item) || empty($item['id'])) { |
|
963 | 963 | return $amount; |
964 | 964 | } |
965 | 965 | |
966 | - if ( empty( $item['quantity'] ) ) { |
|
966 | + if (empty($item['quantity'])) { |
|
967 | 967 | return $amount; |
968 | 968 | } |
969 | 969 | |
970 | - if ( empty( $item['options'] ) ) { |
|
970 | + if (empty($item['options'])) { |
|
971 | 971 | $item['options'] = array(); |
972 | 972 | } |
973 | 973 | |
974 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
974 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
975 | 975 | $discounted_price = $price; |
976 | 976 | |
977 | 977 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
978 | - if ( empty( $discounts ) ) { |
|
978 | + if (empty($discounts)) { |
|
979 | 979 | return $amount; |
980 | 980 | } |
981 | 981 | |
982 | - if ( $discounts ) { |
|
983 | - if ( is_array( $discounts ) ) { |
|
984 | - $discounts = array_values( $discounts ); |
|
982 | + if ($discounts) { |
|
983 | + if (is_array($discounts)) { |
|
984 | + $discounts = array_values($discounts); |
|
985 | 985 | } else { |
986 | - $discounts = explode( ',', $discounts ); |
|
986 | + $discounts = explode(',', $discounts); |
|
987 | 987 | } |
988 | 988 | } |
989 | 989 | |
990 | - if( $discounts ) { |
|
991 | - foreach ( $discounts as $discount ) { |
|
992 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
990 | + if ($discounts) { |
|
991 | + foreach ($discounts as $discount) { |
|
992 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
993 | 993 | |
994 | 994 | // Check discount exists |
995 | - if( $code_id === false ) { |
|
995 | + if ($code_id === false) { |
|
996 | 996 | continue; |
997 | 997 | } |
998 | 998 | |
999 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
1000 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
999 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
1000 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
1001 | 1001 | |
1002 | 1002 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1003 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1004 | - foreach ( $reqs as $item_id ) { |
|
1005 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1006 | - $discounted_price -= wpinv_get_discounted_amount( $discount, $price ); |
|
1003 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1004 | + foreach ($reqs as $item_id) { |
|
1005 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1006 | + $discounted_price -= wpinv_get_discounted_amount($discount, $price); |
|
1007 | 1007 | } |
1008 | 1008 | } |
1009 | 1009 | } else { |
1010 | 1010 | // This is a global cart discount |
1011 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1012 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1011 | + if (!in_array($item['id'], $excluded_items)) { |
|
1012 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1013 | 1013 | $items_subtotal = 0.00; |
1014 | 1014 | $cart_items = wpinv_get_cart_contents(); |
1015 | 1015 | |
1016 | - foreach ( $cart_items as $cart_item ) { |
|
1017 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1018 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1019 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
1016 | + foreach ($cart_items as $cart_item) { |
|
1017 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1018 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1019 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
1020 | 1020 | $items_subtotal += $item_price * $cart_item['quantity']; |
1021 | 1021 | } |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1025 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1024 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1025 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1026 | 1026 | $discounted_amount = $code_amount * $subtotal_percent; |
1027 | 1027 | $discounted_price -= $discounted_amount; |
1028 | 1028 | |
1029 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1029 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1030 | 1030 | |
1031 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1031 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1032 | 1032 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1033 | 1033 | $discounted_price -= $adjustment; |
1034 | 1034 | } |
1035 | 1035 | } else { |
1036 | - $discounted_price -= wpinv_get_discounted_amount( $discount, $price ); |
|
1036 | + $discounted_price -= wpinv_get_discounted_amount($discount, $price); |
|
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | } |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1042 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1043 | 1043 | |
1044 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1044 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1045 | 1045 | $amount = $amount * $item['quantity']; |
1046 | 1046 | } |
1047 | 1047 | } |
@@ -1049,59 +1049,59 @@ discard block |
||
1049 | 1049 | return $amount; |
1050 | 1050 | } |
1051 | 1051 | |
1052 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1053 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1052 | +function wpinv_cart_discounts_html($items = array()) { |
|
1053 | + echo wpinv_get_cart_discounts_html($items); |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1056 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1057 | 1057 | global $wpi_cart_columns; |
1058 | 1058 | |
1059 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1059 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1060 | 1060 | |
1061 | - if ( !$discounts ) { |
|
1062 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1061 | + if (!$discounts) { |
|
1062 | + $discounts = wpinv_get_cart_discounts($items); |
|
1063 | 1063 | } |
1064 | 1064 | |
1065 | - if ( !$discounts ) { |
|
1065 | + if (!$discounts) { |
|
1066 | 1066 | return; |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1069 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1070 | 1070 | |
1071 | 1071 | $html = ''; |
1072 | 1072 | |
1073 | - foreach ( $discounts as $discount ) { |
|
1074 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1075 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1076 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1077 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1078 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1073 | + foreach ($discounts as $discount) { |
|
1074 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1075 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1076 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1077 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1078 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1079 | 1079 | |
1080 | 1080 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1081 | 1081 | ob_start(); |
1082 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1082 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1083 | 1083 | $html .= ob_get_clean(); |
1084 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
1084 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
1085 | 1085 | ob_start(); |
1086 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1086 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1087 | 1087 | $html .= ob_get_clean(); |
1088 | 1088 | $html .= '</tr>'; |
1089 | 1089 | } |
1090 | 1090 | |
1091 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1091 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | -function wpinv_display_cart_discount( /** @scrutinizer ignore-unused */ $formatted = false, $echo = false ) { |
|
1094 | +function wpinv_display_cart_discount(/** @scrutinizer ignore-unused */ $formatted = false, $echo = false) { |
|
1095 | 1095 | $discounts = wpinv_get_cart_discounts(); |
1096 | 1096 | |
1097 | - if ( empty( $discounts ) ) { |
|
1097 | + if (empty($discounts)) { |
|
1098 | 1098 | return false; |
1099 | 1099 | } |
1100 | 1100 | |
1101 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1102 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1101 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1102 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1103 | 1103 | |
1104 | - if ( $echo ) { |
|
1104 | + if ($echo) { |
|
1105 | 1105 | echo $amount; |
1106 | 1106 | } |
1107 | 1107 | |
@@ -1109,65 +1109,65 @@ discard block |
||
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | function wpinv_remove_cart_discount() { |
1112 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1112 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1113 | 1113 | return; |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1116 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1117 | 1117 | |
1118 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1118 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1119 | 1119 | |
1120 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1120 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1121 | 1121 | |
1122 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1122 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1123 | 1123 | } |
1124 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1124 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1125 | 1125 | |
1126 | 1126 | function wpinv_maybe_remove_cart_discount() { |
1127 | 1127 | $discounts = wpinv_get_cart_discounts(); |
1128 | 1128 | |
1129 | - if ( !$discounts ) { |
|
1129 | + if (!$discounts) { |
|
1130 | 1130 | return; |
1131 | 1131 | } |
1132 | 1132 | |
1133 | - $discounts = array_filter( $discounts ); |
|
1134 | - foreach ( $discounts as $discount ) { |
|
1135 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1136 | - wpinv_unset_cart_discount( $discount ); |
|
1133 | + $discounts = array_filter($discounts); |
|
1134 | + foreach ($discounts as $discount) { |
|
1135 | + if (!wpinv_is_discount_valid($discount)) { |
|
1136 | + wpinv_unset_cart_discount($discount); |
|
1137 | 1137 | } |
1138 | 1138 | } |
1139 | 1139 | } |
1140 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1140 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1141 | 1141 | |
1142 | 1142 | function wpinv_multiple_discounts_allowed() { |
1143 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1144 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1143 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1144 | + return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1148 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1149 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1147 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1148 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1149 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1150 | 1150 | |
1151 | - if ( $echo ) { |
|
1151 | + if ($echo) { |
|
1152 | 1152 | echo $label; |
1153 | 1153 | } else { |
1154 | 1154 | return $label; |
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | |
1158 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1159 | - $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code ); |
|
1160 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1158 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1159 | + $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code); |
|
1160 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1161 | 1161 | |
1162 | - if ( $echo ) { |
|
1162 | + if ($echo) { |
|
1163 | 1163 | echo $label; |
1164 | 1164 | } else { |
1165 | 1165 | return $label; |
1166 | 1166 | } |
1167 | 1167 | } |
1168 | 1168 | |
1169 | -function wpinv_check_delete_discount( $check, $post ) { |
|
1170 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1169 | +function wpinv_check_delete_discount($check, $post) { |
|
1170 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1171 | 1171 | return true; |
1172 | 1172 | } |
1173 | 1173 | |
@@ -1178,33 +1178,33 @@ discard block |
||
1178 | 1178 | global $wpi_checkout_id; |
1179 | 1179 | |
1180 | 1180 | $discounts = wpinv_get_cart_discounts(); |
1181 | - $discounts = array_filter( $discounts ); |
|
1181 | + $discounts = array_filter($discounts); |
|
1182 | 1182 | |
1183 | - if ( !empty( $discounts ) ) { |
|
1183 | + if (!empty($discounts)) { |
|
1184 | 1184 | $invalid = false; |
1185 | 1185 | |
1186 | - foreach ( $discounts as $key => $code ) { |
|
1187 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
1186 | + foreach ($discounts as $key => $code) { |
|
1187 | + if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) { |
|
1188 | 1188 | $invalid = true; |
1189 | 1189 | |
1190 | - wpinv_unset_cart_discount( $code ); |
|
1190 | + wpinv_unset_cart_discount($code); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | 1193 | |
1194 | - if ( $invalid ) { |
|
1194 | + if ($invalid) { |
|
1195 | 1195 | $errors = wpinv_get_errors(); |
1196 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1197 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1198 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1196 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1197 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1198 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1199 | 1199 | |
1200 | - wpinv_recalculate_tax( true ); |
|
1200 | + wpinv_recalculate_tax(true); |
|
1201 | 1201 | } |
1202 | 1202 | } |
1203 | 1203 | } |
1204 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1204 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1205 | 1205 | |
1206 | 1206 | function wpinv_discount_amount() { |
1207 | 1207 | $output = 0.00; |
1208 | 1208 | |
1209 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1209 | + return apply_filters('wpinv_discount_amount', $output); |
|
1210 | 1210 | } |
@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Discount extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'discount'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'discount'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Discount Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'status' => 'draft', |
|
40 | - 'version' => '', |
|
41 | - 'date_created' => null, |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'discount'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Discount Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'status' => 'draft', |
|
40 | + 'version' => '', |
|
41 | + 'date_created' => null, |
|
42 | 42 | 'date_modified' => null, |
43 | 43 | 'name' => 'no-name', |
44 | 44 | 'description' => null, |
@@ -58,144 +58,144 @@ discard block |
||
58 | 58 | 'amount' => null, |
59 | 59 | ); |
60 | 60 | |
61 | - /** |
|
62 | - * Stores meta in cache for future reads. |
|
63 | - * |
|
64 | - * A group must be set to to enable caching. |
|
65 | - * |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - protected $cache_group = 'getpaid_discounts'; |
|
61 | + /** |
|
62 | + * Stores meta in cache for future reads. |
|
63 | + * |
|
64 | + * A group must be set to to enable caching. |
|
65 | + * |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + protected $cache_group = 'getpaid_discounts'; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Stores a reference to the original WP_Post object |
72 | 72 | * |
73 | 73 | * @var WP_Post |
74 | 74 | */ |
75 | - protected $post = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
79 | - * |
|
80 | - * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
81 | - */ |
|
82 | - public function __construct( $discount = 0 ) { |
|
83 | - parent::__construct( $discount ); |
|
84 | - |
|
85 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
86 | - $this->set_id( $discount ); |
|
87 | - } elseif ( $discount instanceof self ) { |
|
88 | - $this->set_id( $discount->get_id() ); |
|
89 | - } elseif ( ! empty( $discount->ID ) ) { |
|
90 | - $this->set_id( $discount->ID ); |
|
91 | - } elseif ( is_array( $discount ) ) { |
|
92 | - $this->set_props( $discount ); |
|
93 | - |
|
94 | - if ( isset( $discount['ID'] ) ) { |
|
95 | - $this->set_id( $discount['ID'] ); |
|
96 | - } |
|
97 | - |
|
98 | - } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
99 | - $this->set_id( $discount ); |
|
100 | - } else { |
|
101 | - $this->set_object_read( true ); |
|
102 | - } |
|
75 | + protected $post = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
79 | + * |
|
80 | + * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
81 | + */ |
|
82 | + public function __construct( $discount = 0 ) { |
|
83 | + parent::__construct( $discount ); |
|
84 | + |
|
85 | + if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
86 | + $this->set_id( $discount ); |
|
87 | + } elseif ( $discount instanceof self ) { |
|
88 | + $this->set_id( $discount->get_id() ); |
|
89 | + } elseif ( ! empty( $discount->ID ) ) { |
|
90 | + $this->set_id( $discount->ID ); |
|
91 | + } elseif ( is_array( $discount ) ) { |
|
92 | + $this->set_props( $discount ); |
|
93 | + |
|
94 | + if ( isset( $discount['ID'] ) ) { |
|
95 | + $this->set_id( $discount['ID'] ); |
|
96 | + } |
|
97 | + |
|
98 | + } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
99 | + $this->set_id( $discount ); |
|
100 | + } else { |
|
101 | + $this->set_object_read( true ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | // Load the datastore. |
105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
105 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
106 | 106 | |
107 | - if ( $this->get_id() > 0 ) { |
|
107 | + if ( $this->get_id() > 0 ) { |
|
108 | 108 | $this->post = get_post( $this->get_id() ); |
109 | 109 | $this->ID = $this->get_id(); |
110 | - $this->data_store->read( $this ); |
|
110 | + $this->data_store->read( $this ); |
|
111 | + } |
|
112 | + |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Fetch a discount from the db/cache |
|
117 | + * |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | + * @param string|int $value The field value |
|
122 | + * @deprecated |
|
123 | + * @since 1.0.15 |
|
124 | + * @return array|bool array of discount details on success. False otherwise. |
|
125 | + */ |
|
126 | + public static function get_data_by( $field, $value ) { |
|
127 | + |
|
128 | + if ( 'id' == strtolower( $field ) ) { |
|
129 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | + // to int 1. |
|
131 | + if ( ! is_numeric( $value ) ) |
|
132 | + return false; |
|
133 | + $value = intval( $value ); |
|
134 | + if ( $value < 1 ) |
|
135 | + return false; |
|
136 | + } |
|
137 | + |
|
138 | + if ( ! $value || ! is_string( $field ) ) { |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + $field = trim( $field ); |
|
143 | + |
|
144 | + // prepare query args |
|
145 | + switch ( strtolower( $field ) ) { |
|
146 | + case 'id': |
|
147 | + $discount_id = $value; |
|
148 | + $args = array( 'include' => array( $value ) ); |
|
149 | + break; |
|
150 | + case 'discount_code': |
|
151 | + case 'code': |
|
152 | + $value = trim( $value ); |
|
153 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
154 | + $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
155 | + break; |
|
156 | + case 'name': |
|
157 | + $discount_id = 0; |
|
158 | + $args = array( 'name' => trim( $value ) ); |
|
159 | + break; |
|
160 | + default: |
|
161 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
162 | + if ( ! is_array( $args ) ) { |
|
163 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
164 | + } |
|
165 | + |
|
166 | + } |
|
167 | + |
|
168 | + // Check if there is a cached value. |
|
169 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
170 | + return $discount; |
|
171 | + } |
|
172 | + |
|
173 | + $args = array_merge( |
|
174 | + $args, |
|
175 | + array( |
|
176 | + 'post_type' => 'wpi_discount', |
|
177 | + 'posts_per_page' => 1, |
|
178 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
179 | + ) |
|
180 | + ); |
|
181 | + |
|
182 | + $discount = get_posts( $args ); |
|
183 | + |
|
184 | + if( empty( $discount ) ) { |
|
185 | + return false; |
|
111 | 186 | } |
112 | 187 | |
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Fetch a discount from the db/cache |
|
117 | - * |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | - * @param string|int $value The field value |
|
122 | - * @deprecated |
|
123 | - * @since 1.0.15 |
|
124 | - * @return array|bool array of discount details on success. False otherwise. |
|
125 | - */ |
|
126 | - public static function get_data_by( $field, $value ) { |
|
127 | - |
|
128 | - if ( 'id' == strtolower( $field ) ) { |
|
129 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | - // to int 1. |
|
131 | - if ( ! is_numeric( $value ) ) |
|
132 | - return false; |
|
133 | - $value = intval( $value ); |
|
134 | - if ( $value < 1 ) |
|
135 | - return false; |
|
136 | - } |
|
137 | - |
|
138 | - if ( ! $value || ! is_string( $field ) ) { |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - $field = trim( $field ); |
|
143 | - |
|
144 | - // prepare query args |
|
145 | - switch ( strtolower( $field ) ) { |
|
146 | - case 'id': |
|
147 | - $discount_id = $value; |
|
148 | - $args = array( 'include' => array( $value ) ); |
|
149 | - break; |
|
150 | - case 'discount_code': |
|
151 | - case 'code': |
|
152 | - $value = trim( $value ); |
|
153 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
154 | - $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
155 | - break; |
|
156 | - case 'name': |
|
157 | - $discount_id = 0; |
|
158 | - $args = array( 'name' => trim( $value ) ); |
|
159 | - break; |
|
160 | - default: |
|
161 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
162 | - if ( ! is_array( $args ) ) { |
|
163 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
164 | - } |
|
165 | - |
|
166 | - } |
|
167 | - |
|
168 | - // Check if there is a cached value. |
|
169 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
170 | - return $discount; |
|
171 | - } |
|
172 | - |
|
173 | - $args = array_merge( |
|
174 | - $args, |
|
175 | - array( |
|
176 | - 'post_type' => 'wpi_discount', |
|
177 | - 'posts_per_page' => 1, |
|
178 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
179 | - ) |
|
180 | - ); |
|
181 | - |
|
182 | - $discount = get_posts( $args ); |
|
183 | - |
|
184 | - if( empty( $discount ) ) { |
|
185 | - return false; |
|
186 | - } |
|
187 | - |
|
188 | - $discount = $discount[0]; |
|
189 | - |
|
190 | - // Prepare the return data. |
|
191 | - $return = array( |
|
188 | + $discount = $discount[0]; |
|
189 | + |
|
190 | + // Prepare the return data. |
|
191 | + $return = array( |
|
192 | 192 | 'ID' => $discount->ID, |
193 | 193 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
194 | 194 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
195 | 195 | 'date_created' => $discount->post_date, |
196 | - 'date_modified' => $discount->post_modified, |
|
197 | - 'status' => $discount->post_status, |
|
198 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
196 | + 'date_modified' => $discount->post_modified, |
|
197 | + 'status' => $discount->post_status, |
|
198 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
199 | 199 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
200 | 200 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
201 | 201 | 'description' => $discount->post_excerpt, |
@@ -209,77 +209,77 @@ discard block |
||
209 | 209 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
210 | 210 | ); |
211 | 211 | |
212 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
213 | - |
|
214 | - // Update the cache with our data |
|
215 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
216 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
217 | - |
|
218 | - return $return; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Given a discount code, it returns a discount id. |
|
223 | - * |
|
224 | - * |
|
225 | - * @static |
|
226 | - * @param string $discount_code |
|
227 | - * @since 1.0.15 |
|
228 | - * @return int |
|
229 | - */ |
|
230 | - public static function get_discount_id_by_code( $discount_code ) { |
|
231 | - |
|
232 | - // Trim the code. |
|
233 | - $discount_code = trim( $discount_code ); |
|
234 | - |
|
235 | - // Ensure a value has been passed. |
|
236 | - if ( empty( $discount_code ) ) { |
|
237 | - return 0; |
|
238 | - } |
|
239 | - |
|
240 | - // Maybe retrieve from the cache. |
|
241 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
242 | - if ( ! empty( $discount_id ) ) { |
|
243 | - return $discount_id; |
|
244 | - } |
|
245 | - |
|
246 | - // Fetch the first discount codes. |
|
247 | - $discounts = get_posts( |
|
248 | - array( |
|
249 | - 'meta_key' => '_wpi_discount_code', |
|
250 | - 'meta_value' => $discount_code, |
|
251 | - 'post_type' => 'wpi_discount', |
|
252 | - 'posts_per_page' => 1, |
|
253 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
254 | - 'fields' => 'ids', |
|
255 | - ) |
|
256 | - ); |
|
257 | - |
|
258 | - if ( empty( $discounts ) ) { |
|
259 | - return 0; |
|
260 | - } |
|
261 | - |
|
262 | - $discount_id = $discounts[0]; |
|
263 | - |
|
264 | - // Update the cache with our data |
|
265 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
266 | - |
|
267 | - return $discount_id; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Magic method for checking the existence of a certain custom field. |
|
272 | - * |
|
273 | - * @since 1.0.15 |
|
274 | - * @access public |
|
275 | - * |
|
276 | - * @return bool Whether the given discount field is set. |
|
277 | - */ |
|
278 | - public function __isset( $key ){ |
|
279 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
280 | - } |
|
281 | - |
|
282 | - /* |
|
212 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
213 | + |
|
214 | + // Update the cache with our data |
|
215 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
216 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
217 | + |
|
218 | + return $return; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Given a discount code, it returns a discount id. |
|
223 | + * |
|
224 | + * |
|
225 | + * @static |
|
226 | + * @param string $discount_code |
|
227 | + * @since 1.0.15 |
|
228 | + * @return int |
|
229 | + */ |
|
230 | + public static function get_discount_id_by_code( $discount_code ) { |
|
231 | + |
|
232 | + // Trim the code. |
|
233 | + $discount_code = trim( $discount_code ); |
|
234 | + |
|
235 | + // Ensure a value has been passed. |
|
236 | + if ( empty( $discount_code ) ) { |
|
237 | + return 0; |
|
238 | + } |
|
239 | + |
|
240 | + // Maybe retrieve from the cache. |
|
241 | + $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
242 | + if ( ! empty( $discount_id ) ) { |
|
243 | + return $discount_id; |
|
244 | + } |
|
245 | + |
|
246 | + // Fetch the first discount codes. |
|
247 | + $discounts = get_posts( |
|
248 | + array( |
|
249 | + 'meta_key' => '_wpi_discount_code', |
|
250 | + 'meta_value' => $discount_code, |
|
251 | + 'post_type' => 'wpi_discount', |
|
252 | + 'posts_per_page' => 1, |
|
253 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
254 | + 'fields' => 'ids', |
|
255 | + ) |
|
256 | + ); |
|
257 | + |
|
258 | + if ( empty( $discounts ) ) { |
|
259 | + return 0; |
|
260 | + } |
|
261 | + |
|
262 | + $discount_id = $discounts[0]; |
|
263 | + |
|
264 | + // Update the cache with our data |
|
265 | + wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
266 | + |
|
267 | + return $discount_id; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Magic method for checking the existence of a certain custom field. |
|
272 | + * |
|
273 | + * @since 1.0.15 |
|
274 | + * @access public |
|
275 | + * |
|
276 | + * @return bool Whether the given discount field is set. |
|
277 | + */ |
|
278 | + public function __isset( $key ){ |
|
279 | + return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
280 | + } |
|
281 | + |
|
282 | + /* |
|
283 | 283 | |-------------------------------------------------------------------------- |
284 | 284 | | CRUD methods |
285 | 285 | |-------------------------------------------------------------------------- |
@@ -294,445 +294,445 @@ discard block |
||
294 | 294 | |-------------------------------------------------------------------------- |
295 | 295 | */ |
296 | 296 | |
297 | - /** |
|
298 | - * Get discount status. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param string $context View or edit context. |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function get_status( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'status', $context ); |
|
297 | + /** |
|
298 | + * Get discount status. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param string $context View or edit context. |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function get_status( $context = 'view' ) { |
|
305 | + return $this->get_prop( 'status', $context ); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * Get plugin version when the discount was created. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @param string $context View or edit context. |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function get_version( $context = 'view' ) { |
|
316 | - return $this->get_prop( 'version', $context ); |
|
309 | + * Get plugin version when the discount was created. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @param string $context View or edit context. |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function get_version( $context = 'view' ) { |
|
316 | + return $this->get_prop( 'version', $context ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | - * Get date when the discount was created. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @param string $context View or edit context. |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_date_created( $context = 'view' ) { |
|
327 | - return $this->get_prop( 'date_created', $context ); |
|
320 | + * Get date when the discount was created. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @param string $context View or edit context. |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_date_created( $context = 'view' ) { |
|
327 | + return $this->get_prop( 'date_created', $context ); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
331 | - * Get GMT date when the discount was created. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return string |
|
336 | - */ |
|
337 | - public function get_date_created_gmt( $context = 'view' ) { |
|
331 | + * Get GMT date when the discount was created. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return string |
|
336 | + */ |
|
337 | + public function get_date_created_gmt( $context = 'view' ) { |
|
338 | 338 | $date = $this->get_date_created( $context ); |
339 | 339 | |
340 | 340 | if ( $date ) { |
341 | 341 | $date = get_gmt_from_date( $date ); |
342 | 342 | } |
343 | - return $date; |
|
343 | + return $date; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | - * Get date when the discount was last modified. |
|
348 | - * |
|
349 | - * @since 1.0.19 |
|
350 | - * @param string $context View or edit context. |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function get_date_modified( $context = 'view' ) { |
|
354 | - return $this->get_prop( 'date_modified', $context ); |
|
347 | + * Get date when the discount was last modified. |
|
348 | + * |
|
349 | + * @since 1.0.19 |
|
350 | + * @param string $context View or edit context. |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function get_date_modified( $context = 'view' ) { |
|
354 | + return $this->get_prop( 'date_modified', $context ); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Get GMT date when the discount was last modified. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param string $context View or edit context. |
|
362 | - * @return string |
|
363 | - */ |
|
364 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
358 | + * Get GMT date when the discount was last modified. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param string $context View or edit context. |
|
362 | + * @return string |
|
363 | + */ |
|
364 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
365 | 365 | $date = $this->get_date_modified( $context ); |
366 | 366 | |
367 | 367 | if ( $date ) { |
368 | 368 | $date = get_gmt_from_date( $date ); |
369 | 369 | } |
370 | - return $date; |
|
370 | + return $date; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
374 | - * Get the discount name. |
|
375 | - * |
|
376 | - * @since 1.0.19 |
|
377 | - * @param string $context View or edit context. |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_name( $context = 'view' ) { |
|
381 | - return $this->get_prop( 'name', $context ); |
|
374 | + * Get the discount name. |
|
375 | + * |
|
376 | + * @since 1.0.19 |
|
377 | + * @param string $context View or edit context. |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_name( $context = 'view' ) { |
|
381 | + return $this->get_prop( 'name', $context ); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
385 | - * Alias of self::get_name(). |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - * @param string $context View or edit context. |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_title( $context = 'view' ) { |
|
392 | - return $this->get_name( $context ); |
|
385 | + * Alias of self::get_name(). |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + * @param string $context View or edit context. |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_title( $context = 'view' ) { |
|
392 | + return $this->get_name( $context ); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
396 | - * Get the discount description. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @param string $context View or edit context. |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_description( $context = 'view' ) { |
|
403 | - return $this->get_prop( 'description', $context ); |
|
396 | + * Get the discount description. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @param string $context View or edit context. |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_description( $context = 'view' ) { |
|
403 | + return $this->get_prop( 'description', $context ); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
407 | - * Alias of self::get_description(). |
|
408 | - * |
|
409 | - * @since 1.0.19 |
|
410 | - * @param string $context View or edit context. |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function get_excerpt( $context = 'view' ) { |
|
414 | - return $this->get_description( $context ); |
|
407 | + * Alias of self::get_description(). |
|
408 | + * |
|
409 | + * @since 1.0.19 |
|
410 | + * @param string $context View or edit context. |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function get_excerpt( $context = 'view' ) { |
|
414 | + return $this->get_description( $context ); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | - * Alias of self::get_description(). |
|
419 | - * |
|
420 | - * @since 1.0.19 |
|
421 | - * @param string $context View or edit context. |
|
422 | - * @return string |
|
423 | - */ |
|
424 | - public function get_summary( $context = 'view' ) { |
|
425 | - return $this->get_description( $context ); |
|
418 | + * Alias of self::get_description(). |
|
419 | + * |
|
420 | + * @since 1.0.19 |
|
421 | + * @param string $context View or edit context. |
|
422 | + * @return string |
|
423 | + */ |
|
424 | + public function get_summary( $context = 'view' ) { |
|
425 | + return $this->get_description( $context ); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
429 | - * Get the owner of the discount. |
|
430 | - * |
|
431 | - * @since 1.0.19 |
|
432 | - * @param string $context View or edit context. |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function get_author( $context = 'view' ) { |
|
436 | - return (int) $this->get_prop( 'author', $context ); |
|
437 | - } |
|
429 | + * Get the owner of the discount. |
|
430 | + * |
|
431 | + * @since 1.0.19 |
|
432 | + * @param string $context View or edit context. |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function get_author( $context = 'view' ) { |
|
436 | + return (int) $this->get_prop( 'author', $context ); |
|
437 | + } |
|
438 | 438 | |
439 | - /** |
|
440 | - * Get the discount code. |
|
441 | - * |
|
442 | - * @since 1.0.19 |
|
443 | - * @param string $context View or edit context. |
|
444 | - * @return string |
|
445 | - */ |
|
446 | - public function get_code( $context = 'view' ) { |
|
447 | - return $this->get_prop( 'code', $context ); |
|
448 | - } |
|
439 | + /** |
|
440 | + * Get the discount code. |
|
441 | + * |
|
442 | + * @since 1.0.19 |
|
443 | + * @param string $context View or edit context. |
|
444 | + * @return string |
|
445 | + */ |
|
446 | + public function get_code( $context = 'view' ) { |
|
447 | + return $this->get_prop( 'code', $context ); |
|
448 | + } |
|
449 | 449 | |
450 | - /** |
|
451 | - * Alias for self::get_code(). |
|
452 | - * |
|
453 | - * @since 1.0.19 |
|
454 | - * @param string $context View or edit context. |
|
455 | - * @return string |
|
456 | - */ |
|
457 | - public function get_coupon_code( $context = 'view' ) { |
|
458 | - return $this->get_code( $context ); |
|
459 | - } |
|
450 | + /** |
|
451 | + * Alias for self::get_code(). |
|
452 | + * |
|
453 | + * @since 1.0.19 |
|
454 | + * @param string $context View or edit context. |
|
455 | + * @return string |
|
456 | + */ |
|
457 | + public function get_coupon_code( $context = 'view' ) { |
|
458 | + return $this->get_code( $context ); |
|
459 | + } |
|
460 | 460 | |
461 | - /** |
|
462 | - * Alias for self::get_code(). |
|
463 | - * |
|
464 | - * @since 1.0.19 |
|
465 | - * @param string $context View or edit context. |
|
466 | - * @return string |
|
467 | - */ |
|
468 | - public function get_discount_code( $context = 'view' ) { |
|
469 | - return $this->get_code( $context ); |
|
470 | - } |
|
461 | + /** |
|
462 | + * Alias for self::get_code(). |
|
463 | + * |
|
464 | + * @since 1.0.19 |
|
465 | + * @param string $context View or edit context. |
|
466 | + * @return string |
|
467 | + */ |
|
468 | + public function get_discount_code( $context = 'view' ) { |
|
469 | + return $this->get_code( $context ); |
|
470 | + } |
|
471 | 471 | |
472 | - /** |
|
473 | - * Get the discount's amount. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return float |
|
478 | - */ |
|
479 | - public function get_amount( $context = 'view' ) { |
|
480 | - return $this->get_prop( 'amount', $context ); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the discount's formated amount/rate. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return string |
|
488 | - */ |
|
489 | - public function get_formatted_amount() { |
|
490 | - |
|
491 | - if ( $this->is_type( 'flat' ) ) { |
|
492 | - $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
493 | - } else { |
|
494 | - $rate = $this->get_amount() . '%'; |
|
495 | - } |
|
496 | - |
|
497 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
498 | - } |
|
499 | - |
|
500 | - function wpinv_format_discount_rate( $type, $amount ) { |
|
501 | - if ( $type == 'flat' ) { |
|
502 | - $rate = wpinv_price( wpinv_format_amount( $amount ) ); |
|
503 | - } else { |
|
504 | - $rate = $amount . '%'; |
|
505 | - } |
|
472 | + /** |
|
473 | + * Get the discount's amount. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return float |
|
478 | + */ |
|
479 | + public function get_amount( $context = 'view' ) { |
|
480 | + return $this->get_prop( 'amount', $context ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the discount's formated amount/rate. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return string |
|
488 | + */ |
|
489 | + public function get_formatted_amount() { |
|
490 | + |
|
491 | + if ( $this->is_type( 'flat' ) ) { |
|
492 | + $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
493 | + } else { |
|
494 | + $rate = $this->get_amount() . '%'; |
|
495 | + } |
|
496 | + |
|
497 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
498 | + } |
|
499 | + |
|
500 | + function wpinv_format_discount_rate( $type, $amount ) { |
|
501 | + if ( $type == 'flat' ) { |
|
502 | + $rate = wpinv_price( wpinv_format_amount( $amount ) ); |
|
503 | + } else { |
|
504 | + $rate = $amount . '%'; |
|
505 | + } |
|
506 | 506 | |
507 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount ); |
|
508 | - } |
|
507 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount ); |
|
508 | + } |
|
509 | 509 | |
510 | - /** |
|
511 | - * Get the discount's start date. |
|
512 | - * |
|
513 | - * @since 1.0.19 |
|
514 | - * @param string $context View or edit context. |
|
515 | - * @return string |
|
516 | - */ |
|
517 | - public function get_start( $context = 'view' ) { |
|
518 | - return $this->get_prop( 'start', $context ); |
|
519 | - } |
|
510 | + /** |
|
511 | + * Get the discount's start date. |
|
512 | + * |
|
513 | + * @since 1.0.19 |
|
514 | + * @param string $context View or edit context. |
|
515 | + * @return string |
|
516 | + */ |
|
517 | + public function get_start( $context = 'view' ) { |
|
518 | + return $this->get_prop( 'start', $context ); |
|
519 | + } |
|
520 | 520 | |
521 | - /** |
|
522 | - * Alias for self::get_start(). |
|
523 | - * |
|
524 | - * @since 1.0.19 |
|
525 | - * @param string $context View or edit context. |
|
526 | - * @return string |
|
527 | - */ |
|
528 | - public function get_start_date( $context = 'view' ) { |
|
529 | - return $this->get_start( $context ); |
|
530 | - } |
|
521 | + /** |
|
522 | + * Alias for self::get_start(). |
|
523 | + * |
|
524 | + * @since 1.0.19 |
|
525 | + * @param string $context View or edit context. |
|
526 | + * @return string |
|
527 | + */ |
|
528 | + public function get_start_date( $context = 'view' ) { |
|
529 | + return $this->get_start( $context ); |
|
530 | + } |
|
531 | 531 | |
532 | - /** |
|
533 | - * Get the discount's expiration date. |
|
534 | - * |
|
535 | - * @since 1.0.19 |
|
536 | - * @param string $context View or edit context. |
|
537 | - * @return string |
|
538 | - */ |
|
539 | - public function get_expiration( $context = 'view' ) { |
|
540 | - return $this->get_prop( 'expiration', $context ); |
|
541 | - } |
|
532 | + /** |
|
533 | + * Get the discount's expiration date. |
|
534 | + * |
|
535 | + * @since 1.0.19 |
|
536 | + * @param string $context View or edit context. |
|
537 | + * @return string |
|
538 | + */ |
|
539 | + public function get_expiration( $context = 'view' ) { |
|
540 | + return $this->get_prop( 'expiration', $context ); |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
544 | - * Alias for self::get_expiration(). |
|
545 | - * |
|
546 | - * @since 1.0.19 |
|
547 | - * @param string $context View or edit context. |
|
548 | - * @return string |
|
549 | - */ |
|
550 | - public function get_expiration_date( $context = 'view' ) { |
|
551 | - return $this->get_expiration( $context ); |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Alias for self::get_expiration(). |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - * @param string $context View or edit context. |
|
559 | - * @return string |
|
560 | - */ |
|
561 | - public function get_end_date( $context = 'view' ) { |
|
562 | - return $this->get_expiration( $context ); |
|
563 | - } |
|
543 | + /** |
|
544 | + * Alias for self::get_expiration(). |
|
545 | + * |
|
546 | + * @since 1.0.19 |
|
547 | + * @param string $context View or edit context. |
|
548 | + * @return string |
|
549 | + */ |
|
550 | + public function get_expiration_date( $context = 'view' ) { |
|
551 | + return $this->get_expiration( $context ); |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Alias for self::get_expiration(). |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + * @param string $context View or edit context. |
|
559 | + * @return string |
|
560 | + */ |
|
561 | + public function get_end_date( $context = 'view' ) { |
|
562 | + return $this->get_expiration( $context ); |
|
563 | + } |
|
564 | 564 | |
565 | - /** |
|
566 | - * Get the discount's type. |
|
567 | - * |
|
568 | - * @since 1.0.19 |
|
569 | - * @param string $context View or edit context. |
|
570 | - * @return string |
|
571 | - */ |
|
572 | - public function get_type( $context = 'view' ) { |
|
573 | - return $this->get_prop( 'type', $context ); |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Get the number of times a discount has been used. |
|
578 | - * |
|
579 | - * @since 1.0.19 |
|
580 | - * @param string $context View or edit context. |
|
581 | - * @return int |
|
582 | - */ |
|
583 | - public function get_uses( $context = 'view' ) { |
|
584 | - return (int) $this->get_prop( 'uses', $context ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Get the discount's usage, i.e uses / max uses. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - * @return string |
|
592 | - */ |
|
593 | - public function get_usage() { |
|
594 | - |
|
595 | - if ( ! $this->has_limit() ) { |
|
596 | - return $this->get_uses() . ' / ' . ' ∞'; |
|
597 | - } |
|
598 | - |
|
599 | - return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
600 | - |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Get the maximum number of time a discount can be used. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - * @param string $context View or edit context. |
|
608 | - * @return int |
|
609 | - */ |
|
610 | - public function get_max_uses( $context = 'view' ) { |
|
611 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
612 | - return empty( $max_uses ) ? null : $max_uses; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Checks if this is a single use discount or not. |
|
617 | - * |
|
618 | - * @since 1.0.19 |
|
619 | - * @param string $context View or edit context. |
|
620 | - * @return bool |
|
621 | - */ |
|
622 | - public function get_is_single_use( $context = 'view' ) { |
|
623 | - return $this->get_prop( 'is_single_use', $context ); |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Get the items that can be used with this discount. |
|
628 | - * |
|
629 | - * @since 1.0.19 |
|
630 | - * @param string $context View or edit context. |
|
631 | - * @return array |
|
632 | - */ |
|
633 | - public function get_items( $context = 'view' ) { |
|
634 | - return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Alias for self::get_items(). |
|
639 | - * |
|
640 | - * @since 1.0.19 |
|
641 | - * @param string $context View or edit context. |
|
642 | - * @return array |
|
643 | - */ |
|
644 | - public function get_allowed_items( $context = 'view' ) { |
|
645 | - return $this->get_items( $context ); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Get the items that are not allowed to use this discount. |
|
650 | - * |
|
651 | - * @since 1.0.19 |
|
652 | - * @param string $context View or edit context. |
|
653 | - * @return array |
|
654 | - */ |
|
655 | - public function get_excluded_items( $context = 'view' ) { |
|
656 | - return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Checks if this is a recurring discount or not. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - * @param string $context View or edit context. |
|
664 | - * @return int|string|bool |
|
665 | - */ |
|
666 | - public function get_is_recurring( $context = 'view' ) { |
|
667 | - return $this->get_prop( 'is_recurring', $context ); |
|
668 | - } |
|
669 | - |
|
670 | - /** |
|
671 | - * Get's the minimum total amount allowed for this discount. |
|
672 | - * |
|
673 | - * @since 1.0.19 |
|
674 | - * @param string $context View or edit context. |
|
675 | - * @return float |
|
676 | - */ |
|
677 | - public function get_min_total( $context = 'view' ) { |
|
678 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
679 | - return empty( $minimum ) ? null : $minimum; |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * Alias for self::get_min_total(). |
|
684 | - * |
|
685 | - * @since 1.0.19 |
|
686 | - * @param string $context View or edit context. |
|
687 | - * @return float |
|
688 | - */ |
|
689 | - public function get_minimum_total( $context = 'view' ) { |
|
690 | - return $this->get_min_total( $context ); |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Get's the maximum total amount allowed for this discount. |
|
695 | - * |
|
696 | - * @since 1.0.19 |
|
697 | - * @param string $context View or edit context. |
|
698 | - * @return float |
|
699 | - */ |
|
700 | - public function get_max_total( $context = 'view' ) { |
|
701 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
702 | - return empty( $maximum ) ? null : $maximum; |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * Alias for self::get_max_total(). |
|
707 | - * |
|
708 | - * @since 1.0.19 |
|
709 | - * @param string $context View or edit context. |
|
710 | - * @return float |
|
711 | - */ |
|
712 | - public function get_maximum_total( $context = 'view' ) { |
|
713 | - return $this->get_max_total( $context ); |
|
714 | - } |
|
715 | - |
|
716 | - /** |
|
565 | + /** |
|
566 | + * Get the discount's type. |
|
567 | + * |
|
568 | + * @since 1.0.19 |
|
569 | + * @param string $context View or edit context. |
|
570 | + * @return string |
|
571 | + */ |
|
572 | + public function get_type( $context = 'view' ) { |
|
573 | + return $this->get_prop( 'type', $context ); |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Get the number of times a discount has been used. |
|
578 | + * |
|
579 | + * @since 1.0.19 |
|
580 | + * @param string $context View or edit context. |
|
581 | + * @return int |
|
582 | + */ |
|
583 | + public function get_uses( $context = 'view' ) { |
|
584 | + return (int) $this->get_prop( 'uses', $context ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Get the discount's usage, i.e uses / max uses. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + * @return string |
|
592 | + */ |
|
593 | + public function get_usage() { |
|
594 | + |
|
595 | + if ( ! $this->has_limit() ) { |
|
596 | + return $this->get_uses() . ' / ' . ' ∞'; |
|
597 | + } |
|
598 | + |
|
599 | + return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
600 | + |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Get the maximum number of time a discount can be used. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + * @param string $context View or edit context. |
|
608 | + * @return int |
|
609 | + */ |
|
610 | + public function get_max_uses( $context = 'view' ) { |
|
611 | + $max_uses = $this->get_prop( 'max_uses', $context ); |
|
612 | + return empty( $max_uses ) ? null : $max_uses; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Checks if this is a single use discount or not. |
|
617 | + * |
|
618 | + * @since 1.0.19 |
|
619 | + * @param string $context View or edit context. |
|
620 | + * @return bool |
|
621 | + */ |
|
622 | + public function get_is_single_use( $context = 'view' ) { |
|
623 | + return $this->get_prop( 'is_single_use', $context ); |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * Get the items that can be used with this discount. |
|
628 | + * |
|
629 | + * @since 1.0.19 |
|
630 | + * @param string $context View or edit context. |
|
631 | + * @return array |
|
632 | + */ |
|
633 | + public function get_items( $context = 'view' ) { |
|
634 | + return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Alias for self::get_items(). |
|
639 | + * |
|
640 | + * @since 1.0.19 |
|
641 | + * @param string $context View or edit context. |
|
642 | + * @return array |
|
643 | + */ |
|
644 | + public function get_allowed_items( $context = 'view' ) { |
|
645 | + return $this->get_items( $context ); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Get the items that are not allowed to use this discount. |
|
650 | + * |
|
651 | + * @since 1.0.19 |
|
652 | + * @param string $context View or edit context. |
|
653 | + * @return array |
|
654 | + */ |
|
655 | + public function get_excluded_items( $context = 'view' ) { |
|
656 | + return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Checks if this is a recurring discount or not. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + * @param string $context View or edit context. |
|
664 | + * @return int|string|bool |
|
665 | + */ |
|
666 | + public function get_is_recurring( $context = 'view' ) { |
|
667 | + return $this->get_prop( 'is_recurring', $context ); |
|
668 | + } |
|
669 | + |
|
670 | + /** |
|
671 | + * Get's the minimum total amount allowed for this discount. |
|
672 | + * |
|
673 | + * @since 1.0.19 |
|
674 | + * @param string $context View or edit context. |
|
675 | + * @return float |
|
676 | + */ |
|
677 | + public function get_min_total( $context = 'view' ) { |
|
678 | + $minimum = $this->get_prop( 'min_total', $context ); |
|
679 | + return empty( $minimum ) ? null : $minimum; |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * Alias for self::get_min_total(). |
|
684 | + * |
|
685 | + * @since 1.0.19 |
|
686 | + * @param string $context View or edit context. |
|
687 | + * @return float |
|
688 | + */ |
|
689 | + public function get_minimum_total( $context = 'view' ) { |
|
690 | + return $this->get_min_total( $context ); |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Get's the maximum total amount allowed for this discount. |
|
695 | + * |
|
696 | + * @since 1.0.19 |
|
697 | + * @param string $context View or edit context. |
|
698 | + * @return float |
|
699 | + */ |
|
700 | + public function get_max_total( $context = 'view' ) { |
|
701 | + $maximum = $this->get_prop( 'max_total', $context ); |
|
702 | + return empty( $maximum ) ? null : $maximum; |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * Alias for self::get_max_total(). |
|
707 | + * |
|
708 | + * @since 1.0.19 |
|
709 | + * @param string $context View or edit context. |
|
710 | + * @return float |
|
711 | + */ |
|
712 | + public function get_maximum_total( $context = 'view' ) { |
|
713 | + return $this->get_max_total( $context ); |
|
714 | + } |
|
715 | + |
|
716 | + /** |
|
717 | 717 | * Margic method for retrieving a property. |
718 | 718 | */ |
719 | 719 | public function __get( $key ) { |
720 | 720 | return $this->get( $key ); |
721 | 721 | } |
722 | 722 | |
723 | - /** |
|
724 | - * Magic method for accessing discount properties. |
|
725 | - * |
|
726 | - * @since 1.0.15 |
|
727 | - * @access public |
|
728 | - * |
|
729 | - * @param string $key Discount data to retrieve |
|
730 | - * @param string $context View or edit context. |
|
731 | - * @return mixed Value of the given discount property (if set). |
|
732 | - */ |
|
733 | - public function get( $key, $context = 'view' ) { |
|
723 | + /** |
|
724 | + * Magic method for accessing discount properties. |
|
725 | + * |
|
726 | + * @since 1.0.15 |
|
727 | + * @access public |
|
728 | + * |
|
729 | + * @param string $key Discount data to retrieve |
|
730 | + * @param string $context View or edit context. |
|
731 | + * @return mixed Value of the given discount property (if set). |
|
732 | + */ |
|
733 | + public function get( $key, $context = 'view' ) { |
|
734 | 734 | |
735 | - // Check if we have a helper method for that. |
|
735 | + // Check if we have a helper method for that. |
|
736 | 736 | if ( method_exists( $this, 'get_' . $key ) ) { |
737 | 737 | return call_user_func( array( $this, 'get_' . $key ), $context ); |
738 | 738 | } |
@@ -744,9 +744,9 @@ discard block |
||
744 | 744 | |
745 | 745 | return $this->get_prop( $key, $context ); |
746 | 746 | |
747 | - } |
|
747 | + } |
|
748 | 748 | |
749 | - /* |
|
749 | + /* |
|
750 | 750 | |-------------------------------------------------------------------------- |
751 | 751 | | Setters |
752 | 752 | |-------------------------------------------------------------------------- |
@@ -756,41 +756,41 @@ discard block |
||
756 | 756 | | object. |
757 | 757 | */ |
758 | 758 | |
759 | - /** |
|
760 | - * Sets discount status. |
|
761 | - * |
|
762 | - * @since 1.0.19 |
|
763 | - * @param string $status New status. |
|
764 | - * @return array details of change. |
|
765 | - */ |
|
766 | - public function set_status( $status ) { |
|
759 | + /** |
|
760 | + * Sets discount status. |
|
761 | + * |
|
762 | + * @since 1.0.19 |
|
763 | + * @param string $status New status. |
|
764 | + * @return array details of change. |
|
765 | + */ |
|
766 | + public function set_status( $status ) { |
|
767 | 767 | $old_status = $this->get_status(); |
768 | 768 | |
769 | 769 | $this->set_prop( 'status', $status ); |
770 | 770 | |
771 | - return array( |
|
772 | - 'from' => $old_status, |
|
773 | - 'to' => $status, |
|
774 | - ); |
|
771 | + return array( |
|
772 | + 'from' => $old_status, |
|
773 | + 'to' => $status, |
|
774 | + ); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | /** |
778 | - * Set plugin version when the discount was created. |
|
779 | - * |
|
780 | - * @since 1.0.19 |
|
781 | - */ |
|
782 | - public function set_version( $value ) { |
|
783 | - $this->set_prop( 'version', $value ); |
|
778 | + * Set plugin version when the discount was created. |
|
779 | + * |
|
780 | + * @since 1.0.19 |
|
781 | + */ |
|
782 | + public function set_version( $value ) { |
|
783 | + $this->set_prop( 'version', $value ); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
787 | - * Set date when the discount was created. |
|
788 | - * |
|
789 | - * @since 1.0.19 |
|
790 | - * @param string $value Value to set. |
|
787 | + * Set date when the discount was created. |
|
788 | + * |
|
789 | + * @since 1.0.19 |
|
790 | + * @param string $value Value to set. |
|
791 | 791 | * @return bool Whether or not the date was set. |
792 | - */ |
|
793 | - public function set_date_created( $value ) { |
|
792 | + */ |
|
793 | + public function set_date_created( $value ) { |
|
794 | 794 | $date = strtotime( $value ); |
795 | 795 | |
796 | 796 | if ( $date ) { |
@@ -803,13 +803,13 @@ discard block |
||
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
806 | - * Set date when the discount was last modified. |
|
807 | - * |
|
808 | - * @since 1.0.19 |
|
809 | - * @param string $value Value to set. |
|
806 | + * Set date when the discount was last modified. |
|
807 | + * |
|
808 | + * @since 1.0.19 |
|
809 | + * @param string $value Value to set. |
|
810 | 810 | * @return bool Whether or not the date was set. |
811 | - */ |
|
812 | - public function set_date_modified( $value ) { |
|
811 | + */ |
|
812 | + public function set_date_modified( $value ) { |
|
813 | 813 | $date = strtotime( $value ); |
814 | 814 | |
815 | 815 | if ( $date ) { |
@@ -822,347 +822,347 @@ discard block |
||
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
825 | - * Set the discount name. |
|
826 | - * |
|
827 | - * @since 1.0.19 |
|
828 | - * @param string $value New name. |
|
829 | - */ |
|
830 | - public function set_name( $value ) { |
|
825 | + * Set the discount name. |
|
826 | + * |
|
827 | + * @since 1.0.19 |
|
828 | + * @param string $value New name. |
|
829 | + */ |
|
830 | + public function set_name( $value ) { |
|
831 | 831 | $name = sanitize_text_field( $value ); |
832 | - $this->set_prop( 'name', $name ); |
|
832 | + $this->set_prop( 'name', $name ); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
836 | - * Alias of self::set_name(). |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - * @param string $value New name. |
|
840 | - */ |
|
841 | - public function set_title( $value ) { |
|
842 | - $this->set_name( $value ); |
|
836 | + * Alias of self::set_name(). |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + * @param string $value New name. |
|
840 | + */ |
|
841 | + public function set_title( $value ) { |
|
842 | + $this->set_name( $value ); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Set the discount description. |
|
847 | - * |
|
848 | - * @since 1.0.19 |
|
849 | - * @param string $value New description. |
|
850 | - */ |
|
851 | - public function set_description( $value ) { |
|
846 | + * Set the discount description. |
|
847 | + * |
|
848 | + * @since 1.0.19 |
|
849 | + * @param string $value New description. |
|
850 | + */ |
|
851 | + public function set_description( $value ) { |
|
852 | 852 | $description = wp_kses_post( $value ); |
853 | - return $this->set_prop( 'description', $description ); |
|
853 | + return $this->set_prop( 'description', $description ); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
857 | - * Alias of self::set_description(). |
|
858 | - * |
|
859 | - * @since 1.0.19 |
|
860 | - * @param string $value New description. |
|
861 | - */ |
|
862 | - public function set_excerpt( $value ) { |
|
863 | - $this->set_description( $value ); |
|
857 | + * Alias of self::set_description(). |
|
858 | + * |
|
859 | + * @since 1.0.19 |
|
860 | + * @param string $value New description. |
|
861 | + */ |
|
862 | + public function set_excerpt( $value ) { |
|
863 | + $this->set_description( $value ); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
867 | - * Alias of self::set_description(). |
|
868 | - * |
|
869 | - * @since 1.0.19 |
|
870 | - * @param string $value New description. |
|
871 | - */ |
|
872 | - public function set_summary( $value ) { |
|
873 | - $this->set_description( $value ); |
|
867 | + * Alias of self::set_description(). |
|
868 | + * |
|
869 | + * @since 1.0.19 |
|
870 | + * @param string $value New description. |
|
871 | + */ |
|
872 | + public function set_summary( $value ) { |
|
873 | + $this->set_description( $value ); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
877 | - * Set the owner of the discount. |
|
878 | - * |
|
879 | - * @since 1.0.19 |
|
880 | - * @param int $value New author. |
|
881 | - */ |
|
882 | - public function set_author( $value ) { |
|
883 | - $this->set_prop( 'author', (int) $value ); |
|
884 | - } |
|
877 | + * Set the owner of the discount. |
|
878 | + * |
|
879 | + * @since 1.0.19 |
|
880 | + * @param int $value New author. |
|
881 | + */ |
|
882 | + public function set_author( $value ) { |
|
883 | + $this->set_prop( 'author', (int) $value ); |
|
884 | + } |
|
885 | 885 | |
886 | - /** |
|
887 | - * Sets the discount code. |
|
888 | - * |
|
889 | - * @since 1.0.19 |
|
890 | - * @param string $value New discount code. |
|
891 | - */ |
|
892 | - public function set_code( $value ) { |
|
893 | - $code = sanitize_text_field( $value ); |
|
894 | - $this->set_prop( 'code', $code ); |
|
895 | - } |
|
886 | + /** |
|
887 | + * Sets the discount code. |
|
888 | + * |
|
889 | + * @since 1.0.19 |
|
890 | + * @param string $value New discount code. |
|
891 | + */ |
|
892 | + public function set_code( $value ) { |
|
893 | + $code = sanitize_text_field( $value ); |
|
894 | + $this->set_prop( 'code', $code ); |
|
895 | + } |
|
896 | 896 | |
897 | - /** |
|
898 | - * Alias of self::set_code(). |
|
899 | - * |
|
900 | - * @since 1.0.19 |
|
901 | - * @param string $value New discount code. |
|
902 | - */ |
|
903 | - public function set_coupon_code( $value ) { |
|
904 | - $this->set_code( $value ); |
|
905 | - } |
|
897 | + /** |
|
898 | + * Alias of self::set_code(). |
|
899 | + * |
|
900 | + * @since 1.0.19 |
|
901 | + * @param string $value New discount code. |
|
902 | + */ |
|
903 | + public function set_coupon_code( $value ) { |
|
904 | + $this->set_code( $value ); |
|
905 | + } |
|
906 | 906 | |
907 | - /** |
|
908 | - * Alias of self::set_code(). |
|
909 | - * |
|
910 | - * @since 1.0.19 |
|
911 | - * @param string $value New discount code. |
|
912 | - */ |
|
913 | - public function set_discount_code( $value ) { |
|
914 | - $this->set_code( $value ); |
|
915 | - } |
|
907 | + /** |
|
908 | + * Alias of self::set_code(). |
|
909 | + * |
|
910 | + * @since 1.0.19 |
|
911 | + * @param string $value New discount code. |
|
912 | + */ |
|
913 | + public function set_discount_code( $value ) { |
|
914 | + $this->set_code( $value ); |
|
915 | + } |
|
916 | 916 | |
917 | - /** |
|
918 | - * Sets the discount amount. |
|
919 | - * |
|
920 | - * @since 1.0.19 |
|
921 | - * @param float $value New discount code. |
|
922 | - */ |
|
923 | - public function set_amount( $value ) { |
|
924 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
925 | - $this->set_prop( 'amount', $amount ); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Sets the discount's start date. |
|
930 | - * |
|
931 | - * @since 1.0.19 |
|
932 | - * @param float $value New start date. |
|
933 | - */ |
|
934 | - public function set_start( $value ) { |
|
935 | - $date = strtotime( $value ); |
|
936 | - |
|
937 | - if ( $date ) { |
|
938 | - $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
917 | + /** |
|
918 | + * Sets the discount amount. |
|
919 | + * |
|
920 | + * @since 1.0.19 |
|
921 | + * @param float $value New discount code. |
|
922 | + */ |
|
923 | + public function set_amount( $value ) { |
|
924 | + $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
925 | + $this->set_prop( 'amount', $amount ); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * Sets the discount's start date. |
|
930 | + * |
|
931 | + * @since 1.0.19 |
|
932 | + * @param float $value New start date. |
|
933 | + */ |
|
934 | + public function set_start( $value ) { |
|
935 | + $date = strtotime( $value ); |
|
936 | + |
|
937 | + if ( $date ) { |
|
938 | + $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
939 | 939 | return true; |
940 | - } |
|
940 | + } |
|
941 | 941 | |
942 | - $this->set_prop( 'start', '' ); |
|
942 | + $this->set_prop( 'start', '' ); |
|
943 | 943 | |
944 | 944 | return false; |
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Alias of self::set_start(). |
|
949 | - * |
|
950 | - * @since 1.0.19 |
|
951 | - * @param string $value New start date. |
|
952 | - */ |
|
953 | - public function set_start_date( $value ) { |
|
954 | - $this->set_start( $value ); |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * Sets the discount's expiration date. |
|
959 | - * |
|
960 | - * @since 1.0.19 |
|
961 | - * @param float $value New expiration date. |
|
962 | - */ |
|
963 | - public function set_expiration( $value ) { |
|
964 | - $date = strtotime( $value ); |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Alias of self::set_start(). |
|
949 | + * |
|
950 | + * @since 1.0.19 |
|
951 | + * @param string $value New start date. |
|
952 | + */ |
|
953 | + public function set_start_date( $value ) { |
|
954 | + $this->set_start( $value ); |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * Sets the discount's expiration date. |
|
959 | + * |
|
960 | + * @since 1.0.19 |
|
961 | + * @param float $value New expiration date. |
|
962 | + */ |
|
963 | + public function set_expiration( $value ) { |
|
964 | + $date = strtotime( $value ); |
|
965 | 965 | |
966 | 966 | if ( $date ) { |
967 | 967 | $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
968 | 968 | return true; |
969 | 969 | } |
970 | 970 | |
971 | - $this->set_prop( 'expiration', '' ); |
|
971 | + $this->set_prop( 'expiration', '' ); |
|
972 | 972 | return false; |
973 | - } |
|
974 | - |
|
975 | - /** |
|
976 | - * Alias of self::set_expiration(). |
|
977 | - * |
|
978 | - * @since 1.0.19 |
|
979 | - * @param string $value New expiration date. |
|
980 | - */ |
|
981 | - public function set_expiration_date( $value ) { |
|
982 | - $this->set_expiration( $value ); |
|
983 | - } |
|
984 | - |
|
985 | - /** |
|
986 | - * Alias of self::set_expiration(). |
|
987 | - * |
|
988 | - * @since 1.0.19 |
|
989 | - * @param string $value New expiration date. |
|
990 | - */ |
|
991 | - public function set_end_date( $value ) { |
|
992 | - $this->set_expiration( $value ); |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * Sets the discount type. |
|
997 | - * |
|
998 | - * @since 1.0.19 |
|
999 | - * @param string $value New discount type. |
|
1000 | - */ |
|
1001 | - public function set_type( $value ) { |
|
1002 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
1003 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
1004 | - } |
|
1005 | - } |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * Sets the number of times a discount has been used. |
|
1009 | - * |
|
1010 | - * @since 1.0.19 |
|
1011 | - * @param int $value usage count. |
|
1012 | - */ |
|
1013 | - public function set_uses( $value ) { |
|
1014 | - |
|
1015 | - $value = (int) $value; |
|
1016 | - |
|
1017 | - if ( $value < 0 ) { |
|
1018 | - $value = 0; |
|
1019 | - } |
|
1020 | - |
|
1021 | - $this->set_prop( 'uses', (int) $value ); |
|
1022 | - } |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * Sets the maximum number of times a discount can be used. |
|
1026 | - * |
|
1027 | - * @since 1.0.19 |
|
1028 | - * @param int $value maximum usage count. |
|
1029 | - */ |
|
1030 | - public function set_max_uses( $value ) { |
|
1031 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1032 | - } |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * Sets if this is a single use discount or not. |
|
1036 | - * |
|
1037 | - * @since 1.0.19 |
|
1038 | - * @param int|bool $value is single use. |
|
1039 | - */ |
|
1040 | - public function set_is_single_use( $value ) { |
|
1041 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1042 | - } |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Sets the items that can be used with this discount. |
|
1046 | - * |
|
1047 | - * @since 1.0.19 |
|
1048 | - * @param array $value items. |
|
1049 | - */ |
|
1050 | - public function set_items( $value ) { |
|
1051 | - $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
1052 | - } |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * Alias for self::set_items(). |
|
1056 | - * |
|
1057 | - * @since 1.0.19 |
|
1058 | - * @param array $value items. |
|
1059 | - */ |
|
1060 | - public function set_allowed_items( $value ) { |
|
1061 | - $this->set_items( $value ); |
|
1062 | - } |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * Sets the items that can not be used with this discount. |
|
1066 | - * |
|
1067 | - * @since 1.0.19 |
|
1068 | - * @param array $value items. |
|
1069 | - */ |
|
1070 | - public function set_excluded_items( $value ) { |
|
1071 | - $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
1072 | - } |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * Sets if this is a recurring discounts or not. |
|
1076 | - * |
|
1077 | - * @since 1.0.19 |
|
1078 | - * @param int|bool $value is recurring. |
|
1079 | - */ |
|
1080 | - public function set_is_recurring( $value ) { |
|
1081 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1082 | - } |
|
1083 | - |
|
1084 | - /** |
|
1085 | - * Sets the minimum total that can not be used with this discount. |
|
1086 | - * |
|
1087 | - * @since 1.0.19 |
|
1088 | - * @param float $value minimum total. |
|
1089 | - */ |
|
1090 | - public function set_min_total( $value ) { |
|
1091 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1092 | - } |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Alias for self::set_min_total(). |
|
1096 | - * |
|
1097 | - * @since 1.0.19 |
|
1098 | - * @param float $value minimum total. |
|
1099 | - */ |
|
1100 | - public function set_minimum_total( $value ) { |
|
1101 | - $this->set_min_total( $value ); |
|
1102 | - } |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * Sets the maximum total that can not be used with this discount. |
|
1106 | - * |
|
1107 | - * @since 1.0.19 |
|
1108 | - * @param float $value maximum total. |
|
1109 | - */ |
|
1110 | - public function set_max_total( $value ) { |
|
1111 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * Alias for self::set_max_total(). |
|
1116 | - * |
|
1117 | - * @since 1.0.19 |
|
1118 | - * @param float $value maximum total. |
|
1119 | - */ |
|
1120 | - public function set_maximum_total( $value ) { |
|
1121 | - $this->set_max_total( $value ); |
|
1122 | - } |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * Magic method for setting discount fields. |
|
1126 | - * |
|
1127 | - * This method does not update custom fields in the database. |
|
1128 | - * |
|
1129 | - * @since 1.0.15 |
|
1130 | - * @access public |
|
1131 | - * |
|
1132 | - */ |
|
1133 | - public function __set( $key, $value ) { |
|
1134 | - |
|
1135 | - if ( 'id' == strtolower( $key ) ) { |
|
1136 | - return $this->set_id( $value ); |
|
1137 | - } |
|
1138 | - |
|
1139 | - if ( method_exists( $this, "set_$key") ) { |
|
1140 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
1141 | - } else { |
|
1142 | - $this->set_prop( $key, $value ); |
|
1143 | - } |
|
1144 | - |
|
1145 | - } |
|
1146 | - |
|
1147 | - /** |
|
1148 | - * @deprecated |
|
1149 | - */ |
|
1150 | - public function refresh(){} |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * @deprecated |
|
1154 | - * |
|
1155 | - */ |
|
1156 | - public function update_status( $status = 'publish' ){ |
|
1157 | - |
|
1158 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1159 | - $this->set_status( $status ); |
|
1160 | - $this->save(); |
|
1161 | - } |
|
1162 | - |
|
1163 | - } |
|
1164 | - |
|
1165 | - /* |
|
973 | + } |
|
974 | + |
|
975 | + /** |
|
976 | + * Alias of self::set_expiration(). |
|
977 | + * |
|
978 | + * @since 1.0.19 |
|
979 | + * @param string $value New expiration date. |
|
980 | + */ |
|
981 | + public function set_expiration_date( $value ) { |
|
982 | + $this->set_expiration( $value ); |
|
983 | + } |
|
984 | + |
|
985 | + /** |
|
986 | + * Alias of self::set_expiration(). |
|
987 | + * |
|
988 | + * @since 1.0.19 |
|
989 | + * @param string $value New expiration date. |
|
990 | + */ |
|
991 | + public function set_end_date( $value ) { |
|
992 | + $this->set_expiration( $value ); |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * Sets the discount type. |
|
997 | + * |
|
998 | + * @since 1.0.19 |
|
999 | + * @param string $value New discount type. |
|
1000 | + */ |
|
1001 | + public function set_type( $value ) { |
|
1002 | + if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
1003 | + $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
1004 | + } |
|
1005 | + } |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * Sets the number of times a discount has been used. |
|
1009 | + * |
|
1010 | + * @since 1.0.19 |
|
1011 | + * @param int $value usage count. |
|
1012 | + */ |
|
1013 | + public function set_uses( $value ) { |
|
1014 | + |
|
1015 | + $value = (int) $value; |
|
1016 | + |
|
1017 | + if ( $value < 0 ) { |
|
1018 | + $value = 0; |
|
1019 | + } |
|
1020 | + |
|
1021 | + $this->set_prop( 'uses', (int) $value ); |
|
1022 | + } |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * Sets the maximum number of times a discount can be used. |
|
1026 | + * |
|
1027 | + * @since 1.0.19 |
|
1028 | + * @param int $value maximum usage count. |
|
1029 | + */ |
|
1030 | + public function set_max_uses( $value ) { |
|
1031 | + $this->set_prop( 'max_uses', absint( $value ) ); |
|
1032 | + } |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * Sets if this is a single use discount or not. |
|
1036 | + * |
|
1037 | + * @since 1.0.19 |
|
1038 | + * @param int|bool $value is single use. |
|
1039 | + */ |
|
1040 | + public function set_is_single_use( $value ) { |
|
1041 | + $this->set_prop( 'is_single_use', (bool) $value ); |
|
1042 | + } |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Sets the items that can be used with this discount. |
|
1046 | + * |
|
1047 | + * @since 1.0.19 |
|
1048 | + * @param array $value items. |
|
1049 | + */ |
|
1050 | + public function set_items( $value ) { |
|
1051 | + $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
1052 | + } |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * Alias for self::set_items(). |
|
1056 | + * |
|
1057 | + * @since 1.0.19 |
|
1058 | + * @param array $value items. |
|
1059 | + */ |
|
1060 | + public function set_allowed_items( $value ) { |
|
1061 | + $this->set_items( $value ); |
|
1062 | + } |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * Sets the items that can not be used with this discount. |
|
1066 | + * |
|
1067 | + * @since 1.0.19 |
|
1068 | + * @param array $value items. |
|
1069 | + */ |
|
1070 | + public function set_excluded_items( $value ) { |
|
1071 | + $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
1072 | + } |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * Sets if this is a recurring discounts or not. |
|
1076 | + * |
|
1077 | + * @since 1.0.19 |
|
1078 | + * @param int|bool $value is recurring. |
|
1079 | + */ |
|
1080 | + public function set_is_recurring( $value ) { |
|
1081 | + $this->set_prop( 'is_recurring', (bool) $value ); |
|
1082 | + } |
|
1083 | + |
|
1084 | + /** |
|
1085 | + * Sets the minimum total that can not be used with this discount. |
|
1086 | + * |
|
1087 | + * @since 1.0.19 |
|
1088 | + * @param float $value minimum total. |
|
1089 | + */ |
|
1090 | + public function set_min_total( $value ) { |
|
1091 | + $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1092 | + } |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Alias for self::set_min_total(). |
|
1096 | + * |
|
1097 | + * @since 1.0.19 |
|
1098 | + * @param float $value minimum total. |
|
1099 | + */ |
|
1100 | + public function set_minimum_total( $value ) { |
|
1101 | + $this->set_min_total( $value ); |
|
1102 | + } |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * Sets the maximum total that can not be used with this discount. |
|
1106 | + * |
|
1107 | + * @since 1.0.19 |
|
1108 | + * @param float $value maximum total. |
|
1109 | + */ |
|
1110 | + public function set_max_total( $value ) { |
|
1111 | + $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * Alias for self::set_max_total(). |
|
1116 | + * |
|
1117 | + * @since 1.0.19 |
|
1118 | + * @param float $value maximum total. |
|
1119 | + */ |
|
1120 | + public function set_maximum_total( $value ) { |
|
1121 | + $this->set_max_total( $value ); |
|
1122 | + } |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * Magic method for setting discount fields. |
|
1126 | + * |
|
1127 | + * This method does not update custom fields in the database. |
|
1128 | + * |
|
1129 | + * @since 1.0.15 |
|
1130 | + * @access public |
|
1131 | + * |
|
1132 | + */ |
|
1133 | + public function __set( $key, $value ) { |
|
1134 | + |
|
1135 | + if ( 'id' == strtolower( $key ) ) { |
|
1136 | + return $this->set_id( $value ); |
|
1137 | + } |
|
1138 | + |
|
1139 | + if ( method_exists( $this, "set_$key") ) { |
|
1140 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
1141 | + } else { |
|
1142 | + $this->set_prop( $key, $value ); |
|
1143 | + } |
|
1144 | + |
|
1145 | + } |
|
1146 | + |
|
1147 | + /** |
|
1148 | + * @deprecated |
|
1149 | + */ |
|
1150 | + public function refresh(){} |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * @deprecated |
|
1154 | + * |
|
1155 | + */ |
|
1156 | + public function update_status( $status = 'publish' ){ |
|
1157 | + |
|
1158 | + if ( $this->exists() && $this->get_status() != $status ) { |
|
1159 | + $this->set_status( $status ); |
|
1160 | + $this->save(); |
|
1161 | + } |
|
1162 | + |
|
1163 | + } |
|
1164 | + |
|
1165 | + /* |
|
1166 | 1166 | |-------------------------------------------------------------------------- |
1167 | 1167 | | Conditionals |
1168 | 1168 | |-------------------------------------------------------------------------- |
@@ -1171,263 +1171,263 @@ discard block |
||
1171 | 1171 | | |
1172 | 1172 | */ |
1173 | 1173 | |
1174 | - /** |
|
1175 | - * Checks whether a discount exists in the database or not |
|
1176 | - * |
|
1177 | - * @since 1.0.15 |
|
1178 | - */ |
|
1179 | - public function exists(){ |
|
1180 | - $id = $this->get_id(); |
|
1181 | - return ! empty( $id ); |
|
1182 | - } |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Checks the discount type. |
|
1186 | - * |
|
1187 | - * |
|
1188 | - * @param string $type the discount type to check against |
|
1189 | - * @since 1.0.15 |
|
1190 | - * @return bool |
|
1191 | - */ |
|
1192 | - public function is_type( $type ) { |
|
1193 | - return $this->get_type() == $type; |
|
1194 | - } |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Checks whether the discount is published or not |
|
1198 | - * |
|
1199 | - * @since 1.0.15 |
|
1200 | - * @return bool |
|
1201 | - */ |
|
1202 | - public function is_active() { |
|
1203 | - return $this->get_status() == 'publish'; |
|
1204 | - } |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * Checks whether the discount has max uses |
|
1208 | - * |
|
1209 | - * @since 1.0.15 |
|
1210 | - * @return bool |
|
1211 | - */ |
|
1212 | - public function has_limit() { |
|
1213 | - $limit = $this->get_max_uses(); |
|
1214 | - return ! empty( $limit ); |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * Checks whether the discount has ever been used. |
|
1219 | - * |
|
1220 | - * @since 1.0.15 |
|
1221 | - * @return bool |
|
1222 | - */ |
|
1223 | - public function has_uses() { |
|
1224 | - return $this->get_uses() > 0; |
|
1225 | - } |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Checks whether the discount is has exided the usage limit or not |
|
1229 | - * |
|
1230 | - * @since 1.0.15 |
|
1231 | - * @return bool |
|
1232 | - */ |
|
1233 | - public function has_exceeded_limit() { |
|
1234 | - |
|
1235 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1236 | - $exceeded = false ; |
|
1237 | - } else { |
|
1238 | - $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
1239 | - } |
|
1240 | - |
|
1241 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code ); |
|
1242 | - } |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * Checks whether the discount has an expiration date. |
|
1246 | - * |
|
1247 | - * @since 1.0.15 |
|
1248 | - * @return bool |
|
1249 | - */ |
|
1250 | - public function has_expiration_date() { |
|
1251 | - $date = $this->get_expiration_date(); |
|
1252 | - return ! empty( $date ); |
|
1253 | - } |
|
1254 | - |
|
1255 | - /** |
|
1256 | - * Checks if the discount is expired |
|
1257 | - * |
|
1258 | - * @since 1.0.15 |
|
1259 | - * @return bool |
|
1260 | - */ |
|
1261 | - public function is_expired() { |
|
1262 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1263 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code ); |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * Checks whether the discount has a start date. |
|
1268 | - * |
|
1269 | - * @since 1.0.15 |
|
1270 | - * @return bool |
|
1271 | - */ |
|
1272 | - public function has_start_date() { |
|
1273 | - $date = $this->get_start_date(); |
|
1274 | - return ! empty( $date ); |
|
1275 | - } |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * Checks the discount start date. |
|
1279 | - * |
|
1280 | - * @since 1.0.15 |
|
1281 | - * @return bool |
|
1282 | - */ |
|
1283 | - public function has_started() { |
|
1284 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1285 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code ); |
|
1286 | - } |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * Checks the discount has allowed items or not. |
|
1290 | - * |
|
1291 | - * @since 1.0.15 |
|
1292 | - * @return bool |
|
1293 | - */ |
|
1294 | - public function has_allowed_items() { |
|
1295 | - $allowed_items = $this->get_allowed_items(); |
|
1296 | - return empty( $allowed_items ); |
|
1297 | - } |
|
1298 | - |
|
1299 | - /** |
|
1300 | - * Checks the discount has excluded items or not. |
|
1301 | - * |
|
1302 | - * @since 1.0.15 |
|
1303 | - * @return bool |
|
1304 | - */ |
|
1305 | - public function has_excluded_items() { |
|
1306 | - $excluded_items = $this->get_excluded_items(); |
|
1307 | - return empty( $excluded_items ); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Check if a discount is valid for a given item id. |
|
1312 | - * |
|
1313 | - * @param int|int[] $item_ids |
|
1314 | - * @since 1.0.15 |
|
1315 | - * @return boolean |
|
1316 | - */ |
|
1317 | - public function is_valid_for_items( $item_ids ) { |
|
1318 | - |
|
1319 | - $item_ids = array_map( 'intval', wpinv_parse_list( $item_ids ) ); |
|
1320 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1321 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1322 | - |
|
1323 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1324 | - return false; |
|
1325 | - } |
|
1326 | - |
|
1327 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1328 | - return false; |
|
1329 | - } |
|
1330 | - return true; |
|
1331 | - } |
|
1332 | - |
|
1333 | - /** |
|
1334 | - * Check if a discount is valid for the given amount |
|
1335 | - * |
|
1336 | - * @param float $amount The amount to check against |
|
1337 | - * @since 1.0.15 |
|
1338 | - * @return boolean |
|
1339 | - */ |
|
1340 | - public function is_valid_for_amount( $amount ) { |
|
1341 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * Checks if the minimum amount is set |
|
1346 | - * |
|
1347 | - * @since 1.0.15 |
|
1348 | - * @return boolean |
|
1349 | - */ |
|
1350 | - public function has_minimum_amount() { |
|
1351 | - $minimum = $this->get_minimum_total(); |
|
1352 | - return ! empty( $minimum ); |
|
1353 | - } |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * Checks if the minimum amount is met |
|
1357 | - * |
|
1358 | - * @param float $amount The amount to check against |
|
1359 | - * @since 1.0.15 |
|
1360 | - * @return boolean |
|
1361 | - */ |
|
1362 | - public function is_minimum_amount_met( $amount ) { |
|
1363 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1364 | - $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1365 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount ); |
|
1366 | - } |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * Checks if the maximum amount is set |
|
1370 | - * |
|
1371 | - * @since 1.0.15 |
|
1372 | - * @return boolean |
|
1373 | - */ |
|
1374 | - public function has_maximum_amount() { |
|
1375 | - $maximum = $this->get_maximum_total(); |
|
1376 | - return ! empty( $maximum ); |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Checks if the maximum amount is met |
|
1381 | - * |
|
1382 | - * @param float $amount The amount to check against |
|
1383 | - * @since 1.0.15 |
|
1384 | - * @return boolean |
|
1385 | - */ |
|
1386 | - public function is_maximum_amount_met( $amount ) { |
|
1387 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1388 | - $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1389 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount ); |
|
1390 | - } |
|
1391 | - |
|
1392 | - /** |
|
1393 | - * Checks if the discount is recurring. |
|
1394 | - * |
|
1395 | - * @since 1.0.15 |
|
1396 | - * @return boolean |
|
1397 | - */ |
|
1398 | - public function is_recurring() { |
|
1399 | - $recurring = $this->get_is_recurring(); |
|
1400 | - return ! empty( $recurring ); |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * Checks if the discount is single use. |
|
1405 | - * |
|
1406 | - * @since 1.0.15 |
|
1407 | - * @return boolean |
|
1408 | - */ |
|
1409 | - public function is_single_use() { |
|
1410 | - $usage = $this->get_is_single_use(); |
|
1411 | - return ! empty( $usage ); |
|
1412 | - } |
|
1413 | - |
|
1414 | - /** |
|
1415 | - * Check if a discount is valid for the given user |
|
1416 | - * |
|
1417 | - * @param int|string $user |
|
1418 | - * @since 1.0.15 |
|
1419 | - * @return boolean |
|
1420 | - */ |
|
1421 | - public function is_valid_for_user( $user ) { |
|
1422 | - global $wpi_checkout_id; |
|
1423 | - |
|
1424 | - // Ensure that the discount is single use. |
|
1425 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1426 | - return true; |
|
1427 | - } |
|
1428 | - |
|
1429 | - // Prepare the user id. |
|
1430 | - $user_id = 0; |
|
1174 | + /** |
|
1175 | + * Checks whether a discount exists in the database or not |
|
1176 | + * |
|
1177 | + * @since 1.0.15 |
|
1178 | + */ |
|
1179 | + public function exists(){ |
|
1180 | + $id = $this->get_id(); |
|
1181 | + return ! empty( $id ); |
|
1182 | + } |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Checks the discount type. |
|
1186 | + * |
|
1187 | + * |
|
1188 | + * @param string $type the discount type to check against |
|
1189 | + * @since 1.0.15 |
|
1190 | + * @return bool |
|
1191 | + */ |
|
1192 | + public function is_type( $type ) { |
|
1193 | + return $this->get_type() == $type; |
|
1194 | + } |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Checks whether the discount is published or not |
|
1198 | + * |
|
1199 | + * @since 1.0.15 |
|
1200 | + * @return bool |
|
1201 | + */ |
|
1202 | + public function is_active() { |
|
1203 | + return $this->get_status() == 'publish'; |
|
1204 | + } |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * Checks whether the discount has max uses |
|
1208 | + * |
|
1209 | + * @since 1.0.15 |
|
1210 | + * @return bool |
|
1211 | + */ |
|
1212 | + public function has_limit() { |
|
1213 | + $limit = $this->get_max_uses(); |
|
1214 | + return ! empty( $limit ); |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * Checks whether the discount has ever been used. |
|
1219 | + * |
|
1220 | + * @since 1.0.15 |
|
1221 | + * @return bool |
|
1222 | + */ |
|
1223 | + public function has_uses() { |
|
1224 | + return $this->get_uses() > 0; |
|
1225 | + } |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Checks whether the discount is has exided the usage limit or not |
|
1229 | + * |
|
1230 | + * @since 1.0.15 |
|
1231 | + * @return bool |
|
1232 | + */ |
|
1233 | + public function has_exceeded_limit() { |
|
1234 | + |
|
1235 | + if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1236 | + $exceeded = false ; |
|
1237 | + } else { |
|
1238 | + $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
1239 | + } |
|
1240 | + |
|
1241 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code ); |
|
1242 | + } |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * Checks whether the discount has an expiration date. |
|
1246 | + * |
|
1247 | + * @since 1.0.15 |
|
1248 | + * @return bool |
|
1249 | + */ |
|
1250 | + public function has_expiration_date() { |
|
1251 | + $date = $this->get_expiration_date(); |
|
1252 | + return ! empty( $date ); |
|
1253 | + } |
|
1254 | + |
|
1255 | + /** |
|
1256 | + * Checks if the discount is expired |
|
1257 | + * |
|
1258 | + * @since 1.0.15 |
|
1259 | + * @return bool |
|
1260 | + */ |
|
1261 | + public function is_expired() { |
|
1262 | + $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1263 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code ); |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * Checks whether the discount has a start date. |
|
1268 | + * |
|
1269 | + * @since 1.0.15 |
|
1270 | + * @return bool |
|
1271 | + */ |
|
1272 | + public function has_start_date() { |
|
1273 | + $date = $this->get_start_date(); |
|
1274 | + return ! empty( $date ); |
|
1275 | + } |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * Checks the discount start date. |
|
1279 | + * |
|
1280 | + * @since 1.0.15 |
|
1281 | + * @return bool |
|
1282 | + */ |
|
1283 | + public function has_started() { |
|
1284 | + $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1285 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code ); |
|
1286 | + } |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * Checks the discount has allowed items or not. |
|
1290 | + * |
|
1291 | + * @since 1.0.15 |
|
1292 | + * @return bool |
|
1293 | + */ |
|
1294 | + public function has_allowed_items() { |
|
1295 | + $allowed_items = $this->get_allowed_items(); |
|
1296 | + return empty( $allowed_items ); |
|
1297 | + } |
|
1298 | + |
|
1299 | + /** |
|
1300 | + * Checks the discount has excluded items or not. |
|
1301 | + * |
|
1302 | + * @since 1.0.15 |
|
1303 | + * @return bool |
|
1304 | + */ |
|
1305 | + public function has_excluded_items() { |
|
1306 | + $excluded_items = $this->get_excluded_items(); |
|
1307 | + return empty( $excluded_items ); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Check if a discount is valid for a given item id. |
|
1312 | + * |
|
1313 | + * @param int|int[] $item_ids |
|
1314 | + * @since 1.0.15 |
|
1315 | + * @return boolean |
|
1316 | + */ |
|
1317 | + public function is_valid_for_items( $item_ids ) { |
|
1318 | + |
|
1319 | + $item_ids = array_map( 'intval', wpinv_parse_list( $item_ids ) ); |
|
1320 | + $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1321 | + $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1322 | + |
|
1323 | + if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1324 | + return false; |
|
1325 | + } |
|
1326 | + |
|
1327 | + if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1328 | + return false; |
|
1329 | + } |
|
1330 | + return true; |
|
1331 | + } |
|
1332 | + |
|
1333 | + /** |
|
1334 | + * Check if a discount is valid for the given amount |
|
1335 | + * |
|
1336 | + * @param float $amount The amount to check against |
|
1337 | + * @since 1.0.15 |
|
1338 | + * @return boolean |
|
1339 | + */ |
|
1340 | + public function is_valid_for_amount( $amount ) { |
|
1341 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * Checks if the minimum amount is set |
|
1346 | + * |
|
1347 | + * @since 1.0.15 |
|
1348 | + * @return boolean |
|
1349 | + */ |
|
1350 | + public function has_minimum_amount() { |
|
1351 | + $minimum = $this->get_minimum_total(); |
|
1352 | + return ! empty( $minimum ); |
|
1353 | + } |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * Checks if the minimum amount is met |
|
1357 | + * |
|
1358 | + * @param float $amount The amount to check against |
|
1359 | + * @since 1.0.15 |
|
1360 | + * @return boolean |
|
1361 | + */ |
|
1362 | + public function is_minimum_amount_met( $amount ) { |
|
1363 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1364 | + $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1365 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount ); |
|
1366 | + } |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * Checks if the maximum amount is set |
|
1370 | + * |
|
1371 | + * @since 1.0.15 |
|
1372 | + * @return boolean |
|
1373 | + */ |
|
1374 | + public function has_maximum_amount() { |
|
1375 | + $maximum = $this->get_maximum_total(); |
|
1376 | + return ! empty( $maximum ); |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Checks if the maximum amount is met |
|
1381 | + * |
|
1382 | + * @param float $amount The amount to check against |
|
1383 | + * @since 1.0.15 |
|
1384 | + * @return boolean |
|
1385 | + */ |
|
1386 | + public function is_maximum_amount_met( $amount ) { |
|
1387 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1388 | + $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1389 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount ); |
|
1390 | + } |
|
1391 | + |
|
1392 | + /** |
|
1393 | + * Checks if the discount is recurring. |
|
1394 | + * |
|
1395 | + * @since 1.0.15 |
|
1396 | + * @return boolean |
|
1397 | + */ |
|
1398 | + public function is_recurring() { |
|
1399 | + $recurring = $this->get_is_recurring(); |
|
1400 | + return ! empty( $recurring ); |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * Checks if the discount is single use. |
|
1405 | + * |
|
1406 | + * @since 1.0.15 |
|
1407 | + * @return boolean |
|
1408 | + */ |
|
1409 | + public function is_single_use() { |
|
1410 | + $usage = $this->get_is_single_use(); |
|
1411 | + return ! empty( $usage ); |
|
1412 | + } |
|
1413 | + |
|
1414 | + /** |
|
1415 | + * Check if a discount is valid for the given user |
|
1416 | + * |
|
1417 | + * @param int|string $user |
|
1418 | + * @since 1.0.15 |
|
1419 | + * @return boolean |
|
1420 | + */ |
|
1421 | + public function is_valid_for_user( $user ) { |
|
1422 | + global $wpi_checkout_id; |
|
1423 | + |
|
1424 | + // Ensure that the discount is single use. |
|
1425 | + if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1426 | + return true; |
|
1427 | + } |
|
1428 | + |
|
1429 | + // Prepare the user id. |
|
1430 | + $user_id = 0; |
|
1431 | 1431 | if ( is_int( $user ) ) { |
1432 | 1432 | $user_id = absint( $user ); |
1433 | 1433 | } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -1436,135 +1436,135 @@ discard block |
||
1436 | 1436 | $user_id = $user_data->ID; |
1437 | 1437 | } else if ( absint( $user ) > 0 ) { |
1438 | 1438 | $user_id = absint( $user ); |
1439 | - } |
|
1439 | + } |
|
1440 | 1440 | |
1441 | - // Ensure that we have a user. |
|
1442 | - if ( empty( $user_id ) ) { |
|
1443 | - return true; |
|
1444 | - } |
|
1441 | + // Ensure that we have a user. |
|
1442 | + if ( empty( $user_id ) ) { |
|
1443 | + return true; |
|
1444 | + } |
|
1445 | 1445 | |
1446 | - // Get all payments with matching user id. |
|
1446 | + // Get all payments with matching user id. |
|
1447 | 1447 | $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) ); |
1448 | - $code = strtolower( $this->get_code() ); |
|
1449 | - |
|
1450 | - // For each payment... |
|
1451 | - foreach ( $payments as $payment ) { |
|
1452 | - |
|
1453 | - // ... skip the current payment. |
|
1454 | - if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
1455 | - continue; |
|
1456 | - } |
|
1457 | - |
|
1458 | - // And failed payments. |
|
1459 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
1460 | - continue; |
|
1461 | - } |
|
1462 | - |
|
1463 | - // Retrieve all the discounts for the payment. |
|
1464 | - $discounts = $payment->get_discounts( true ); |
|
1465 | - if ( empty( $discounts ) ) { |
|
1466 | - continue; |
|
1467 | - } |
|
1468 | - |
|
1469 | - // And check if the current discount is amongst them. |
|
1470 | - $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) ); |
|
1471 | - if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
1472 | - return false; |
|
1473 | - } |
|
1474 | - } |
|
1475 | - |
|
1476 | - return true; |
|
1477 | - } |
|
1478 | - |
|
1479 | - /** |
|
1480 | - * Deletes the discount from the database |
|
1481 | - * |
|
1482 | - * @since 1.0.15 |
|
1483 | - * @return boolean |
|
1484 | - */ |
|
1485 | - public function remove() { |
|
1486 | - return $this->delete(); |
|
1487 | - } |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * Increases a discount's usage. |
|
1491 | - * |
|
1492 | - * @since 1.0.15 |
|
1493 | - * @param int $by The number of usages to increas by. |
|
1494 | - * @return int |
|
1495 | - */ |
|
1496 | - public function increase_usage( $by = 1 ) { |
|
1497 | - |
|
1498 | - // Abort if zero. |
|
1499 | - if ( empty( $by ) ) { |
|
1500 | - return; |
|
1501 | - } |
|
1502 | - |
|
1503 | - // Increase the usage. |
|
1504 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1505 | - |
|
1506 | - // Save the discount. |
|
1507 | - $this->save(); |
|
1508 | - |
|
1509 | - // Fire relevant hooks. |
|
1510 | - if( (int) $by > 0 ) { |
|
1511 | - do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
1512 | - } else { |
|
1513 | - do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
1514 | - } |
|
1515 | - |
|
1516 | - // Return the number of times the discount has been used. |
|
1517 | - return $this->get_uses(); |
|
1518 | - } |
|
1519 | - |
|
1520 | - /** |
|
1521 | - * Alias of self::__toString() |
|
1522 | - * |
|
1523 | - * @since 1.0.15 |
|
1524 | - * @return string|false |
|
1525 | - */ |
|
1526 | - public function get_data_as_json() { |
|
1527 | - return $this->__toString(); |
|
1528 | - } |
|
1529 | - |
|
1530 | - /** |
|
1531 | - * Returns a discount's discounted amount. |
|
1532 | - * |
|
1533 | - * @since 1.0.15 |
|
1534 | - * @param float $amount |
|
1535 | - * @return float |
|
1536 | - */ |
|
1537 | - public function get_discounted_amount( $amount ) { |
|
1538 | - |
|
1539 | - // Convert amount to float. |
|
1540 | - $amount = (float) $amount; |
|
1541 | - |
|
1542 | - // Get discount amount. |
|
1543 | - $discount_amount = $this->get_amount(); |
|
1544 | - |
|
1545 | - if ( empty( $discount_amount ) ) { |
|
1546 | - return 0; |
|
1547 | - } |
|
1548 | - |
|
1549 | - // Format the amount. |
|
1550 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1448 | + $code = strtolower( $this->get_code() ); |
|
1449 | + |
|
1450 | + // For each payment... |
|
1451 | + foreach ( $payments as $payment ) { |
|
1452 | + |
|
1453 | + // ... skip the current payment. |
|
1454 | + if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
1455 | + continue; |
|
1456 | + } |
|
1457 | + |
|
1458 | + // And failed payments. |
|
1459 | + if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
1460 | + continue; |
|
1461 | + } |
|
1462 | + |
|
1463 | + // Retrieve all the discounts for the payment. |
|
1464 | + $discounts = $payment->get_discounts( true ); |
|
1465 | + if ( empty( $discounts ) ) { |
|
1466 | + continue; |
|
1467 | + } |
|
1468 | + |
|
1469 | + // And check if the current discount is amongst them. |
|
1470 | + $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) ); |
|
1471 | + if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
1472 | + return false; |
|
1473 | + } |
|
1474 | + } |
|
1475 | + |
|
1476 | + return true; |
|
1477 | + } |
|
1478 | + |
|
1479 | + /** |
|
1480 | + * Deletes the discount from the database |
|
1481 | + * |
|
1482 | + * @since 1.0.15 |
|
1483 | + * @return boolean |
|
1484 | + */ |
|
1485 | + public function remove() { |
|
1486 | + return $this->delete(); |
|
1487 | + } |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * Increases a discount's usage. |
|
1491 | + * |
|
1492 | + * @since 1.0.15 |
|
1493 | + * @param int $by The number of usages to increas by. |
|
1494 | + * @return int |
|
1495 | + */ |
|
1496 | + public function increase_usage( $by = 1 ) { |
|
1497 | + |
|
1498 | + // Abort if zero. |
|
1499 | + if ( empty( $by ) ) { |
|
1500 | + return; |
|
1501 | + } |
|
1502 | + |
|
1503 | + // Increase the usage. |
|
1504 | + $this->set_uses( $this->get_uses() + (int) $by ); |
|
1505 | + |
|
1506 | + // Save the discount. |
|
1507 | + $this->save(); |
|
1508 | + |
|
1509 | + // Fire relevant hooks. |
|
1510 | + if( (int) $by > 0 ) { |
|
1511 | + do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
1512 | + } else { |
|
1513 | + do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
1514 | + } |
|
1515 | + |
|
1516 | + // Return the number of times the discount has been used. |
|
1517 | + return $this->get_uses(); |
|
1518 | + } |
|
1519 | + |
|
1520 | + /** |
|
1521 | + * Alias of self::__toString() |
|
1522 | + * |
|
1523 | + * @since 1.0.15 |
|
1524 | + * @return string|false |
|
1525 | + */ |
|
1526 | + public function get_data_as_json() { |
|
1527 | + return $this->__toString(); |
|
1528 | + } |
|
1529 | + |
|
1530 | + /** |
|
1531 | + * Returns a discount's discounted amount. |
|
1532 | + * |
|
1533 | + * @since 1.0.15 |
|
1534 | + * @param float $amount |
|
1535 | + * @return float |
|
1536 | + */ |
|
1537 | + public function get_discounted_amount( $amount ) { |
|
1538 | + |
|
1539 | + // Convert amount to float. |
|
1540 | + $amount = (float) $amount; |
|
1541 | + |
|
1542 | + // Get discount amount. |
|
1543 | + $discount_amount = $this->get_amount(); |
|
1544 | + |
|
1545 | + if ( empty( $discount_amount ) ) { |
|
1546 | + return 0; |
|
1547 | + } |
|
1548 | + |
|
1549 | + // Format the amount. |
|
1550 | + $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1551 | 1551 | |
1552 | - // If this is a percentage discount. |
|
1553 | - if ( $this->is_type( 'percent' ) ) { |
|
1552 | + // If this is a percentage discount. |
|
1553 | + if ( $this->is_type( 'percent' ) ) { |
|
1554 | 1554 | $discount_amount = $amount * ( $discount_amount / 100 ); |
1555 | - } |
|
1555 | + } |
|
1556 | 1556 | |
1557 | - // Discount can not be less than zero... |
|
1558 | - if ( $discount_amount < 0 ) { |
|
1559 | - $discount_amount = 0; |
|
1560 | - } |
|
1557 | + // Discount can not be less than zero... |
|
1558 | + if ( $discount_amount < 0 ) { |
|
1559 | + $discount_amount = 0; |
|
1560 | + } |
|
1561 | 1561 | |
1562 | - // ... or more than the amount. |
|
1563 | - if ( $discount_amount > $amount ) { |
|
1564 | - $discount_amount = $amount; |
|
1565 | - } |
|
1562 | + // ... or more than the amount. |
|
1563 | + if ( $discount_amount > $amount ) { |
|
1564 | + $discount_amount = $amount; |
|
1565 | + } |
|
1566 | 1566 | |
1567 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1568 | - } |
|
1567 | + return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1568 | + } |
|
1569 | 1569 | |
1570 | 1570 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 1.0.15 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Discount class. |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @since 1.0.15 |
14 | 14 | * |
15 | 15 | */ |
16 | -class WPInv_Discount extends GetPaid_Data { |
|
16 | +class WPInv_Discount extends GetPaid_Data { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Which data store to load. |
@@ -79,35 +79,35 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
81 | 81 | */ |
82 | - public function __construct( $discount = 0 ) { |
|
83 | - parent::__construct( $discount ); |
|
82 | + public function __construct($discount = 0) { |
|
83 | + parent::__construct($discount); |
|
84 | 84 | |
85 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
86 | - $this->set_id( $discount ); |
|
87 | - } elseif ( $discount instanceof self ) { |
|
88 | - $this->set_id( $discount->get_id() ); |
|
89 | - } elseif ( ! empty( $discount->ID ) ) { |
|
90 | - $this->set_id( $discount->ID ); |
|
91 | - } elseif ( is_array( $discount ) ) { |
|
92 | - $this->set_props( $discount ); |
|
85 | + if (is_numeric($discount) && 'wpi_discount' === get_post_type($discount)) { |
|
86 | + $this->set_id($discount); |
|
87 | + } elseif ($discount instanceof self) { |
|
88 | + $this->set_id($discount->get_id()); |
|
89 | + } elseif (!empty($discount->ID)) { |
|
90 | + $this->set_id($discount->ID); |
|
91 | + } elseif (is_array($discount)) { |
|
92 | + $this->set_props($discount); |
|
93 | 93 | |
94 | - if ( isset( $discount['ID'] ) ) { |
|
95 | - $this->set_id( $discount['ID'] ); |
|
94 | + if (isset($discount['ID'])) { |
|
95 | + $this->set_id($discount['ID']); |
|
96 | 96 | } |
97 | 97 | |
98 | - } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
99 | - $this->set_id( $discount ); |
|
98 | + } elseif (is_scalar($discount) && $discount = self::get_discount_id_by_code($discount)) { |
|
99 | + $this->set_id($discount); |
|
100 | 100 | } else { |
101 | - $this->set_object_read( true ); |
|
101 | + $this->set_object_read(true); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Load the datastore. |
105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
105 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
106 | 106 | |
107 | - if ( $this->get_id() > 0 ) { |
|
108 | - $this->post = get_post( $this->get_id() ); |
|
107 | + if ($this->get_id() > 0) { |
|
108 | + $this->post = get_post($this->get_id()); |
|
109 | 109 | $this->ID = $this->get_id(); |
110 | - $this->data_store->read( $this ); |
|
110 | + $this->data_store->read($this); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -123,50 +123,50 @@ discard block |
||
123 | 123 | * @since 1.0.15 |
124 | 124 | * @return array|bool array of discount details on success. False otherwise. |
125 | 125 | */ |
126 | - public static function get_data_by( $field, $value ) { |
|
126 | + public static function get_data_by($field, $value) { |
|
127 | 127 | |
128 | - if ( 'id' == strtolower( $field ) ) { |
|
128 | + if ('id' == strtolower($field)) { |
|
129 | 129 | // Make sure the value is numeric to avoid casting objects, for example, |
130 | 130 | // to int 1. |
131 | - if ( ! is_numeric( $value ) ) |
|
131 | + if (!is_numeric($value)) |
|
132 | 132 | return false; |
133 | - $value = intval( $value ); |
|
134 | - if ( $value < 1 ) |
|
133 | + $value = intval($value); |
|
134 | + if ($value < 1) |
|
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | |
138 | - if ( ! $value || ! is_string( $field ) ) { |
|
138 | + if (!$value || !is_string($field)) { |
|
139 | 139 | return false; |
140 | 140 | } |
141 | 141 | |
142 | - $field = trim( $field ); |
|
142 | + $field = trim($field); |
|
143 | 143 | |
144 | 144 | // prepare query args |
145 | - switch ( strtolower( $field ) ) { |
|
145 | + switch (strtolower($field)) { |
|
146 | 146 | case 'id': |
147 | 147 | $discount_id = $value; |
148 | - $args = array( 'include' => array( $value ) ); |
|
148 | + $args = array('include' => array($value)); |
|
149 | 149 | break; |
150 | 150 | case 'discount_code': |
151 | 151 | case 'code': |
152 | - $value = trim( $value ); |
|
153 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
154 | - $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
152 | + $value = trim($value); |
|
153 | + $discount_id = wp_cache_get($value, 'WPInv_Discount_Codes'); |
|
154 | + $args = array('meta_key' => '_wpi_discount_code', 'meta_value' => $value); |
|
155 | 155 | break; |
156 | 156 | case 'name': |
157 | 157 | $discount_id = 0; |
158 | - $args = array( 'name' => trim( $value ) ); |
|
158 | + $args = array('name' => trim($value)); |
|
159 | 159 | break; |
160 | 160 | default: |
161 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
162 | - if ( ! is_array( $args ) ) { |
|
163 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
161 | + $args = apply_filters("wpinv_discount_get_data_by_{$field}_args", null, $value); |
|
162 | + if (!is_array($args)) { |
|
163 | + return apply_filters("wpinv_discount_get_data_by_$field", false, $value); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | } |
167 | 167 | |
168 | 168 | // Check if there is a cached value. |
169 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
169 | + if (!empty($discount_id) && $discount = wp_cache_get((int) $discount_id, 'WPInv_Discounts')) { |
|
170 | 170 | return $discount; |
171 | 171 | } |
172 | 172 | |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | array( |
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'posts_per_page' => 1, |
178 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
178 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
179 | 179 | ) |
180 | 180 | ); |
181 | 181 | |
182 | - $discount = get_posts( $args ); |
|
182 | + $discount = get_posts($args); |
|
183 | 183 | |
184 | - if( empty( $discount ) ) { |
|
184 | + if (empty($discount)) { |
|
185 | 185 | return false; |
186 | 186 | } |
187 | 187 | |
@@ -190,30 +190,30 @@ discard block |
||
190 | 190 | // Prepare the return data. |
191 | 191 | $return = array( |
192 | 192 | 'ID' => $discount->ID, |
193 | - 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
|
194 | - 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
|
193 | + 'code' => get_post_meta($discount->ID, '_wpi_discount_code', true), |
|
194 | + 'amount' => get_post_meta($discount->ID, '_wpi_discount_amount', true), |
|
195 | 195 | 'date_created' => $discount->post_date, |
196 | 196 | 'date_modified' => $discount->post_modified, |
197 | 197 | 'status' => $discount->post_status, |
198 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
199 | - 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
|
200 | - 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
|
198 | + 'start' => get_post_meta($discount->ID, '_wpi_discount_start', true), |
|
199 | + 'expiration' => get_post_meta($discount->ID, '_wpi_discount_expiration', true), |
|
200 | + 'type' => get_post_meta($discount->ID, '_wpi_discount_type', true), |
|
201 | 201 | 'description' => $discount->post_excerpt, |
202 | - 'uses' => get_post_meta( $discount->ID, '_wpi_discount_uses', true ), |
|
203 | - 'is_single_use' => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ), |
|
204 | - 'items' => get_post_meta( $discount->ID, '_wpi_discount_items', true ), |
|
205 | - 'excluded_items' => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ), |
|
206 | - 'max_uses' => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ), |
|
207 | - 'is_recurring' => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ), |
|
208 | - 'min_total' => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ), |
|
209 | - 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
|
202 | + 'uses' => get_post_meta($discount->ID, '_wpi_discount_uses', true), |
|
203 | + 'is_single_use' => get_post_meta($discount->ID, '_wpi_discount_is_single_use', true), |
|
204 | + 'items' => get_post_meta($discount->ID, '_wpi_discount_items', true), |
|
205 | + 'excluded_items' => get_post_meta($discount->ID, '_wpi_discount_excluded_items', true), |
|
206 | + 'max_uses' => get_post_meta($discount->ID, '_wpi_discount_max_uses', true), |
|
207 | + 'is_recurring' => get_post_meta($discount->ID, '_wpi_discount_is_recurring', true), |
|
208 | + 'min_total' => get_post_meta($discount->ID, '_wpi_discount_min_total', true), |
|
209 | + 'max_total' => get_post_meta($discount->ID, '_wpi_discount_max_total', true), |
|
210 | 210 | ); |
211 | 211 | |
212 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
212 | + $return = apply_filters('wpinv_discount_properties', $return); |
|
213 | 213 | |
214 | 214 | // Update the cache with our data |
215 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
216 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
215 | + wp_cache_add($discount->ID, $return, 'WPInv_Discounts'); |
|
216 | + wp_cache_add($return['code'], $discount->ID, 'WPInv_Discount_Codes'); |
|
217 | 217 | |
218 | 218 | return $return; |
219 | 219 | } |
@@ -227,19 +227,19 @@ discard block |
||
227 | 227 | * @since 1.0.15 |
228 | 228 | * @return int |
229 | 229 | */ |
230 | - public static function get_discount_id_by_code( $discount_code ) { |
|
230 | + public static function get_discount_id_by_code($discount_code) { |
|
231 | 231 | |
232 | 232 | // Trim the code. |
233 | - $discount_code = trim( $discount_code ); |
|
233 | + $discount_code = trim($discount_code); |
|
234 | 234 | |
235 | 235 | // Ensure a value has been passed. |
236 | - if ( empty( $discount_code ) ) { |
|
236 | + if (empty($discount_code)) { |
|
237 | 237 | return 0; |
238 | 238 | } |
239 | 239 | |
240 | 240 | // Maybe retrieve from the cache. |
241 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
242 | - if ( ! empty( $discount_id ) ) { |
|
241 | + $discount_id = wp_cache_get($discount_code, 'getpaid_discount_codes'); |
|
242 | + if (!empty($discount_id)) { |
|
243 | 243 | return $discount_id; |
244 | 244 | } |
245 | 245 | |
@@ -250,19 +250,19 @@ discard block |
||
250 | 250 | 'meta_value' => $discount_code, |
251 | 251 | 'post_type' => 'wpi_discount', |
252 | 252 | 'posts_per_page' => 1, |
253 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
253 | + 'post_status' => array('publish', 'pending', 'draft', 'expired'), |
|
254 | 254 | 'fields' => 'ids', |
255 | 255 | ) |
256 | 256 | ); |
257 | 257 | |
258 | - if ( empty( $discounts ) ) { |
|
258 | + if (empty($discounts)) { |
|
259 | 259 | return 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $discount_id = $discounts[0]; |
263 | 263 | |
264 | 264 | // Update the cache with our data |
265 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
265 | + wp_cache_add(get_post_meta($discount_id, '_wpi_discount_code', true), $discount_id, 'getpaid_discount_codes'); |
|
266 | 266 | |
267 | 267 | return $discount_id; |
268 | 268 | } |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @return bool Whether the given discount field is set. |
277 | 277 | */ |
278 | - public function __isset( $key ){ |
|
279 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
278 | + public function __isset($key) { |
|
279 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /* |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * @param string $context View or edit context. |
302 | 302 | * @return string |
303 | 303 | */ |
304 | - public function get_status( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'status', $context ); |
|
304 | + public function get_status($context = 'view') { |
|
305 | + return $this->get_prop('status', $context); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @param string $context View or edit context. |
313 | 313 | * @return string |
314 | 314 | */ |
315 | - public function get_version( $context = 'view' ) { |
|
316 | - return $this->get_prop( 'version', $context ); |
|
315 | + public function get_version($context = 'view') { |
|
316 | + return $this->get_prop('version', $context); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string $context View or edit context. |
324 | 324 | * @return string |
325 | 325 | */ |
326 | - public function get_date_created( $context = 'view' ) { |
|
327 | - return $this->get_prop( 'date_created', $context ); |
|
326 | + public function get_date_created($context = 'view') { |
|
327 | + return $this->get_prop('date_created', $context); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | * @param string $context View or edit context. |
335 | 335 | * @return string |
336 | 336 | */ |
337 | - public function get_date_created_gmt( $context = 'view' ) { |
|
338 | - $date = $this->get_date_created( $context ); |
|
337 | + public function get_date_created_gmt($context = 'view') { |
|
338 | + $date = $this->get_date_created($context); |
|
339 | 339 | |
340 | - if ( $date ) { |
|
341 | - $date = get_gmt_from_date( $date ); |
|
340 | + if ($date) { |
|
341 | + $date = get_gmt_from_date($date); |
|
342 | 342 | } |
343 | 343 | return $date; |
344 | 344 | } |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | * @param string $context View or edit context. |
351 | 351 | * @return string |
352 | 352 | */ |
353 | - public function get_date_modified( $context = 'view' ) { |
|
354 | - return $this->get_prop( 'date_modified', $context ); |
|
353 | + public function get_date_modified($context = 'view') { |
|
354 | + return $this->get_prop('date_modified', $context); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | * @param string $context View or edit context. |
362 | 362 | * @return string |
363 | 363 | */ |
364 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
365 | - $date = $this->get_date_modified( $context ); |
|
364 | + public function get_date_modified_gmt($context = 'view') { |
|
365 | + $date = $this->get_date_modified($context); |
|
366 | 366 | |
367 | - if ( $date ) { |
|
368 | - $date = get_gmt_from_date( $date ); |
|
367 | + if ($date) { |
|
368 | + $date = get_gmt_from_date($date); |
|
369 | 369 | } |
370 | 370 | return $date; |
371 | 371 | } |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | * @param string $context View or edit context. |
378 | 378 | * @return string |
379 | 379 | */ |
380 | - public function get_name( $context = 'view' ) { |
|
381 | - return $this->get_prop( 'name', $context ); |
|
380 | + public function get_name($context = 'view') { |
|
381 | + return $this->get_prop('name', $context); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * @param string $context View or edit context. |
389 | 389 | * @return string |
390 | 390 | */ |
391 | - public function get_title( $context = 'view' ) { |
|
392 | - return $this->get_name( $context ); |
|
391 | + public function get_title($context = 'view') { |
|
392 | + return $this->get_name($context); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | * @param string $context View or edit context. |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public function get_description( $context = 'view' ) { |
|
403 | - return $this->get_prop( 'description', $context ); |
|
402 | + public function get_description($context = 'view') { |
|
403 | + return $this->get_prop('description', $context); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -410,8 +410,8 @@ discard block |
||
410 | 410 | * @param string $context View or edit context. |
411 | 411 | * @return string |
412 | 412 | */ |
413 | - public function get_excerpt( $context = 'view' ) { |
|
414 | - return $this->get_description( $context ); |
|
413 | + public function get_excerpt($context = 'view') { |
|
414 | + return $this->get_description($context); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | * @param string $context View or edit context. |
422 | 422 | * @return string |
423 | 423 | */ |
424 | - public function get_summary( $context = 'view' ) { |
|
425 | - return $this->get_description( $context ); |
|
424 | + public function get_summary($context = 'view') { |
|
425 | + return $this->get_description($context); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | * @param string $context View or edit context. |
433 | 433 | * @return string |
434 | 434 | */ |
435 | - public function get_author( $context = 'view' ) { |
|
436 | - return (int) $this->get_prop( 'author', $context ); |
|
435 | + public function get_author($context = 'view') { |
|
436 | + return (int) $this->get_prop('author', $context); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * @param string $context View or edit context. |
444 | 444 | * @return string |
445 | 445 | */ |
446 | - public function get_code( $context = 'view' ) { |
|
447 | - return $this->get_prop( 'code', $context ); |
|
446 | + public function get_code($context = 'view') { |
|
447 | + return $this->get_prop('code', $context); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @param string $context View or edit context. |
455 | 455 | * @return string |
456 | 456 | */ |
457 | - public function get_coupon_code( $context = 'view' ) { |
|
458 | - return $this->get_code( $context ); |
|
457 | + public function get_coupon_code($context = 'view') { |
|
458 | + return $this->get_code($context); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | * @param string $context View or edit context. |
466 | 466 | * @return string |
467 | 467 | */ |
468 | - public function get_discount_code( $context = 'view' ) { |
|
469 | - return $this->get_code( $context ); |
|
468 | + public function get_discount_code($context = 'view') { |
|
469 | + return $this->get_code($context); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | * @param string $context View or edit context. |
477 | 477 | * @return float |
478 | 478 | */ |
479 | - public function get_amount( $context = 'view' ) { |
|
480 | - return $this->get_prop( 'amount', $context ); |
|
479 | + public function get_amount($context = 'view') { |
|
480 | + return $this->get_prop('amount', $context); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -488,23 +488,23 @@ discard block |
||
488 | 488 | */ |
489 | 489 | public function get_formatted_amount() { |
490 | 490 | |
491 | - if ( $this->is_type( 'flat' ) ) { |
|
492 | - $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
491 | + if ($this->is_type('flat')) { |
|
492 | + $rate = wpinv_price(wpinv_format_amount($this->get_amount())); |
|
493 | 493 | } else { |
494 | 494 | $rate = $this->get_amount() . '%'; |
495 | 495 | } |
496 | 496 | |
497 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
497 | + return apply_filters('wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount()); |
|
498 | 498 | } |
499 | 499 | |
500 | - function wpinv_format_discount_rate( $type, $amount ) { |
|
501 | - if ( $type == 'flat' ) { |
|
502 | - $rate = wpinv_price( wpinv_format_amount( $amount ) ); |
|
500 | + function wpinv_format_discount_rate($type, $amount) { |
|
501 | + if ($type == 'flat') { |
|
502 | + $rate = wpinv_price(wpinv_format_amount($amount)); |
|
503 | 503 | } else { |
504 | 504 | $rate = $amount . '%'; |
505 | 505 | } |
506 | 506 | |
507 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount ); |
|
507 | + return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -514,8 +514,8 @@ discard block |
||
514 | 514 | * @param string $context View or edit context. |
515 | 515 | * @return string |
516 | 516 | */ |
517 | - public function get_start( $context = 'view' ) { |
|
518 | - return $this->get_prop( 'start', $context ); |
|
517 | + public function get_start($context = 'view') { |
|
518 | + return $this->get_prop('start', $context); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -525,8 +525,8 @@ discard block |
||
525 | 525 | * @param string $context View or edit context. |
526 | 526 | * @return string |
527 | 527 | */ |
528 | - public function get_start_date( $context = 'view' ) { |
|
529 | - return $this->get_start( $context ); |
|
528 | + public function get_start_date($context = 'view') { |
|
529 | + return $this->get_start($context); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -536,8 +536,8 @@ discard block |
||
536 | 536 | * @param string $context View or edit context. |
537 | 537 | * @return string |
538 | 538 | */ |
539 | - public function get_expiration( $context = 'view' ) { |
|
540 | - return $this->get_prop( 'expiration', $context ); |
|
539 | + public function get_expiration($context = 'view') { |
|
540 | + return $this->get_prop('expiration', $context); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -547,8 +547,8 @@ discard block |
||
547 | 547 | * @param string $context View or edit context. |
548 | 548 | * @return string |
549 | 549 | */ |
550 | - public function get_expiration_date( $context = 'view' ) { |
|
551 | - return $this->get_expiration( $context ); |
|
550 | + public function get_expiration_date($context = 'view') { |
|
551 | + return $this->get_expiration($context); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -558,8 +558,8 @@ discard block |
||
558 | 558 | * @param string $context View or edit context. |
559 | 559 | * @return string |
560 | 560 | */ |
561 | - public function get_end_date( $context = 'view' ) { |
|
562 | - return $this->get_expiration( $context ); |
|
561 | + public function get_end_date($context = 'view') { |
|
562 | + return $this->get_expiration($context); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | * @param string $context View or edit context. |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - public function get_type( $context = 'view' ) { |
|
573 | - return $this->get_prop( 'type', $context ); |
|
572 | + public function get_type($context = 'view') { |
|
573 | + return $this->get_prop('type', $context); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | * @param string $context View or edit context. |
581 | 581 | * @return int |
582 | 582 | */ |
583 | - public function get_uses( $context = 'view' ) { |
|
584 | - return (int) $this->get_prop( 'uses', $context ); |
|
583 | + public function get_uses($context = 'view') { |
|
584 | + return (int) $this->get_prop('uses', $context); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | */ |
593 | 593 | public function get_usage() { |
594 | 594 | |
595 | - if ( ! $this->has_limit() ) { |
|
595 | + if (!$this->has_limit()) { |
|
596 | 596 | return $this->get_uses() . ' / ' . ' ∞'; |
597 | 597 | } |
598 | 598 | |
@@ -607,9 +607,9 @@ discard block |
||
607 | 607 | * @param string $context View or edit context. |
608 | 608 | * @return int |
609 | 609 | */ |
610 | - public function get_max_uses( $context = 'view' ) { |
|
611 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
612 | - return empty( $max_uses ) ? null : $max_uses; |
|
610 | + public function get_max_uses($context = 'view') { |
|
611 | + $max_uses = $this->get_prop('max_uses', $context); |
|
612 | + return empty($max_uses) ? null : $max_uses; |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | /** |
@@ -619,8 +619,8 @@ discard block |
||
619 | 619 | * @param string $context View or edit context. |
620 | 620 | * @return bool |
621 | 621 | */ |
622 | - public function get_is_single_use( $context = 'view' ) { |
|
623 | - return $this->get_prop( 'is_single_use', $context ); |
|
622 | + public function get_is_single_use($context = 'view') { |
|
623 | + return $this->get_prop('is_single_use', $context); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
@@ -630,8 +630,8 @@ discard block |
||
630 | 630 | * @param string $context View or edit context. |
631 | 631 | * @return array |
632 | 632 | */ |
633 | - public function get_items( $context = 'view' ) { |
|
634 | - return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
633 | + public function get_items($context = 'view') { |
|
634 | + return wpinv_parse_list($this->get_prop('items', $context)); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | /** |
@@ -641,8 +641,8 @@ discard block |
||
641 | 641 | * @param string $context View or edit context. |
642 | 642 | * @return array |
643 | 643 | */ |
644 | - public function get_allowed_items( $context = 'view' ) { |
|
645 | - return $this->get_items( $context ); |
|
644 | + public function get_allowed_items($context = 'view') { |
|
645 | + return $this->get_items($context); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -652,8 +652,8 @@ discard block |
||
652 | 652 | * @param string $context View or edit context. |
653 | 653 | * @return array |
654 | 654 | */ |
655 | - public function get_excluded_items( $context = 'view' ) { |
|
656 | - return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
655 | + public function get_excluded_items($context = 'view') { |
|
656 | + return wpinv_parse_list($this->get_prop('excluded_items', $context)); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | * @param string $context View or edit context. |
664 | 664 | * @return int|string|bool |
665 | 665 | */ |
666 | - public function get_is_recurring( $context = 'view' ) { |
|
667 | - return $this->get_prop( 'is_recurring', $context ); |
|
666 | + public function get_is_recurring($context = 'view') { |
|
667 | + return $this->get_prop('is_recurring', $context); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -674,9 +674,9 @@ discard block |
||
674 | 674 | * @param string $context View or edit context. |
675 | 675 | * @return float |
676 | 676 | */ |
677 | - public function get_min_total( $context = 'view' ) { |
|
678 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
679 | - return empty( $minimum ) ? null : $minimum; |
|
677 | + public function get_min_total($context = 'view') { |
|
678 | + $minimum = $this->get_prop('min_total', $context); |
|
679 | + return empty($minimum) ? null : $minimum; |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | /** |
@@ -686,8 +686,8 @@ discard block |
||
686 | 686 | * @param string $context View or edit context. |
687 | 687 | * @return float |
688 | 688 | */ |
689 | - public function get_minimum_total( $context = 'view' ) { |
|
690 | - return $this->get_min_total( $context ); |
|
689 | + public function get_minimum_total($context = 'view') { |
|
690 | + return $this->get_min_total($context); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | * @param string $context View or edit context. |
698 | 698 | * @return float |
699 | 699 | */ |
700 | - public function get_max_total( $context = 'view' ) { |
|
701 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
702 | - return empty( $maximum ) ? null : $maximum; |
|
700 | + public function get_max_total($context = 'view') { |
|
701 | + $maximum = $this->get_prop('max_total', $context); |
|
702 | + return empty($maximum) ? null : $maximum; |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
@@ -709,15 +709,15 @@ discard block |
||
709 | 709 | * @param string $context View or edit context. |
710 | 710 | * @return float |
711 | 711 | */ |
712 | - public function get_maximum_total( $context = 'view' ) { |
|
713 | - return $this->get_max_total( $context ); |
|
712 | + public function get_maximum_total($context = 'view') { |
|
713 | + return $this->get_max_total($context); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | /** |
717 | 717 | * Margic method for retrieving a property. |
718 | 718 | */ |
719 | - public function __get( $key ) { |
|
720 | - return $this->get( $key ); |
|
719 | + public function __get($key) { |
|
720 | + return $this->get($key); |
|
721 | 721 | } |
722 | 722 | |
723 | 723 | /** |
@@ -730,19 +730,19 @@ discard block |
||
730 | 730 | * @param string $context View or edit context. |
731 | 731 | * @return mixed Value of the given discount property (if set). |
732 | 732 | */ |
733 | - public function get( $key, $context = 'view' ) { |
|
733 | + public function get($key, $context = 'view') { |
|
734 | 734 | |
735 | 735 | // Check if we have a helper method for that. |
736 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
737 | - return call_user_func( array( $this, 'get_' . $key ), $context ); |
|
736 | + if (method_exists($this, 'get_' . $key)) { |
|
737 | + return call_user_func(array($this, 'get_' . $key), $context); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | // Check if the key is in the associated $post object. |
741 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
741 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
742 | 742 | return $this->post->$key; |
743 | 743 | } |
744 | 744 | |
745 | - return $this->get_prop( $key, $context ); |
|
745 | + return $this->get_prop($key, $context); |
|
746 | 746 | |
747 | 747 | } |
748 | 748 | |
@@ -763,10 +763,10 @@ discard block |
||
763 | 763 | * @param string $status New status. |
764 | 764 | * @return array details of change. |
765 | 765 | */ |
766 | - public function set_status( $status ) { |
|
766 | + public function set_status($status) { |
|
767 | 767 | $old_status = $this->get_status(); |
768 | 768 | |
769 | - $this->set_prop( 'status', $status ); |
|
769 | + $this->set_prop('status', $status); |
|
770 | 770 | |
771 | 771 | return array( |
772 | 772 | 'from' => $old_status, |
@@ -779,8 +779,8 @@ discard block |
||
779 | 779 | * |
780 | 780 | * @since 1.0.19 |
781 | 781 | */ |
782 | - public function set_version( $value ) { |
|
783 | - $this->set_prop( 'version', $value ); |
|
782 | + public function set_version($value) { |
|
783 | + $this->set_prop('version', $value); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
@@ -790,11 +790,11 @@ discard block |
||
790 | 790 | * @param string $value Value to set. |
791 | 791 | * @return bool Whether or not the date was set. |
792 | 792 | */ |
793 | - public function set_date_created( $value ) { |
|
794 | - $date = strtotime( $value ); |
|
793 | + public function set_date_created($value) { |
|
794 | + $date = strtotime($value); |
|
795 | 795 | |
796 | - if ( $date ) { |
|
797 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
796 | + if ($date) { |
|
797 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
798 | 798 | return true; |
799 | 799 | } |
800 | 800 | |
@@ -809,11 +809,11 @@ discard block |
||
809 | 809 | * @param string $value Value to set. |
810 | 810 | * @return bool Whether or not the date was set. |
811 | 811 | */ |
812 | - public function set_date_modified( $value ) { |
|
813 | - $date = strtotime( $value ); |
|
812 | + public function set_date_modified($value) { |
|
813 | + $date = strtotime($value); |
|
814 | 814 | |
815 | - if ( $date ) { |
|
816 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
815 | + if ($date) { |
|
816 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
817 | 817 | return true; |
818 | 818 | } |
819 | 819 | |
@@ -827,9 +827,9 @@ discard block |
||
827 | 827 | * @since 1.0.19 |
828 | 828 | * @param string $value New name. |
829 | 829 | */ |
830 | - public function set_name( $value ) { |
|
831 | - $name = sanitize_text_field( $value ); |
|
832 | - $this->set_prop( 'name', $name ); |
|
830 | + public function set_name($value) { |
|
831 | + $name = sanitize_text_field($value); |
|
832 | + $this->set_prop('name', $name); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,8 +838,8 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | * @param string $value New name. |
840 | 840 | */ |
841 | - public function set_title( $value ) { |
|
842 | - $this->set_name( $value ); |
|
841 | + public function set_title($value) { |
|
842 | + $this->set_name($value); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
@@ -848,9 +848,9 @@ discard block |
||
848 | 848 | * @since 1.0.19 |
849 | 849 | * @param string $value New description. |
850 | 850 | */ |
851 | - public function set_description( $value ) { |
|
852 | - $description = wp_kses_post( $value ); |
|
853 | - return $this->set_prop( 'description', $description ); |
|
851 | + public function set_description($value) { |
|
852 | + $description = wp_kses_post($value); |
|
853 | + return $this->set_prop('description', $description); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -859,8 +859,8 @@ discard block |
||
859 | 859 | * @since 1.0.19 |
860 | 860 | * @param string $value New description. |
861 | 861 | */ |
862 | - public function set_excerpt( $value ) { |
|
863 | - $this->set_description( $value ); |
|
862 | + public function set_excerpt($value) { |
|
863 | + $this->set_description($value); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
@@ -869,8 +869,8 @@ discard block |
||
869 | 869 | * @since 1.0.19 |
870 | 870 | * @param string $value New description. |
871 | 871 | */ |
872 | - public function set_summary( $value ) { |
|
873 | - $this->set_description( $value ); |
|
872 | + public function set_summary($value) { |
|
873 | + $this->set_description($value); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -879,8 +879,8 @@ discard block |
||
879 | 879 | * @since 1.0.19 |
880 | 880 | * @param int $value New author. |
881 | 881 | */ |
882 | - public function set_author( $value ) { |
|
883 | - $this->set_prop( 'author', (int) $value ); |
|
882 | + public function set_author($value) { |
|
883 | + $this->set_prop('author', (int) $value); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -889,9 +889,9 @@ discard block |
||
889 | 889 | * @since 1.0.19 |
890 | 890 | * @param string $value New discount code. |
891 | 891 | */ |
892 | - public function set_code( $value ) { |
|
893 | - $code = sanitize_text_field( $value ); |
|
894 | - $this->set_prop( 'code', $code ); |
|
892 | + public function set_code($value) { |
|
893 | + $code = sanitize_text_field($value); |
|
894 | + $this->set_prop('code', $code); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -900,8 +900,8 @@ discard block |
||
900 | 900 | * @since 1.0.19 |
901 | 901 | * @param string $value New discount code. |
902 | 902 | */ |
903 | - public function set_coupon_code( $value ) { |
|
904 | - $this->set_code( $value ); |
|
903 | + public function set_coupon_code($value) { |
|
904 | + $this->set_code($value); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | * @since 1.0.19 |
911 | 911 | * @param string $value New discount code. |
912 | 912 | */ |
913 | - public function set_discount_code( $value ) { |
|
914 | - $this->set_code( $value ); |
|
913 | + public function set_discount_code($value) { |
|
914 | + $this->set_code($value); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
@@ -920,9 +920,9 @@ discard block |
||
920 | 920 | * @since 1.0.19 |
921 | 921 | * @param float $value New discount code. |
922 | 922 | */ |
923 | - public function set_amount( $value ) { |
|
924 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
925 | - $this->set_prop( 'amount', $amount ); |
|
923 | + public function set_amount($value) { |
|
924 | + $amount = floatval(wpinv_sanitize_amount($value)); |
|
925 | + $this->set_prop('amount', $amount); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
@@ -931,15 +931,15 @@ discard block |
||
931 | 931 | * @since 1.0.19 |
932 | 932 | * @param float $value New start date. |
933 | 933 | */ |
934 | - public function set_start( $value ) { |
|
935 | - $date = strtotime( $value ); |
|
934 | + public function set_start($value) { |
|
935 | + $date = strtotime($value); |
|
936 | 936 | |
937 | - if ( $date ) { |
|
938 | - $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
937 | + if ($date) { |
|
938 | + $this->set_prop('start', date('Y-m-d H:i', $date)); |
|
939 | 939 | return true; |
940 | 940 | } |
941 | 941 | |
942 | - $this->set_prop( 'start', '' ); |
|
942 | + $this->set_prop('start', ''); |
|
943 | 943 | |
944 | 944 | return false; |
945 | 945 | } |
@@ -950,8 +950,8 @@ discard block |
||
950 | 950 | * @since 1.0.19 |
951 | 951 | * @param string $value New start date. |
952 | 952 | */ |
953 | - public function set_start_date( $value ) { |
|
954 | - $this->set_start( $value ); |
|
953 | + public function set_start_date($value) { |
|
954 | + $this->set_start($value); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | /** |
@@ -960,15 +960,15 @@ discard block |
||
960 | 960 | * @since 1.0.19 |
961 | 961 | * @param float $value New expiration date. |
962 | 962 | */ |
963 | - public function set_expiration( $value ) { |
|
964 | - $date = strtotime( $value ); |
|
963 | + public function set_expiration($value) { |
|
964 | + $date = strtotime($value); |
|
965 | 965 | |
966 | - if ( $date ) { |
|
967 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
|
966 | + if ($date) { |
|
967 | + $this->set_prop('expiration', date('Y-m-d H:i', $date)); |
|
968 | 968 | return true; |
969 | 969 | } |
970 | 970 | |
971 | - $this->set_prop( 'expiration', '' ); |
|
971 | + $this->set_prop('expiration', ''); |
|
972 | 972 | return false; |
973 | 973 | } |
974 | 974 | |
@@ -978,8 +978,8 @@ discard block |
||
978 | 978 | * @since 1.0.19 |
979 | 979 | * @param string $value New expiration date. |
980 | 980 | */ |
981 | - public function set_expiration_date( $value ) { |
|
982 | - $this->set_expiration( $value ); |
|
981 | + public function set_expiration_date($value) { |
|
982 | + $this->set_expiration($value); |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | /** |
@@ -988,8 +988,8 @@ discard block |
||
988 | 988 | * @since 1.0.19 |
989 | 989 | * @param string $value New expiration date. |
990 | 990 | */ |
991 | - public function set_end_date( $value ) { |
|
992 | - $this->set_expiration( $value ); |
|
991 | + public function set_end_date($value) { |
|
992 | + $this->set_expiration($value); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | /** |
@@ -998,9 +998,9 @@ discard block |
||
998 | 998 | * @since 1.0.19 |
999 | 999 | * @param string $value New discount type. |
1000 | 1000 | */ |
1001 | - public function set_type( $value ) { |
|
1002 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
1003 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
1001 | + public function set_type($value) { |
|
1002 | + if ($value && array_key_exists(sanitize_text_field($value), wpinv_get_discount_types())) { |
|
1003 | + $this->set_prop('type', sanitize_text_field($value)); |
|
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | |
@@ -1010,15 +1010,15 @@ discard block |
||
1010 | 1010 | * @since 1.0.19 |
1011 | 1011 | * @param int $value usage count. |
1012 | 1012 | */ |
1013 | - public function set_uses( $value ) { |
|
1013 | + public function set_uses($value) { |
|
1014 | 1014 | |
1015 | 1015 | $value = (int) $value; |
1016 | 1016 | |
1017 | - if ( $value < 0 ) { |
|
1017 | + if ($value < 0) { |
|
1018 | 1018 | $value = 0; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - $this->set_prop( 'uses', (int) $value ); |
|
1021 | + $this->set_prop('uses', (int) $value); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | /** |
@@ -1027,8 +1027,8 @@ discard block |
||
1027 | 1027 | * @since 1.0.19 |
1028 | 1028 | * @param int $value maximum usage count. |
1029 | 1029 | */ |
1030 | - public function set_max_uses( $value ) { |
|
1031 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1030 | + public function set_max_uses($value) { |
|
1031 | + $this->set_prop('max_uses', absint($value)); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
@@ -1037,8 +1037,8 @@ discard block |
||
1037 | 1037 | * @since 1.0.19 |
1038 | 1038 | * @param int|bool $value is single use. |
1039 | 1039 | */ |
1040 | - public function set_is_single_use( $value ) { |
|
1041 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1040 | + public function set_is_single_use($value) { |
|
1041 | + $this->set_prop('is_single_use', (bool) $value); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
@@ -1047,8 +1047,8 @@ discard block |
||
1047 | 1047 | * @since 1.0.19 |
1048 | 1048 | * @param array $value items. |
1049 | 1049 | */ |
1050 | - public function set_items( $value ) { |
|
1051 | - $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
1050 | + public function set_items($value) { |
|
1051 | + $this->set_prop('items', wpinv_parse_list($value)); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1057,8 +1057,8 @@ discard block |
||
1057 | 1057 | * @since 1.0.19 |
1058 | 1058 | * @param array $value items. |
1059 | 1059 | */ |
1060 | - public function set_allowed_items( $value ) { |
|
1061 | - $this->set_items( $value ); |
|
1060 | + public function set_allowed_items($value) { |
|
1061 | + $this->set_items($value); |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | /** |
@@ -1067,8 +1067,8 @@ discard block |
||
1067 | 1067 | * @since 1.0.19 |
1068 | 1068 | * @param array $value items. |
1069 | 1069 | */ |
1070 | - public function set_excluded_items( $value ) { |
|
1071 | - $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
1070 | + public function set_excluded_items($value) { |
|
1071 | + $this->set_prop('excluded_items', wpinv_parse_list($value)); |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | /** |
@@ -1077,8 +1077,8 @@ discard block |
||
1077 | 1077 | * @since 1.0.19 |
1078 | 1078 | * @param int|bool $value is recurring. |
1079 | 1079 | */ |
1080 | - public function set_is_recurring( $value ) { |
|
1081 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1080 | + public function set_is_recurring($value) { |
|
1081 | + $this->set_prop('is_recurring', (bool) $value); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | /** |
@@ -1087,8 +1087,8 @@ discard block |
||
1087 | 1087 | * @since 1.0.19 |
1088 | 1088 | * @param float $value minimum total. |
1089 | 1089 | */ |
1090 | - public function set_min_total( $value ) { |
|
1091 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1090 | + public function set_min_total($value) { |
|
1091 | + $this->set_prop('min_total', (float) wpinv_sanitize_amount($value)); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | /** |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @since 1.0.19 |
1098 | 1098 | * @param float $value minimum total. |
1099 | 1099 | */ |
1100 | - public function set_minimum_total( $value ) { |
|
1101 | - $this->set_min_total( $value ); |
|
1100 | + public function set_minimum_total($value) { |
|
1101 | + $this->set_min_total($value); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | /** |
@@ -1107,8 +1107,8 @@ discard block |
||
1107 | 1107 | * @since 1.0.19 |
1108 | 1108 | * @param float $value maximum total. |
1109 | 1109 | */ |
1110 | - public function set_max_total( $value ) { |
|
1111 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1110 | + public function set_max_total($value) { |
|
1111 | + $this->set_prop('max_total', (float) wpinv_sanitize_amount($value)); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | /** |
@@ -1117,8 +1117,8 @@ discard block |
||
1117 | 1117 | * @since 1.0.19 |
1118 | 1118 | * @param float $value maximum total. |
1119 | 1119 | */ |
1120 | - public function set_maximum_total( $value ) { |
|
1121 | - $this->set_max_total( $value ); |
|
1120 | + public function set_maximum_total($value) { |
|
1121 | + $this->set_max_total($value); |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | /** |
@@ -1130,16 +1130,16 @@ discard block |
||
1130 | 1130 | * @access public |
1131 | 1131 | * |
1132 | 1132 | */ |
1133 | - public function __set( $key, $value ) { |
|
1133 | + public function __set($key, $value) { |
|
1134 | 1134 | |
1135 | - if ( 'id' == strtolower( $key ) ) { |
|
1136 | - return $this->set_id( $value ); |
|
1135 | + if ('id' == strtolower($key)) { |
|
1136 | + return $this->set_id($value); |
|
1137 | 1137 | } |
1138 | 1138 | |
1139 | - if ( method_exists( $this, "set_$key") ) { |
|
1140 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
1139 | + if (method_exists($this, "set_$key")) { |
|
1140 | + call_user_func(array($this, "set_$key"), $value); |
|
1141 | 1141 | } else { |
1142 | - $this->set_prop( $key, $value ); |
|
1142 | + $this->set_prop($key, $value); |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | } |
@@ -1147,16 +1147,16 @@ discard block |
||
1147 | 1147 | /** |
1148 | 1148 | * @deprecated |
1149 | 1149 | */ |
1150 | - public function refresh(){} |
|
1150 | + public function refresh() {} |
|
1151 | 1151 | |
1152 | 1152 | /** |
1153 | 1153 | * @deprecated |
1154 | 1154 | * |
1155 | 1155 | */ |
1156 | - public function update_status( $status = 'publish' ){ |
|
1156 | + public function update_status($status = 'publish') { |
|
1157 | 1157 | |
1158 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1159 | - $this->set_status( $status ); |
|
1158 | + if ($this->exists() && $this->get_status() != $status) { |
|
1159 | + $this->set_status($status); |
|
1160 | 1160 | $this->save(); |
1161 | 1161 | } |
1162 | 1162 | |
@@ -1176,9 +1176,9 @@ discard block |
||
1176 | 1176 | * |
1177 | 1177 | * @since 1.0.15 |
1178 | 1178 | */ |
1179 | - public function exists(){ |
|
1179 | + public function exists() { |
|
1180 | 1180 | $id = $this->get_id(); |
1181 | - return ! empty( $id ); |
|
1181 | + return !empty($id); |
|
1182 | 1182 | } |
1183 | 1183 | |
1184 | 1184 | /** |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | * @since 1.0.15 |
1190 | 1190 | * @return bool |
1191 | 1191 | */ |
1192 | - public function is_type( $type ) { |
|
1192 | + public function is_type($type) { |
|
1193 | 1193 | return $this->get_type() == $type; |
1194 | 1194 | } |
1195 | 1195 | |
@@ -1211,7 +1211,7 @@ discard block |
||
1211 | 1211 | */ |
1212 | 1212 | public function has_limit() { |
1213 | 1213 | $limit = $this->get_max_uses(); |
1214 | - return ! empty( $limit ); |
|
1214 | + return !empty($limit); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | /** |
@@ -1232,13 +1232,13 @@ discard block |
||
1232 | 1232 | */ |
1233 | 1233 | public function has_exceeded_limit() { |
1234 | 1234 | |
1235 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1236 | - $exceeded = false ; |
|
1235 | + if (!$this->has_limit() || !$this->has_uses()) { |
|
1236 | + $exceeded = false; |
|
1237 | 1237 | } else { |
1238 | - $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
1238 | + $exceeded = !((int) $this->get_max_uses() < $this->get_uses()); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code ); |
|
1241 | + return apply_filters('wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | /** |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | */ |
1250 | 1250 | public function has_expiration_date() { |
1251 | 1251 | $date = $this->get_expiration_date(); |
1252 | - return ! empty( $date ); |
|
1252 | + return !empty($date); |
|
1253 | 1253 | } |
1254 | 1254 | |
1255 | 1255 | /** |
@@ -1259,8 +1259,8 @@ discard block |
||
1259 | 1259 | * @return bool |
1260 | 1260 | */ |
1261 | 1261 | public function is_expired() { |
1262 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1263 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code ); |
|
1262 | + $expired = $this->has_expiration_date() ? current_time('timestamp') > strtotime($this->get_expiration_date()) : false; |
|
1263 | + return apply_filters('wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code); |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | /** |
@@ -1271,7 +1271,7 @@ discard block |
||
1271 | 1271 | */ |
1272 | 1272 | public function has_start_date() { |
1273 | 1273 | $date = $this->get_start_date(); |
1274 | - return ! empty( $date ); |
|
1274 | + return !empty($date); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | 1277 | /** |
@@ -1281,8 +1281,8 @@ discard block |
||
1281 | 1281 | * @return bool |
1282 | 1282 | */ |
1283 | 1283 | public function has_started() { |
1284 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1285 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code ); |
|
1284 | + $started = $this->has_start_date() ? true : current_time('timestamp') > strtotime($this->get_start_date()); |
|
1285 | + return apply_filters('wpinv_is_discount_started', $started, $this->ID, $this, $this->code); |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | /** |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | */ |
1294 | 1294 | public function has_allowed_items() { |
1295 | 1295 | $allowed_items = $this->get_allowed_items(); |
1296 | - return empty( $allowed_items ); |
|
1296 | + return empty($allowed_items); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | /** |
@@ -1304,7 +1304,7 @@ discard block |
||
1304 | 1304 | */ |
1305 | 1305 | public function has_excluded_items() { |
1306 | 1306 | $excluded_items = $this->get_excluded_items(); |
1307 | - return empty( $excluded_items ); |
|
1307 | + return empty($excluded_items); |
|
1308 | 1308 | } |
1309 | 1309 | |
1310 | 1310 | /** |
@@ -1314,17 +1314,17 @@ discard block |
||
1314 | 1314 | * @since 1.0.15 |
1315 | 1315 | * @return boolean |
1316 | 1316 | */ |
1317 | - public function is_valid_for_items( $item_ids ) { |
|
1317 | + public function is_valid_for_items($item_ids) { |
|
1318 | 1318 | |
1319 | - $item_ids = array_map( 'intval', wpinv_parse_list( $item_ids ) ); |
|
1320 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1321 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1319 | + $item_ids = array_map('intval', wpinv_parse_list($item_ids)); |
|
1320 | + $included = array_intersect($item_ids, $this->get_allowed_items()); |
|
1321 | + $excluded = array_intersect($item_ids, $this->get_excluded_items()); |
|
1322 | 1322 | |
1323 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1323 | + if ($this->has_excluded_items() && !empty($excluded)) { |
|
1324 | 1324 | return false; |
1325 | 1325 | } |
1326 | 1326 | |
1327 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1327 | + if ($this->has_allowed_items() && empty($included)) { |
|
1328 | 1328 | return false; |
1329 | 1329 | } |
1330 | 1330 | return true; |
@@ -1337,8 +1337,8 @@ discard block |
||
1337 | 1337 | * @since 1.0.15 |
1338 | 1338 | * @return boolean |
1339 | 1339 | */ |
1340 | - public function is_valid_for_amount( $amount ) { |
|
1341 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1340 | + public function is_valid_for_amount($amount) { |
|
1341 | + return $this->is_minimum_amount_met($amount) && $this->is_maximum_amount_met($amount); |
|
1342 | 1342 | } |
1343 | 1343 | |
1344 | 1344 | /** |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | */ |
1350 | 1350 | public function has_minimum_amount() { |
1351 | 1351 | $minimum = $this->get_minimum_total(); |
1352 | - return ! empty( $minimum ); |
|
1352 | + return !empty($minimum); |
|
1353 | 1353 | } |
1354 | 1354 | |
1355 | 1355 | /** |
@@ -1359,10 +1359,10 @@ discard block |
||
1359 | 1359 | * @since 1.0.15 |
1360 | 1360 | * @return boolean |
1361 | 1361 | */ |
1362 | - public function is_minimum_amount_met( $amount ) { |
|
1363 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1364 | - $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1365 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount ); |
|
1362 | + public function is_minimum_amount_met($amount) { |
|
1363 | + $amount = floatval(wpinv_sanitize_amount($amount)); |
|
1364 | + $min_met = !($this->has_minimum_amount() && $amount < floatval(wpinv_sanitize_amount($this->get_minimum_total()))); |
|
1365 | + return apply_filters('wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | 1368 | /** |
@@ -1373,7 +1373,7 @@ discard block |
||
1373 | 1373 | */ |
1374 | 1374 | public function has_maximum_amount() { |
1375 | 1375 | $maximum = $this->get_maximum_total(); |
1376 | - return ! empty( $maximum ); |
|
1376 | + return !empty($maximum); |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | 1379 | /** |
@@ -1383,10 +1383,10 @@ discard block |
||
1383 | 1383 | * @since 1.0.15 |
1384 | 1384 | * @return boolean |
1385 | 1385 | */ |
1386 | - public function is_maximum_amount_met( $amount ) { |
|
1387 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1388 | - $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1389 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount ); |
|
1386 | + public function is_maximum_amount_met($amount) { |
|
1387 | + $amount = floatval(wpinv_sanitize_amount($amount)); |
|
1388 | + $max_met = !($this->has_maximum_amount() && $amount > floatval(wpinv_sanitize_amount($this->get_maximum_total()))); |
|
1389 | + return apply_filters('wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount); |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | /** |
@@ -1397,7 +1397,7 @@ discard block |
||
1397 | 1397 | */ |
1398 | 1398 | public function is_recurring() { |
1399 | 1399 | $recurring = $this->get_is_recurring(); |
1400 | - return ! empty( $recurring ); |
|
1400 | + return !empty($recurring); |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | 1403 | /** |
@@ -1408,7 +1408,7 @@ discard block |
||
1408 | 1408 | */ |
1409 | 1409 | public function is_single_use() { |
1410 | 1410 | $usage = $this->get_is_single_use(); |
1411 | - return ! empty( $usage ); |
|
1411 | + return !empty($usage); |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | /** |
@@ -1418,57 +1418,57 @@ discard block |
||
1418 | 1418 | * @since 1.0.15 |
1419 | 1419 | * @return boolean |
1420 | 1420 | */ |
1421 | - public function is_valid_for_user( $user ) { |
|
1421 | + public function is_valid_for_user($user) { |
|
1422 | 1422 | global $wpi_checkout_id; |
1423 | 1423 | |
1424 | 1424 | // Ensure that the discount is single use. |
1425 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1425 | + if (empty($user) || !$this->is_single_use()) { |
|
1426 | 1426 | return true; |
1427 | 1427 | } |
1428 | 1428 | |
1429 | 1429 | // Prepare the user id. |
1430 | 1430 | $user_id = 0; |
1431 | - if ( is_int( $user ) ) { |
|
1432 | - $user_id = absint( $user ); |
|
1433 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
1431 | + if (is_int($user)) { |
|
1432 | + $user_id = absint($user); |
|
1433 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
1434 | 1434 | $user_id = $user_data->ID; |
1435 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
1435 | + } else if ($user_data = get_user_by('login', $user)) { |
|
1436 | 1436 | $user_id = $user_data->ID; |
1437 | - } else if ( absint( $user ) > 0 ) { |
|
1438 | - $user_id = absint( $user ); |
|
1437 | + } else if (absint($user) > 0) { |
|
1438 | + $user_id = absint($user); |
|
1439 | 1439 | } |
1440 | 1440 | |
1441 | 1441 | // Ensure that we have a user. |
1442 | - if ( empty( $user_id ) ) { |
|
1442 | + if (empty($user_id)) { |
|
1443 | 1443 | return true; |
1444 | 1444 | } |
1445 | 1445 | |
1446 | 1446 | // Get all payments with matching user id. |
1447 | - $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) ); |
|
1448 | - $code = strtolower( $this->get_code() ); |
|
1447 | + $payments = wpinv_get_invoices(array('user' => $user_id, 'limit' => false)); |
|
1448 | + $code = strtolower($this->get_code()); |
|
1449 | 1449 | |
1450 | 1450 | // For each payment... |
1451 | - foreach ( $payments as $payment ) { |
|
1451 | + foreach ($payments as $payment) { |
|
1452 | 1452 | |
1453 | 1453 | // ... skip the current payment. |
1454 | - if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
1454 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
1455 | 1455 | continue; |
1456 | 1456 | } |
1457 | 1457 | |
1458 | 1458 | // And failed payments. |
1459 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
1459 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
1460 | 1460 | continue; |
1461 | 1461 | } |
1462 | 1462 | |
1463 | 1463 | // Retrieve all the discounts for the payment. |
1464 | - $discounts = $payment->get_discounts( true ); |
|
1465 | - if ( empty( $discounts ) ) { |
|
1464 | + $discounts = $payment->get_discounts(true); |
|
1465 | + if (empty($discounts)) { |
|
1466 | 1466 | continue; |
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | // And check if the current discount is amongst them. |
1470 | - $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) ); |
|
1471 | - if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
1470 | + $discounts = array_map('strtolower', wpinv_parse_list($discounts)); |
|
1471 | + if (!empty($discounts) && in_array($code, $discounts)) { |
|
1472 | 1472 | return false; |
1473 | 1473 | } |
1474 | 1474 | } |
@@ -1493,24 +1493,24 @@ discard block |
||
1493 | 1493 | * @param int $by The number of usages to increas by. |
1494 | 1494 | * @return int |
1495 | 1495 | */ |
1496 | - public function increase_usage( $by = 1 ) { |
|
1496 | + public function increase_usage($by = 1) { |
|
1497 | 1497 | |
1498 | 1498 | // Abort if zero. |
1499 | - if ( empty( $by ) ) { |
|
1499 | + if (empty($by)) { |
|
1500 | 1500 | return; |
1501 | 1501 | } |
1502 | 1502 | |
1503 | 1503 | // Increase the usage. |
1504 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1504 | + $this->set_uses($this->get_uses() + (int) $by); |
|
1505 | 1505 | |
1506 | 1506 | // Save the discount. |
1507 | 1507 | $this->save(); |
1508 | 1508 | |
1509 | 1509 | // Fire relevant hooks. |
1510 | - if( (int) $by > 0 ) { |
|
1511 | - do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
1510 | + if ((int) $by > 0) { |
|
1511 | + do_action('wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, absint($by)); |
|
1512 | 1512 | } else { |
1513 | - do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
1513 | + do_action('wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint($by)); |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | // Return the number of times the discount has been used. |
@@ -1534,7 +1534,7 @@ discard block |
||
1534 | 1534 | * @param float $amount |
1535 | 1535 | * @return float |
1536 | 1536 | */ |
1537 | - public function get_discounted_amount( $amount ) { |
|
1537 | + public function get_discounted_amount($amount) { |
|
1538 | 1538 | |
1539 | 1539 | // Convert amount to float. |
1540 | 1540 | $amount = (float) $amount; |
@@ -1542,29 +1542,29 @@ discard block |
||
1542 | 1542 | // Get discount amount. |
1543 | 1543 | $discount_amount = $this->get_amount(); |
1544 | 1544 | |
1545 | - if ( empty( $discount_amount ) ) { |
|
1545 | + if (empty($discount_amount)) { |
|
1546 | 1546 | return 0; |
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | // Format the amount. |
1550 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1550 | + $discount_amount = floatval(wpinv_sanitize_amount($discount_amount)); |
|
1551 | 1551 | |
1552 | 1552 | // If this is a percentage discount. |
1553 | - if ( $this->is_type( 'percent' ) ) { |
|
1554 | - $discount_amount = $amount * ( $discount_amount / 100 ); |
|
1553 | + if ($this->is_type('percent')) { |
|
1554 | + $discount_amount = $amount * ($discount_amount / 100); |
|
1555 | 1555 | } |
1556 | 1556 | |
1557 | 1557 | // Discount can not be less than zero... |
1558 | - if ( $discount_amount < 0 ) { |
|
1558 | + if ($discount_amount < 0) { |
|
1559 | 1559 | $discount_amount = 0; |
1560 | 1560 | } |
1561 | 1561 | |
1562 | 1562 | // ... or more than the amount. |
1563 | - if ( $discount_amount > $amount ) { |
|
1563 | + if ($discount_amount > $amount) { |
|
1564 | 1564 | $discount_amount = $amount; |
1565 | 1565 | } |
1566 | 1566 | |
1567 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1567 | + return apply_filters('wpinv_discount_total_discount_amount', $discount_amount, $amount, $this); |
|
1568 | 1568 | } |
1569 | 1569 | |
1570 | 1570 | } |
@@ -11,184 +11,184 @@ |
||
11 | 11 | */ |
12 | 12 | class GetPaid_Data_Store { |
13 | 13 | |
14 | - /** |
|
15 | - * Contains an instance of the data store class that we are working with. |
|
16 | - * |
|
17 | - * @var GetPaid_Data_Store |
|
18 | - */ |
|
19 | - private $instance = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * Contains an array of default supported data stores. |
|
23 | - * Format of object name => class name. |
|
24 | - * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | - * You can also pass something like item-<type> for item stores and |
|
26 | - * that type will be used first when available, if a store is requested like |
|
27 | - * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | - * Ran through `getpaid_data_stores`. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $stores = array( |
|
33 | - 'item' => 'GetPaid_Item_Data_Store', |
|
34 | - 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | - 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | - ); |
|
37 | - |
|
38 | - /** |
|
39 | - * Contains the name of the current data store's class name. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - private $current_class_name = ''; |
|
44 | - |
|
45 | - /** |
|
46 | - * The object type this store works with. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $object_type = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * Tells GetPaid_Data_Store which object |
|
54 | - * store we want to work with. |
|
55 | - * |
|
56 | - * @param string $object_type Name of object. |
|
57 | - */ |
|
58 | - public function __construct( $object_type ) { |
|
59 | - $this->object_type = $object_type; |
|
60 | - $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
61 | - |
|
62 | - // If this object type can't be found, check to see if we can load one |
|
63 | - // level up (so if item-type isn't found, we try item). |
|
64 | - if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
65 | - $pieces = explode( '-', $object_type ); |
|
66 | - $object_type = $pieces[0]; |
|
67 | - } |
|
68 | - |
|
69 | - if ( array_key_exists( $object_type, $this->stores ) ) { |
|
70 | - $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
71 | - if ( is_object( $store ) ) { |
|
72 | - $this->current_class_name = get_class( $store ); |
|
73 | - $this->instance = $store; |
|
74 | - } else { |
|
75 | - if ( ! class_exists( $store ) ) { |
|
76 | - throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
77 | - } |
|
78 | - $this->current_class_name = $store; |
|
79 | - $this->instance = new $store(); |
|
80 | - } |
|
81 | - } else { |
|
82 | - throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Only store the object type to avoid serializing the data store instance. |
|
88 | - * |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function __sleep() { |
|
92 | - return array( 'object_type' ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Re-run the constructor with the object type. |
|
97 | - * |
|
98 | - * @throws Exception When validation fails. |
|
99 | - */ |
|
100 | - public function __wakeup() { |
|
101 | - $this->__construct( $this->object_type ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Loads a data store. |
|
106 | - * |
|
107 | - * @param string $object_type Name of object. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @throws Exception When validation fails. |
|
111 | - * @return GetPaid_Data_Store |
|
112 | - */ |
|
113 | - public static function load( $object_type ) { |
|
114 | - return new GetPaid_Data_Store( $object_type ); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Returns the class name of the current data store. |
|
119 | - * |
|
120 | - * @since 1.0.19 |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_current_class_name() { |
|
124 | - return $this->current_class_name; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns the object type of the current data store. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_object_type() { |
|
134 | - return $this->object_type; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Reads an object from the data store. |
|
139 | - * |
|
140 | - * @since 1.0.19 |
|
141 | - * @param GetPaid_Data $data GetPaid data instance. |
|
142 | - */ |
|
143 | - public function read( &$data ) { |
|
144 | - $this->instance->read( $data ); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Create an object in the data store. |
|
149 | - * |
|
150 | - * @since 1.0.19 |
|
151 | - * @param GetPaid_Data $data GetPaid data instance. |
|
152 | - */ |
|
153 | - public function create( &$data ) { |
|
154 | - $this->instance->create( $data ); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Update an object in the data store. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param GetPaid_Data $data GetPaid data instance. |
|
162 | - */ |
|
163 | - public function update( &$data ) { |
|
164 | - $this->instance->update( $data ); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Delete an object from the data store. |
|
169 | - * |
|
170 | - * @since 1.0.19 |
|
171 | - * @param GetPaid_Data $data GetPaid data instance. |
|
172 | - * @param array $args Array of args to pass to the delete method. |
|
173 | - */ |
|
174 | - public function delete( &$data, $args = array() ) { |
|
175 | - $this->instance->delete( $data, $args ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Data stores can define additional function. This passes |
|
180 | - * through to the instance if that function exists. |
|
181 | - * |
|
182 | - * @since 1.0.19 |
|
183 | - * @param string $method Method. |
|
184 | - * @return mixed |
|
185 | - */ |
|
186 | - public function __call( $method, $parameters ) { |
|
187 | - if ( is_callable( array( $this->instance, $method ) ) ) { |
|
188 | - $object = array_shift( $parameters ); |
|
189 | - $parameters = array_merge( array( &$object ), $parameters ); |
|
190 | - return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
191 | - } |
|
192 | - } |
|
14 | + /** |
|
15 | + * Contains an instance of the data store class that we are working with. |
|
16 | + * |
|
17 | + * @var GetPaid_Data_Store |
|
18 | + */ |
|
19 | + private $instance = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * Contains an array of default supported data stores. |
|
23 | + * Format of object name => class name. |
|
24 | + * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | + * You can also pass something like item-<type> for item stores and |
|
26 | + * that type will be used first when available, if a store is requested like |
|
27 | + * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | + * Ran through `getpaid_data_stores`. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $stores = array( |
|
33 | + 'item' => 'GetPaid_Item_Data_Store', |
|
34 | + 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | + 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | + ); |
|
37 | + |
|
38 | + /** |
|
39 | + * Contains the name of the current data store's class name. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + private $current_class_name = ''; |
|
44 | + |
|
45 | + /** |
|
46 | + * The object type this store works with. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $object_type = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * Tells GetPaid_Data_Store which object |
|
54 | + * store we want to work with. |
|
55 | + * |
|
56 | + * @param string $object_type Name of object. |
|
57 | + */ |
|
58 | + public function __construct( $object_type ) { |
|
59 | + $this->object_type = $object_type; |
|
60 | + $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
61 | + |
|
62 | + // If this object type can't be found, check to see if we can load one |
|
63 | + // level up (so if item-type isn't found, we try item). |
|
64 | + if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
65 | + $pieces = explode( '-', $object_type ); |
|
66 | + $object_type = $pieces[0]; |
|
67 | + } |
|
68 | + |
|
69 | + if ( array_key_exists( $object_type, $this->stores ) ) { |
|
70 | + $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
71 | + if ( is_object( $store ) ) { |
|
72 | + $this->current_class_name = get_class( $store ); |
|
73 | + $this->instance = $store; |
|
74 | + } else { |
|
75 | + if ( ! class_exists( $store ) ) { |
|
76 | + throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
77 | + } |
|
78 | + $this->current_class_name = $store; |
|
79 | + $this->instance = new $store(); |
|
80 | + } |
|
81 | + } else { |
|
82 | + throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Only store the object type to avoid serializing the data store instance. |
|
88 | + * |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function __sleep() { |
|
92 | + return array( 'object_type' ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Re-run the constructor with the object type. |
|
97 | + * |
|
98 | + * @throws Exception When validation fails. |
|
99 | + */ |
|
100 | + public function __wakeup() { |
|
101 | + $this->__construct( $this->object_type ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Loads a data store. |
|
106 | + * |
|
107 | + * @param string $object_type Name of object. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @throws Exception When validation fails. |
|
111 | + * @return GetPaid_Data_Store |
|
112 | + */ |
|
113 | + public static function load( $object_type ) { |
|
114 | + return new GetPaid_Data_Store( $object_type ); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Returns the class name of the current data store. |
|
119 | + * |
|
120 | + * @since 1.0.19 |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_current_class_name() { |
|
124 | + return $this->current_class_name; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns the object type of the current data store. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_object_type() { |
|
134 | + return $this->object_type; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Reads an object from the data store. |
|
139 | + * |
|
140 | + * @since 1.0.19 |
|
141 | + * @param GetPaid_Data $data GetPaid data instance. |
|
142 | + */ |
|
143 | + public function read( &$data ) { |
|
144 | + $this->instance->read( $data ); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Create an object in the data store. |
|
149 | + * |
|
150 | + * @since 1.0.19 |
|
151 | + * @param GetPaid_Data $data GetPaid data instance. |
|
152 | + */ |
|
153 | + public function create( &$data ) { |
|
154 | + $this->instance->create( $data ); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Update an object in the data store. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param GetPaid_Data $data GetPaid data instance. |
|
162 | + */ |
|
163 | + public function update( &$data ) { |
|
164 | + $this->instance->update( $data ); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Delete an object from the data store. |
|
169 | + * |
|
170 | + * @since 1.0.19 |
|
171 | + * @param GetPaid_Data $data GetPaid data instance. |
|
172 | + * @param array $args Array of args to pass to the delete method. |
|
173 | + */ |
|
174 | + public function delete( &$data, $args = array() ) { |
|
175 | + $this->instance->delete( $data, $args ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Data stores can define additional function. This passes |
|
180 | + * through to the instance if that function exists. |
|
181 | + * |
|
182 | + * @since 1.0.19 |
|
183 | + * @param string $method Method. |
|
184 | + * @return mixed |
|
185 | + */ |
|
186 | + public function __call( $method, $parameters ) { |
|
187 | + if ( is_callable( array( $this->instance, $method ) ) ) { |
|
188 | + $object = array_shift( $parameters ); |
|
189 | + $parameters = array_merge( array( &$object ), $parameters ); |
|
190 | + return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,11 +368,11 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // verify nonce |
378 | 378 | if ( ! isset( $_POST['wpinv_discount_metabox_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) { |
@@ -384,23 +384,23 @@ discard block |
||
384 | 384 | |
385 | 385 | // Load new data. |
386 | 386 | $discount->set_props( |
387 | - array( |
|
388 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
389 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
390 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
391 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
392 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
387 | + array( |
|
388 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
389 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
390 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
391 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
392 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
393 | 393 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
394 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
395 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : null, |
|
396 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : null, |
|
397 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
398 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
399 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
400 | - ) |
|
394 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
395 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : null, |
|
396 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : null, |
|
397 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
398 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
399 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
400 | + ) |
|
401 | 401 | ); |
402 | 402 | |
403 | - $discount->save(); |
|
404 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
405 | - } |
|
403 | + $discount->save(); |
|
404 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
405 | + } |
|
406 | 406 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); |
|
30 | + wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | 'type' => 'datepicker', |
239 | 239 | 'id' => 'wpinv_discount_start', |
240 | 240 | 'name' => 'wpinv_discount_start', |
241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
241 | + 'label' => __('Start Date', 'invoicing'), |
|
242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
243 | 243 | 'class' => 'form-control-sm', |
244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
244 | + 'value' => $discount->get_start_date('edit'), |
|
245 | 245 | 'extra_attributes' => array( |
246 | 246 | 'data-enable-time' => 'true', |
247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | </div> |
254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
256 | 256 | </div> |
257 | 257 | </div> |
258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
259 | 259 | |
260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
261 | 261 | <div class="form-group row"> |
262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
264 | 264 | </label> |
265 | 265 | <div class="col-sm-8"> |
266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | 'type' => 'datepicker', |
270 | 270 | 'id' => 'wpinv_discount_expiration', |
271 | 271 | 'name' => 'wpinv_discount_expiration', |
272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
274 | 274 | 'class' => 'form-control-sm', |
275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
275 | + 'value' => $discount->get_end_date('edit'), |
|
276 | 276 | 'extra_attributes' => array( |
277 | 277 | 'data-enable-time' => 'true', |
278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | ?> |
286 | 286 | </div> |
287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
289 | 289 | </div> |
290 | 290 | </div> |
291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
292 | 292 | |
293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
294 | 294 | <div class="form-group row"> |
295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
297 | 297 | </label> |
298 | 298 | <div class="col-sm-8"> |
299 | 299 | <div class="input-group input-group-sm"> |
300 | - <?php if( 'left' == $position ) : ?> |
|
300 | + <?php if ('left' == $position) : ?> |
|
301 | 301 | <div class="input-group-prepend"> |
302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
303 | 303 | </div> |
304 | 304 | <?php endif; ?> |
305 | 305 | |
306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
307 | 307 | |
308 | - <?php if( 'left' != $position ) : ?> |
|
308 | + <?php if ('left' != $position) : ?> |
|
309 | 309 | <div class="input-group-append"> |
310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
356 | 356 | </div> |
357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
359 | 359 | </div> |
360 | 360 | </div> |
361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
362 | 362 | |
363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
364 | 364 | |
365 | 365 | </div> |
366 | 366 | <?php |
367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
367 | + do_action('wpinv_discount_form_bottom', $post); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,35 +372,35 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param int $post_id |
374 | 374 | */ |
375 | - public static function save( $post_id ) { |
|
375 | + public static function save($post_id) { |
|
376 | 376 | |
377 | 377 | // verify nonce |
378 | - if ( ! isset( $_POST['wpinv_discount_metabox_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) { |
|
378 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce')) { |
|
379 | 379 | return; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Prepare the discount. |
383 | - $discount = new WPInv_Discount( $post_id ); |
|
383 | + $discount = new WPInv_Discount($post_id); |
|
384 | 384 | |
385 | 385 | // Load new data. |
386 | 386 | $discount->set_props( |
387 | 387 | array( |
388 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
389 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
390 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
391 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
392 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
393 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
|
394 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
395 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : null, |
|
396 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : null, |
|
397 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
398 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
399 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
388 | + 'code' => isset($_POST['wpinv_discount_code']) ? $_POST['wpinv_discount_code'] : null, |
|
389 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? $_POST['wpinv_discount_amount'] : null, |
|
390 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
391 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
392 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
393 | + 'type' => isset($_POST['wpinv_discount_type']) ? $_POST['wpinv_discount_type'] : null, |
|
394 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
395 | + 'items' => isset($_POST['wpinv_discount_items']) ? $_POST['wpinv_discount_items'] : null, |
|
396 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? $_POST['wpinv_discount_excluded_items'] : null, |
|
397 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? $_POST['wpinv_discount_max_uses'] : null, |
|
398 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? $_POST['wpinv_discount_min_total'] : null, |
|
399 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? $_POST['wpinv_discount_max_total'] : null, |
|
400 | 400 | ) |
401 | 401 | ); |
402 | 402 | |
403 | 403 | $discount->save(); |
404 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
404 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
405 | 405 | } |
406 | 406 | } |
@@ -1,68 +1,68 @@ 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 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
29 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
28 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
29 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
30 | 30 | |
31 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
32 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
33 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
31 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
32 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
33 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
34 | 34 | |
35 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
36 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
35 | + if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) { |
|
36 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
40 | 40 | } |
41 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
41 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Saves meta boxes. |
45 | 45 | */ |
46 | -function wpinv_save_meta_boxes( $post_id, $post ) { |
|
47 | - remove_action( 'save_post', __FUNCTION__ ); |
|
46 | +function wpinv_save_meta_boxes($post_id, $post) { |
|
47 | + remove_action('save_post', __FUNCTION__); |
|
48 | 48 | |
49 | 49 | // $post_id and $post are required. |
50 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
50 | + if (empty($post_id) || empty($post)) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | // Ensure that this user can edit the post. |
55 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
55 | + if (!current_user_can('edit_post', $post_id)) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | 59 | // Dont' save meta boxes for revisions or autosaves |
60 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
60 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Do not save for ajax requests. |
65 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
65 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
@@ -75,46 +75,46 @@ discard block |
||
75 | 75 | ); |
76 | 76 | |
77 | 77 | // Is this our post type? |
78 | - if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
78 | + if (empty($post->post_type) || !isset($post_types_map[$post->post_type])) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Save the post. |
83 | - $class = $post_types_map[ $post->post_type ]; |
|
84 | - $class::save( $post_id, $_POST, $post ); |
|
83 | + $class = $post_types_map[$post->post_type]; |
|
84 | + $class::save($post_id, $_POST, $post); |
|
85 | 85 | |
86 | 86 | } |
87 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
87 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
88 | 88 | |
89 | 89 | function wpinv_register_item_meta_boxes() { |
90 | 90 | global $wpinv_euvat; |
91 | 91 | |
92 | 92 | // Item details metabox. |
93 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
93 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
94 | 94 | |
95 | 95 | // If taxes are enabled, register the tax metabox. |
96 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
97 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
96 | + if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) { |
|
97 | + add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | // Item info. |
101 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
101 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | 105 | function wpinv_register_discount_meta_boxes() { |
106 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
106 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Remove trash link from the default form. |
111 | 111 | */ |
112 | -function getpaid_remove_action_link( $actions, $post ) { |
|
113 | - $post = get_post( $post ); |
|
114 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
115 | - unset( $actions['trash'] ); |
|
116 | - unset( $actions['inline hide-if-no-js'] ); |
|
112 | +function getpaid_remove_action_link($actions, $post) { |
|
113 | + $post = get_post($post); |
|
114 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
115 | + unset($actions['trash']); |
|
116 | + unset($actions['inline hide-if-no-js']); |
|
117 | 117 | } |
118 | 118 | return $actions; |
119 | 119 | } |
120 | -add_filter( 'post_row_actions', 'getpaid_remove_action_link', 10, 2 ); |
|
120 | +add_filter('post_row_actions', 'getpaid_remove_action_link', 10, 2); |
@@ -1,38 +1,38 @@ 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 | -add_filter( 'manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns' ); |
|
8 | -function wpinv_payment_form_columns( $existing_columns ) { |
|
7 | +add_filter('manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns'); |
|
8 | +function wpinv_payment_form_columns($existing_columns) { |
|
9 | 9 | $date = $existing_columns['date']; |
10 | - unset( $existing_columns['date'] ); |
|
11 | - $existing_columns['shortcode'] = __( 'Shortcode', 'invoicing' ); |
|
10 | + unset($existing_columns['date']); |
|
11 | + $existing_columns['shortcode'] = __('Shortcode', 'invoicing'); |
|
12 | 12 | $existing_columns['date'] = $date; |
13 | 13 | return $existing_columns; |
14 | 14 | } |
15 | 15 | |
16 | -add_action( 'manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column' ); |
|
17 | -function wpinv_payment_form_custom_column( $column ) { |
|
16 | +add_action('manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column'); |
|
17 | +function wpinv_payment_form_custom_column($column) { |
|
18 | 18 | global $post; |
19 | 19 | |
20 | - if( 'shortcode' == $column ) { |
|
21 | - WPInv_Meta_Box_Payment_Form::output_shortcode( $post ); |
|
20 | + if ('shortcode' == $column) { |
|
21 | + WPInv_Meta_Box_Payment_Form::output_shortcode($post); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | } |
25 | 25 | |
26 | -function wpinv_filter_discount_post_state( $post_states, $post ) { |
|
26 | +function wpinv_filter_discount_post_state($post_states, $post) { |
|
27 | 27 | |
28 | - if ( 'wpi_discount' == $post->post_type ) { |
|
29 | - $discount = new WPInv_Discount( $post ); |
|
28 | + if ('wpi_discount' == $post->post_type) { |
|
29 | + $discount = new WPInv_Discount($post); |
|
30 | 30 | |
31 | 31 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
32 | 32 | |
33 | - if ( $status != 'publish' ) { |
|
33 | + if ($status != 'publish') { |
|
34 | 34 | return array( |
35 | - 'discount_status' => wpinv_discount_status( $status ), |
|
35 | + 'discount_status' => wpinv_discount_status($status), |
|
36 | 36 | ); |
37 | 37 | } |
38 | 38 | |
@@ -43,35 +43,35 @@ discard block |
||
43 | 43 | return $post_states; |
44 | 44 | |
45 | 45 | } |
46 | -add_filter( 'display_post_states', 'wpinv_filter_discount_post_state', 10, 2 ); |
|
46 | +add_filter('display_post_states', 'wpinv_filter_discount_post_state', 10, 2); |
|
47 | 47 | |
48 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
49 | -function wpinv_discount_columns( $columns ) { |
|
48 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
49 | +function wpinv_discount_columns($columns) { |
|
50 | 50 | |
51 | - if ( isset( $columns['date'] ) ) { |
|
52 | - unset( $columns['date'] ); |
|
51 | + if (isset($columns['date'])) { |
|
52 | + unset($columns['date']); |
|
53 | 53 | } |
54 | 54 | |
55 | - if ( isset( $columns['title'] ) ) { |
|
56 | - $columns['title'] = __( 'Name', 'invoicing' ); |
|
55 | + if (isset($columns['title'])) { |
|
56 | + $columns['title'] = __('Name', 'invoicing'); |
|
57 | 57 | } |
58 | 58 | |
59 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
60 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
61 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
62 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
63 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
59 | + $columns['code'] = __('Code', 'invoicing'); |
|
60 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
61 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
62 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
63 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
64 | 64 | |
65 | 65 | return $columns; |
66 | 66 | } |
67 | 67 | |
68 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
69 | -function wpinv_discount_custom_column( $column ) { |
|
68 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
69 | +function wpinv_discount_custom_column($column) { |
|
70 | 70 | global $post; |
71 | 71 | |
72 | - $discount = new WPInv_Discount( $post ); |
|
72 | + $discount = new WPInv_Discount($post); |
|
73 | 73 | |
74 | - switch ( $column ) { |
|
74 | + switch ($column) { |
|
75 | 75 | case 'code' : |
76 | 76 | echo $discount->get_code(); |
77 | 77 | break; |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | echo $discount->get_usage(); |
83 | 83 | break; |
84 | 84 | case 'start_date' : |
85 | - if ( $discount->has_start_date() ) { |
|
86 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $discount->get_start_date() ) ); |
|
85 | + if ($discount->has_start_date()) { |
|
86 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($discount->get_start_date())); |
|
87 | 87 | } else { |
88 | 88 | $value = '—'; |
89 | 89 | } |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | echo $value; |
92 | 92 | break; |
93 | 93 | case 'expiry_date' : |
94 | - if ( $discount->has_expiration_date() ) { |
|
95 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $discount->get_expiration_date() ) ); |
|
94 | + if ($discount->has_expiration_date()) { |
|
95 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($discount->get_expiration_date())); |
|
96 | 96 | } else { |
97 | - $value = __( 'Never', 'invoicing' ); |
|
97 | + $value = __('Never', 'invoicing'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | echo $value; |
@@ -102,30 +102,30 @@ discard block |
||
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
106 | -function wpinv_post_row_actions( $actions, $post ) { |
|
107 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
105 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
106 | +function wpinv_post_row_actions($actions, $post) { |
|
107 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
108 | 108 | |
109 | - if ( $post_type == 'wpi_invoice' ) { |
|
109 | + if ($post_type == 'wpi_invoice') { |
|
110 | 110 | $actions = array(); |
111 | 111 | } |
112 | 112 | |
113 | - if ( $post_type == 'wpi_discount' ) { |
|
114 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
113 | + if ($post_type == 'wpi_discount') { |
|
114 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return $actions; |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
121 | - $row_actions = array(); |
|
122 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
123 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
120 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
121 | + $row_actions = array(); |
|
122 | + $edit_link = get_edit_post_link($discount->ID); |
|
123 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
124 | 124 | |
125 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
126 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
127 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
128 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
125 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
126 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
127 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
128 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | $delete_url = esc_url( |
@@ -139,110 +139,110 @@ discard block |
||
139 | 139 | 'wpinv_discount_nonce' |
140 | 140 | ) |
141 | 141 | ); |
142 | - $row_actions['delete'] = '<a href="' . $delete_url . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
142 | + $row_actions['delete'] = '<a href="' . $delete_url . '">' . __('Delete', 'invoicing') . '</a>'; |
|
143 | 143 | |
144 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
144 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
145 | 145 | |
146 | 146 | return $row_actions; |
147 | 147 | } |
148 | 148 | |
149 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
150 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
151 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
149 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
150 | +function wpinv_table_primary_column($default, $screen_id) { |
|
151 | + if ('edit-wpi_invoice' === $screen_id) { |
|
152 | 152 | return 'name'; |
153 | 153 | } |
154 | 154 | |
155 | 155 | return $default; |
156 | 156 | } |
157 | 157 | |
158 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
159 | - if ( !$display ) { |
|
158 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
159 | + if (!$display) { |
|
160 | 160 | return array(); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $actions = array( |
164 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
165 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
166 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
164 | + 'activate' => __('Activate', 'invoicing'), |
|
165 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
166 | + 'delete' => __('Delete', 'invoicing'), |
|
167 | 167 | ); |
168 | 168 | $two = ''; |
169 | 169 | $which = 'top'; |
170 | 170 | echo '</div><div class="alignleft actions bulkactions">'; |
171 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
172 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
173 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
171 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
172 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
173 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
174 | 174 | |
175 | - foreach ( $actions as $name => $title ) { |
|
175 | + foreach ($actions as $name => $title) { |
|
176 | 176 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
177 | 177 | |
178 | 178 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
179 | 179 | } |
180 | 180 | echo "</select>"; |
181 | 181 | |
182 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
182 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
183 | 183 | |
184 | 184 | echo '</div><div class="alignleft actions">'; |
185 | 185 | } |
186 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
186 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
187 | 187 | |
188 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
189 | - if ( $post_type == 'wpi_discount' ) { |
|
188 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
189 | + if ($post_type == 'wpi_discount') { |
|
190 | 190 | $disable = true; |
191 | 191 | } |
192 | 192 | |
193 | 193 | return $disable; |
194 | 194 | } |
195 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
195 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
196 | 196 | |
197 | 197 | function wpinv_restrict_manage_posts() { |
198 | 198 | global $typenow; |
199 | 199 | |
200 | - if( 'wpi_discount' == $typenow ) { |
|
200 | + if ('wpi_discount' == $typenow) { |
|
201 | 201 | wpinv_discount_filters(); |
202 | 202 | } |
203 | 203 | } |
204 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
204 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
205 | 205 | |
206 | 206 | function wpinv_discount_filters() { |
207 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
207 | + echo wpinv_discount_bulk_actions(array(), true); |
|
208 | 208 | |
209 | 209 | ?> |
210 | 210 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
211 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
211 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
212 | 212 | <?php |
213 | 213 | $types = wpinv_get_discount_types(); |
214 | 214 | |
215 | - foreach ( $types as $name => $type ) { |
|
216 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
215 | + foreach ($types as $name => $type) { |
|
216 | + echo '<option value="' . esc_attr($name) . '"'; |
|
217 | 217 | |
218 | - if ( isset( $_GET['discount_type'] ) ) |
|
219 | - selected( $name, $_GET['discount_type'] ); |
|
218 | + if (isset($_GET['discount_type'])) |
|
219 | + selected($name, $_GET['discount_type']); |
|
220 | 220 | |
221 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
221 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
222 | 222 | } |
223 | 223 | ?> |
224 | 224 | </select> |
225 | 225 | <?php |
226 | 226 | } |
227 | 227 | |
228 | -function wpinv_request( $vars ) { |
|
228 | +function wpinv_request($vars) { |
|
229 | 229 | global $typenow, $wp_query, $wp_post_statuses; |
230 | 230 | |
231 | - if ( 'wpi_invoice' === $typenow ) { |
|
232 | - if ( !isset( $vars['post_status'] ) ) { |
|
231 | + if ('wpi_invoice' === $typenow) { |
|
232 | + if (!isset($vars['post_status'])) { |
|
233 | 233 | $post_statuses = wpinv_get_invoice_statuses(); |
234 | 234 | |
235 | - foreach ( $post_statuses as $status => $value ) { |
|
236 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
237 | - unset( $post_statuses[ $status ] ); |
|
235 | + foreach ($post_statuses as $status => $value) { |
|
236 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
237 | + unset($post_statuses[$status]); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
241 | + $vars['post_status'] = array_keys($post_statuses); |
|
242 | 242 | } |
243 | 243 | |
244 | - if ( isset( $vars['orderby'] ) ) { |
|
245 | - if ( 'amount' == $vars['orderby'] ) { |
|
244 | + if (isset($vars['orderby'])) { |
|
245 | + if ('amount' == $vars['orderby']) { |
|
246 | 246 | $vars = array_merge( |
247 | 247 | $vars, |
248 | 248 | array( |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | 'orderby' => 'meta_value_num' |
251 | 251 | ) |
252 | 252 | ); |
253 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
253 | + } else if ('customer' == $vars['orderby']) { |
|
254 | 254 | $vars = array_merge( |
255 | 255 | $vars, |
256 | 256 | array( |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | 'orderby' => 'meta_value' |
259 | 259 | ) |
260 | 260 | ); |
261 | - } else if ( 'number' == $vars['orderby'] ) { |
|
261 | + } else if ('number' == $vars['orderby']) { |
|
262 | 262 | $vars = array_merge( |
263 | 263 | $vars, |
264 | 264 | array( |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | 'orderby' => 'meta_value' |
267 | 267 | ) |
268 | 268 | ); |
269 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
269 | + } else if ('payment_date' == $vars['orderby']) { |
|
270 | 270 | $vars = array_merge( |
271 | 271 | $vars, |
272 | 272 | array( |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | ); |
277 | 277 | } |
278 | 278 | } |
279 | - } else if ( 'wpi_item' == $typenow ) { |
|
279 | + } else if ('wpi_item' == $typenow) { |
|
280 | 280 | // Check if 'orderby' is set to "price" |
281 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
281 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
282 | 282 | $vars = array_merge( |
283 | 283 | $vars, |
284 | 284 | array( |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // Check if "orderby" is set to "vat_rule" |
292 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
292 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
293 | 293 | $vars = array_merge( |
294 | 294 | $vars, |
295 | 295 | array( |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Check if "orderby" is set to "vat_class" |
303 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
303 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
304 | 304 | $vars = array_merge( |
305 | 305 | $vars, |
306 | 306 | array( |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | // Check if "orderby" is set to "type" |
314 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
314 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
315 | 315 | $vars = array_merge( |
316 | 316 | $vars, |
317 | 317 | array( |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | } |
323 | 323 | |
324 | 324 | // Check if "orderby" is set to "recurring" |
325 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
325 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
326 | 326 | $vars = array_merge( |
327 | 327 | $vars, |
328 | 328 | array( |
@@ -332,104 +332,104 @@ discard block |
||
332 | 332 | ); |
333 | 333 | } |
334 | 334 | |
335 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
335 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
336 | 336 | // Filter vat rule type |
337 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
337 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
338 | 338 | $meta_query[] = array( |
339 | 339 | 'key' => '_wpinv_vat_rule', |
340 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
340 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
341 | 341 | 'compare' => '=' |
342 | 342 | ); |
343 | 343 | } |
344 | 344 | |
345 | 345 | // Filter vat class |
346 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
346 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
347 | 347 | $meta_query[] = array( |
348 | 348 | 'key' => '_wpinv_vat_class', |
349 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
349 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
350 | 350 | 'compare' => '=' |
351 | 351 | ); |
352 | 352 | } |
353 | 353 | |
354 | 354 | // Filter item type |
355 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
355 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
356 | 356 | $meta_query[] = array( |
357 | 357 | 'key' => '_wpinv_type', |
358 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
358 | + 'value' => sanitize_text_field($_GET['type']), |
|
359 | 359 | 'compare' => '=' |
360 | 360 | ); |
361 | 361 | } |
362 | 362 | |
363 | - if ( !empty( $meta_query ) ) { |
|
363 | + if (!empty($meta_query)) { |
|
364 | 364 | $vars['meta_query'] = $meta_query; |
365 | 365 | } |
366 | - } else if ( 'wpi_discount' == $typenow ) { |
|
367 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
366 | + } else if ('wpi_discount' == $typenow) { |
|
367 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
368 | 368 | // Filter vat rule type |
369 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
369 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
370 | 370 | $meta_query[] = array( |
371 | 371 | 'key' => '_wpi_discount_type', |
372 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
372 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
373 | 373 | 'compare' => '=' |
374 | 374 | ); |
375 | 375 | } |
376 | 376 | |
377 | - if ( !empty( $meta_query ) ) { |
|
377 | + if (!empty($meta_query)) { |
|
378 | 378 | $vars['meta_query'] = $meta_query; |
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | 382 | return $vars; |
383 | 383 | } |
384 | -add_filter( 'request', 'wpinv_request' ); |
|
384 | +add_filter('request', 'wpinv_request'); |
|
385 | 385 | |
386 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
386 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
387 | 387 | global $pagenow, $typenow; |
388 | 388 | |
389 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
390 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
391 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
389 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
390 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
391 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
392 | 392 | } |
393 | 393 | |
394 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
394 | + if (!wpinv_item_is_editable($post_id)) { |
|
395 | 395 | $classes[] = 'wpi-editable-n'; |
396 | 396 | } |
397 | 397 | } |
398 | 398 | return $classes; |
399 | 399 | } |
400 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
400 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
401 | 401 | |
402 | 402 | function wpinv_check_quick_edit() { |
403 | 403 | global $pagenow, $current_screen, $wpinv_item_screen; |
404 | 404 | |
405 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
406 | - if ( empty( $wpinv_item_screen ) ) { |
|
407 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
405 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
406 | + if (empty($wpinv_item_screen)) { |
|
407 | + if ($current_screen->post_type == 'wpi_item') { |
|
408 | 408 | $wpinv_item_screen = 'y'; |
409 | 409 | } else { |
410 | 410 | $wpinv_item_screen = 'n'; |
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
414 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
415 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
416 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
414 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
415 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
416 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | } |
420 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
420 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
421 | 421 | |
422 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
423 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
424 | - unset( $actions['inline hide-if-no-js'] ); |
|
422 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
423 | + if (isset($actions['inline hide-if-no-js'])) { |
|
424 | + unset($actions['inline hide-if-no-js']); |
|
425 | 425 | } |
426 | 426 | |
427 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
428 | - if ( isset( $actions['trash'] ) ) { |
|
429 | - unset( $actions['trash'] ); |
|
427 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
428 | + if (isset($actions['trash'])) { |
|
429 | + unset($actions['trash']); |
|
430 | 430 | } |
431 | - if ( isset( $actions['delete'] ) ) { |
|
432 | - unset( $actions['delete'] ); |
|
431 | + if (isset($actions['delete'])) { |
|
432 | + unset($actions['delete']); |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | |
@@ -446,19 +446,19 @@ discard block |
||
446 | 446 | * @param int $post_parent (default: 0) Parent for the new page |
447 | 447 | * @return int page ID |
448 | 448 | */ |
449 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
449 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
450 | 450 | global $wpdb; |
451 | 451 | |
452 | - $option_value = wpinv_get_option( $option ); |
|
452 | + $option_value = wpinv_get_option($option); |
|
453 | 453 | |
454 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
455 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
454 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
455 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
456 | 456 | // Valid page is already in place |
457 | 457 | return $page_object->ID; |
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - if(!empty($post_parent)){ |
|
461 | + if (!empty($post_parent)) { |
|
462 | 462 | $page = get_page_by_path($post_parent); |
463 | 463 | if ($page) { |
464 | 464 | $post_parent = $page->ID; |
@@ -467,40 +467,40 @@ discard block |
||
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
470 | - if ( strlen( $page_content ) > 0 ) { |
|
470 | + if (strlen($page_content) > 0) { |
|
471 | 471 | // Search for an existing page with the specified page content (typically a shortcode) |
472 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
472 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
473 | 473 | } else { |
474 | 474 | // Search for an existing page with the specified page slug |
475 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
475 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
476 | 476 | } |
477 | 477 | |
478 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
478 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
479 | 479 | |
480 | - if ( $valid_page_found ) { |
|
481 | - if ( $option ) { |
|
482 | - wpinv_update_option( $option, $valid_page_found ); |
|
480 | + if ($valid_page_found) { |
|
481 | + if ($option) { |
|
482 | + wpinv_update_option($option, $valid_page_found); |
|
483 | 483 | } |
484 | 484 | return $valid_page_found; |
485 | 485 | } |
486 | 486 | |
487 | 487 | // Search for a matching valid trashed page |
488 | - if ( strlen( $page_content ) > 0 ) { |
|
488 | + if (strlen($page_content) > 0) { |
|
489 | 489 | // Search for an existing page with the specified page content (typically a shortcode) |
490 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
490 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
491 | 491 | } else { |
492 | 492 | // Search for an existing page with the specified page slug |
493 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
493 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
494 | 494 | } |
495 | 495 | |
496 | - if ( $trashed_page_found ) { |
|
496 | + if ($trashed_page_found) { |
|
497 | 497 | $page_id = $trashed_page_found; |
498 | 498 | $page_data = array( |
499 | 499 | 'ID' => $page_id, |
500 | 500 | 'post_status' => 'publish', |
501 | 501 | 'post_parent' => $post_parent, |
502 | 502 | ); |
503 | - wp_update_post( $page_data ); |
|
503 | + wp_update_post($page_data); |
|
504 | 504 | } else { |
505 | 505 | $page_data = array( |
506 | 506 | 'post_status' => 'publish', |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | 'post_parent' => $post_parent, |
513 | 513 | 'comment_status' => 'closed', |
514 | 514 | ); |
515 | - $page_id = wp_insert_post( $page_data ); |
|
515 | + $page_id = wp_insert_post($page_data); |
|
516 | 516 | } |
517 | 517 | |
518 | - if ( $option ) { |
|
519 | - wpinv_update_option( $option, (int)$page_id ); |
|
518 | + if ($option) { |
|
519 | + wpinv_update_option($option, (int) $page_id); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | return $page_id; |
@@ -7,15 +7,15 @@ 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_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -33,35 +33,35 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function define_constants() { |
36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function actions() { |
41 | 41 | /* Internationalize the text strings used. */ |
42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
43 | 43 | |
44 | 44 | /* Perform actions on admin initialization. */ |
45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
47 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
46 | + add_action('init', array(&$this, 'init'), 3); |
|
47 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
48 | 48 | |
49 | - if ( class_exists( 'BuddyPress' ) ) { |
|
50 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
49 | + if (class_exists('BuddyPress')) { |
|
50 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
51 | 51 | } |
52 | 52 | |
53 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
55 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
56 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
53 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
54 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
55 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
56 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
57 | 57 | |
58 | - if ( is_admin() ) { |
|
59 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
60 | - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
61 | - add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
58 | + if (is_admin()) { |
|
59 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
60 | + add_filter('admin_body_class', array(&$this, 'admin_body_class')); |
|
61 | + add_action('admin_init', array(&$this, 'init_ayecode_connect_helper')); |
|
62 | 62 | |
63 | 63 | } else { |
64 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
64 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,28 +71,28 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
73 | 73 | */ |
74 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
74 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
75 | 75 | |
76 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
76 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Maybe show the AyeCode Connect Notice. |
81 | 81 | */ |
82 | - public function init_ayecode_connect_helper(){ |
|
82 | + public function init_ayecode_connect_helper() { |
|
83 | 83 | // AyeCode Connect notice |
84 | - if ( is_admin() ){ |
|
84 | + if (is_admin()) { |
|
85 | 85 | // set the strings so they can be translated |
86 | 86 | $strings = array( |
87 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
88 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
89 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
90 | - 'connect_button' => __("Connect Site","invoicing"), |
|
91 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
92 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
93 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
87 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
88 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
89 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
90 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
91 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
92 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
93 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
94 | 94 | ); |
95 | - new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
95 | + new AyeCode_Connect_Helper($strings, array('wpi-addons')); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | /* Internationalize the text strings used. */ |
101 | 101 | $this->load_textdomain(); |
102 | 102 | |
103 | - do_action( 'wpinv_loaded' ); |
|
103 | + do_action('wpinv_loaded'); |
|
104 | 104 | |
105 | 105 | // Fix oxygen page builder conflict |
106 | - if ( function_exists( 'ct_css_output' ) ) { |
|
106 | + if (function_exists('ct_css_output')) { |
|
107 | 107 | wpinv_oxygen_fix_conflict(); |
108 | 108 | } |
109 | 109 | } |
@@ -113,144 +113,144 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @since 1.0 |
115 | 115 | */ |
116 | - public function load_textdomain( $locale = NULL ) { |
|
117 | - if ( empty( $locale ) ) { |
|
118 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
116 | + public function load_textdomain($locale = NULL) { |
|
117 | + if (empty($locale)) { |
|
118 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
119 | 119 | } |
120 | 120 | |
121 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
121 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
122 | 122 | |
123 | - unload_textdomain( 'invoicing' ); |
|
124 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
125 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
123 | + unload_textdomain('invoicing'); |
|
124 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
125 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Define language constants. |
129 | 129 | */ |
130 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function includes() { |
134 | 134 | global $wpinv_options; |
135 | 135 | |
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
137 | 137 | $wpinv_options = wpinv_get_settings(); |
138 | 138 | |
139 | 139 | // Load composer packages. |
140 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
141 | 141 | |
142 | 142 | // load AUI |
143 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
143 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
144 | 144 | |
145 | 145 | // Load the action scheduler. |
146 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
146 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php'); |
|
147 | 147 | |
148 | 148 | // Load functions. |
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
154 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
155 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
156 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
157 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
158 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
159 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
160 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
161 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
154 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
155 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
157 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
158 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
159 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
160 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
161 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
162 | 162 | |
163 | 163 | // Register autoloader. |
164 | 164 | try { |
165 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
166 | - } catch ( Exception $e ) { |
|
167 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
168 | - } |
|
169 | - |
|
170 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
172 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' ); |
|
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
174 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
176 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
177 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
179 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
180 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
181 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
182 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
185 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
186 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
189 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
199 | - |
|
200 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
165 | + spl_autoload_register(array($this, 'autoload'), true); |
|
166 | + } catch (Exception $e) { |
|
167 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
168 | + } |
|
169 | + |
|
170 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
171 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
172 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php'); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
174 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
176 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
177 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
179 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
180 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
181 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
182 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
183 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
185 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
186 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
189 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
190 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php'); |
|
199 | + |
|
200 | + if (!class_exists('WPInv_EUVat')) { |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
205 | - if ( !empty( $gateways ) ) { |
|
206 | - foreach ( $gateways as $gateway ) { |
|
207 | - if ( $gateway == 'manual' ) { |
|
204 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
205 | + if (!empty($gateways)) { |
|
206 | + foreach ($gateways as $gateway) { |
|
207 | + if ($gateway == 'manual') { |
|
208 | 208 | continue; |
209 | 209 | } |
210 | 210 | |
211 | 211 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
212 | 212 | |
213 | - if ( file_exists( $gateway_file ) ) { |
|
214 | - require_once( $gateway_file ); |
|
213 | + if (file_exists($gateway_file)) { |
|
214 | + require_once($gateway_file); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | } |
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
219 | 219 | |
220 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
220 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
224 | 224 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
234 | 234 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
235 | 235 | // load the user class only on the users.php page |
236 | 236 | global $pagenow; |
237 | - if($pagenow=='users.php'){ |
|
237 | + if ($pagenow == 'users.php') { |
|
238 | 238 | new WPInv_Admin_Users(); |
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Register cli commands |
243 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
245 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
243 | + if (defined('WP_CLI') && WP_CLI) { |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
245 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | // include css inliner |
249 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
250 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
249 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
250 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
251 | 251 | } |
252 | 252 | |
253 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
253 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | * @since 1.0.19 |
262 | 262 | * @return void |
263 | 263 | */ |
264 | - public function autoload( $class_name ) { |
|
264 | + public function autoload($class_name) { |
|
265 | 265 | |
266 | 266 | // Normalize the class name... |
267 | - $class_name = strtolower( $class_name ); |
|
267 | + $class_name = strtolower($class_name); |
|
268 | 268 | |
269 | 269 | // ... and make sure it is our class. |
270 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
270 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Next, prepare the file name from the class. |
275 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
275 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
276 | 276 | |
277 | 277 | // And an array of possible locations in order of importance. |
278 | 278 | $locations = array( |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | ); |
284 | 284 | |
285 | 285 | // Base path of the classes. |
286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
286 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
287 | 287 | |
288 | - foreach ( $locations as $location ) { |
|
288 | + foreach ($locations as $location) { |
|
289 | 289 | |
290 | - if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
290 | + if (file_exists("$plugin_path/$location/$file_name")) { |
|
291 | 291 | include "$plugin_path/$location/$file_name"; |
292 | 292 | break; |
293 | 293 | } |
@@ -301,117 +301,117 @@ discard block |
||
301 | 301 | |
302 | 302 | public function admin_init() { |
303 | 303 | self::$instance->default_payment_form = wpinv_get_default_payment_form(); |
304 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
304 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | public function activation_redirect() { |
308 | 308 | // Bail if no activation redirect |
309 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
309 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
310 | 310 | return; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // Delete the redirect transient |
314 | - delete_transient( '_wpinv_activation_redirect' ); |
|
314 | + delete_transient('_wpinv_activation_redirect'); |
|
315 | 315 | |
316 | 316 | // Bail if activating from network, or bulk |
317 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
317 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
318 | 318 | return; |
319 | 319 | } |
320 | 320 | |
321 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
321 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
322 | 322 | exit; |
323 | 323 | } |
324 | 324 | |
325 | 325 | public function enqueue_scripts() { |
326 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
326 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
327 | 327 | |
328 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
329 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
330 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
328 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
329 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
330 | + wp_enqueue_style('wpinv_front_style'); |
|
331 | 331 | |
332 | 332 | // Register scripts |
333 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
334 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
333 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
334 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
335 | 335 | |
336 | 336 | $localize = array(); |
337 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
338 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
337 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
338 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
339 | 339 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
340 | 340 | $localize['currency_pos'] = wpinv_currency_position(); |
341 | 341 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
342 | 342 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
343 | 343 | $localize['decimals'] = wpinv_decimals(); |
344 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
344 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
345 | 345 | $localize['UseTaxes'] = wpinv_use_taxes(); |
346 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
347 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
348 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
346 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
347 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
348 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
349 | 349 | |
350 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
350 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
351 | 351 | |
352 | - wp_enqueue_script( 'jquery-blockui' ); |
|
352 | + wp_enqueue_script('jquery-blockui'); |
|
353 | 353 | $autofill_api = wpinv_get_option('address_autofill_api'); |
354 | 354 | $autofill_active = wpinv_get_option('address_autofill_active'); |
355 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
356 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
357 | - wp_dequeue_script( 'google-maps-api' ); |
|
355 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
356 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
357 | + wp_dequeue_script('google-maps-api'); |
|
358 | 358 | } |
359 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
360 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
359 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
360 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
361 | 361 | } |
362 | 362 | |
363 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
364 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
363 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
364 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
365 | 365 | |
366 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
367 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
366 | + wp_enqueue_script('wpinv-front-script'); |
|
367 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
368 | 368 | |
369 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
370 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
369 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
370 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
371 | 371 | } |
372 | 372 | |
373 | - public function admin_enqueue_scripts( $hook ) { |
|
373 | + public function admin_enqueue_scripts($hook) { |
|
374 | 374 | global $post, $pagenow; |
375 | 375 | |
376 | 376 | $post_type = wpinv_admin_post_type(); |
377 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
378 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
377 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
378 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
379 | 379 | |
380 | 380 | $jquery_ui_css = false; |
381 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
381 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
382 | 382 | $jquery_ui_css = true; |
383 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
383 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
384 | 384 | $jquery_ui_css = true; |
385 | 385 | } |
386 | - if ( $jquery_ui_css ) { |
|
387 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
388 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
389 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
390 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
386 | + if ($jquery_ui_css) { |
|
387 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
388 | + wp_enqueue_style('jquery-ui-css'); |
|
389 | + wp_deregister_style('yoast-seo-select2'); |
|
390 | + wp_deregister_style('yoast-seo-monorepo'); |
|
391 | 391 | } |
392 | 392 | |
393 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
394 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
393 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
394 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
395 | 395 | |
396 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
397 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
398 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
396 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
397 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version); |
|
398 | + wp_enqueue_style('wpinv_admin_style'); |
|
399 | 399 | |
400 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
401 | - if ( $page == 'wpinv-subscriptions' ) { |
|
402 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
403 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
404 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
400 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
401 | + if ($page == 'wpinv-subscriptions') { |
|
402 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
403 | + wp_deregister_style('yoast-seo-select2'); |
|
404 | + wp_deregister_style('yoast-seo-monorepo'); |
|
405 | 405 | } |
406 | 406 | |
407 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
408 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
407 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
408 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
409 | 409 | } |
410 | 410 | |
411 | - wp_enqueue_style( 'wp-color-picker' ); |
|
412 | - wp_enqueue_script( 'wp-color-picker' ); |
|
411 | + wp_enqueue_style('wp-color-picker'); |
|
412 | + wp_enqueue_script('wp-color-picker'); |
|
413 | 413 | |
414 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
414 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
415 | 415 | |
416 | 416 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
417 | 417 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -422,21 +422,21 @@ discard block |
||
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
426 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
425 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
426 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
427 | 427 | |
428 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
429 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
430 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
428 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
429 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version); |
|
430 | + wp_enqueue_script('wpinv-admin-script'); |
|
431 | 431 | |
432 | 432 | $localize = array(); |
433 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
434 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
435 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
436 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
437 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
438 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
439 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
433 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
434 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
435 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
436 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
437 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
438 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
439 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
440 | 440 | $localize['tax'] = wpinv_tax_amount(); |
441 | 441 | $localize['discount'] = wpinv_discount_amount(); |
442 | 442 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -444,102 +444,102 @@ discard block |
||
444 | 444 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
445 | 445 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
446 | 446 | $localize['decimals'] = wpinv_decimals(); |
447 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
448 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
449 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
450 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
451 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
452 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
453 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
454 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
455 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
456 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
457 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
458 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
459 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
460 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
461 | - $localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
462 | - $localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
463 | - |
|
464 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
465 | - |
|
466 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
447 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
448 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
449 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
450 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
451 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
452 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
453 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
454 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
455 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
456 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
457 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
458 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
459 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
460 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
461 | + $localize['item_description'] = __('Item Description', 'invoicing'); |
|
462 | + $localize['discount_description'] = __('Discount Description', 'invoicing'); |
|
463 | + |
|
464 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
465 | + |
|
466 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
467 | 467 | |
468 | 468 | // Load payment form scripts on our admin pages only. |
469 | - if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
469 | + if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) { |
|
470 | 470 | |
471 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
472 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
473 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
471 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
472 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
473 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
474 | 474 | |
475 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
476 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
475 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
476 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
477 | 477 | |
478 | - wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
478 | + wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
479 | 479 | 'elements' => $this->form_elements->get_elements(), |
480 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
480 | + 'form_elements' => $this->form_elements->get_form_elements($post->ID), |
|
481 | 481 | 'all_items' => $this->form_elements->get_published_items(), |
482 | 482 | 'currency' => wpinv_currency_symbol(), |
483 | 483 | 'position' => wpinv_currency_position(), |
484 | 484 | 'decimals' => (int) wpinv_decimals(), |
485 | 485 | 'thousands_sep' => wpinv_thousands_separator(), |
486 | 486 | 'decimals_sep' => wpinv_decimal_separator(), |
487 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
487 | + 'form_items' => $this->form_elements->get_form_items($post->ID), |
|
488 | 488 | 'is_default' => $post->ID == $this->default_payment_form, |
489 | - ) ); |
|
489 | + )); |
|
490 | 490 | |
491 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
491 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
492 | 492 | } |
493 | 493 | |
494 | - if ( $page == 'wpinv-subscriptions' ) { |
|
495 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
496 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
494 | + if ($page == 'wpinv-subscriptions') { |
|
495 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
496 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
497 | 497 | } |
498 | 498 | |
499 | - if ( $page == 'wpinv-reports' ) { |
|
500 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
499 | + if ($page == 'wpinv-reports') { |
|
500 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | } |
504 | 504 | |
505 | - public function admin_body_class( $classes ) { |
|
505 | + public function admin_body_class($classes) { |
|
506 | 506 | global $pagenow, $post, $current_screen; |
507 | 507 | |
508 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
508 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) { |
|
509 | 509 | $classes .= ' wpinv-cpt'; |
510 | 510 | } |
511 | 511 | |
512 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
512 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
513 | 513 | |
514 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
515 | - if ( $add_class ) { |
|
516 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
514 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
515 | + if ($add_class) { |
|
516 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | $settings_class = array(); |
520 | - if ( $page == 'wpinv-settings' ) { |
|
521 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
522 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
520 | + if ($page == 'wpinv-settings') { |
|
521 | + if (!empty($_REQUEST['tab'])) { |
|
522 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
523 | 523 | } |
524 | 524 | |
525 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
526 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
525 | + if (!empty($_REQUEST['section'])) { |
|
526 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
527 | 527 | } |
528 | 528 | |
529 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
529 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
530 | 530 | } |
531 | 531 | |
532 | - if ( !empty( $settings_class ) ) { |
|
533 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
532 | + if (!empty($settings_class)) { |
|
533 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | $post_type = wpinv_admin_post_type(); |
537 | 537 | |
538 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
538 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
539 | 539 | return $classes .= ' wpinv'; |
540 | 540 | } |
541 | 541 | |
542 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
542 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
543 | 543 | $classes .= ' wpi-editable-n'; |
544 | 544 | } |
545 | 545 | |
@@ -551,21 +551,21 @@ discard block |
||
551 | 551 | } |
552 | 552 | |
553 | 553 | public function wpinv_actions() { |
554 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
555 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
554 | + if (isset($_REQUEST['wpi_action'])) { |
|
555 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
559 | - public function pre_get_posts( $wp_query ) { |
|
560 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
561 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
559 | + public function pre_get_posts($wp_query) { |
|
560 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
561 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | return $wp_query; |
565 | 565 | } |
566 | 566 | |
567 | 567 | public function bp_invoicing_init() { |
568 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
568 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -573,13 +573,13 @@ discard block |
||
573 | 573 | * |
574 | 574 | */ |
575 | 575 | public function register_widgets() { |
576 | - register_widget( "WPInv_Checkout_Widget" ); |
|
577 | - register_widget( "WPInv_History_Widget" ); |
|
578 | - register_widget( "WPInv_Receipt_Widget" ); |
|
579 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
580 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
581 | - register_widget( "WPInv_Messages_Widget" ); |
|
582 | - register_widget( 'WPInv_GetPaid_Widget' ); |
|
576 | + register_widget("WPInv_Checkout_Widget"); |
|
577 | + register_widget("WPInv_History_Widget"); |
|
578 | + register_widget("WPInv_Receipt_Widget"); |
|
579 | + register_widget("WPInv_Subscriptions_Widget"); |
|
580 | + register_widget("WPInv_Buy_Item_Widget"); |
|
581 | + register_widget("WPInv_Messages_Widget"); |
|
582 | + register_widget('WPInv_GetPaid_Widget'); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
@@ -588,10 +588,10 @@ discard block |
||
588 | 588 | * @since 1.0.19 |
589 | 589 | * @param int[] $excluded_posts_ids |
590 | 590 | */ |
591 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
591 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
592 | 592 | |
593 | 593 | // Ensure that we have an array. |
594 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
594 | + if (!is_array($excluded_posts_ids)) { |
|
595 | 595 | $excluded_posts_ids = array(); |
596 | 596 | } |
597 | 597 | |
@@ -599,24 +599,24 @@ discard block |
||
599 | 599 | $our_pages = array(); |
600 | 600 | |
601 | 601 | // Checkout page. |
602 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
602 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
603 | 603 | |
604 | 604 | // Success page. |
605 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
605 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
606 | 606 | |
607 | 607 | // Failure page. |
608 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
608 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
609 | 609 | |
610 | 610 | // History page. |
611 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
611 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
612 | 612 | |
613 | 613 | // Subscriptions page. |
614 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
614 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
615 | 615 | |
616 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
616 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
617 | 617 | |
618 | 618 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
619 | - return array_unique( $excluded_posts_ids ); |
|
619 | + return array_unique($excluded_posts_ids); |
|
620 | 620 | |
621 | 621 | } |
622 | 622 |
@@ -7,91 +7,91 @@ 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 | -if ( !is_admin() ) { |
|
15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
14 | +if (!is_admin()) { |
|
15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | function wpinv_template_path() { |
22 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
22 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
26 | - if ( empty( $invoice ) ) { |
|
25 | +function wpinv_display_invoice_top_bar($invoice) { |
|
26 | + if (empty($invoice)) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | ?> |
30 | 30 | <div class="row wpinv-top-bar no-print"> |
31 | 31 | <div class="container"> |
32 | 32 | <div class="col-xs-6"> |
33 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
33 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
34 | 34 | </div> |
35 | 35 | <div class="col-xs-6 text-right"> |
36 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
36 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
37 | 37 | </div> |
38 | 38 | </div> |
39 | 39 | </div> |
40 | 40 | <?php |
41 | 41 | } |
42 | 42 | |
43 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
44 | - if ( empty( $invoice ) ) { |
|
43 | +function wpinv_invoice_display_left_actions($invoice) { |
|
44 | + if (empty($invoice)) { |
|
45 | 45 | return; // Exit if invoice is not set. |
46 | 46 | } |
47 | 47 | |
48 | - if ( $invoice->post_type == 'wpi_invoice' ) { |
|
49 | - if ( $invoice->needs_payment() ) { |
|
50 | - ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php |
|
48 | + if ($invoice->post_type == 'wpi_invoice') { |
|
49 | + if ($invoice->needs_payment()) { |
|
50 | + ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | do_action('wpinv_invoice_display_left_actions', $invoice); |
54 | 54 | } |
55 | 55 | |
56 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
57 | - if ( empty( $invoice ) ) { |
|
56 | +function wpinv_invoice_display_right_actions($invoice) { |
|
57 | + if (empty($invoice)) { |
|
58 | 58 | return; // Exit if invoice is not set. |
59 | 59 | } |
60 | 60 | |
61 | - if ( $invoice->post_type == 'wpi_invoice' ) { ?> |
|
62 | - <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
63 | - <?php if ( is_user_logged_in() ) { ?> |
|
64 | - <a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
61 | + if ($invoice->post_type == 'wpi_invoice') { ?> |
|
62 | + <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
63 | + <?php if (is_user_logged_in()) { ?> |
|
64 | + <a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
65 | 65 | <?php } |
66 | 66 | } |
67 | 67 | do_action('wpinv_invoice_display_right_actions', $invoice); |
68 | 68 | } |
69 | 69 | |
70 | -function wpinv_before_invoice_content( $content ) { |
|
70 | +function wpinv_before_invoice_content($content) { |
|
71 | 71 | global $post; |
72 | 72 | |
73 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
73 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
74 | 74 | ob_start(); |
75 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
75 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
76 | 76 | $content = ob_get_clean() . $content; |
77 | 77 | } |
78 | 78 | |
79 | 79 | return $content; |
80 | 80 | } |
81 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
81 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
82 | 82 | |
83 | -function wpinv_after_invoice_content( $content ) { |
|
83 | +function wpinv_after_invoice_content($content) { |
|
84 | 84 | global $post; |
85 | 85 | |
86 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
86 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
87 | 87 | ob_start(); |
88 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
88 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
89 | 89 | $content .= ob_get_clean(); |
90 | 90 | } |
91 | 91 | |
92 | 92 | return $content; |
93 | 93 | } |
94 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
94 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
95 | 95 | |
96 | 96 | function wpinv_get_templates_dir() { |
97 | 97 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -101,105 +101,105 @@ discard block |
||
101 | 101 | return WPINV_PLUGIN_URL . 'templates'; |
102 | 102 | } |
103 | 103 | |
104 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
105 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
106 | - extract( $args ); |
|
104 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
105 | + if (!empty($args) && is_array($args)) { |
|
106 | + extract($args); |
|
107 | 107 | } |
108 | 108 | |
109 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
109 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
110 | 110 | // Allow 3rd party plugin filter template file from their plugin. |
111 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
111 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
112 | 112 | |
113 | - if ( ! file_exists( $located ) ) { |
|
114 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
113 | + if (!file_exists($located)) { |
|
114 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
118 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
119 | 119 | |
120 | - include( $located ); |
|
120 | + include($located); |
|
121 | 121 | |
122 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
122 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
123 | 123 | } |
124 | 124 | |
125 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
125 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
126 | 126 | ob_start(); |
127 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
127 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
128 | 128 | return ob_get_clean(); |
129 | 129 | } |
130 | 130 | |
131 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
132 | - if ( ! $template_path ) { |
|
131 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
132 | + if (!$template_path) { |
|
133 | 133 | $template_path = wpinv_template_path(); |
134 | 134 | } |
135 | 135 | |
136 | - if ( ! $default_path ) { |
|
136 | + if (!$default_path) { |
|
137 | 137 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
138 | 138 | } |
139 | 139 | |
140 | 140 | // Look within passed path within the theme - this is priority. |
141 | 141 | $template = locate_template( |
142 | 142 | array( |
143 | - trailingslashit( $template_path ) . $template_name, |
|
143 | + trailingslashit($template_path) . $template_name, |
|
144 | 144 | $template_name |
145 | 145 | ) |
146 | 146 | ); |
147 | 147 | |
148 | 148 | // Get default templates/ |
149 | - if ( !$template && $default_path ) { |
|
150 | - $template = trailingslashit( $default_path ) . $template_name; |
|
149 | + if (!$template && $default_path) { |
|
150 | + $template = trailingslashit($default_path) . $template_name; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Return what we found. |
154 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
154 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
155 | 155 | } |
156 | 156 | |
157 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
158 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
157 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
158 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
159 | 159 | |
160 | 160 | // Setup possible parts |
161 | 161 | $templates = array(); |
162 | - if ( isset( $name ) ) |
|
162 | + if (isset($name)) |
|
163 | 163 | $templates[] = $slug . '-' . $name . '.php'; |
164 | 164 | $templates[] = $slug . '.php'; |
165 | 165 | |
166 | 166 | // Allow template parts to be filtered |
167 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
167 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
168 | 168 | |
169 | 169 | // Return the part that is found |
170 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
170 | + return wpinv_locate_tmpl($templates, $load, false); |
|
171 | 171 | } |
172 | 172 | |
173 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
173 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
174 | 174 | // No file found yet |
175 | 175 | $located = false; |
176 | 176 | |
177 | 177 | // Try to find a template file |
178 | - foreach ( (array)$template_names as $template_name ) { |
|
178 | + foreach ((array) $template_names as $template_name) { |
|
179 | 179 | |
180 | 180 | // Continue if template is empty |
181 | - if ( empty( $template_name ) ) |
|
181 | + if (empty($template_name)) |
|
182 | 182 | continue; |
183 | 183 | |
184 | 184 | // Trim off any slashes from the template name |
185 | - $template_name = ltrim( $template_name, '/' ); |
|
185 | + $template_name = ltrim($template_name, '/'); |
|
186 | 186 | |
187 | 187 | // try locating this template file by looping through the template paths |
188 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
188 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
189 | 189 | |
190 | - if( file_exists( $template_path . $template_name ) ) { |
|
190 | + if (file_exists($template_path . $template_name)) { |
|
191 | 191 | $located = $template_path . $template_name; |
192 | 192 | break; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if( !empty( $located ) ) { |
|
196 | + if (!empty($located)) { |
|
197 | 197 | break; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
201 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
202 | - load_template( $located, $require_once ); |
|
201 | + if ((true == $load) && !empty($located)) |
|
202 | + load_template($located, $require_once); |
|
203 | 203 | |
204 | 204 | return $located; |
205 | 205 | } |
@@ -208,159 +208,159 @@ discard block |
||
208 | 208 | $template_dir = wpinv_get_theme_template_dir_name(); |
209 | 209 | |
210 | 210 | $file_paths = array( |
211 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
212 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
211 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
212 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
213 | 213 | 100 => wpinv_get_templates_dir() |
214 | 214 | ); |
215 | 215 | |
216 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
216 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
217 | 217 | |
218 | 218 | // sort the file paths based on priority |
219 | - ksort( $file_paths, SORT_NUMERIC ); |
|
219 | + ksort($file_paths, SORT_NUMERIC); |
|
220 | 220 | |
221 | - return array_map( 'trailingslashit', $file_paths ); |
|
221 | + return array_map('trailingslashit', $file_paths); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_theme_template_dir_name() { |
225 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
225 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | function wpinv_checkout_meta_tags() { |
229 | 229 | |
230 | 230 | $pages = array(); |
231 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
232 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
233 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
234 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
231 | + $pages[] = wpinv_get_option('success_page'); |
|
232 | + $pages[] = wpinv_get_option('failure_page'); |
|
233 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
234 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
235 | 235 | |
236 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
236 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
237 | 237 | return; |
238 | 238 | } |
239 | 239 | |
240 | 240 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
241 | 241 | } |
242 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
242 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
243 | 243 | |
244 | -function wpinv_add_body_classes( $class ) { |
|
245 | - $classes = (array)$class; |
|
244 | +function wpinv_add_body_classes($class) { |
|
245 | + $classes = (array) $class; |
|
246 | 246 | |
247 | - if( wpinv_is_checkout() ) { |
|
247 | + if (wpinv_is_checkout()) { |
|
248 | 248 | $classes[] = 'wpinv-checkout'; |
249 | 249 | $classes[] = 'wpinv-page'; |
250 | 250 | } |
251 | 251 | |
252 | - if( wpinv_is_success_page() ) { |
|
252 | + if (wpinv_is_success_page()) { |
|
253 | 253 | $classes[] = 'wpinv-success'; |
254 | 254 | $classes[] = 'wpinv-page'; |
255 | 255 | } |
256 | 256 | |
257 | - if( wpinv_is_failed_transaction_page() ) { |
|
257 | + if (wpinv_is_failed_transaction_page()) { |
|
258 | 258 | $classes[] = 'wpinv-failed-transaction'; |
259 | 259 | $classes[] = 'wpinv-page'; |
260 | 260 | } |
261 | 261 | |
262 | - if( wpinv_is_invoice_history_page() ) { |
|
262 | + if (wpinv_is_invoice_history_page()) { |
|
263 | 263 | $classes[] = 'wpinv-history'; |
264 | 264 | $classes[] = 'wpinv-page'; |
265 | 265 | } |
266 | 266 | |
267 | - if( wpinv_is_subscriptions_history_page() ) { |
|
267 | + if (wpinv_is_subscriptions_history_page()) { |
|
268 | 268 | $classes[] = 'wpinv-subscription'; |
269 | 269 | $classes[] = 'wpinv-page'; |
270 | 270 | } |
271 | 271 | |
272 | - if( wpinv_is_test_mode() ) { |
|
272 | + if (wpinv_is_test_mode()) { |
|
273 | 273 | $classes[] = 'wpinv-test-mode'; |
274 | 274 | $classes[] = 'wpinv-page'; |
275 | 275 | } |
276 | 276 | |
277 | - return array_unique( $classes ); |
|
277 | + return array_unique($classes); |
|
278 | 278 | } |
279 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
279 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
280 | 280 | |
281 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
282 | - $args = array( 'nopaging' => true ); |
|
281 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
282 | + $args = array('nopaging' => true); |
|
283 | 283 | |
284 | - if ( ! empty( $status ) ) |
|
284 | + if (!empty($status)) |
|
285 | 285 | $args['post_status'] = $status; |
286 | 286 | |
287 | - $discounts = wpinv_get_discounts( $args ); |
|
287 | + $discounts = wpinv_get_discounts($args); |
|
288 | 288 | $options = array(); |
289 | 289 | |
290 | - if ( $discounts ) { |
|
291 | - foreach ( $discounts as $discount ) { |
|
292 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
290 | + if ($discounts) { |
|
291 | + foreach ($discounts as $discount) { |
|
292 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
293 | 293 | } |
294 | 294 | } else { |
295 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
295 | + $options[0] = __('No discounts found', 'invoicing'); |
|
296 | 296 | } |
297 | 297 | |
298 | - $output = wpinv_html_select( array( |
|
298 | + $output = wpinv_html_select(array( |
|
299 | 299 | 'name' => $name, |
300 | 300 | 'selected' => $selected, |
301 | 301 | 'options' => $options, |
302 | 302 | 'show_option_all' => false, |
303 | 303 | 'show_option_none' => false, |
304 | - ) ); |
|
304 | + )); |
|
305 | 305 | |
306 | 306 | return $output; |
307 | 307 | } |
308 | 308 | |
309 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
310 | - $current = date( 'Y' ); |
|
311 | - $start_year = $current - absint( $years_before ); |
|
312 | - $end_year = $current + absint( $years_after ); |
|
313 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
309 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
310 | + $current = date('Y'); |
|
311 | + $start_year = $current - absint($years_before); |
|
312 | + $end_year = $current + absint($years_after); |
|
313 | + $selected = empty($selected) ? date('Y') : $selected; |
|
314 | 314 | $options = array(); |
315 | 315 | |
316 | - while ( $start_year <= $end_year ) { |
|
317 | - $options[ absint( $start_year ) ] = $start_year; |
|
316 | + while ($start_year <= $end_year) { |
|
317 | + $options[absint($start_year)] = $start_year; |
|
318 | 318 | $start_year++; |
319 | 319 | } |
320 | 320 | |
321 | - $output = wpinv_html_select( array( |
|
321 | + $output = wpinv_html_select(array( |
|
322 | 322 | 'name' => $name, |
323 | 323 | 'selected' => $selected, |
324 | 324 | 'options' => $options, |
325 | 325 | 'show_option_all' => false, |
326 | 326 | 'show_option_none' => false |
327 | - ) ); |
|
327 | + )); |
|
328 | 328 | |
329 | 329 | return $output; |
330 | 330 | } |
331 | 331 | |
332 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
332 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
333 | 333 | |
334 | 334 | $options = array( |
335 | - '1' => __( 'January', 'invoicing' ), |
|
336 | - '2' => __( 'February', 'invoicing' ), |
|
337 | - '3' => __( 'March', 'invoicing' ), |
|
338 | - '4' => __( 'April', 'invoicing' ), |
|
339 | - '5' => __( 'May', 'invoicing' ), |
|
340 | - '6' => __( 'June', 'invoicing' ), |
|
341 | - '7' => __( 'July', 'invoicing' ), |
|
342 | - '8' => __( 'August', 'invoicing' ), |
|
343 | - '9' => __( 'September', 'invoicing' ), |
|
344 | - '10' => __( 'October', 'invoicing' ), |
|
345 | - '11' => __( 'November', 'invoicing' ), |
|
346 | - '12' => __( 'December', 'invoicing' ), |
|
335 | + '1' => __('January', 'invoicing'), |
|
336 | + '2' => __('February', 'invoicing'), |
|
337 | + '3' => __('March', 'invoicing'), |
|
338 | + '4' => __('April', 'invoicing'), |
|
339 | + '5' => __('May', 'invoicing'), |
|
340 | + '6' => __('June', 'invoicing'), |
|
341 | + '7' => __('July', 'invoicing'), |
|
342 | + '8' => __('August', 'invoicing'), |
|
343 | + '9' => __('September', 'invoicing'), |
|
344 | + '10' => __('October', 'invoicing'), |
|
345 | + '11' => __('November', 'invoicing'), |
|
346 | + '12' => __('December', 'invoicing'), |
|
347 | 347 | ); |
348 | 348 | |
349 | 349 | // If no month is selected, default to the current month |
350 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
350 | + $selected = empty($selected) ? date('n') : $selected; |
|
351 | 351 | |
352 | - $output = wpinv_html_select( array( |
|
352 | + $output = wpinv_html_select(array( |
|
353 | 353 | 'name' => $name, |
354 | 354 | 'selected' => $selected, |
355 | 355 | 'options' => $options, |
356 | 356 | 'show_option_all' => false, |
357 | 357 | 'show_option_none' => false |
358 | - ) ); |
|
358 | + )); |
|
359 | 359 | |
360 | 360 | return $output; |
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_html_select( $args = array() ) { |
|
363 | +function wpinv_html_select($args = array()) { |
|
364 | 364 | $defaults = array( |
365 | 365 | 'options' => array(), |
366 | 366 | 'name' => null, |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | 'selected' => 0, |
370 | 370 | 'placeholder' => null, |
371 | 371 | 'multiple' => false, |
372 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
373 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
372 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
373 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
374 | 374 | 'data' => array(), |
375 | 375 | 'onchange' => null, |
376 | 376 | 'required' => false, |
@@ -378,74 +378,74 @@ discard block |
||
378 | 378 | 'readonly' => false, |
379 | 379 | ); |
380 | 380 | |
381 | - $args = wp_parse_args( $args, $defaults ); |
|
381 | + $args = wp_parse_args($args, $defaults); |
|
382 | 382 | |
383 | 383 | $data_elements = ''; |
384 | - foreach ( $args['data'] as $key => $value ) { |
|
385 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
384 | + foreach ($args['data'] as $key => $value) { |
|
385 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
386 | 386 | } |
387 | 387 | |
388 | - if( $args['multiple'] ) { |
|
388 | + if ($args['multiple']) { |
|
389 | 389 | $multiple = ' MULTIPLE'; |
390 | 390 | } else { |
391 | 391 | $multiple = ''; |
392 | 392 | } |
393 | 393 | |
394 | - if( $args['placeholder'] ) { |
|
394 | + if ($args['placeholder']) { |
|
395 | 395 | $placeholder = $args['placeholder']; |
396 | 396 | } else { |
397 | 397 | $placeholder = ''; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $options = ''; |
401 | - if( !empty( $args['onchange'] ) ) { |
|
402 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
401 | + if (!empty($args['onchange'])) { |
|
402 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
403 | 403 | } |
404 | 404 | |
405 | - if( !empty( $args['required'] ) ) { |
|
405 | + if (!empty($args['required'])) { |
|
406 | 406 | $options .= ' required="required"'; |
407 | 407 | } |
408 | 408 | |
409 | - if( !empty( $args['disabled'] ) ) { |
|
409 | + if (!empty($args['disabled'])) { |
|
410 | 410 | $options .= ' disabled'; |
411 | 411 | } |
412 | 412 | |
413 | - if( !empty( $args['readonly'] ) ) { |
|
413 | + if (!empty($args['readonly'])) { |
|
414 | 414 | $options .= ' readonly'; |
415 | 415 | } |
416 | 416 | |
417 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
418 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
417 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
418 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
419 | 419 | |
420 | - if ( $args['show_option_all'] ) { |
|
421 | - if( $args['multiple'] ) { |
|
422 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
420 | + if ($args['show_option_all']) { |
|
421 | + if ($args['multiple']) { |
|
422 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
423 | 423 | } else { |
424 | - $selected = selected( $args['selected'], 0, false ); |
|
424 | + $selected = selected($args['selected'], 0, false); |
|
425 | 425 | } |
426 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
426 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
427 | 427 | } |
428 | 428 | |
429 | - if ( !empty( $args['options'] ) ) { |
|
429 | + if (!empty($args['options'])) { |
|
430 | 430 | |
431 | - if ( $args['show_option_none'] ) { |
|
432 | - if( $args['multiple'] ) { |
|
433 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
431 | + if ($args['show_option_none']) { |
|
432 | + if ($args['multiple']) { |
|
433 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
434 | 434 | } else { |
435 | - $selected = selected( $args['selected'] === "", true, false ); |
|
435 | + $selected = selected($args['selected'] === "", true, false); |
|
436 | 436 | } |
437 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
437 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
438 | 438 | } |
439 | 439 | |
440 | - foreach( $args['options'] as $key => $option ) { |
|
440 | + foreach ($args['options'] as $key => $option) { |
|
441 | 441 | |
442 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
443 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
442 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
443 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
444 | 444 | } else { |
445 | - $selected = selected( $args['selected'], $key, false ); |
|
445 | + $selected = selected($args['selected'], $key, false); |
|
446 | 446 | } |
447 | 447 | |
448 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
448 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | return $output; |
455 | 455 | } |
456 | 456 | |
457 | -function wpinv_item_dropdown( $args = array() ) { |
|
457 | +function wpinv_item_dropdown($args = array()) { |
|
458 | 458 | $defaults = array( |
459 | 459 | 'name' => 'wpi_item', |
460 | 460 | 'id' => 'wpi_item', |
@@ -462,14 +462,14 @@ discard block |
||
462 | 462 | 'multiple' => false, |
463 | 463 | 'selected' => 0, |
464 | 464 | 'number' => 100, |
465 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
466 | - 'data' => array( 'search-type' => 'item' ), |
|
465 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
466 | + 'data' => array('search-type' => 'item'), |
|
467 | 467 | 'show_option_all' => false, |
468 | 468 | 'show_option_none' => false, |
469 | 469 | 'show_recurring' => false, |
470 | 470 | ); |
471 | 471 | |
472 | - $args = wp_parse_args( $args, $defaults ); |
|
472 | + $args = wp_parse_args($args, $defaults); |
|
473 | 473 | |
474 | 474 | $item_args = array( |
475 | 475 | 'post_type' => 'wpi_item', |
@@ -478,44 +478,44 @@ discard block |
||
478 | 478 | 'posts_per_page' => $args['number'] |
479 | 479 | ); |
480 | 480 | |
481 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
481 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
482 | 482 | |
483 | - $items = get_posts( $item_args ); |
|
483 | + $items = get_posts($item_args); |
|
484 | 484 | $options = array(); |
485 | - if ( $items ) { |
|
486 | - foreach ( $items as $item ) { |
|
487 | - $title = esc_html( $item->post_title ); |
|
485 | + if ($items) { |
|
486 | + foreach ($items as $item) { |
|
487 | + $title = esc_html($item->post_title); |
|
488 | 488 | |
489 | - if ( !empty( $args['show_recurring'] ) ) { |
|
490 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
489 | + if (!empty($args['show_recurring'])) { |
|
490 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
491 | 491 | } |
492 | 492 | |
493 | - $options[ absint( $item->ID ) ] = $title; |
|
493 | + $options[absint($item->ID)] = $title; |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | // This ensures that any selected items are included in the drop down |
498 | - if( is_array( $args['selected'] ) ) { |
|
499 | - foreach( $args['selected'] as $item ) { |
|
500 | - if( ! in_array( $item, $options ) ) { |
|
501 | - $title = get_the_title( $item ); |
|
502 | - if ( !empty( $args['show_recurring'] ) ) { |
|
503 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
498 | + if (is_array($args['selected'])) { |
|
499 | + foreach ($args['selected'] as $item) { |
|
500 | + if (!in_array($item, $options)) { |
|
501 | + $title = get_the_title($item); |
|
502 | + if (!empty($args['show_recurring'])) { |
|
503 | + $title .= wpinv_get_item_suffix($item, false); |
|
504 | 504 | } |
505 | 505 | $options[$item] = $title; |
506 | 506 | } |
507 | 507 | } |
508 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
509 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
510 | - $title = get_the_title( $args['selected'] ); |
|
511 | - if ( !empty( $args['show_recurring'] ) ) { |
|
512 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
508 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
509 | + if (!in_array($args['selected'], $options)) { |
|
510 | + $title = get_the_title($args['selected']); |
|
511 | + if (!empty($args['show_recurring'])) { |
|
512 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
513 | 513 | } |
514 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
514 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
518 | - $output = wpinv_html_select( array( |
|
518 | + $output = wpinv_html_select(array( |
|
519 | 519 | 'name' => $args['name'], |
520 | 520 | 'selected' => $args['selected'], |
521 | 521 | 'id' => $args['id'], |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | 'show_option_all' => $args['show_option_all'], |
527 | 527 | 'show_option_none' => $args['show_option_none'], |
528 | 528 | 'data' => $args['data'], |
529 | - ) ); |
|
529 | + )); |
|
530 | 530 | |
531 | 531 | return $output; |
532 | 532 | } |
@@ -546,16 +546,16 @@ discard block |
||
546 | 546 | ); |
547 | 547 | |
548 | 548 | $options = array(); |
549 | - if ( $items ) { |
|
550 | - foreach ( $items as $item ) { |
|
551 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
549 | + if ($items) { |
|
550 | + foreach ($items as $item) { |
|
551 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | 555 | return $options; |
556 | 556 | } |
557 | 557 | |
558 | -function wpinv_html_checkbox( $args = array() ) { |
|
558 | +function wpinv_html_checkbox($args = array()) { |
|
559 | 559 | $defaults = array( |
560 | 560 | 'name' => null, |
561 | 561 | 'current' => null, |
@@ -566,38 +566,38 @@ discard block |
||
566 | 566 | ) |
567 | 567 | ); |
568 | 568 | |
569 | - $args = wp_parse_args( $args, $defaults ); |
|
569 | + $args = wp_parse_args($args, $defaults); |
|
570 | 570 | |
571 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
571 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
572 | 572 | $options = ''; |
573 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
573 | + if (!empty($args['options']['disabled'])) { |
|
574 | 574 | $options .= ' disabled="disabled"'; |
575 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
575 | + } elseif (!empty($args['options']['readonly'])) { |
|
576 | 576 | $options .= ' readonly'; |
577 | 577 | } |
578 | 578 | |
579 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
579 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
580 | 580 | |
581 | 581 | return $output; |
582 | 582 | } |
583 | 583 | |
584 | -function wpinv_html_text( $args = array() ) { |
|
584 | +function wpinv_html_text($args = array()) { |
|
585 | 585 | // Backwards compatibility |
586 | - if ( func_num_args() > 1 ) { |
|
586 | + if (func_num_args() > 1) { |
|
587 | 587 | $args = func_get_args(); |
588 | 588 | |
589 | 589 | $name = $args[0]; |
590 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
591 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
592 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
590 | + $value = isset($args[1]) ? $args[1] : ''; |
|
591 | + $label = isset($args[2]) ? $args[2] : ''; |
|
592 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | $defaults = array( |
596 | 596 | 'id' => '', |
597 | - 'name' => isset( $name ) ? $name : 'text', |
|
598 | - 'value' => isset( $value ) ? $value : null, |
|
599 | - 'label' => isset( $label ) ? $label : null, |
|
600 | - 'desc' => isset( $desc ) ? $desc : null, |
|
597 | + 'name' => isset($name) ? $name : 'text', |
|
598 | + 'value' => isset($value) ? $value : null, |
|
599 | + 'label' => isset($label) ? $label : null, |
|
600 | + 'desc' => isset($desc) ? $desc : null, |
|
601 | 601 | 'placeholder' => '', |
602 | 602 | 'class' => 'regular-text', |
603 | 603 | 'disabled' => false, |
@@ -607,51 +607,51 @@ discard block |
||
607 | 607 | 'data' => false |
608 | 608 | ); |
609 | 609 | |
610 | - $args = wp_parse_args( $args, $defaults ); |
|
610 | + $args = wp_parse_args($args, $defaults); |
|
611 | 611 | |
612 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
612 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
613 | 613 | $options = ''; |
614 | - if( $args['required'] ) { |
|
614 | + if ($args['required']) { |
|
615 | 615 | $options .= ' required="required"'; |
616 | 616 | } |
617 | - if( $args['readonly'] ) { |
|
617 | + if ($args['readonly']) { |
|
618 | 618 | $options .= ' readonly'; |
619 | 619 | } |
620 | - if( $args['readonly'] ) { |
|
620 | + if ($args['readonly']) { |
|
621 | 621 | $options .= ' readonly'; |
622 | 622 | } |
623 | 623 | |
624 | 624 | $data = ''; |
625 | - if ( !empty( $args['data'] ) ) { |
|
626 | - foreach ( $args['data'] as $key => $value ) { |
|
627 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
625 | + if (!empty($args['data'])) { |
|
626 | + foreach ($args['data'] as $key => $value) { |
|
627 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
632 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
633 | - if ( ! empty( $args['desc'] ) ) { |
|
634 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
631 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
632 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
633 | + if (!empty($args['desc'])) { |
|
634 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
635 | 635 | } |
636 | 636 | |
637 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
637 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
638 | 638 | |
639 | 639 | $output .= '</span>'; |
640 | 640 | |
641 | 641 | return $output; |
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_html_date_field( $args = array() ) { |
|
645 | - if( empty( $args['class'] ) ) { |
|
644 | +function wpinv_html_date_field($args = array()) { |
|
645 | + if (empty($args['class'])) { |
|
646 | 646 | $args['class'] = 'wpiDatepicker'; |
647 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
647 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
648 | 648 | $args['class'] .= ' wpiDatepicker'; |
649 | 649 | } |
650 | 650 | |
651 | - return wpinv_html_text( $args ); |
|
651 | + return wpinv_html_text($args); |
|
652 | 652 | } |
653 | 653 | |
654 | -function wpinv_html_textarea( $args = array() ) { |
|
654 | +function wpinv_html_textarea($args = array()) { |
|
655 | 655 | $defaults = array( |
656 | 656 | 'name' => 'textarea', |
657 | 657 | 'value' => null, |
@@ -662,31 +662,31 @@ discard block |
||
662 | 662 | 'placeholder' => '', |
663 | 663 | ); |
664 | 664 | |
665 | - $args = wp_parse_args( $args, $defaults ); |
|
665 | + $args = wp_parse_args($args, $defaults); |
|
666 | 666 | |
667 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
667 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
668 | 668 | $disabled = ''; |
669 | - if( $args['disabled'] ) { |
|
669 | + if ($args['disabled']) { |
|
670 | 670 | $disabled = ' disabled="disabled"'; |
671 | 671 | } |
672 | 672 | |
673 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
674 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
675 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
673 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
674 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
675 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
676 | 676 | |
677 | - if ( ! empty( $args['desc'] ) ) { |
|
678 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
677 | + if (!empty($args['desc'])) { |
|
678 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
679 | 679 | } |
680 | 680 | $output .= '</span>'; |
681 | 681 | |
682 | 682 | return $output; |
683 | 683 | } |
684 | 684 | |
685 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
685 | +function wpinv_html_ajax_user_search($args = array()) { |
|
686 | 686 | $defaults = array( |
687 | 687 | 'name' => 'user_id', |
688 | 688 | 'value' => null, |
689 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
689 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
690 | 690 | 'label' => null, |
691 | 691 | 'desc' => null, |
692 | 692 | 'class' => '', |
@@ -695,13 +695,13 @@ discard block |
||
695 | 695 | 'data' => false |
696 | 696 | ); |
697 | 697 | |
698 | - $args = wp_parse_args( $args, $defaults ); |
|
698 | + $args = wp_parse_args($args, $defaults); |
|
699 | 699 | |
700 | 700 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
701 | 701 | |
702 | 702 | $output = '<span class="wpinv_user_search_wrap">'; |
703 | - $output .= wpinv_html_text( $args ); |
|
704 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
703 | + $output .= wpinv_html_text($args); |
|
704 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
705 | 705 | $output .= '</span>'; |
706 | 706 | |
707 | 707 | return $output; |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | function wpinv_ip_geolocation() { |
711 | 711 | global $wpinv_euvat; |
712 | 712 | |
713 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
713 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
714 | 714 | $content = ''; |
715 | 715 | $iso = ''; |
716 | 716 | $country = ''; |
@@ -721,69 +721,69 @@ discard block |
||
721 | 721 | $credit = ''; |
722 | 722 | $address = ''; |
723 | 723 | |
724 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
724 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
725 | 725 | try { |
726 | 726 | $iso = $geoip2_city->country->isoCode; |
727 | 727 | $country = $geoip2_city->country->name; |
728 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
728 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
729 | 729 | $city = $geoip2_city->city->name; |
730 | 730 | $longitude = $geoip2_city->location->longitude; |
731 | 731 | $latitude = $geoip2_city->location->latitude; |
732 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
733 | - } catch( Exception $e ) { } |
|
732 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
733 | + } catch (Exception $e) { } |
|
734 | 734 | } |
735 | 735 | |
736 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
736 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
737 | 737 | try { |
738 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
738 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
739 | 739 | |
740 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
740 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
741 | 741 | $iso = $load_xml->geoplugin_countryCode; |
742 | 742 | $country = $load_xml->geoplugin_countryName; |
743 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
744 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
743 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
744 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
745 | 745 | $longitude = $load_xml->geoplugin_longitude; |
746 | 746 | $latitude = $load_xml->geoplugin_latitude; |
747 | 747 | $credit = $load_xml->geoplugin_credit; |
748 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
748 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
749 | 749 | } |
750 | - } catch( Exception $e ) { } |
|
750 | + } catch (Exception $e) { } |
|
751 | 751 | } |
752 | 752 | |
753 | - if ( $iso && $longitude && $latitude ) { |
|
754 | - if ( $city ) { |
|
753 | + if ($iso && $longitude && $latitude) { |
|
754 | + if ($city) { |
|
755 | 755 | $address .= $city . ', '; |
756 | 756 | } |
757 | 757 | |
758 | - if ( $region ) { |
|
758 | + if ($region) { |
|
759 | 759 | $address .= $region . ', '; |
760 | 760 | } |
761 | 761 | |
762 | 762 | $address .= $country . ' (' . $iso . ')'; |
763 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
764 | - $content .= '<p>'. $credit . '</p>'; |
|
763 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
764 | + $content .= '<p>' . $credit . '</p>'; |
|
765 | 765 | } else { |
766 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
766 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
767 | 767 | } |
768 | 768 | ?> |
769 | 769 | <!DOCTYPE html> |
770 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
770 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
771 | 771 | <body> |
772 | - <?php if ( $latitude && $latitude ) { ?> |
|
772 | + <?php if ($latitude && $latitude) { ?> |
|
773 | 773 | <div id="map"></div> |
774 | 774 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
775 | 775 | <script type="text/javascript"> |
776 | 776 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
777 | 777 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
778 | 778 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
779 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
779 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
780 | 780 | |
781 | 781 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
782 | 782 | |
783 | 783 | var marker = new L.Marker(latlng); |
784 | 784 | map.addLayer(marker); |
785 | 785 | |
786 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
786 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
787 | 787 | </script> |
788 | 788 | <?php } ?> |
789 | 789 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -791,18 +791,18 @@ discard block |
||
791 | 791 | <?php |
792 | 792 | exit; |
793 | 793 | } |
794 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
795 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
794 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
795 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
796 | 796 | |
797 | 797 | // Set up the template for the invoice. |
798 | -function wpinv_template( $template ) { |
|
798 | +function wpinv_template($template) { |
|
799 | 799 | global $post, $wp_query; |
800 | 800 | |
801 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
802 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
803 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
801 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
802 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
803 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
804 | 804 | } else { |
805 | - $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
805 | + $template = wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | |
812 | 812 | function wpinv_get_business_address() { |
813 | 813 | $business_address = wpinv_store_address(); |
814 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
814 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
815 | 815 | |
816 | 816 | /* |
817 | 817 | $default_country = wpinv_get_default_country(); |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | |
836 | 836 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
837 | 837 | |
838 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
838 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | function wpinv_display_from_address() { |
@@ -845,116 +845,116 @@ discard block |
||
845 | 845 | if (empty($from_name)) { |
846 | 846 | $from_name = wpinv_get_business_name(); |
847 | 847 | } |
848 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
848 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
849 | 849 | <div class="wrapper col-xs-10"> |
850 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
851 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
852 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
850 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
851 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
852 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
853 | 853 | <?php } ?> |
854 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
855 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div> |
|
854 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
855 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div> |
|
856 | 856 | <?php } ?> |
857 | 857 | </div> |
858 | 858 | <?php |
859 | 859 | } |
860 | 860 | |
861 | -function wpinv_watermark( $id = 0 ) { |
|
862 | - $output = wpinv_get_watermark( $id ); |
|
861 | +function wpinv_watermark($id = 0) { |
|
862 | + $output = wpinv_get_watermark($id); |
|
863 | 863 | |
864 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
864 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
865 | 865 | } |
866 | 866 | |
867 | -function wpinv_get_watermark( $id ) { |
|
868 | - if ( !$id > 0 ) { |
|
867 | +function wpinv_get_watermark($id) { |
|
868 | + if (!$id > 0) { |
|
869 | 869 | return NULL; |
870 | 870 | } |
871 | - $invoice = wpinv_get_invoice( $id ); |
|
871 | + $invoice = wpinv_get_invoice($id); |
|
872 | 872 | |
873 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
874 | - if ( $invoice->is_paid() ) { |
|
875 | - return __( 'Paid', 'invoicing' ); |
|
873 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
874 | + if ($invoice->is_paid()) { |
|
875 | + return __('Paid', 'invoicing'); |
|
876 | 876 | } |
877 | - if ( $invoice->is_refunded() ) { |
|
878 | - return __( 'Refunded', 'invoicing' ); |
|
877 | + if ($invoice->is_refunded()) { |
|
878 | + return __('Refunded', 'invoicing'); |
|
879 | 879 | } |
880 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
881 | - return __( 'Cancelled', 'invoicing' ); |
|
880 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
881 | + return __('Cancelled', 'invoicing'); |
|
882 | 882 | } |
883 | 883 | } |
884 | 884 | |
885 | 885 | return NULL; |
886 | 886 | } |
887 | 887 | |
888 | -function wpinv_display_invoice_details( $invoice ) { |
|
888 | +function wpinv_display_invoice_details($invoice) { |
|
889 | 889 | global $wpinv_euvat; |
890 | 890 | |
891 | 891 | $invoice_id = $invoice->ID; |
892 | 892 | $vat_name = $wpinv_euvat->get_vat_name(); |
893 | 893 | $use_taxes = wpinv_use_taxes(); |
894 | 894 | |
895 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
895 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
896 | 896 | ?> |
897 | 897 | <table class="table table-bordered table-sm"> |
898 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
898 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
899 | 899 | <tr class="wpi-row-number"> |
900 | - <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th> |
|
901 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
900 | + <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th> |
|
901 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
902 | 902 | </tr> |
903 | 903 | <?php } ?> |
904 | 904 | <tr class="wpi-row-status"> |
905 | - <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th> |
|
906 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
905 | + <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th> |
|
906 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
907 | 907 | </tr> |
908 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
908 | + <?php if ($invoice->is_renewal()) { ?> |
|
909 | 909 | <tr class="wpi-row-parent"> |
910 | - <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th> |
|
911 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
910 | + <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th> |
|
911 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
912 | 912 | </tr> |
913 | 913 | <?php } ?> |
914 | - <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?> |
|
914 | + <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?> |
|
915 | 915 | <tr class="wpi-row-gateway"> |
916 | - <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th> |
|
916 | + <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th> |
|
917 | 917 | <td><?php echo $gateway_name; ?></td> |
918 | 918 | </tr> |
919 | 919 | <?php } ?> |
920 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
920 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
921 | 921 | <tr class="wpi-row-date"> |
922 | - <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th> |
|
922 | + <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th> |
|
923 | 923 | <td><?php echo $invoice_date; ?></td> |
924 | 924 | </tr> |
925 | 925 | <?php } ?> |
926 | - <?php do_action( 'wpinv_display_details_before_due_date', $invoice_id ); ?> |
|
927 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
926 | + <?php do_action('wpinv_display_details_before_due_date', $invoice_id); ?> |
|
927 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
928 | 928 | <tr class="wpi-row-date"> |
929 | - <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th> |
|
929 | + <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th> |
|
930 | 930 | <td><?php echo $due_date; ?></td> |
931 | 931 | </tr> |
932 | 932 | <?php } ?> |
933 | - <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?> |
|
934 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
933 | + <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?> |
|
934 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
935 | 935 | <tr class="wpi-row-ovatno"> |
936 | - <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th> |
|
936 | + <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th> |
|
937 | 937 | <td><?php echo $owner_vat_number; ?></td> |
938 | 938 | </tr> |
939 | 939 | <?php } ?> |
940 | - <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?> |
|
940 | + <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?> |
|
941 | 941 | <tr class="wpi-row-uvatno"> |
942 | - <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th> |
|
942 | + <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th> |
|
943 | 943 | <td><?php echo $user_vat_number; ?></td> |
944 | 944 | </tr> |
945 | 945 | <?php } ?> |
946 | 946 | <tr class="table-active tr-total wpi-row-total"> |
947 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
948 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
947 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
948 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
949 | 949 | </tr> |
950 | - <?php if ( $subscription = wpinv_get_subscription( $invoice_id ) ) { ?> |
|
950 | + <?php if ($subscription = wpinv_get_subscription($invoice_id)) { ?> |
|
951 | 951 | <tr class="table-active wpi-row-recurring-total"> |
952 | - <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Recurring Amount', 'invoicing' ), $invoice ); ?></th> |
|
953 | - <td><strong><?php echo wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ); ?></strong></td> |
|
952 | + <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Recurring Amount', 'invoicing'), $invoice); ?></th> |
|
953 | + <td><strong><?php echo wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()); ?></strong></td> |
|
954 | 954 | </tr> |
955 | 955 | <tr class="wpi-row-expires"> |
956 | - <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Renews On', 'invoicing' ), $invoice ); ?></th> |
|
957 | - <td><?php echo sanitize_text_field( $subscription->expiration ); ?></td> |
|
956 | + <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Renews On', 'invoicing'), $invoice); ?></th> |
|
957 | + <td><?php echo sanitize_text_field($subscription->expiration); ?></td> |
|
958 | 958 | </tr> |
959 | 959 | <?php } ?> |
960 | 960 | </table> |
@@ -971,84 +971,84 @@ discard block |
||
971 | 971 | * @param string $separator How to separate address lines. |
972 | 972 | * @return string |
973 | 973 | */ |
974 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
974 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
975 | 975 | |
976 | 976 | // Retrieve the address markup... |
977 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
978 | - $format = wpinv_get_full_address_format( $country ); |
|
977 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
978 | + $format = wpinv_get_full_address_format($country); |
|
979 | 979 | |
980 | 980 | // ... and the replacements. |
981 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
981 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
982 | 982 | |
983 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
983 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
984 | 984 | |
985 | 985 | // Remove unavailable tags. |
986 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
986 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
987 | 987 | |
988 | 988 | // Clean up white space. |
989 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
990 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
989 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
990 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
991 | 991 | |
992 | 992 | // Break newlines apart and remove empty lines/trim commas and white space. |
993 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
993 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
994 | 994 | |
995 | 995 | // Add html breaks. |
996 | - $formatted_address = implode( $separator, $formatted_address ); |
|
996 | + $formatted_address = implode($separator, $formatted_address); |
|
997 | 997 | |
998 | 998 | // We're done! |
999 | 999 | return $formatted_address; |
1000 | 1000 | |
1001 | 1001 | } |
1002 | 1002 | |
1003 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
1004 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1003 | +function wpinv_display_to_address($invoice_id = 0) { |
|
1004 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1005 | 1005 | |
1006 | - if ( empty( $invoice ) ) { |
|
1006 | + if (empty($invoice)) { |
|
1007 | 1007 | return NULL; |
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | $billing_details = $invoice->get_user_info(); |
1011 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
1011 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
1012 | 1012 | $output .= '<div class="wrapper col-xs-10">'; |
1013 | 1013 | |
1014 | 1014 | ob_start(); |
1015 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
1015 | + do_action('wpinv_display_to_address_top', $invoice); |
|
1016 | 1016 | $output .= ob_get_clean(); |
1017 | 1017 | |
1018 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1018 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1019 | 1019 | |
1020 | - if ( $address_row ) { |
|
1020 | + if ($address_row) { |
|
1021 | 1021 | $output .= '<div class="address">' . $address_row . '</div>'; |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - if ( $phone = $invoice->get_phone() ) { |
|
1025 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>'; |
|
1024 | + if ($phone = $invoice->get_phone()) { |
|
1025 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>'; |
|
1026 | 1026 | } |
1027 | - if ( $email = $invoice->get_email() ) { |
|
1028 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>'; |
|
1027 | + if ($email = $invoice->get_email()) { |
|
1028 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>'; |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | ob_start(); |
1032 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1032 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
1033 | 1033 | $output .= ob_get_clean(); |
1034 | 1034 | |
1035 | 1035 | $output .= '</div>'; |
1036 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1036 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
1037 | 1037 | |
1038 | 1038 | echo $output; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1041 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1042 | 1042 | global $wpinv_euvat, $ajax_cart_details; |
1043 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1043 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1044 | 1044 | $quantities_enabled = wpinv_item_quantities_enabled(); |
1045 | 1045 | $use_taxes = wpinv_use_taxes(); |
1046 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
1046 | + if (!$use_taxes && (float) $invoice->get_tax() > 0) { |
|
1047 | 1047 | $use_taxes = true; |
1048 | 1048 | } |
1049 | - $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
|
1050 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1051 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1049 | + $zero_tax = !(float) $invoice->get_tax() > 0 ? true : false; |
|
1050 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
1051 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
1052 | 1052 | |
1053 | 1053 | $cart_details = $invoice->get_cart_details(); |
1054 | 1054 | $ajax_cart_details = $cart_details; |
@@ -1057,67 +1057,67 @@ discard block |
||
1057 | 1057 | <table class="table table-sm table-bordered"> |
1058 | 1058 | <thead> |
1059 | 1059 | <tr> |
1060 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1061 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1060 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1061 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1062 | 1062 | <?php if ($quantities_enabled) { ?> |
1063 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1063 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1064 | 1064 | <?php } ?> |
1065 | 1065 | <?php if ($use_taxes && !$zero_tax) { ?> |
1066 | 1066 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1067 | 1067 | <?php } ?> |
1068 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1068 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1069 | 1069 | </tr> |
1070 | 1070 | </thead> |
1071 | 1071 | <tbody> |
1072 | 1072 | <?php |
1073 | - if ( !empty( $cart_details ) ) { |
|
1074 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1073 | + if (!empty($cart_details)) { |
|
1074 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1075 | 1075 | |
1076 | 1076 | $count = 0; |
1077 | 1077 | $cols = 3; |
1078 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1079 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1080 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
1081 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
1082 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1078 | + foreach ($cart_details as $key => $cart_item) { |
|
1079 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1080 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
1081 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
1082 | + $quantity = !empty($cart_item['quantity']) && (int) $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1083 | 1083 | |
1084 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1084 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1085 | 1085 | $summary = ''; |
1086 | - $item_name = ''; |
|
1086 | + $item_name = ''; |
|
1087 | 1087 | $cols = 3; |
1088 | - if ( !empty($item) ) { |
|
1088 | + if (!empty($item)) { |
|
1089 | 1089 | $item_name = $item->get_name(); |
1090 | 1090 | $summary = $item->get_summary(); |
1091 | 1091 | } |
1092 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1092 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1093 | 1093 | |
1094 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1094 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1095 | 1095 | |
1096 | 1096 | $item_tax = ''; |
1097 | 1097 | $tax_rate = ''; |
1098 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1099 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() ); |
|
1100 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1101 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
1098 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1099 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency()); |
|
1100 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1101 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
1102 | 1102 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | $line_item_tax = $item_tax . $tax_rate; |
1106 | 1106 | |
1107 | - if ( $line_item_tax === '' ) { |
|
1107 | + if ($line_item_tax === '') { |
|
1108 | 1108 | $line_item_tax = 0; // Zero tax |
1109 | 1109 | } |
1110 | 1110 | |
1111 | - $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols ); |
|
1111 | + $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols); |
|
1112 | 1112 | |
1113 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1114 | - $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1115 | - if ( $summary !== '' ) { |
|
1116 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1113 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1114 | + $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1115 | + if ($summary !== '') { |
|
1116 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1117 | 1117 | } |
1118 | 1118 | $line_item .= '</td>'; |
1119 | 1119 | |
1120 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
1120 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
1121 | 1121 | if ($quantities_enabled) { |
1122 | 1122 | $cols++; |
1123 | 1123 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1126,55 +1126,55 @@ discard block |
||
1126 | 1126 | $cols++; |
1127 | 1127 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1128 | 1128 | } |
1129 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
1129 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
1130 | 1130 | $line_item .= '</tr>'; |
1131 | 1131 | |
1132 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1132 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1133 | 1133 | |
1134 | 1134 | $count++; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1137 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1138 | 1138 | ?> |
1139 | 1139 | <tr class="row-sub-total row_odd"> |
1140 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1141 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1140 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1141 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1142 | 1142 | </tr> |
1143 | 1143 | <?php |
1144 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1144 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1145 | 1145 | |
1146 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1147 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1146 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1147 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1148 | 1148 | ?> |
1149 | 1149 | <tr class="row-discount"> |
1150 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1151 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1150 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1151 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1152 | 1152 | </tr> |
1153 | 1153 | <?php |
1154 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1154 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | - if ( $use_taxes ) { |
|
1158 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1157 | + if ($use_taxes) { |
|
1158 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1159 | 1159 | ?> |
1160 | 1160 | <tr class="row-tax"> |
1161 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1162 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1161 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1162 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1163 | 1163 | </tr> |
1164 | 1164 | <?php |
1165 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1165 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1168 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1169 | 1169 | ?> |
1170 | 1170 | <tr class="table-active row-total"> |
1171 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1172 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1171 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1172 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1173 | 1173 | </tr> |
1174 | 1174 | <?php |
1175 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1175 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1176 | 1176 | |
1177 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1177 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1178 | 1178 | } |
1179 | 1179 | ?> |
1180 | 1180 | </tbody> |
@@ -1186,56 +1186,56 @@ discard block |
||
1186 | 1186 | /** |
1187 | 1187 | * @param WPInv_Invoice $invoice |
1188 | 1188 | */ |
1189 | -function wpinv_display_invoice_notes( $invoice ) { |
|
1189 | +function wpinv_display_invoice_notes($invoice) { |
|
1190 | 1190 | |
1191 | - $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' ); |
|
1191 | + $notes = wpinv_get_invoice_notes($invoice->ID, 'customer'); |
|
1192 | 1192 | |
1193 | - if ( empty( $notes ) ) { |
|
1193 | + if (empty($notes)) { |
|
1194 | 1194 | return; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | echo '<div class="wpi_invoice_notes_container">'; |
1198 | - echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>'; |
|
1198 | + echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>'; |
|
1199 | 1199 | echo '<ul class="wpi_invoice_notes">'; |
1200 | 1200 | |
1201 | - foreach( $notes as $note ) { |
|
1202 | - wpinv_get_invoice_note_line_item( $note ); |
|
1201 | + foreach ($notes as $note) { |
|
1202 | + wpinv_get_invoice_note_line_item($note); |
|
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | echo '</ul>'; |
1206 | 1206 | echo '</div>'; |
1207 | 1207 | } |
1208 | -add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' ); |
|
1208 | +add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes'); |
|
1209 | 1209 | |
1210 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1210 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1211 | 1211 | $use_taxes = wpinv_use_taxes(); |
1212 | 1212 | |
1213 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1213 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1214 | 1214 | ?> |
1215 | 1215 | <table class="table table-sm table-bordered table-responsive"> |
1216 | 1216 | <tbody> |
1217 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1217 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1218 | 1218 | <tr class="row-sub-total"> |
1219 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1220 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1219 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1220 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1221 | 1221 | </tr> |
1222 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1223 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1222 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1223 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1224 | 1224 | <tr class="row-discount"> |
1225 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1226 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1225 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1226 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1227 | 1227 | </tr> |
1228 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1228 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1229 | 1229 | <?php } ?> |
1230 | - <?php if ( $use_taxes ) { ?> |
|
1230 | + <?php if ($use_taxes) { ?> |
|
1231 | 1231 | <tr class="row-tax"> |
1232 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1233 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1232 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1233 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1234 | 1234 | </tr> |
1235 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1235 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1236 | 1236 | <?php } ?> |
1237 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1238 | - <?php foreach ( $fees as $fee ) { ?> |
|
1237 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1238 | + <?php foreach ($fees as $fee) { ?> |
|
1239 | 1239 | <tr class="row-fee"> |
1240 | 1240 | <td class="rate"><?php echo $fee['label']; ?></td> |
1241 | 1241 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1243,82 +1243,82 @@ discard block |
||
1243 | 1243 | <?php } ?> |
1244 | 1244 | <?php } ?> |
1245 | 1245 | <tr class="table-active row-total"> |
1246 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1247 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1246 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1247 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1248 | 1248 | </tr> |
1249 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1249 | + <?php do_action('wpinv_after_totals'); ?> |
|
1250 | 1250 | </tbody> |
1251 | 1251 | |
1252 | 1252 | </table> |
1253 | 1253 | |
1254 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1254 | + <?php do_action('wpinv_after_totals_table'); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1258 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1257 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1258 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1259 | 1259 | |
1260 | 1260 | ob_start(); |
1261 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1262 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
1261 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1262 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) { |
|
1263 | 1263 | ?> |
1264 | 1264 | <div class="wpi-payment-info"> |
1265 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1266 | - <?php if ( $gateway_title ) { ?> |
|
1267 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1265 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1266 | + <?php if ($gateway_title) { ?> |
|
1267 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1268 | 1268 | <?php } ?> |
1269 | 1269 | </div> |
1270 | 1270 | <?php |
1271 | 1271 | } |
1272 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1272 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1273 | 1273 | $outout = ob_get_clean(); |
1274 | 1274 | |
1275 | - if ( $echo ) { |
|
1275 | + if ($echo) { |
|
1276 | 1276 | echo $outout; |
1277 | 1277 | } else { |
1278 | 1278 | return $outout; |
1279 | 1279 | } |
1280 | 1280 | } |
1281 | 1281 | |
1282 | -function wpinv_display_style( $invoice ) { |
|
1283 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1282 | +function wpinv_display_style($invoice) { |
|
1283 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1284 | 1284 | |
1285 | - wp_print_styles( 'open-sans' ); |
|
1286 | - wp_print_styles( 'wpinv-single-style' ); |
|
1285 | + wp_print_styles('open-sans'); |
|
1286 | + wp_print_styles('wpinv-single-style'); |
|
1287 | 1287 | |
1288 | 1288 | $custom_css = wpinv_get_option('template_custom_css'); |
1289 | - if(isset($custom_css) && !empty($custom_css)){ |
|
1290 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
1291 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
1289 | + if (isset($custom_css) && !empty($custom_css)) { |
|
1290 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
1291 | + $custom_css = str_replace('>', '>', $custom_css); |
|
1292 | 1292 | echo '<style type="text/css">'; |
1293 | 1293 | echo $custom_css; |
1294 | 1294 | echo '</style>'; |
1295 | 1295 | } |
1296 | 1296 | } |
1297 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1298 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
1297 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1298 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1299 | 1299 | |
1300 | 1300 | function wpinv_checkout_billing_details() { |
1301 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
1301 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
1302 | 1302 | if (empty($invoice_id)) { |
1303 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1303 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1304 | 1304 | return null; |
1305 | 1305 | } |
1306 | 1306 | |
1307 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1307 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1308 | 1308 | if (empty($invoice)) { |
1309 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1309 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1310 | 1310 | return null; |
1311 | 1311 | } |
1312 | 1312 | $user_id = $invoice->get_user_id(); |
1313 | 1313 | $user_info = $invoice->get_user_info(); |
1314 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1314 | + $address_info = wpinv_get_user_address($user_id); |
|
1315 | 1315 | |
1316 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1316 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1317 | 1317 | $user_info['first_name'] = $user_info['first_name']; |
1318 | 1318 | $user_info['last_name'] = $user_info['last_name']; |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1321 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1322 | 1322 | $user_info['country'] = $address_info['country']; |
1323 | 1323 | $user_info['state'] = $address_info['state']; |
1324 | 1324 | $user_info['city'] = $address_info['city']; |
@@ -1334,99 +1334,99 @@ discard block |
||
1334 | 1334 | 'address' |
1335 | 1335 | ); |
1336 | 1336 | |
1337 | - foreach ( $address_fields as $field ) { |
|
1338 | - if ( empty( $user_info[$field] ) ) { |
|
1337 | + foreach ($address_fields as $field) { |
|
1338 | + if (empty($user_info[$field])) { |
|
1339 | 1339 | $user_info[$field] = $address_info[$field]; |
1340 | 1340 | } |
1341 | 1341 | } |
1342 | 1342 | |
1343 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1343 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | 1346 | function wpinv_admin_get_line_items($invoice = array()) { |
1347 | 1347 | $item_quantities = wpinv_item_quantities_enabled(); |
1348 | 1348 | $use_taxes = wpinv_use_taxes(); |
1349 | 1349 | |
1350 | - if ( empty( $invoice ) ) { |
|
1350 | + if (empty($invoice)) { |
|
1351 | 1351 | return NULL; |
1352 | 1352 | } |
1353 | 1353 | |
1354 | 1354 | $cart_items = $invoice->get_cart_details(); |
1355 | - if ( empty( $cart_items ) ) { |
|
1355 | + if (empty($cart_items)) { |
|
1356 | 1356 | return NULL; |
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | ob_start(); |
1360 | 1360 | |
1361 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1361 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1362 | 1362 | |
1363 | 1363 | $count = 0; |
1364 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1364 | + foreach ($cart_items as $key => $cart_item) { |
|
1365 | 1365 | $item_id = $cart_item['id']; |
1366 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1366 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1367 | 1367 | |
1368 | 1368 | if (empty($wpi_item)) { |
1369 | 1369 | continue; |
1370 | 1370 | } |
1371 | 1371 | |
1372 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() ); |
|
1373 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1374 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() ); |
|
1372 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency()); |
|
1373 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1374 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency()); |
|
1375 | 1375 | $can_remove = true; |
1376 | 1376 | |
1377 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice ); |
|
1377 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice); |
|
1378 | 1378 | |
1379 | 1379 | $item_tax = ''; |
1380 | 1380 | $tax_rate = ''; |
1381 | - if ( $invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1382 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() ); |
|
1383 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1384 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
1381 | + if ($invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1382 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency()); |
|
1383 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1384 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
1385 | 1385 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1386 | 1386 | } |
1387 | 1387 | $line_item_tax = $item_tax . $tax_rate; |
1388 | 1388 | |
1389 | - if ( $line_item_tax === '' ) { |
|
1389 | + if ($line_item_tax === '') { |
|
1390 | 1390 | $line_item_tax = 0; // Zero tax |
1391 | 1391 | } |
1392 | 1392 | |
1393 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1393 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1394 | 1394 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1395 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1396 | - if ( $summary !== '' ) { |
|
1397 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1395 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
1396 | + if ($summary !== '') { |
|
1397 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1398 | 1398 | } |
1399 | 1399 | $line_item .= '</td>'; |
1400 | 1400 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1401 | 1401 | |
1402 | - if ( $item_quantities ) { |
|
1403 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1402 | + if ($item_quantities) { |
|
1403 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1404 | 1404 | $can_remove = false; |
1405 | 1405 | } |
1406 | 1406 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1407 | 1407 | } else { |
1408 | - if ( count( $cart_items ) == 1 ) { |
|
1408 | + if (count($cart_items) == 1) { |
|
1409 | 1409 | $can_remove = false; |
1410 | 1410 | } |
1411 | 1411 | } |
1412 | 1412 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1413 | 1413 | |
1414 | - if ( $use_taxes ) { |
|
1414 | + if ($use_taxes) { |
|
1415 | 1415 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1416 | 1416 | } |
1417 | 1417 | $line_item .= '<td class="action">'; |
1418 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
1418 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
1419 | 1419 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1420 | 1420 | } |
1421 | 1421 | $line_item .= '</td>'; |
1422 | 1422 | $line_item .= '</tr>'; |
1423 | 1423 | |
1424 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1424 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1425 | 1425 | |
1426 | 1426 | $count++; |
1427 | 1427 | } |
1428 | 1428 | |
1429 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1429 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1430 | 1430 | |
1431 | 1431 | return ob_get_clean(); |
1432 | 1432 | } |
@@ -1436,70 +1436,70 @@ discard block |
||
1436 | 1436 | |
1437 | 1437 | // Set current invoice id. |
1438 | 1438 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1439 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1439 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1440 | 1440 | $payment_form = wpinv_get_default_payment_form(); |
1441 | 1441 | |
1442 | 1442 | ob_start(); |
1443 | - do_action( 'wpinv_checkout_content_before' ); |
|
1443 | + do_action('wpinv_checkout_content_before'); |
|
1444 | 1444 | |
1445 | - if ( wpinv_get_cart_contents() ) { |
|
1445 | + if (wpinv_get_cart_contents()) { |
|
1446 | 1446 | |
1447 | 1447 | // Get the form elements and items. |
1448 | - $elements = $invoicing->form_elements->get_form_elements( $payment_form ); |
|
1449 | - $items = $invoicing->form_elements->convert_checkout_items( wpinv_get_cart_contents(), wpinv_get_invoice_cart() ); |
|
1448 | + $elements = $invoicing->form_elements->get_form_elements($payment_form); |
|
1449 | + $items = $invoicing->form_elements->convert_checkout_items(wpinv_get_cart_contents(), wpinv_get_invoice_cart()); |
|
1450 | 1450 | ?> |
1451 | 1451 | <form class="wpinv_payment_form" action="<?php echo $form_action; ?>" method="POST"> |
1452 | - <?php do_action( 'wpinv_main_checkout_form_top' ); ?> |
|
1453 | - <input type='hidden' name='form_id' value='<?php echo esc_attr( $payment_form ); ?>'/> |
|
1454 | - <input type='hidden' name='invoice_id' value='<?php echo esc_attr( $wpi_checkout_id ); ?>'/> |
|
1452 | + <?php do_action('wpinv_main_checkout_form_top'); ?> |
|
1453 | + <input type='hidden' name='form_id' value='<?php echo esc_attr($payment_form); ?>'/> |
|
1454 | + <input type='hidden' name='invoice_id' value='<?php echo esc_attr($wpi_checkout_id); ?>'/> |
|
1455 | 1455 | <?php |
1456 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
1457 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
1456 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
1457 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
1458 | 1458 | |
1459 | - foreach ( $elements as $element ) { |
|
1460 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $payment_form ); |
|
1461 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $payment_form ); |
|
1459 | + foreach ($elements as $element) { |
|
1460 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $payment_form); |
|
1461 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $payment_form); |
|
1462 | 1462 | } |
1463 | 1463 | ?> |
1464 | 1464 | <div class='wpinv_payment_form_errors alert alert-danger d-none'></div> |
1465 | - <?php do_action( 'wpinv_main_checkout_form_bottom' ); ?> |
|
1465 | + <?php do_action('wpinv_main_checkout_form_bottom'); ?> |
|
1466 | 1466 | </form> |
1467 | 1467 | <?php |
1468 | 1468 | |
1469 | 1469 | } else { |
1470 | - do_action( 'wpinv_cart_empty' ); |
|
1470 | + do_action('wpinv_cart_empty'); |
|
1471 | 1471 | } |
1472 | 1472 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1473 | - do_action( 'wpinv_checkout_content_after' ); |
|
1473 | + do_action('wpinv_checkout_content_after'); |
|
1474 | 1474 | $content = ob_get_clean(); |
1475 | 1475 | |
1476 | - return str_replace( 'sr-only', '', $content ); |
|
1476 | + return str_replace('sr-only', '', $content); |
|
1477 | 1477 | } |
1478 | 1478 | |
1479 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1479 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1480 | 1480 | global $ajax_cart_details; |
1481 | 1481 | $ajax_cart_details = $cart_details; |
1482 | 1482 | |
1483 | 1483 | ob_start(); |
1484 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1484 | + do_action('wpinv_before_checkout_cart'); |
|
1485 | 1485 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1486 | 1486 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1487 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1487 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1488 | 1488 | echo '</div>'; |
1489 | 1489 | echo '</div>'; |
1490 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1490 | + do_action('wpinv_after_checkout_cart'); |
|
1491 | 1491 | $content = ob_get_clean(); |
1492 | 1492 | |
1493 | - if ( $echo ) { |
|
1493 | + if ($echo) { |
|
1494 | 1494 | echo $content; |
1495 | 1495 | } else { |
1496 | 1496 | return $content; |
1497 | 1497 | } |
1498 | 1498 | } |
1499 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1499 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1500 | 1500 | |
1501 | 1501 | function wpinv_empty_cart_message() { |
1502 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1502 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | 1505 | /** |
@@ -1516,83 +1516,83 @@ discard block |
||
1516 | 1516 | ) |
1517 | 1517 | ); |
1518 | 1518 | } |
1519 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1519 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1520 | 1520 | |
1521 | 1521 | function wpinv_update_cart_button() { |
1522 | - if ( !wpinv_item_quantities_enabled() ) |
|
1522 | + if (!wpinv_item_quantities_enabled()) |
|
1523 | 1523 | return; |
1524 | 1524 | ?> |
1525 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1525 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1526 | 1526 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1527 | 1527 | <?php |
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | function wpinv_checkout_cart_columns() { |
1531 | 1531 | $default = 3; |
1532 | - if ( wpinv_item_quantities_enabled() ) { |
|
1532 | + if (wpinv_item_quantities_enabled()) { |
|
1533 | 1533 | $default++; |
1534 | 1534 | } |
1535 | 1535 | |
1536 | - if ( wpinv_use_taxes() ) { |
|
1536 | + if (wpinv_use_taxes()) { |
|
1537 | 1537 | $default++; |
1538 | 1538 | } |
1539 | 1539 | |
1540 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1540 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1541 | 1541 | } |
1542 | 1542 | |
1543 | 1543 | function wpinv_display_cart_messages() { |
1544 | 1544 | global $wpi_session; |
1545 | 1545 | |
1546 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1546 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1547 | 1547 | |
1548 | - if ( $messages ) { |
|
1549 | - foreach ( $messages as $message_id => $message ) { |
|
1548 | + if ($messages) { |
|
1549 | + foreach ($messages as $message_id => $message) { |
|
1550 | 1550 | // Try and detect what type of message this is |
1551 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1551 | + if (strpos(strtolower($message), 'error')) { |
|
1552 | 1552 | $type = 'error'; |
1553 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1553 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1554 | 1554 | $type = 'success'; |
1555 | 1555 | } else { |
1556 | 1556 | $type = 'info'; |
1557 | 1557 | } |
1558 | 1558 | |
1559 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1559 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1560 | 1560 | |
1561 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1561 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1562 | 1562 | // Loop message codes and display messages |
1563 | 1563 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1564 | 1564 | echo '</div>'; |
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | // Remove all of the cart saving messages |
1568 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1568 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1569 | 1569 | } |
1570 | 1570 | } |
1571 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1571 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1572 | 1572 | |
1573 | 1573 | function wpinv_discount_field() { |
1574 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1574 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1575 | 1575 | return; // Only show before a payment method has been selected if ajax is disabled |
1576 | 1576 | } |
1577 | 1577 | |
1578 | - if ( !wpinv_is_checkout() ) { |
|
1578 | + if (!wpinv_is_checkout()) { |
|
1579 | 1579 | return; |
1580 | 1580 | } |
1581 | 1581 | |
1582 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1582 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1583 | 1583 | ?> |
1584 | 1584 | <div id="wpinv-discount-field" class="panel panel-default"> |
1585 | 1585 | <div class="panel-body"> |
1586 | 1586 | <p> |
1587 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1588 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1587 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1588 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1589 | 1589 | </p> |
1590 | 1590 | <div class="form-group row"> |
1591 | 1591 | <div class="col-sm-4"> |
1592 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1592 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1593 | 1593 | </div> |
1594 | 1594 | <div class="col-sm-3"> |
1595 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1595 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1596 | 1596 | </div> |
1597 | 1597 | <div style="clear:both"></div> |
1598 | 1598 | <div class="col-sm-12 wpinv-discount-msg"> |
@@ -1605,10 +1605,10 @@ discard block |
||
1605 | 1605 | <?php |
1606 | 1606 | } |
1607 | 1607 | } |
1608 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1608 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1609 | 1609 | |
1610 | 1610 | function wpinv_agree_to_terms_js() { |
1611 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1611 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1612 | 1612 | ?> |
1613 | 1613 | <script type="text/javascript"> |
1614 | 1614 | jQuery(document).ready(function($){ |
@@ -1623,127 +1623,127 @@ discard block |
||
1623 | 1623 | <?php |
1624 | 1624 | } |
1625 | 1625 | } |
1626 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1626 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1627 | 1627 | |
1628 | -function wpinv_payment_mode_select( $title ) { |
|
1629 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1630 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1631 | - $invoice = wpinv_get_invoice( 0, true ); |
|
1628 | +function wpinv_payment_mode_select($title) { |
|
1629 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1630 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1631 | + $invoice = wpinv_get_invoice(0, true); |
|
1632 | 1632 | |
1633 | 1633 | do_action('wpinv_payment_mode_top'); |
1634 | - $invoice_id = $invoice ? (int)$invoice->ID : 0; |
|
1635 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1634 | + $invoice_id = $invoice ? (int) $invoice->ID : 0; |
|
1635 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1636 | 1636 | ?> |
1637 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( ( $invoice && $invoice->is_free() ) ? 'style="display:none;" data-free="1"' : '' ); ?>> |
|
1638 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1637 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo (($invoice && $invoice->is_free()) ? 'style="display:none;" data-free="1"' : ''); ?>> |
|
1638 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1639 | 1639 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1640 | 1640 | <div class="panel-heading wpi-payment_methods_title"> |
1641 | - <h6 class="panel-title"><?php echo sanitize_text_field( $title ); ?></h6> |
|
1641 | + <h6 class="panel-title"><?php echo sanitize_text_field($title); ?></h6> |
|
1642 | 1642 | </div> |
1643 | 1643 | <div class="panel-body wpi-payment_methods"> |
1644 | 1644 | <?php |
1645 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1646 | - |
|
1647 | - if ( !empty( $gateways ) ) { |
|
1648 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1649 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1650 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1651 | - $gateway_label = wpinv_get_gateway_checkout_label( $gateway_id ); |
|
1652 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1645 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1646 | + |
|
1647 | + if (!empty($gateways)) { |
|
1648 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1649 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1650 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1651 | + $gateway_label = wpinv_get_gateway_checkout_label($gateway_id); |
|
1652 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1653 | 1653 | ?> |
1654 | 1654 | <div class="pt-2 pb-2"> |
1655 | 1655 | <div class="radio"> |
1656 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway_label ); ?></label> |
|
1656 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway_label); ?></label> |
|
1657 | 1657 | </div> |
1658 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1659 | - <?php if ( !empty( $description ) ) { ?> |
|
1660 | - <div class="wpi-gateway-desc"><?php _e( $description, 'invoicing' ); ?></div> |
|
1658 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1659 | + <?php if (!empty($description)) { ?> |
|
1660 | + <div class="wpi-gateway-desc"><?php _e($description, 'invoicing'); ?></div> |
|
1661 | 1661 | <?php } ?> |
1662 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1662 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1663 | 1663 | </div> |
1664 | 1664 | </div> |
1665 | 1665 | <?php |
1666 | 1666 | } |
1667 | 1667 | } else { |
1668 | - echo '<div class="alert alert-danger">'. __( 'No payment gateway active', 'invoicing' ) .'</div>'; |
|
1668 | + echo '<div class="alert alert-danger">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1669 | 1669 | } |
1670 | 1670 | |
1671 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1671 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1672 | 1672 | ?> |
1673 | 1673 | </div> |
1674 | 1674 | </div> |
1675 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1675 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1676 | 1676 | </div> |
1677 | 1677 | <?php |
1678 | 1678 | do_action('wpinv_payment_mode_bottom'); |
1679 | 1679 | } |
1680 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1680 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1681 | 1681 | |
1682 | 1682 | function wpinv_checkout_billing_info() { |
1683 | - if ( wpinv_is_checkout() ) { |
|
1683 | + if (wpinv_is_checkout()) { |
|
1684 | 1684 | $billing_details = wpinv_checkout_billing_details(); |
1685 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1685 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1686 | 1686 | ?> |
1687 | 1687 | <div id="wpinv-fields" class="clearfix"> |
1688 | 1688 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1689 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1689 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1690 | 1690 | <div id="wpinv-fields-box" class="panel-body"> |
1691 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1691 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1692 | 1692 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1693 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1693 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1694 | 1694 | <?php |
1695 | - echo wpinv_html_text( array( |
|
1695 | + echo wpinv_html_text(array( |
|
1696 | 1696 | 'id' => 'wpinv_first_name', |
1697 | 1697 | 'name' => 'wpinv_first_name', |
1698 | 1698 | 'value' => $billing_details['first_name'], |
1699 | 1699 | 'class' => 'wpi-input form-control', |
1700 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1701 | - 'required' => (bool)wpinv_get_option( 'fname_mandatory' ), |
|
1702 | - ) ); |
|
1700 | + 'placeholder' => __('First name', 'invoicing'), |
|
1701 | + 'required' => (bool) wpinv_get_option('fname_mandatory'), |
|
1702 | + )); |
|
1703 | 1703 | ?> |
1704 | 1704 | </p> |
1705 | 1705 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1706 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1706 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1707 | 1707 | <?php |
1708 | - echo wpinv_html_text( array( |
|
1708 | + echo wpinv_html_text(array( |
|
1709 | 1709 | 'id' => 'wpinv_last_name', |
1710 | 1710 | 'name' => 'wpinv_last_name', |
1711 | 1711 | 'value' => $billing_details['last_name'], |
1712 | 1712 | 'class' => 'wpi-input form-control', |
1713 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1714 | - 'required' => (bool)wpinv_get_option( 'lname_mandatory' ), |
|
1715 | - ) ); |
|
1713 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1714 | + 'required' => (bool) wpinv_get_option('lname_mandatory'), |
|
1715 | + )); |
|
1716 | 1716 | ?> |
1717 | 1717 | </p> |
1718 | 1718 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1719 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1719 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1720 | 1720 | <?php |
1721 | - echo wpinv_html_text( array( |
|
1721 | + echo wpinv_html_text(array( |
|
1722 | 1722 | 'id' => 'wpinv_address', |
1723 | 1723 | 'name' => 'wpinv_address', |
1724 | 1724 | 'value' => $billing_details['address'], |
1725 | 1725 | 'class' => 'wpi-input form-control', |
1726 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1727 | - 'required' => (bool)wpinv_get_option( 'address_mandatory' ), |
|
1728 | - ) ); |
|
1726 | + 'placeholder' => __('Address', 'invoicing'), |
|
1727 | + 'required' => (bool) wpinv_get_option('address_mandatory'), |
|
1728 | + )); |
|
1729 | 1729 | ?> |
1730 | 1730 | </p> |
1731 | 1731 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1732 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1732 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1733 | 1733 | <?php |
1734 | - echo wpinv_html_text( array( |
|
1734 | + echo wpinv_html_text(array( |
|
1735 | 1735 | 'id' => 'wpinv_city', |
1736 | 1736 | 'name' => 'wpinv_city', |
1737 | 1737 | 'value' => $billing_details['city'], |
1738 | 1738 | 'class' => 'wpi-input form-control', |
1739 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1740 | - 'required' => (bool)wpinv_get_option( 'city_mandatory' ), |
|
1741 | - ) ); |
|
1739 | + 'placeholder' => __('City', 'invoicing'), |
|
1740 | + 'required' => (bool) wpinv_get_option('city_mandatory'), |
|
1741 | + )); |
|
1742 | 1742 | ?> |
1743 | 1743 | </p> |
1744 | 1744 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1745 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1746 | - <?php echo wpinv_html_select( array( |
|
1745 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1746 | + <?php echo wpinv_html_select(array( |
|
1747 | 1747 | 'options' => wpinv_get_country_list(), |
1748 | 1748 | 'name' => 'wpinv_country', |
1749 | 1749 | 'id' => 'wpinv_country', |
@@ -1751,16 +1751,16 @@ discard block |
||
1751 | 1751 | 'show_option_all' => false, |
1752 | 1752 | 'show_option_none' => false, |
1753 | 1753 | 'class' => 'wpi-input form-control wpi_select2', |
1754 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1755 | - 'required' => (bool)wpinv_get_option( 'country_mandatory' ), |
|
1756 | - ) ); ?> |
|
1754 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1755 | + 'required' => (bool) wpinv_get_option('country_mandatory'), |
|
1756 | + )); ?> |
|
1757 | 1757 | </p> |
1758 | 1758 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1759 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1759 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1760 | 1760 | <?php |
1761 | - $states = wpinv_get_country_states( $selected_country ); |
|
1762 | - if( !empty( $states ) ) { |
|
1763 | - echo wpinv_html_select( array( |
|
1761 | + $states = wpinv_get_country_states($selected_country); |
|
1762 | + if (!empty($states)) { |
|
1763 | + echo wpinv_html_select(array( |
|
1764 | 1764 | 'options' => $states, |
1765 | 1765 | 'name' => 'wpinv_state', |
1766 | 1766 | 'id' => 'wpinv_state', |
@@ -1768,61 +1768,61 @@ discard block |
||
1768 | 1768 | 'show_option_all' => false, |
1769 | 1769 | 'show_option_none' => false, |
1770 | 1770 | 'class' => 'wpi-input form-control wpi_select2', |
1771 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1772 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
1773 | - ) ); |
|
1771 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1772 | + 'required' => (bool) wpinv_get_option('state_mandatory'), |
|
1773 | + )); |
|
1774 | 1774 | } else { |
1775 | - echo wpinv_html_text( array( |
|
1775 | + echo wpinv_html_text(array( |
|
1776 | 1776 | 'name' => 'wpinv_state', |
1777 | 1777 | 'value' => $billing_details['state'], |
1778 | 1778 | 'id' => 'wpinv_state', |
1779 | 1779 | 'class' => 'wpi-input form-control', |
1780 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1781 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
1782 | - ) ); |
|
1780 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1781 | + 'required' => (bool) wpinv_get_option('state_mandatory'), |
|
1782 | + )); |
|
1783 | 1783 | } |
1784 | 1784 | ?> |
1785 | 1785 | </p> |
1786 | 1786 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1787 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1787 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1788 | 1788 | <?php |
1789 | - echo wpinv_html_text( array( |
|
1789 | + echo wpinv_html_text(array( |
|
1790 | 1790 | 'name' => 'wpinv_zip', |
1791 | 1791 | 'value' => $billing_details['zip'], |
1792 | 1792 | 'id' => 'wpinv_zip', |
1793 | 1793 | 'class' => 'wpi-input form-control', |
1794 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1795 | - 'required' => (bool)wpinv_get_option( 'zip_mandatory' ), |
|
1796 | - ) ); |
|
1794 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1795 | + 'required' => (bool) wpinv_get_option('zip_mandatory'), |
|
1796 | + )); |
|
1797 | 1797 | ?> |
1798 | 1798 | </p> |
1799 | 1799 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1800 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1800 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1801 | 1801 | <?php |
1802 | - echo wpinv_html_text( array( |
|
1802 | + echo wpinv_html_text(array( |
|
1803 | 1803 | 'id' => 'wpinv_phone', |
1804 | 1804 | 'name' => 'wpinv_phone', |
1805 | 1805 | 'value' => $billing_details['phone'], |
1806 | 1806 | 'class' => 'wpi-input form-control', |
1807 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1808 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1809 | - ) ); |
|
1807 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1808 | + 'required' => (bool) wpinv_get_option('phone_mandatory'), |
|
1809 | + )); |
|
1810 | 1810 | ?> |
1811 | 1811 | </p> |
1812 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1812 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1813 | 1813 | <div class="clearfix"></div> |
1814 | 1814 | </div> |
1815 | 1815 | </div> |
1816 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1816 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1817 | 1817 | </div> |
1818 | 1818 | <?php |
1819 | 1819 | } |
1820 | 1820 | } |
1821 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1821 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1822 | 1822 | |
1823 | 1823 | function wpinv_checkout_hidden_fields() { |
1824 | 1824 | ?> |
1825 | - <?php if ( is_user_logged_in() ) { ?> |
|
1825 | + <?php if (is_user_logged_in()) { ?> |
|
1826 | 1826 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1827 | 1827 | <?php } ?> |
1828 | 1828 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1832,9 +1832,9 @@ discard block |
||
1832 | 1832 | function wpinv_checkout_button_purchase() { |
1833 | 1833 | ob_start(); |
1834 | 1834 | ?> |
1835 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1835 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
1836 | 1836 | <?php |
1837 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1837 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1838 | 1838 | } |
1839 | 1839 | |
1840 | 1840 | function wpinv_checkout_total() { |
@@ -1843,64 +1843,64 @@ discard block |
||
1843 | 1843 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1844 | 1844 | <div class="panel-body"> |
1845 | 1845 | <?php |
1846 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1846 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1847 | 1847 | ?> |
1848 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1848 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1849 | 1849 | <?php |
1850 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1850 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1851 | 1851 | ?> |
1852 | 1852 | </div> |
1853 | 1853 | </div> |
1854 | 1854 | <?php |
1855 | 1855 | } |
1856 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1856 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1857 | 1857 | |
1858 | 1858 | function wpinv_checkout_submit() { |
1859 | 1859 | ?> |
1860 | 1860 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1861 | 1861 | <div class="panel-body text-center"> |
1862 | 1862 | <?php |
1863 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1863 | + do_action('wpinv_purchase_form_before_submit'); |
|
1864 | 1864 | wpinv_checkout_hidden_fields(); |
1865 | 1865 | echo wpinv_checkout_button_purchase(); |
1866 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1866 | + do_action('wpinv_purchase_form_after_submit'); |
|
1867 | 1867 | ?> |
1868 | 1868 | </div> |
1869 | 1869 | </div> |
1870 | 1870 | <?php |
1871 | 1871 | } |
1872 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1872 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1873 | 1873 | |
1874 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1875 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1874 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1875 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1876 | 1876 | |
1877 | - if ( empty( $invoice ) ) { |
|
1877 | + if (empty($invoice)) { |
|
1878 | 1878 | return NULL; |
1879 | 1879 | } |
1880 | 1880 | |
1881 | 1881 | $billing_details = $invoice->get_user_info(); |
1882 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1882 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1883 | 1883 | |
1884 | 1884 | ob_start(); |
1885 | 1885 | ?> |
1886 | 1886 | <table class="table table-bordered table-sm wpi-billing-details"> |
1887 | 1887 | <tbody> |
1888 | 1888 | <tr class="wpi-receipt-name"> |
1889 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1890 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1889 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1890 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1891 | 1891 | </tr> |
1892 | 1892 | <tr class="wpi-receipt-email"> |
1893 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1894 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1893 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1894 | + <td><?php echo $billing_details['email']; ?></td> |
|
1895 | 1895 | </tr> |
1896 | 1896 | <tr class="wpi-receipt-address"> |
1897 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1898 | - <td><?php echo $address_row ;?></td> |
|
1897 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1898 | + <td><?php echo $address_row; ?></td> |
|
1899 | 1899 | </tr> |
1900 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1900 | + <?php if ($billing_details['phone']) { ?> |
|
1901 | 1901 | <tr class="wpi-receipt-phone"> |
1902 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1903 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1902 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1903 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1904 | 1904 | </tr> |
1905 | 1905 | <?php } ?> |
1906 | 1906 | </tbody> |
@@ -1908,74 +1908,74 @@ discard block |
||
1908 | 1908 | <?php |
1909 | 1909 | $output = ob_get_clean(); |
1910 | 1910 | |
1911 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1911 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1912 | 1912 | |
1913 | 1913 | echo $output; |
1914 | 1914 | } |
1915 | 1915 | |
1916 | -function wpinv_filter_success_page_content( $content ) { |
|
1917 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1918 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1919 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1916 | +function wpinv_filter_success_page_content($content) { |
|
1917 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1918 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1919 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1920 | 1920 | } |
1921 | 1921 | } |
1922 | 1922 | |
1923 | 1923 | return $content; |
1924 | 1924 | } |
1925 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1925 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1926 | 1926 | |
1927 | -function wpinv_receipt_actions( $invoice ) { |
|
1928 | - if ( !empty( $invoice ) ) { |
|
1927 | +function wpinv_receipt_actions($invoice) { |
|
1928 | + if (!empty($invoice)) { |
|
1929 | 1929 | $actions = array(); |
1930 | 1930 | |
1931 | - if ( wpinv_user_can_view_invoice( $invoice->ID ) ) { |
|
1932 | - $actions['print'] = array( |
|
1933 | - 'url' => $invoice->get_view_url( true ), |
|
1934 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1931 | + if (wpinv_user_can_view_invoice($invoice->ID)) { |
|
1932 | + $actions['print'] = array( |
|
1933 | + 'url' => $invoice->get_view_url(true), |
|
1934 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1935 | 1935 | 'class' => 'btn-primary', |
1936 | 1936 | ); |
1937 | 1937 | } |
1938 | 1938 | |
1939 | - if ( is_user_logged_in() ) { |
|
1939 | + if (is_user_logged_in()) { |
|
1940 | 1940 | $actions['history'] = array( |
1941 | 1941 | 'url' => wpinv_get_history_page_uri(), |
1942 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1942 | + 'name' => __('Invoice History', 'invoicing'), |
|
1943 | 1943 | 'class' => 'btn-warning', |
1944 | 1944 | ); |
1945 | 1945 | } |
1946 | 1946 | |
1947 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1947 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1948 | 1948 | |
1949 | - if ( !empty( $actions ) ) { |
|
1949 | + if (!empty($actions)) { |
|
1950 | 1950 | ?> |
1951 | 1951 | <div class="wpinv-receipt-actions text-right"> |
1952 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1953 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1952 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1953 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
1954 | 1954 | <?php } ?> |
1955 | 1955 | </div> |
1956 | 1956 | <?php |
1957 | 1957 | } |
1958 | 1958 | } |
1959 | 1959 | } |
1960 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1960 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1961 | 1961 | |
1962 | -function wpinv_invoice_link( $invoice_id ) { |
|
1963 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1962 | +function wpinv_invoice_link($invoice_id) { |
|
1963 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1964 | 1964 | |
1965 | - if ( empty( $invoice ) ) { |
|
1965 | + if (empty($invoice)) { |
|
1966 | 1966 | return NULL; |
1967 | 1967 | } |
1968 | 1968 | |
1969 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1969 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1970 | 1970 | |
1971 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1971 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1972 | 1972 | } |
1973 | 1973 | |
1974 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1975 | - if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) { |
|
1976 | - $subscription = wpinv_get_subscription( $invoice, true ); |
|
1974 | +function wpinv_invoice_subscription_details($invoice) { |
|
1975 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1976 | + $subscription = wpinv_get_subscription($invoice, true); |
|
1977 | 1977 | |
1978 | - if ( empty( $subscription ) ) { |
|
1978 | + if (empty($subscription)) { |
|
1979 | 1979 | return; |
1980 | 1980 | } |
1981 | 1981 | |
@@ -1986,15 +1986,15 @@ discard block |
||
1986 | 1986 | $payments = $subscription->get_child_payments(); |
1987 | 1987 | ?> |
1988 | 1988 | <div class="wpinv-subscriptions-details"> |
1989 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1989 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1990 | 1990 | <table class="table"> |
1991 | 1991 | <thead> |
1992 | 1992 | <tr> |
1993 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1994 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1995 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1996 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1997 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1993 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1994 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1995 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1996 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1997 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1998 | 1998 | </tr> |
1999 | 1999 | </thead> |
2000 | 2000 | <tbody> |
@@ -2008,29 +2008,29 @@ discard block |
||
2008 | 2008 | </tbody> |
2009 | 2009 | </table> |
2010 | 2010 | </div> |
2011 | - <?php if ( !empty( $payments ) ) { ?> |
|
2011 | + <?php if (!empty($payments)) { ?> |
|
2012 | 2012 | <div class="wpinv-renewal-payments"> |
2013 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
2013 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
2014 | 2014 | <table class="table"> |
2015 | 2015 | <thead> |
2016 | 2016 | <tr> |
2017 | 2017 | <th>#</th> |
2018 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2019 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2020 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2018 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
2019 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
2020 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
2021 | 2021 | </tr> |
2022 | 2022 | </thead> |
2023 | 2023 | <tbody> |
2024 | 2024 | <?php |
2025 | 2025 | $i = 1; |
2026 | - foreach ( $payments as $payment ) { |
|
2026 | + foreach ($payments as $payment) { |
|
2027 | 2027 | $invoice_id = $payment->ID; |
2028 | 2028 | ?> |
2029 | 2029 | <tr> |
2030 | - <th scope="row"><?php echo $i;?></th> |
|
2031 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2032 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2033 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2030 | + <th scope="row"><?php echo $i; ?></th> |
|
2031 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
2032 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
2033 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
2034 | 2034 | </tr> |
2035 | 2035 | <?php $i++; } ?> |
2036 | 2036 | </tbody> |
@@ -2041,52 +2041,52 @@ discard block |
||
2041 | 2041 | } |
2042 | 2042 | } |
2043 | 2043 | |
2044 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
2045 | - if ( empty( $invoice ) ) { |
|
2044 | +function wpinv_cart_total_label($label, $invoice) { |
|
2045 | + if (empty($invoice)) { |
|
2046 | 2046 | return $label; |
2047 | 2047 | } |
2048 | 2048 | |
2049 | 2049 | $prefix_label = ''; |
2050 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2051 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2052 | - } else if ( $invoice->is_renewal() ) { |
|
2053 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2050 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
2051 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
2052 | + } else if ($invoice->is_renewal()) { |
|
2053 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2054 | 2054 | } |
2055 | 2055 | |
2056 | - if ( $prefix_label != '' ) { |
|
2057 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2056 | + if ($prefix_label != '') { |
|
2057 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2058 | 2058 | } |
2059 | 2059 | |
2060 | 2060 | return $label; |
2061 | 2061 | } |
2062 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2063 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2064 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2062 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2063 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2064 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2065 | 2065 | |
2066 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2066 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2067 | 2067 | |
2068 | -function wpinv_invoice_print_description( $invoice ) { |
|
2069 | - if ( empty( $invoice ) ) { |
|
2068 | +function wpinv_invoice_print_description($invoice) { |
|
2069 | + if (empty($invoice)) { |
|
2070 | 2070 | return NULL; |
2071 | 2071 | } |
2072 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2072 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2073 | 2073 | ?> |
2074 | 2074 | <div class="row wpinv-lower"> |
2075 | 2075 | <div class="col-sm-12 wpinv-description"> |
2076 | - <?php echo wpautop( $description ); ?> |
|
2076 | + <?php echo wpautop($description); ?> |
|
2077 | 2077 | </div> |
2078 | 2078 | </div> |
2079 | 2079 | <?php |
2080 | 2080 | } |
2081 | 2081 | } |
2082 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2082 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2083 | 2083 | |
2084 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2085 | - if ( empty( $invoice ) ) { |
|
2084 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2085 | + if (empty($invoice)) { |
|
2086 | 2086 | return NULL; |
2087 | 2087 | } |
2088 | 2088 | |
2089 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2089 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2090 | 2090 | ?> |
2091 | 2091 | <div class="row wpinv-payments"> |
2092 | 2092 | <div class="col-sm-12"> |
@@ -2098,43 +2098,43 @@ discard block |
||
2098 | 2098 | } |
2099 | 2099 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2100 | 2100 | |
2101 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2102 | - if ( empty( $note ) ) { |
|
2101 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2102 | + if (empty($note)) { |
|
2103 | 2103 | return NULL; |
2104 | 2104 | } |
2105 | 2105 | |
2106 | - if ( is_int( $note ) ) { |
|
2107 | - $note = get_comment( $note ); |
|
2106 | + if (is_int($note)) { |
|
2107 | + $note = get_comment($note); |
|
2108 | 2108 | } |
2109 | 2109 | |
2110 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2110 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2111 | 2111 | return NULL; |
2112 | 2112 | } |
2113 | 2113 | |
2114 | - $note_classes = array( 'note' ); |
|
2115 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2114 | + $note_classes = array('note'); |
|
2115 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2116 | 2116 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
2117 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2118 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2117 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2118 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2119 | 2119 | |
2120 | 2120 | ob_start(); |
2121 | 2121 | ?> |
2122 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2122 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2123 | 2123 | <div class="note_content"> |
2124 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2124 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2125 | 2125 | </div> |
2126 | 2126 | <p class="meta"> |
2127 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> |
|
2128 | - <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?> |
|
2129 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2127 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> |
|
2128 | + <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?> |
|
2129 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2130 | 2130 | <?php } ?> |
2131 | 2131 | </p> |
2132 | 2132 | </li> |
2133 | 2133 | <?php |
2134 | 2134 | $note_content = ob_get_clean(); |
2135 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2135 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2136 | 2136 | |
2137 | - if ( $echo ) { |
|
2137 | + if ($echo) { |
|
2138 | 2138 | echo $note_content; |
2139 | 2139 | } else { |
2140 | 2140 | return $note_content; |
@@ -2144,43 +2144,43 @@ discard block |
||
2144 | 2144 | function wpinv_invalid_invoice_content() { |
2145 | 2145 | global $post; |
2146 | 2146 | |
2147 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
2147 | + $invoice = wpinv_get_invoice($post->ID); |
|
2148 | 2148 | |
2149 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
2150 | - if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
2151 | - if ( is_user_logged_in() ) { |
|
2152 | - if ( wpinv_require_login_to_checkout() ) { |
|
2153 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2154 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
2149 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
2150 | + if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
2151 | + if (is_user_logged_in()) { |
|
2152 | + if (wpinv_require_login_to_checkout()) { |
|
2153 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2154 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
2155 | 2155 | } |
2156 | 2156 | } |
2157 | 2157 | } else { |
2158 | - if ( wpinv_require_login_to_checkout() ) { |
|
2159 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2160 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
2158 | + if (wpinv_require_login_to_checkout()) { |
|
2159 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2160 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
2161 | 2161 | } |
2162 | 2162 | } |
2163 | 2163 | } |
2164 | 2164 | } else { |
2165 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
2165 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
2166 | 2166 | } |
2167 | 2167 | ?> |
2168 | 2168 | <div class="row wpinv-row-invalid"> |
2169 | 2169 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
2170 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
2170 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
2171 | 2171 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
2172 | 2172 | </div> |
2173 | 2173 | </div> |
2174 | 2174 | <?php |
2175 | 2175 | } |
2176 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
2176 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
2177 | 2177 | |
2178 | -add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field'); |
|
2179 | -function wpinv_force_company_name_field(){ |
|
2178 | +add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field'); |
|
2179 | +function wpinv_force_company_name_field() { |
|
2180 | 2180 | $invoice = wpinv_get_invoice_cart(); |
2181 | - $user_id = wpinv_get_user_id( $invoice->ID ); |
|
2182 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
2183 | - if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) { |
|
2181 | + $user_id = wpinv_get_user_id($invoice->ID); |
|
2182 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
2183 | + if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) { |
|
2184 | 2184 | ?> |
2185 | 2185 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
2186 | 2186 | <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
@@ -2206,21 +2206,21 @@ discard block |
||
2206 | 2206 | * @return string |
2207 | 2207 | */ |
2208 | 2208 | function wpinv_get_policy_text() { |
2209 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
2209 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
2210 | 2210 | |
2211 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
2211 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
2212 | 2212 | |
2213 | - if(!$privacy_page_id){ |
|
2214 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
2213 | + if (!$privacy_page_id) { |
|
2214 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
2215 | 2215 | } |
2216 | 2216 | |
2217 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
2217 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
2218 | 2218 | |
2219 | 2219 | $find_replace = array( |
2220 | 2220 | '[wpinv_privacy_policy]' => $privacy_link, |
2221 | 2221 | ); |
2222 | 2222 | |
2223 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
2223 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
2224 | 2224 | |
2225 | 2225 | return wp_kses_post(wpautop($privacy_text)); |
2226 | 2226 | } |
@@ -2229,25 +2229,25 @@ discard block |
||
2229 | 2229 | /** |
2230 | 2230 | * Allows the user to set their own price for an invoice item |
2231 | 2231 | */ |
2232 | -function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) { |
|
2232 | +function wpinv_checkout_cart_item_name_your_price($cart_item, $key) { |
|
2233 | 2233 | |
2234 | 2234 | //Ensure we have an item id |
2235 | - if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) { |
|
2235 | + if (!is_array($cart_item) || empty($cart_item['id'])) { |
|
2236 | 2236 | return; |
2237 | 2237 | } |
2238 | 2238 | |
2239 | 2239 | //Fetch the item |
2240 | 2240 | $item_id = $cart_item['id']; |
2241 | - $item = new WPInv_Item( $item_id ); |
|
2241 | + $item = new WPInv_Item($item_id); |
|
2242 | 2242 | |
2243 | - if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) { |
|
2243 | + if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) { |
|
2244 | 2244 | return; |
2245 | 2245 | } |
2246 | 2246 | |
2247 | 2247 | //Fetch the dynamic pricing "strings" |
2248 | - $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) ); |
|
2249 | - $minimum_price_text = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) ); |
|
2250 | - $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) ); |
|
2248 | + $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing'))); |
|
2249 | + $minimum_price_text = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing'))); |
|
2250 | + $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing'))); |
|
2251 | 2251 | |
2252 | 2252 | //Display a "name_your_price" button |
2253 | 2253 | echo " — <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>"; |
@@ -2256,7 +2256,7 @@ discard block |
||
2256 | 2256 | echo '<div class="name-your-price-miniform">'; |
2257 | 2257 | |
2258 | 2258 | //Maybe display the recommended price |
2259 | - if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) { |
|
2259 | + if ($item->get_price() > 0 && !empty($suggested_price_text)) { |
|
2260 | 2260 | $suggested_price = $item->get_the_price(); |
2261 | 2261 | echo "<div>$suggested_price_text — $suggested_price</div>"; |
2262 | 2262 | } |
@@ -2264,198 +2264,198 @@ discard block |
||
2264 | 2264 | //Display the update price form |
2265 | 2265 | $symbol = wpinv_currency_symbol(); |
2266 | 2266 | $position = wpinv_currency_position(); |
2267 | - $minimum = esc_attr( $item->get_minimum_price() ); |
|
2268 | - $price = esc_attr( $cart_item['item_price'] ); |
|
2269 | - $update = esc_attr__( "Update", 'invoicing' ); |
|
2267 | + $minimum = esc_attr($item->get_minimum_price()); |
|
2268 | + $price = esc_attr($cart_item['item_price']); |
|
2269 | + $update = esc_attr__("Update", 'invoicing'); |
|
2270 | 2270 | |
2271 | 2271 | //Ensure it supports dynamic prici |
2272 | - if( $price < $minimum ) { |
|
2272 | + if ($price < $minimum) { |
|
2273 | 2273 | $price = $minimum; |
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | echo '<label>'; |
2277 | 2277 | echo $position != 'right' ? $symbol . ' ' : ''; |
2278 | 2278 | echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />"; |
2279 | - echo $position == 'right' ? ' ' . $symbol : '' ; |
|
2279 | + echo $position == 'right' ? ' ' . $symbol : ''; |
|
2280 | 2280 | echo "</label>"; |
2281 | 2281 | echo "<input type='hidden' value='$item_id' class='wpi-field-item' />"; |
2282 | 2282 | echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>"; |
2283 | 2283 | |
2284 | 2284 | //Maybe display the minimum price |
2285 | - if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) { |
|
2286 | - $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) ); |
|
2285 | + if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) { |
|
2286 | + $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price())); |
|
2287 | 2287 | echo "<div>$minimum_price_text — $minimum_price</div>"; |
2288 | 2288 | } |
2289 | 2289 | |
2290 | 2290 | echo "</div>"; |
2291 | 2291 | |
2292 | 2292 | } |
2293 | -add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 ); |
|
2293 | +add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2); |
|
2294 | 2294 | |
2295 | 2295 | function wpinv_oxygen_fix_conflict() { |
2296 | 2296 | global $ct_ignore_post_types; |
2297 | 2297 | |
2298 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
2298 | + if (!is_array($ct_ignore_post_types)) { |
|
2299 | 2299 | $ct_ignore_post_types = array(); |
2300 | 2300 | } |
2301 | 2301 | |
2302 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
2302 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
2303 | 2303 | |
2304 | - foreach ( $post_types as $post_type ) { |
|
2304 | + foreach ($post_types as $post_type) { |
|
2305 | 2305 | $ct_ignore_post_types[] = $post_type; |
2306 | 2306 | |
2307 | 2307 | // Ignore post type |
2308 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
2308 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
2309 | 2309 | } |
2310 | 2310 | |
2311 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
2312 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
2311 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
2312 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
2313 | 2313 | } |
2314 | 2314 | |
2315 | 2315 | /** |
2316 | 2316 | * Helper function to display a payment form on the frontend. |
2317 | 2317 | */ |
2318 | -function getpaid_display_payment_form( $form ) { |
|
2318 | +function getpaid_display_payment_form($form) { |
|
2319 | 2319 | global $invoicing; |
2320 | 2320 | |
2321 | 2321 | // Ensure that it is published. |
2322 | - if ( 'publish' != get_post_status( $form ) ) { |
|
2322 | + if ('publish' != get_post_status($form)) { |
|
2323 | 2323 | return aui()->alert( |
2324 | 2324 | array( |
2325 | 2325 | 'type' => 'warning', |
2326 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
2326 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
2327 | 2327 | ) |
2328 | 2328 | ); |
2329 | 2329 | } |
2330 | 2330 | |
2331 | 2331 | // Get the form. |
2332 | - $form = new GetPaid_Payment_Form( $form ); |
|
2333 | - $html = wpinv_get_template_html( 'payment-forms/form.php', compact( 'form' ) ); |
|
2334 | - return str_replace( 'sr-only', '', $html ); |
|
2332 | + $form = new GetPaid_Payment_Form($form); |
|
2333 | + $html = wpinv_get_template_html('payment-forms/form.php', compact('form')); |
|
2334 | + return str_replace('sr-only', '', $html); |
|
2335 | 2335 | |
2336 | 2336 | } |
2337 | 2337 | |
2338 | 2338 | /** |
2339 | 2339 | * Helper function to display a item payment form on the frontend. |
2340 | 2340 | */ |
2341 | -function getpaid_display_item_payment_form( $items ) { |
|
2341 | +function getpaid_display_item_payment_form($items) { |
|
2342 | 2342 | global $invoicing; |
2343 | 2343 | |
2344 | - foreach ( array_keys( $items ) as $id ) { |
|
2345 | - if ( 'publish' != get_post_status( $id ) ) { |
|
2346 | - unset( $items[ $id ] ); |
|
2344 | + foreach (array_keys($items) as $id) { |
|
2345 | + if ('publish' != get_post_status($id)) { |
|
2346 | + unset($items[$id]); |
|
2347 | 2347 | } |
2348 | 2348 | } |
2349 | 2349 | |
2350 | - if ( empty( $items ) ) { |
|
2350 | + if (empty($items)) { |
|
2351 | 2351 | return aui()->alert( |
2352 | 2352 | array( |
2353 | 2353 | 'type' => 'warning', |
2354 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
2354 | + 'content' => __('No published items found', 'invoicing'), |
|
2355 | 2355 | ) |
2356 | 2356 | ); |
2357 | 2357 | } |
2358 | 2358 | |
2359 | - $item_key = getpaid_convert_items_to_string( $items ); |
|
2359 | + $item_key = getpaid_convert_items_to_string($items); |
|
2360 | 2360 | |
2361 | 2361 | // Get the form elements and items. |
2362 | 2362 | $form = wpinv_get_default_payment_form(); |
2363 | - $elements = $invoicing->form_elements->get_form_elements( $form ); |
|
2364 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
2363 | + $elements = $invoicing->form_elements->get_form_elements($form); |
|
2364 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
2365 | 2365 | |
2366 | 2366 | ob_start(); |
2367 | 2367 | echo "<form class='wpinv_payment_form'>"; |
2368 | - do_action( 'wpinv_payment_form_top' ); |
|
2368 | + do_action('wpinv_payment_form_top'); |
|
2369 | 2369 | echo "<input type='hidden' name='form_id' value='$form'/>"; |
2370 | 2370 | echo "<input type='hidden' name='form_items' value='$item_key'/>"; |
2371 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
2372 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
2371 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
2372 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
2373 | 2373 | |
2374 | - foreach ( $elements as $element ) { |
|
2375 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form ); |
|
2376 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form ); |
|
2374 | + foreach ($elements as $element) { |
|
2375 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form); |
|
2376 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form); |
|
2377 | 2377 | } |
2378 | 2378 | |
2379 | 2379 | echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
2380 | - do_action( 'wpinv_payment_form_bottom' ); |
|
2380 | + do_action('wpinv_payment_form_bottom'); |
|
2381 | 2381 | echo '</form>'; |
2382 | 2382 | |
2383 | 2383 | $content = ob_get_clean(); |
2384 | - return str_replace( 'sr-only', '', $content ); |
|
2384 | + return str_replace('sr-only', '', $content); |
|
2385 | 2385 | } |
2386 | 2386 | |
2387 | 2387 | /** |
2388 | 2388 | * Helper function to display an invoice payment form on the frontend. |
2389 | 2389 | */ |
2390 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
2390 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
2391 | 2391 | global $invoicing; |
2392 | 2392 | |
2393 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
2393 | + $invoice = wpinv_get_invoice($invoice_id); |
|
2394 | 2394 | |
2395 | - if ( empty( $invoice ) ) { |
|
2395 | + if (empty($invoice)) { |
|
2396 | 2396 | return aui()->alert( |
2397 | 2397 | array( |
2398 | 2398 | 'type' => 'warning', |
2399 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
2399 | + 'content' => __('Invoice not found', 'invoicing'), |
|
2400 | 2400 | ) |
2401 | 2401 | ); |
2402 | 2402 | } |
2403 | 2403 | |
2404 | - if ( $invoice->is_paid() ) { |
|
2404 | + if ($invoice->is_paid()) { |
|
2405 | 2405 | return aui()->alert( |
2406 | 2406 | array( |
2407 | 2407 | 'type' => 'warning', |
2408 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
2408 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
2409 | 2409 | ) |
2410 | 2410 | ); |
2411 | 2411 | } |
2412 | 2412 | |
2413 | 2413 | // Get the form elements and items. |
2414 | - $form = wpinv_get_default_payment_form(); |
|
2415 | - $elements = $invoicing->form_elements->get_form_elements( $form ); |
|
2416 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
2414 | + $form = wpinv_get_default_payment_form(); |
|
2415 | + $elements = $invoicing->form_elements->get_form_elements($form); |
|
2416 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
2417 | 2417 | |
2418 | 2418 | ob_start(); |
2419 | 2419 | echo "<form class='wpinv_payment_form'>"; |
2420 | - do_action( 'wpinv_payment_form_top' ); |
|
2420 | + do_action('wpinv_payment_form_top'); |
|
2421 | 2421 | echo "<input type='hidden' name='form_id' value='$form'/>"; |
2422 | 2422 | echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>"; |
2423 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
2424 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
2423 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
2424 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
2425 | 2425 | |
2426 | - foreach ( $elements as $element ) { |
|
2427 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form ); |
|
2428 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form ); |
|
2426 | + foreach ($elements as $element) { |
|
2427 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form); |
|
2428 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form); |
|
2429 | 2429 | } |
2430 | 2430 | |
2431 | 2431 | echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
2432 | - do_action( 'wpinv_payment_form_bottom' ); |
|
2432 | + do_action('wpinv_payment_form_bottom'); |
|
2433 | 2433 | echo '</form>'; |
2434 | 2434 | |
2435 | 2435 | $content = ob_get_clean(); |
2436 | - return str_replace( 'sr-only', '', $content ); |
|
2436 | + return str_replace('sr-only', '', $content); |
|
2437 | 2437 | } |
2438 | 2438 | |
2439 | 2439 | /** |
2440 | 2440 | * Helper function to convert item string to array. |
2441 | 2441 | */ |
2442 | -function getpaid_convert_items_to_array( $items ) { |
|
2443 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
2442 | +function getpaid_convert_items_to_array($items) { |
|
2443 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
2444 | 2444 | $prepared = array(); |
2445 | 2445 | |
2446 | - foreach ( $items as $item ) { |
|
2447 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
2446 | + foreach ($items as $item) { |
|
2447 | + $data = array_map('trim', explode('|', $item)); |
|
2448 | 2448 | |
2449 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
2449 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
2450 | 2450 | continue; |
2451 | 2451 | } |
2452 | 2452 | |
2453 | 2453 | $quantity = 1; |
2454 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
2454 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
2455 | 2455 | $quantity = $data[1]; |
2456 | 2456 | } |
2457 | 2457 | |
2458 | - $prepared[ $data[0] ] = $quantity; |
|
2458 | + $prepared[$data[0]] = $quantity; |
|
2459 | 2459 | |
2460 | 2460 | } |
2461 | 2461 | |
@@ -2465,13 +2465,13 @@ discard block |
||
2465 | 2465 | /** |
2466 | 2466 | * Helper function to convert item array to string. |
2467 | 2467 | */ |
2468 | -function getpaid_convert_items_to_string( $items ) { |
|
2468 | +function getpaid_convert_items_to_string($items) { |
|
2469 | 2469 | $prepared = array(); |
2470 | 2470 | |
2471 | - foreach ( $items as $item => $quantity ) { |
|
2471 | + foreach ($items as $item => $quantity) { |
|
2472 | 2472 | $prepared[] = "$item|$quantity"; |
2473 | 2473 | } |
2474 | - return implode( ',', $prepared ); |
|
2474 | + return implode(',', $prepared); |
|
2475 | 2475 | } |
2476 | 2476 | |
2477 | 2477 | /** |
@@ -2479,22 +2479,22 @@ discard block |
||
2479 | 2479 | * |
2480 | 2480 | * Provide a label and one of $form, $items or $invoice. |
2481 | 2481 | */ |
2482 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
2483 | - $label = sanitize_text_field( $label ); |
|
2482 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
2483 | + $label = sanitize_text_field($label); |
|
2484 | 2484 | $nonce = wp_create_nonce('getpaid_ajax_form'); |
2485 | 2485 | |
2486 | - if ( ! empty( $form ) ) { |
|
2487 | - $form = esc_attr( $form ); |
|
2486 | + if (!empty($form)) { |
|
2487 | + $form = esc_attr($form); |
|
2488 | 2488 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
2489 | 2489 | } |
2490 | 2490 | |
2491 | - if ( ! empty( $items ) ) { |
|
2492 | - $items = esc_attr( $items ); |
|
2491 | + if (!empty($items)) { |
|
2492 | + $items = esc_attr($items); |
|
2493 | 2493 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
2494 | 2494 | } |
2495 | 2495 | |
2496 | - if ( ! empty( $invoice ) ) { |
|
2497 | - $invoice = esc_attr( $invoice ); |
|
2496 | + if (!empty($invoice)) { |
|
2497 | + $invoice = esc_attr($invoice); |
|
2498 | 2498 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; |
2499 | 2499 | } |
2500 | 2500 | |
@@ -2505,15 +2505,15 @@ discard block |
||
2505 | 2505 | * |
2506 | 2506 | * @param WPInv_Invoice $invoice |
2507 | 2507 | */ |
2508 | -function getpaid_the_invoice_description( $invoice ) { |
|
2509 | - if ( empty( $invoice->description ) ) { |
|
2508 | +function getpaid_the_invoice_description($invoice) { |
|
2509 | + if (empty($invoice->description)) { |
|
2510 | 2510 | return; |
2511 | 2511 | } |
2512 | 2512 | |
2513 | - $description = wp_kses_post( $invoice->description ); |
|
2513 | + $description = wp_kses_post($invoice->description); |
|
2514 | 2514 | echo "<div style='color: #616161; font-size: 90%; margin-bottom: 20px;'><em>$description</em></div>"; |
2515 | 2515 | } |
2516 | -add_action( 'wpinv_invoice_print_before_line_items', 'getpaid_the_invoice_description' ); |
|
2516 | +add_action('wpinv_invoice_print_before_line_items', 'getpaid_the_invoice_description'); |
|
2517 | 2517 | |
2518 | 2518 | /** |
2519 | 2519 | * Render element on a form. |
@@ -2521,38 +2521,38 @@ discard block |
||
2521 | 2521 | * @param array $element |
2522 | 2522 | * @param GetPaid_Payment_Form $form |
2523 | 2523 | */ |
2524 | -function getpaid_payment_form_element( $element, $form ) { |
|
2524 | +function getpaid_payment_form_element($element, $form) { |
|
2525 | 2525 | |
2526 | 2526 | // Set up the args. |
2527 | - $element_type = trim( $element['type'] ); |
|
2527 | + $element_type = trim($element['type']); |
|
2528 | 2528 | $element['form'] = $form; |
2529 | - extract( $element ); |
|
2529 | + extract($element); |
|
2530 | 2530 | |
2531 | 2531 | // Try to locate the appropriate template. |
2532 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
2532 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
2533 | 2533 | |
2534 | 2534 | // Abort if this is not our element. |
2535 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
2535 | + if (empty($located) || !file_exists($located)) { |
|
2536 | 2536 | return; |
2537 | 2537 | } |
2538 | 2538 | |
2539 | 2539 | // Generate the class and id of the element. |
2540 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
2541 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
2540 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
2541 | + $id = isset($id) ? $id : uniqid('gp'); |
|
2542 | 2542 | |
2543 | 2543 | // Echo the opening wrapper. |
2544 | 2544 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
2545 | 2545 | |
2546 | 2546 | // Fires before displaying a given element type's content. |
2547 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
2547 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
2548 | 2548 | |
2549 | 2549 | // Include the template for the element. |
2550 | 2550 | include $located; |
2551 | 2551 | |
2552 | 2552 | // Fires after displaying a given element type's content. |
2553 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
2553 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
2554 | 2554 | |
2555 | 2555 | // Echo the closing wrapper. |
2556 | 2556 | echo '</div>'; |
2557 | 2557 | } |
2558 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
2558 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |