@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | 'remove_discount' => false, |
77 | 77 | ); |
78 | 78 | |
79 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
80 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
79 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
80 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
81 | 81 | |
82 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
83 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
82 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
83 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $nopriv ) { |
|
87 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
86 | + if ($nopriv) { |
|
87 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
88 | 88 | |
89 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
89 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | public static function add_note() { |
95 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
95 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
96 | 96 | |
97 | - if ( !current_user_can( 'manage_options' ) ) { |
|
97 | + if (!current_user_can('manage_options')) { |
|
98 | 98 | die(-1); |
99 | 99 | } |
100 | 100 | |
101 | - $post_id = absint( $_POST['post_id'] ); |
|
102 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
103 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
101 | + $post_id = absint($_POST['post_id']); |
|
102 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
103 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
104 | 104 | |
105 | 105 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
106 | 106 | |
107 | - if ( $post_id > 0 ) { |
|
108 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
107 | + if ($post_id > 0) { |
|
108 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
109 | 109 | |
110 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
111 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
110 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
111 | + wpinv_get_invoice_note_line_item($note_id); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function delete_note() { |
119 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( !current_user_can( 'manage_options' ) ) { |
|
121 | + if (!current_user_can('manage_options')) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $note_id = (int)$_POST['note_id']; |
126 | 126 | |
127 | - if ( $note_id > 0 ) { |
|
128 | - wp_delete_comment( $note_id, true ); |
|
127 | + if ($note_id > 0) { |
|
128 | + wp_delete_comment($note_id, true); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | die(); |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function checkout() { |
141 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
142 | - define( 'WPINV_CHECKOUT', true ); |
|
141 | + if (!defined('WPINV_CHECKOUT')) { |
|
142 | + define('WPINV_CHECKOUT', true); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | wpinv_process_checkout(); |
@@ -148,53 +148,53 @@ discard block |
||
148 | 148 | |
149 | 149 | public static function add_invoice_item() { |
150 | 150 | global $wpi_userID, $wpinv_ip_address_country; |
151 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
152 | - if ( !current_user_can( 'manage_options' ) ) { |
|
151 | + check_ajax_referer('invoice-item', '_nonce'); |
|
152 | + if (!current_user_can('manage_options')) { |
|
153 | 153 | die(-1); |
154 | 154 | } |
155 | 155 | |
156 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
157 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
156 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
157 | + $invoice_id = absint($_POST['invoice_id']); |
|
158 | 158 | |
159 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
159 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
160 | 160 | die(); |
161 | 161 | } |
162 | 162 | |
163 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
164 | - if ( empty( $invoice ) ) { |
|
163 | + $invoice = wpinv_get_invoice($invoice_id); |
|
164 | + if (empty($invoice)) { |
|
165 | 165 | die(); |
166 | 166 | } |
167 | 167 | |
168 | - if ( $invoice->is_paid() ) { |
|
168 | + if ($invoice->is_paid()) { |
|
169 | 169 | die(); // Don't allow modify items for paid invoice. |
170 | 170 | } |
171 | 171 | |
172 | - if ( !empty( $_POST['user_id'] ) ) { |
|
173 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
172 | + if (!empty($_POST['user_id'])) { |
|
173 | + $wpi_userID = absint($_POST['user_id']); |
|
174 | 174 | } |
175 | 175 | |
176 | - $item = new WPInv_Item( $item_id ); |
|
177 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
176 | + $item = new WPInv_Item($item_id); |
|
177 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
178 | 178 | die(); |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Validate item before adding to invoice because recurring item must be paid individually. |
182 | - if ( !empty( $invoice->cart_details ) ) { |
|
182 | + if (!empty($invoice->cart_details)) { |
|
183 | 183 | $valid = true; |
184 | 184 | |
185 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
186 | - if ( $recurring_item != $item_id ) { |
|
185 | + if ($recurring_item = $invoice->get_recurring()) { |
|
186 | + if ($recurring_item != $item_id) { |
|
187 | 187 | $valid = false; |
188 | 188 | } |
189 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
189 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
190 | 190 | $valid = false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( !$valid ) { |
|
193 | + if (!$valid) { |
|
194 | 194 | $response = array(); |
195 | 195 | $response['success'] = false; |
196 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
197 | - wp_send_json( $response ); |
|
196 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
197 | + wp_send_json($response); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | |
203 | 203 | $data = array(); |
204 | 204 | $data['invoice_id'] = $invoice_id; |
205 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
205 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
206 | 206 | |
207 | - wpinv_set_checkout_session( $data ); |
|
207 | + wpinv_set_checkout_session($data); |
|
208 | 208 | |
209 | 209 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
210 | 210 | |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | 'fees' => array() |
220 | 220 | ); |
221 | 221 | |
222 | - $invoice->add_item( $item_id, $args ); |
|
222 | + $invoice->add_item($item_id, $args); |
|
223 | 223 | $invoice->save(); |
224 | 224 | |
225 | - if ( empty( $_POST['country'] ) ) { |
|
225 | + if (empty($_POST['country'])) { |
|
226 | 226 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
227 | 227 | } |
228 | - if ( empty( $_POST['state'] ) ) { |
|
228 | + if (empty($_POST['state'])) { |
|
229 | 229 | $_POST['state'] = $invoice->state; |
230 | 230 | } |
231 | 231 | |
232 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
233 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
232 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
233 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
234 | 234 | |
235 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
236 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
235 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
236 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
237 | 237 | |
238 | 238 | $wpinv_ip_address_country = $invoice->country; |
239 | 239 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | $response = array(); |
243 | 243 | $response['success'] = true; |
244 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
244 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
245 | 245 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
246 | 246 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
247 | 247 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -253,40 +253,40 @@ discard block |
||
253 | 253 | |
254 | 254 | wpinv_set_checkout_session($checkout_session); |
255 | 255 | |
256 | - wp_send_json( $response ); |
|
256 | + wp_send_json($response); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | public static function remove_invoice_item() { |
260 | 260 | global $wpi_userID, $wpinv_ip_address_country; |
261 | 261 | |
262 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
263 | - if ( !current_user_can( 'manage_options' ) ) { |
|
262 | + check_ajax_referer('invoice-item', '_nonce'); |
|
263 | + if (!current_user_can('manage_options')) { |
|
264 | 264 | die(-1); |
265 | 265 | } |
266 | 266 | |
267 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
268 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
269 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
267 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
268 | + $invoice_id = absint($_POST['invoice_id']); |
|
269 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
270 | 270 | |
271 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
271 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
272 | 272 | die(); |
273 | 273 | } |
274 | 274 | |
275 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
276 | - if ( empty( $invoice ) ) { |
|
275 | + $invoice = wpinv_get_invoice($invoice_id); |
|
276 | + if (empty($invoice)) { |
|
277 | 277 | die(); |
278 | 278 | } |
279 | 279 | |
280 | - if ( $invoice->is_paid() ) { |
|
280 | + if ($invoice->is_paid()) { |
|
281 | 281 | die(); // Don't allow modify items for paid invoice. |
282 | 282 | } |
283 | 283 | |
284 | - if ( !empty( $_POST['user_id'] ) ) { |
|
285 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
284 | + if (!empty($_POST['user_id'])) { |
|
285 | + $wpi_userID = absint($_POST['user_id']); |
|
286 | 286 | } |
287 | 287 | |
288 | - $item = new WPInv_Item( $item_id ); |
|
289 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
288 | + $item = new WPInv_Item($item_id); |
|
289 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
290 | 290 | die(); |
291 | 291 | } |
292 | 292 | |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | |
295 | 295 | $data = array(); |
296 | 296 | $data['invoice_id'] = $invoice_id; |
297 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
297 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
298 | 298 | |
299 | - wpinv_set_checkout_session( $data ); |
|
299 | + wpinv_set_checkout_session($data); |
|
300 | 300 | |
301 | 301 | $args = array( |
302 | 302 | 'id' => $item_id, |
@@ -304,21 +304,21 @@ discard block |
||
304 | 304 | 'cart_index' => $cart_index |
305 | 305 | ); |
306 | 306 | |
307 | - $invoice->remove_item( $item_id, $args ); |
|
307 | + $invoice->remove_item($item_id, $args); |
|
308 | 308 | $invoice->save(); |
309 | 309 | |
310 | - if ( empty( $_POST['country'] ) ) { |
|
310 | + if (empty($_POST['country'])) { |
|
311 | 311 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
312 | 312 | } |
313 | - if ( empty( $_POST['state'] ) ) { |
|
313 | + if (empty($_POST['state'])) { |
|
314 | 314 | $_POST['state'] = $invoice->state; |
315 | 315 | } |
316 | 316 | |
317 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
318 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
317 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
318 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
319 | 319 | |
320 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
321 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
320 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
321 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
322 | 322 | |
323 | 323 | $wpinv_ip_address_country = $invoice->country; |
324 | 324 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | |
327 | 327 | $response = array(); |
328 | 328 | $response['success'] = true; |
329 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
329 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
330 | 330 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
331 | 331 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
332 | 332 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -338,40 +338,40 @@ discard block |
||
338 | 338 | |
339 | 339 | wpinv_set_checkout_session($checkout_session); |
340 | 340 | |
341 | - wp_send_json( $response ); |
|
341 | + wp_send_json($response); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | public static function create_invoice_item() { |
345 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
346 | - if ( !current_user_can( 'manage_options' ) ) { |
|
345 | + check_ajax_referer('invoice-item', '_nonce'); |
|
346 | + if (!current_user_can('manage_options')) { |
|
347 | 347 | die(-1); |
348 | 348 | } |
349 | 349 | |
350 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
350 | + $invoice_id = absint($_POST['invoice_id']); |
|
351 | 351 | |
352 | 352 | // Find the item |
353 | - if ( !is_numeric( $invoice_id ) ) { |
|
353 | + if (!is_numeric($invoice_id)) { |
|
354 | 354 | die(); |
355 | 355 | } |
356 | 356 | |
357 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
358 | - if ( empty( $invoice ) ) { |
|
357 | + $invoice = wpinv_get_invoice($invoice_id); |
|
358 | + if (empty($invoice)) { |
|
359 | 359 | die(); |
360 | 360 | } |
361 | 361 | |
362 | 362 | // Validate item before adding to invoice because recurring item must be paid individually. |
363 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
363 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
364 | 364 | $response = array(); |
365 | 365 | $response['success'] = false; |
366 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
367 | - wp_send_json( $response ); |
|
366 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
367 | + wp_send_json($response); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | $save_item = $_POST['_wpinv_quick']; |
371 | 371 | |
372 | 372 | $meta = array(); |
373 | 373 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
374 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
374 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
375 | 375 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
376 | 376 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
377 | 377 | |
@@ -381,9 +381,9 @@ discard block |
||
381 | 381 | $data['meta'] = $meta; |
382 | 382 | |
383 | 383 | $item = new WPInv_Item(); |
384 | - $item->create( $data ); |
|
384 | + $item->create($data); |
|
385 | 385 | |
386 | - if ( !empty( $item ) ) { |
|
386 | + if (!empty($item)) { |
|
387 | 387 | $_POST['item_id'] = $item->ID; |
388 | 388 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
389 | 389 | |
@@ -393,15 +393,15 @@ discard block |
||
393 | 393 | } |
394 | 394 | |
395 | 395 | public static function get_billing_details() { |
396 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
396 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
397 | 397 | |
398 | - if ( !current_user_can( 'manage_options' ) ) { |
|
398 | + if (!current_user_can('manage_options')) { |
|
399 | 399 | die(-1); |
400 | 400 | } |
401 | 401 | |
402 | 402 | $user_id = (int)$_POST['user_id']; |
403 | 403 | $billing_details = wpinv_get_user_address($user_id); |
404 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
404 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
405 | 405 | |
406 | 406 | if (isset($billing_details['user_id'])) { |
407 | 407 | unset($billing_details['user_id']); |
@@ -415,20 +415,20 @@ discard block |
||
415 | 415 | $response['success'] = true; |
416 | 416 | $response['data']['billing_details'] = $billing_details; |
417 | 417 | |
418 | - wp_send_json( $response ); |
|
418 | + wp_send_json($response); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | public static function admin_recalculate_totals() { |
422 | 422 | global $wpi_userID, $wpinv_ip_address_country; |
423 | 423 | |
424 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
425 | - if ( !current_user_can( 'manage_options' ) ) { |
|
424 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
425 | + if (!current_user_can('manage_options')) { |
|
426 | 426 | die(-1); |
427 | 427 | } |
428 | 428 | |
429 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
430 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
431 | - if ( empty( $invoice ) ) { |
|
429 | + $invoice_id = absint($_POST['invoice_id']); |
|
430 | + $invoice = wpinv_get_invoice($invoice_id); |
|
431 | + if (empty($invoice)) { |
|
432 | 432 | die(); |
433 | 433 | } |
434 | 434 | |
@@ -436,23 +436,23 @@ discard block |
||
436 | 436 | |
437 | 437 | $data = array(); |
438 | 438 | $data['invoice_id'] = $invoice_id; |
439 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
439 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
440 | 440 | |
441 | - wpinv_set_checkout_session( $data ); |
|
441 | + wpinv_set_checkout_session($data); |
|
442 | 442 | |
443 | - if ( !empty( $_POST['user_id'] ) ) { |
|
444 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
443 | + if (!empty($_POST['user_id'])) { |
|
444 | + $wpi_userID = absint($_POST['user_id']); |
|
445 | 445 | } |
446 | 446 | |
447 | - if ( empty( $_POST['country'] ) ) { |
|
447 | + if (empty($_POST['country'])) { |
|
448 | 448 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
449 | 449 | } |
450 | 450 | |
451 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
452 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
453 | - if ( isset( $_POST['state'] ) ) { |
|
454 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
455 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
451 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
452 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
453 | + if (isset($_POST['state'])) { |
|
454 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
455 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | $wpinv_ip_address_country = $invoice->country; |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | |
462 | 462 | $response = array(); |
463 | 463 | $response['success'] = true; |
464 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
464 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
465 | 465 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
466 | 466 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
467 | 467 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -473,25 +473,25 @@ discard block |
||
473 | 473 | |
474 | 474 | wpinv_set_checkout_session($checkout_session); |
475 | 475 | |
476 | - wp_send_json( $response ); |
|
476 | + wp_send_json($response); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | public static function admin_apply_discount() { |
480 | 480 | global $wpi_userID; |
481 | 481 | |
482 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
483 | - if ( !current_user_can( 'manage_options' ) ) { |
|
482 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
483 | + if (!current_user_can('manage_options')) { |
|
484 | 484 | die(-1); |
485 | 485 | } |
486 | 486 | |
487 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
488 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
489 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
487 | + $invoice_id = absint($_POST['invoice_id']); |
|
488 | + $discount_code = sanitize_text_field($_POST['code']); |
|
489 | + if (empty($invoice_id) || empty($discount_code)) { |
|
490 | 490 | die(); |
491 | 491 | } |
492 | 492 | |
493 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
494 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
493 | + $invoice = wpinv_get_invoice($invoice_id); |
|
494 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
495 | 495 | die(); |
496 | 496 | } |
497 | 497 | |
@@ -499,49 +499,49 @@ discard block |
||
499 | 499 | |
500 | 500 | $data = array(); |
501 | 501 | $data['invoice_id'] = $invoice_id; |
502 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
502 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
503 | 503 | |
504 | - wpinv_set_checkout_session( $data ); |
|
504 | + wpinv_set_checkout_session($data); |
|
505 | 505 | |
506 | 506 | $response = array(); |
507 | 507 | $response['success'] = false; |
508 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
508 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
509 | 509 | $response['data']['code'] = $discount_code; |
510 | 510 | |
511 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
512 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
511 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
512 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
513 | 513 | |
514 | 514 | $response['success'] = true; |
515 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
516 | - } else { |
|
515 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
516 | + } else { |
|
517 | 517 | $errors = wpinv_get_errors(); |
518 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
518 | + if (!empty($errors['wpinv-discount-error'])) { |
|
519 | 519 | $response['msg'] = $errors['wpinv-discount-error']; |
520 | 520 | } |
521 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
521 | + wpinv_unset_error('wpinv-discount-error'); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | wpinv_set_checkout_session($checkout_session); |
525 | 525 | |
526 | - wp_send_json( $response ); |
|
526 | + wp_send_json($response); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | public static function admin_remove_discount() { |
530 | 530 | global $wpi_userID; |
531 | 531 | |
532 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
533 | - if ( !current_user_can( 'manage_options' ) ) { |
|
532 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
533 | + if (!current_user_can('manage_options')) { |
|
534 | 534 | die(-1); |
535 | 535 | } |
536 | 536 | |
537 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
538 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
539 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
537 | + $invoice_id = absint($_POST['invoice_id']); |
|
538 | + $discount_code = sanitize_text_field($_POST['code']); |
|
539 | + if (empty($invoice_id) || empty($discount_code)) { |
|
540 | 540 | die(); |
541 | 541 | } |
542 | 542 | |
543 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
544 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
543 | + $invoice = wpinv_get_invoice($invoice_id); |
|
544 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
545 | 545 | die(); |
546 | 546 | } |
547 | 547 | |
@@ -549,38 +549,38 @@ discard block |
||
549 | 549 | |
550 | 550 | $data = array(); |
551 | 551 | $data['invoice_id'] = $invoice_id; |
552 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
552 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
553 | 553 | |
554 | - wpinv_set_checkout_session( $data ); |
|
554 | + wpinv_set_checkout_session($data); |
|
555 | 555 | |
556 | 556 | $response = array(); |
557 | 557 | $response['success'] = false; |
558 | 558 | $response['msg'] = NULL; |
559 | 559 | |
560 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
560 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
561 | 561 | $response['success'] = true; |
562 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
562 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
563 | 563 | |
564 | 564 | wpinv_set_checkout_session($checkout_session); |
565 | 565 | |
566 | - wp_send_json( $response ); |
|
566 | + wp_send_json($response); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | public static function check_email() { |
570 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
571 | - if ( !current_user_can( 'manage_options' ) ) { |
|
570 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
571 | + if (!current_user_can('manage_options')) { |
|
572 | 572 | die(-1); |
573 | 573 | } |
574 | 574 | |
575 | - $email = sanitize_text_field( $_POST['email'] ); |
|
575 | + $email = sanitize_text_field($_POST['email']); |
|
576 | 576 | |
577 | 577 | $response = array(); |
578 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
578 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
579 | 579 | $user_id = $user_data->ID; |
580 | 580 | $user_login = $user_data->user_login; |
581 | 581 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
582 | 582 | $billing_details = wpinv_get_user_address($user_id); |
583 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
583 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
584 | 584 | |
585 | 585 | if (isset($billing_details['user_id'])) { |
586 | 586 | unset($billing_details['user_id']); |
@@ -596,31 +596,31 @@ discard block |
||
596 | 596 | $response['data']['billing_details'] = $billing_details; |
597 | 597 | } |
598 | 598 | |
599 | - wp_send_json( $response ); |
|
599 | + wp_send_json($response); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | public static function run_tool() { |
603 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
604 | - if ( !current_user_can( 'manage_options' ) ) { |
|
603 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
604 | + if (!current_user_can('manage_options')) { |
|
605 | 605 | die(-1); |
606 | 606 | } |
607 | 607 | |
608 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
608 | + $tool = sanitize_text_field($_POST['tool']); |
|
609 | 609 | |
610 | - do_action( 'wpinv_run_tool' ); |
|
610 | + do_action('wpinv_run_tool'); |
|
611 | 611 | |
612 | - if ( !empty( $tool ) ) { |
|
613 | - do_action( 'wpinv_tool_' . $tool ); |
|
612 | + if (!empty($tool)) { |
|
613 | + do_action('wpinv_tool_' . $tool); |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 | |
617 | 617 | public static function apply_discount() { |
618 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
618 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
619 | 619 | |
620 | 620 | $response = array(); |
621 | 621 | |
622 | - if ( isset( $_POST['code'] ) ) { |
|
623 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
622 | + if (isset($_POST['code'])) { |
|
623 | + $discount_code = sanitize_text_field($_POST['code']); |
|
624 | 624 | |
625 | 625 | $response['success'] = false; |
626 | 626 | $response['msg'] = ''; |
@@ -628,14 +628,14 @@ discard block |
||
628 | 628 | |
629 | 629 | $user = is_user_logged_in() ? get_current_user_id() : ''; |
630 | 630 | |
631 | - if ( wpinv_is_discount_valid( $discount_code, $user ) ) { |
|
632 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
633 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
634 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
635 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
636 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
631 | + if (wpinv_is_discount_valid($discount_code, $user)) { |
|
632 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
633 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
634 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
635 | + $total = wpinv_get_cart_total(null, $discounts); |
|
636 | + $cart_totals = wpinv_recalculate_tax(true); |
|
637 | 637 | |
638 | - if ( !empty( $cart_totals ) ) { |
|
638 | + if (!empty($cart_totals)) { |
|
639 | 639 | $response['success'] = true; |
640 | 640 | $response['data'] = $cart_totals; |
641 | 641 | $response['data']['code'] = $discount_code; |
@@ -644,29 +644,29 @@ discard block |
||
644 | 644 | } |
645 | 645 | } else { |
646 | 646 | $errors = wpinv_get_errors(); |
647 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
648 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
647 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
648 | + wpinv_unset_error('wpinv-discount-error'); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | // Allow for custom discount code handling |
652 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
652 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
653 | 653 | } |
654 | 654 | |
655 | - wp_send_json( $response ); |
|
655 | + wp_send_json($response); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | public static function remove_discount() { |
659 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
659 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
660 | 660 | |
661 | 661 | $response = array(); |
662 | 662 | |
663 | - if ( isset( $_POST['code'] ) ) { |
|
664 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
665 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
666 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
667 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
663 | + if (isset($_POST['code'])) { |
|
664 | + $discount_code = sanitize_text_field($_POST['code']); |
|
665 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
666 | + $total = wpinv_get_cart_total(null, $discounts); |
|
667 | + $cart_totals = wpinv_recalculate_tax(true); |
|
668 | 668 | |
669 | - if ( !empty( $cart_totals ) ) { |
|
669 | + if (!empty($cart_totals)) { |
|
670 | 670 | $response['success'] = true; |
671 | 671 | $response['data'] = $cart_totals; |
672 | 672 | $response['data']['code'] = $discount_code; |
@@ -675,10 +675,10 @@ discard block |
||
675 | 675 | } |
676 | 676 | |
677 | 677 | // Allow for custom discount code handling |
678 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
678 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
679 | 679 | } |
680 | 680 | |
681 | - wp_send_json( $response ); |
|
681 | + wp_send_json($response); |
|
682 | 682 | } |
683 | 683 | } |
684 | 684 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | if ( !( $user_id = get_current_user_id() ) ) { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | <tbody> |
32 | 32 | <?php foreach ( $user_invoices->invoices as $invoice ) { |
33 | - ?> |
|
33 | + ?> |
|
34 | 34 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
35 | 35 | <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
36 | 36 | <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>"> |
@@ -53,31 +53,31 @@ discard block |
||
53 | 53 | |
54 | 54 | <?php elseif ( 'invoice-actions' === $column_id ) : ?> |
55 | 55 | <?php |
56 | - $actions = array( |
|
57 | - 'pay' => array( |
|
58 | - 'url' => $invoice->get_checkout_payment_url(), |
|
59 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
56 | + $actions = array( |
|
57 | + 'pay' => array( |
|
58 | + 'url' => $invoice->get_checkout_payment_url(), |
|
59 | + 'name' => __( 'Pay Now', 'invoicing' ), |
|
60 | 60 | 'class' => 'btn-success' |
61 | - ), |
|
61 | + ), |
|
62 | 62 | 'print' => array( |
63 | - 'url' => $invoice->get_view_url(), |
|
64 | - 'name' => __( 'Print', 'invoicing' ), |
|
63 | + 'url' => $invoice->get_view_url(), |
|
64 | + 'name' => __( 'Print', 'invoicing' ), |
|
65 | 65 | 'class' => 'btn-primary', |
66 | 66 | 'attrs' => 'target="_blank"' |
67 | - ) |
|
68 | - ); |
|
67 | + ) |
|
68 | + ); |
|
69 | 69 | |
70 | - if ( ! $invoice->needs_payment() ) { |
|
71 | - unset( $actions['pay'] ); |
|
72 | - } |
|
70 | + if ( ! $invoice->needs_payment() ) { |
|
71 | + unset( $actions['pay'] ); |
|
72 | + } |
|
73 | 73 | |
74 | - if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
75 | - foreach ( $actions as $key => $action ) { |
|
76 | - $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
74 | + if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
75 | + foreach ( $actions as $key => $action ) { |
|
76 | + $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
77 | 77 | echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
78 | - } |
|
79 | - } |
|
80 | - ?> |
|
78 | + } |
|
79 | + } |
|
80 | + ?> |
|
81 | 81 | <?php endif; ?> |
82 | 82 | </td> |
83 | 83 | <?php endforeach; ?> |
@@ -91,26 +91,26 @@ discard block |
||
91 | 91 | <?php if ( 1 < $user_invoices->max_num_pages ) : ?> |
92 | 92 | <div class="invoicing-Pagination"> |
93 | 93 | <?php |
94 | - $big = 999999; |
|
95 | - $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : ''; |
|
96 | - |
|
97 | - if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) |
|
98 | - $current_page = get_query_var('paged'); |
|
99 | - elseif (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) |
|
100 | - $current_page = get_query_var('page'); |
|
101 | - else |
|
102 | - $current_page = 1; |
|
103 | - |
|
104 | - echo paginate_links( array( |
|
105 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
106 | - 'format' => '?paged=%#%', |
|
107 | - 'current' => max( 1, $current_page ), |
|
108 | - 'total' => $user_invoices->max_num_pages, |
|
109 | - 'add_args' => array( |
|
110 | - 'wpinv-cpt' => 'wpi_invoice', |
|
111 | - ) |
|
112 | - ) ); |
|
113 | - ?> |
|
94 | + $big = 999999; |
|
95 | + $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : ''; |
|
96 | + |
|
97 | + if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) |
|
98 | + $current_page = get_query_var('paged'); |
|
99 | + elseif (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) |
|
100 | + $current_page = get_query_var('page'); |
|
101 | + else |
|
102 | + $current_page = 1; |
|
103 | + |
|
104 | + echo paginate_links( array( |
|
105 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
106 | + 'format' => '?paged=%#%', |
|
107 | + 'current' => max( 1, $current_page ), |
|
108 | + 'total' => $user_invoices->max_num_pages, |
|
109 | + 'add_args' => array( |
|
110 | + 'wpinv-cpt' => 'wpi_invoice', |
|
111 | + ) |
|
112 | + ) ); |
|
113 | + ?> |
|
114 | 114 | </div> |
115 | 115 | <?php endif; ?> |
116 | 116 |
@@ -1,80 +1,80 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -if ( !( $user_id = get_current_user_id() ) ) { |
|
6 | +if (!($user_id = get_current_user_id())) { |
|
7 | 7 | ?> |
8 | - <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div> |
|
8 | + <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div> |
|
9 | 9 | <?php |
10 | 10 | return; |
11 | 11 | } |
12 | 12 | |
13 | 13 | global $current_page; |
14 | -$current_page = empty( $current_page ) ? 1 : absint( $current_page ); |
|
15 | -$query = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) ); |
|
16 | -$user_invoices = wpinv_get_invoices( $query ); |
|
14 | +$current_page = empty($current_page) ? 1 : absint($current_page); |
|
15 | +$query = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true)); |
|
16 | +$user_invoices = wpinv_get_invoices($query); |
|
17 | 17 | $has_invoices = 0 < $user_invoices->total; |
18 | 18 | |
19 | -do_action( 'wpinv_before_user_invoices', $has_invoices ); ?> |
|
19 | +do_action('wpinv_before_user_invoices', $has_invoices); ?> |
|
20 | 20 | |
21 | -<?php if ( $has_invoices ) { ?> |
|
21 | +<?php if ($has_invoices) { ?> |
|
22 | 22 | <table class="table table-bordered table-hover wpi-user-invoices"> |
23 | 23 | <thead> |
24 | 24 | <tr> |
25 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
26 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th> |
|
25 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
26 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th> |
|
27 | 27 | <?php endforeach; ?> |
28 | 28 | </tr> |
29 | 29 | </thead> |
30 | 30 | |
31 | 31 | <tbody> |
32 | - <?php foreach ( $user_invoices->invoices as $invoice ) { |
|
32 | + <?php foreach ($user_invoices->invoices as $invoice) { |
|
33 | 33 | ?> |
34 | 34 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
35 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
36 | - <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>"> |
|
37 | - <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?> |
|
38 | - <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?> |
|
39 | - |
|
40 | - <?php elseif ( 'invoice-number' === $column_id ) : ?> |
|
41 | - <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>"> |
|
42 | - <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?> |
|
35 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
36 | + <td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>"> |
|
37 | + <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?> |
|
38 | + <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?> |
|
39 | + |
|
40 | + <?php elseif ('invoice-number' === $column_id) : ?> |
|
41 | + <a href="<?php echo esc_url($invoice->get_view_url()); ?>"> |
|
42 | + <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?> |
|
43 | 43 | </a> |
44 | 44 | |
45 | - <?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?> |
|
46 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
45 | + <?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?> |
|
46 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
47 | 47 | |
48 | - <?php elseif ( 'invoice-status' === $column_id ) : ?> |
|
49 | - <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?> |
|
48 | + <?php elseif ('invoice-status' === $column_id) : ?> |
|
49 | + <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?> |
|
50 | 50 | |
51 | - <?php elseif ( 'invoice-total' === $column_id ) : ?> |
|
52 | - <?php echo $invoice->get_total( true ); ?> |
|
51 | + <?php elseif ('invoice-total' === $column_id) : ?> |
|
52 | + <?php echo $invoice->get_total(true); ?> |
|
53 | 53 | |
54 | - <?php elseif ( 'invoice-actions' === $column_id ) : ?> |
|
54 | + <?php elseif ('invoice-actions' === $column_id) : ?> |
|
55 | 55 | <?php |
56 | 56 | $actions = array( |
57 | 57 | 'pay' => array( |
58 | 58 | 'url' => $invoice->get_checkout_payment_url(), |
59 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
59 | + 'name' => __('Pay Now', 'invoicing'), |
|
60 | 60 | 'class' => 'btn-success' |
61 | 61 | ), |
62 | 62 | 'print' => array( |
63 | 63 | 'url' => $invoice->get_view_url(), |
64 | - 'name' => __( 'Print', 'invoicing' ), |
|
64 | + 'name' => __('Print', 'invoicing'), |
|
65 | 65 | 'class' => 'btn-primary', |
66 | 66 | 'attrs' => 'target="_blank"' |
67 | 67 | ) |
68 | 68 | ); |
69 | 69 | |
70 | - if ( ! $invoice->needs_payment() ) { |
|
71 | - unset( $actions['pay'] ); |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | + unset($actions['pay']); |
|
72 | 72 | } |
73 | 73 | |
74 | - if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
75 | - foreach ( $actions as $key => $action ) { |
|
74 | + if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) { |
|
75 | + foreach ($actions as $key => $action) { |
|
76 | 76 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
77 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
77 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | ?> |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | </tbody> |
87 | 87 | </table> |
88 | 88 | |
89 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
89 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
90 | 90 | |
91 | - <?php if ( 1 < $user_invoices->max_num_pages ) : ?> |
|
91 | + <?php if (1 < $user_invoices->max_num_pages) : ?> |
|
92 | 92 | <div class="invoicing-Pagination"> |
93 | 93 | <?php |
94 | 94 | $big = 999999; |
@@ -101,23 +101,23 @@ discard block |
||
101 | 101 | else |
102 | 102 | $current_page = 1; |
103 | 103 | |
104 | - echo paginate_links( array( |
|
105 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
104 | + echo paginate_links(array( |
|
105 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
106 | 106 | 'format' => '?paged=%#%', |
107 | - 'current' => max( 1, $current_page ), |
|
107 | + 'current' => max(1, $current_page), |
|
108 | 108 | 'total' => $user_invoices->max_num_pages, |
109 | 109 | 'add_args' => array( |
110 | 110 | 'wpinv-cpt' => 'wpi_invoice', |
111 | 111 | ) |
112 | - ) ); |
|
112 | + )); |
|
113 | 113 | ?> |
114 | 114 | </div> |
115 | 115 | <?php endif; ?> |
116 | 116 | |
117 | 117 | <?php } else { ?> |
118 | 118 | <div class="wpinv-empty alert-info"> |
119 | - <?php _e( 'No invoice has been made yet.', 'invoicing' ); ?> |
|
119 | + <?php _e('No invoice has been made yet.', 'invoicing'); ?> |
|
120 | 120 | </div> |
121 | 121 | <?php } ?> |
122 | 122 | |
123 | -<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?> |
|
123 | +<?php do_action('wpinv_after_user_invoices', $has_invoices); ?> |
@@ -94,12 +94,13 @@ |
||
94 | 94 | $big = 999999; |
95 | 95 | $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : ''; |
96 | 96 | |
97 | - if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) |
|
98 | - $current_page = get_query_var('paged'); |
|
99 | - elseif (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) |
|
100 | - $current_page = get_query_var('page'); |
|
101 | - else |
|
102 | - $current_page = 1; |
|
97 | + if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) { |
|
98 | + $current_page = get_query_var('paged'); |
|
99 | + } elseif (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) { |
|
100 | + $current_page = get_query_var('page'); |
|
101 | + } else { |
|
102 | + $current_page = 1; |
|
103 | + } |
|
103 | 104 | |
104 | 105 | echo paginate_links( array( |
105 | 106 | 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
@@ -7,109 +7,109 @@ 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', 'invoicing/' ); |
|
22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
26 | 26 | global $pagenow, $typenow; |
27 | 27 | |
28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
29 | 29 | $classes[] = 'wpi-gd-package'; |
30 | 30 | } |
31 | 31 | return $classes; |
32 | 32 | } |
33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
34 | 34 | |
35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
36 | - if ( empty( $invoice ) ) { |
|
35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
36 | + if (empty($invoice)) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | ?> |
40 | 40 | <div class="row wpinv-top-bar no-print"> |
41 | 41 | <div class="container"> |
42 | 42 | <div class="col-xs-6"> |
43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
44 | 44 | </div> |
45 | 45 | <div class="col-xs-6 text-right"> |
46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | <?php |
51 | 51 | } |
52 | 52 | |
53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
54 | - if ( empty( $invoice ) ) { |
|
53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
54 | + if (empty($invoice)) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if($invoice->post_type == 'wpi_invoice'){ |
|
58 | + if ($invoice->post_type == 'wpi_invoice') { |
|
59 | 59 | |
60 | 60 | $user_id = (int)$invoice->get_user_id(); |
61 | 61 | $current_user_id = (int)get_current_user_id(); |
62 | 62 | |
63 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
63 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
64 | 64 | ?> |
65 | - <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> |
|
65 | + <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> |
|
66 | 66 | <?php |
67 | 67 | } |
68 | 68 | } |
69 | 69 | do_action('wpinv_invoice_display_left_actions', $invoice); |
70 | 70 | } |
71 | 71 | |
72 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
72 | +function wpinv_invoice_display_right_actions($invoice) { |
|
73 | + if (empty($invoice)) return; //Exit if invoice is not set. |
|
74 | 74 | |
75 | - if($invoice->post_type == 'wpi_invoice'){ |
|
75 | + if ($invoice->post_type == 'wpi_invoice') { |
|
76 | 76 | $user_id = (int)$invoice->get_user_id(); |
77 | 77 | $current_user_id = (int)get_current_user_id(); |
78 | 78 | |
79 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
79 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
80 | 80 | ?> |
81 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
82 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
81 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
82 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
83 | 83 | <?php } |
84 | 84 | } |
85 | 85 | do_action('wpinv_invoice_display_right_actions', $invoice); |
86 | 86 | } |
87 | 87 | |
88 | -function wpinv_before_invoice_content( $content ) { |
|
88 | +function wpinv_before_invoice_content($content) { |
|
89 | 89 | global $post; |
90 | 90 | |
91 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
91 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
92 | 92 | ob_start(); |
93 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
93 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
94 | 94 | $content = ob_get_clean() . $content; |
95 | 95 | } |
96 | 96 | |
97 | 97 | return $content; |
98 | 98 | } |
99 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
99 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
100 | 100 | |
101 | -function wpinv_after_invoice_content( $content ) { |
|
101 | +function wpinv_after_invoice_content($content) { |
|
102 | 102 | global $post; |
103 | 103 | |
104 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
104 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
105 | 105 | ob_start(); |
106 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
106 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
107 | 107 | $content .= ob_get_clean(); |
108 | 108 | } |
109 | 109 | |
110 | 110 | return $content; |
111 | 111 | } |
112 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
112 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_templates_dir() { |
115 | 115 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -119,105 +119,105 @@ discard block |
||
119 | 119 | return WPINV_PLUGIN_URL . 'templates'; |
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
123 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
124 | - extract( $args ); |
|
122 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
123 | + if (!empty($args) && is_array($args)) { |
|
124 | + extract($args); |
|
125 | 125 | } |
126 | 126 | |
127 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
127 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
128 | 128 | // Allow 3rd party plugin filter template file from their plugin. |
129 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
129 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
130 | 130 | |
131 | - if ( ! file_exists( $located ) ) { |
|
132 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
131 | + if (!file_exists($located)) { |
|
132 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
136 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
137 | 137 | |
138 | - include( $located ); |
|
138 | + include($located); |
|
139 | 139 | |
140 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
140 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
141 | 141 | } |
142 | 142 | |
143 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
144 | 144 | ob_start(); |
145 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
145 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
146 | 146 | return ob_get_clean(); |
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
150 | - if ( ! $template_path ) { |
|
149 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
150 | + if (!$template_path) { |
|
151 | 151 | $template_path = wpinv_template_path(); |
152 | 152 | } |
153 | 153 | |
154 | - if ( ! $default_path ) { |
|
154 | + if (!$default_path) { |
|
155 | 155 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Look within passed path within the theme - this is priority. |
159 | 159 | $template = locate_template( |
160 | 160 | array( |
161 | - trailingslashit( $template_path ) . $template_name, |
|
161 | + trailingslashit($template_path) . $template_name, |
|
162 | 162 | $template_name |
163 | 163 | ) |
164 | 164 | ); |
165 | 165 | |
166 | 166 | // Get default templates/ |
167 | - if ( !$template && $default_path ) { |
|
168 | - $template = trailingslashit( $default_path ) . $template_name; |
|
167 | + if (!$template && $default_path) { |
|
168 | + $template = trailingslashit($default_path) . $template_name; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Return what we found. |
172 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
172 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
173 | 173 | } |
174 | 174 | |
175 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
176 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
175 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
176 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
177 | 177 | |
178 | 178 | // Setup possible parts |
179 | 179 | $templates = array(); |
180 | - if ( isset( $name ) ) |
|
180 | + if (isset($name)) |
|
181 | 181 | $templates[] = $slug . '-' . $name . '.php'; |
182 | 182 | $templates[] = $slug . '.php'; |
183 | 183 | |
184 | 184 | // Allow template parts to be filtered |
185 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
185 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
186 | 186 | |
187 | 187 | // Return the part that is found |
188 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
188 | + return wpinv_locate_tmpl($templates, $load, false); |
|
189 | 189 | } |
190 | 190 | |
191 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
191 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
192 | 192 | // No file found yet |
193 | 193 | $located = false; |
194 | 194 | |
195 | 195 | // Try to find a template file |
196 | - foreach ( (array)$template_names as $template_name ) { |
|
196 | + foreach ((array)$template_names as $template_name) { |
|
197 | 197 | |
198 | 198 | // Continue if template is empty |
199 | - if ( empty( $template_name ) ) |
|
199 | + if (empty($template_name)) |
|
200 | 200 | continue; |
201 | 201 | |
202 | 202 | // Trim off any slashes from the template name |
203 | - $template_name = ltrim( $template_name, '/' ); |
|
203 | + $template_name = ltrim($template_name, '/'); |
|
204 | 204 | |
205 | 205 | // try locating this template file by looping through the template paths |
206 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
206 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
207 | 207 | |
208 | - if( file_exists( $template_path . $template_name ) ) { |
|
208 | + if (file_exists($template_path . $template_name)) { |
|
209 | 209 | $located = $template_path . $template_name; |
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if( !empty( $located ) ) { |
|
214 | + if (!empty($located)) { |
|
215 | 215 | break; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
220 | - load_template( $located, $require_once ); |
|
219 | + if ((true == $load) && !empty($located)) |
|
220 | + load_template($located, $require_once); |
|
221 | 221 | |
222 | 222 | return $located; |
223 | 223 | } |
@@ -226,143 +226,143 @@ discard block |
||
226 | 226 | $template_dir = wpinv_get_theme_template_dir_name(); |
227 | 227 | |
228 | 228 | $file_paths = array( |
229 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
230 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
229 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
230 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
231 | 231 | 100 => wpinv_get_templates_dir() |
232 | 232 | ); |
233 | 233 | |
234 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
234 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
235 | 235 | |
236 | 236 | // sort the file paths based on priority |
237 | - ksort( $file_paths, SORT_NUMERIC ); |
|
237 | + ksort($file_paths, SORT_NUMERIC); |
|
238 | 238 | |
239 | - return array_map( 'trailingslashit', $file_paths ); |
|
239 | + return array_map('trailingslashit', $file_paths); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | function wpinv_get_theme_template_dir_name() { |
243 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
243 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | function wpinv_checkout_meta_tags() { |
247 | 247 | |
248 | 248 | $pages = array(); |
249 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
249 | + $pages[] = wpinv_get_option('success_page'); |
|
250 | + $pages[] = wpinv_get_option('failure_page'); |
|
251 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
252 | 252 | |
253 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | 257 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
258 | 258 | } |
259 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
259 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
260 | 260 | |
261 | -function wpinv_add_body_classes( $class ) { |
|
261 | +function wpinv_add_body_classes($class) { |
|
262 | 262 | $classes = (array)$class; |
263 | 263 | |
264 | - if( wpinv_is_checkout() ) { |
|
264 | + if (wpinv_is_checkout()) { |
|
265 | 265 | $classes[] = 'wpinv-checkout'; |
266 | 266 | $classes[] = 'wpinv-page'; |
267 | 267 | } |
268 | 268 | |
269 | - if( wpinv_is_success_page() ) { |
|
269 | + if (wpinv_is_success_page()) { |
|
270 | 270 | $classes[] = 'wpinv-success'; |
271 | 271 | $classes[] = 'wpinv-page'; |
272 | 272 | } |
273 | 273 | |
274 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | + if (wpinv_is_failed_transaction_page()) { |
|
275 | 275 | $classes[] = 'wpinv-failed-transaction'; |
276 | 276 | $classes[] = 'wpinv-page'; |
277 | 277 | } |
278 | 278 | |
279 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | + if (wpinv_is_invoice_history_page()) { |
|
280 | 280 | $classes[] = 'wpinv-history'; |
281 | 281 | $classes[] = 'wpinv-page'; |
282 | 282 | } |
283 | 283 | |
284 | - if( wpinv_is_test_mode() ) { |
|
284 | + if (wpinv_is_test_mode()) { |
|
285 | 285 | $classes[] = 'wpinv-test-mode'; |
286 | 286 | $classes[] = 'wpinv-page'; |
287 | 287 | } |
288 | 288 | |
289 | - return array_unique( $classes ); |
|
289 | + return array_unique($classes); |
|
290 | 290 | } |
291 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
291 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
292 | 292 | |
293 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
294 | - $args = array( 'nopaging' => true ); |
|
293 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
294 | + $args = array('nopaging' => true); |
|
295 | 295 | |
296 | - if ( ! empty( $status ) ) |
|
296 | + if (!empty($status)) |
|
297 | 297 | $args['post_status'] = $status; |
298 | 298 | |
299 | - $discounts = wpinv_get_discounts( $args ); |
|
299 | + $discounts = wpinv_get_discounts($args); |
|
300 | 300 | $options = array(); |
301 | 301 | |
302 | - if ( $discounts ) { |
|
303 | - foreach ( $discounts as $discount ) { |
|
304 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
302 | + if ($discounts) { |
|
303 | + foreach ($discounts as $discount) { |
|
304 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
305 | 305 | } |
306 | 306 | } else { |
307 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
307 | + $options[0] = __('No discounts found', 'invoicing'); |
|
308 | 308 | } |
309 | 309 | |
310 | - $output = wpinv_html_select( array( |
|
310 | + $output = wpinv_html_select(array( |
|
311 | 311 | 'name' => $name, |
312 | 312 | 'selected' => $selected, |
313 | 313 | 'options' => $options, |
314 | 314 | 'show_option_all' => false, |
315 | 315 | 'show_option_none' => false, |
316 | - ) ); |
|
316 | + )); |
|
317 | 317 | |
318 | 318 | return $output; |
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
322 | - $current = date( 'Y' ); |
|
323 | - $start_year = $current - absint( $years_before ); |
|
324 | - $end_year = $current + absint( $years_after ); |
|
325 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
321 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
322 | + $current = date('Y'); |
|
323 | + $start_year = $current - absint($years_before); |
|
324 | + $end_year = $current + absint($years_after); |
|
325 | + $selected = empty($selected) ? date('Y') : $selected; |
|
326 | 326 | $options = array(); |
327 | 327 | |
328 | - while ( $start_year <= $end_year ) { |
|
329 | - $options[ absint( $start_year ) ] = $start_year; |
|
328 | + while ($start_year <= $end_year) { |
|
329 | + $options[absint($start_year)] = $start_year; |
|
330 | 330 | $start_year++; |
331 | 331 | } |
332 | 332 | |
333 | - $output = wpinv_html_select( array( |
|
333 | + $output = wpinv_html_select(array( |
|
334 | 334 | 'name' => $name, |
335 | 335 | 'selected' => $selected, |
336 | 336 | 'options' => $options, |
337 | 337 | 'show_option_all' => false, |
338 | 338 | 'show_option_none' => false |
339 | - ) ); |
|
339 | + )); |
|
340 | 340 | |
341 | 341 | return $output; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
344 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
345 | 345 | $month = 1; |
346 | 346 | $options = array(); |
347 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
347 | + $selected = empty($selected) ? date('n') : $selected; |
|
348 | 348 | |
349 | - while ( $month <= 12 ) { |
|
350 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
349 | + while ($month <= 12) { |
|
350 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
351 | 351 | $month++; |
352 | 352 | } |
353 | 353 | |
354 | - $output = wpinv_html_select( array( |
|
354 | + $output = wpinv_html_select(array( |
|
355 | 355 | 'name' => $name, |
356 | 356 | 'selected' => $selected, |
357 | 357 | 'options' => $options, |
358 | 358 | 'show_option_all' => false, |
359 | 359 | 'show_option_none' => false |
360 | - ) ); |
|
360 | + )); |
|
361 | 361 | |
362 | 362 | return $output; |
363 | 363 | } |
364 | 364 | |
365 | -function wpinv_html_select( $args = array() ) { |
|
365 | +function wpinv_html_select($args = array()) { |
|
366 | 366 | $defaults = array( |
367 | 367 | 'options' => array(), |
368 | 368 | 'name' => null, |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | 'chosen' => false, |
373 | 373 | 'placeholder' => null, |
374 | 374 | 'multiple' => false, |
375 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
376 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
375 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
376 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
377 | 377 | 'data' => array(), |
378 | 378 | 'onchange' => null, |
379 | 379 | 'required' => false, |
@@ -381,78 +381,78 @@ discard block |
||
381 | 381 | 'readonly' => false, |
382 | 382 | ); |
383 | 383 | |
384 | - $args = wp_parse_args( $args, $defaults ); |
|
384 | + $args = wp_parse_args($args, $defaults); |
|
385 | 385 | |
386 | 386 | $data_elements = ''; |
387 | - foreach ( $args['data'] as $key => $value ) { |
|
388 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
387 | + foreach ($args['data'] as $key => $value) { |
|
388 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
389 | 389 | } |
390 | 390 | |
391 | - if( $args['multiple'] ) { |
|
391 | + if ($args['multiple']) { |
|
392 | 392 | $multiple = ' MULTIPLE'; |
393 | 393 | } else { |
394 | 394 | $multiple = ''; |
395 | 395 | } |
396 | 396 | |
397 | - if( $args['chosen'] ) { |
|
397 | + if ($args['chosen']) { |
|
398 | 398 | $args['class'] .= ' wpinv-select-chosen'; |
399 | 399 | } |
400 | 400 | |
401 | - if( $args['placeholder'] ) { |
|
401 | + if ($args['placeholder']) { |
|
402 | 402 | $placeholder = $args['placeholder']; |
403 | 403 | } else { |
404 | 404 | $placeholder = ''; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $options = ''; |
408 | - if( !empty( $args['onchange'] ) ) { |
|
409 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
408 | + if (!empty($args['onchange'])) { |
|
409 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
410 | 410 | } |
411 | 411 | |
412 | - if( !empty( $args['required'] ) ) { |
|
412 | + if (!empty($args['required'])) { |
|
413 | 413 | $options .= ' required="required"'; |
414 | 414 | } |
415 | 415 | |
416 | - if( !empty( $args['disabled'] ) ) { |
|
416 | + if (!empty($args['disabled'])) { |
|
417 | 417 | $options .= ' disabled'; |
418 | 418 | } |
419 | 419 | |
420 | - if( !empty( $args['readonly'] ) ) { |
|
420 | + if (!empty($args['readonly'])) { |
|
421 | 421 | $options .= ' readonly'; |
422 | 422 | } |
423 | 423 | |
424 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
425 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
424 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
425 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
426 | 426 | |
427 | - if ( $args['show_option_all'] ) { |
|
428 | - if( $args['multiple'] ) { |
|
429 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
427 | + if ($args['show_option_all']) { |
|
428 | + if ($args['multiple']) { |
|
429 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
430 | 430 | } else { |
431 | - $selected = selected( $args['selected'], 0, false ); |
|
431 | + $selected = selected($args['selected'], 0, false); |
|
432 | 432 | } |
433 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
433 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
434 | 434 | } |
435 | 435 | |
436 | - if ( !empty( $args['options'] ) ) { |
|
436 | + if (!empty($args['options'])) { |
|
437 | 437 | |
438 | - if ( $args['show_option_none'] ) { |
|
439 | - if( $args['multiple'] ) { |
|
440 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
438 | + if ($args['show_option_none']) { |
|
439 | + if ($args['multiple']) { |
|
440 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
441 | 441 | } else { |
442 | - $selected = selected( $args['selected'] === "", true, false ); |
|
442 | + $selected = selected($args['selected'] === "", true, false); |
|
443 | 443 | } |
444 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
444 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
445 | 445 | } |
446 | 446 | |
447 | - foreach( $args['options'] as $key => $option ) { |
|
447 | + foreach ($args['options'] as $key => $option) { |
|
448 | 448 | |
449 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
450 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
449 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
450 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
451 | 451 | } else { |
452 | - $selected = selected( $args['selected'], $key, false ); |
|
452 | + $selected = selected($args['selected'], $key, false); |
|
453 | 453 | } |
454 | 454 | |
455 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
455 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | return $output; |
462 | 462 | } |
463 | 463 | |
464 | -function wpinv_item_dropdown( $args = array() ) { |
|
464 | +function wpinv_item_dropdown($args = array()) { |
|
465 | 465 | $defaults = array( |
466 | 466 | 'name' => 'wpi_item', |
467 | 467 | 'id' => 'wpi_item', |
@@ -470,15 +470,15 @@ discard block |
||
470 | 470 | 'selected' => 0, |
471 | 471 | 'chosen' => false, |
472 | 472 | 'number' => 100, |
473 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
474 | - 'data' => array( 'search-type' => 'item' ), |
|
473 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
474 | + 'data' => array('search-type' => 'item'), |
|
475 | 475 | 'show_option_all' => false, |
476 | 476 | 'show_option_none' => false, |
477 | 477 | 'with_packages' => true, |
478 | 478 | 'show_recurring' => false, |
479 | 479 | ); |
480 | 480 | |
481 | - $args = wp_parse_args( $args, $defaults ); |
|
481 | + $args = wp_parse_args($args, $defaults); |
|
482 | 482 | |
483 | 483 | $item_args = array( |
484 | 484 | 'post_type' => 'wpi_item', |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | 'posts_per_page' => $args['number'] |
488 | 488 | ); |
489 | 489 | |
490 | - if ( !$args['with_packages'] ) { |
|
490 | + if (!$args['with_packages']) { |
|
491 | 491 | $item_args['meta_query'] = array( |
492 | 492 | array( |
493 | 493 | 'key' => '_wpinv_type', |
@@ -497,42 +497,42 @@ discard block |
||
497 | 497 | ); |
498 | 498 | } |
499 | 499 | |
500 | - $items = get_posts( $item_args ); |
|
500 | + $items = get_posts($item_args); |
|
501 | 501 | $options = array(); |
502 | - if ( $items ) { |
|
503 | - foreach ( $items as $item ) { |
|
504 | - $title = esc_html( $item->post_title ); |
|
502 | + if ($items) { |
|
503 | + foreach ($items as $item) { |
|
504 | + $title = esc_html($item->post_title); |
|
505 | 505 | |
506 | - if ( !empty( $args['show_recurring'] ) ) { |
|
507 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
506 | + if (!empty($args['show_recurring'])) { |
|
507 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
508 | 508 | } |
509 | 509 | |
510 | - $options[ absint( $item->ID ) ] = $title; |
|
510 | + $options[absint($item->ID)] = $title; |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | 514 | // This ensures that any selected items are included in the drop down |
515 | - if( is_array( $args['selected'] ) ) { |
|
516 | - foreach( $args['selected'] as $item ) { |
|
517 | - if( ! in_array( $item, $options ) ) { |
|
518 | - $title = get_the_title( $item ); |
|
519 | - if ( !empty( $args['show_recurring'] ) ) { |
|
520 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
515 | + if (is_array($args['selected'])) { |
|
516 | + foreach ($args['selected'] as $item) { |
|
517 | + if (!in_array($item, $options)) { |
|
518 | + $title = get_the_title($item); |
|
519 | + if (!empty($args['show_recurring'])) { |
|
520 | + $title .= wpinv_get_item_suffix($item, false); |
|
521 | 521 | } |
522 | 522 | $options[$item] = $title; |
523 | 523 | } |
524 | 524 | } |
525 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
526 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
527 | - $title = get_the_title( $args['selected'] ); |
|
528 | - if ( !empty( $args['show_recurring'] ) ) { |
|
529 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
525 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
526 | + if (!in_array($args['selected'], $options)) { |
|
527 | + $title = get_the_title($args['selected']); |
|
528 | + if (!empty($args['show_recurring'])) { |
|
529 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
530 | 530 | } |
531 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
531 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | - $output = wpinv_html_select( array( |
|
535 | + $output = wpinv_html_select(array( |
|
536 | 536 | 'name' => $args['name'], |
537 | 537 | 'selected' => $args['selected'], |
538 | 538 | 'id' => $args['id'], |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | 'show_option_all' => $args['show_option_all'], |
545 | 545 | 'show_option_none' => $args['show_option_none'], |
546 | 546 | 'data' => $args['data'], |
547 | - ) ); |
|
547 | + )); |
|
548 | 548 | |
549 | 549 | return $output; |
550 | 550 | } |
551 | 551 | |
552 | -function wpinv_html_checkbox( $args = array() ) { |
|
552 | +function wpinv_html_checkbox($args = array()) { |
|
553 | 553 | $defaults = array( |
554 | 554 | 'name' => null, |
555 | 555 | 'current' => null, |
@@ -560,38 +560,38 @@ discard block |
||
560 | 560 | ) |
561 | 561 | ); |
562 | 562 | |
563 | - $args = wp_parse_args( $args, $defaults ); |
|
563 | + $args = wp_parse_args($args, $defaults); |
|
564 | 564 | |
565 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
565 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
566 | 566 | $options = ''; |
567 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
567 | + if (!empty($args['options']['disabled'])) { |
|
568 | 568 | $options .= ' disabled="disabled"'; |
569 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
569 | + } elseif (!empty($args['options']['readonly'])) { |
|
570 | 570 | $options .= ' readonly'; |
571 | 571 | } |
572 | 572 | |
573 | - $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 ) . ' />'; |
|
573 | + $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) . ' />'; |
|
574 | 574 | |
575 | 575 | return $output; |
576 | 576 | } |
577 | 577 | |
578 | -function wpinv_html_text( $args = array() ) { |
|
578 | +function wpinv_html_text($args = array()) { |
|
579 | 579 | // Backwards compatibility |
580 | - if ( func_num_args() > 1 ) { |
|
580 | + if (func_num_args() > 1) { |
|
581 | 581 | $args = func_get_args(); |
582 | 582 | |
583 | 583 | $name = $args[0]; |
584 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
585 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
586 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
584 | + $value = isset($args[1]) ? $args[1] : ''; |
|
585 | + $label = isset($args[2]) ? $args[2] : ''; |
|
586 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | $defaults = array( |
590 | 590 | 'id' => '', |
591 | - 'name' => isset( $name ) ? $name : 'text', |
|
592 | - 'value' => isset( $value ) ? $value : null, |
|
593 | - 'label' => isset( $label ) ? $label : null, |
|
594 | - 'desc' => isset( $desc ) ? $desc : null, |
|
591 | + 'name' => isset($name) ? $name : 'text', |
|
592 | + 'value' => isset($value) ? $value : null, |
|
593 | + 'label' => isset($label) ? $label : null, |
|
594 | + 'desc' => isset($desc) ? $desc : null, |
|
595 | 595 | 'placeholder' => '', |
596 | 596 | 'class' => 'regular-text', |
597 | 597 | 'disabled' => false, |
@@ -601,51 +601,51 @@ discard block |
||
601 | 601 | 'data' => false |
602 | 602 | ); |
603 | 603 | |
604 | - $args = wp_parse_args( $args, $defaults ); |
|
604 | + $args = wp_parse_args($args, $defaults); |
|
605 | 605 | |
606 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
606 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
607 | 607 | $options = ''; |
608 | - if( $args['required'] ) { |
|
608 | + if ($args['required']) { |
|
609 | 609 | $options .= ' required="required"'; |
610 | 610 | } |
611 | - if( $args['readonly'] ) { |
|
611 | + if ($args['readonly']) { |
|
612 | 612 | $options .= ' readonly'; |
613 | 613 | } |
614 | - if( $args['readonly'] ) { |
|
614 | + if ($args['readonly']) { |
|
615 | 615 | $options .= ' readonly'; |
616 | 616 | } |
617 | 617 | |
618 | 618 | $data = ''; |
619 | - if ( !empty( $args['data'] ) ) { |
|
620 | - foreach ( $args['data'] as $key => $value ) { |
|
621 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
619 | + if (!empty($args['data'])) { |
|
620 | + foreach ($args['data'] as $key => $value) { |
|
621 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
625 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
626 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
627 | - if ( ! empty( $args['desc'] ) ) { |
|
628 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
625 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
626 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
627 | + if (!empty($args['desc'])) { |
|
628 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
629 | 629 | } |
630 | 630 | |
631 | - $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 ) . '/>'; |
|
631 | + $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) . '/>'; |
|
632 | 632 | |
633 | 633 | $output .= '</span>'; |
634 | 634 | |
635 | 635 | return $output; |
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_html_date_field( $args = array() ) { |
|
639 | - if( empty( $args['class'] ) ) { |
|
638 | +function wpinv_html_date_field($args = array()) { |
|
639 | + if (empty($args['class'])) { |
|
640 | 640 | $args['class'] = 'wpiDatepicker'; |
641 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
641 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
642 | 642 | $args['class'] .= ' wpiDatepicker'; |
643 | 643 | } |
644 | 644 | |
645 | - return wpinv_html_text( $args ); |
|
645 | + return wpinv_html_text($args); |
|
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_html_textarea( $args = array() ) { |
|
648 | +function wpinv_html_textarea($args = array()) { |
|
649 | 649 | $defaults = array( |
650 | 650 | 'name' => 'textarea', |
651 | 651 | 'value' => null, |
@@ -655,31 +655,31 @@ discard block |
||
655 | 655 | 'disabled' => false |
656 | 656 | ); |
657 | 657 | |
658 | - $args = wp_parse_args( $args, $defaults ); |
|
658 | + $args = wp_parse_args($args, $defaults); |
|
659 | 659 | |
660 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
660 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
661 | 661 | $disabled = ''; |
662 | - if( $args['disabled'] ) { |
|
662 | + if ($args['disabled']) { |
|
663 | 663 | $disabled = ' disabled="disabled"'; |
664 | 664 | } |
665 | 665 | |
666 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
667 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
668 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
666 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
667 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
668 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
669 | 669 | |
670 | - if ( ! empty( $args['desc'] ) ) { |
|
671 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
670 | + if (!empty($args['desc'])) { |
|
671 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
672 | 672 | } |
673 | 673 | $output .= '</span>'; |
674 | 674 | |
675 | 675 | return $output; |
676 | 676 | } |
677 | 677 | |
678 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
678 | +function wpinv_html_ajax_user_search($args = array()) { |
|
679 | 679 | $defaults = array( |
680 | 680 | 'name' => 'user_id', |
681 | 681 | 'value' => null, |
682 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
682 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
683 | 683 | 'label' => null, |
684 | 684 | 'desc' => null, |
685 | 685 | 'class' => '', |
@@ -688,13 +688,13 @@ discard block |
||
688 | 688 | 'data' => false |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | 693 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
694 | 694 | |
695 | 695 | $output = '<span class="wpinv_user_search_wrap">'; |
696 | - $output .= wpinv_html_text( $args ); |
|
697 | - $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>'; |
|
696 | + $output .= wpinv_html_text($args); |
|
697 | + $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>'; |
|
698 | 698 | $output .= '</span>'; |
699 | 699 | |
700 | 700 | return $output; |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | function wpinv_ip_geolocation() { |
704 | 704 | global $wpinv_euvat; |
705 | 705 | |
706 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
706 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
707 | 707 | $content = ''; |
708 | 708 | $iso = ''; |
709 | 709 | $country = ''; |
@@ -714,69 +714,69 @@ discard block |
||
714 | 714 | $credit = ''; |
715 | 715 | $address = ''; |
716 | 716 | |
717 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
717 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
718 | 718 | try { |
719 | 719 | $iso = $geoip2_city->country->isoCode; |
720 | 720 | $country = $geoip2_city->country->name; |
721 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
721 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
722 | 722 | $city = $geoip2_city->city->name; |
723 | 723 | $longitude = $geoip2_city->location->longitude; |
724 | 724 | $latitude = $geoip2_city->location->latitude; |
725 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
726 | - } catch( Exception $e ) { } |
|
725 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
726 | + } catch (Exception $e) { } |
|
727 | 727 | } |
728 | 728 | |
729 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
729 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
730 | 730 | try { |
731 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
731 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
732 | 732 | |
733 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
733 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
734 | 734 | $iso = $load_xml->geoplugin_countryCode; |
735 | 735 | $country = $load_xml->geoplugin_countryName; |
736 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
737 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
736 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
737 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
738 | 738 | $longitude = $load_xml->geoplugin_longitude; |
739 | 739 | $latitude = $load_xml->geoplugin_latitude; |
740 | 740 | $credit = $load_xml->geoplugin_credit; |
741 | - $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; |
|
741 | + $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; |
|
742 | 742 | } |
743 | - } catch( Exception $e ) { } |
|
743 | + } catch (Exception $e) { } |
|
744 | 744 | } |
745 | 745 | |
746 | - if ( $iso && $longitude && $latitude ) { |
|
747 | - if ( $city ) { |
|
746 | + if ($iso && $longitude && $latitude) { |
|
747 | + if ($city) { |
|
748 | 748 | $address .= $city . ', '; |
749 | 749 | } |
750 | 750 | |
751 | - if ( $region ) { |
|
751 | + if ($region) { |
|
752 | 752 | $address .= $region . ', '; |
753 | 753 | } |
754 | 754 | |
755 | 755 | $address .= $country . ' (' . $iso . ')'; |
756 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
757 | - $content .= '<p>'. $credit . '</p>'; |
|
756 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
757 | + $content .= '<p>' . $credit . '</p>'; |
|
758 | 758 | } else { |
759 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
759 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
760 | 760 | } |
761 | 761 | ?> |
762 | 762 | <!DOCTYPE html> |
763 | -<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> |
|
763 | +<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> |
|
764 | 764 | <body> |
765 | - <?php if ( $latitude && $latitude ) { ?> |
|
765 | + <?php if ($latitude && $latitude) { ?> |
|
766 | 766 | <div id="map"></div> |
767 | 767 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
768 | 768 | <script type="text/javascript"> |
769 | 769 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
770 | 770 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
771 | 771 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
772 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
772 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
773 | 773 | |
774 | 774 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
775 | 775 | |
776 | 776 | var marker = new L.Marker(latlng); |
777 | 777 | map.addLayer(marker); |
778 | 778 | |
779 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
779 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
780 | 780 | </script> |
781 | 781 | <?php } ?> |
782 | 782 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -784,31 +784,31 @@ discard block |
||
784 | 784 | <?php |
785 | 785 | exit; |
786 | 786 | } |
787 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
788 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
787 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
788 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
789 | 789 | |
790 | 790 | // Set up the template for the invoice. |
791 | -function wpinv_template( $template ) { |
|
791 | +function wpinv_template($template) { |
|
792 | 792 | global $post, $wp_query; |
793 | 793 | |
794 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
795 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
796 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
794 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
795 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
796 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
797 | 797 | } else { |
798 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
798 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
799 | 799 | $user_id = $invoice->get_user_id(); |
800 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
800 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
801 | 801 | |
802 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
803 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
802 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
803 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
804 | 804 | |
805 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
805 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
806 | 806 | wpinv_die(); |
807 | 807 | } |
808 | 808 | } |
809 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
809 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
810 | 810 | |
811 | - wp_redirect( $redirect_to ); |
|
811 | + wp_redirect($redirect_to); |
|
812 | 812 | wpinv_die(); |
813 | 813 | } |
814 | 814 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | |
819 | 819 | function wpinv_get_business_address() { |
820 | 820 | $business_address = wpinv_store_address(); |
821 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
821 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
822 | 822 | |
823 | 823 | /* |
824 | 824 | $default_country = wpinv_get_default_country(); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
844 | 844 | |
845 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
845 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | function wpinv_display_from_address() { |
@@ -852,185 +852,185 @@ discard block |
||
852 | 852 | if (empty($from_name)) { |
853 | 853 | $from_name = wpinv_get_business_name(); |
854 | 854 | } |
855 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
855 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
856 | 856 | <div class="wrapper col-xs-10"> |
857 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
858 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
859 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
857 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
858 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
859 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
860 | 860 | <?php } ?> |
861 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
862 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
861 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
862 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
863 | 863 | <?php } ?> |
864 | 864 | </div> |
865 | 865 | <?php |
866 | 866 | } |
867 | 867 | |
868 | -function wpinv_watermark( $id = 0 ) { |
|
869 | - $output = wpinv_get_watermark( $id ); |
|
868 | +function wpinv_watermark($id = 0) { |
|
869 | + $output = wpinv_get_watermark($id); |
|
870 | 870 | |
871 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
871 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
872 | 872 | } |
873 | 873 | |
874 | -function wpinv_get_watermark( $id ) { |
|
875 | - if ( !$id > 0 ) { |
|
874 | +function wpinv_get_watermark($id) { |
|
875 | + if (!$id > 0) { |
|
876 | 876 | return NULL; |
877 | 877 | } |
878 | - $invoice = wpinv_get_invoice( $id ); |
|
878 | + $invoice = wpinv_get_invoice($id); |
|
879 | 879 | |
880 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
881 | - if ( $invoice->is_paid() ) { |
|
882 | - return __( 'Paid', 'invoicing' ); |
|
880 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
881 | + if ($invoice->is_paid()) { |
|
882 | + return __('Paid', 'invoicing'); |
|
883 | 883 | } |
884 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
885 | - return __( 'Cancelled', 'invoicing' ); |
|
884 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
885 | + return __('Cancelled', 'invoicing'); |
|
886 | 886 | } |
887 | 887 | } |
888 | 888 | |
889 | 889 | return NULL; |
890 | 890 | } |
891 | 891 | |
892 | -function wpinv_display_invoice_details( $invoice ) { |
|
892 | +function wpinv_display_invoice_details($invoice) { |
|
893 | 893 | global $wpinv_euvat; |
894 | 894 | |
895 | 895 | $invoice_id = $invoice->ID; |
896 | 896 | $vat_name = $wpinv_euvat->get_vat_name(); |
897 | 897 | $use_taxes = wpinv_use_taxes(); |
898 | 898 | |
899 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
899 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
900 | 900 | |
901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
901 | + if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | + elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
903 | 903 | ?> |
904 | 904 | <table class="table table-bordered table-sm"> |
905 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
905 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
906 | 906 | <tr class="wpi-row-number"> |
907 | - <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th> |
|
908 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
907 | + <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th> |
|
908 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
909 | 909 | </tr> |
910 | 910 | <?php } ?> |
911 | 911 | <tr class="wpi-row-status"> |
912 | - <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th> |
|
913 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
912 | + <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th> |
|
913 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
914 | 914 | </tr> |
915 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
915 | + <?php if ($invoice->is_renewal()) { ?> |
|
916 | 916 | <tr class="wpi-row-parent"> |
917 | - <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th> |
|
918 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
917 | + <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th> |
|
918 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
919 | 919 | </tr> |
920 | 920 | <?php } ?> |
921 | 921 | <tr class="wpi-row-gateway"> |
922 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
923 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
922 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
923 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
924 | 924 | </tr> |
925 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
925 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
926 | 926 | <tr class="wpi-row-date"> |
927 | - <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th> |
|
927 | + <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th> |
|
928 | 928 | <td><?php echo $invoice_date; ?></td> |
929 | 929 | </tr> |
930 | 930 | <?php } ?> |
931 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
931 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
932 | 932 | <tr class="wpi-row-date"> |
933 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
933 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
934 | 934 | <td><?php echo $due_date; ?></td> |
935 | 935 | </tr> |
936 | 936 | <?php } ?> |
937 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
937 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
938 | 938 | <tr class="wpi-row-ovatno"> |
939 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
939 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
940 | 940 | <td><?php echo $owner_vat_number; ?></td> |
941 | 941 | </tr> |
942 | 942 | <?php } ?> |
943 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
943 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
944 | 944 | <tr class="wpi-row-uvatno"> |
945 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
945 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
946 | 946 | <td><?php echo $user_vat_number; ?></td> |
947 | 947 | </tr> |
948 | 948 | <?php } ?> |
949 | 949 | <tr class="table-active tr-total wpi-row-total"> |
950 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
951 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
950 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
951 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
952 | 952 | </tr> |
953 | 953 | </table> |
954 | 954 | <?php |
955 | 955 | } |
956 | 956 | |
957 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
958 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
957 | +function wpinv_display_to_address($invoice_id = 0) { |
|
958 | + $invoice = wpinv_get_invoice($invoice_id); |
|
959 | 959 | |
960 | - if ( empty( $invoice ) ) { |
|
960 | + if (empty($invoice)) { |
|
961 | 961 | return NULL; |
962 | 962 | } |
963 | 963 | |
964 | 964 | $billing_details = $invoice->get_user_info(); |
965 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
965 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
966 | 966 | $output .= '<div class="wrapper col-xs-10">'; |
967 | 967 | |
968 | 968 | ob_start(); |
969 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
969 | + do_action('wpinv_display_to_address_top', $invoice); |
|
970 | 970 | $output .= ob_get_clean(); |
971 | 971 | |
972 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
973 | - if ( $company = $billing_details['company'] ) { |
|
974 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
972 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
973 | + if ($company = $billing_details['company']) { |
|
974 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
975 | 975 | } |
976 | 976 | $address_row = ''; |
977 | - if ( $address = $billing_details['address'] ) { |
|
978 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
977 | + if ($address = $billing_details['address']) { |
|
978 | + $address_row .= wpautop(wp_kses_post($address)); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | $address_fields = array(); |
982 | - if ( !empty( $billing_details['city'] ) ) { |
|
982 | + if (!empty($billing_details['city'])) { |
|
983 | 983 | $address_fields[] = $billing_details['city']; |
984 | 984 | } |
985 | 985 | |
986 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
987 | - if ( !empty( $billing_details['state'] ) ) { |
|
988 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
986 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
987 | + if (!empty($billing_details['state'])) { |
|
988 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
989 | 989 | } |
990 | 990 | |
991 | - if ( !empty( $billing_country ) ) { |
|
992 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
991 | + if (!empty($billing_country)) { |
|
992 | + $address_fields[] = wpinv_country_name($billing_country); |
|
993 | 993 | } |
994 | 994 | |
995 | - if ( !empty( $address_fields ) ) { |
|
996 | - $address_fields = implode( ", ", $address_fields ); |
|
995 | + if (!empty($address_fields)) { |
|
996 | + $address_fields = implode(", ", $address_fields); |
|
997 | 997 | |
998 | - if ( !empty( $billing_details['zip'] ) ) { |
|
998 | + if (!empty($billing_details['zip'])) { |
|
999 | 999 | $address_fields .= ' ' . $billing_details['zip']; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1002 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if ( $address_row ) { |
|
1005 | + if ($address_row) { |
|
1006 | 1006 | $output .= '<div class="address">' . $address_row . '</div>'; |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if ( $phone = $invoice->get_phone() ) { |
|
1010 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
1009 | + if ($phone = $invoice->get_phone()) { |
|
1010 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
1011 | 1011 | } |
1012 | - if ( $email = $invoice->get_email() ) { |
|
1013 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
1012 | + if ($email = $invoice->get_email()) { |
|
1013 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | ob_start(); |
1017 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1017 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
1018 | 1018 | $output .= ob_get_clean(); |
1019 | 1019 | |
1020 | 1020 | $output .= '</div>'; |
1021 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1021 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
1022 | 1022 | |
1023 | 1023 | echo $output; |
1024 | 1024 | } |
1025 | 1025 | |
1026 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1026 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1027 | 1027 | global $wpinv_euvat, $ajax_cart_details; |
1028 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1028 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1029 | 1029 | $quantities_enabled = wpinv_item_quantities_enabled(); |
1030 | 1030 | $use_taxes = wpinv_use_taxes(); |
1031 | 1031 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
1032 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1033 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1032 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
1033 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
1034 | 1034 | |
1035 | 1035 | $cart_details = $invoice->get_cart_details(); |
1036 | 1036 | $ajax_cart_details = $cart_details; |
@@ -1039,68 +1039,68 @@ discard block |
||
1039 | 1039 | <table class="table table-sm table-bordered table-responsive"> |
1040 | 1040 | <thead> |
1041 | 1041 | <tr> |
1042 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1043 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1042 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1043 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1044 | 1044 | <?php if ($quantities_enabled) { ?> |
1045 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1045 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1046 | 1046 | <?php } ?> |
1047 | 1047 | <?php if ($use_taxes && !$zero_tax) { ?> |
1048 | 1048 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1049 | 1049 | <?php } ?> |
1050 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1050 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1051 | 1051 | </tr> |
1052 | 1052 | </thead> |
1053 | 1053 | <tbody> |
1054 | 1054 | <?php |
1055 | - if ( !empty( $cart_details ) ) { |
|
1056 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1055 | + if (!empty($cart_details)) { |
|
1056 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1057 | 1057 | |
1058 | 1058 | $count = 0; |
1059 | 1059 | $cols = 3; |
1060 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1061 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1062 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
1063 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
1064 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1060 | + foreach ($cart_details as $key => $cart_item) { |
|
1061 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1062 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
1063 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
1064 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1065 | 1065 | |
1066 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1066 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1067 | 1067 | $summary = ''; |
1068 | 1068 | $cols = 3; |
1069 | - if ( !empty($item) ) { |
|
1069 | + if (!empty($item)) { |
|
1070 | 1070 | $item_name = $item->get_name(); |
1071 | 1071 | $summary = $item->get_summary(); |
1072 | 1072 | } |
1073 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1073 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1074 | 1074 | |
1075 | 1075 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1076 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1077 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link ); |
|
1076 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1077 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link); |
|
1078 | 1078 | } |
1079 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1079 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1080 | 1080 | |
1081 | 1081 | $item_tax = ''; |
1082 | 1082 | $tax_rate = ''; |
1083 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1084 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1085 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1086 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
1083 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1084 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1085 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1086 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
1087 | 1087 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | $line_item_tax = $item_tax . $tax_rate; |
1091 | 1091 | |
1092 | - if ( $line_item_tax === '' ) { |
|
1092 | + if ($line_item_tax === '') { |
|
1093 | 1093 | $line_item_tax = 0; // Zero tax |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1097 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1098 | - if ( $summary !== '' ) { |
|
1099 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1096 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1097 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1098 | + if ($summary !== '') { |
|
1099 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1100 | 1100 | } |
1101 | 1101 | $line_item .= '</td>'; |
1102 | 1102 | |
1103 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
1103 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
1104 | 1104 | if ($quantities_enabled) { |
1105 | 1105 | $cols++; |
1106 | 1106 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1109,55 +1109,55 @@ discard block |
||
1109 | 1109 | $cols++; |
1110 | 1110 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1111 | 1111 | } |
1112 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
1112 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
1113 | 1113 | $line_item .= '</tr>'; |
1114 | 1114 | |
1115 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1115 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1116 | 1116 | |
1117 | 1117 | $count++; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1120 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1121 | 1121 | ?> |
1122 | 1122 | <tr class="row-sub-total row_odd"> |
1123 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1124 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1123 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1124 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1125 | 1125 | </tr> |
1126 | 1126 | <?php |
1127 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1127 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1128 | 1128 | |
1129 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1130 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1129 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1130 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1131 | 1131 | ?> |
1132 | 1132 | <tr class="row-discount"> |
1133 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1134 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1133 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1134 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1135 | 1135 | </tr> |
1136 | 1136 | <?php |
1137 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1137 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | - if ( $use_taxes ) { |
|
1141 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1140 | + if ($use_taxes) { |
|
1141 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1142 | 1142 | ?> |
1143 | 1143 | <tr class="row-tax"> |
1144 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1145 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1144 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1145 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1146 | 1146 | </tr> |
1147 | 1147 | <?php |
1148 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1148 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1151 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1152 | 1152 | ?> |
1153 | 1153 | <tr class="table-active row-total"> |
1154 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1155 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1154 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1155 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1156 | 1156 | </tr> |
1157 | 1157 | <?php |
1158 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1158 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1159 | 1159 | |
1160 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1160 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1161 | 1161 | } |
1162 | 1162 | ?> |
1163 | 1163 | </tbody> |
@@ -1166,35 +1166,35 @@ discard block |
||
1166 | 1166 | echo ob_get_clean(); |
1167 | 1167 | } |
1168 | 1168 | |
1169 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1169 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1170 | 1170 | $use_taxes = wpinv_use_taxes(); |
1171 | 1171 | |
1172 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1172 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1173 | 1173 | ?> |
1174 | 1174 | <table class="table table-sm table-bordered table-responsive"> |
1175 | 1175 | <tbody> |
1176 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1176 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1177 | 1177 | <tr class="row-sub-total"> |
1178 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1179 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1178 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1179 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1180 | 1180 | </tr> |
1181 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1182 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1181 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1182 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1183 | 1183 | <tr class="row-discount"> |
1184 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1185 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1184 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1185 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1186 | 1186 | </tr> |
1187 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1187 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1188 | 1188 | <?php } ?> |
1189 | - <?php if ( $use_taxes ) { ?> |
|
1189 | + <?php if ($use_taxes) { ?> |
|
1190 | 1190 | <tr class="row-tax"> |
1191 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1192 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1191 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1192 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1193 | 1193 | </tr> |
1194 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1194 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1195 | 1195 | <?php } ?> |
1196 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1197 | - <?php foreach ( $fees as $fee ) { ?> |
|
1196 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1197 | + <?php foreach ($fees as $fee) { ?> |
|
1198 | 1198 | <tr class="row-fee"> |
1199 | 1199 | <td class="rate"><?php echo $fee['label']; ?></td> |
1200 | 1200 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1202,72 +1202,72 @@ discard block |
||
1202 | 1202 | <?php } ?> |
1203 | 1203 | <?php } ?> |
1204 | 1204 | <tr class="table-active row-total"> |
1205 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1206 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1205 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1206 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1207 | 1207 | </tr> |
1208 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1208 | + <?php do_action('wpinv_after_totals'); ?> |
|
1209 | 1209 | </tbody> |
1210 | 1210 | |
1211 | 1211 | </table> |
1212 | 1212 | |
1213 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1213 | + <?php do_action('wpinv_after_totals_table'); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1217 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1216 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1217 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1218 | 1218 | |
1219 | 1219 | ob_start(); |
1220 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1221 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
1220 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1221 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
1222 | 1222 | ?> |
1223 | 1223 | <div class="wpi-payment-info"> |
1224 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1225 | - <?php if ( $gateway_title ) { ?> |
|
1226 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1224 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1225 | + <?php if ($gateway_title) { ?> |
|
1226 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1227 | 1227 | <?php } ?> |
1228 | 1228 | </div> |
1229 | 1229 | <?php |
1230 | 1230 | } |
1231 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1231 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1232 | 1232 | $outout = ob_get_clean(); |
1233 | 1233 | |
1234 | - if ( $echo ) { |
|
1234 | + if ($echo) { |
|
1235 | 1235 | echo $outout; |
1236 | 1236 | } else { |
1237 | 1237 | return $outout; |
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | -function wpinv_display_style( $invoice ) { |
|
1242 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1241 | +function wpinv_display_style($invoice) { |
|
1242 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1243 | 1243 | |
1244 | - wp_print_styles( 'open-sans' ); |
|
1245 | - wp_print_styles( 'wpinv-single-style' ); |
|
1244 | + wp_print_styles('open-sans'); |
|
1245 | + wp_print_styles('wpinv-single-style'); |
|
1246 | 1246 | } |
1247 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1247 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1248 | 1248 | |
1249 | 1249 | function wpinv_checkout_billing_details() { |
1250 | 1250 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1251 | 1251 | if (empty($invoice_id)) { |
1252 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1252 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1253 | 1253 | return null; |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1256 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1257 | 1257 | if (empty($invoice)) { |
1258 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1258 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1259 | 1259 | return null; |
1260 | 1260 | } |
1261 | 1261 | $user_id = $invoice->get_user_id(); |
1262 | 1262 | $user_info = $invoice->get_user_info(); |
1263 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1263 | + $address_info = wpinv_get_user_address($user_id); |
|
1264 | 1264 | |
1265 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1265 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1266 | 1266 | $user_info['first_name'] = $user_info['first_name']; |
1267 | 1267 | $user_info['last_name'] = $user_info['last_name']; |
1268 | 1268 | } |
1269 | 1269 | |
1270 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1270 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1271 | 1271 | $user_info['country'] = $address_info['country']; |
1272 | 1272 | $user_info['state'] = $address_info['state']; |
1273 | 1273 | $user_info['city'] = $address_info['city']; |
@@ -1283,103 +1283,103 @@ discard block |
||
1283 | 1283 | 'address' |
1284 | 1284 | ); |
1285 | 1285 | |
1286 | - foreach ( $address_fields as $field ) { |
|
1287 | - if ( empty( $user_info[$field] ) ) { |
|
1286 | + foreach ($address_fields as $field) { |
|
1287 | + if (empty($user_info[$field])) { |
|
1288 | 1288 | $user_info[$field] = $address_info[$field]; |
1289 | 1289 | } |
1290 | 1290 | } |
1291 | 1291 | |
1292 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1292 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | function wpinv_admin_get_line_items($invoice = array()) { |
1296 | 1296 | $item_quantities = wpinv_item_quantities_enabled(); |
1297 | 1297 | $use_taxes = wpinv_use_taxes(); |
1298 | 1298 | |
1299 | - if ( empty( $invoice ) ) { |
|
1299 | + if (empty($invoice)) { |
|
1300 | 1300 | return NULL; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | $cart_items = $invoice->get_cart_details(); |
1304 | - if ( empty( $cart_items ) ) { |
|
1304 | + if (empty($cart_items)) { |
|
1305 | 1305 | return NULL; |
1306 | 1306 | } |
1307 | 1307 | ob_start(); |
1308 | 1308 | |
1309 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1309 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1310 | 1310 | |
1311 | 1311 | $count = 0; |
1312 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1312 | + foreach ($cart_items as $key => $cart_item) { |
|
1313 | 1313 | $item_id = $cart_item['id']; |
1314 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1314 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1315 | 1315 | |
1316 | 1316 | if (empty($wpi_item)) { |
1317 | 1317 | continue; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
1321 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
1320 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
1321 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
1323 | 1323 | $can_remove = true; |
1324 | 1324 | |
1325 | 1325 | $summary = ''; |
1326 | 1326 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1327 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1328 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link ); |
|
1327 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1328 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link); |
|
1329 | 1329 | } |
1330 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
1330 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
1331 | 1331 | |
1332 | 1332 | $item_tax = ''; |
1333 | 1333 | $tax_rate = ''; |
1334 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1335 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1336 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1337 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
1334 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1335 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1336 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1337 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
1338 | 1338 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1339 | 1339 | } |
1340 | 1340 | $line_item_tax = $item_tax . $tax_rate; |
1341 | 1341 | |
1342 | - if ( $line_item_tax === '' ) { |
|
1342 | + if ($line_item_tax === '') { |
|
1343 | 1343 | $line_item_tax = 0; // Zero tax |
1344 | 1344 | } |
1345 | 1345 | |
1346 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1346 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1347 | 1347 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1348 | - $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 ); |
|
1349 | - if ( $summary !== '' ) { |
|
1350 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1348 | + $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); |
|
1349 | + if ($summary !== '') { |
|
1350 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1351 | 1351 | } |
1352 | 1352 | $line_item .= '</td>'; |
1353 | 1353 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1354 | 1354 | |
1355 | - if ( $item_quantities ) { |
|
1356 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1355 | + if ($item_quantities) { |
|
1356 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1357 | 1357 | $can_remove = false; |
1358 | 1358 | } |
1359 | 1359 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1360 | 1360 | } else { |
1361 | - if ( count( $cart_items ) == 1 ) { |
|
1361 | + if (count($cart_items) == 1) { |
|
1362 | 1362 | $can_remove = false; |
1363 | 1363 | } |
1364 | 1364 | } |
1365 | 1365 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1366 | 1366 | |
1367 | - if ( $use_taxes ) { |
|
1367 | + if ($use_taxes) { |
|
1368 | 1368 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1369 | 1369 | } |
1370 | 1370 | $line_item .= '<td class="action">'; |
1371 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
1371 | + if (!$invoice->is_paid() && $can_remove) { |
|
1372 | 1372 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1373 | 1373 | } |
1374 | 1374 | $line_item .= '</td>'; |
1375 | 1375 | $line_item .= '</tr>'; |
1376 | 1376 | |
1377 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1377 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1378 | 1378 | |
1379 | 1379 | $count++; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1382 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1383 | 1383 | |
1384 | 1384 | return ob_get_clean(); |
1385 | 1385 | } |
@@ -1390,35 +1390,35 @@ discard block |
||
1390 | 1390 | // Set current invoice id. |
1391 | 1391 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1392 | 1392 | |
1393 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1393 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1394 | 1394 | |
1395 | 1395 | ob_start(); |
1396 | 1396 | echo '<div id="wpinv_checkout_wrap">'; |
1397 | 1397 | |
1398 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1398 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
1399 | 1399 | ?> |
1400 | 1400 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
1401 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1401 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
1402 | 1402 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
1403 | 1403 | <?php |
1404 | - do_action( 'wpinv_checkout_form_top' ); |
|
1405 | - do_action( 'wpinv_checkout_billing_info' ); |
|
1406 | - do_action( 'wpinv_checkout_cart' ); |
|
1407 | - do_action( 'wpinv_payment_mode_select' ); |
|
1408 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
1404 | + do_action('wpinv_checkout_form_top'); |
|
1405 | + do_action('wpinv_checkout_billing_info'); |
|
1406 | + do_action('wpinv_checkout_cart'); |
|
1407 | + do_action('wpinv_payment_mode_select'); |
|
1408 | + do_action('wpinv_checkout_form_bottom') |
|
1409 | 1409 | ?> |
1410 | 1410 | </form> |
1411 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1411 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
1412 | 1412 | </div><!--end #wpinv_checkout_form_wrap--> |
1413 | 1413 | <?php |
1414 | 1414 | } else { |
1415 | - do_action( 'wpinv_cart_empty' ); |
|
1415 | + do_action('wpinv_cart_empty'); |
|
1416 | 1416 | } |
1417 | 1417 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1418 | 1418 | return ob_get_clean(); |
1419 | 1419 | } |
1420 | 1420 | |
1421 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1421 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1422 | 1422 | global $ajax_cart_details; |
1423 | 1423 | $ajax_cart_details = $cart_details; |
1424 | 1424 | /* |
@@ -1433,25 +1433,25 @@ discard block |
||
1433 | 1433 | } |
1434 | 1434 | */ |
1435 | 1435 | ob_start(); |
1436 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1436 | + do_action('wpinv_before_checkout_cart'); |
|
1437 | 1437 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1438 | 1438 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1439 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1439 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1440 | 1440 | echo '</div>'; |
1441 | 1441 | echo '</div>'; |
1442 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1442 | + do_action('wpinv_after_checkout_cart'); |
|
1443 | 1443 | $content = ob_get_clean(); |
1444 | 1444 | |
1445 | - if ( $echo ) { |
|
1445 | + if ($echo) { |
|
1446 | 1446 | echo $content; |
1447 | 1447 | } else { |
1448 | 1448 | return $content; |
1449 | 1449 | } |
1450 | 1450 | } |
1451 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1451 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1452 | 1452 | |
1453 | 1453 | function wpinv_empty_cart_message() { |
1454 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1454 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1455 | 1455 | } |
1456 | 1456 | |
1457 | 1457 | /** |
@@ -1463,91 +1463,91 @@ discard block |
||
1463 | 1463 | function wpinv_empty_checkout_cart() { |
1464 | 1464 | echo wpinv_empty_cart_message(); |
1465 | 1465 | } |
1466 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1466 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1467 | 1467 | |
1468 | 1468 | function wpinv_save_cart_button() { |
1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1469 | + if (wpinv_is_cart_saving_disabled()) |
|
1470 | 1470 | return; |
1471 | 1471 | ?> |
1472 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1472 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
1473 | 1473 | <?php |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | function wpinv_update_cart_button() { |
1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
1477 | + if (!wpinv_item_quantities_enabled()) |
|
1478 | 1478 | return; |
1479 | 1479 | ?> |
1480 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1480 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1481 | 1481 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1482 | 1482 | <?php |
1483 | 1483 | } |
1484 | 1484 | |
1485 | 1485 | function wpinv_checkout_cart_columns() { |
1486 | 1486 | $default = 3; |
1487 | - if ( wpinv_item_quantities_enabled() ) { |
|
1487 | + if (wpinv_item_quantities_enabled()) { |
|
1488 | 1488 | $default++; |
1489 | 1489 | } |
1490 | 1490 | |
1491 | - if ( wpinv_use_taxes() ) { |
|
1491 | + if (wpinv_use_taxes()) { |
|
1492 | 1492 | $default++; |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1495 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1496 | 1496 | } |
1497 | 1497 | |
1498 | 1498 | function wpinv_display_cart_messages() { |
1499 | 1499 | global $wpi_session; |
1500 | 1500 | |
1501 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1501 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1502 | 1502 | |
1503 | - if ( $messages ) { |
|
1504 | - foreach ( $messages as $message_id => $message ) { |
|
1503 | + if ($messages) { |
|
1504 | + foreach ($messages as $message_id => $message) { |
|
1505 | 1505 | // Try and detect what type of message this is |
1506 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1506 | + if (strpos(strtolower($message), 'error')) { |
|
1507 | 1507 | $type = 'error'; |
1508 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1508 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1509 | 1509 | $type = 'success'; |
1510 | 1510 | } else { |
1511 | 1511 | $type = 'info'; |
1512 | 1512 | } |
1513 | 1513 | |
1514 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1514 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1515 | 1515 | |
1516 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1516 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1517 | 1517 | // Loop message codes and display messages |
1518 | 1518 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1519 | 1519 | echo '</div>'; |
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | // Remove all of the cart saving messages |
1523 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1523 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1524 | 1524 | } |
1525 | 1525 | } |
1526 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1526 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1527 | 1527 | |
1528 | 1528 | function wpinv_discount_field() { |
1529 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1529 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1530 | 1530 | return; // Only show before a payment method has been selected if ajax is disabled |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - if ( !wpinv_is_checkout() ) { |
|
1533 | + if (!wpinv_is_checkout()) { |
|
1534 | 1534 | return; |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1537 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1538 | 1538 | ?> |
1539 | 1539 | <div id="wpinv-discount-field" class="panel panel-default"> |
1540 | 1540 | <div class="panel-body"> |
1541 | 1541 | <p> |
1542 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1543 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1542 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1543 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1544 | 1544 | </p> |
1545 | 1545 | <div class="form-group row"> |
1546 | 1546 | <div class="col-sm-4"> |
1547 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1547 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1548 | 1548 | </div> |
1549 | 1549 | <div class="col-sm-3"> |
1550 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1550 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1551 | 1551 | </div> |
1552 | 1552 | <div style="clear:both"></div> |
1553 | 1553 | <div class="col-sm-12 wpinv-discount-msg"> |
@@ -1560,10 +1560,10 @@ discard block |
||
1560 | 1560 | <?php |
1561 | 1561 | } |
1562 | 1562 | } |
1563 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1563 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1564 | 1564 | |
1565 | 1565 | function wpinv_agree_to_terms_js() { |
1566 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1566 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1567 | 1567 | ?> |
1568 | 1568 | <script type="text/javascript"> |
1569 | 1569 | jQuery(document).ready(function($){ |
@@ -1578,126 +1578,126 @@ discard block |
||
1578 | 1578 | <?php |
1579 | 1579 | } |
1580 | 1580 | } |
1581 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1581 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1582 | 1582 | |
1583 | 1583 | function wpinv_payment_mode_select() { |
1584 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1585 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1584 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1585 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1586 | 1586 | $page_URL = wpinv_get_current_page_url(); |
1587 | - $invoice = wpinv_get_invoice( 0, true ); |
|
1587 | + $invoice = wpinv_get_invoice(0, true); |
|
1588 | 1588 | |
1589 | 1589 | do_action('wpinv_payment_mode_top'); |
1590 | 1590 | $invoice_id = (int)$invoice->ID; |
1591 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1591 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1592 | 1592 | ?> |
1593 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>> |
|
1594 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1593 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>> |
|
1594 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1595 | 1595 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1596 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1596 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
1597 | 1597 | <div class="panel-body list-group wpi-payment_methods"> |
1598 | 1598 | <?php |
1599 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1599 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1600 | 1600 | |
1601 | - if(!empty($gateways)){ |
|
1602 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1603 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1604 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1605 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1601 | + if (!empty($gateways)) { |
|
1602 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1603 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1604 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1605 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1606 | 1606 | ?> |
1607 | 1607 | <div class="list-group-item"> |
1608 | 1608 | <div class="radio"> |
1609 | - <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['checkout_label'] ); ?></label> |
|
1609 | + <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['checkout_label']); ?></label> |
|
1610 | 1610 | </div> |
1611 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1612 | - <?php if ( !empty( $description ) ) { ?> |
|
1613 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1611 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1612 | + <?php if (!empty($description)) { ?> |
|
1613 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
1614 | 1614 | <?php } ?> |
1615 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1615 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1616 | 1616 | </div> |
1617 | 1617 | </div> |
1618 | 1618 | <?php |
1619 | 1619 | } |
1620 | - }else{ |
|
1621 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
1620 | + } else { |
|
1621 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1624 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1625 | 1625 | ?> |
1626 | 1626 | </div> |
1627 | 1627 | </div> |
1628 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1628 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1629 | 1629 | </div> |
1630 | 1630 | <?php |
1631 | 1631 | do_action('wpinv_payment_mode_bottom'); |
1632 | 1632 | } |
1633 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1633 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1634 | 1634 | |
1635 | 1635 | function wpinv_checkout_billing_info() { |
1636 | - if ( wpinv_is_checkout() ) { |
|
1636 | + if (wpinv_is_checkout()) { |
|
1637 | 1637 | $logged_in = is_user_logged_in(); |
1638 | 1638 | $billing_details = wpinv_checkout_billing_details(); |
1639 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1639 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1640 | 1640 | ?> |
1641 | 1641 | <div id="wpinv-fields" class="clearfix"> |
1642 | 1642 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1643 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1643 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1644 | 1644 | <div id="wpinv-fields-box" class="panel-body"> |
1645 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1645 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1646 | 1646 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1647 | - <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> |
|
1647 | + <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> |
|
1648 | 1648 | <?php |
1649 | - echo wpinv_html_text( array( |
|
1649 | + echo wpinv_html_text(array( |
|
1650 | 1650 | 'id' => 'wpinv_first_name', |
1651 | 1651 | 'name' => 'wpinv_first_name', |
1652 | 1652 | 'value' => $billing_details['first_name'], |
1653 | 1653 | 'class' => 'wpi-input form-control required', |
1654 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1655 | - 'required' => (bool)wpinv_get_option( 'fname_mandatory' ), |
|
1656 | - ) ); |
|
1654 | + 'placeholder' => __('First name', 'invoicing'), |
|
1655 | + 'required' => (bool)wpinv_get_option('fname_mandatory'), |
|
1656 | + )); |
|
1657 | 1657 | ?> |
1658 | 1658 | </p> |
1659 | 1659 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1660 | - <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> |
|
1660 | + <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> |
|
1661 | 1661 | <?php |
1662 | - echo wpinv_html_text( array( |
|
1662 | + echo wpinv_html_text(array( |
|
1663 | 1663 | 'id' => 'wpinv_last_name', |
1664 | 1664 | 'name' => 'wpinv_last_name', |
1665 | 1665 | 'value' => $billing_details['last_name'], |
1666 | 1666 | 'class' => 'wpi-input form-control', |
1667 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1668 | - 'required' => (bool)wpinv_get_option( 'lname_mandatory' ), |
|
1669 | - ) ); |
|
1667 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1668 | + 'required' => (bool)wpinv_get_option('lname_mandatory'), |
|
1669 | + )); |
|
1670 | 1670 | ?> |
1671 | 1671 | </p> |
1672 | 1672 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1673 | - <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> |
|
1673 | + <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> |
|
1674 | 1674 | <?php |
1675 | - echo wpinv_html_text( array( |
|
1675 | + echo wpinv_html_text(array( |
|
1676 | 1676 | 'id' => 'wpinv_address', |
1677 | 1677 | 'name' => 'wpinv_address', |
1678 | 1678 | 'value' => $billing_details['address'], |
1679 | 1679 | 'class' => 'wpi-input form-control required', |
1680 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1681 | - 'required' => (bool)wpinv_get_option( 'address_mandatory' ), |
|
1682 | - ) ); |
|
1680 | + 'placeholder' => __('Address', 'invoicing'), |
|
1681 | + 'required' => (bool)wpinv_get_option('address_mandatory'), |
|
1682 | + )); |
|
1683 | 1683 | ?> |
1684 | 1684 | </p> |
1685 | 1685 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1686 | - <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> |
|
1686 | + <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> |
|
1687 | 1687 | <?php |
1688 | - echo wpinv_html_text( array( |
|
1688 | + echo wpinv_html_text(array( |
|
1689 | 1689 | 'id' => 'wpinv_city', |
1690 | 1690 | 'name' => 'wpinv_city', |
1691 | 1691 | 'value' => $billing_details['city'], |
1692 | 1692 | 'class' => 'wpi-input form-control required', |
1693 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1694 | - 'required' => (bool)wpinv_get_option( 'city_mandatory' ), |
|
1695 | - ) ); |
|
1693 | + 'placeholder' => __('City', 'invoicing'), |
|
1694 | + 'required' => (bool)wpinv_get_option('city_mandatory'), |
|
1695 | + )); |
|
1696 | 1696 | ?> |
1697 | 1697 | </p> |
1698 | 1698 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1699 | - <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> |
|
1700 | - <?php echo wpinv_html_select( array( |
|
1699 | + <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> |
|
1700 | + <?php echo wpinv_html_select(array( |
|
1701 | 1701 | 'options' => wpinv_get_country_list(), |
1702 | 1702 | 'name' => 'wpinv_country', |
1703 | 1703 | 'id' => 'wpinv_country', |
@@ -1705,16 +1705,16 @@ discard block |
||
1705 | 1705 | 'show_option_all' => false, |
1706 | 1706 | 'show_option_none' => false, |
1707 | 1707 | 'class' => 'wpi-input form-control required', |
1708 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1709 | - 'required' => (bool)wpinv_get_option( 'country_mandatory' ), |
|
1710 | - ) ); ?> |
|
1708 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1709 | + 'required' => (bool)wpinv_get_option('country_mandatory'), |
|
1710 | + )); ?> |
|
1711 | 1711 | </p> |
1712 | 1712 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1713 | - <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> |
|
1713 | + <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> |
|
1714 | 1714 | <?php |
1715 | - $states = wpinv_get_country_states( $selected_country ); |
|
1716 | - if( !empty( $states ) ) { |
|
1717 | - echo wpinv_html_select( array( |
|
1715 | + $states = wpinv_get_country_states($selected_country); |
|
1716 | + if (!empty($states)) { |
|
1717 | + echo wpinv_html_select(array( |
|
1718 | 1718 | 'options' => $states, |
1719 | 1719 | 'name' => 'wpinv_state', |
1720 | 1720 | 'id' => 'wpinv_state', |
@@ -1722,61 +1722,61 @@ discard block |
||
1722 | 1722 | 'show_option_all' => false, |
1723 | 1723 | 'show_option_none' => false, |
1724 | 1724 | 'class' => 'wpi-input form-control required', |
1725 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1726 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
1727 | - ) ); |
|
1725 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1726 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
1727 | + )); |
|
1728 | 1728 | } else { |
1729 | - echo wpinv_html_text( array( |
|
1729 | + echo wpinv_html_text(array( |
|
1730 | 1730 | 'name' => 'wpinv_state', |
1731 | 1731 | 'value' => $billing_details['state'], |
1732 | 1732 | 'id' => 'wpinv_state', |
1733 | 1733 | 'class' => 'wpi-input form-control required', |
1734 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1735 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
1736 | - ) ); |
|
1734 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1735 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
1736 | + )); |
|
1737 | 1737 | } |
1738 | 1738 | ?> |
1739 | 1739 | </p> |
1740 | 1740 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1741 | - <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> |
|
1741 | + <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> |
|
1742 | 1742 | <?php |
1743 | - echo wpinv_html_text( array( |
|
1743 | + echo wpinv_html_text(array( |
|
1744 | 1744 | 'name' => 'wpinv_zip', |
1745 | 1745 | 'value' => $billing_details['zip'], |
1746 | 1746 | 'id' => 'wpinv_zip', |
1747 | 1747 | 'class' => 'wpi-input form-control', |
1748 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1749 | - 'required' => (bool)wpinv_get_option( 'zip_mandatory' ), |
|
1750 | - ) ); |
|
1748 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1749 | + 'required' => (bool)wpinv_get_option('zip_mandatory'), |
|
1750 | + )); |
|
1751 | 1751 | ?> |
1752 | 1752 | </p> |
1753 | 1753 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1754 | - <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> |
|
1754 | + <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> |
|
1755 | 1755 | <?php |
1756 | - echo wpinv_html_text( array( |
|
1756 | + echo wpinv_html_text(array( |
|
1757 | 1757 | 'id' => 'wpinv_phone', |
1758 | 1758 | 'name' => 'wpinv_phone', |
1759 | 1759 | 'value' => $billing_details['phone'], |
1760 | 1760 | 'class' => 'wpi-input form-control', |
1761 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1762 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1763 | - ) ); |
|
1761 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1762 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
1763 | + )); |
|
1764 | 1764 | ?> |
1765 | 1765 | </p> |
1766 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1766 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1767 | 1767 | <div class="clearfix"></div> |
1768 | 1768 | </div> |
1769 | 1769 | </div> |
1770 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1770 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1771 | 1771 | </div> |
1772 | 1772 | <?php |
1773 | 1773 | } |
1774 | 1774 | } |
1775 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1775 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1776 | 1776 | |
1777 | 1777 | function wpinv_checkout_hidden_fields() { |
1778 | 1778 | ?> |
1779 | - <?php if ( is_user_logged_in() ) { ?> |
|
1779 | + <?php if (is_user_logged_in()) { ?> |
|
1780 | 1780 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1781 | 1781 | <?php } ?> |
1782 | 1782 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1786,9 +1786,9 @@ discard block |
||
1786 | 1786 | function wpinv_checkout_button_purchase() { |
1787 | 1787 | ob_start(); |
1788 | 1788 | ?> |
1789 | - <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' ) ?>"/> |
|
1789 | + <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') ?>"/> |
|
1790 | 1790 | <?php |
1791 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1791 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1792 | 1792 | } |
1793 | 1793 | |
1794 | 1794 | function wpinv_checkout_total() { |
@@ -1797,96 +1797,96 @@ discard block |
||
1797 | 1797 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1798 | 1798 | <div class="panel-body"> |
1799 | 1799 | <?php |
1800 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1800 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1801 | 1801 | ?> |
1802 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1802 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1803 | 1803 | <?php |
1804 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1804 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1805 | 1805 | ?> |
1806 | 1806 | </div> |
1807 | 1807 | </div> |
1808 | 1808 | <?php |
1809 | 1809 | } |
1810 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1810 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1811 | 1811 | |
1812 | 1812 | function wpinv_checkout_submit() { |
1813 | 1813 | ?> |
1814 | 1814 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1815 | 1815 | <div class="panel-body text-center"> |
1816 | 1816 | <?php |
1817 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1817 | + do_action('wpinv_purchase_form_before_submit'); |
|
1818 | 1818 | wpinv_checkout_hidden_fields(); |
1819 | 1819 | echo wpinv_checkout_button_purchase(); |
1820 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1820 | + do_action('wpinv_purchase_form_after_submit'); |
|
1821 | 1821 | ?> |
1822 | 1822 | </div> |
1823 | 1823 | </div> |
1824 | 1824 | <?php |
1825 | 1825 | } |
1826 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1826 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1827 | 1827 | |
1828 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1829 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1828 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1829 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1830 | 1830 | |
1831 | - if ( empty( $invoice ) ) { |
|
1831 | + if (empty($invoice)) { |
|
1832 | 1832 | return NULL; |
1833 | 1833 | } |
1834 | 1834 | |
1835 | 1835 | $billing_details = $invoice->get_user_info(); |
1836 | 1836 | $address_row = ''; |
1837 | - if ( $address = $billing_details['address'] ) { |
|
1838 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
1837 | + if ($address = $billing_details['address']) { |
|
1838 | + $address_row .= wpautop(wp_kses_post($address)); |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | 1841 | $address_fields = array(); |
1842 | - if ( !empty( $billing_details['city'] ) ) { |
|
1842 | + if (!empty($billing_details['city'])) { |
|
1843 | 1843 | $address_fields[] = $billing_details['city']; |
1844 | 1844 | } |
1845 | 1845 | |
1846 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1847 | - if ( !empty( $billing_details['state'] ) ) { |
|
1848 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1846 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
1847 | + if (!empty($billing_details['state'])) { |
|
1848 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
1849 | 1849 | } |
1850 | 1850 | |
1851 | - if ( !empty( $billing_country ) ) { |
|
1852 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
1851 | + if (!empty($billing_country)) { |
|
1852 | + $address_fields[] = wpinv_country_name($billing_country); |
|
1853 | 1853 | } |
1854 | 1854 | |
1855 | - if ( !empty( $address_fields ) ) { |
|
1856 | - $address_fields = implode( ", ", $address_fields ); |
|
1855 | + if (!empty($address_fields)) { |
|
1856 | + $address_fields = implode(", ", $address_fields); |
|
1857 | 1857 | |
1858 | - if ( !empty( $billing_details['zip'] ) ) { |
|
1858 | + if (!empty($billing_details['zip'])) { |
|
1859 | 1859 | $address_fields .= ' ' . $billing_details['zip']; |
1860 | 1860 | } |
1861 | 1861 | |
1862 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1862 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1863 | 1863 | } |
1864 | 1864 | ob_start(); |
1865 | 1865 | ?> |
1866 | 1866 | <table class="table table-bordered table-sm wpi-billing-details"> |
1867 | 1867 | <tbody> |
1868 | 1868 | <tr class="wpi-receipt-name"> |
1869 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1870 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1869 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1870 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1871 | 1871 | </tr> |
1872 | 1872 | <tr class="wpi-receipt-email"> |
1873 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1874 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1873 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1874 | + <td><?php echo $billing_details['email']; ?></td> |
|
1875 | 1875 | </tr> |
1876 | - <?php if ( $billing_details['company'] ) { ?> |
|
1876 | + <?php if ($billing_details['company']) { ?> |
|
1877 | 1877 | <tr class="wpi-receipt-company"> |
1878 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1879 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1878 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
1879 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
1880 | 1880 | </tr> |
1881 | 1881 | <?php } ?> |
1882 | 1882 | <tr class="wpi-receipt-address"> |
1883 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1884 | - <td><?php echo $address_row ;?></td> |
|
1883 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1884 | + <td><?php echo $address_row; ?></td> |
|
1885 | 1885 | </tr> |
1886 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1886 | + <?php if ($billing_details['phone']) { ?> |
|
1887 | 1887 | <tr class="wpi-receipt-phone"> |
1888 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1889 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1888 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1889 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1890 | 1890 | </tr> |
1891 | 1891 | <?php } ?> |
1892 | 1892 | </tbody> |
@@ -1894,98 +1894,98 @@ discard block |
||
1894 | 1894 | <?php |
1895 | 1895 | $output = ob_get_clean(); |
1896 | 1896 | |
1897 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1897 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1898 | 1898 | |
1899 | 1899 | echo $output; |
1900 | 1900 | } |
1901 | 1901 | |
1902 | -function wpinv_filter_success_page_content( $content ) { |
|
1903 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1904 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1905 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1902 | +function wpinv_filter_success_page_content($content) { |
|
1903 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1904 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1905 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1906 | 1906 | } |
1907 | 1907 | } |
1908 | 1908 | |
1909 | 1909 | return $content; |
1910 | 1910 | } |
1911 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1911 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1912 | 1912 | |
1913 | -function wpinv_receipt_actions( $invoice ) { |
|
1914 | - if ( !empty( $invoice ) ) { |
|
1913 | +function wpinv_receipt_actions($invoice) { |
|
1914 | + if (!empty($invoice)) { |
|
1915 | 1915 | $actions = array( |
1916 | 1916 | 'print' => array( |
1917 | 1917 | 'url' => $invoice->get_view_url(), |
1918 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1918 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1919 | 1919 | 'class' => 'btn-primary', |
1920 | 1920 | ), |
1921 | 1921 | 'history' => array( |
1922 | 1922 | 'url' => wpinv_get_history_page_uri(), |
1923 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1923 | + 'name' => __('Invoice History', 'invoicing'), |
|
1924 | 1924 | 'class' => 'btn-warning', |
1925 | 1925 | ) |
1926 | 1926 | ); |
1927 | 1927 | |
1928 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1928 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1929 | 1929 | |
1930 | - if ( !empty( $actions ) ) { |
|
1930 | + if (!empty($actions)) { |
|
1931 | 1931 | ?> |
1932 | 1932 | <div class="wpinv-receipt-actions text-right"> |
1933 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1934 | - <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> |
|
1933 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1934 | + <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> |
|
1935 | 1935 | <?php } ?> |
1936 | 1936 | </div> |
1937 | 1937 | <?php |
1938 | 1938 | } |
1939 | 1939 | } |
1940 | 1940 | } |
1941 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1941 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1942 | 1942 | |
1943 | -function wpinv_invoice_link( $invoice_id ) { |
|
1944 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1943 | +function wpinv_invoice_link($invoice_id) { |
|
1944 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1945 | 1945 | |
1946 | - if ( empty( $invoice ) ) { |
|
1946 | + if (empty($invoice)) { |
|
1947 | 1947 | return NULL; |
1948 | 1948 | } |
1949 | 1949 | |
1950 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1950 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1951 | 1951 | |
1952 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1952 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1953 | 1953 | } |
1954 | 1954 | |
1955 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1956 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1955 | +function wpinv_invoice_subscription_details($invoice) { |
|
1956 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1957 | 1957 | $total_payments = (int)$invoice->get_total_payments(); |
1958 | 1958 | $payments = $invoice->get_child_payments(); |
1959 | 1959 | |
1960 | 1960 | $subscription = $invoice->get_subscription_data(); |
1961 | 1961 | |
1962 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
1962 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
1963 | 1963 | return; |
1964 | 1964 | } |
1965 | 1965 | |
1966 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
1967 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
1966 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
1967 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
1968 | 1968 | |
1969 | 1969 | $subscription_status = $invoice->get_subscription_status(); |
1970 | 1970 | |
1971 | 1971 | $status_desc = ''; |
1972 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
1973 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
1974 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
1975 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
1972 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
1973 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
1974 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
1975 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
1976 | 1976 | } |
1977 | 1977 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
1978 | 1978 | ?> |
1979 | 1979 | <div class="wpinv-subscriptions-details"> |
1980 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1980 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1981 | 1981 | <table class="table"> |
1982 | 1982 | <thead> |
1983 | 1983 | <tr> |
1984 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1985 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1986 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1987 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1988 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1984 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1985 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1986 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1987 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1988 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1989 | 1989 | </tr> |
1990 | 1990 | </thead> |
1991 | 1991 | <tbody> |
@@ -1994,32 +1994,32 @@ discard block |
||
1994 | 1994 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
1995 | 1995 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
1996 | 1996 | <td class="text-center"><?php echo $times_billed; ?></td> |
1997 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
1997 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
1998 | 1998 | <?php echo $status_desc; ?> |
1999 | 1999 | </td> |
2000 | 2000 | </tr> |
2001 | 2001 | </tbody> |
2002 | 2002 | </table> |
2003 | 2003 | </div> |
2004 | - <?php if ( !empty( $payments ) ) { ?> |
|
2004 | + <?php if (!empty($payments)) { ?> |
|
2005 | 2005 | <div class="wpinv-renewal-payments"> |
2006 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
2006 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
2007 | 2007 | <table class="table"> |
2008 | 2008 | <thead> |
2009 | 2009 | <tr> |
2010 | 2010 | <th>#</th> |
2011 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2012 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2013 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2011 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
2012 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
2013 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
2014 | 2014 | </tr> |
2015 | 2015 | </thead> |
2016 | 2016 | <tbody> |
2017 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
2017 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
2018 | 2018 | <tr> |
2019 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
2020 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2021 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2022 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2019 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
2020 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
2021 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
2022 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
2023 | 2023 | </tr> |
2024 | 2024 | <?php } ?> |
2025 | 2025 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2031,52 +2031,52 @@ discard block |
||
2031 | 2031 | } |
2032 | 2032 | } |
2033 | 2033 | |
2034 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
2035 | - if ( empty( $invoice ) ) { |
|
2034 | +function wpinv_cart_total_label($label, $invoice) { |
|
2035 | + if (empty($invoice)) { |
|
2036 | 2036 | return $label; |
2037 | 2037 | } |
2038 | 2038 | |
2039 | 2039 | $prefix_label = ''; |
2040 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2041 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2042 | - } else if ( $invoice->is_renewal() ) { |
|
2043 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2040 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
2041 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
2042 | + } else if ($invoice->is_renewal()) { |
|
2043 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2044 | 2044 | } |
2045 | 2045 | |
2046 | - if ( $prefix_label != '' ) { |
|
2047 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2046 | + if ($prefix_label != '') { |
|
2047 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2048 | 2048 | } |
2049 | 2049 | |
2050 | 2050 | return $label; |
2051 | 2051 | } |
2052 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2053 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2054 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2052 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2053 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2054 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2055 | 2055 | |
2056 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2056 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2057 | 2057 | |
2058 | -function wpinv_invoice_print_description( $invoice ) { |
|
2059 | - if ( empty( $invoice ) ) { |
|
2058 | +function wpinv_invoice_print_description($invoice) { |
|
2059 | + if (empty($invoice)) { |
|
2060 | 2060 | return NULL; |
2061 | 2061 | } |
2062 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2062 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2063 | 2063 | ?> |
2064 | 2064 | <div class="row wpinv-lower"> |
2065 | 2065 | <div class="col-sm-12 wpinv-description"> |
2066 | - <?php echo wpautop( $description ); ?> |
|
2066 | + <?php echo wpautop($description); ?> |
|
2067 | 2067 | </div> |
2068 | 2068 | </div> |
2069 | 2069 | <?php |
2070 | 2070 | } |
2071 | 2071 | } |
2072 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2072 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2073 | 2073 | |
2074 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2075 | - if ( empty( $invoice ) ) { |
|
2074 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2075 | + if (empty($invoice)) { |
|
2076 | 2076 | return NULL; |
2077 | 2077 | } |
2078 | 2078 | |
2079 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2079 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2080 | 2080 | ?> |
2081 | 2081 | <div class="row wpinv-payments"> |
2082 | 2082 | <div class="col-sm-12"> |
@@ -2088,43 +2088,43 @@ discard block |
||
2088 | 2088 | } |
2089 | 2089 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2090 | 2090 | |
2091 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2092 | - if ( empty( $note ) ) { |
|
2091 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2092 | + if (empty($note)) { |
|
2093 | 2093 | return NULL; |
2094 | 2094 | } |
2095 | 2095 | |
2096 | - if ( is_int( $note ) ) { |
|
2097 | - $note = get_comment( $note ); |
|
2096 | + if (is_int($note)) { |
|
2097 | + $note = get_comment($note); |
|
2098 | 2098 | } |
2099 | 2099 | |
2100 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2100 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2101 | 2101 | return NULL; |
2102 | 2102 | } |
2103 | 2103 | |
2104 | - $note_classes = array( 'note' ); |
|
2105 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2106 | - $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : ''; |
|
2107 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2108 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2104 | + $note_classes = array('note'); |
|
2105 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2106 | + $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : ''; |
|
2107 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2108 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2109 | 2109 | |
2110 | 2110 | ob_start(); |
2111 | 2111 | ?> |
2112 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2112 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2113 | 2113 | <div class="note_content"> |
2114 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2114 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2115 | 2115 | </div> |
2116 | 2116 | <p class="meta"> |
2117 | - <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> |
|
2118 | - <?php if($note->comment_author !== 'System') {?> |
|
2119 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2117 | + <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> |
|
2118 | + <?php if ($note->comment_author !== 'System') {?> |
|
2119 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2120 | 2120 | <?php } ?> |
2121 | 2121 | </p> |
2122 | 2122 | </li> |
2123 | 2123 | <?php |
2124 | 2124 | $note_content = ob_get_clean(); |
2125 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2125 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2126 | 2126 | |
2127 | - if ( $echo ) { |
|
2127 | + if ($echo) { |
|
2128 | 2128 | echo $note_content; |
2129 | 2129 | } else { |
2130 | 2130 | return $note_content; |
@@ -7,12 +7,12 @@ 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_init_transactional_emails() { |
15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
16 | 16 | 'wpinv_status_pending_to_processing', |
17 | 17 | 'wpinv_status_pending_to_publish', |
18 | 18 | 'wpinv_status_pending_to_cancelled', |
@@ -28,79 +28,79 @@ discard block |
||
28 | 28 | 'wpinv_fully_refunded', |
29 | 29 | 'wpinv_partially_refunded', |
30 | 30 | 'wpinv_new_invoice_note' |
31 | - ) ); |
|
31 | + )); |
|
32 | 32 | |
33 | - foreach ( $email_actions as $action ) { |
|
34 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
33 | + foreach ($email_actions as $action) { |
|
34 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
35 | 35 | } |
36 | 36 | } |
37 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
37 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
38 | 38 | |
39 | 39 | // New invoice email |
40 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
41 | -add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
42 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
43 | -add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
44 | -add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
45 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
40 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
41 | +add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
42 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
43 | +add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
44 | +add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
45 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
46 | 46 | |
47 | 47 | // Cancelled invoice email |
48 | -add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
49 | -add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
48 | +add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
49 | +add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
50 | 50 | |
51 | 51 | // Failed invoice email |
52 | -add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
53 | -add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
52 | +add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
53 | +add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
54 | 54 | |
55 | 55 | // On hold invoice email |
56 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
57 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
56 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
57 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
58 | 58 | |
59 | 59 | // Processing invoice email |
60 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' ); |
|
60 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification'); |
|
61 | 61 | |
62 | 62 | // Paid invoice email |
63 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
63 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
64 | 64 | |
65 | 65 | // Refunded invoice email |
66 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
67 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
66 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
67 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
68 | 68 | |
69 | 69 | // Invoice note |
70 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
70 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
71 | 71 | |
72 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
73 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
74 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
75 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
76 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
77 | -add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 ); |
|
72 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
73 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
74 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
75 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
76 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
77 | +add_action('wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4); |
|
78 | 78 | |
79 | 79 | function wpinv_send_transactional_email() { |
80 | 80 | $args = func_get_args(); |
81 | 81 | $function = current_filter() . '_notification'; |
82 | - do_action_ref_array( $function, $args ); |
|
82 | + do_action_ref_array($function, $args); |
|
83 | 83 | } |
84 | 84 | |
85 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
85 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
86 | 86 | global $wpinv_email_search, $wpinv_email_replace; |
87 | 87 | |
88 | 88 | $email_type = 'new_invoice'; |
89 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
89 | + if (!wpinv_email_is_enabled($email_type)) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
94 | - if ( empty( $invoice ) ) { |
|
93 | + $invoice = wpinv_get_invoice($invoice_id); |
|
94 | + if (empty($invoice)) { |
|
95 | 95 | return false; |
96 | 96 | } |
97 | 97 | |
98 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
98 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | |
102 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
103 | - if ( !is_email( $recipient ) ) { |
|
102 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
103 | + if (!is_email($recipient)) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
@@ -117,41 +117,41 @@ discard block |
||
117 | 117 | $wpinv_email_search = $search; |
118 | 118 | $wpinv_email_replace = $replace; |
119 | 119 | |
120 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
121 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
122 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
123 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
120 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
121 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
122 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
123 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
124 | 124 | |
125 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
125 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
126 | 126 | 'invoice' => $invoice, |
127 | 127 | 'email_type' => $email_type, |
128 | 128 | 'email_heading' => $email_heading, |
129 | 129 | 'sent_to_admin' => true, |
130 | 130 | 'plain_text' => false, |
131 | - ) ); |
|
131 | + )); |
|
132 | 132 | |
133 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
133 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
136 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
137 | 137 | global $wpinv_email_search, $wpinv_email_replace; |
138 | 138 | |
139 | 139 | $email_type = 'cancelled_invoice'; |
140 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
140 | + if (!wpinv_email_is_enabled($email_type)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
145 | - if ( empty( $invoice ) ) { |
|
144 | + $invoice = wpinv_get_invoice($invoice_id); |
|
145 | + if (empty($invoice)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
149 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
149 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | |
153 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
154 | - if ( !is_email( $recipient ) ) { |
|
153 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
154 | + if (!is_email($recipient)) { |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
@@ -168,41 +168,41 @@ discard block |
||
168 | 168 | $wpinv_email_search = $search; |
169 | 169 | $wpinv_email_replace = $replace; |
170 | 170 | |
171 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
172 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
173 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
174 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
171 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
172 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
173 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
174 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
175 | 175 | |
176 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
176 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
177 | 177 | 'invoice' => $invoice, |
178 | 178 | 'email_type' => $email_type, |
179 | 179 | 'email_heading' => $email_heading, |
180 | 180 | 'sent_to_admin' => true, |
181 | 181 | 'plain_text' => false, |
182 | - ) ); |
|
182 | + )); |
|
183 | 183 | |
184 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
184 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
185 | 185 | } |
186 | 186 | |
187 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
187 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
188 | 188 | global $wpinv_email_search, $wpinv_email_replace; |
189 | 189 | |
190 | 190 | $email_type = 'failed_invoice'; |
191 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
191 | + if (!wpinv_email_is_enabled($email_type)) { |
|
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
195 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
196 | - if ( empty( $invoice ) ) { |
|
195 | + $invoice = wpinv_get_invoice($invoice_id); |
|
196 | + if (empty($invoice)) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
200 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
205 | - if ( !is_email( $recipient ) ) { |
|
204 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
205 | + if (!is_email($recipient)) { |
|
206 | 206 | return false; |
207 | 207 | } |
208 | 208 | |
@@ -219,41 +219,41 @@ discard block |
||
219 | 219 | $wpinv_email_search = $search; |
220 | 220 | $wpinv_email_replace = $replace; |
221 | 221 | |
222 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
223 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
224 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
225 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
222 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
223 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
224 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
225 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
226 | 226 | |
227 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
227 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
228 | 228 | 'invoice' => $invoice, |
229 | 229 | 'email_type' => $email_type, |
230 | 230 | 'email_heading' => $email_heading, |
231 | 231 | 'sent_to_admin' => true, |
232 | 232 | 'plain_text' => false, |
233 | - ) ); |
|
233 | + )); |
|
234 | 234 | |
235 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
235 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
236 | 236 | } |
237 | 237 | |
238 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
238 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
239 | 239 | global $wpinv_email_search, $wpinv_email_replace; |
240 | 240 | |
241 | 241 | $email_type = 'onhold_invoice'; |
242 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
242 | + if (!wpinv_email_is_enabled($email_type)) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
247 | - if ( empty( $invoice ) ) { |
|
246 | + $invoice = wpinv_get_invoice($invoice_id); |
|
247 | + if (empty($invoice)) { |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | |
251 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
251 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | |
255 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
256 | - if ( !is_email( $recipient ) ) { |
|
255 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
256 | + if (!is_email($recipient)) { |
|
257 | 257 | return false; |
258 | 258 | } |
259 | 259 | |
@@ -270,49 +270,49 @@ discard block |
||
270 | 270 | $wpinv_email_search = $search; |
271 | 271 | $wpinv_email_replace = $replace; |
272 | 272 | |
273 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
274 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
275 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
276 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
273 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
274 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
275 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
276 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
277 | 277 | |
278 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
278 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
279 | 279 | 'invoice' => $invoice, |
280 | 280 | 'email_type' => $email_type, |
281 | 281 | 'email_heading' => $email_heading, |
282 | 282 | 'sent_to_admin' => false, |
283 | 283 | 'plain_text' => false, |
284 | - ) ); |
|
284 | + )); |
|
285 | 285 | |
286 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
286 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
287 | 287 | |
288 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
289 | - $recipient = wpinv_get_admin_email(); |
|
290 | - $subject .= ' - ADMIN BCC COPY'; |
|
291 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
288 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
289 | + $recipient = wpinv_get_admin_email(); |
|
290 | + $subject .= ' - ADMIN BCC COPY'; |
|
291 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | return $sent; |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
297 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
298 | 298 | global $wpinv_email_search, $wpinv_email_replace; |
299 | 299 | |
300 | 300 | $email_type = 'processing_invoice'; |
301 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
301 | + if (!wpinv_email_is_enabled($email_type)) { |
|
302 | 302 | return false; |
303 | 303 | } |
304 | 304 | |
305 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
306 | - if ( empty( $invoice ) ) { |
|
305 | + $invoice = wpinv_get_invoice($invoice_id); |
|
306 | + if (empty($invoice)) { |
|
307 | 307 | return false; |
308 | 308 | } |
309 | 309 | |
310 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
310 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
311 | 311 | return false; |
312 | 312 | } |
313 | 313 | |
314 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
315 | - if ( !is_email( $recipient ) ) { |
|
314 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
315 | + if (!is_email($recipient)) { |
|
316 | 316 | return false; |
317 | 317 | } |
318 | 318 | |
@@ -329,49 +329,49 @@ discard block |
||
329 | 329 | $wpinv_email_search = $search; |
330 | 330 | $wpinv_email_replace = $replace; |
331 | 331 | |
332 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
333 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
334 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
335 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
332 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
333 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
334 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
335 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
336 | 336 | |
337 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
337 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
338 | 338 | 'invoice' => $invoice, |
339 | 339 | 'email_type' => $email_type, |
340 | 340 | 'email_heading' => $email_heading, |
341 | 341 | 'sent_to_admin' => false, |
342 | 342 | 'plain_text' => false, |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | |
345 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
345 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
346 | 346 | |
347 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
348 | - $recipient = wpinv_get_admin_email(); |
|
349 | - $subject .= ' - ADMIN BCC COPY'; |
|
350 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
347 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
348 | + $recipient = wpinv_get_admin_email(); |
|
349 | + $subject .= ' - ADMIN BCC COPY'; |
|
350 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | return $sent; |
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
356 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
357 | 357 | global $wpinv_email_search, $wpinv_email_replace; |
358 | 358 | |
359 | 359 | $email_type = 'completed_invoice'; |
360 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
360 | + if (!wpinv_email_is_enabled($email_type)) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | |
364 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
365 | - if ( empty( $invoice ) ) { |
|
364 | + $invoice = wpinv_get_invoice($invoice_id); |
|
365 | + if (empty($invoice)) { |
|
366 | 366 | return false; |
367 | 367 | } |
368 | 368 | |
369 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
369 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
374 | - if ( !is_email( $recipient ) ) { |
|
373 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
374 | + if (!is_email($recipient)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
@@ -388,49 +388,49 @@ discard block |
||
388 | 388 | $wpinv_email_search = $search; |
389 | 389 | $wpinv_email_replace = $replace; |
390 | 390 | |
391 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
392 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
393 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
394 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
391 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
392 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
393 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
394 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
395 | 395 | |
396 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
396 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
397 | 397 | 'invoice' => $invoice, |
398 | 398 | 'email_type' => $email_type, |
399 | 399 | 'email_heading' => $email_heading, |
400 | 400 | 'sent_to_admin' => false, |
401 | 401 | 'plain_text' => false, |
402 | - ) ); |
|
402 | + )); |
|
403 | 403 | |
404 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
404 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
405 | 405 | |
406 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
407 | - $recipient = wpinv_get_admin_email(); |
|
408 | - $subject .= ' - ADMIN BCC COPY'; |
|
409 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
406 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
407 | + $recipient = wpinv_get_admin_email(); |
|
408 | + $subject .= ' - ADMIN BCC COPY'; |
|
409 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | return $sent; |
413 | 413 | } |
414 | 414 | |
415 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
415 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
416 | 416 | global $wpinv_email_search, $wpinv_email_replace; |
417 | 417 | |
418 | 418 | $email_type = 'refunded_invoice'; |
419 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
419 | + if (!wpinv_email_is_enabled($email_type)) { |
|
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | |
423 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
424 | - if ( empty( $invoice ) ) { |
|
423 | + $invoice = wpinv_get_invoice($invoice_id); |
|
424 | + if (empty($invoice)) { |
|
425 | 425 | return false; |
426 | 426 | } |
427 | 427 | |
428 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
428 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
429 | 429 | return false; |
430 | 430 | } |
431 | 431 | |
432 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
433 | - if ( !is_email( $recipient ) ) { |
|
432 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
433 | + if (!is_email($recipient)) { |
|
434 | 434 | return false; |
435 | 435 | } |
436 | 436 | |
@@ -447,50 +447,50 @@ discard block |
||
447 | 447 | $wpinv_email_search = $search; |
448 | 448 | $wpinv_email_replace = $replace; |
449 | 449 | |
450 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
451 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
452 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
453 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
450 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
451 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
452 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
453 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
454 | 454 | |
455 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
455 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
456 | 456 | 'invoice' => $invoice, |
457 | 457 | 'email_type' => $email_type, |
458 | 458 | 'email_heading' => $email_heading, |
459 | 459 | 'sent_to_admin' => false, |
460 | 460 | 'plain_text' => false, |
461 | 461 | 'partial_refund' => false |
462 | - ) ); |
|
462 | + )); |
|
463 | 463 | |
464 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
464 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
465 | 465 | |
466 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
467 | - $recipient = wpinv_get_admin_email(); |
|
468 | - $subject .= ' - ADMIN BCC COPY'; |
|
469 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
466 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
467 | + $recipient = wpinv_get_admin_email(); |
|
468 | + $subject .= ' - ADMIN BCC COPY'; |
|
469 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | return $sent; |
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
475 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
476 | 476 | global $wpinv_email_search, $wpinv_email_replace; |
477 | 477 | |
478 | 478 | $email_type = 'refunded_invoice'; |
479 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
479 | + if (!wpinv_email_is_enabled($email_type)) { |
|
480 | 480 | return false; |
481 | 481 | } |
482 | 482 | |
483 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
484 | - if ( empty( $invoice ) ) { |
|
483 | + $invoice = wpinv_get_invoice($invoice_id); |
|
484 | + if (empty($invoice)) { |
|
485 | 485 | return false; |
486 | 486 | } |
487 | 487 | |
488 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
488 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
489 | 489 | return false; |
490 | 490 | } |
491 | 491 | |
492 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
493 | - if ( !is_email( $recipient ) ) { |
|
492 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
493 | + if (!is_email($recipient)) { |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | |
@@ -507,53 +507,53 @@ discard block |
||
507 | 507 | $wpinv_email_search = $search; |
508 | 508 | $wpinv_email_replace = $replace; |
509 | 509 | |
510 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
511 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
512 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
513 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
510 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
511 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
512 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
513 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
514 | 514 | |
515 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
515 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
516 | 516 | 'invoice' => $invoice, |
517 | 517 | 'email_type' => $email_type, |
518 | 518 | 'email_heading' => $email_heading, |
519 | 519 | 'sent_to_admin' => false, |
520 | 520 | 'plain_text' => false, |
521 | 521 | 'partial_refund' => true |
522 | - ) ); |
|
522 | + )); |
|
523 | 523 | |
524 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
524 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
525 | 525 | |
526 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
527 | - $recipient = wpinv_get_admin_email(); |
|
528 | - $subject .= ' - ADMIN BCC COPY'; |
|
529 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
526 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
527 | + $recipient = wpinv_get_admin_email(); |
|
528 | + $subject .= ' - ADMIN BCC COPY'; |
|
529 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $sent; |
533 | 533 | } |
534 | 534 | |
535 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
535 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
536 | 536 | } |
537 | 537 | |
538 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
538 | +function wpinv_user_invoice_notification($invoice_id) { |
|
539 | 539 | global $wpinv_email_search, $wpinv_email_replace; |
540 | 540 | |
541 | 541 | $email_type = 'user_invoice'; |
542 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
542 | + if (!wpinv_email_is_enabled($email_type)) { |
|
543 | 543 | return false; |
544 | 544 | } |
545 | 545 | |
546 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
547 | - if ( empty( $invoice ) ) { |
|
546 | + $invoice = wpinv_get_invoice($invoice_id); |
|
547 | + if (empty($invoice)) { |
|
548 | 548 | return false; |
549 | 549 | } |
550 | 550 | |
551 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
551 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
552 | 552 | return false; |
553 | 553 | } |
554 | 554 | |
555 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
556 | - if ( !is_email( $recipient ) ) { |
|
555 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
556 | + if (!is_email($recipient)) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | |
@@ -570,52 +570,52 @@ discard block |
||
570 | 570 | $wpinv_email_search = $search; |
571 | 571 | $wpinv_email_replace = $replace; |
572 | 572 | |
573 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
574 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
575 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
576 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
573 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
574 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
575 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
576 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
577 | 577 | |
578 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
578 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
579 | 579 | 'invoice' => $invoice, |
580 | 580 | 'email_type' => $email_type, |
581 | 581 | 'email_heading' => $email_heading, |
582 | 582 | 'sent_to_admin' => false, |
583 | 583 | 'plain_text' => false, |
584 | - ) ); |
|
584 | + )); |
|
585 | 585 | |
586 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
586 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
587 | 587 | |
588 | - if ( $sent ) { |
|
589 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
588 | + if ($sent) { |
|
589 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
590 | 590 | } else { |
591 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
591 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
592 | 592 | } |
593 | - $invoice->add_note( $note, '', '', true ); // Add private note. |
|
593 | + $invoice->add_note($note, '', '', true); // Add private note. |
|
594 | 594 | |
595 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
596 | - $recipient = wpinv_get_admin_email(); |
|
597 | - $subject .= ' - ADMIN BCC COPY'; |
|
598 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
595 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
596 | + $recipient = wpinv_get_admin_email(); |
|
597 | + $subject .= ' - ADMIN BCC COPY'; |
|
598 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | return $sent; |
602 | 602 | } |
603 | 603 | |
604 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
604 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
605 | 605 | global $wpinv_email_search, $wpinv_email_replace; |
606 | 606 | |
607 | 607 | $email_type = 'user_note'; |
608 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
608 | + if (!wpinv_email_is_enabled($email_type)) { |
|
609 | 609 | return false; |
610 | 610 | } |
611 | 611 | |
612 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
613 | - if ( empty( $invoice ) ) { |
|
612 | + $invoice = wpinv_get_invoice($invoice_id); |
|
613 | + if (empty($invoice)) { |
|
614 | 614 | return false; |
615 | 615 | } |
616 | 616 | |
617 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
618 | - if ( !is_email( $recipient ) ) { |
|
617 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
618 | + if (!is_email($recipient)) { |
|
619 | 619 | return false; |
620 | 620 | } |
621 | 621 | |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | 'user_note' => '' |
624 | 624 | ); |
625 | 625 | |
626 | - $args = wp_parse_args( $args, $defaults ); |
|
626 | + $args = wp_parse_args($args, $defaults); |
|
627 | 627 | |
628 | 628 | $search = array(); |
629 | 629 | $search['invoice_number'] = '{invoice_number}'; |
@@ -642,46 +642,46 @@ discard block |
||
642 | 642 | $wpinv_email_search = $search; |
643 | 643 | $wpinv_email_replace = $replace; |
644 | 644 | |
645 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
646 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
647 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
648 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
645 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
646 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
647 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
648 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
649 | 649 | |
650 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
650 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
651 | 651 | 'invoice' => $invoice, |
652 | 652 | 'email_type' => $email_type, |
653 | 653 | 'email_heading' => $email_heading, |
654 | 654 | 'sent_to_admin' => false, |
655 | 655 | 'plain_text' => false, |
656 | 656 | 'customer_note' => $args['user_note'] |
657 | - ) ); |
|
657 | + )); |
|
658 | 658 | |
659 | - $content = wpinv_email_format_text( $content ); |
|
659 | + $content = wpinv_email_format_text($content); |
|
660 | 660 | |
661 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
661 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
662 | 662 | |
663 | 663 | return $sent; |
664 | 664 | } |
665 | 665 | |
666 | 666 | function wpinv_mail_get_from_address() { |
667 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
668 | - return sanitize_email( $from_address ); |
|
667 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
668 | + return sanitize_email($from_address); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | function wpinv_mail_get_from_name() { |
672 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
673 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
672 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
673 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
674 | 674 | } |
675 | 675 | |
676 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
677 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
678 | - return ( $active ? true : false ); |
|
676 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
677 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
678 | + return ($active ? true : false); |
|
679 | 679 | } |
680 | 680 | |
681 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
682 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
681 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
682 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
683 | 683 | |
684 | - switch ( $email_type ) { |
|
684 | + switch ($email_type) { |
|
685 | 685 | case 'html' : |
686 | 686 | $content_type = 'text/html'; |
687 | 687 | break; |
@@ -696,35 +696,35 @@ discard block |
||
696 | 696 | return $content_type; |
697 | 697 | } |
698 | 698 | |
699 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
700 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
701 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
702 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
699 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
700 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
701 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
702 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
703 | 703 | |
704 | - $message = wpinv_email_style_body( $message ); |
|
705 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
704 | + $message = wpinv_email_style_body($message); |
|
705 | + $message = apply_filters('wpinv_mail_content', $message); |
|
706 | 706 | |
707 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
707 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
708 | 708 | |
709 | - if ( !$sent ) { |
|
710 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
711 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
709 | + if (!$sent) { |
|
710 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
711 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
712 | 712 | } |
713 | 713 | |
714 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
715 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
716 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
714 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
715 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
716 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
717 | 717 | |
718 | 718 | return $sent; |
719 | 719 | } |
720 | 720 | |
721 | 721 | function wpinv_get_emails() { |
722 | 722 | $overdue_days_options = array(); |
723 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
724 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
723 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
724 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
725 | 725 | |
726 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
727 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
726 | + for ($i = 2; $i <= 10; $i++) { |
|
727 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | // Default, built-in gateways |
@@ -732,130 +732,130 @@ discard block |
||
732 | 732 | 'new_invoice' => array( |
733 | 733 | 'email_new_invoice_header' => array( |
734 | 734 | 'id' => 'email_new_invoice_header', |
735 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
736 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
735 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
736 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
737 | 737 | 'type' => 'header', |
738 | 738 | ), |
739 | 739 | 'email_new_invoice_active' => array( |
740 | 740 | 'id' => 'email_new_invoice_active', |
741 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
742 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
741 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
742 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
743 | 743 | 'type' => 'checkbox', |
744 | 744 | 'std' => 1 |
745 | 745 | ), |
746 | 746 | 'email_new_invoice_subject' => array( |
747 | 747 | 'id' => 'email_new_invoice_subject', |
748 | - 'name' => __( 'Subject', 'invoicing' ), |
|
749 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
748 | + 'name' => __('Subject', 'invoicing'), |
|
749 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
750 | 750 | 'type' => 'text', |
751 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
751 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
752 | 752 | 'size' => 'large' |
753 | 753 | ), |
754 | 754 | 'email_new_invoice_heading' => array( |
755 | 755 | 'id' => 'email_new_invoice_heading', |
756 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
757 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
756 | + 'name' => __('Email Heading', 'invoicing'), |
|
757 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
758 | 758 | 'type' => 'text', |
759 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
759 | + 'std' => __('New payment invoice', 'invoicing'), |
|
760 | 760 | 'size' => 'large' |
761 | 761 | ), |
762 | 762 | ), |
763 | 763 | 'cancelled_invoice' => array( |
764 | 764 | 'email_cancelled_invoice_header' => array( |
765 | 765 | 'id' => 'email_cancelled_invoice_header', |
766 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
767 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
766 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
767 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
768 | 768 | 'type' => 'header', |
769 | 769 | ), |
770 | 770 | 'email_cancelled_invoice_active' => array( |
771 | 771 | 'id' => 'email_cancelled_invoice_active', |
772 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
773 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
772 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
773 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
774 | 774 | 'type' => 'checkbox', |
775 | 775 | 'std' => 1 |
776 | 776 | ), |
777 | 777 | 'email_cancelled_invoice_subject' => array( |
778 | 778 | 'id' => 'email_cancelled_invoice_subject', |
779 | - 'name' => __( 'Subject', 'invoicing' ), |
|
780 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
779 | + 'name' => __('Subject', 'invoicing'), |
|
780 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
781 | 781 | 'type' => 'text', |
782 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
782 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
783 | 783 | 'size' => 'large' |
784 | 784 | ), |
785 | 785 | 'email_cancelled_invoice_heading' => array( |
786 | 786 | 'id' => 'email_cancelled_invoice_heading', |
787 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
788 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
787 | + 'name' => __('Email Heading', 'invoicing'), |
|
788 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
789 | 789 | 'type' => 'text', |
790 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
790 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
791 | 791 | 'size' => 'large' |
792 | 792 | ), |
793 | 793 | ), |
794 | 794 | 'failed_invoice' => array( |
795 | 795 | 'email_failed_invoice_header' => array( |
796 | 796 | 'id' => 'email_failed_invoice_header', |
797 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
798 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
797 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
798 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
799 | 799 | 'type' => 'header', |
800 | 800 | ), |
801 | 801 | 'email_failed_invoice_active' => array( |
802 | 802 | 'id' => 'email_failed_invoice_active', |
803 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
804 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
803 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
804 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
805 | 805 | 'type' => 'checkbox', |
806 | 806 | 'std' => 1 |
807 | 807 | ), |
808 | 808 | 'email_failed_invoice_subject' => array( |
809 | 809 | 'id' => 'email_failed_invoice_subject', |
810 | - 'name' => __( 'Subject', 'invoicing' ), |
|
811 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
810 | + 'name' => __('Subject', 'invoicing'), |
|
811 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
812 | 812 | 'type' => 'text', |
813 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
813 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
814 | 814 | 'size' => 'large' |
815 | 815 | ), |
816 | 816 | 'email_failed_invoice_heading' => array( |
817 | 817 | 'id' => 'email_failed_invoice_heading', |
818 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
819 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
818 | + 'name' => __('Email Heading', 'invoicing'), |
|
819 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
820 | 820 | 'type' => 'text', |
821 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
821 | + 'std' => __('Failed invoice', 'invoicing'), |
|
822 | 822 | 'size' => 'large' |
823 | 823 | ) |
824 | 824 | ), |
825 | 825 | 'onhold_invoice' => array( |
826 | 826 | 'email_onhold_invoice_header' => array( |
827 | 827 | 'id' => 'email_onhold_invoice_header', |
828 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
829 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
828 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
829 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
830 | 830 | 'type' => 'header', |
831 | 831 | ), |
832 | 832 | 'email_onhold_invoice_active' => array( |
833 | 833 | 'id' => 'email_onhold_invoice_active', |
834 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
835 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
834 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
835 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
836 | 836 | 'type' => 'checkbox', |
837 | 837 | 'std' => 1 |
838 | 838 | ), |
839 | 839 | 'email_onhold_invoice_subject' => array( |
840 | 840 | 'id' => 'email_onhold_invoice_subject', |
841 | - 'name' => __( 'Subject', 'invoicing' ), |
|
842 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
841 | + 'name' => __('Subject', 'invoicing'), |
|
842 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
843 | 843 | 'type' => 'text', |
844 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
844 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
845 | 845 | 'size' => 'large' |
846 | 846 | ), |
847 | 847 | 'email_onhold_invoice_heading' => array( |
848 | 848 | 'id' => 'email_onhold_invoice_heading', |
849 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
850 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
849 | + 'name' => __('Email Heading', 'invoicing'), |
|
850 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
851 | 851 | 'type' => 'text', |
852 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
852 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
853 | 853 | 'size' => 'large' |
854 | 854 | ), |
855 | 855 | 'email_onhold_invoice_admin_bcc' => array( |
856 | 856 | 'id' => 'email_onhold_invoice_admin_bcc', |
857 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
858 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
857 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
858 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
859 | 859 | 'type' => 'checkbox', |
860 | 860 | 'std' => 1 |
861 | 861 | ), |
@@ -863,37 +863,37 @@ discard block |
||
863 | 863 | 'processing_invoice' => array( |
864 | 864 | 'email_processing_invoice_header' => array( |
865 | 865 | 'id' => 'email_processing_invoice_header', |
866 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
867 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
866 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
867 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
868 | 868 | 'type' => 'header', |
869 | 869 | ), |
870 | 870 | 'email_processing_invoice_active' => array( |
871 | 871 | 'id' => 'email_processing_invoice_active', |
872 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
873 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
872 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
873 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
874 | 874 | 'type' => 'checkbox', |
875 | 875 | 'std' => 1 |
876 | 876 | ), |
877 | 877 | 'email_processing_invoice_subject' => array( |
878 | 878 | 'id' => 'email_processing_invoice_subject', |
879 | - 'name' => __( 'Subject', 'invoicing' ), |
|
880 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
879 | + 'name' => __('Subject', 'invoicing'), |
|
880 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
881 | 881 | 'type' => 'text', |
882 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
882 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
883 | 883 | 'size' => 'large' |
884 | 884 | ), |
885 | 885 | 'email_processing_invoice_heading' => array( |
886 | 886 | 'id' => 'email_processing_invoice_heading', |
887 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
888 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
887 | + 'name' => __('Email Heading', 'invoicing'), |
|
888 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
889 | 889 | 'type' => 'text', |
890 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
890 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
891 | 891 | 'size' => 'large' |
892 | 892 | ), |
893 | 893 | 'email_processing_invoice_admin_bcc' => array( |
894 | 894 | 'id' => 'email_processing_invoice_admin_bcc', |
895 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
896 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
895 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
896 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
897 | 897 | 'type' => 'checkbox', |
898 | 898 | 'std' => 1 |
899 | 899 | ), |
@@ -901,37 +901,37 @@ discard block |
||
901 | 901 | 'completed_invoice' => array( |
902 | 902 | 'email_completed_invoice_header' => array( |
903 | 903 | 'id' => 'email_completed_invoice_header', |
904 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
905 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
904 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
905 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
906 | 906 | 'type' => 'header', |
907 | 907 | ), |
908 | 908 | 'email_completed_invoice_active' => array( |
909 | 909 | 'id' => 'email_completed_invoice_active', |
910 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
911 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
910 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
911 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
912 | 912 | 'type' => 'checkbox', |
913 | 913 | 'std' => 1 |
914 | 914 | ), |
915 | 915 | 'email_completed_invoice_subject' => array( |
916 | 916 | 'id' => 'email_completed_invoice_subject', |
917 | - 'name' => __( 'Subject', 'invoicing' ), |
|
918 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
917 | + 'name' => __('Subject', 'invoicing'), |
|
918 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
919 | 919 | 'type' => 'text', |
920 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
920 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
921 | 921 | 'size' => 'large' |
922 | 922 | ), |
923 | 923 | 'email_completed_invoice_heading' => array( |
924 | 924 | 'id' => 'email_completed_invoice_heading', |
925 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
926 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
925 | + 'name' => __('Email Heading', 'invoicing'), |
|
926 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
927 | 927 | 'type' => 'text', |
928 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
928 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
929 | 929 | 'size' => 'large' |
930 | 930 | ), |
931 | 931 | 'email_completed_invoice_admin_bcc' => array( |
932 | 932 | 'id' => 'email_completed_invoice_admin_bcc', |
933 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
934 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
933 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
934 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
935 | 935 | 'type' => 'checkbox', |
936 | 936 | ), |
937 | 937 | 'std' => 1 |
@@ -939,37 +939,37 @@ discard block |
||
939 | 939 | 'refunded_invoice' => array( |
940 | 940 | 'email_refunded_invoice_header' => array( |
941 | 941 | 'id' => 'email_refunded_invoice_header', |
942 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
943 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
942 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
943 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
944 | 944 | 'type' => 'header', |
945 | 945 | ), |
946 | 946 | 'email_refunded_invoice_active' => array( |
947 | 947 | 'id' => 'email_refunded_invoice_active', |
948 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
949 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
948 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
949 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
950 | 950 | 'type' => 'checkbox', |
951 | 951 | 'std' => 1 |
952 | 952 | ), |
953 | 953 | 'email_refunded_invoice_subject' => array( |
954 | 954 | 'id' => 'email_refunded_invoice_subject', |
955 | - 'name' => __( 'Subject', 'invoicing' ), |
|
956 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
955 | + 'name' => __('Subject', 'invoicing'), |
|
956 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
957 | 957 | 'type' => 'text', |
958 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
958 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
959 | 959 | 'size' => 'large' |
960 | 960 | ), |
961 | 961 | 'email_refunded_invoice_heading' => array( |
962 | 962 | 'id' => 'email_refunded_invoice_heading', |
963 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
964 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
963 | + 'name' => __('Email Heading', 'invoicing'), |
|
964 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
965 | 965 | 'type' => 'text', |
966 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
966 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
967 | 967 | 'size' => 'large' |
968 | 968 | ), |
969 | 969 | 'email_refunded_invoice_admin_bcc' => array( |
970 | 970 | 'id' => 'email_refunded_invoice_admin_bcc', |
971 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
972 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
971 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
972 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
973 | 973 | 'type' => 'checkbox', |
974 | 974 | 'std' => 1 |
975 | 975 | ), |
@@ -977,37 +977,37 @@ discard block |
||
977 | 977 | 'user_invoice' => array( |
978 | 978 | 'email_user_invoice_header' => array( |
979 | 979 | 'id' => 'email_user_invoice_header', |
980 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
981 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
980 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
981 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
982 | 982 | 'type' => 'header', |
983 | 983 | ), |
984 | 984 | 'email_user_invoice_active' => array( |
985 | 985 | 'id' => 'email_user_invoice_active', |
986 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
987 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
986 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
987 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
988 | 988 | 'type' => 'checkbox', |
989 | 989 | 'std' => 1 |
990 | 990 | ), |
991 | 991 | 'email_user_invoice_subject' => array( |
992 | 992 | 'id' => 'email_user_invoice_subject', |
993 | - 'name' => __( 'Subject', 'invoicing' ), |
|
994 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
993 | + 'name' => __('Subject', 'invoicing'), |
|
994 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
995 | 995 | 'type' => 'text', |
996 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
996 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
997 | 997 | 'size' => 'large' |
998 | 998 | ), |
999 | 999 | 'email_user_invoice_heading' => array( |
1000 | 1000 | 'id' => 'email_user_invoice_heading', |
1001 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1002 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
1001 | + 'name' => __('Email Heading', 'invoicing'), |
|
1002 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
1003 | 1003 | 'type' => 'text', |
1004 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
1004 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
1005 | 1005 | 'size' => 'large' |
1006 | 1006 | ), |
1007 | 1007 | 'email_user_invoice_admin_bcc' => array( |
1008 | 1008 | 'id' => 'email_user_invoice_admin_bcc', |
1009 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
1010 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
1009 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
1010 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
1011 | 1011 | 'type' => 'checkbox', |
1012 | 1012 | 'std' => 1 |
1013 | 1013 | ), |
@@ -1015,177 +1015,177 @@ discard block |
||
1015 | 1015 | 'user_note' => array( |
1016 | 1016 | 'email_user_note_header' => array( |
1017 | 1017 | 'id' => 'email_user_note_header', |
1018 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
1019 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ), |
|
1018 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
1019 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'), |
|
1020 | 1020 | 'type' => 'header', |
1021 | 1021 | ), |
1022 | 1022 | 'email_user_note_active' => array( |
1023 | 1023 | 'id' => 'email_user_note_active', |
1024 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1025 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1024 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1025 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1026 | 1026 | 'type' => 'checkbox', |
1027 | 1027 | 'std' => 1 |
1028 | 1028 | ), |
1029 | 1029 | 'email_user_note_subject' => array( |
1030 | 1030 | 'id' => 'email_user_note_subject', |
1031 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1032 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1031 | + 'name' => __('Subject', 'invoicing'), |
|
1032 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1033 | 1033 | 'type' => 'text', |
1034 | - 'std' => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
1034 | + 'std' => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'), |
|
1035 | 1035 | 'size' => 'large' |
1036 | 1036 | ), |
1037 | 1037 | 'email_user_note_heading' => array( |
1038 | 1038 | 'id' => 'email_user_note_heading', |
1039 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1040 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1039 | + 'name' => __('Email Heading', 'invoicing'), |
|
1040 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1041 | 1041 | 'type' => 'text', |
1042 | - 'std' => __( 'A note has been added to your invoice', 'invoicing' ), |
|
1042 | + 'std' => __('A note has been added to your invoice', 'invoicing'), |
|
1043 | 1043 | 'size' => 'large' |
1044 | 1044 | ), |
1045 | 1045 | ), |
1046 | 1046 | 'overdue' => array( |
1047 | 1047 | 'email_overdue_header' => array( |
1048 | 1048 | 'id' => 'email_overdue_header', |
1049 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
1050 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
1049 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
1050 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
1051 | 1051 | 'type' => 'header', |
1052 | 1052 | ), |
1053 | 1053 | 'email_overdue_active' => array( |
1054 | 1054 | 'id' => 'email_overdue_active', |
1055 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1056 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1055 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1056 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1057 | 1057 | 'type' => 'checkbox', |
1058 | 1058 | 'std' => 1 |
1059 | 1059 | ), |
1060 | 1060 | 'email_due_reminder_days' => array( |
1061 | 1061 | 'id' => 'email_due_reminder_days', |
1062 | - 'name' => __( 'When to Send', 'sliced-invoices' ), |
|
1063 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
1062 | + 'name' => __('When to Send', 'sliced-invoices'), |
|
1063 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
1064 | 1064 | 'default' => '', |
1065 | 1065 | 'type' => 'multicheck', |
1066 | 1066 | 'options' => $overdue_days_options, |
1067 | 1067 | ), |
1068 | 1068 | 'email_overdue_subject' => array( |
1069 | 1069 | 'id' => 'email_overdue_subject', |
1070 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1071 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1070 | + 'name' => __('Subject', 'invoicing'), |
|
1071 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1072 | 1072 | 'type' => 'text', |
1073 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
1073 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
1074 | 1074 | 'size' => 'large' |
1075 | 1075 | ), |
1076 | 1076 | 'email_overdue_heading' => array( |
1077 | 1077 | 'id' => 'email_overdue_heading', |
1078 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1079 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1078 | + 'name' => __('Email Heading', 'invoicing'), |
|
1079 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1080 | 1080 | 'type' => 'text', |
1081 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
1081 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
1082 | 1082 | 'size' => 'large' |
1083 | 1083 | ), |
1084 | 1084 | 'email_overdue_body' => array( |
1085 | 1085 | 'id' => 'email_overdue_body', |
1086 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1087 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
1086 | + 'name' => __('Email Content', 'invoicing'), |
|
1087 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
1088 | 1088 | 'type' => 'rich_editor', |
1089 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ), |
|
1089 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'), |
|
1090 | 1090 | 'class' => 'large', |
1091 | 1091 | 'size' => 10, |
1092 | 1092 | ), |
1093 | 1093 | ), |
1094 | 1094 | ); |
1095 | 1095 | |
1096 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
1096 | + return apply_filters('wpinv_get_emails', $emails); |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | -function wpinv_settings_emails( $settings = array() ) { |
|
1099 | +function wpinv_settings_emails($settings = array()) { |
|
1100 | 1100 | $emails = wpinv_get_emails(); |
1101 | 1101 | |
1102 | - if ( !empty( $emails ) ) { |
|
1103 | - foreach ( $emails as $key => $email ) { |
|
1102 | + if (!empty($emails)) { |
|
1103 | + foreach ($emails as $key => $email) { |
|
1104 | 1104 | $settings[$key] = $email; |
1105 | 1105 | } |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
1108 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
1109 | 1109 | } |
1110 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
1110 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
1111 | 1111 | |
1112 | -function wpinv_settings_sections_emails( $settings ) { |
|
1112 | +function wpinv_settings_sections_emails($settings) { |
|
1113 | 1113 | $emails = wpinv_get_emails(); |
1114 | 1114 | |
1115 | 1115 | if (!empty($emails)) { |
1116 | - foreach ($emails as $key => $email) { |
|
1117 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
1116 | + foreach ($emails as $key => $email) { |
|
1117 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | return $settings; |
1122 | 1122 | } |
1123 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
1123 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
1124 | 1124 | |
1125 | -function wpinv_email_is_enabled( $email_type ) { |
|
1125 | +function wpinv_email_is_enabled($email_type) { |
|
1126 | 1126 | $emails = wpinv_get_emails(); |
1127 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false; |
|
1127 | + $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false; |
|
1128 | 1128 | |
1129 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
1129 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
1130 | 1130 | } |
1131 | 1131 | |
1132 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1133 | - switch ( $email_type ) { |
|
1132 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1133 | + switch ($email_type) { |
|
1134 | 1134 | case 'new_invoice': |
1135 | 1135 | case 'cancelled_invoice': |
1136 | 1136 | case 'failed_invoice': |
1137 | 1137 | $recipient = wpinv_get_admin_email(); |
1138 | 1138 | break; |
1139 | 1139 | default: |
1140 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1141 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
1140 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1141 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
1142 | 1142 | break; |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
1145 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
1146 | 1146 | } |
1147 | 1147 | |
1148 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1149 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
1148 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1149 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
1150 | 1150 | |
1151 | - $subject = wpinv_email_format_text( $subject ); |
|
1151 | + $subject = wpinv_email_format_text($subject); |
|
1152 | 1152 | |
1153 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
1153 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
1154 | 1154 | } |
1155 | 1155 | |
1156 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1157 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
1156 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1157 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
1158 | 1158 | |
1159 | - $email_heading = wpinv_email_format_text( $email_heading ); |
|
1159 | + $email_heading = wpinv_email_format_text($email_heading); |
|
1160 | 1160 | |
1161 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
1161 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1165 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
1164 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1165 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
1166 | 1166 | |
1167 | - $content = wpinv_email_format_text( $content ); |
|
1167 | + $content = wpinv_email_format_text($content); |
|
1168 | 1168 | |
1169 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
1169 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1172 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1173 | 1173 | $from_name = wpinv_mail_get_from_address(); |
1174 | 1174 | $from_email = wpinv_mail_get_from_address(); |
1175 | 1175 | |
1176 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1176 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1177 | 1177 | |
1178 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
1179 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
1178 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
1179 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
1180 | 1180 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
1181 | 1181 | |
1182 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
1182 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
1183 | 1183 | } |
1184 | 1184 | |
1185 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1185 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1186 | 1186 | $attachments = array(); |
1187 | 1187 | |
1188 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
1188 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | function wpinv_email_global_vars() { |
@@ -1202,73 +1202,73 @@ discard block |
||
1202 | 1202 | $replace['sitename'] = $blogname; |
1203 | 1203 | $replace['site-title'] = $blogname; |
1204 | 1204 | |
1205 | - return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) ); |
|
1205 | + return apply_filters('wpinv_email_global_vars', array($search, $replace)); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | -function wpinv_email_format_text( $content ) { |
|
1208 | +function wpinv_email_format_text($content) { |
|
1209 | 1209 | global $wpinv_email_search, $wpinv_email_replace; |
1210 | 1210 | |
1211 | - if ( empty( $wpinv_email_search ) ) { |
|
1211 | + if (empty($wpinv_email_search)) { |
|
1212 | 1212 | $wpinv_email_search = array(); |
1213 | 1213 | } |
1214 | 1214 | |
1215 | - if ( empty( $wpinv_email_replace ) ) { |
|
1215 | + if (empty($wpinv_email_replace)) { |
|
1216 | 1216 | $wpinv_email_replace = array(); |
1217 | 1217 | } |
1218 | 1218 | |
1219 | - $wpinv_email_search = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search ); |
|
1220 | - $wpinv_email_replace = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace ); |
|
1219 | + $wpinv_email_search = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search); |
|
1220 | + $wpinv_email_replace = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace); |
|
1221 | 1221 | |
1222 | 1222 | $global_vars = wpinv_email_global_vars(); |
1223 | 1223 | |
1224 | - $search = array_merge( $global_vars[0], $wpinv_email_search ); |
|
1225 | - $replace = array_merge( $global_vars[1], $wpinv_email_replace ); |
|
1224 | + $search = array_merge($global_vars[0], $wpinv_email_search); |
|
1225 | + $replace = array_merge($global_vars[1], $wpinv_email_replace); |
|
1226 | 1226 | |
1227 | - if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) { |
|
1227 | + if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) { |
|
1228 | 1228 | return $content; |
1229 | 1229 | } |
1230 | 1230 | |
1231 | - return str_replace( $search, $replace, $content ); |
|
1231 | + return str_replace($search, $replace, $content); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | -function wpinv_email_style_body( $content ) { |
|
1234 | +function wpinv_email_style_body($content) { |
|
1235 | 1235 | // make sure we only inline CSS for html emails |
1236 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
1236 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
1237 | 1237 | ob_start(); |
1238 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
1239 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
1238 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
1239 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
1240 | 1240 | |
1241 | 1241 | // apply CSS styles inline for picky email clients |
1242 | 1242 | try { |
1243 | - $emogrifier = new Emogrifier( $content, $css ); |
|
1243 | + $emogrifier = new Emogrifier($content, $css); |
|
1244 | 1244 | $content = $emogrifier->emogrify(); |
1245 | - } catch ( Exception $e ) { |
|
1246 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
1245 | + } catch (Exception $e) { |
|
1246 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
1247 | 1247 | } |
1248 | 1248 | } |
1249 | 1249 | return $content; |
1250 | 1250 | } |
1251 | 1251 | |
1252 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1253 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1252 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1253 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1254 | 1254 | } |
1255 | 1255 | |
1256 | 1256 | /** |
1257 | 1257 | * Get the email footer. |
1258 | 1258 | */ |
1259 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1260 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1259 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1260 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1261 | 1261 | } |
1262 | 1262 | |
1263 | -function wpinv_email_wrap_message( $message ) { |
|
1263 | +function wpinv_email_wrap_message($message) { |
|
1264 | 1264 | // Buffer |
1265 | 1265 | ob_start(); |
1266 | 1266 | |
1267 | - do_action( 'wpinv_email_header' ); |
|
1267 | + do_action('wpinv_email_header'); |
|
1268 | 1268 | |
1269 | - echo wpautop( wptexturize( $message ) ); |
|
1269 | + echo wpautop(wptexturize($message)); |
|
1270 | 1270 | |
1271 | - do_action( 'wpinv_email_footer' ); |
|
1271 | + do_action('wpinv_email_footer'); |
|
1272 | 1272 | |
1273 | 1273 | // Get contents |
1274 | 1274 | $message = ob_get_clean(); |
@@ -1276,86 +1276,86 @@ discard block |
||
1276 | 1276 | return $message; |
1277 | 1277 | } |
1278 | 1278 | |
1279 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1280 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1279 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1280 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1284 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1283 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
1284 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1285 | 1285 | } |
1286 | 1286 | |
1287 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1288 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1287 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1288 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1289 | 1289 | } |
1290 | 1290 | |
1291 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
1292 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1291 | +function wpinv_send_customer_invoice($data = array()) { |
|
1292 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1293 | 1293 | |
1294 | - if ( empty( $invoice_id ) ) { |
|
1294 | + if (empty($invoice_id)) { |
|
1295 | 1295 | return; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1299 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1298 | + if (!current_user_can('manage_options')) { |
|
1299 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1300 | 1300 | } |
1301 | 1301 | |
1302 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
1302 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
1303 | 1303 | |
1304 | 1304 | $status = $sent ? 'email_sent' : 'email_fail'; |
1305 | 1305 | |
1306 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1307 | - wp_redirect( $redirect ); |
|
1306 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1307 | + wp_redirect($redirect); |
|
1308 | 1308 | exit; |
1309 | 1309 | } |
1310 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
1310 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
1311 | 1311 | |
1312 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
1313 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1312 | +function wpinv_send_overdue_reminder($data = array()) { |
|
1313 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1314 | 1314 | |
1315 | - if ( empty( $invoice_id ) ) { |
|
1315 | + if (empty($invoice_id)) { |
|
1316 | 1316 | return; |
1317 | 1317 | } |
1318 | 1318 | |
1319 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1320 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1319 | + if (!current_user_can('manage_options')) { |
|
1320 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1321 | 1321 | } |
1322 | 1322 | |
1323 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
1323 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
1324 | 1324 | |
1325 | 1325 | $status = $sent ? 'email_sent' : 'email_fail'; |
1326 | 1326 | |
1327 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1328 | - wp_redirect( $redirect ); |
|
1327 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1328 | + wp_redirect($redirect); |
|
1329 | 1329 | exit; |
1330 | 1330 | } |
1331 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
1331 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
1332 | 1332 | |
1333 | -function wpinv_send_customer_note_email( $data ) { |
|
1334 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1333 | +function wpinv_send_customer_note_email($data) { |
|
1334 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1335 | 1335 | |
1336 | - if ( empty( $invoice_id ) ) { |
|
1336 | + if (empty($invoice_id)) { |
|
1337 | 1337 | return; |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
1340 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
1341 | 1341 | } |
1342 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
1342 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
1343 | 1343 | |
1344 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
1345 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
1346 | - $date_format = get_option( 'date_format' ); |
|
1347 | - $time_format = get_option( 'time_format' ); |
|
1344 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
1345 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
1346 | + $date_format = get_option('date_format'); |
|
1347 | + $time_format = get_option('time_format'); |
|
1348 | 1348 | ?> |
1349 | 1349 | <div id="wpinv-email-notes"> |
1350 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
1350 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
1351 | 1351 | <ol class="wpinv-notes-lists"> |
1352 | 1352 | <?php |
1353 | - foreach ( $invoice_notes as $note ) { |
|
1354 | - $note_time = strtotime( $note->comment_date ); |
|
1353 | + foreach ($invoice_notes as $note) { |
|
1354 | + $note_time = strtotime($note->comment_date); |
|
1355 | 1355 | ?> |
1356 | 1356 | <li class="comment wpinv-note"> |
1357 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
1358 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
1357 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
1358 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
1359 | 1359 | </li> |
1360 | 1360 | <?php |
1361 | 1361 | } |
@@ -1364,21 +1364,21 @@ discard block |
||
1364 | 1364 | <?php |
1365 | 1365 | } |
1366 | 1366 | } |
1367 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
1367 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
1368 | 1368 | |
1369 | 1369 | function wpinv_email_payment_reminders() { |
1370 | 1370 | global $wpi_auto_reminder; |
1371 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
1371 | + if (!wpinv_get_option('email_overdue_active')) { |
|
1372 | 1372 | return; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
1376 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
1375 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
1376 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
1377 | 1377 | |
1378 | - if ( empty( $reminder_days ) ) { |
|
1378 | + if (empty($reminder_days)) { |
|
1379 | 1379 | return; |
1380 | 1380 | } |
1381 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
1381 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
1382 | 1382 | |
1383 | 1383 | $args = array( |
1384 | 1384 | 'post_type' => 'wpi_invoice', |
@@ -1388,7 +1388,7 @@ discard block |
||
1388 | 1388 | 'meta_query' => array( |
1389 | 1389 | array( |
1390 | 1390 | 'key' => '_wpinv_due_date', |
1391 | - 'value' => array( '', 'none' ), |
|
1391 | + 'value' => array('', 'none'), |
|
1392 | 1392 | 'compare' => 'NOT IN', |
1393 | 1393 | ) |
1394 | 1394 | ), |
@@ -1397,64 +1397,64 @@ discard block |
||
1397 | 1397 | 'order' => 'ASC', |
1398 | 1398 | ); |
1399 | 1399 | |
1400 | - $invoices = get_posts( $args ); |
|
1400 | + $invoices = get_posts($args); |
|
1401 | 1401 | |
1402 | - if ( empty( $invoices ) ) { |
|
1402 | + if (empty($invoices)) { |
|
1403 | 1403 | return; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | - $date_to_send = array(); |
|
1406 | + $date_to_send = array(); |
|
1407 | 1407 | |
1408 | - foreach ( $invoices as $id ) { |
|
1409 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
1408 | + foreach ($invoices as $id) { |
|
1409 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
1410 | 1410 | |
1411 | - foreach ( $reminder_days as $key => $days ) { |
|
1412 | - if ( $days !== '' ) { |
|
1413 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
1411 | + foreach ($reminder_days as $key => $days) { |
|
1412 | + if ($days !== '') { |
|
1413 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
1414 | 1414 | } |
1415 | 1415 | } |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - $today = date_i18n( 'Y-m-d' ); |
|
1418 | + $today = date_i18n('Y-m-d'); |
|
1419 | 1419 | $wpi_auto_reminder = true; |
1420 | 1420 | |
1421 | - foreach ( $date_to_send as $id => $values ) { |
|
1422 | - if ( in_array( $today, $values ) ) { |
|
1423 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
1421 | + foreach ($date_to_send as $id => $values) { |
|
1422 | + if (in_array($today, $values)) { |
|
1423 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
1424 | 1424 | |
1425 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
1426 | - if ( !in_array( $today, $sent ) ) { |
|
1427 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1425 | + if (isset($sent) && !empty($sent)) { |
|
1426 | + if (!in_array($today, $sent)) { |
|
1427 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1428 | 1428 | } |
1429 | 1429 | } else { |
1430 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1430 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1431 | 1431 | } |
1432 | 1432 | } |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - $wpi_auto_reminder = false; |
|
1435 | + $wpi_auto_reminder = false; |
|
1436 | 1436 | } |
1437 | 1437 | } |
1438 | 1438 | |
1439 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
1439 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
1440 | 1440 | global $wpinv_email_search, $wpinv_email_replace; |
1441 | 1441 | |
1442 | 1442 | $email_type = 'overdue'; |
1443 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
1443 | + if (!wpinv_email_is_enabled($email_type)) { |
|
1444 | 1444 | return false; |
1445 | 1445 | } |
1446 | 1446 | |
1447 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1448 | - if ( empty( $invoice ) ) { |
|
1447 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1448 | + if (empty($invoice)) { |
|
1449 | 1449 | return false; |
1450 | 1450 | } |
1451 | 1451 | |
1452 | - if ( !$invoice->needs_payment() ) { |
|
1452 | + if (!$invoice->needs_payment()) { |
|
1453 | 1453 | return false; |
1454 | 1454 | } |
1455 | 1455 | |
1456 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
1457 | - if ( !is_email( $recipient ) ) { |
|
1456 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
1457 | + if (!is_email($recipient)) { |
|
1458 | 1458 | return false; |
1459 | 1459 | } |
1460 | 1460 | |
@@ -1470,70 +1470,70 @@ discard block |
||
1470 | 1470 | $replace = array(); |
1471 | 1471 | $replace['full_name'] = $invoice->get_user_full_name(); |
1472 | 1472 | $replace['invoice_number'] = $invoice->get_number(); |
1473 | - $replace['invoice_due_date']= $invoice->get_due_date( true ); |
|
1474 | - $replace['invoice_total'] = $invoice->get_total( true ); |
|
1475 | - $replace['invoice_link'] = $invoice->get_view_url( true ); |
|
1476 | - $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true ); |
|
1477 | - $replace['is_was'] = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ); |
|
1473 | + $replace['invoice_due_date'] = $invoice->get_due_date(true); |
|
1474 | + $replace['invoice_total'] = $invoice->get_total(true); |
|
1475 | + $replace['invoice_link'] = $invoice->get_view_url(true); |
|
1476 | + $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true); |
|
1477 | + $replace['is_was'] = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'); |
|
1478 | 1478 | |
1479 | 1479 | $wpinv_email_search = $search; |
1480 | 1480 | $wpinv_email_replace = $replace; |
1481 | 1481 | |
1482 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
1483 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
1484 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
1485 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
1482 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
1483 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
1484 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
1485 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
1486 | 1486 | |
1487 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
1487 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
1488 | 1488 | |
1489 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
1489 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
1490 | 1490 | 'invoice' => $invoice, |
1491 | 1491 | 'email_type' => $email_type, |
1492 | 1492 | 'email_heading' => $email_heading, |
1493 | 1493 | 'sent_to_admin' => false, |
1494 | 1494 | 'plain_text' => false, |
1495 | 1495 | 'message_body' => $message_body |
1496 | - ) ); |
|
1496 | + )); |
|
1497 | 1497 | |
1498 | - $content = wpinv_email_format_text( $content ); |
|
1498 | + $content = wpinv_email_format_text($content); |
|
1499 | 1499 | |
1500 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
1501 | - if ( $sent ) { |
|
1502 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
1500 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
1501 | + if ($sent) { |
|
1502 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | 1505 | return $sent; |
1506 | 1506 | } |
1507 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
1507 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
1508 | 1508 | |
1509 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
1509 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
1510 | 1510 | global $wpi_auto_reminder; |
1511 | 1511 | |
1512 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
1512 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
1513 | 1513 | |
1514 | - if ( empty( $sent ) ) { |
|
1514 | + if (empty($sent)) { |
|
1515 | 1515 | $sent = array(); |
1516 | 1516 | } |
1517 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
1517 | + $sent[] = date_i18n('Y-m-d'); |
|
1518 | 1518 | |
1519 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
1519 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
1520 | 1520 | |
1521 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
1522 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1523 | - $invoice->add_note( $note, false, false, true ); |
|
1521 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
1522 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1523 | + $invoice->add_note($note, false, false, true); |
|
1524 | 1524 | } else { // Menual reminder note. |
1525 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1526 | - $invoice->add_note( $note ); |
|
1525 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1526 | + $invoice->add_note($note); |
|
1527 | 1527 | } |
1528 | 1528 | } |
1529 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
1529 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
|
1530 | 1530 | |
1531 | -function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) { |
|
1531 | +function wpinv_email_before_note_details($invoice, $email_type, $sent_to_admin, $customer_note) { |
|
1532 | 1532 | if ("wpi_invoice" === $invoice->post_type && !empty($customer_note)) { |
1533 | 1533 | $before_note = ''; |
1534 | - $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' ); |
|
1535 | - $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>'; |
|
1536 | - $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' ); |
|
1534 | + $before_note .= __('Hello, a note has just been added to your invoice:', 'invoicing'); |
|
1535 | + $before_note .= '<blockquote class="wpinv-note">' . wpautop(wptexturize($customer_note)) . '</blockquote>'; |
|
1536 | + $before_note .= __('For your reference, your invoice details are shown below.', 'invoicing'); |
|
1537 | 1537 | echo $before_note; |
1538 | 1538 | } |
1539 | 1539 | } |
1540 | 1540 | \ No newline at end of file |
@@ -1,30 +1,30 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Details { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | $currency_symbol = wpinv_currency_symbol(); |
10 | 10 | $statuses = wpinv_get_invoice_statuses(); |
11 | 11 | |
12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
13 | + $invoice = new WPInv_Invoice($post_id); |
|
14 | 14 | |
15 | - $status = $invoice->get_status( false ); // Current status |
|
15 | + $status = $invoice->get_status(false); // Current status |
|
16 | 16 | $discount = $invoice->get_discount(); |
17 | 17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
18 | 18 | $invoice_number = $invoice->get_number(); |
19 | 19 | |
20 | 20 | $date_created = $invoice->get_created_date(); |
21 | - $datetime_created = strtotime( $date_created ); |
|
22 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
21 | + $datetime_created = strtotime($date_created); |
|
22 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
23 | 23 | $date_completed = $invoice->get_completed_date(); |
24 | - $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
|
25 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
26 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
27 | - $mail_notice = esc_attr__( 'After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
|
24 | + $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a'; |
|
25 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
26 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
27 | + $mail_notice = esc_attr__('After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing'); |
|
28 | 28 | |
29 | 29 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
30 | 30 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | <div class="gdmbx2-wrap form-table"> |
35 | 35 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
36 | 36 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
37 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
38 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
37 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
38 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
39 | 39 | </div> |
40 | - <?php if ( wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?> |
|
40 | + <?php if (wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?> |
|
41 | 41 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
42 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
42 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
43 | 43 | <div class="gdmbx-td"> |
44 | - <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
|
44 | + <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd"> |
|
45 | 45 | </div> |
46 | 46 | </div> |
47 | 47 | <?php } ?> |
48 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
48 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
49 | 49 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
50 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
51 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
50 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
51 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
52 | 52 | </div> |
53 | 53 | <?php } ?> |
54 | 54 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
55 | 55 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
56 | 56 | <div class="gdmbx-td"> |
57 | 57 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select"> |
58 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
59 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
58 | + <?php foreach ($statuses as $value => $label) { ?> |
|
59 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
60 | 60 | <?php } ?> |
61 | 61 | </select> |
62 | 62 | </div> |
@@ -64,107 +64,107 @@ discard block |
||
64 | 64 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
65 | 65 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
66 | 66 | <div class="gdmbx-td"> |
67 | - <input type="text" placeholder="<?php echo esc_attr( wpinv_format_invoice_number( 1 ) ); ?>" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
67 | + <input type="text" placeholder="<?php echo esc_attr(wpinv_format_invoice_number(1)); ?>" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
68 | 68 | </div> |
69 | 69 | </div> |
70 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); ?> |
|
71 | - <?php if ( !( $is_paid = $invoice->is_paid() ) || $discount_code ) { ?> |
|
70 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); ?> |
|
71 | + <?php if (!($is_paid = $invoice->is_paid()) || $discount_code) { ?> |
|
72 | 72 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
73 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
73 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
74 | 74 | <div class="gdmbx-td"> |
75 | - <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
75 | + <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
76 | 76 | </div> |
77 | 77 | </div> |
78 | 78 | <?php } ?> |
79 | 79 | </div> |
80 | 80 | </div> |
81 | 81 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
82 | - <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label> |
|
82 | + <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label> |
|
83 | 83 | <select id="wpi_save_send" name="wpi_save_send"> |
84 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
85 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
84 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
85 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
86 | 86 | </select> |
87 | 87 | </p> |
88 | 88 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
89 | 89 | </div> |
90 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
90 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
91 | 91 | <?php |
92 | 92 | } |
93 | 93 | |
94 | - public static function resend_invoice( $post ) { |
|
94 | + public static function resend_invoice($post) { |
|
95 | 95 | global $wpi_mb_invoice; |
96 | 96 | |
97 | - if ( empty( $wpi_mb_invoice ) ) { |
|
97 | + if (empty($wpi_mb_invoice)) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $text = array( |
102 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the customer’s email address.', 'invoicing' ), |
|
103 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
102 | + 'message' => esc_attr__('This will send a copy of the invoice to the customer’s email address.', 'invoicing'), |
|
103 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
104 | 104 | ); |
105 | 105 | |
106 | 106 | $text = apply_filters('wpinv_resend_invoice_metabox_text', $text); |
107 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
107 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
108 | 108 | |
109 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
109 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
110 | 110 | $email_actions = array(); |
111 | - $email_actions['email_url'] = add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ); |
|
112 | - $email_actions['reminder_url'] = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
111 | + $email_actions['email_url'] = add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)); |
|
112 | + $email_actions['reminder_url'] = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
113 | 113 | |
114 | - $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions ); |
|
114 | + $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions); |
|
115 | 115 | ?> |
116 | 116 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
117 | - <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
118 | - <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
119 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
117 | + <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
118 | + <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
119 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
120 | 120 | <?php } ?> |
121 | 121 | <?php |
122 | 122 | } |
123 | 123 | |
124 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
124 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
125 | 125 | } |
126 | 126 | |
127 | - public static function subscriptions( $post ) { |
|
127 | + public static function subscriptions($post) { |
|
128 | 128 | global $wpi_mb_invoice; |
129 | 129 | |
130 | 130 | $invoice = $wpi_mb_invoice; |
131 | 131 | |
132 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
132 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
133 | 133 | $payments = $invoice->get_child_payments(); |
134 | 134 | |
135 | 135 | $total_payments = (int)$invoice->get_total_payments(); |
136 | 136 | $subscription = $invoice->get_subscription_data(); |
137 | 137 | |
138 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
139 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
138 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
139 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
140 | 140 | $subscription_status = $invoice->get_subscription_status(); |
141 | 141 | ?> |
142 | - <p class="wpi-meta-row wpi-sub-label"><?php _e( 'Recurring Payment', 'invoicing' );?></p> |
|
143 | - <?php if ( $subscription_id = $invoice->get_subscription_id() ) { ?> |
|
144 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $subscription_id; ?></p> |
|
142 | + <p class="wpi-meta-row wpi-sub-label"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
|
143 | + <?php if ($subscription_id = $invoice->get_subscription_id()) { ?> |
|
144 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $subscription_id; ?></p> |
|
145 | 145 | <?php } ?> |
146 | - <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e( 'Billing Cycle:', 'invoicing' );?> </label><?php echo $billing_cycle; ?></p> |
|
147 | - <p class="wpi-meta-row wpi-billed-times"><label><?php _e( 'Times Billed:', 'invoicing' );?> </label><?php echo $times_billed; ?></p> |
|
148 | - <?php if ( !empty( $payments ) || $invoice->is_paid() ) { ?> |
|
149 | - <p class="wpi-meta-row wpi-start-date"><label><?php _e( 'Start Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
150 | - <p class="wpi-meta-row wpi-end-date"><label><?php _e( 'Expiration Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
151 | - <?php if ( $status_label = $invoice->get_subscription_status_label( $subscription_status ) ) { ?> |
|
152 | - <p class="wpi-meta-row wpi-sub-status"><label><?php _e( 'Subscription Status:', 'invoicing' );?> </label><?php echo $status_label; ?></p> |
|
146 | + <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php echo $billing_cycle; ?></p> |
|
147 | + <p class="wpi-meta-row wpi-billed-times"><label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $times_billed; ?></p> |
|
148 | + <?php if (!empty($payments) || $invoice->is_paid()) { ?> |
|
149 | + <p class="wpi-meta-row wpi-start-date"><label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
150 | + <p class="wpi-meta-row wpi-end-date"><label><?php _e('Expiration Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
151 | + <?php if ($status_label = $invoice->get_subscription_status_label($subscription_status)) { ?> |
|
152 | + <p class="wpi-meta-row wpi-sub-status"><label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $status_label; ?></p> |
|
153 | 153 | <?php } ?> |
154 | - <?php if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { ?> |
|
155 | - <p class="wpi-meta-row wpi-trial-date"><label><?php _e( 'Trial Until:', 'invoicing' );?> </label><?php echo $trial_end_date; ?></p> |
|
154 | + <?php if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { ?> |
|
155 | + <p class="wpi-meta-row wpi-trial-date"><label><?php _e('Trial Until:', 'invoicing'); ?> </label><?php echo $trial_end_date; ?></p> |
|
156 | 156 | <?php } ?> |
157 | - <?php if ( $cancelled_date = $invoice->get_cancelled_date() ) { ?> |
|
158 | - <p class="wpi-meta-row wpi-cancel-date"><label><?php _e( 'Cancelled On:', 'invoicing' );?> </label><?php echo $cancelled_date; ?></p> |
|
157 | + <?php if ($cancelled_date = $invoice->get_cancelled_date()) { ?> |
|
158 | + <p class="wpi-meta-row wpi-cancel-date"><label><?php _e('Cancelled On:', 'invoicing'); ?> </label><?php echo $cancelled_date; ?></p> |
|
159 | 159 | <?php } ?> |
160 | - <?php if ( !empty( $payments ) ) { ?> |
|
161 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
160 | + <?php if (!empty($payments)) { ?> |
|
161 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
162 | 162 | <ul id="wpi-sub-payments"> |
163 | - <?php foreach ( $payments as $invoice_id ) { ?> |
|
163 | + <?php foreach ($payments as $invoice_id) { ?> |
|
164 | 164 | <li> |
165 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
166 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
167 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
165 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
166 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
167 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
168 | 168 | </li> |
169 | 169 | <?php } ?> |
170 | 170 | </ul> |
@@ -172,47 +172,47 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - public static function renewals( $post ) { |
|
175 | + public static function renewals($post) { |
|
176 | 176 | global $wpi_mb_invoice; |
177 | 177 | |
178 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
179 | - $parent_url = get_edit_post_link( $wpi_mb_invoice->parent_invoice ); |
|
180 | - $parent_id = wpinv_get_invoice_number( $wpi_mb_invoice->parent_invoice ); |
|
178 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
179 | + $parent_url = get_edit_post_link($wpi_mb_invoice->parent_invoice); |
|
180 | + $parent_id = wpinv_get_invoice_number($wpi_mb_invoice->parent_invoice); |
|
181 | 181 | ?> |
182 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
183 | - <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
|
182 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
183 | + <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p> |
|
184 | 184 | <?php |
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - public static function payment_meta( $post ) { |
|
188 | + public static function payment_meta($post) { |
|
189 | 189 | global $wpi_mb_invoice; |
190 | 190 | |
191 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
192 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() ) { |
|
191 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
192 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid()) { |
|
193 | 193 | $set_dateway = true; |
194 | 194 | } |
195 | 195 | |
196 | 196 | ?> |
197 | 197 | <p class="wpi-meta-row"> |
198 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
199 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
198 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
199 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
200 | 200 | <select required="required" id="wpinv_gateway" name="wpinv_gateway"> |
201 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
202 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
201 | + <?php foreach ($gateways as $name => $gateway) { |
|
202 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | ?> |
206 | - <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
206 | + <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
207 | 207 | <?php } ?> |
208 | 208 | </select> |
209 | 209 | <?php } else { |
210 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_checkout_label( $wpi_mb_invoice->gateway ) ); |
|
210 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_checkout_label($wpi_mb_invoice->gateway)); |
|
211 | 211 | } ?> |
212 | 212 | </p> |
213 | - <?php if ( $wpi_mb_invoice->is_paid() ) { ?> |
|
214 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $wpi_mb_invoice->get_key() ); ?></p> |
|
215 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
213 | + <?php if ($wpi_mb_invoice->is_paid()) { ?> |
|
214 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $wpi_mb_invoice->get_key()); ?></p> |
|
215 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
216 | 216 | <?php } ?> |
217 | 217 | <?php |
218 | 218 | } |
@@ -7,40 +7,40 @@ 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_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
21 | 21 | return NULL; |
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
25 | - if ( empty( $invoice_data ) ) { |
|
24 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
25 | + if (empty($invoice_data)) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | |
29 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
30 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0; |
|
29 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
30 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0; |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
33 | + if (empty($invoice_data['user_id'])) { |
|
34 | 34 | $invoice_data['user_id'] = get_current_user_id(); |
35 | 35 | } |
36 | 36 | |
37 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
37 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
38 | 38 | |
39 | - if ( empty( $invoice_data['status'] ) ) { |
|
39 | + if (empty($invoice_data['status'])) { |
|
40 | 40 | $invoice_data['status'] = 'pending'; |
41 | 41 | } |
42 | 42 | |
43 | - if ( empty( $invoice_data['ip'] ) ) { |
|
43 | + if (empty($invoice_data['ip'])) { |
|
44 | 44 | $invoice_data['ip'] = wpinv_get_ip(); |
45 | 45 | } |
46 | 46 | |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | 'status' => $invoice_data['status'], |
52 | 52 | ); |
53 | 53 | |
54 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
55 | - if ( is_wp_error( $invoice ) ) { |
|
54 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
55 | + if (is_wp_error($invoice)) { |
|
56 | 56 | return $wp_error ? $invoice : 0; |
57 | 57 | } |
58 | 58 | |
59 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
59 | + if (empty($invoice_data['invoice_id'])) { |
|
60 | 60 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
61 | 61 | } |
62 | 62 | |
@@ -79,20 +79,20 @@ discard block |
||
79 | 79 | 'discount' => array(), |
80 | 80 | ); |
81 | 81 | |
82 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
83 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
84 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
82 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
83 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
84 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
88 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
89 | 89 | |
90 | - if ( empty( $user_info['first_name'] ) ) { |
|
90 | + if (empty($user_info['first_name'])) { |
|
91 | 91 | $user_info['first_name'] = $default_user_info['first_name']; |
92 | 92 | $user_info['last_name'] = $default_user_info['last_name']; |
93 | 93 | } |
94 | 94 | |
95 | - if ( empty( $user_info['country'] ) ) { |
|
95 | + if (empty($user_info['country'])) { |
|
96 | 96 | $user_info['country'] = $default_user_info['country']; |
97 | 97 | $user_info['state'] = $default_user_info['state']; |
98 | 98 | $user_info['city'] = $default_user_info['city']; |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | $user_info['phone'] = $default_user_info['phone']; |
102 | 102 | } |
103 | 103 | |
104 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
104 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
105 | 105 | $user_info['discount'] = (array)$user_info['discount']; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Payment details |
109 | 109 | $payment_details = array(); |
110 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
110 | + if (!empty($invoice_data['payment_details'])) { |
|
111 | 111 | $default_payment_details = array( |
112 | 112 | 'gateway' => 'manual', |
113 | 113 | 'gateway_title' => '', |
@@ -115,59 +115,59 @@ discard block |
||
115 | 115 | 'transaction_id' => '', |
116 | 116 | ); |
117 | 117 | |
118 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
118 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
119 | 119 | |
120 | - if ( empty( $payment_details['gateway'] ) ) { |
|
120 | + if (empty($payment_details['gateway'])) { |
|
121 | 121 | $payment_details['gateway'] = 'manual'; |
122 | 122 | } |
123 | 123 | |
124 | - if ( empty( $payment_details['currency'] ) ) { |
|
124 | + if (empty($payment_details['currency'])) { |
|
125 | 125 | $payment_details['currency'] = geodir_get_currency_type(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
129 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
128 | + if (empty($payment_details['gateway_title'])) { |
|
129 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) ); |
|
134 | - |
|
135 | - if ( !empty( $payment_details ) ) { |
|
136 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
137 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
138 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
139 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
140 | - } |
|
141 | - |
|
142 | - $invoice->set( 'user_info', $user_info ); |
|
143 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
144 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
145 | - $invoice->set( 'address', $user_info['address'] ); |
|
146 | - $invoice->set( 'company', $user_info['company'] ); |
|
147 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
148 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
149 | - $invoice->set( 'city', $user_info['city'] ); |
|
150 | - $invoice->set( 'country', $user_info['country'] ); |
|
151 | - $invoice->set( 'state', $user_info['state'] ); |
|
152 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
153 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
154 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
155 | - if ( !empty( $invoice_data['invoice_key'] ) ) { |
|
156 | - $invoice->set( 'key', $invoice_data['invoice_key'] ); |
|
157 | - } |
|
158 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
159 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
160 | - |
|
161 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
162 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
163 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
164 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
165 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
166 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
133 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending')); |
|
134 | + |
|
135 | + if (!empty($payment_details)) { |
|
136 | + $invoice->set('currency', $payment_details['currency']); |
|
137 | + $invoice->set('gateway', $payment_details['gateway']); |
|
138 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
139 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
140 | + } |
|
141 | + |
|
142 | + $invoice->set('user_info', $user_info); |
|
143 | + $invoice->set('first_name', $user_info['first_name']); |
|
144 | + $invoice->set('last_name', $user_info['last_name']); |
|
145 | + $invoice->set('address', $user_info['address']); |
|
146 | + $invoice->set('company', $user_info['company']); |
|
147 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
148 | + $invoice->set('phone', $user_info['phone']); |
|
149 | + $invoice->set('city', $user_info['city']); |
|
150 | + $invoice->set('country', $user_info['country']); |
|
151 | + $invoice->set('state', $user_info['state']); |
|
152 | + $invoice->set('zip', $user_info['zip']); |
|
153 | + $invoice->set('discounts', $user_info['discount']); |
|
154 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
155 | + if (!empty($invoice_data['invoice_key'])) { |
|
156 | + $invoice->set('key', $invoice_data['invoice_key']); |
|
157 | + } |
|
158 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
159 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
160 | + |
|
161 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
162 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
163 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
164 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
165 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
166 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
167 | 167 | |
168 | - $post_item = new WPInv_Item( $item_id ); |
|
169 | - if ( !empty( $post_item ) ) { |
|
170 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
168 | + $post_item = new WPInv_Item($item_id); |
|
169 | + if (!empty($post_item)) { |
|
170 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
171 | 171 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
172 | 172 | } else { |
173 | 173 | continue; |
@@ -177,494 +177,494 @@ discard block |
||
177 | 177 | 'name' => $name, |
178 | 178 | 'quantity' => $quantity, |
179 | 179 | 'item_price' => $item_price, |
180 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
181 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
182 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
183 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
184 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
180 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
181 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
182 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
183 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
184 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
185 | 185 | ); |
186 | 186 | |
187 | - $invoice->add_item( $item_id, $args ); |
|
187 | + $invoice->add_item($item_id, $args); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
191 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
192 | 192 | |
193 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
194 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
193 | + if (isset($invoice_data['post_date'])) { |
|
194 | + $invoice->set('date', $invoice_data['post_date']); |
|
195 | 195 | } |
196 | 196 | |
197 | - $number = wpinv_format_invoice_number( $invoice->ID ); |
|
198 | - $invoice->set( 'number', $number ); |
|
199 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
197 | + $number = wpinv_format_invoice_number($invoice->ID); |
|
198 | + $invoice->set('number', $number); |
|
199 | + update_option('wpinv_last_invoice_number', $number); |
|
200 | 200 | |
201 | 201 | $invoice->save(); |
202 | 202 | |
203 | 203 | // Add notes |
204 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
205 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
204 | + if (!empty($invoice_data['private_note'])) { |
|
205 | + $invoice->add_note($invoice_data['private_note']); |
|
206 | 206 | } |
207 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
208 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
207 | + if (!empty($invoice_data['user_note'])) { |
|
208 | + $invoice->add_note($invoice_data['user_note'], true); |
|
209 | 209 | } |
210 | 210 | |
211 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
211 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
212 | 212 | |
213 | - if ( ! empty( $invoice->ID ) ) { |
|
213 | + if (!empty($invoice->ID)) { |
|
214 | 214 | global $wpi_userID, $wpinv_ip_address_country; |
215 | 215 | |
216 | 216 | $checkout_session = wpinv_get_checkout_session(); |
217 | 217 | |
218 | 218 | $data_session = array(); |
219 | 219 | $data_session['invoice_id'] = $invoice->ID; |
220 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
220 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
221 | 221 | |
222 | - wpinv_set_checkout_session( $data_session ); |
|
222 | + wpinv_set_checkout_session($data_session); |
|
223 | 223 | |
224 | 224 | $wpi_userID = (int)$invoice->get_user_id(); |
225 | 225 | |
226 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
226 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
227 | 227 | $_POST['state'] = $invoice->state; |
228 | 228 | |
229 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
230 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
229 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
230 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
231 | 231 | |
232 | 232 | $wpinv_ip_address_country = $invoice->country; |
233 | 233 | |
234 | - $invoice = $invoice->recalculate_totals( true ); |
|
234 | + $invoice = $invoice->recalculate_totals(true); |
|
235 | 235 | |
236 | - wpinv_set_checkout_session( $checkout_session ); |
|
236 | + wpinv_set_checkout_session($checkout_session); |
|
237 | 237 | |
238 | 238 | return $invoice; |
239 | 239 | } |
240 | 240 | |
241 | - if ( $wp_error ) { |
|
242 | - if ( is_wp_error( $invoice ) ) { |
|
241 | + if ($wp_error) { |
|
242 | + if (is_wp_error($invoice)) { |
|
243 | 243 | return $invoice; |
244 | 244 | } else { |
245 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
245 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
246 | 246 | } |
247 | 247 | } else { |
248 | 248 | return 0; |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
253 | - if ( $cart && empty( $invoice_id ) ) { |
|
252 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
253 | + if ($cart && empty($invoice_id)) { |
|
254 | 254 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
255 | 255 | } |
256 | 256 | |
257 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
257 | + $invoice = new WPInv_Invoice($invoice_id); |
|
258 | 258 | return $invoice; |
259 | 259 | } |
260 | 260 | |
261 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
262 | - return wpinv_get_invoice( $invoice_id, true ); |
|
261 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
262 | + return wpinv_get_invoice($invoice_id, true); |
|
263 | 263 | } |
264 | 264 | |
265 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
266 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
265 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
266 | + $invoice = new WPInv_Invoice($invoice_id); |
|
267 | 267 | return $invoice->get_description(); |
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
271 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
270 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
271 | + $invoice = new WPInv_Invoice($invoice_id); |
|
272 | 272 | return $invoice->get_currency(); |
273 | 273 | } |
274 | 274 | |
275 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
276 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
275 | +function wpinv_get_payment_user_email($invoice_id) { |
|
276 | + $invoice = new WPInv_Invoice($invoice_id); |
|
277 | 277 | return $invoice->get_email(); |
278 | 278 | } |
279 | 279 | |
280 | -function wpinv_get_user_id( $invoice_id ) { |
|
281 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
280 | +function wpinv_get_user_id($invoice_id) { |
|
281 | + $invoice = new WPInv_Invoice($invoice_id); |
|
282 | 282 | return $invoice->get_user_id(); |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
286 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
285 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
286 | + $invoice = new WPInv_Invoice($invoice_id); |
|
287 | 287 | |
288 | - return $invoice->get_status( $return_label ); |
|
288 | + return $invoice->get_status($return_label); |
|
289 | 289 | } |
290 | 290 | |
291 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
292 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
291 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
292 | + $invoice = new WPInv_Invoice($invoice_id); |
|
293 | 293 | |
294 | - return $invoice->get_gateway( $return_label ); |
|
294 | + return $invoice->get_gateway($return_label); |
|
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
298 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
297 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
298 | + $invoice = new WPInv_Invoice($invoice_id); |
|
299 | 299 | |
300 | 300 | return $invoice->get_gateway_title(); |
301 | 301 | } |
302 | 302 | |
303 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
304 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
303 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
304 | + $invoice = new WPInv_Invoice($invoice_id); |
|
305 | 305 | |
306 | 306 | return $invoice->get_transaction_id(); |
307 | 307 | } |
308 | 308 | |
309 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
309 | +function wpinv_get_id_by_transaction_id($key) { |
|
310 | 310 | global $wpdb; |
311 | 311 | |
312 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
312 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
313 | 313 | |
314 | - if ( $invoice_id != NULL ) |
|
314 | + if ($invoice_id != NULL) |
|
315 | 315 | return $invoice_id; |
316 | 316 | |
317 | 317 | return 0; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
321 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
320 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
321 | + $invoice = new WPInv_Invoice($invoice_id); |
|
322 | 322 | |
323 | - return $invoice->get_meta( $meta_key, $single ); |
|
323 | + return $invoice->get_meta($meta_key, $single); |
|
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
327 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
326 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
327 | + $invoice = new WPInv_Invoice($invoice_id); |
|
328 | 328 | |
329 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
329 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
330 | 330 | } |
331 | 331 | |
332 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
333 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
332 | +function wpinv_get_items($invoice_id = 0) { |
|
333 | + $invoice = wpinv_get_invoice($invoice_id); |
|
334 | 334 | |
335 | 335 | $items = $invoice->get_items(); |
336 | 336 | $invoice_currency = $invoice->get_currency(); |
337 | 337 | |
338 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
339 | - foreach ( $items as $key => $item ) { |
|
338 | + if (!empty($items) && is_array($items)) { |
|
339 | + foreach ($items as $key => $item) { |
|
340 | 340 | $items[$key]['currency'] = $invoice_currency; |
341 | 341 | |
342 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
342 | + if (!isset($cart_item['subtotal'])) { |
|
343 | 343 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
344 | 344 | } |
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
348 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
352 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
351 | +function wpinv_get_fees($invoice_id = 0) { |
|
352 | + $invoice = wpinv_get_invoice($invoice_id); |
|
353 | 353 | $fees = $invoice->get_fees(); |
354 | 354 | |
355 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
355 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
359 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
358 | +function wpinv_get_invoice_ip($invoice_id) { |
|
359 | + $invoice = new WPInv_Invoice($invoice_id); |
|
360 | 360 | return $invoice->get_ip(); |
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
364 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
363 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
364 | + $invoice = new WPInv_Invoice($invoice_id); |
|
365 | 365 | return $invoice->get_user_info(); |
366 | 366 | } |
367 | 367 | |
368 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
369 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
368 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
369 | + $invoice = new WPInv_Invoice($invoice_id); |
|
370 | 370 | |
371 | - return $invoice->get_subtotal( $currency ); |
|
371 | + return $invoice->get_subtotal($currency); |
|
372 | 372 | } |
373 | 373 | |
374 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
375 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
374 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
375 | + $invoice = new WPInv_Invoice($invoice_id); |
|
376 | 376 | |
377 | - return $invoice->get_tax( $currency ); |
|
377 | + return $invoice->get_tax($currency); |
|
378 | 378 | } |
379 | 379 | |
380 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
381 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
380 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
381 | + $invoice = wpinv_get_invoice($invoice_id); |
|
382 | 382 | |
383 | - return $invoice->get_discount( $currency, $dash ); |
|
383 | + return $invoice->get_discount($currency, $dash); |
|
384 | 384 | } |
385 | 385 | |
386 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
387 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
386 | +function wpinv_discount_code($invoice_id = 0) { |
|
387 | + $invoice = new WPInv_Invoice($invoice_id); |
|
388 | 388 | |
389 | 389 | return $invoice->get_discount_code(); |
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
393 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
392 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
393 | + $invoice = new WPInv_Invoice($invoice_id); |
|
394 | 394 | |
395 | - return $invoice->get_total( $currency ); |
|
395 | + return $invoice->get_total($currency); |
|
396 | 396 | } |
397 | 397 | |
398 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
399 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
398 | +function wpinv_get_date_created($invoice_id = 0) { |
|
399 | + $invoice = new WPInv_Invoice($invoice_id); |
|
400 | 400 | |
401 | 401 | $date_created = $invoice->get_created_date(); |
402 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
402 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
403 | 403 | |
404 | 404 | return $date_created; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
408 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
407 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
408 | + $invoice = new WPInv_Invoice($invoice_id); |
|
409 | 409 | |
410 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
410 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
411 | 411 | $date_completed = $invoice->get_completed_date(); |
412 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
413 | - if ( $invoice_date == '' ) { |
|
412 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
413 | + if ($invoice_date == '') { |
|
414 | 414 | $date_created = $invoice->get_created_date(); |
415 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
415 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | return $invoice_date; |
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
422 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
421 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
422 | + $invoice = new WPInv_Invoice($invoice_id); |
|
423 | 423 | |
424 | 424 | return $invoice->vat_number; |
425 | 425 | } |
426 | 426 | |
427 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) { |
|
428 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
427 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) { |
|
428 | + $invoice = new WPInv_Invoice($invoice_id); |
|
429 | 429 | |
430 | - return $invoice->add_note( $note, $user_type, $added_by_user ); |
|
430 | + return $invoice->add_note($note, $user_type, $added_by_user); |
|
431 | 431 | } |
432 | 432 | |
433 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
433 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
434 | 434 | global $invoicing; |
435 | 435 | |
436 | - if ( empty( $invoice_id ) ) { |
|
436 | + if (empty($invoice_id)) { |
|
437 | 437 | return NULL; |
438 | 438 | } |
439 | 439 | |
440 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
440 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
441 | 441 | |
442 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
442 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
446 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
445 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
446 | + $invoice = new WPInv_Invoice($invoice_id); |
|
447 | 447 | return $invoice->get_key(); |
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
451 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
450 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
451 | + $invoice = new WPInv_Invoice($invoice_id); |
|
452 | 452 | return $invoice->get_number(); |
453 | 453 | } |
454 | 454 | |
455 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
455 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
456 | 456 | $cart_items = wpinv_get_cart_content_details(); |
457 | 457 | $items = array(); |
458 | 458 | |
459 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
459 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
460 | 460 | |
461 | - if( $cart_items ) { |
|
461 | + if ($cart_items) { |
|
462 | 462 | |
463 | - foreach( $cart_items as $item ) { |
|
463 | + foreach ($cart_items as $item) { |
|
464 | 464 | |
465 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
466 | - $items[] = $item; |
|
465 | + if (!in_array($item['id'], $excluded_items)) { |
|
466 | + $items[] = $item; |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
471 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
472 | 472 | |
473 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
473 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
474 | 474 | } |
475 | 475 | |
476 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
476 | +function wpinv_get_cart_items_subtotal($items) { |
|
477 | 477 | $subtotal = 0.00; |
478 | 478 | |
479 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
480 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
479 | + if (is_array($items) && !empty($items)) { |
|
480 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
481 | 481 | |
482 | - if( is_array( $prices ) ) { |
|
483 | - $subtotal = array_sum( $prices ); |
|
482 | + if (is_array($prices)) { |
|
483 | + $subtotal = array_sum($prices); |
|
484 | 484 | } else { |
485 | 485 | $subtotal = 0.00; |
486 | 486 | } |
487 | 487 | |
488 | - if( $subtotal < 0 ) { |
|
488 | + if ($subtotal < 0) { |
|
489 | 489 | $subtotal = 0.00; |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
493 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
494 | 494 | } |
495 | 495 | |
496 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
497 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
498 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
496 | +function wpinv_get_cart_subtotal($items = array()) { |
|
497 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
498 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
499 | 499 | |
500 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
500 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
501 | 501 | } |
502 | 502 | |
503 | -function wpinv_cart_subtotal( $items = array() ) { |
|
504 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
503 | +function wpinv_cart_subtotal($items = array()) { |
|
504 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
505 | 505 | |
506 | 506 | return $price; |
507 | 507 | } |
508 | 508 | |
509 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
510 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
511 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
512 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
509 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
510 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
511 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
512 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
513 | 513 | $fees = (float)wpinv_get_cart_fee_total(); |
514 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
514 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
515 | 515 | $total = 0; |
516 | 516 | } else { |
517 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
517 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
518 | 518 | } |
519 | 519 | |
520 | - if ( $total < 0 ) { |
|
520 | + if ($total < 0) { |
|
521 | 521 | $total = 0.00; |
522 | 522 | } |
523 | 523 | |
524 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
524 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
525 | 525 | |
526 | - return wpinv_sanitize_amount( $total ); |
|
526 | + return wpinv_sanitize_amount($total); |
|
527 | 527 | } |
528 | 528 | |
529 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
529 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
530 | 530 | global $cart_total; |
531 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
532 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
531 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
532 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
533 | 533 | |
534 | 534 | $cart_total = $total; |
535 | 535 | |
536 | - if ( !$echo ) { |
|
536 | + if (!$echo) { |
|
537 | 537 | return $total; |
538 | 538 | } |
539 | 539 | |
540 | 540 | echo $total; |
541 | 541 | } |
542 | 542 | |
543 | -function wpinv_get_cart_tax( $items = array() ) { |
|
543 | +function wpinv_get_cart_tax($items = array()) { |
|
544 | 544 | $cart_tax = 0; |
545 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
545 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
546 | 546 | |
547 | - if ( $items ) { |
|
548 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
547 | + if ($items) { |
|
548 | + $taxes = wp_list_pluck($items, 'tax'); |
|
549 | 549 | |
550 | - if( is_array( $taxes ) ) { |
|
551 | - $cart_tax = array_sum( $taxes ); |
|
550 | + if (is_array($taxes)) { |
|
551 | + $cart_tax = array_sum($taxes); |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | 555 | $cart_tax += wpinv_get_cart_fee_tax(); |
556 | 556 | |
557 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
557 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
561 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
562 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
560 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
561 | + $cart_tax = wpinv_get_cart_tax($items); |
|
562 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
563 | 563 | |
564 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
564 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
565 | 565 | |
566 | - if ( !$echo ) { |
|
566 | + if (!$echo) { |
|
567 | 567 | return $tax; |
568 | 568 | } |
569 | 569 | |
570 | 570 | echo $tax; |
571 | 571 | } |
572 | 572 | |
573 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
573 | +function wpinv_get_cart_discount_code($items = array()) { |
|
574 | 574 | $invoice = wpinv_get_invoice_cart(); |
575 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
575 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
576 | 576 | |
577 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
577 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
578 | 578 | } |
579 | 579 | |
580 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
581 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
580 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
581 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
582 | 582 | |
583 | - if ( $cart_discount_code != '' ) { |
|
583 | + if ($cart_discount_code != '') { |
|
584 | 584 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
585 | 585 | } |
586 | 586 | |
587 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
587 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
588 | 588 | |
589 | - if ( !$echo ) { |
|
589 | + if (!$echo) { |
|
590 | 590 | return $discount_code; |
591 | 591 | } |
592 | 592 | |
593 | 593 | echo $discount_code; |
594 | 594 | } |
595 | 595 | |
596 | -function wpinv_get_cart_discount( $items = array() ) { |
|
596 | +function wpinv_get_cart_discount($items = array()) { |
|
597 | 597 | $invoice = wpinv_get_invoice_cart(); |
598 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
598 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
599 | 599 | |
600 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
600 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
601 | 601 | } |
602 | 602 | |
603 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
604 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
605 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
603 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
604 | + $cart_discount = wpinv_get_cart_discount($items); |
|
605 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
606 | 606 | |
607 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
607 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
608 | 608 | |
609 | - if ( !$echo ) { |
|
609 | + if (!$echo) { |
|
610 | 610 | return $discount; |
611 | 611 | } |
612 | 612 | |
613 | 613 | echo $discount; |
614 | 614 | } |
615 | 615 | |
616 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
617 | - $item = new WPInv_Item( $item_id ); |
|
616 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
617 | + $item = new WPInv_Item($item_id); |
|
618 | 618 | |
619 | - return $item->get_fees( $type, $item_id ); |
|
619 | + return $item->get_fees($type, $item_id); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | function wpinv_get_cart_fee_total() { |
623 | - $total = 0; |
|
623 | + $total = 0; |
|
624 | 624 | $fees = wpinv_get_cart_fees(); |
625 | 625 | |
626 | - if ( $fees ) { |
|
627 | - foreach ( $fees as $fee_id => $fee ) { |
|
626 | + if ($fees) { |
|
627 | + foreach ($fees as $fee_id => $fee) { |
|
628 | 628 | $total += $fee['amount']; |
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
632 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | function wpinv_get_cart_fee_tax() { |
636 | 636 | $tax = 0; |
637 | 637 | $fees = wpinv_get_cart_fees(); |
638 | 638 | |
639 | - if ( $fees ) { |
|
640 | - foreach ( $fees as $fee_id => $fee ) { |
|
641 | - if( ! empty( $fee['no_tax'] ) ) { |
|
639 | + if ($fees) { |
|
640 | + foreach ($fees as $fee_id => $fee) { |
|
641 | + if (!empty($fee['no_tax'])) { |
|
642 | 642 | continue; |
643 | 643 | } |
644 | 644 | |
645 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
645 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
649 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | function wpinv_cart_has_recurring_item() { |
653 | 653 | $cart_items = wpinv_get_cart_contents(); |
654 | 654 | |
655 | - if ( empty( $cart_items ) ) { |
|
655 | + if (empty($cart_items)) { |
|
656 | 656 | return false; |
657 | 657 | } |
658 | 658 | |
659 | 659 | $has_subscription = false; |
660 | - foreach( $cart_items as $cart_item ) { |
|
661 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
660 | + foreach ($cart_items as $cart_item) { |
|
661 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
662 | 662 | $has_subscription = true; |
663 | 663 | break; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
667 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | function wpinv_cart_has_free_trial() { |
@@ -672,94 +672,94 @@ discard block |
||
672 | 672 | |
673 | 673 | $free_trial = false; |
674 | 674 | |
675 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
675 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
676 | 676 | $free_trial = true; |
677 | 677 | } |
678 | 678 | |
679 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
679 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | function wpinv_get_cart_contents() { |
683 | 683 | $cart_details = wpinv_get_cart_details(); |
684 | 684 | |
685 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
685 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | function wpinv_get_cart_content_details() { |
689 | 689 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
690 | 690 | $cart_items = wpinv_get_cart_contents(); |
691 | 691 | |
692 | - if ( empty( $cart_items ) ) { |
|
692 | + if (empty($cart_items)) { |
|
693 | 693 | return false; |
694 | 694 | } |
695 | 695 | $invoice = wpinv_get_invoice_cart(); |
696 | 696 | |
697 | 697 | $details = array(); |
698 | - $length = count( $cart_items ) - 1; |
|
698 | + $length = count($cart_items) - 1; |
|
699 | 699 | |
700 | - if ( empty( $_POST['country'] ) ) { |
|
700 | + if (empty($_POST['country'])) { |
|
701 | 701 | $_POST['country'] = $invoice->country; |
702 | 702 | } |
703 | - if ( !isset( $_POST['state'] ) ) { |
|
703 | + if (!isset($_POST['state'])) { |
|
704 | 704 | $_POST['state'] = $invoice->state; |
705 | 705 | } |
706 | 706 | |
707 | - foreach( $cart_items as $key => $item ) { |
|
708 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
709 | - if ( empty( $item_id ) ) { |
|
707 | + foreach ($cart_items as $key => $item) { |
|
708 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
709 | + if (empty($item_id)) { |
|
710 | 710 | continue; |
711 | 711 | } |
712 | 712 | |
713 | 713 | $wpi_current_id = $invoice->ID; |
714 | 714 | $wpi_item_id = $item_id; |
715 | 715 | |
716 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
716 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
717 | 717 | $item_price = $item['custom_price']; |
718 | 718 | } else { |
719 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
719 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
720 | 720 | $item_price = $item['item_price']; |
721 | 721 | } else { |
722 | - $item_price = wpinv_get_item_price( $item_id ); |
|
722 | + $item_price = wpinv_get_item_price($item_id); |
|
723 | 723 | } |
724 | 724 | } |
725 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
726 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
727 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
728 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
725 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
726 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
727 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
728 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
729 | 729 | |
730 | 730 | $subtotal = $item_price * $quantity; |
731 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
732 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
733 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
731 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
732 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
733 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
734 | 734 | |
735 | - if ( wpinv_prices_include_tax() ) { |
|
736 | - $subtotal -= wpinv_round_amount( $tax ); |
|
735 | + if (wpinv_prices_include_tax()) { |
|
736 | + $subtotal -= wpinv_round_amount($tax); |
|
737 | 737 | } |
738 | 738 | |
739 | - $total = $subtotal - $discount + $tax; |
|
739 | + $total = $subtotal - $discount + $tax; |
|
740 | 740 | |
741 | 741 | // Do not allow totals to go negatve |
742 | - if( $total < 0 ) { |
|
742 | + if ($total < 0) { |
|
743 | 743 | $total = 0; |
744 | 744 | } |
745 | 745 | |
746 | - $details[ $key ] = array( |
|
746 | + $details[$key] = array( |
|
747 | 747 | 'id' => $item_id, |
748 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
749 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
750 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
748 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
749 | + 'item_price' => wpinv_round_amount($item_price), |
|
750 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
751 | 751 | 'quantity' => $quantity, |
752 | - 'discount' => wpinv_round_amount( $discount ), |
|
753 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
754 | - 'tax' => wpinv_round_amount( $tax ), |
|
755 | - 'price' => wpinv_round_amount( $total ), |
|
752 | + 'discount' => wpinv_round_amount($discount), |
|
753 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
754 | + 'tax' => wpinv_round_amount($tax), |
|
755 | + 'price' => wpinv_round_amount($total), |
|
756 | 756 | 'vat_rates_class' => $tax_class, |
757 | 757 | 'vat_rate' => $tax_rate, |
758 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
758 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
759 | 759 | 'fees' => $fees, |
760 | 760 | ); |
761 | 761 | |
762 | - if ( $wpinv_is_last_cart_item ) { |
|
762 | + if ($wpinv_is_last_cart_item) { |
|
763 | 763 | $wpinv_is_last_cart_item = false; |
764 | 764 | $wpinv_flat_discount_total = 0.00; |
765 | 765 | } |
@@ -768,60 +768,60 @@ discard block |
||
768 | 768 | return $details; |
769 | 769 | } |
770 | 770 | |
771 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
771 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
772 | 772 | global $ajax_cart_details; |
773 | 773 | |
774 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
775 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
774 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
775 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
776 | 776 | |
777 | 777 | $invoice_currency = $invoice->currency; |
778 | 778 | |
779 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
780 | - foreach ( $cart_details as $key => $cart_item ) { |
|
781 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
779 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
780 | + foreach ($cart_details as $key => $cart_item) { |
|
781 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
782 | 782 | |
783 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
784 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
783 | + if (!isset($cart_item['subtotal'])) { |
|
784 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
785 | 785 | } |
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
789 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
789 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
790 | 790 | } |
791 | 791 | |
792 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
793 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
792 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
793 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
794 | 794 | return; |
795 | 795 | } |
796 | 796 | |
797 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
797 | + $invoice = wpinv_get_invoice($invoice_id); |
|
798 | 798 | |
799 | - $old_status = wpinv_status_nicename( $old_status ); |
|
800 | - $new_status = wpinv_status_nicename( $new_status ); |
|
799 | + $old_status = wpinv_status_nicename($old_status); |
|
800 | + $new_status = wpinv_status_nicename($new_status); |
|
801 | 801 | |
802 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
802 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
803 | 803 | |
804 | 804 | // Add note |
805 | - return $invoice->add_note( $status_change, false, false, true ); |
|
805 | + return $invoice->add_note($status_change, false, false, true); |
|
806 | 806 | } |
807 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
807 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
808 | 808 | |
809 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
809 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
810 | 810 | global $wpi_has_free_trial; |
811 | 811 | |
812 | 812 | $wpi_has_free_trial = false; |
813 | 813 | |
814 | - if ( $old_status == 'publish' ) { |
|
814 | + if ($old_status == 'publish') { |
|
815 | 815 | return; // Make sure that payments are only paid once |
816 | 816 | } |
817 | 817 | |
818 | 818 | // Make sure the payment completion is only processed when new status is paid |
819 | - if ( $new_status != 'publish' ) { |
|
819 | + if ($new_status != 'publish') { |
|
820 | 820 | return; |
821 | 821 | } |
822 | 822 | |
823 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
824 | - if ( empty( $invoice ) ) { |
|
823 | + $invoice = new WPInv_Invoice($invoice_id); |
|
824 | + if (empty($invoice)) { |
|
825 | 825 | return; |
826 | 826 | } |
827 | 827 | |
@@ -829,58 +829,58 @@ discard block |
||
829 | 829 | $completed_date = $invoice->completed_date; |
830 | 830 | $cart_details = $invoice->cart_details; |
831 | 831 | |
832 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
832 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
833 | 833 | |
834 | - if ( is_array( $cart_details ) ) { |
|
834 | + if (is_array($cart_details)) { |
|
835 | 835 | // Increase purchase count and earnings |
836 | - foreach ( $cart_details as $cart_index => $item ) { |
|
836 | + foreach ($cart_details as $cart_index => $item) { |
|
837 | 837 | // Ensure these actions only run once, ever |
838 | - if ( empty( $completed_date ) ) { |
|
839 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
838 | + if (empty($completed_date)) { |
|
839 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
840 | 840 | } |
841 | 841 | } |
842 | 842 | } |
843 | 843 | |
844 | 844 | // Check for discount codes and increment their use counts |
845 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
846 | - if( ! empty( $discounts ) ) { |
|
847 | - foreach( $discounts as $code ) { |
|
848 | - wpinv_increase_discount_usage( $code ); |
|
845 | + if ($discounts = $invoice->get_discounts(true)) { |
|
846 | + if (!empty($discounts)) { |
|
847 | + foreach ($discounts as $code) { |
|
848 | + wpinv_increase_discount_usage($code); |
|
849 | 849 | } |
850 | 850 | } |
851 | 851 | } |
852 | 852 | |
853 | 853 | // Ensure this action only runs once ever |
854 | - if( empty( $completed_date ) ) { |
|
854 | + if (empty($completed_date)) { |
|
855 | 855 | // Save the completed date |
856 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
856 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
857 | 857 | $invoice->save(); |
858 | 858 | |
859 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
859 | + do_action('wpinv_complete_payment', $invoice_id); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | // Empty the shopping cart |
863 | 863 | wpinv_empty_cart(); |
864 | 864 | } |
865 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
865 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
866 | 866 | |
867 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
868 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
867 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
868 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
869 | 869 | |
870 | - if ( empty( $invoice ) ) { |
|
870 | + if (empty($invoice)) { |
|
871 | 871 | return false; |
872 | 872 | } |
873 | 873 | |
874 | - return $invoice->update_status( $new_status ); |
|
874 | + return $invoice->update_status($new_status); |
|
875 | 875 | } |
876 | 876 | |
877 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
877 | +function wpinv_cart_has_fees($type = 'all') { |
|
878 | 878 | return false; |
879 | 879 | } |
880 | 880 | |
881 | 881 | function wpinv_validate_checkout_fields() { |
882 | 882 | // Check if there is $_POST |
883 | - if ( empty( $_POST ) ) { |
|
883 | + if (empty($_POST)) { |
|
884 | 884 | return false; |
885 | 885 | } |
886 | 886 | |
@@ -892,11 +892,11 @@ discard block |
||
892 | 892 | ); |
893 | 893 | |
894 | 894 | // Validate agree to terms |
895 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
895 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
896 | 896 | wpinv_checkout_validate_agree_to_terms(); |
897 | 897 | } |
898 | 898 | |
899 | - $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
899 | + $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
900 | 900 | |
901 | 901 | // Return collected data |
902 | 902 | return $valid_data; |
@@ -907,26 +907,26 @@ discard block |
||
907 | 907 | |
908 | 908 | $invoice = wpinv_get_invoice_cart(); |
909 | 909 | $has_subscription = $invoice->is_recurring(); |
910 | - if ( empty( $invoice ) ) { |
|
911 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
910 | + if (empty($invoice)) { |
|
911 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
912 | 912 | return $gateway; |
913 | 913 | } |
914 | 914 | |
915 | 915 | // Check if a gateway value is present |
916 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
917 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
916 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
917 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
918 | 918 | |
919 | - if ( $invoice->is_free() ) { |
|
919 | + if ($invoice->is_free()) { |
|
920 | 920 | $gateway = 'manual'; |
921 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
922 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
923 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
924 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
921 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
922 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
923 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
924 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
929 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
928 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
929 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | return $gateway; |
@@ -938,10 +938,10 @@ discard block |
||
938 | 938 | |
939 | 939 | $error = false; |
940 | 940 | // If we have discounts, loop through them |
941 | - if ( ! empty( $discounts ) ) { |
|
942 | - foreach ( $discounts as $discount ) { |
|
941 | + if (!empty($discounts)) { |
|
942 | + foreach ($discounts as $discount) { |
|
943 | 943 | // Check if valid |
944 | - if ( !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) { |
|
944 | + if (!wpinv_is_discount_valid($discount, get_current_user_id())) { |
|
945 | 945 | // Discount is not valid |
946 | 946 | $error = true; |
947 | 947 | } |
@@ -951,20 +951,20 @@ discard block |
||
951 | 951 | return NULL; |
952 | 952 | } |
953 | 953 | |
954 | - if ( $error && !wpinv_get_errors() ) { |
|
955 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
954 | + if ($error && !wpinv_get_errors()) { |
|
955 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
956 | 956 | } |
957 | 957 | |
958 | - return implode( ',', $discounts ); |
|
958 | + return implode(',', $discounts); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | function wpinv_checkout_validate_cc() { |
962 | 962 | $card_data = wpinv_checkout_get_cc_info(); |
963 | 963 | |
964 | 964 | // Validate the card zip |
965 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
966 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
967 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
965 | + if (!empty($card_data['wpinv_zip'])) { |
|
966 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
967 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
@@ -974,28 +974,28 @@ discard block |
||
974 | 974 | |
975 | 975 | function wpinv_checkout_get_cc_info() { |
976 | 976 | $cc_info = array(); |
977 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
978 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
979 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
980 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
981 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
982 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
983 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
984 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
985 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
986 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
977 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
978 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
979 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
980 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
981 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
982 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
983 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
984 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
985 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
986 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
987 | 987 | |
988 | 988 | // Return cc info |
989 | 989 | return $cc_info; |
990 | 990 | } |
991 | 991 | |
992 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
992 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
993 | 993 | $ret = false; |
994 | 994 | |
995 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
995 | + if (empty($zip) || empty($country_code)) |
|
996 | 996 | return $ret; |
997 | 997 | |
998 | - $country_code = strtoupper( $country_code ); |
|
998 | + $country_code = strtoupper($country_code); |
|
999 | 999 | |
1000 | 1000 | $zip_regex = array( |
1001 | 1001 | "AD" => "AD\d{3}", |
@@ -1155,17 +1155,17 @@ discard block |
||
1155 | 1155 | "ZM" => "\d{5}" |
1156 | 1156 | ); |
1157 | 1157 | |
1158 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1158 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1159 | 1159 | $ret = true; |
1160 | 1160 | |
1161 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1161 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | function wpinv_checkout_validate_agree_to_terms() { |
1165 | 1165 | // Validate agree to terms |
1166 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1166 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1167 | 1167 | // User did not agree |
1168 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1168 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1169 | 1169 | } |
1170 | 1170 | } |
1171 | 1171 | |
@@ -1178,36 +1178,36 @@ discard block |
||
1178 | 1178 | ); |
1179 | 1179 | |
1180 | 1180 | // Verify there is a user_ID |
1181 | - if ( $user_ID > 0 ) { |
|
1181 | + if ($user_ID > 0) { |
|
1182 | 1182 | // Get the logged in user data |
1183 | - $user_data = get_userdata( $user_ID ); |
|
1184 | - $required_fields = wpinv_checkout_required_fields(); |
|
1183 | + $user_data = get_userdata($user_ID); |
|
1184 | + $required_fields = wpinv_checkout_required_fields(); |
|
1185 | 1185 | |
1186 | 1186 | // Loop through required fields and show error messages |
1187 | - if ( !empty( $required_fields ) ) { |
|
1188 | - foreach ( $required_fields as $field_name => $value ) { |
|
1189 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1190 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1187 | + if (!empty($required_fields)) { |
|
1188 | + foreach ($required_fields as $field_name => $value) { |
|
1189 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1190 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | // Verify data |
1196 | - if ( $user_data ) { |
|
1196 | + if ($user_data) { |
|
1197 | 1197 | // Collected logged in user data |
1198 | 1198 | $valid_user_data = array( |
1199 | 1199 | 'user_id' => $user_ID, |
1200 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1201 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1202 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1200 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1201 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1202 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1203 | 1203 | ); |
1204 | 1204 | |
1205 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1206 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1205 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1206 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1207 | 1207 | } |
1208 | 1208 | } else { |
1209 | 1209 | // Set invalid user error |
1210 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1210 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1211 | 1211 | } |
1212 | 1212 | } |
1213 | 1213 | |
@@ -1215,21 +1215,21 @@ discard block |
||
1215 | 1215 | return $valid_user_data; |
1216 | 1216 | } |
1217 | 1217 | |
1218 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1218 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1219 | 1219 | // Initialize user |
1220 | 1220 | $user = false; |
1221 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1221 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1222 | 1222 | |
1223 | 1223 | /*if ( $is_ajax ) { |
1224 | 1224 | // Do not create or login the user during the ajax submission (check for errors only) |
1225 | 1225 | return true; |
1226 | - } else */if ( is_user_logged_in() ) { |
|
1226 | + } else */if (is_user_logged_in()) { |
|
1227 | 1227 | // Set the valid user as the logged in collected data |
1228 | 1228 | $user = $valid_data['logged_in_user']; |
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | // Verify we have an user |
1232 | - if ( false === $user || empty( $user ) ) { |
|
1232 | + if (false === $user || empty($user)) { |
|
1233 | 1233 | // Return false |
1234 | 1234 | return false; |
1235 | 1235 | } |
@@ -1248,11 +1248,11 @@ discard block |
||
1248 | 1248 | 'zip', |
1249 | 1249 | ); |
1250 | 1250 | |
1251 | - foreach ( $address_fields as $field ) { |
|
1252 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1251 | + foreach ($address_fields as $field) { |
|
1252 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1253 | 1253 | |
1254 | - if ( !empty( $user['user_id'] ) ) { |
|
1255 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1254 | + if (!empty($user['user_id'])) { |
|
1255 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1256 | 1256 | } |
1257 | 1257 | } |
1258 | 1258 | |
@@ -1260,28 +1260,28 @@ discard block |
||
1260 | 1260 | return $user; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1263 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1264 | 1264 | global $wpi_session; |
1265 | 1265 | |
1266 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1266 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | function wpinv_get_checkout_session() { |
1270 | 1270 | global $wpi_session; |
1271 | 1271 | |
1272 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1272 | + return $wpi_session->get('wpinv_checkout'); |
|
1273 | 1273 | } |
1274 | 1274 | |
1275 | 1275 | function wpinv_empty_cart() { |
1276 | 1276 | global $wpi_session; |
1277 | 1277 | |
1278 | 1278 | // Remove cart contents |
1279 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1279 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1280 | 1280 | |
1281 | 1281 | // Remove all cart fees |
1282 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1282 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1283 | 1283 | |
1284 | - do_action( 'wpinv_empty_cart' ); |
|
1284 | + do_action('wpinv_empty_cart'); |
|
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | function wpinv_process_checkout() { |
@@ -1293,42 +1293,42 @@ discard block |
||
1293 | 1293 | |
1294 | 1294 | $wpi_checkout_id = $invoice->ID; |
1295 | 1295 | |
1296 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1296 | + do_action('wpinv_pre_process_checkout'); |
|
1297 | 1297 | |
1298 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1298 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1299 | 1299 | $valid_data = false; |
1300 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1300 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1301 | 1301 | } else { |
1302 | 1302 | // Validate the form $_POST data |
1303 | 1303 | $valid_data = wpinv_validate_checkout_fields(); |
1304 | 1304 | |
1305 | 1305 | // Allow themes and plugins to hook to errors |
1306 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1306 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1309 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1310 | 1310 | |
1311 | 1311 | // Validate the user |
1312 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1312 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1313 | 1313 | |
1314 | 1314 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1315 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1315 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1316 | 1316 | |
1317 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1318 | - if ( $is_ajax ) { |
|
1319 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1317 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1318 | + if ($is_ajax) { |
|
1319 | + do_action('wpinv_ajax_checkout_errors'); |
|
1320 | 1320 | die(); |
1321 | 1321 | } else { |
1322 | 1322 | return false; |
1323 | 1323 | } |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - if ( $is_ajax ) { |
|
1326 | + if ($is_ajax) { |
|
1327 | 1327 | // Save address fields. |
1328 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1329 | - foreach ( $address_fields as $field ) { |
|
1330 | - if ( isset( $user[$field] ) ) { |
|
1331 | - $invoice->set( $field, $user[$field] ); |
|
1328 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1329 | + foreach ($address_fields as $field) { |
|
1330 | + if (isset($user[$field])) { |
|
1331 | + $invoice->set($field, $user[$field]); |
|
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | $invoice->save(); |
@@ -1336,15 +1336,15 @@ discard block |
||
1336 | 1336 | |
1337 | 1337 | $response['success'] = true; |
1338 | 1338 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1339 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1339 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1340 | 1340 | $response['data']['discount'] = $invoice->get_discount(); |
1341 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1341 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1342 | 1342 | $response['data']['tax'] = $invoice->get_tax(); |
1343 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1343 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1344 | 1344 | $response['data']['total'] = $invoice->get_total(); |
1345 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1345 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1346 | 1346 | |
1347 | - wp_send_json( $response ); |
|
1347 | + wp_send_json($response); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | 1350 | $user_info = array( |
@@ -1366,42 +1366,42 @@ discard block |
||
1366 | 1366 | |
1367 | 1367 | // Setup invoice information |
1368 | 1368 | $invoice_data = array( |
1369 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1369 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1370 | 1370 | 'items' => $cart_items, |
1371 | 1371 | 'cart_discounts' => $discounts, |
1372 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1373 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1374 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1375 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1376 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1372 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1373 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1374 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1375 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1376 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1377 | 1377 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1378 | 1378 | 'user_email' => $user['email'], |
1379 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1380 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1379 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1380 | + 'user_info' => stripslashes_deep($user_info), |
|
1381 | 1381 | 'post_data' => $_POST, |
1382 | 1382 | 'cart_details' => $cart_items, |
1383 | 1383 | 'gateway' => $valid_data['gateway'], |
1384 | 1384 | 'card_info' => $valid_data['cc_info'] |
1385 | 1385 | ); |
1386 | 1386 | |
1387 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1388 | - if ( is_array( $vat_info ) ) { |
|
1387 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1388 | + if (is_array($vat_info)) { |
|
1389 | 1389 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1390 | 1390 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1391 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1391 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1392 | 1392 | |
1393 | 1393 | // Add the VAT rate to each item in the cart |
1394 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1394 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1395 | 1395 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1396 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1396 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 | // Save vat fields. |
1401 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1402 | - foreach ( $address_fields as $field ) { |
|
1403 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1404 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1401 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1402 | + foreach ($address_fields as $field) { |
|
1403 | + if (isset($invoice_data['user_info'][$field])) { |
|
1404 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | $invoice->save(); |
@@ -1411,49 +1411,49 @@ discard block |
||
1411 | 1411 | $valid_data['user'] = $user; |
1412 | 1412 | |
1413 | 1413 | // Allow themes and plugins to hook before the gateway |
1414 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1414 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1415 | 1415 | |
1416 | 1416 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1417 | - if ( !$invoice_data['price'] ) { |
|
1417 | + if (!$invoice_data['price']) { |
|
1418 | 1418 | // Revert to manual |
1419 | 1419 | $invoice_data['gateway'] = 'manual'; |
1420 | 1420 | $_POST['wpi-gateway'] = 'manual'; |
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | // Allow the invoice data to be modified before it is sent to the gateway |
1424 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1424 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1425 | 1425 | |
1426 | 1426 | // Setup the data we're storing in the purchase session |
1427 | 1427 | $session_data = $invoice_data; |
1428 | 1428 | // Make sure credit card numbers are never stored in sessions |
1429 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1430 | - unset( $session_data['card_info']['card_number'] ); |
|
1429 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1430 | + unset($session_data['card_info']['card_number']); |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1434 | - wpinv_set_checkout_session( $invoice_data ); |
|
1434 | + wpinv_set_checkout_session($invoice_data); |
|
1435 | 1435 | |
1436 | 1436 | // Set gateway |
1437 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1438 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
1439 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
1437 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1438 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
1439 | + $invoice->update_meta('_wpinv_checkout', true); |
|
1440 | 1440 | |
1441 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1441 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1442 | 1442 | |
1443 | 1443 | // Send info to the gateway for payment processing |
1444 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1444 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1445 | 1445 | die(); |
1446 | 1446 | } |
1447 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1447 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1448 | 1448 | |
1449 | -function wpinv_get_invoices( $args ) { |
|
1450 | - $args = wp_parse_args( $args, array( |
|
1451 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1449 | +function wpinv_get_invoices($args) { |
|
1450 | + $args = wp_parse_args($args, array( |
|
1451 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1452 | 1452 | 'type' => 'wpi_invoice', |
1453 | 1453 | 'parent' => null, |
1454 | 1454 | 'user' => null, |
1455 | 1455 | 'email' => '', |
1456 | - 'limit' => get_option( 'posts_per_page' ), |
|
1456 | + 'limit' => get_option('posts_per_page'), |
|
1457 | 1457 | 'offset' => null, |
1458 | 1458 | 'page' => 1, |
1459 | 1459 | 'exclude' => array(), |
@@ -1461,7 +1461,7 @@ discard block |
||
1461 | 1461 | 'order' => 'DESC', |
1462 | 1462 | 'return' => 'objects', |
1463 | 1463 | 'paginate' => false, |
1464 | - ) ); |
|
1464 | + )); |
|
1465 | 1465 | |
1466 | 1466 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1467 | 1467 | $map_legacy = array( |
@@ -1474,20 +1474,20 @@ discard block |
||
1474 | 1474 | 'paged' => 'page', |
1475 | 1475 | ); |
1476 | 1476 | |
1477 | - foreach ( $map_legacy as $from => $to ) { |
|
1478 | - if ( isset( $args[ $from ] ) ) { |
|
1479 | - $args[ $to ] = $args[ $from ]; |
|
1477 | + foreach ($map_legacy as $from => $to) { |
|
1478 | + if (isset($args[$from])) { |
|
1479 | + $args[$to] = $args[$from]; |
|
1480 | 1480 | } |
1481 | 1481 | } |
1482 | 1482 | |
1483 | - $wpinv_cpt = isset( $_REQUEST[ 'wpinv-cpt' ] ) ? $_REQUEST[ 'wpinv-cpt' ] : ''; |
|
1483 | + $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : ''; |
|
1484 | 1484 | |
1485 | - if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
1485 | + if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) |
|
1486 | 1486 | $args['page'] = get_query_var('paged'); |
1487 | - else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
1488 | - $args['page'] = get_query_var( 'page' ); |
|
1489 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1490 | - $args['page'] = $args[ 'page' ]; |
|
1487 | + else if (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) |
|
1488 | + $args['page'] = get_query_var('page'); |
|
1489 | + else if (!empty($args['page'])) |
|
1490 | + $args['page'] = $args['page']; |
|
1491 | 1491 | else |
1492 | 1492 | $args['page'] = 1; |
1493 | 1493 | |
@@ -1500,47 +1500,47 @@ discard block |
||
1500 | 1500 | 'post_status' => $args['status'], |
1501 | 1501 | 'posts_per_page' => $args['limit'], |
1502 | 1502 | 'meta_query' => array(), |
1503 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1503 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1504 | 1504 | 'fields' => 'ids', |
1505 | 1505 | 'orderby' => $args['orderby'], |
1506 | 1506 | 'order' => $args['order'], |
1507 | 1507 | ); |
1508 | 1508 | |
1509 | - if ( !empty( $args['user'] ) ) { |
|
1510 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1509 | + if (!empty($args['user'])) { |
|
1510 | + $wp_query_args['author'] = absint($args['user']); |
|
1511 | 1511 | } |
1512 | 1512 | |
1513 | - if ( ! is_null( $args['parent'] ) ) { |
|
1514 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1513 | + if (!is_null($args['parent'])) { |
|
1514 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1515 | 1515 | } |
1516 | 1516 | |
1517 | - if ( ! is_null( $args['offset'] ) ) { |
|
1518 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1517 | + if (!is_null($args['offset'])) { |
|
1518 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1519 | 1519 | } else { |
1520 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1520 | + $wp_query_args['paged'] = absint($args['page']); |
|
1521 | 1521 | } |
1522 | 1522 | |
1523 | - if ( ! empty( $args['exclude'] ) ) { |
|
1524 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1523 | + if (!empty($args['exclude'])) { |
|
1524 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | - if ( ! $args['paginate' ] ) { |
|
1527 | + if (!$args['paginate']) { |
|
1528 | 1528 | $wp_query_args['no_found_rows'] = true; |
1529 | 1529 | } |
1530 | 1530 | |
1531 | 1531 | // Get results. |
1532 | - $invoices = new WP_Query( $wp_query_args ); |
|
1532 | + $invoices = new WP_Query($wp_query_args); |
|
1533 | 1533 | |
1534 | - if ( 'objects' === $args['return'] ) { |
|
1535 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1536 | - } elseif ( 'self' === $args['return'] ) { |
|
1534 | + if ('objects' === $args['return']) { |
|
1535 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1536 | + } elseif ('self' === $args['return']) { |
|
1537 | 1537 | return $invoices; |
1538 | 1538 | } else { |
1539 | 1539 | $return = $invoices->posts; |
1540 | 1540 | } |
1541 | 1541 | |
1542 | - if ( $args['paginate' ] ) { |
|
1543 | - return (object) array( |
|
1542 | + if ($args['paginate']) { |
|
1543 | + return (object)array( |
|
1544 | 1544 | 'invoices' => $return, |
1545 | 1545 | 'total' => $invoices->found_posts, |
1546 | 1546 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1552,21 +1552,21 @@ discard block |
||
1552 | 1552 | |
1553 | 1553 | function wpinv_get_user_invoices_columns() { |
1554 | 1554 | $columns = array( |
1555 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1556 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1557 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1558 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1559 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1555 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1556 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
1557 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1558 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1559 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1560 | 1560 | ); |
1561 | 1561 | |
1562 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1562 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1563 | 1563 | } |
1564 | 1564 | |
1565 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1565 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1566 | 1566 | global $wpinv_receipt_args; |
1567 | 1567 | |
1568 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1569 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1568 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1569 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1570 | 1570 | 'price' => true, |
1571 | 1571 | 'discount' => true, |
1572 | 1572 | 'items' => true, |
@@ -1575,185 +1575,185 @@ discard block |
||
1575 | 1575 | 'invoice_key' => false, |
1576 | 1576 | 'payment_method' => true, |
1577 | 1577 | 'invoice_id' => true |
1578 | - ), $atts, 'wpinv_receipt' ); |
|
1578 | + ), $atts, 'wpinv_receipt'); |
|
1579 | 1579 | |
1580 | 1580 | $session = wpinv_get_checkout_session(); |
1581 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1582 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1583 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1581 | + if (isset($_GET['invoice_key'])) { |
|
1582 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1583 | + } else if ($session && isset($session['invoice_key'])) { |
|
1584 | 1584 | $invoice_key = $session['invoice_key']; |
1585 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1585 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1586 | 1586 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1587 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1588 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1587 | + } else if (isset($_GET['invoice-id'])) { |
|
1588 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | // No key found |
1592 | - if ( ! isset( $invoice_key ) ) { |
|
1592 | + if (!isset($invoice_key)) { |
|
1593 | 1593 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1594 | 1594 | } |
1595 | 1595 | |
1596 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1597 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1598 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1596 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1597 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1598 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1599 | 1599 | $invoice_id = (int)$_GET['invoice-id']; |
1600 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1600 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1601 | 1601 | } |
1602 | 1602 | |
1603 | 1603 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1604 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1604 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1605 | 1605 | // login redirect |
1606 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1606 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1607 | 1607 | } |
1608 | 1608 | |
1609 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1609 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1610 | 1610 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1611 | 1611 | } |
1612 | 1612 | |
1613 | 1613 | ob_start(); |
1614 | 1614 | |
1615 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1615 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1616 | 1616 | |
1617 | 1617 | $display = ob_get_clean(); |
1618 | 1618 | |
1619 | 1619 | return $display; |
1620 | 1620 | } |
1621 | 1621 | |
1622 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1622 | +function wpinv_get_invoice_id_by_key($key) { |
|
1623 | 1623 | global $wpdb; |
1624 | 1624 | |
1625 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1625 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1626 | 1626 | |
1627 | - if ( $invoice_id != NULL ) |
|
1627 | + if ($invoice_id != NULL) |
|
1628 | 1628 | return $invoice_id; |
1629 | 1629 | |
1630 | 1630 | return 0; |
1631 | 1631 | } |
1632 | 1632 | |
1633 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1633 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1634 | 1634 | $return = false; |
1635 | 1635 | |
1636 | - if ( empty( $invoice_key ) ) { |
|
1636 | + if (empty($invoice_key)) { |
|
1637 | 1637 | return $return; |
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | global $wpinv_receipt_args; |
1641 | 1641 | |
1642 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1643 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1644 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1642 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1643 | + if (isset($_GET['invoice-id'])) { |
|
1644 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
1645 | 1645 | } |
1646 | 1646 | |
1647 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
1648 | - $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
|
1647 | + $user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']); |
|
1648 | + $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']); |
|
1649 | 1649 | |
1650 | - if ( is_user_logged_in() ) { |
|
1651 | - if ( $user_id === (int) get_current_user_id() ) { |
|
1650 | + if (is_user_logged_in()) { |
|
1651 | + if ($user_id === (int)get_current_user_id()) { |
|
1652 | 1652 | $return = true; |
1653 | 1653 | } |
1654 | 1654 | } |
1655 | 1655 | |
1656 | 1656 | $session = wpinv_get_checkout_session(); |
1657 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
1658 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
1657 | + if (!empty($session) && !is_user_logged_in()) { |
|
1658 | + if ($session['invoice_key'] === $invoice_meta['key']) { |
|
1659 | 1659 | $return = true; |
1660 | 1660 | } |
1661 | 1661 | } |
1662 | 1662 | |
1663 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1663 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1664 | 1664 | } |
1665 | 1665 | |
1666 | 1666 | function wpinv_pay_for_invoice() { |
1667 | 1667 | global $wpinv_euvat; |
1668 | 1668 | |
1669 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1669 | + if (isset($_GET['invoice_key'])) { |
|
1670 | 1670 | $checkout_uri = wpinv_get_checkout_uri(); |
1671 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1671 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1672 | 1672 | |
1673 | - if ( empty( $invoice_key ) ) { |
|
1674 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1675 | - wp_redirect( $checkout_uri ); |
|
1673 | + if (empty($invoice_key)) { |
|
1674 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1675 | + wp_redirect($checkout_uri); |
|
1676 | 1676 | wpinv_die(); |
1677 | 1677 | } |
1678 | 1678 | |
1679 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1679 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1680 | 1680 | |
1681 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1682 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1683 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1681 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1682 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1683 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1684 | 1684 | $invoice_id = (int)$_GET['invoice-id']; |
1685 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1685 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1686 | 1686 | } |
1687 | 1687 | |
1688 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1689 | - if ( $invoice->needs_payment() ) { |
|
1688 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1689 | + if ($invoice->needs_payment()) { |
|
1690 | 1690 | $data = array(); |
1691 | 1691 | $data['invoice_id'] = $invoice_id; |
1692 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1692 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1693 | 1693 | |
1694 | - wpinv_set_checkout_session( $data ); |
|
1694 | + wpinv_set_checkout_session($data); |
|
1695 | 1695 | |
1696 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1696 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1697 | 1697 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
1698 | 1698 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
1699 | 1699 | |
1700 | - wpinv_recalculate_tax( true ); |
|
1700 | + wpinv_recalculate_tax(true); |
|
1701 | 1701 | } |
1702 | 1702 | |
1703 | 1703 | } else { |
1704 | 1704 | $checkout_uri = $invoice->get_view_url(); |
1705 | 1705 | } |
1706 | 1706 | } else { |
1707 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
1707 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
1708 | 1708 | |
1709 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
1709 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
1710 | 1710 | } |
1711 | 1711 | |
1712 | - wp_redirect( $checkout_uri ); |
|
1712 | + wp_redirect($checkout_uri); |
|
1713 | 1713 | wpinv_die(); |
1714 | 1714 | } |
1715 | 1715 | } |
1716 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
1716 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
1717 | 1717 | |
1718 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
1719 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
1720 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1718 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
1719 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
1720 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
1721 | 1721 | $user_id = $invoice->get_user_id(); |
1722 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
1722 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
1723 | 1723 | |
1724 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
1725 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
1724 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
1725 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
1726 | 1726 | |
1727 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
1727 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
1728 | 1728 | wpinv_die(); |
1729 | 1729 | } |
1730 | 1730 | } |
1731 | 1731 | } |
1732 | 1732 | } |
1733 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
1733 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
1734 | 1734 | |
1735 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
1736 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
1735 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
1736 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
1737 | 1737 | |
1738 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
1738 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
1739 | 1739 | return false; |
1740 | 1740 | } |
1741 | 1741 | |
1742 | - if ( empty( $transaction_id ) ) { |
|
1742 | + if (empty($transaction_id)) { |
|
1743 | 1743 | $transaction_id = $invoice_id; |
1744 | 1744 | } |
1745 | 1745 | |
1746 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
1746 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
1747 | 1747 | |
1748 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
1748 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
1749 | 1749 | } |
1750 | 1750 | |
1751 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
1752 | - if ( empty( $status_display ) ) { |
|
1753 | - $status_display = wpinv_status_nicename( $status ); |
|
1751 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
1752 | + if (empty($status_display)) { |
|
1753 | + $status_display = wpinv_status_nicename($status); |
|
1754 | 1754 | } |
1755 | 1755 | |
1756 | - switch ( $status ) { |
|
1756 | + switch ($status) { |
|
1757 | 1757 | case 'publish' : |
1758 | 1758 | case 'wpi-renewal' : |
1759 | 1759 | $class = 'label-success'; |
@@ -1778,28 +1778,28 @@ discard block |
||
1778 | 1778 | |
1779 | 1779 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
1780 | 1780 | |
1781 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
1781 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
1782 | 1782 | } |
1783 | 1783 | |
1784 | -function wpinv_format_invoice_number( $number ) { |
|
1785 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
1784 | +function wpinv_format_invoice_number($number) { |
|
1785 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
1786 | 1786 | |
1787 | 1787 | // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release. |
1788 | - if ( $padd === '' || $padd === false || $padd === NULL ) { |
|
1789 | - return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number ); |
|
1788 | + if ($padd === '' || $padd === false || $padd === NULL) { |
|
1789 | + return wp_sprintf(__('WPINV-%d', 'invoicing'), $number); |
|
1790 | 1790 | } |
1791 | 1791 | |
1792 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
1793 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
1792 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
1793 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
1794 | 1794 | |
1795 | - $padd = absint( $padd ); |
|
1796 | - $formatted_number = absint( $number ); |
|
1795 | + $padd = absint($padd); |
|
1796 | + $formatted_number = absint($number); |
|
1797 | 1797 | |
1798 | - if ( $padd > 0 ) { |
|
1799 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
1798 | + if ($padd > 0) { |
|
1799 | + $formatted_number = zeroise($formatted_number, $padd); |
|
1800 | 1800 | } |
1801 | 1801 | |
1802 | 1802 | $formatted_number = $prefix . $formatted_number . $postfix; |
1803 | 1803 | |
1804 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
1804 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
1805 | 1805 | } |
1806 | 1806 | \ No newline at end of file |
@@ -311,8 +311,9 @@ discard block |
||
311 | 311 | |
312 | 312 | $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
313 | 313 | |
314 | - if ( $invoice_id != NULL ) |
|
315 | - return $invoice_id; |
|
314 | + if ( $invoice_id != NULL ) { |
|
315 | + return $invoice_id; |
|
316 | + } |
|
316 | 317 | |
317 | 318 | return 0; |
318 | 319 | } |
@@ -992,8 +993,9 @@ discard block |
||
992 | 993 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
993 | 994 | $ret = false; |
994 | 995 | |
995 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
996 | - return $ret; |
|
996 | + if ( empty( $zip ) || empty( $country_code ) ) { |
|
997 | + return $ret; |
|
998 | + } |
|
997 | 999 | |
998 | 1000 | $country_code = strtoupper( $country_code ); |
999 | 1001 | |
@@ -1155,8 +1157,9 @@ discard block |
||
1155 | 1157 | "ZM" => "\d{5}" |
1156 | 1158 | ); |
1157 | 1159 | |
1158 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1159 | - $ret = true; |
|
1160 | + if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) { |
|
1161 | + $ret = true; |
|
1162 | + } |
|
1160 | 1163 | |
1161 | 1164 | return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
1162 | 1165 | } |
@@ -1482,14 +1485,15 @@ discard block |
||
1482 | 1485 | |
1483 | 1486 | $wpinv_cpt = isset( $_REQUEST[ 'wpinv-cpt' ] ) ? $_REQUEST[ 'wpinv-cpt' ] : ''; |
1484 | 1487 | |
1485 | - if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
1486 | - $args['page'] = get_query_var('paged'); |
|
1487 | - else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
1488 | - $args['page'] = get_query_var( 'page' ); |
|
1489 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1490 | - $args['page'] = $args[ 'page' ]; |
|
1491 | - else |
|
1492 | - $args['page'] = 1; |
|
1488 | + if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) { |
|
1489 | + $args['page'] = get_query_var('paged'); |
|
1490 | + } else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) { |
|
1491 | + $args['page'] = get_query_var( 'page' ); |
|
1492 | + } else if ( !empty( $args[ 'page' ] ) ) { |
|
1493 | + $args['page'] = $args[ 'page' ]; |
|
1494 | + } else { |
|
1495 | + $args['page'] = 1; |
|
1496 | + } |
|
1493 | 1497 | |
1494 | 1498 | /** |
1495 | 1499 | * Generate WP_Query args. This logic will change if orders are moved to |
@@ -1624,8 +1628,9 @@ discard block |
||
1624 | 1628 | |
1625 | 1629 | $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
1626 | 1630 | |
1627 | - if ( $invoice_id != NULL ) |
|
1628 | - return $invoice_id; |
|
1631 | + if ( $invoice_id != NULL ) { |
|
1632 | + return $invoice_id; |
|
1633 | + } |
|
1629 | 1634 | |
1630 | 1635 | return 0; |
1631 | 1636 | } |
@@ -1,28 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_user_invoices( $current_page = 1 ) { |
|
5 | +function wpinv_user_invoices($current_page = 1) { |
|
6 | 6 | global $current_page; |
7 | - do_action( 'wpinv_before_user_invoices_template', $current_page ); |
|
8 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
9 | - do_action( 'wpinv_after_user_invoices_template', $current_page ); |
|
7 | + do_action('wpinv_before_user_invoices_template', $current_page); |
|
8 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
9 | + do_action('wpinv_after_user_invoices_template', $current_page); |
|
10 | 10 | } |
11 | 11 | |
12 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) { |
|
13 | - if ( empty( $user ) ) { |
|
12 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') { |
|
13 | + if (empty($user)) { |
|
14 | 14 | $user = get_current_user_id(); |
15 | 15 | } |
16 | 16 | |
17 | - if ( 0 === $user ) { |
|
17 | + if (0 === $user) { |
|
18 | 18 | return false; |
19 | 19 | } |
20 | 20 | |
21 | - if ( $pagination ) { |
|
22 | - if ( get_query_var( 'paged' ) ) |
|
21 | + if ($pagination) { |
|
22 | + if (get_query_var('paged')) |
|
23 | 23 | $paged = get_query_var('paged'); |
24 | - else if ( get_query_var( 'page' ) ) |
|
25 | - $paged = get_query_var( 'page' ); |
|
24 | + else if (get_query_var('page')) |
|
25 | + $paged = get_query_var('page'); |
|
26 | 26 | else |
27 | 27 | $paged = 1; |
28 | 28 | } |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | 'post_type' => 'wpi_invoice', |
32 | 32 | 'posts_per_page' => 20, |
33 | 33 | 'paged' => null, |
34 | - 'post_status' => array( 'publish', 'pending' ), |
|
34 | + 'post_status' => array('publish', 'pending'), |
|
35 | 35 | 'user' => $user, |
36 | 36 | 'order' => 'date', |
37 | 37 | ); |
38 | 38 | |
39 | - $invoices = get_posts( $args ); |
|
39 | + $invoices = get_posts($args); |
|
40 | 40 | |
41 | 41 | // No invoices |
42 | - if ( ! $invoices ) |
|
42 | + if (!$invoices) |
|
43 | 43 | return false; |
44 | 44 | |
45 | 45 | return $invoices; |
46 | 46 | } |
47 | 47 | |
48 | -function wpinv_dropdown_users( $args = '' ) { |
|
48 | +function wpinv_dropdown_users($args = '') { |
|
49 | 49 | $defaults = array( |
50 | 50 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
51 | 51 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | 'option_none_value' => -1 |
57 | 57 | ); |
58 | 58 | |
59 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
59 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
60 | 60 | |
61 | - $r = wp_parse_args( $args, $defaults ); |
|
61 | + $r = wp_parse_args($args, $defaults); |
|
62 | 62 | |
63 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
63 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
64 | 64 | |
65 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
65 | + $fields = array('ID', 'user_login', 'user_email'); |
|
66 | 66 | |
67 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
68 | - if ( 'display_name_with_login' === $show ) { |
|
67 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
68 | + if ('display_name_with_login' === $show) { |
|
69 | 69 | $fields[] = 'display_name'; |
70 | - } else if ( 'display_name_with_email' === $show ) { |
|
70 | + } else if ('display_name_with_email' === $show) { |
|
71 | 71 | $fields[] = 'display_name'; |
72 | 72 | } else { |
73 | 73 | $fields[] = $show; |
@@ -79,99 +79,99 @@ discard block |
||
79 | 79 | $show_option_none = $r['show_option_none']; |
80 | 80 | $option_none_value = $r['option_none_value']; |
81 | 81 | |
82 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
82 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
83 | 83 | |
84 | - $users = get_users( $query_args ); |
|
84 | + $users = get_users($query_args); |
|
85 | 85 | |
86 | 86 | $output = ''; |
87 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
88 | - $name = esc_attr( $r['name'] ); |
|
89 | - if ( $r['multi'] && ! $r['id'] ) { |
|
87 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
88 | + $name = esc_attr($r['name']); |
|
89 | + if ($r['multi'] && !$r['id']) { |
|
90 | 90 | $id = ''; |
91 | 91 | } else { |
92 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
92 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
93 | 93 | } |
94 | 94 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
95 | 95 | |
96 | - if ( $show_option_all ) { |
|
96 | + if ($show_option_all) { |
|
97 | 97 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
98 | 98 | } |
99 | 99 | |
100 | - if ( $show_option_none ) { |
|
101 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
102 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
100 | + if ($show_option_none) { |
|
101 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
102 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
105 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
106 | 106 | $found_selected = false; |
107 | - $r['selected'] = (int) $r['selected']; |
|
108 | - foreach ( (array) $users as $user ) { |
|
109 | - $user->ID = (int) $user->ID; |
|
110 | - if ( $user->ID === $r['selected'] ) { |
|
107 | + $r['selected'] = (int)$r['selected']; |
|
108 | + foreach ((array)$users as $user) { |
|
109 | + $user->ID = (int)$user->ID; |
|
110 | + if ($user->ID === $r['selected']) { |
|
111 | 111 | $found_selected = true; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - if ( ! $found_selected ) { |
|
116 | - $users[] = get_userdata( $r['selected'] ); |
|
115 | + if (!$found_selected) { |
|
116 | + $users[] = get_userdata($r['selected']); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - foreach ( (array) $users as $user ) { |
|
121 | - if ( 'display_name_with_login' === $show ) { |
|
120 | + foreach ((array)$users as $user) { |
|
121 | + if ('display_name_with_login' === $show) { |
|
122 | 122 | /* translators: 1: display name, 2: user_login */ |
123 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
124 | - } elseif ( 'display_name_with_email' === $show ) { |
|
123 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
124 | + } elseif ('display_name_with_email' === $show) { |
|
125 | 125 | /* translators: 1: display name, 2: user_email */ |
126 | - if ( $user->display_name == $user->user_email ) { |
|
126 | + if ($user->display_name == $user->user_email) { |
|
127 | 127 | $display = $user->display_name; |
128 | 128 | } else { |
129 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
129 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
130 | 130 | } |
131 | - } elseif ( ! empty( $user->$show ) ) { |
|
131 | + } elseif (!empty($user->$show)) { |
|
132 | 132 | $display = $user->$show; |
133 | 133 | } else { |
134 | 134 | $display = '(' . $user->user_login . ')'; |
135 | 135 | } |
136 | 136 | |
137 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
138 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
137 | + $_selected = selected($user->ID, $r['selected'], false); |
|
138 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $output .= "</select>"; |
142 | 142 | } |
143 | 143 | |
144 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
144 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
145 | 145 | |
146 | - if ( $r['echo'] ) { |
|
146 | + if ($r['echo']) { |
|
147 | 147 | echo $html; |
148 | 148 | } |
149 | 149 | return $html; |
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
153 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
154 | - wpinv_login_user( $user_id ); |
|
152 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
153 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
154 | + wpinv_login_user($user_id); |
|
155 | 155 | } else { |
156 | - $redirect_to = wp_login_url( $redirect_to ); |
|
156 | + $redirect_to = wp_login_url($redirect_to); |
|
157 | 157 | } |
158 | 158 | |
159 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
159 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
160 | 160 | |
161 | - wp_redirect( $redirect_to ); |
|
161 | + wp_redirect($redirect_to); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_login_user( $user_id ) { |
|
165 | - if ( is_user_logged_in() ) { |
|
164 | +function wpinv_login_user($user_id) { |
|
165 | + if (is_user_logged_in()) { |
|
166 | 166 | return true; |
167 | 167 | } |
168 | 168 | |
169 | - $user = get_user_by( 'id', $user_id ); |
|
169 | + $user = get_user_by('id', $user_id); |
|
170 | 170 | |
171 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
172 | - wp_set_current_user( $user_id, $user->user_login ); |
|
173 | - wp_set_auth_cookie( $user_id ); |
|
174 | - do_action( 'wp_login', $user->user_login ); |
|
171 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
172 | + wp_set_current_user($user_id, $user->user_login); |
|
173 | + wp_set_auth_cookie($user_id); |
|
174 | + do_action('wp_login', $user->user_login); |
|
175 | 175 | |
176 | 176 | return true; |
177 | 177 | } |