@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // MUST have WordPress. |
4 | -if ( !defined( 'WPINC' ) ) { |
|
5 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
4 | +if (!defined('WPINC')) { |
|
5 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -130,38 +130,38 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @param int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read. |
132 | 132 | */ |
133 | - public function __construct( $invoice = false ) { |
|
133 | + public function __construct($invoice = false) { |
|
134 | 134 | |
135 | - parent::__construct( $invoice ); |
|
135 | + parent::__construct($invoice); |
|
136 | 136 | |
137 | - if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
138 | - $this->set_id( $invoice ); |
|
139 | - } elseif ( $invoice instanceof self ) { |
|
140 | - $this->set_id( $invoice->get_id() ); |
|
141 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
142 | - $this->set_id( $invoice->ID ); |
|
143 | - } elseif ( is_array( $invoice ) ) { |
|
144 | - $this->set_props( $invoice ); |
|
137 | + if (is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type($invoice))) { |
|
138 | + $this->set_id($invoice); |
|
139 | + } elseif ($invoice instanceof self) { |
|
140 | + $this->set_id($invoice->get_id()); |
|
141 | + } elseif (!empty($invoice->ID)) { |
|
142 | + $this->set_id($invoice->ID); |
|
143 | + } elseif (is_array($invoice)) { |
|
144 | + $this->set_props($invoice); |
|
145 | 145 | |
146 | - if ( isset( $invoice['ID'] ) ) { |
|
147 | - $this->set_id( $invoice['ID'] ); |
|
146 | + if (isset($invoice['ID'])) { |
|
147 | + $this->set_id($invoice['ID']); |
|
148 | 148 | } |
149 | 149 | |
150 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) { |
|
151 | - $this->set_id( $invoice_id ); |
|
152 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) { |
|
153 | - $this->set_id( $invoice_id ); |
|
150 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_discount_id_by_code($invoice, 'key')) { |
|
151 | + $this->set_id($invoice_id); |
|
152 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_discount_id_by_code($invoice, 'number')) { |
|
153 | + $this->set_id($invoice_id); |
|
154 | 154 | } else { |
155 | - $this->set_object_read( true ); |
|
155 | + $this->set_object_read(true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Load the datastore. |
159 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
159 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
160 | 160 | |
161 | - if ( $this->get_id() > 0 ) { |
|
162 | - $this->post = get_post( $this->get_id() ); |
|
161 | + if ($this->get_id() > 0) { |
|
162 | + $this->post = get_post($this->get_id()); |
|
163 | 163 | $this->ID = $this->get_id(); |
164 | - $this->data_store->read( $this ); |
|
164 | + $this->data_store->read($this); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | } |
@@ -175,38 +175,38 @@ discard block |
||
175 | 175 | * @since 1.0.15 |
176 | 176 | * @return int |
177 | 177 | */ |
178 | - public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) { |
|
178 | + public static function get_discount_id_by_code($invoice_key_or_number, $field = 'key') { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | 181 | // Trim the code. |
182 | - $key = trim( $invoice_key_or_number ); |
|
182 | + $key = trim($invoice_key_or_number); |
|
183 | 183 | |
184 | 184 | // Valid fields. |
185 | - $fields = array( 'key', 'number' ); |
|
185 | + $fields = array('key', 'number'); |
|
186 | 186 | |
187 | 187 | // Ensure a value has been passed. |
188 | - if ( empty( $key ) || ! in_array( $field, $fields ) ) { |
|
188 | + if (empty($key) || !in_array($field, $fields)) { |
|
189 | 189 | return 0; |
190 | 190 | } |
191 | 191 | |
192 | 192 | // Maybe retrieve from the cache. |
193 | - $invoice_id = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field ); |
|
194 | - if ( ! empty( $invoice_id ) ) { |
|
193 | + $invoice_id = wp_cache_get($key, 'getpaid_invoice_keys_' . $field); |
|
194 | + if (!empty($invoice_id)) { |
|
195 | 195 | return $invoice_id; |
196 | 196 | } |
197 | 197 | |
198 | 198 | // Fetch from the db. |
199 | 199 | $table = $wpdb->prefix . 'getpaid_invoices'; |
200 | 200 | $invoice_id = $wpdb->get_var( |
201 | - $wpdb->prepare( "SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key ) |
|
201 | + $wpdb->prepare("SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key) |
|
202 | 202 | ); |
203 | 203 | |
204 | - if ( empty( $invoice_id ) ) { |
|
204 | + if (empty($invoice_id)) { |
|
205 | 205 | return 0; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // Update the cache with our data |
209 | - wp_cache_set( $key, $invoice_id, 'getpaid_invoice_keys_' . $field ); |
|
209 | + wp_cache_set($key, $invoice_id, 'getpaid_invoice_keys_' . $field); |
|
210 | 210 | |
211 | 211 | return $invoice_id; |
212 | 212 | } |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | /** |
215 | 215 | * Checks if an invoice key is set. |
216 | 216 | */ |
217 | - public function _isset( $key ) { |
|
218 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
217 | + public function _isset($key) { |
|
218 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /* |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * @param string $context View or edit context. |
241 | 241 | * @return int |
242 | 242 | */ |
243 | - public function get_parent_id( $context = 'view' ) { |
|
244 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
243 | + public function get_parent_id($context = 'view') { |
|
244 | + return (int) $this->get_prop('parent_id', $context); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return WPInv_Invoice |
252 | 252 | */ |
253 | 253 | public function get_parent_payment() { |
254 | - return new WPInv_Invoice( $this->get_parent_id() ); |
|
254 | + return new WPInv_Invoice($this->get_parent_id()); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -271,8 +271,8 @@ discard block |
||
271 | 271 | * @param string $context View or edit context. |
272 | 272 | * @return string |
273 | 273 | */ |
274 | - public function get_status( $context = 'view' ) { |
|
275 | - return $this->get_prop( 'status', $context ); |
|
274 | + public function get_status($context = 'view') { |
|
275 | + return $this->get_prop('status', $context); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | * @return string |
283 | 283 | */ |
284 | 284 | public function get_status_nicename() { |
285 | - $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
285 | + $statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
286 | 286 | |
287 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
287 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
288 | 288 | $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
289 | 289 | } |
290 | 290 | |
291 | - $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
|
291 | + $status = isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : $this->get_status(); |
|
292 | 292 | |
293 | - return apply_filters( 'wpinv_get_invoice_status_nicename', $status ); |
|
293 | + return apply_filters('wpinv_get_invoice_status_nicename', $status); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -300,27 +300,27 @@ discard block |
||
300 | 300 | * @param string $context View or edit context. |
301 | 301 | * @return string |
302 | 302 | */ |
303 | - public function get_version( $context = 'view' ) { |
|
304 | - return $this->get_prop( 'version', $context ); |
|
303 | + public function get_version($context = 'view') { |
|
304 | + return $this->get_prop('version', $context); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | 308 | * @deprecated |
309 | 309 | */ |
310 | - public function get_invoice_date( $formatted = true ) { |
|
310 | + public function get_invoice_date($formatted = true) { |
|
311 | 311 | $date_completed = $this->get_date_completed(); |
312 | 312 | $invoice_date = $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
313 | 313 | |
314 | - if ( $invoice_date == '' ) { |
|
314 | + if ($invoice_date == '') { |
|
315 | 315 | $date_created = $this->get_date_created(); |
316 | 316 | $invoice_date = $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
317 | 317 | } |
318 | 318 | |
319 | - if ( $formatted && $invoice_date ) { |
|
320 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
319 | + if ($formatted && $invoice_date) { |
|
320 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
321 | 321 | } |
322 | 322 | |
323 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
323 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | * @param string $context View or edit context. |
331 | 331 | * @return string |
332 | 332 | */ |
333 | - public function get_date_created( $context = 'view' ) { |
|
334 | - return $this->get_prop( 'date_created', $context ); |
|
333 | + public function get_date_created($context = 'view') { |
|
334 | + return $this->get_prop('date_created', $context); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | * @param string $context View or edit context. |
342 | 342 | * @return string |
343 | 343 | */ |
344 | - public function get_created_date( $context = 'view' ) { |
|
345 | - return $this->get_date_created( $context ); |
|
344 | + public function get_created_date($context = 'view') { |
|
345 | + return $this->get_date_created($context); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | * @param string $context View or edit context. |
353 | 353 | * @return string |
354 | 354 | */ |
355 | - public function get_date_created_gmt( $context = 'view' ) { |
|
356 | - $date = $this->get_date_created( $context ); |
|
355 | + public function get_date_created_gmt($context = 'view') { |
|
356 | + $date = $this->get_date_created($context); |
|
357 | 357 | |
358 | - if ( $date ) { |
|
359 | - $date = get_gmt_from_date( $date ); |
|
358 | + if ($date) { |
|
359 | + $date = get_gmt_from_date($date); |
|
360 | 360 | } |
361 | 361 | return $date; |
362 | 362 | } |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * @param string $context View or edit context. |
369 | 369 | * @return string |
370 | 370 | */ |
371 | - public function get_date_modified( $context = 'view' ) { |
|
372 | - return $this->get_prop( 'date_modified', $context ); |
|
371 | + public function get_date_modified($context = 'view') { |
|
372 | + return $this->get_prop('date_modified', $context); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -379,8 +379,8 @@ discard block |
||
379 | 379 | * @param string $context View or edit context. |
380 | 380 | * @return string |
381 | 381 | */ |
382 | - public function get_modified_date( $context = 'view' ) { |
|
383 | - return $this->get_date_modified( $context ); |
|
382 | + public function get_modified_date($context = 'view') { |
|
383 | + return $this->get_date_modified($context); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | * @param string $context View or edit context. |
391 | 391 | * @return string |
392 | 392 | */ |
393 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
394 | - $date = $this->get_date_modified( $context ); |
|
393 | + public function get_date_modified_gmt($context = 'view') { |
|
394 | + $date = $this->get_date_modified($context); |
|
395 | 395 | |
396 | - if ( $date ) { |
|
397 | - $date = get_gmt_from_date( $date ); |
|
396 | + if ($date) { |
|
397 | + $date = get_gmt_from_date($date); |
|
398 | 398 | } |
399 | 399 | return $date; |
400 | 400 | } |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | * @param string $context View or edit context. |
407 | 407 | * @return string |
408 | 408 | */ |
409 | - public function get_due_date( $context = 'view' ) { |
|
410 | - return $this->get_prop( 'due_date', $context ); |
|
409 | + public function get_due_date($context = 'view') { |
|
410 | + return $this->get_prop('due_date', $context); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | * @param string $context View or edit context. |
418 | 418 | * @return string |
419 | 419 | */ |
420 | - public function get_date_due( $context = 'view' ) { |
|
421 | - return $this->get_due_date( $context ); |
|
420 | + public function get_date_due($context = 'view') { |
|
421 | + return $this->get_due_date($context); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
@@ -428,11 +428,11 @@ discard block |
||
428 | 428 | * @param string $context View or edit context. |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public function get_due_date_gmt( $context = 'view' ) { |
|
432 | - $date = $this->get_due_date( $context ); |
|
431 | + public function get_due_date_gmt($context = 'view') { |
|
432 | + $date = $this->get_due_date($context); |
|
433 | 433 | |
434 | - if ( $date ) { |
|
435 | - $date = get_gmt_from_date( $date ); |
|
434 | + if ($date) { |
|
435 | + $date = get_gmt_from_date($date); |
|
436 | 436 | } |
437 | 437 | return $date; |
438 | 438 | } |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | * @param string $context View or edit context. |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - public function get_gmt_date_due( $context = 'view' ) { |
|
448 | - return $this->get_due_date_gmt( $context ); |
|
447 | + public function get_gmt_date_due($context = 'view') { |
|
448 | + return $this->get_due_date_gmt($context); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | * @param string $context View or edit context. |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - public function get_completed_date( $context = 'view' ) { |
|
459 | - return $this->get_prop( 'completed_date', $context ); |
|
458 | + public function get_completed_date($context = 'view') { |
|
459 | + return $this->get_prop('completed_date', $context); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
@@ -466,8 +466,8 @@ discard block |
||
466 | 466 | * @param string $context View or edit context. |
467 | 467 | * @return string |
468 | 468 | */ |
469 | - public function get_date_completed( $context = 'view' ) { |
|
470 | - return $this->get_completed_date( $context ); |
|
469 | + public function get_date_completed($context = 'view') { |
|
470 | + return $this->get_completed_date($context); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
@@ -477,11 +477,11 @@ discard block |
||
477 | 477 | * @param string $context View or edit context. |
478 | 478 | * @return string |
479 | 479 | */ |
480 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
481 | - $date = $this->get_completed_date( $context ); |
|
480 | + public function get_completed_date_gmt($context = 'view') { |
|
481 | + $date = $this->get_completed_date($context); |
|
482 | 482 | |
483 | - if ( $date ) { |
|
484 | - $date = get_gmt_from_date( $date ); |
|
483 | + if ($date) { |
|
484 | + $date = get_gmt_from_date($date); |
|
485 | 485 | } |
486 | 486 | return $date; |
487 | 487 | } |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | * @param string $context View or edit context. |
494 | 494 | * @return string |
495 | 495 | */ |
496 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
497 | - return $this->get_completed_date_gmt( $context ); |
|
496 | + public function get_gmt_completed_date($context = 'view') { |
|
497 | + return $this->get_completed_date_gmt($context); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | * @param string $context View or edit context. |
505 | 505 | * @return string |
506 | 506 | */ |
507 | - public function get_number( $context = 'view' ) { |
|
508 | - $number = $this->get_prop( 'number', $context ); |
|
507 | + public function get_number($context = 'view') { |
|
508 | + $number = $this->get_prop('number', $context); |
|
509 | 509 | |
510 | - if ( empty( $number ) ) { |
|
510 | + if (empty($number)) { |
|
511 | 511 | $number = $this->generate_number(); |
512 | - $this->set_number( $number ); |
|
512 | + $this->set_number($number); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | return $number; |
@@ -522,12 +522,12 @@ discard block |
||
522 | 522 | * @param string $context View or edit context. |
523 | 523 | * @return string |
524 | 524 | */ |
525 | - public function get_key( $context = 'view' ) { |
|
526 | - $key = $this->get_prop( 'key', $context ); |
|
525 | + public function get_key($context = 'view') { |
|
526 | + $key = $this->get_prop('key', $context); |
|
527 | 527 | |
528 | - if ( empty( $key ) ) { |
|
529 | - $key = $this->generate_key( $this->post_type ); |
|
530 | - $this->set_key( $key ); |
|
528 | + if (empty($key)) { |
|
529 | + $key = $this->generate_key($this->post_type); |
|
530 | + $this->set_key($key); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | return $key; |
@@ -540,23 +540,23 @@ discard block |
||
540 | 540 | * @param string $context View or edit context. |
541 | 541 | * @return string |
542 | 542 | */ |
543 | - public function get_type( $context = 'view' ) { |
|
544 | - return $this->get_prop( 'type', $context ); |
|
543 | + public function get_type($context = 'view') { |
|
544 | + return $this->get_prop('type', $context); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | 548 | * @deprecated |
549 | 549 | */ |
550 | - public function get_invoice_quote_type( $post_id ) { |
|
551 | - if ( empty( $post_id ) ) { |
|
550 | + public function get_invoice_quote_type($post_id) { |
|
551 | + if (empty($post_id)) { |
|
552 | 552 | return ''; |
553 | 553 | } |
554 | 554 | |
555 | - $type = get_post_type( $post_id ); |
|
555 | + $type = get_post_type($post_id); |
|
556 | 556 | |
557 | - if ( 'wpi_invoice' === $type ) { |
|
557 | + if ('wpi_invoice' === $type) { |
|
558 | 558 | $post_type = __('Invoice', 'invoicing'); |
559 | - } else{ |
|
559 | + } else { |
|
560 | 560 | $post_type = __('Quote', 'invoicing'); |
561 | 561 | } |
562 | 562 | |
@@ -570,8 +570,8 @@ discard block |
||
570 | 570 | * @param string $context View or edit context. |
571 | 571 | * @return string |
572 | 572 | */ |
573 | - public function get_post_type( $context = 'view' ) { |
|
574 | - return $this->get_prop( 'post_type', $context ); |
|
573 | + public function get_post_type($context = 'view') { |
|
574 | + return $this->get_prop('post_type', $context); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -581,8 +581,8 @@ discard block |
||
581 | 581 | * @param string $context View or edit context. |
582 | 582 | * @return string |
583 | 583 | */ |
584 | - public function get_mode( $context = 'view' ) { |
|
585 | - return $this->get_prop( 'mode', $context ); |
|
584 | + public function get_mode($context = 'view') { |
|
585 | + return $this->get_prop('mode', $context); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
@@ -592,12 +592,12 @@ discard block |
||
592 | 592 | * @param string $context View or edit context. |
593 | 593 | * @return string |
594 | 594 | */ |
595 | - public function get_path( $context = 'view' ) { |
|
596 | - $path = $this->get_prop( 'path', $context ); |
|
595 | + public function get_path($context = 'view') { |
|
596 | + $path = $this->get_prop('path', $context); |
|
597 | 597 | |
598 | - if ( empty( $path ) ) { |
|
599 | - $prefix = apply_filters( 'wpinv_post_name_prefix', 'inv-', $this->post_type ); |
|
600 | - $path = sanitize_title( $prefix . $this->get_id() ); |
|
598 | + if (empty($path)) { |
|
599 | + $prefix = apply_filters('wpinv_post_name_prefix', 'inv-', $this->post_type); |
|
600 | + $path = sanitize_title($prefix . $this->get_id()); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | return $path; |
@@ -610,10 +610,10 @@ discard block |
||
610 | 610 | * @param string $context View or edit context. |
611 | 611 | * @return string |
612 | 612 | */ |
613 | - public function get_name( $context = 'view' ) { |
|
614 | - $name = $this->get_prop( 'title', $context ); |
|
613 | + public function get_name($context = 'view') { |
|
614 | + $name = $this->get_prop('title', $context); |
|
615 | 615 | |
616 | - return empty( $name ) ? $this->get_number( $context ) : $name; |
|
616 | + return empty($name) ? $this->get_number($context) : $name; |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -623,8 +623,8 @@ discard block |
||
623 | 623 | * @param string $context View or edit context. |
624 | 624 | * @return string |
625 | 625 | */ |
626 | - public function get_title( $context = 'view' ) { |
|
627 | - return $this->get_name( $context ); |
|
626 | + public function get_title($context = 'view') { |
|
627 | + return $this->get_name($context); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -634,8 +634,8 @@ discard block |
||
634 | 634 | * @param string $context View or edit context. |
635 | 635 | * @return string |
636 | 636 | */ |
637 | - public function get_description( $context = 'view' ) { |
|
638 | - return $this->get_prop( 'description', $context ); |
|
637 | + public function get_description($context = 'view') { |
|
638 | + return $this->get_prop('description', $context); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
@@ -645,8 +645,8 @@ discard block |
||
645 | 645 | * @param string $context View or edit context. |
646 | 646 | * @return string |
647 | 647 | */ |
648 | - public function get_excerpt( $context = 'view' ) { |
|
649 | - return $this->get_description( $context ); |
|
648 | + public function get_excerpt($context = 'view') { |
|
649 | + return $this->get_description($context); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
@@ -656,8 +656,8 @@ discard block |
||
656 | 656 | * @param string $context View or edit context. |
657 | 657 | * @return string |
658 | 658 | */ |
659 | - public function get_summary( $context = 'view' ) { |
|
660 | - return $this->get_description( $context ); |
|
659 | + public function get_summary($context = 'view') { |
|
660 | + return $this->get_description($context); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -667,23 +667,23 @@ discard block |
||
667 | 667 | * @param string $context View or edit context. |
668 | 668 | * @return array |
669 | 669 | */ |
670 | - public function get_user_info( $context = 'view' ) { |
|
670 | + public function get_user_info($context = 'view') { |
|
671 | 671 | $user_info = array( |
672 | - 'user_id' => $this->get_user_id( $context ), |
|
673 | - 'email' => $this->get_email( $context ), |
|
674 | - 'first_name' => $this->get_first_name( $context ), |
|
675 | - 'last_name' => $this->get_last_name( $context ), |
|
676 | - 'address' => $this->get_address( $context ), |
|
677 | - 'phone' => $this->get_phone( $context ), |
|
678 | - 'city' => $this->get_city( $context ), |
|
679 | - 'country' => $this->get_country( $context ), |
|
680 | - 'state' => $this->get_state( $context ), |
|
681 | - 'zip' => $this->get_zip( $context ), |
|
682 | - 'company' => $this->get_company( $context ), |
|
683 | - 'vat_number' => $this->get_vat_number( $context ), |
|
684 | - 'discount' => $this->get_discount_code( $context ), |
|
672 | + 'user_id' => $this->get_user_id($context), |
|
673 | + 'email' => $this->get_email($context), |
|
674 | + 'first_name' => $this->get_first_name($context), |
|
675 | + 'last_name' => $this->get_last_name($context), |
|
676 | + 'address' => $this->get_address($context), |
|
677 | + 'phone' => $this->get_phone($context), |
|
678 | + 'city' => $this->get_city($context), |
|
679 | + 'country' => $this->get_country($context), |
|
680 | + 'state' => $this->get_state($context), |
|
681 | + 'zip' => $this->get_zip($context), |
|
682 | + 'company' => $this->get_company($context), |
|
683 | + 'vat_number' => $this->get_vat_number($context), |
|
684 | + 'discount' => $this->get_discount_code($context), |
|
685 | 685 | ); |
686 | - return apply_filters( 'wpinv_user_info', $user_info, $this->ID, $this ); |
|
686 | + return apply_filters('wpinv_user_info', $user_info, $this->ID, $this); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * @param string $context View or edit context. |
694 | 694 | * @return int |
695 | 695 | */ |
696 | - public function get_author( $context = 'view' ) { |
|
697 | - return (int) $this->get_prop( 'author', $context ); |
|
696 | + public function get_author($context = 'view') { |
|
697 | + return (int) $this->get_prop('author', $context); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -704,8 +704,8 @@ discard block |
||
704 | 704 | * @param string $context View or edit context. |
705 | 705 | * @return int |
706 | 706 | */ |
707 | - public function get_user_id( $context = 'view' ) { |
|
708 | - return $this->get_author( $context ); |
|
707 | + public function get_user_id($context = 'view') { |
|
708 | + return $this->get_author($context); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
@@ -715,8 +715,8 @@ discard block |
||
715 | 715 | * @param string $context View or edit context. |
716 | 716 | * @return int |
717 | 717 | */ |
718 | - public function get_customer_id( $context = 'view' ) { |
|
719 | - return $this->get_author( $context ); |
|
718 | + public function get_customer_id($context = 'view') { |
|
719 | + return $this->get_author($context); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -726,8 +726,8 @@ discard block |
||
726 | 726 | * @param string $context View or edit context. |
727 | 727 | * @return string |
728 | 728 | */ |
729 | - public function get_ip( $context = 'view' ) { |
|
730 | - return $this->get_prop( 'user_ip', $context ); |
|
729 | + public function get_ip($context = 'view') { |
|
730 | + return $this->get_prop('user_ip', $context); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -737,8 +737,8 @@ discard block |
||
737 | 737 | * @param string $context View or edit context. |
738 | 738 | * @return string |
739 | 739 | */ |
740 | - public function get_user_ip( $context = 'view' ) { |
|
741 | - return $this->get_ip( $context ); |
|
740 | + public function get_user_ip($context = 'view') { |
|
741 | + return $this->get_ip($context); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | /** |
@@ -748,8 +748,8 @@ discard block |
||
748 | 748 | * @param string $context View or edit context. |
749 | 749 | * @return string |
750 | 750 | */ |
751 | - public function get_customer_ip( $context = 'view' ) { |
|
752 | - return $this->get_ip( $context ); |
|
751 | + public function get_customer_ip($context = 'view') { |
|
752 | + return $this->get_ip($context); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
@@ -759,8 +759,8 @@ discard block |
||
759 | 759 | * @param string $context View or edit context. |
760 | 760 | * @return string |
761 | 761 | */ |
762 | - public function get_first_name( $context = 'view' ) { |
|
763 | - return $this->get_prop( 'first_name', $context ); |
|
762 | + public function get_first_name($context = 'view') { |
|
763 | + return $this->get_prop('first_name', $context); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
@@ -770,8 +770,8 @@ discard block |
||
770 | 770 | * @param string $context View or edit context. |
771 | 771 | * @return int |
772 | 772 | */ |
773 | - public function get_user_first_name( $context = 'view' ) { |
|
774 | - return $this->get_first_name( $context ); |
|
773 | + public function get_user_first_name($context = 'view') { |
|
774 | + return $this->get_first_name($context); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | /** |
@@ -781,8 +781,8 @@ discard block |
||
781 | 781 | * @param string $context View or edit context. |
782 | 782 | * @return int |
783 | 783 | */ |
784 | - public function get_customer_first_name( $context = 'view' ) { |
|
785 | - return $this->get_first_name( $context ); |
|
784 | + public function get_customer_first_name($context = 'view') { |
|
785 | + return $this->get_first_name($context); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -792,8 +792,8 @@ discard block |
||
792 | 792 | * @param string $context View or edit context. |
793 | 793 | * @return string |
794 | 794 | */ |
795 | - public function get_last_name( $context = 'view' ) { |
|
796 | - return $this->get_prop( 'last_name', $context ); |
|
795 | + public function get_last_name($context = 'view') { |
|
796 | + return $this->get_prop('last_name', $context); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
@@ -803,8 +803,8 @@ discard block |
||
803 | 803 | * @param string $context View or edit context. |
804 | 804 | * @return int |
805 | 805 | */ |
806 | - public function get_user_last_name( $context = 'view' ) { |
|
807 | - return $this->get_last_name( $context ); |
|
806 | + public function get_user_last_name($context = 'view') { |
|
807 | + return $this->get_last_name($context); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
@@ -814,8 +814,8 @@ discard block |
||
814 | 814 | * @param string $context View or edit context. |
815 | 815 | * @return int |
816 | 816 | */ |
817 | - public function get_customer_last_name( $context = 'view' ) { |
|
818 | - return $this->get_last_name( $context ); |
|
817 | + public function get_customer_last_name($context = 'view') { |
|
818 | + return $this->get_last_name($context); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | /** |
@@ -825,8 +825,8 @@ discard block |
||
825 | 825 | * @param string $context View or edit context. |
826 | 826 | * @return string |
827 | 827 | */ |
828 | - public function get_full_name( $context = 'view' ) { |
|
829 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
828 | + public function get_full_name($context = 'view') { |
|
829 | + return trim($this->get_first_name($context) . ' ' . $this->get_last_name($context)); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -836,8 +836,8 @@ discard block |
||
836 | 836 | * @param string $context View or edit context. |
837 | 837 | * @return int |
838 | 838 | */ |
839 | - public function get_user_full_name( $context = 'view' ) { |
|
840 | - return $this->get_full_name( $context ); |
|
839 | + public function get_user_full_name($context = 'view') { |
|
840 | + return $this->get_full_name($context); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -847,8 +847,8 @@ discard block |
||
847 | 847 | * @param string $context View or edit context. |
848 | 848 | * @return int |
849 | 849 | */ |
850 | - public function get_customer_full_name( $context = 'view' ) { |
|
851 | - return $this->get_full_name( $context ); |
|
850 | + public function get_customer_full_name($context = 'view') { |
|
851 | + return $this->get_full_name($context); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -858,8 +858,8 @@ discard block |
||
858 | 858 | * @param string $context View or edit context. |
859 | 859 | * @return string |
860 | 860 | */ |
861 | - public function get_phone( $context = 'view' ) { |
|
862 | - return $this->get_prop( 'phone', $context ); |
|
861 | + public function get_phone($context = 'view') { |
|
862 | + return $this->get_prop('phone', $context); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -869,8 +869,8 @@ discard block |
||
869 | 869 | * @param string $context View or edit context. |
870 | 870 | * @return int |
871 | 871 | */ |
872 | - public function get_phone_number( $context = 'view' ) { |
|
873 | - return $this->get_phone( $context ); |
|
872 | + public function get_phone_number($context = 'view') { |
|
873 | + return $this->get_phone($context); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param string $context View or edit context. |
881 | 881 | * @return int |
882 | 882 | */ |
883 | - public function get_user_phone( $context = 'view' ) { |
|
884 | - return $this->get_phone( $context ); |
|
883 | + public function get_user_phone($context = 'view') { |
|
884 | + return $this->get_phone($context); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -891,8 +891,8 @@ discard block |
||
891 | 891 | * @param string $context View or edit context. |
892 | 892 | * @return int |
893 | 893 | */ |
894 | - public function get_customer_phone( $context = 'view' ) { |
|
895 | - return $this->get_phone( $context ); |
|
894 | + public function get_customer_phone($context = 'view') { |
|
895 | + return $this->get_phone($context); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | /** |
@@ -902,8 +902,8 @@ discard block |
||
902 | 902 | * @param string $context View or edit context. |
903 | 903 | * @return string |
904 | 904 | */ |
905 | - public function get_email( $context = 'view' ) { |
|
906 | - return $this->get_prop( 'email', $context ); |
|
905 | + public function get_email($context = 'view') { |
|
906 | + return $this->get_prop('email', $context); |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | /** |
@@ -913,8 +913,8 @@ discard block |
||
913 | 913 | * @param string $context View or edit context. |
914 | 914 | * @return string |
915 | 915 | */ |
916 | - public function get_email_address( $context = 'view' ) { |
|
917 | - return $this->get_email( $context ); |
|
916 | + public function get_email_address($context = 'view') { |
|
917 | + return $this->get_email($context); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | /** |
@@ -924,8 +924,8 @@ discard block |
||
924 | 924 | * @param string $context View or edit context. |
925 | 925 | * @return int |
926 | 926 | */ |
927 | - public function get_user_email( $context = 'view' ) { |
|
928 | - return $this->get_email( $context ); |
|
927 | + public function get_user_email($context = 'view') { |
|
928 | + return $this->get_email($context); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
@@ -935,8 +935,8 @@ discard block |
||
935 | 935 | * @param string $context View or edit context. |
936 | 936 | * @return int |
937 | 937 | */ |
938 | - public function get_customer_email( $context = 'view' ) { |
|
939 | - return $this->get_email( $context ); |
|
938 | + public function get_customer_email($context = 'view') { |
|
939 | + return $this->get_email($context); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
@@ -946,9 +946,9 @@ discard block |
||
946 | 946 | * @param string $context View or edit context. |
947 | 947 | * @return string |
948 | 948 | */ |
949 | - public function get_country( $context = 'view' ) { |
|
950 | - $country = $this->get_prop( 'country', $context ); |
|
951 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
949 | + public function get_country($context = 'view') { |
|
950 | + $country = $this->get_prop('country', $context); |
|
951 | + return empty($country) ? wpinv_get_default_country() : $country; |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | /** |
@@ -958,8 +958,8 @@ discard block |
||
958 | 958 | * @param string $context View or edit context. |
959 | 959 | * @return int |
960 | 960 | */ |
961 | - public function get_user_country( $context = 'view' ) { |
|
962 | - return $this->get_country( $context ); |
|
961 | + public function get_user_country($context = 'view') { |
|
962 | + return $this->get_country($context); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | /** |
@@ -969,8 +969,8 @@ discard block |
||
969 | 969 | * @param string $context View or edit context. |
970 | 970 | * @return int |
971 | 971 | */ |
972 | - public function get_customer_country( $context = 'view' ) { |
|
973 | - return $this->get_country( $context ); |
|
972 | + public function get_customer_country($context = 'view') { |
|
973 | + return $this->get_country($context); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
@@ -980,9 +980,9 @@ discard block |
||
980 | 980 | * @param string $context View or edit context. |
981 | 981 | * @return string |
982 | 982 | */ |
983 | - public function get_state( $context = 'view' ) { |
|
984 | - $state = $this->get_prop( 'state', $context ); |
|
985 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
983 | + public function get_state($context = 'view') { |
|
984 | + $state = $this->get_prop('state', $context); |
|
985 | + return empty($state) ? wpinv_get_default_state() : $state; |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | /** |
@@ -992,8 +992,8 @@ discard block |
||
992 | 992 | * @param string $context View or edit context. |
993 | 993 | * @return int |
994 | 994 | */ |
995 | - public function get_user_state( $context = 'view' ) { |
|
996 | - return $this->get_state( $context ); |
|
995 | + public function get_user_state($context = 'view') { |
|
996 | + return $this->get_state($context); |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | /** |
@@ -1003,8 +1003,8 @@ discard block |
||
1003 | 1003 | * @param string $context View or edit context. |
1004 | 1004 | * @return int |
1005 | 1005 | */ |
1006 | - public function get_customer_state( $context = 'view' ) { |
|
1007 | - return $this->get_state( $context ); |
|
1006 | + public function get_customer_state($context = 'view') { |
|
1007 | + return $this->get_state($context); |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | /** |
@@ -1014,8 +1014,8 @@ discard block |
||
1014 | 1014 | * @param string $context View or edit context. |
1015 | 1015 | * @return string |
1016 | 1016 | */ |
1017 | - public function get_city( $context = 'view' ) { |
|
1018 | - return $this->get_prop( 'city', $context ); |
|
1017 | + public function get_city($context = 'view') { |
|
1018 | + return $this->get_prop('city', $context); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | /** |
@@ -1025,8 +1025,8 @@ discard block |
||
1025 | 1025 | * @param string $context View or edit context. |
1026 | 1026 | * @return string |
1027 | 1027 | */ |
1028 | - public function get_user_city( $context = 'view' ) { |
|
1029 | - return $this->get_city( $context ); |
|
1028 | + public function get_user_city($context = 'view') { |
|
1029 | + return $this->get_city($context); |
|
1030 | 1030 | } |
1031 | 1031 | |
1032 | 1032 | /** |
@@ -1036,8 +1036,8 @@ discard block |
||
1036 | 1036 | * @param string $context View or edit context. |
1037 | 1037 | * @return string |
1038 | 1038 | */ |
1039 | - public function get_customer_city( $context = 'view' ) { |
|
1040 | - return $this->get_city( $context ); |
|
1039 | + public function get_customer_city($context = 'view') { |
|
1040 | + return $this->get_city($context); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | /** |
@@ -1047,8 +1047,8 @@ discard block |
||
1047 | 1047 | * @param string $context View or edit context. |
1048 | 1048 | * @return string |
1049 | 1049 | */ |
1050 | - public function get_zip( $context = 'view' ) { |
|
1051 | - return $this->get_prop( 'zip', $context ); |
|
1050 | + public function get_zip($context = 'view') { |
|
1051 | + return $this->get_prop('zip', $context); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1058,8 +1058,8 @@ discard block |
||
1058 | 1058 | * @param string $context View or edit context. |
1059 | 1059 | * @return string |
1060 | 1060 | */ |
1061 | - public function get_user_zip( $context = 'view' ) { |
|
1062 | - return $this->get_zip( $context ); |
|
1061 | + public function get_user_zip($context = 'view') { |
|
1062 | + return $this->get_zip($context); |
|
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | /** |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | * @param string $context View or edit context. |
1070 | 1070 | * @return string |
1071 | 1071 | */ |
1072 | - public function get_customer_zip( $context = 'view' ) { |
|
1073 | - return $this->get_zip( $context ); |
|
1072 | + public function get_customer_zip($context = 'view') { |
|
1073 | + return $this->get_zip($context); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
@@ -1080,8 +1080,8 @@ discard block |
||
1080 | 1080 | * @param string $context View or edit context. |
1081 | 1081 | * @return string |
1082 | 1082 | */ |
1083 | - public function get_company( $context = 'view' ) { |
|
1084 | - return $this->get_prop( 'company', $context ); |
|
1083 | + public function get_company($context = 'view') { |
|
1084 | + return $this->get_prop('company', $context); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | /** |
@@ -1091,8 +1091,8 @@ discard block |
||
1091 | 1091 | * @param string $context View or edit context. |
1092 | 1092 | * @return string |
1093 | 1093 | */ |
1094 | - public function get_user_company( $context = 'view' ) { |
|
1095 | - return $this->get_company( $context ); |
|
1094 | + public function get_user_company($context = 'view') { |
|
1095 | + return $this->get_company($context); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | /** |
@@ -1102,8 +1102,8 @@ discard block |
||
1102 | 1102 | * @param string $context View or edit context. |
1103 | 1103 | * @return string |
1104 | 1104 | */ |
1105 | - public function get_customer_company( $context = 'view' ) { |
|
1106 | - return $this->get_company( $context ); |
|
1105 | + public function get_customer_company($context = 'view') { |
|
1106 | + return $this->get_company($context); |
|
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | /** |
@@ -1113,8 +1113,8 @@ discard block |
||
1113 | 1113 | * @param string $context View or edit context. |
1114 | 1114 | * @return string |
1115 | 1115 | */ |
1116 | - public function get_vat_number( $context = 'view' ) { |
|
1117 | - return $this->get_prop( 'vat_number', $context ); |
|
1116 | + public function get_vat_number($context = 'view') { |
|
1117 | + return $this->get_prop('vat_number', $context); |
|
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | /** |
@@ -1124,8 +1124,8 @@ discard block |
||
1124 | 1124 | * @param string $context View or edit context. |
1125 | 1125 | * @return string |
1126 | 1126 | */ |
1127 | - public function get_user_vat_number( $context = 'view' ) { |
|
1128 | - return $this->get_vat_number( $context ); |
|
1127 | + public function get_user_vat_number($context = 'view') { |
|
1128 | + return $this->get_vat_number($context); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | /** |
@@ -1135,8 +1135,8 @@ discard block |
||
1135 | 1135 | * @param string $context View or edit context. |
1136 | 1136 | * @return string |
1137 | 1137 | */ |
1138 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1139 | - return $this->get_vat_number( $context ); |
|
1138 | + public function get_customer_vat_number($context = 'view') { |
|
1139 | + return $this->get_vat_number($context); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |
@@ -1146,8 +1146,8 @@ discard block |
||
1146 | 1146 | * @param string $context View or edit context. |
1147 | 1147 | * @return string |
1148 | 1148 | */ |
1149 | - public function get_vat_rate( $context = 'view' ) { |
|
1150 | - return $this->get_prop( 'vat_rate', $context ); |
|
1149 | + public function get_vat_rate($context = 'view') { |
|
1150 | + return $this->get_prop('vat_rate', $context); |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | /** |
@@ -1157,8 +1157,8 @@ discard block |
||
1157 | 1157 | * @param string $context View or edit context. |
1158 | 1158 | * @return string |
1159 | 1159 | */ |
1160 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1161 | - return $this->get_vat_rate( $context ); |
|
1160 | + public function get_user_vat_rate($context = 'view') { |
|
1161 | + return $this->get_vat_rate($context); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | /** |
@@ -1168,8 +1168,8 @@ discard block |
||
1168 | 1168 | * @param string $context View or edit context. |
1169 | 1169 | * @return string |
1170 | 1170 | */ |
1171 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1172 | - return $this->get_vat_rate( $context ); |
|
1171 | + public function get_customer_vat_rate($context = 'view') { |
|
1172 | + return $this->get_vat_rate($context); |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | 1175 | /** |
@@ -1179,8 +1179,8 @@ discard block |
||
1179 | 1179 | * @param string $context View or edit context. |
1180 | 1180 | * @return string |
1181 | 1181 | */ |
1182 | - public function get_address( $context = 'view' ) { |
|
1183 | - return $this->get_prop( 'address', $context ); |
|
1182 | + public function get_address($context = 'view') { |
|
1183 | + return $this->get_prop('address', $context); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | /** |
@@ -1190,8 +1190,8 @@ discard block |
||
1190 | 1190 | * @param string $context View or edit context. |
1191 | 1191 | * @return string |
1192 | 1192 | */ |
1193 | - public function get_user_address( $context = 'view' ) { |
|
1194 | - return $this->get_address( $context ); |
|
1193 | + public function get_user_address($context = 'view') { |
|
1194 | + return $this->get_address($context); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | /** |
@@ -1201,8 +1201,8 @@ discard block |
||
1201 | 1201 | * @param string $context View or edit context. |
1202 | 1202 | * @return string |
1203 | 1203 | */ |
1204 | - public function get_customer_address( $context = 'view' ) { |
|
1205 | - return $this->get_address( $context ); |
|
1204 | + public function get_customer_address($context = 'view') { |
|
1205 | + return $this->get_address($context); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | /** |
@@ -1212,8 +1212,8 @@ discard block |
||
1212 | 1212 | * @param string $context View or edit context. |
1213 | 1213 | * @return bool |
1214 | 1214 | */ |
1215 | - public function get_is_viewed( $context = 'view' ) { |
|
1216 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1215 | + public function get_is_viewed($context = 'view') { |
|
1216 | + return (bool) $this->get_prop('is_viewed', $context); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | /** |
@@ -1223,8 +1223,8 @@ discard block |
||
1223 | 1223 | * @param string $context View or edit context. |
1224 | 1224 | * @return bool |
1225 | 1225 | */ |
1226 | - public function get_email_cc( $context = 'view' ) { |
|
1227 | - return $this->get_prop( 'email_cc', $context ); |
|
1226 | + public function get_email_cc($context = 'view') { |
|
1227 | + return $this->get_prop('email_cc', $context); |
|
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | /** |
@@ -1234,8 +1234,8 @@ discard block |
||
1234 | 1234 | * @param string $context View or edit context. |
1235 | 1235 | * @return bool |
1236 | 1236 | */ |
1237 | - public function get_template( $context = 'view' ) { |
|
1238 | - return $this->get_prop( 'template', $context ); |
|
1237 | + public function get_template($context = 'view') { |
|
1238 | + return $this->get_prop('template', $context); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | /** |
@@ -1245,8 +1245,8 @@ discard block |
||
1245 | 1245 | * @param string $context View or edit context. |
1246 | 1246 | * @return bool |
1247 | 1247 | */ |
1248 | - public function get_address_confirmed( $context = 'view' ) { |
|
1249 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1248 | + public function get_address_confirmed($context = 'view') { |
|
1249 | + return (bool) $this->get_prop('address_confirmed', $context); |
|
1250 | 1250 | } |
1251 | 1251 | |
1252 | 1252 | /** |
@@ -1256,8 +1256,8 @@ discard block |
||
1256 | 1256 | * @param string $context View or edit context. |
1257 | 1257 | * @return bool |
1258 | 1258 | */ |
1259 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1260 | - return $this->get_address_confirmed( $context ); |
|
1259 | + public function get_user_address_confirmed($context = 'view') { |
|
1260 | + return $this->get_address_confirmed($context); |
|
1261 | 1261 | } |
1262 | 1262 | |
1263 | 1263 | /** |
@@ -1267,8 +1267,8 @@ discard block |
||
1267 | 1267 | * @param string $context View or edit context. |
1268 | 1268 | * @return bool |
1269 | 1269 | */ |
1270 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1271 | - return $this->get_address_confirmed( $context ); |
|
1270 | + public function get_customer_address_confirmed($context = 'view') { |
|
1271 | + return $this->get_address_confirmed($context); |
|
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | /** |
@@ -1278,12 +1278,12 @@ discard block |
||
1278 | 1278 | * @param string $context View or edit context. |
1279 | 1279 | * @return float |
1280 | 1280 | */ |
1281 | - public function get_subtotal( $context = 'view' ) { |
|
1282 | - $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
|
1281 | + public function get_subtotal($context = 'view') { |
|
1282 | + $subtotal = (float) $this->get_prop('subtotal', $context); |
|
1283 | 1283 | |
1284 | 1284 | // Backwards compatibility. |
1285 | - if ( is_bool( $context ) && $context ) { |
|
1286 | - return wpinv_price( wpinv_format_amount( $subtotal ), $this->get_currency() ); |
|
1285 | + if (is_bool($context) && $context) { |
|
1286 | + return wpinv_price(wpinv_format_amount($subtotal), $this->get_currency()); |
|
1287 | 1287 | } |
1288 | 1288 | |
1289 | 1289 | return $subtotal; |
@@ -1296,8 +1296,8 @@ discard block |
||
1296 | 1296 | * @param string $context View or edit context. |
1297 | 1297 | * @return float |
1298 | 1298 | */ |
1299 | - public function get_total_discount( $context = 'view' ) { |
|
1300 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
1299 | + public function get_total_discount($context = 'view') { |
|
1300 | + return (float) $this->get_prop('total_discount', $context); |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | /** |
@@ -1307,18 +1307,18 @@ discard block |
||
1307 | 1307 | * @param string $context View or edit context. |
1308 | 1308 | * @return float |
1309 | 1309 | */ |
1310 | - public function get_total_tax( $context = 'view' ) { |
|
1311 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
1310 | + public function get_total_tax($context = 'view') { |
|
1311 | + return (float) $this->get_prop('total_tax', $context); |
|
1312 | 1312 | } |
1313 | 1313 | |
1314 | 1314 | /** |
1315 | 1315 | * @deprecated |
1316 | 1316 | */ |
1317 | - public function get_final_tax( $currency = false ) { |
|
1317 | + public function get_final_tax($currency = false) { |
|
1318 | 1318 | $tax = $this->get_total_tax(); |
1319 | 1319 | |
1320 | - if ( $currency ) { |
|
1321 | - return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1320 | + if ($currency) { |
|
1321 | + return wpinv_price(wpinv_format_amount($tax, NULL, false), $this->get_currency()); |
|
1322 | 1322 | } |
1323 | 1323 | |
1324 | 1324 | return $tax; |
@@ -1331,8 +1331,8 @@ discard block |
||
1331 | 1331 | * @param string $context View or edit context. |
1332 | 1332 | * @return float |
1333 | 1333 | */ |
1334 | - public function get_total_fees( $context = 'view' ) { |
|
1335 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
1334 | + public function get_total_fees($context = 'view') { |
|
1335 | + return (float) $this->get_prop('total_fees', $context); |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | /** |
@@ -1342,8 +1342,8 @@ discard block |
||
1342 | 1342 | * @param string $context View or edit context. |
1343 | 1343 | * @return float |
1344 | 1344 | */ |
1345 | - public function get_fees_total( $context = 'view' ) { |
|
1346 | - return $this->get_total_fees( $context ); |
|
1345 | + public function get_fees_total($context = 'view') { |
|
1346 | + return $this->get_total_fees($context); |
|
1347 | 1347 | } |
1348 | 1348 | |
1349 | 1349 | /** |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | */ |
1355 | 1355 | public function get_total() { |
1356 | 1356 | $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
1357 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1357 | + return apply_filters('getpaid_get_invoice_total_amount', $total, $this); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | /** |
@@ -1366,7 +1366,7 @@ discard block |
||
1366 | 1366 | */ |
1367 | 1367 | public function get_initial_total() { |
1368 | 1368 | |
1369 | - if ( empty( $this->totals ) ) { |
|
1369 | + if (empty($this->totals)) { |
|
1370 | 1370 | $this->recalculate_total(); |
1371 | 1371 | } |
1372 | 1372 | |
@@ -1376,11 +1376,11 @@ discard block |
||
1376 | 1376 | $subtotal = $this->totals['subtotal']['initial']; |
1377 | 1377 | $total = $tax + $fee - $discount + $subtotal; |
1378 | 1378 | |
1379 | - if ( 0 > $total ) { |
|
1379 | + if (0 > $total) { |
|
1380 | 1380 | $total = 0; |
1381 | 1381 | } |
1382 | 1382 | |
1383 | - return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
|
1383 | + return apply_filters('wpinv_get_initial_invoice_total', $total, $this); |
|
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 | /** |
@@ -1392,7 +1392,7 @@ discard block |
||
1392 | 1392 | */ |
1393 | 1393 | public function get_recurring_total() { |
1394 | 1394 | |
1395 | - if ( empty( $this->totals ) ) { |
|
1395 | + if (empty($this->totals)) { |
|
1396 | 1396 | $this->recalculate_total(); |
1397 | 1397 | } |
1398 | 1398 | |
@@ -1402,11 +1402,11 @@ discard block |
||
1402 | 1402 | $subtotal = $this->totals['subtotal']['recurring']; |
1403 | 1403 | $total = $tax + $fee - $discount + $subtotal; |
1404 | 1404 | |
1405 | - if ( 0 > $total ) { |
|
1405 | + if (0 > $total) { |
|
1406 | 1406 | $total = 0; |
1407 | 1407 | } |
1408 | 1408 | |
1409 | - return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
|
1409 | + return apply_filters('wpinv_get_recurring_invoice_total', $total, $this); |
|
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | /** |
@@ -1417,10 +1417,10 @@ discard block |
||
1417 | 1417 | * @param string $currency Whether to include the currency. |
1418 | 1418 | * @return float |
1419 | 1419 | */ |
1420 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1420 | + public function get_recurring_details($field = '', $currency = false) { |
|
1421 | 1421 | |
1422 | 1422 | // Maybe recalculate totals. |
1423 | - if ( empty( $this->totals ) ) { |
|
1423 | + if (empty($this->totals)) { |
|
1424 | 1424 | $this->recalculate_total(); |
1425 | 1425 | } |
1426 | 1426 | |
@@ -1440,8 +1440,8 @@ discard block |
||
1440 | 1440 | $currency |
1441 | 1441 | ); |
1442 | 1442 | |
1443 | - if ( isset( $data[$field] ) ) { |
|
1444 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1443 | + if (isset($data[$field])) { |
|
1444 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1445 | 1445 | } |
1446 | 1446 | |
1447 | 1447 | return $data; |
@@ -1454,8 +1454,8 @@ discard block |
||
1454 | 1454 | * @param string $context View or edit context. |
1455 | 1455 | * @return array |
1456 | 1456 | */ |
1457 | - public function get_fees( $context = 'view' ) { |
|
1458 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1457 | + public function get_fees($context = 'view') { |
|
1458 | + return wpinv_parse_list($this->get_prop('fees', $context)); |
|
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 | /** |
@@ -1465,8 +1465,8 @@ discard block |
||
1465 | 1465 | * @param string $context View or edit context. |
1466 | 1466 | * @return array |
1467 | 1467 | */ |
1468 | - public function get_discounts( $context = 'view' ) { |
|
1469 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1468 | + public function get_discounts($context = 'view') { |
|
1469 | + return wpinv_parse_list($this->get_prop('discounts', $context)); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | /** |
@@ -1476,8 +1476,8 @@ discard block |
||
1476 | 1476 | * @param string $context View or edit context. |
1477 | 1477 | * @return array |
1478 | 1478 | */ |
1479 | - public function get_taxes( $context = 'view' ) { |
|
1480 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1479 | + public function get_taxes($context = 'view') { |
|
1480 | + return wpinv_parse_list($this->get_prop('taxes', $context)); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | /** |
@@ -1487,8 +1487,8 @@ discard block |
||
1487 | 1487 | * @param string $context View or edit context. |
1488 | 1488 | * @return GetPaid_Form_Item[] |
1489 | 1489 | */ |
1490 | - public function get_items( $context = 'view' ) { |
|
1491 | - return $this->get_prop( 'items', $context ); |
|
1490 | + public function get_items($context = 'view') { |
|
1491 | + return $this->get_prop('items', $context); |
|
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | /** |
@@ -1498,8 +1498,8 @@ discard block |
||
1498 | 1498 | * @param string $context View or edit context. |
1499 | 1499 | * @return int |
1500 | 1500 | */ |
1501 | - public function get_payment_form( $context = 'view' ) { |
|
1502 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1501 | + public function get_payment_form($context = 'view') { |
|
1502 | + return intval($this->get_prop('payment_form', $context)); |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | 1505 | /** |
@@ -1509,8 +1509,8 @@ discard block |
||
1509 | 1509 | * @param string $context View or edit context. |
1510 | 1510 | * @return string |
1511 | 1511 | */ |
1512 | - public function get_submission_id( $context = 'view' ) { |
|
1513 | - return $this->get_prop( 'submission_id', $context ); |
|
1512 | + public function get_submission_id($context = 'view') { |
|
1513 | + return $this->get_prop('submission_id', $context); |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | /** |
@@ -1520,8 +1520,8 @@ discard block |
||
1520 | 1520 | * @param string $context View or edit context. |
1521 | 1521 | * @return string |
1522 | 1522 | */ |
1523 | - public function get_discount_code( $context = 'view' ) { |
|
1524 | - return $this->get_prop( 'discount_code', $context ); |
|
1523 | + public function get_discount_code($context = 'view') { |
|
1524 | + return $this->get_prop('discount_code', $context); |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | /** |
@@ -1531,8 +1531,8 @@ discard block |
||
1531 | 1531 | * @param string $context View or edit context. |
1532 | 1532 | * @return string |
1533 | 1533 | */ |
1534 | - public function get_gateway( $context = 'view' ) { |
|
1535 | - return $this->get_prop( 'gateway', $context ); |
|
1534 | + public function get_gateway($context = 'view') { |
|
1535 | + return $this->get_prop('gateway', $context); |
|
1536 | 1536 | } |
1537 | 1537 | |
1538 | 1538 | /** |
@@ -1542,8 +1542,8 @@ discard block |
||
1542 | 1542 | * @return string |
1543 | 1543 | */ |
1544 | 1544 | public function get_gateway_title() { |
1545 | - $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
|
1546 | - return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
|
1545 | + $title = wpinv_get_gateway_checkout_label($this->get_gateway()); |
|
1546 | + return apply_filters('wpinv_gateway_title', $title, $this->get_id(), $this); |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | /** |
@@ -1553,8 +1553,8 @@ discard block |
||
1553 | 1553 | * @param string $context View or edit context. |
1554 | 1554 | * @return string |
1555 | 1555 | */ |
1556 | - public function get_transaction_id( $context = 'view' ) { |
|
1557 | - return $this->get_prop( 'transaction_id', $context ); |
|
1556 | + public function get_transaction_id($context = 'view') { |
|
1557 | + return $this->get_prop('transaction_id', $context); |
|
1558 | 1558 | } |
1559 | 1559 | |
1560 | 1560 | /** |
@@ -1564,9 +1564,9 @@ discard block |
||
1564 | 1564 | * @param string $context View or edit context. |
1565 | 1565 | * @return string |
1566 | 1566 | */ |
1567 | - public function get_currency( $context = 'view' ) { |
|
1568 | - $currency = $this->get_prop( 'currency', $context ); |
|
1569 | - return empty( $currency ) ? wpinv_get_currency() : $currency; |
|
1567 | + public function get_currency($context = 'view') { |
|
1568 | + $currency = $this->get_prop('currency', $context); |
|
1569 | + return empty($currency) ? wpinv_get_currency() : $currency; |
|
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | /** |
@@ -1576,8 +1576,8 @@ discard block |
||
1576 | 1576 | * @param string $context View or edit context. |
1577 | 1577 | * @return bool |
1578 | 1578 | */ |
1579 | - public function get_disable_taxes( $context = 'view' ) { |
|
1580 | - return (bool) $this->get_prop( 'disable_taxes', $context ); |
|
1579 | + public function get_disable_taxes($context = 'view') { |
|
1580 | + return (bool) $this->get_prop('disable_taxes', $context); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | /** |
@@ -1587,12 +1587,12 @@ discard block |
||
1587 | 1587 | * @param string $context View or edit context. |
1588 | 1588 | * @return int |
1589 | 1589 | */ |
1590 | - public function get_subscription_id( $context = 'view' ) { |
|
1591 | - $subscription_id = $this->get_prop( 'subscription_id', $context ); |
|
1590 | + public function get_subscription_id($context = 'view') { |
|
1591 | + $subscription_id = $this->get_prop('subscription_id', $context); |
|
1592 | 1592 | |
1593 | - if ( empty( $subscription_id ) && $this->is_renewal() ) { |
|
1593 | + if (empty($subscription_id) && $this->is_renewal()) { |
|
1594 | 1594 | $parent = $this->get_parent(); |
1595 | - return $parent->get_subscription_id( $context ); |
|
1595 | + return $parent->get_subscription_id($context); |
|
1596 | 1596 | } |
1597 | 1597 | |
1598 | 1598 | return $subscription_id; |
@@ -1605,20 +1605,20 @@ discard block |
||
1605 | 1605 | * @param string $context View or edit context. |
1606 | 1606 | * @return array |
1607 | 1607 | */ |
1608 | - public function get_payment_meta( $context = 'view' ) { |
|
1608 | + public function get_payment_meta($context = 'view') { |
|
1609 | 1609 | |
1610 | 1610 | return array( |
1611 | - 'price' => $this->get_total( $context ), |
|
1612 | - 'date' => $this->get_date_created( $context ), |
|
1613 | - 'user_email' => $this->get_email( $context ), |
|
1614 | - 'invoice_key' => $this->get_key( $context ), |
|
1615 | - 'currency' => $this->get_currency( $context ), |
|
1616 | - 'items' => $this->get_items( $context ), |
|
1617 | - 'user_info' => $this->get_user_info( $context ), |
|
1611 | + 'price' => $this->get_total($context), |
|
1612 | + 'date' => $this->get_date_created($context), |
|
1613 | + 'user_email' => $this->get_email($context), |
|
1614 | + 'invoice_key' => $this->get_key($context), |
|
1615 | + 'currency' => $this->get_currency($context), |
|
1616 | + 'items' => $this->get_items($context), |
|
1617 | + 'user_info' => $this->get_user_info($context), |
|
1618 | 1618 | 'cart_details' => $this->get_cart_details(), |
1619 | - 'status' => $this->get_status( $context ), |
|
1620 | - 'fees' => $this->get_fees( $context ), |
|
1621 | - 'taxes' => $this->get_taxes( $context ), |
|
1619 | + 'status' => $this->get_status($context), |
|
1620 | + 'fees' => $this->get_fees($context), |
|
1621 | + 'taxes' => $this->get_taxes($context), |
|
1622 | 1622 | ); |
1623 | 1623 | |
1624 | 1624 | } |
@@ -1633,7 +1633,7 @@ discard block |
||
1633 | 1633 | $items = $this->get_items(); |
1634 | 1634 | $cart_details = array(); |
1635 | 1635 | |
1636 | - foreach ( $items as $item_id => $item ) { |
|
1636 | + foreach ($items as $item_id => $item) { |
|
1637 | 1637 | $cart_details[] = $item->prepare_data_for_saving(); |
1638 | 1638 | } |
1639 | 1639 | |
@@ -1645,11 +1645,11 @@ discard block |
||
1645 | 1645 | * |
1646 | 1646 | * @return null|GetPaid_Form_Item |
1647 | 1647 | */ |
1648 | - public function get_recurring( $object = false ) { |
|
1648 | + public function get_recurring($object = false) { |
|
1649 | 1649 | |
1650 | 1650 | // Are we returning an object? |
1651 | - if ( $object ) { |
|
1652 | - return $this->get_item( $this->recurring_item ); |
|
1651 | + if ($object) { |
|
1652 | + return $this->get_item($this->recurring_item); |
|
1653 | 1653 | } |
1654 | 1654 | |
1655 | 1655 | return $this->recurring_item; |
@@ -1664,15 +1664,15 @@ discard block |
||
1664 | 1664 | public function get_subscription_name() { |
1665 | 1665 | |
1666 | 1666 | // Retrieve the recurring name |
1667 | - $item = $this->get_recurring( true ); |
|
1667 | + $item = $this->get_recurring(true); |
|
1668 | 1668 | |
1669 | 1669 | // Abort if it does not exist. |
1670 | - if ( empty( $item ) ) { |
|
1670 | + if (empty($item)) { |
|
1671 | 1671 | return ''; |
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | // Return the item name. |
1675 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
|
1675 | + return apply_filters('wpinv_invoice_get_subscription_name', $item->get_name(), $this); |
|
1676 | 1676 | } |
1677 | 1677 | |
1678 | 1678 | /** |
@@ -1682,9 +1682,9 @@ discard block |
||
1682 | 1682 | * @return string |
1683 | 1683 | */ |
1684 | 1684 | public function get_view_url() { |
1685 | - $invoice_url = get_permalink( $this->get_id() ); |
|
1686 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1687 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
|
1685 | + $invoice_url = get_permalink($this->get_id()); |
|
1686 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
1687 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this); |
|
1688 | 1688 | } |
1689 | 1689 | |
1690 | 1690 | /** |
@@ -1693,25 +1693,25 @@ discard block |
||
1693 | 1693 | * @since 1.0.19 |
1694 | 1694 | * @return string |
1695 | 1695 | */ |
1696 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1696 | + public function get_checkout_payment_url($deprecated = false, $secret = false) { |
|
1697 | 1697 | |
1698 | 1698 | // Retrieve the checkout url. |
1699 | 1699 | $pay_url = wpinv_get_checkout_uri(); |
1700 | 1700 | |
1701 | 1701 | // Maybe force ssl. |
1702 | - if ( is_ssl() ) { |
|
1703 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
1702 | + if (is_ssl()) { |
|
1703 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
1704 | 1704 | } |
1705 | 1705 | |
1706 | 1706 | // Add the invoice key. |
1707 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1707 | + $pay_url = add_query_arg('invoice_key', $this->get_key(), $pay_url); |
|
1708 | 1708 | |
1709 | 1709 | // (Maybe?) add a secret |
1710 | - if ( $secret ) { |
|
1711 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
|
1710 | + if ($secret) { |
|
1711 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $pay_url); |
|
1712 | 1712 | } |
1713 | 1713 | |
1714 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
|
1714 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret); |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | /** |
@@ -1724,8 +1724,8 @@ discard block |
||
1724 | 1724 | * @param string $context View or edit context. |
1725 | 1725 | * @return mixed Value of the given invoice property (if set). |
1726 | 1726 | */ |
1727 | - public function get( $key, $context = 'view' ) { |
|
1728 | - return $this->get_prop( $key, $context ); |
|
1727 | + public function get($key, $context = 'view') { |
|
1728 | + return $this->get_prop($key, $context); |
|
1729 | 1729 | } |
1730 | 1730 | |
1731 | 1731 | /* |
@@ -1748,11 +1748,11 @@ discard block |
||
1748 | 1748 | * @param mixed $value new value. |
1749 | 1749 | * @return mixed Value of the given invoice property (if set). |
1750 | 1750 | */ |
1751 | - public function set( $key, $value ) { |
|
1751 | + public function set($key, $value) { |
|
1752 | 1752 | |
1753 | 1753 | $setter = "set_$key"; |
1754 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
1755 | - $this->{$setter}( $value ); |
|
1754 | + if (is_callable(array($this, $setter))) { |
|
1755 | + $this->{$setter}($value); |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | 1758 | } |
@@ -1766,35 +1766,35 @@ discard block |
||
1766 | 1766 | * @param bool $manual_update Is this a manual status change?. |
1767 | 1767 | * @return array details of change. |
1768 | 1768 | */ |
1769 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1769 | + public function set_status($new_status, $note = '', $manual_update = false) { |
|
1770 | 1770 | $old_status = $this->get_status(); |
1771 | 1771 | |
1772 | - $this->set_prop( 'status', $new_status ); |
|
1772 | + $this->set_prop('status', $new_status); |
|
1773 | 1773 | |
1774 | 1774 | // If setting the status, ensure it's set to a valid status. |
1775 | - if ( true === $this->object_read ) { |
|
1775 | + if (true === $this->object_read) { |
|
1776 | 1776 | |
1777 | 1777 | // Only allow valid new status. |
1778 | - if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) { |
|
1778 | + if (!array_key_exists($new_status, wpinv_get_invoice_statuses(false, true))) { |
|
1779 | 1779 | $new_status = 'wpi-pending'; |
1780 | 1780 | } |
1781 | 1781 | |
1782 | 1782 | // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
1783 | - if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) { |
|
1783 | + if ($old_status && !array_key_exists($new_status, wpinv_get_invoice_statuses(false, true))) { |
|
1784 | 1784 | $old_status = 'wpi-pending'; |
1785 | 1785 | } |
1786 | 1786 | } |
1787 | 1787 | |
1788 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1788 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
1789 | 1789 | $this->status_transition = array( |
1790 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1790 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
1791 | 1791 | 'to' => $new_status, |
1792 | 1792 | 'note' => $note, |
1793 | 1793 | 'manual' => (bool) $manual_update, |
1794 | 1794 | ); |
1795 | 1795 | |
1796 | - if ( $manual_update ) { |
|
1797 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1796 | + if ($manual_update) { |
|
1797 | + do_action('getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status); |
|
1798 | 1798 | } |
1799 | 1799 | |
1800 | 1800 | $this->maybe_set_date_paid(); |
@@ -1817,8 +1817,8 @@ discard block |
||
1817 | 1817 | */ |
1818 | 1818 | public function maybe_set_date_paid() { |
1819 | 1819 | |
1820 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1821 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
1820 | + if (!$this->get_date_completed('edit') && $this->is_paid()) { |
|
1821 | + $this->set_date_completed(current_time('mysql')); |
|
1822 | 1822 | } |
1823 | 1823 | } |
1824 | 1824 | |
@@ -1827,11 +1827,11 @@ discard block |
||
1827 | 1827 | * |
1828 | 1828 | * @since 1.0.19 |
1829 | 1829 | */ |
1830 | - public function set_parent_id( $value ) { |
|
1831 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
1830 | + public function set_parent_id($value) { |
|
1831 | + if ($value && ($value === $this->get_id())) { |
|
1832 | 1832 | return; |
1833 | 1833 | } |
1834 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
1834 | + $this->set_prop('parent_id', absint($value)); |
|
1835 | 1835 | } |
1836 | 1836 | |
1837 | 1837 | /** |
@@ -1839,8 +1839,8 @@ discard block |
||
1839 | 1839 | * |
1840 | 1840 | * @since 1.0.19 |
1841 | 1841 | */ |
1842 | - public function set_version( $value ) { |
|
1843 | - $this->set_prop( 'version', $value ); |
|
1842 | + public function set_version($value) { |
|
1843 | + $this->set_prop('version', $value); |
|
1844 | 1844 | } |
1845 | 1845 | |
1846 | 1846 | /** |
@@ -1850,15 +1850,15 @@ discard block |
||
1850 | 1850 | * @param string $value Value to set. |
1851 | 1851 | * @return bool Whether or not the date was set. |
1852 | 1852 | */ |
1853 | - public function set_date_created( $value ) { |
|
1854 | - $date = strtotime( $value ); |
|
1853 | + public function set_date_created($value) { |
|
1854 | + $date = strtotime($value); |
|
1855 | 1855 | |
1856 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
1857 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
1856 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
1857 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
1858 | 1858 | return true; |
1859 | 1859 | } |
1860 | 1860 | |
1861 | - return $this->set_prop( 'date_created', '' ); |
|
1861 | + return $this->set_prop('date_created', ''); |
|
1862 | 1862 | |
1863 | 1863 | } |
1864 | 1864 | |
@@ -1869,15 +1869,15 @@ discard block |
||
1869 | 1869 | * @param string $value Value to set. |
1870 | 1870 | * @return bool Whether or not the date was set. |
1871 | 1871 | */ |
1872 | - public function set_due_date( $value ) { |
|
1873 | - $date = strtotime( $value ); |
|
1872 | + public function set_due_date($value) { |
|
1873 | + $date = strtotime($value); |
|
1874 | 1874 | |
1875 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
1876 | - $this->set_prop( 'due_date', date( 'Y-m-d H:i:s', $date ) ); |
|
1875 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
1876 | + $this->set_prop('due_date', date('Y-m-d H:i:s', $date)); |
|
1877 | 1877 | return true; |
1878 | 1878 | } |
1879 | 1879 | |
1880 | - $this->set_prop( 'due_date', '' ); |
|
1880 | + $this->set_prop('due_date', ''); |
|
1881 | 1881 | return false; |
1882 | 1882 | |
1883 | 1883 | } |
@@ -1888,8 +1888,8 @@ discard block |
||
1888 | 1888 | * @since 1.0.19 |
1889 | 1889 | * @param string $value New name. |
1890 | 1890 | */ |
1891 | - public function set_date_due( $value ) { |
|
1892 | - $this->set_due_date( $value ); |
|
1891 | + public function set_date_due($value) { |
|
1892 | + $this->set_due_date($value); |
|
1893 | 1893 | } |
1894 | 1894 | |
1895 | 1895 | /** |
@@ -1899,15 +1899,15 @@ discard block |
||
1899 | 1899 | * @param string $value Value to set. |
1900 | 1900 | * @return bool Whether or not the date was set. |
1901 | 1901 | */ |
1902 | - public function set_completed_date( $value ) { |
|
1903 | - $date = strtotime( $value ); |
|
1902 | + public function set_completed_date($value) { |
|
1903 | + $date = strtotime($value); |
|
1904 | 1904 | |
1905 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
1906 | - $this->set_prop( 'completed_date', date( 'Y-m-d H:i:s', $date ) ); |
|
1905 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
1906 | + $this->set_prop('completed_date', date('Y-m-d H:i:s', $date)); |
|
1907 | 1907 | return true; |
1908 | 1908 | } |
1909 | 1909 | |
1910 | - $this->set_prop( 'completed_date', '' ); |
|
1910 | + $this->set_prop('completed_date', ''); |
|
1911 | 1911 | return false; |
1912 | 1912 | |
1913 | 1913 | } |
@@ -1918,8 +1918,8 @@ discard block |
||
1918 | 1918 | * @since 1.0.19 |
1919 | 1919 | * @param string $value New name. |
1920 | 1920 | */ |
1921 | - public function set_date_completed( $value ) { |
|
1922 | - $this->set_completed_date( $value ); |
|
1921 | + public function set_date_completed($value) { |
|
1922 | + $this->set_completed_date($value); |
|
1923 | 1923 | } |
1924 | 1924 | |
1925 | 1925 | /** |
@@ -1929,15 +1929,15 @@ discard block |
||
1929 | 1929 | * @param string $value Value to set. |
1930 | 1930 | * @return bool Whether or not the date was set. |
1931 | 1931 | */ |
1932 | - public function set_date_modified( $value ) { |
|
1933 | - $date = strtotime( $value ); |
|
1932 | + public function set_date_modified($value) { |
|
1933 | + $date = strtotime($value); |
|
1934 | 1934 | |
1935 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
1936 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
1935 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
1936 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
1937 | 1937 | return true; |
1938 | 1938 | } |
1939 | 1939 | |
1940 | - $this->set_prop( 'date_modified', '' ); |
|
1940 | + $this->set_prop('date_modified', ''); |
|
1941 | 1941 | return false; |
1942 | 1942 | |
1943 | 1943 | } |
@@ -1948,9 +1948,9 @@ discard block |
||
1948 | 1948 | * @since 1.0.19 |
1949 | 1949 | * @param string $value New number. |
1950 | 1950 | */ |
1951 | - public function set_number( $value ) { |
|
1952 | - $number = sanitize_text_field( $value ); |
|
1953 | - $this->set_prop( 'number', $number ); |
|
1951 | + public function set_number($value) { |
|
1952 | + $number = sanitize_text_field($value); |
|
1953 | + $this->set_prop('number', $number); |
|
1954 | 1954 | } |
1955 | 1955 | |
1956 | 1956 | /** |
@@ -1959,9 +1959,9 @@ discard block |
||
1959 | 1959 | * @since 1.0.19 |
1960 | 1960 | * @param string $value Type. |
1961 | 1961 | */ |
1962 | - public function set_type( $value ) { |
|
1963 | - $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
|
1964 | - $this->set_prop( 'type', $type ); |
|
1962 | + public function set_type($value) { |
|
1963 | + $type = sanitize_text_field(str_replace('wpi_', '', $value)); |
|
1964 | + $this->set_prop('type', $type); |
|
1965 | 1965 | } |
1966 | 1966 | |
1967 | 1967 | /** |
@@ -1970,10 +1970,10 @@ discard block |
||
1970 | 1970 | * @since 1.0.19 |
1971 | 1971 | * @param string $value Post type. |
1972 | 1972 | */ |
1973 | - public function set_post_type( $value ) { |
|
1974 | - if ( getpaid_is_invoice_post_type( $value ) ) { |
|
1975 | - $this->set_type( $value ); |
|
1976 | - $this->set_prop( 'post_type', $value ); |
|
1973 | + public function set_post_type($value) { |
|
1974 | + if (getpaid_is_invoice_post_type($value)) { |
|
1975 | + $this->set_type($value); |
|
1976 | + $this->set_prop('post_type', $value); |
|
1977 | 1977 | } |
1978 | 1978 | } |
1979 | 1979 | |
@@ -1983,9 +1983,9 @@ discard block |
||
1983 | 1983 | * @since 1.0.19 |
1984 | 1984 | * @param string $value New key. |
1985 | 1985 | */ |
1986 | - public function set_key( $value ) { |
|
1987 | - $key = sanitize_text_field( $value ); |
|
1988 | - $this->set_prop( 'key', $key ); |
|
1986 | + public function set_key($value) { |
|
1987 | + $key = sanitize_text_field($value); |
|
1988 | + $this->set_prop('key', $key); |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | 1991 | /** |
@@ -1994,9 +1994,9 @@ discard block |
||
1994 | 1994 | * @since 1.0.19 |
1995 | 1995 | * @param string $value mode. |
1996 | 1996 | */ |
1997 | - public function set_mode( $value ) { |
|
1998 | - if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
|
1999 | - $this->set_prop( 'value', $value ); |
|
1997 | + public function set_mode($value) { |
|
1998 | + if (!in_array($value, array('live', 'test'))) { |
|
1999 | + $this->set_prop('value', $value); |
|
2000 | 2000 | } |
2001 | 2001 | } |
2002 | 2002 | |
@@ -2006,8 +2006,8 @@ discard block |
||
2006 | 2006 | * @since 1.0.19 |
2007 | 2007 | * @param string $value path. |
2008 | 2008 | */ |
2009 | - public function set_path( $value ) { |
|
2010 | - $this->set_prop( 'path', $value ); |
|
2009 | + public function set_path($value) { |
|
2010 | + $this->set_prop('path', $value); |
|
2011 | 2011 | } |
2012 | 2012 | |
2013 | 2013 | /** |
@@ -2016,9 +2016,9 @@ discard block |
||
2016 | 2016 | * @since 1.0.19 |
2017 | 2017 | * @param string $value New name. |
2018 | 2018 | */ |
2019 | - public function set_name( $value ) { |
|
2020 | - $name = sanitize_text_field( $value ); |
|
2021 | - $this->set_prop( 'name', $name ); |
|
2019 | + public function set_name($value) { |
|
2020 | + $name = sanitize_text_field($value); |
|
2021 | + $this->set_prop('name', $name); |
|
2022 | 2022 | } |
2023 | 2023 | |
2024 | 2024 | /** |
@@ -2027,8 +2027,8 @@ discard block |
||
2027 | 2027 | * @since 1.0.19 |
2028 | 2028 | * @param string $value New name. |
2029 | 2029 | */ |
2030 | - public function set_title( $value ) { |
|
2031 | - $this->set_name( $value ); |
|
2030 | + public function set_title($value) { |
|
2031 | + $this->set_name($value); |
|
2032 | 2032 | } |
2033 | 2033 | |
2034 | 2034 | /** |
@@ -2037,9 +2037,9 @@ discard block |
||
2037 | 2037 | * @since 1.0.19 |
2038 | 2038 | * @param string $value New description. |
2039 | 2039 | */ |
2040 | - public function set_description( $value ) { |
|
2041 | - $description = wp_kses_post( $value ); |
|
2042 | - return $this->set_prop( 'description', $description ); |
|
2040 | + public function set_description($value) { |
|
2041 | + $description = wp_kses_post($value); |
|
2042 | + return $this->set_prop('description', $description); |
|
2043 | 2043 | } |
2044 | 2044 | |
2045 | 2045 | /** |
@@ -2048,8 +2048,8 @@ discard block |
||
2048 | 2048 | * @since 1.0.19 |
2049 | 2049 | * @param string $value New description. |
2050 | 2050 | */ |
2051 | - public function set_excerpt( $value ) { |
|
2052 | - $this->set_description( $value ); |
|
2051 | + public function set_excerpt($value) { |
|
2052 | + $this->set_description($value); |
|
2053 | 2053 | } |
2054 | 2054 | |
2055 | 2055 | /** |
@@ -2058,8 +2058,8 @@ discard block |
||
2058 | 2058 | * @since 1.0.19 |
2059 | 2059 | * @param string $value New description. |
2060 | 2060 | */ |
2061 | - public function set_summary( $value ) { |
|
2062 | - $this->set_description( $value ); |
|
2061 | + public function set_summary($value) { |
|
2062 | + $this->set_description($value); |
|
2063 | 2063 | } |
2064 | 2064 | |
2065 | 2065 | /** |
@@ -2068,12 +2068,12 @@ discard block |
||
2068 | 2068 | * @since 1.0.19 |
2069 | 2069 | * @param int $value New author. |
2070 | 2070 | */ |
2071 | - public function set_author( $value ) { |
|
2072 | - $user = get_user_by( 'id', (int) $value ); |
|
2071 | + public function set_author($value) { |
|
2072 | + $user = get_user_by('id', (int) $value); |
|
2073 | 2073 | |
2074 | - if ( $user && $user->ID ) { |
|
2075 | - $this->set_prop( 'author', $user->ID ); |
|
2076 | - $this->set_prop( 'email', $user->user_email ); |
|
2074 | + if ($user && $user->ID) { |
|
2075 | + $this->set_prop('author', $user->ID); |
|
2076 | + $this->set_prop('email', $user->user_email); |
|
2077 | 2077 | } |
2078 | 2078 | |
2079 | 2079 | } |
@@ -2084,8 +2084,8 @@ discard block |
||
2084 | 2084 | * @since 1.0.19 |
2085 | 2085 | * @param int $value New user id. |
2086 | 2086 | */ |
2087 | - public function set_user_id( $value ) { |
|
2088 | - $this->set_author( $value ); |
|
2087 | + public function set_user_id($value) { |
|
2088 | + $this->set_author($value); |
|
2089 | 2089 | } |
2090 | 2090 | |
2091 | 2091 | /** |
@@ -2094,8 +2094,8 @@ discard block |
||
2094 | 2094 | * @since 1.0.19 |
2095 | 2095 | * @param int $value New user id. |
2096 | 2096 | */ |
2097 | - public function set_customer_id( $value ) { |
|
2098 | - $this->set_author( $value ); |
|
2097 | + public function set_customer_id($value) { |
|
2098 | + $this->set_author($value); |
|
2099 | 2099 | } |
2100 | 2100 | |
2101 | 2101 | /** |
@@ -2104,8 +2104,8 @@ discard block |
||
2104 | 2104 | * @since 1.0.19 |
2105 | 2105 | * @param string $value ip address. |
2106 | 2106 | */ |
2107 | - public function set_ip( $value ) { |
|
2108 | - $this->set_prop( 'ip', $value ); |
|
2107 | + public function set_ip($value) { |
|
2108 | + $this->set_prop('ip', $value); |
|
2109 | 2109 | } |
2110 | 2110 | |
2111 | 2111 | /** |
@@ -2114,8 +2114,8 @@ discard block |
||
2114 | 2114 | * @since 1.0.19 |
2115 | 2115 | * @param string $value ip address. |
2116 | 2116 | */ |
2117 | - public function set_user_ip( $value ) { |
|
2118 | - $this->set_ip( $value ); |
|
2117 | + public function set_user_ip($value) { |
|
2118 | + $this->set_ip($value); |
|
2119 | 2119 | } |
2120 | 2120 | |
2121 | 2121 | /** |
@@ -2124,8 +2124,8 @@ discard block |
||
2124 | 2124 | * @since 1.0.19 |
2125 | 2125 | * @param string $value first name. |
2126 | 2126 | */ |
2127 | - public function set_first_name( $value ) { |
|
2128 | - $this->set_prop( 'first_name', $value ); |
|
2127 | + public function set_first_name($value) { |
|
2128 | + $this->set_prop('first_name', $value); |
|
2129 | 2129 | } |
2130 | 2130 | |
2131 | 2131 | /** |
@@ -2134,8 +2134,8 @@ discard block |
||
2134 | 2134 | * @since 1.0.19 |
2135 | 2135 | * @param string $value first name. |
2136 | 2136 | */ |
2137 | - public function set_user_first_name( $value ) { |
|
2138 | - $this->set_first_name( $value ); |
|
2137 | + public function set_user_first_name($value) { |
|
2138 | + $this->set_first_name($value); |
|
2139 | 2139 | } |
2140 | 2140 | |
2141 | 2141 | /** |
@@ -2144,8 +2144,8 @@ discard block |
||
2144 | 2144 | * @since 1.0.19 |
2145 | 2145 | * @param string $value first name. |
2146 | 2146 | */ |
2147 | - public function set_customer_first_name( $value ) { |
|
2148 | - $this->set_first_name( $value ); |
|
2147 | + public function set_customer_first_name($value) { |
|
2148 | + $this->set_first_name($value); |
|
2149 | 2149 | } |
2150 | 2150 | |
2151 | 2151 | /** |
@@ -2154,8 +2154,8 @@ discard block |
||
2154 | 2154 | * @since 1.0.19 |
2155 | 2155 | * @param string $value last name. |
2156 | 2156 | */ |
2157 | - public function set_last_name( $value ) { |
|
2158 | - $this->set_prop( 'last_name', $value ); |
|
2157 | + public function set_last_name($value) { |
|
2158 | + $this->set_prop('last_name', $value); |
|
2159 | 2159 | } |
2160 | 2160 | |
2161 | 2161 | /** |
@@ -2164,8 +2164,8 @@ discard block |
||
2164 | 2164 | * @since 1.0.19 |
2165 | 2165 | * @param string $value last name. |
2166 | 2166 | */ |
2167 | - public function set_user_last_name( $value ) { |
|
2168 | - $this->set_last_name( $value ); |
|
2167 | + public function set_user_last_name($value) { |
|
2168 | + $this->set_last_name($value); |
|
2169 | 2169 | } |
2170 | 2170 | |
2171 | 2171 | /** |
@@ -2174,8 +2174,8 @@ discard block |
||
2174 | 2174 | * @since 1.0.19 |
2175 | 2175 | * @param string $value last name. |
2176 | 2176 | */ |
2177 | - public function set_customer_last_name( $value ) { |
|
2178 | - $this->set_last_name( $value ); |
|
2177 | + public function set_customer_last_name($value) { |
|
2178 | + $this->set_last_name($value); |
|
2179 | 2179 | } |
2180 | 2180 | |
2181 | 2181 | /** |
@@ -2184,8 +2184,8 @@ discard block |
||
2184 | 2184 | * @since 1.0.19 |
2185 | 2185 | * @param string $value phone. |
2186 | 2186 | */ |
2187 | - public function set_phone( $value ) { |
|
2188 | - $this->set_prop( 'phone', $value ); |
|
2187 | + public function set_phone($value) { |
|
2188 | + $this->set_prop('phone', $value); |
|
2189 | 2189 | } |
2190 | 2190 | |
2191 | 2191 | /** |
@@ -2194,8 +2194,8 @@ discard block |
||
2194 | 2194 | * @since 1.0.19 |
2195 | 2195 | * @param string $value phone. |
2196 | 2196 | */ |
2197 | - public function set_user_phone( $value ) { |
|
2198 | - $this->set_phone( $value ); |
|
2197 | + public function set_user_phone($value) { |
|
2198 | + $this->set_phone($value); |
|
2199 | 2199 | } |
2200 | 2200 | |
2201 | 2201 | /** |
@@ -2204,8 +2204,8 @@ discard block |
||
2204 | 2204 | * @since 1.0.19 |
2205 | 2205 | * @param string $value phone. |
2206 | 2206 | */ |
2207 | - public function set_customer_phone( $value ) { |
|
2208 | - $this->set_phone( $value ); |
|
2207 | + public function set_customer_phone($value) { |
|
2208 | + $this->set_phone($value); |
|
2209 | 2209 | } |
2210 | 2210 | |
2211 | 2211 | /** |
@@ -2214,8 +2214,8 @@ discard block |
||
2214 | 2214 | * @since 1.0.19 |
2215 | 2215 | * @param string $value phone. |
2216 | 2216 | */ |
2217 | - public function set_phone_number( $value ) { |
|
2218 | - $this->set_phone( $value ); |
|
2217 | + public function set_phone_number($value) { |
|
2218 | + $this->set_phone($value); |
|
2219 | 2219 | } |
2220 | 2220 | |
2221 | 2221 | /** |
@@ -2224,8 +2224,8 @@ discard block |
||
2224 | 2224 | * @since 1.0.19 |
2225 | 2225 | * @param string $value email address. |
2226 | 2226 | */ |
2227 | - public function set_email( $value ) { |
|
2228 | - $this->set_prop( 'email', $value ); |
|
2227 | + public function set_email($value) { |
|
2228 | + $this->set_prop('email', $value); |
|
2229 | 2229 | } |
2230 | 2230 | |
2231 | 2231 | /** |
@@ -2234,8 +2234,8 @@ discard block |
||
2234 | 2234 | * @since 1.0.19 |
2235 | 2235 | * @param string $value email address. |
2236 | 2236 | */ |
2237 | - public function set_user_email( $value ) { |
|
2238 | - $this->set_email( $value ); |
|
2237 | + public function set_user_email($value) { |
|
2238 | + $this->set_email($value); |
|
2239 | 2239 | } |
2240 | 2240 | |
2241 | 2241 | /** |
@@ -2244,8 +2244,8 @@ discard block |
||
2244 | 2244 | * @since 1.0.19 |
2245 | 2245 | * @param string $value email address. |
2246 | 2246 | */ |
2247 | - public function set_email_address( $value ) { |
|
2248 | - $this->set_email( $value ); |
|
2247 | + public function set_email_address($value) { |
|
2248 | + $this->set_email($value); |
|
2249 | 2249 | } |
2250 | 2250 | |
2251 | 2251 | /** |
@@ -2254,8 +2254,8 @@ discard block |
||
2254 | 2254 | * @since 1.0.19 |
2255 | 2255 | * @param string $value email address. |
2256 | 2256 | */ |
2257 | - public function set_customer_email( $value ) { |
|
2258 | - $this->set_email( $value ); |
|
2257 | + public function set_customer_email($value) { |
|
2258 | + $this->set_email($value); |
|
2259 | 2259 | } |
2260 | 2260 | |
2261 | 2261 | /** |
@@ -2264,8 +2264,8 @@ discard block |
||
2264 | 2264 | * @since 1.0.19 |
2265 | 2265 | * @param string $value country. |
2266 | 2266 | */ |
2267 | - public function set_country( $value ) { |
|
2268 | - $this->set_prop( 'country', $value ); |
|
2267 | + public function set_country($value) { |
|
2268 | + $this->set_prop('country', $value); |
|
2269 | 2269 | } |
2270 | 2270 | |
2271 | 2271 | /** |
@@ -2274,8 +2274,8 @@ discard block |
||
2274 | 2274 | * @since 1.0.19 |
2275 | 2275 | * @param string $value country. |
2276 | 2276 | */ |
2277 | - public function set_user_country( $value ) { |
|
2278 | - $this->set_country( $value ); |
|
2277 | + public function set_user_country($value) { |
|
2278 | + $this->set_country($value); |
|
2279 | 2279 | } |
2280 | 2280 | |
2281 | 2281 | /** |
@@ -2284,8 +2284,8 @@ discard block |
||
2284 | 2284 | * @since 1.0.19 |
2285 | 2285 | * @param string $value country. |
2286 | 2286 | */ |
2287 | - public function set_customer_country( $value ) { |
|
2288 | - $this->set_country( $value ); |
|
2287 | + public function set_customer_country($value) { |
|
2288 | + $this->set_country($value); |
|
2289 | 2289 | } |
2290 | 2290 | |
2291 | 2291 | /** |
@@ -2294,8 +2294,8 @@ discard block |
||
2294 | 2294 | * @since 1.0.19 |
2295 | 2295 | * @param string $value state. |
2296 | 2296 | */ |
2297 | - public function set_state( $value ) { |
|
2298 | - $this->set_prop( 'state', $value ); |
|
2297 | + public function set_state($value) { |
|
2298 | + $this->set_prop('state', $value); |
|
2299 | 2299 | } |
2300 | 2300 | |
2301 | 2301 | /** |
@@ -2304,8 +2304,8 @@ discard block |
||
2304 | 2304 | * @since 1.0.19 |
2305 | 2305 | * @param string $value state. |
2306 | 2306 | */ |
2307 | - public function set_user_state( $value ) { |
|
2308 | - $this->set_state( $value ); |
|
2307 | + public function set_user_state($value) { |
|
2308 | + $this->set_state($value); |
|
2309 | 2309 | } |
2310 | 2310 | |
2311 | 2311 | /** |
@@ -2314,8 +2314,8 @@ discard block |
||
2314 | 2314 | * @since 1.0.19 |
2315 | 2315 | * @param string $value state. |
2316 | 2316 | */ |
2317 | - public function set_customer_state( $value ) { |
|
2318 | - $this->set_state( $value ); |
|
2317 | + public function set_customer_state($value) { |
|
2318 | + $this->set_state($value); |
|
2319 | 2319 | } |
2320 | 2320 | |
2321 | 2321 | /** |
@@ -2324,8 +2324,8 @@ discard block |
||
2324 | 2324 | * @since 1.0.19 |
2325 | 2325 | * @param string $value city. |
2326 | 2326 | */ |
2327 | - public function set_city( $value ) { |
|
2328 | - $this->set_prop( 'city', $value ); |
|
2327 | + public function set_city($value) { |
|
2328 | + $this->set_prop('city', $value); |
|
2329 | 2329 | } |
2330 | 2330 | |
2331 | 2331 | /** |
@@ -2334,8 +2334,8 @@ discard block |
||
2334 | 2334 | * @since 1.0.19 |
2335 | 2335 | * @param string $value city. |
2336 | 2336 | */ |
2337 | - public function set_user_city( $value ) { |
|
2338 | - $this->set_city( $value ); |
|
2337 | + public function set_user_city($value) { |
|
2338 | + $this->set_city($value); |
|
2339 | 2339 | } |
2340 | 2340 | |
2341 | 2341 | /** |
@@ -2344,8 +2344,8 @@ discard block |
||
2344 | 2344 | * @since 1.0.19 |
2345 | 2345 | * @param string $value city. |
2346 | 2346 | */ |
2347 | - public function set_customer_city( $value ) { |
|
2348 | - $this->set_city( $value ); |
|
2347 | + public function set_customer_city($value) { |
|
2348 | + $this->set_city($value); |
|
2349 | 2349 | } |
2350 | 2350 | |
2351 | 2351 | /** |
@@ -2354,8 +2354,8 @@ discard block |
||
2354 | 2354 | * @since 1.0.19 |
2355 | 2355 | * @param string $value zip. |
2356 | 2356 | */ |
2357 | - public function set_zip( $value ) { |
|
2358 | - $this->set_prop( 'zip', $value ); |
|
2357 | + public function set_zip($value) { |
|
2358 | + $this->set_prop('zip', $value); |
|
2359 | 2359 | } |
2360 | 2360 | |
2361 | 2361 | /** |
@@ -2364,8 +2364,8 @@ discard block |
||
2364 | 2364 | * @since 1.0.19 |
2365 | 2365 | * @param string $value zip. |
2366 | 2366 | */ |
2367 | - public function set_user_zip( $value ) { |
|
2368 | - $this->set_zip( $value ); |
|
2367 | + public function set_user_zip($value) { |
|
2368 | + $this->set_zip($value); |
|
2369 | 2369 | } |
2370 | 2370 | |
2371 | 2371 | /** |
@@ -2374,8 +2374,8 @@ discard block |
||
2374 | 2374 | * @since 1.0.19 |
2375 | 2375 | * @param string $value zip. |
2376 | 2376 | */ |
2377 | - public function set_customer_zip( $value ) { |
|
2378 | - $this->set_zip( $value ); |
|
2377 | + public function set_customer_zip($value) { |
|
2378 | + $this->set_zip($value); |
|
2379 | 2379 | } |
2380 | 2380 | |
2381 | 2381 | /** |
@@ -2384,8 +2384,8 @@ discard block |
||
2384 | 2384 | * @since 1.0.19 |
2385 | 2385 | * @param string $value company. |
2386 | 2386 | */ |
2387 | - public function set_company( $value ) { |
|
2388 | - $this->set_prop( 'company', $value ); |
|
2387 | + public function set_company($value) { |
|
2388 | + $this->set_prop('company', $value); |
|
2389 | 2389 | } |
2390 | 2390 | |
2391 | 2391 | /** |
@@ -2394,8 +2394,8 @@ discard block |
||
2394 | 2394 | * @since 1.0.19 |
2395 | 2395 | * @param string $value company. |
2396 | 2396 | */ |
2397 | - public function set_user_company( $value ) { |
|
2398 | - $this->set_company( $value ); |
|
2397 | + public function set_user_company($value) { |
|
2398 | + $this->set_company($value); |
|
2399 | 2399 | } |
2400 | 2400 | |
2401 | 2401 | /** |
@@ -2404,8 +2404,8 @@ discard block |
||
2404 | 2404 | * @since 1.0.19 |
2405 | 2405 | * @param string $value company. |
2406 | 2406 | */ |
2407 | - public function set_customer_company( $value ) { |
|
2408 | - $this->set_company( $value ); |
|
2407 | + public function set_customer_company($value) { |
|
2408 | + $this->set_company($value); |
|
2409 | 2409 | } |
2410 | 2410 | |
2411 | 2411 | /** |
@@ -2414,8 +2414,8 @@ discard block |
||
2414 | 2414 | * @since 1.0.19 |
2415 | 2415 | * @param string $value var number. |
2416 | 2416 | */ |
2417 | - public function set_vat_number( $value ) { |
|
2418 | - $this->set_prop( 'vat_number', $value ); |
|
2417 | + public function set_vat_number($value) { |
|
2418 | + $this->set_prop('vat_number', $value); |
|
2419 | 2419 | } |
2420 | 2420 | |
2421 | 2421 | /** |
@@ -2424,8 +2424,8 @@ discard block |
||
2424 | 2424 | * @since 1.0.19 |
2425 | 2425 | * @param string $value var number. |
2426 | 2426 | */ |
2427 | - public function set_user_vat_number( $value ) { |
|
2428 | - $this->set_vat_number( $value ); |
|
2427 | + public function set_user_vat_number($value) { |
|
2428 | + $this->set_vat_number($value); |
|
2429 | 2429 | } |
2430 | 2430 | |
2431 | 2431 | /** |
@@ -2434,8 +2434,8 @@ discard block |
||
2434 | 2434 | * @since 1.0.19 |
2435 | 2435 | * @param string $value var number. |
2436 | 2436 | */ |
2437 | - public function set_customer_vat_number( $value ) { |
|
2438 | - $this->set_vat_number( $value ); |
|
2437 | + public function set_customer_vat_number($value) { |
|
2438 | + $this->set_vat_number($value); |
|
2439 | 2439 | } |
2440 | 2440 | |
2441 | 2441 | /** |
@@ -2444,8 +2444,8 @@ discard block |
||
2444 | 2444 | * @since 1.0.19 |
2445 | 2445 | * @param string $value var rate. |
2446 | 2446 | */ |
2447 | - public function set_vat_rate( $value ) { |
|
2448 | - $this->set_prop( 'vat_rate', $value ); |
|
2447 | + public function set_vat_rate($value) { |
|
2448 | + $this->set_prop('vat_rate', $value); |
|
2449 | 2449 | } |
2450 | 2450 | |
2451 | 2451 | /** |
@@ -2454,8 +2454,8 @@ discard block |
||
2454 | 2454 | * @since 1.0.19 |
2455 | 2455 | * @param string $value var number. |
2456 | 2456 | */ |
2457 | - public function set_user_vat_rate( $value ) { |
|
2458 | - $this->set_vat_rate( $value ); |
|
2457 | + public function set_user_vat_rate($value) { |
|
2458 | + $this->set_vat_rate($value); |
|
2459 | 2459 | } |
2460 | 2460 | |
2461 | 2461 | /** |
@@ -2464,8 +2464,8 @@ discard block |
||
2464 | 2464 | * @since 1.0.19 |
2465 | 2465 | * @param string $value var number. |
2466 | 2466 | */ |
2467 | - public function set_customer_vat_rate( $value ) { |
|
2468 | - $this->set_vat_rate( $value ); |
|
2467 | + public function set_customer_vat_rate($value) { |
|
2468 | + $this->set_vat_rate($value); |
|
2469 | 2469 | } |
2470 | 2470 | |
2471 | 2471 | /** |
@@ -2474,8 +2474,8 @@ discard block |
||
2474 | 2474 | * @since 1.0.19 |
2475 | 2475 | * @param string $value address. |
2476 | 2476 | */ |
2477 | - public function set_address( $value ) { |
|
2478 | - $this->set_prop( 'address', $value ); |
|
2477 | + public function set_address($value) { |
|
2478 | + $this->set_prop('address', $value); |
|
2479 | 2479 | } |
2480 | 2480 | |
2481 | 2481 | /** |
@@ -2484,8 +2484,8 @@ discard block |
||
2484 | 2484 | * @since 1.0.19 |
2485 | 2485 | * @param string $value address. |
2486 | 2486 | */ |
2487 | - public function set_user_address( $value ) { |
|
2488 | - $this->set_address( $value ); |
|
2487 | + public function set_user_address($value) { |
|
2488 | + $this->set_address($value); |
|
2489 | 2489 | } |
2490 | 2490 | |
2491 | 2491 | /** |
@@ -2494,8 +2494,8 @@ discard block |
||
2494 | 2494 | * @since 1.0.19 |
2495 | 2495 | * @param string $value address. |
2496 | 2496 | */ |
2497 | - public function set_customer_address( $value ) { |
|
2498 | - $this->set_address( $value ); |
|
2497 | + public function set_customer_address($value) { |
|
2498 | + $this->set_address($value); |
|
2499 | 2499 | } |
2500 | 2500 | |
2501 | 2501 | /** |
@@ -2504,8 +2504,8 @@ discard block |
||
2504 | 2504 | * @since 1.0.19 |
2505 | 2505 | * @param int|bool $value confirmed. |
2506 | 2506 | */ |
2507 | - public function set_is_viewed( $value ) { |
|
2508 | - $this->set_prop( 'is_viewed', $value ); |
|
2507 | + public function set_is_viewed($value) { |
|
2508 | + $this->set_prop('is_viewed', $value); |
|
2509 | 2509 | } |
2510 | 2510 | |
2511 | 2511 | /** |
@@ -2514,8 +2514,8 @@ discard block |
||
2514 | 2514 | * @since 1.0.19 |
2515 | 2515 | * @param string $value email recipients. |
2516 | 2516 | */ |
2517 | - public function set_email_cc( $value ) { |
|
2518 | - $this->set_prop( 'email_cc', $value ); |
|
2517 | + public function set_email_cc($value) { |
|
2518 | + $this->set_prop('email_cc', $value); |
|
2519 | 2519 | } |
2520 | 2520 | |
2521 | 2521 | /** |
@@ -2524,9 +2524,9 @@ discard block |
||
2524 | 2524 | * @since 1.0.19 |
2525 | 2525 | * @param string $value email recipients. |
2526 | 2526 | */ |
2527 | - public function set_template( $value ) { |
|
2528 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2529 | - $this->set_prop( 'template', $value ); |
|
2527 | + public function set_template($value) { |
|
2528 | + if (in_array($value, array('quantity', 'hours', 'amount'))) { |
|
2529 | + $this->set_prop('template', $value); |
|
2530 | 2530 | } |
2531 | 2531 | } |
2532 | 2532 | |
@@ -2536,8 +2536,8 @@ discard block |
||
2536 | 2536 | * @since 1.0.19 |
2537 | 2537 | * @param int|bool $value confirmed. |
2538 | 2538 | */ |
2539 | - public function set_address_confirmed( $value ) { |
|
2540 | - $this->set_prop( 'address_confirmed', $value ); |
|
2539 | + public function set_address_confirmed($value) { |
|
2540 | + $this->set_prop('address_confirmed', $value); |
|
2541 | 2541 | } |
2542 | 2542 | |
2543 | 2543 | /** |
@@ -2546,8 +2546,8 @@ discard block |
||
2546 | 2546 | * @since 1.0.19 |
2547 | 2547 | * @param int|bool $value confirmed. |
2548 | 2548 | */ |
2549 | - public function set_user_address_confirmed( $value ) { |
|
2550 | - $this->set_address_confirmed( $value ); |
|
2549 | + public function set_user_address_confirmed($value) { |
|
2550 | + $this->set_address_confirmed($value); |
|
2551 | 2551 | } |
2552 | 2552 | |
2553 | 2553 | /** |
@@ -2556,8 +2556,8 @@ discard block |
||
2556 | 2556 | * @since 1.0.19 |
2557 | 2557 | * @param int|bool $value confirmed. |
2558 | 2558 | */ |
2559 | - public function set_customer_address_confirmed( $value ) { |
|
2560 | - $this->set_address_confirmed( $value ); |
|
2559 | + public function set_customer_address_confirmed($value) { |
|
2560 | + $this->set_address_confirmed($value); |
|
2561 | 2561 | } |
2562 | 2562 | |
2563 | 2563 | /** |
@@ -2566,8 +2566,8 @@ discard block |
||
2566 | 2566 | * @since 1.0.19 |
2567 | 2567 | * @param float $value sub total. |
2568 | 2568 | */ |
2569 | - public function set_subtotal( $value ) { |
|
2570 | - $this->set_prop( 'subtotal', $value ); |
|
2569 | + public function set_subtotal($value) { |
|
2570 | + $this->set_prop('subtotal', $value); |
|
2571 | 2571 | } |
2572 | 2572 | |
2573 | 2573 | /** |
@@ -2576,8 +2576,8 @@ discard block |
||
2576 | 2576 | * @since 1.0.19 |
2577 | 2577 | * @param float $value discount total. |
2578 | 2578 | */ |
2579 | - public function set_total_discount( $value ) { |
|
2580 | - $this->set_prop( 'total_discount', $value ); |
|
2579 | + public function set_total_discount($value) { |
|
2580 | + $this->set_prop('total_discount', $value); |
|
2581 | 2581 | } |
2582 | 2582 | |
2583 | 2583 | /** |
@@ -2586,8 +2586,8 @@ discard block |
||
2586 | 2586 | * @since 1.0.19 |
2587 | 2587 | * @param float $value discount total. |
2588 | 2588 | */ |
2589 | - public function set_discount( $value ) { |
|
2590 | - $this->set_total_discount( $value ); |
|
2589 | + public function set_discount($value) { |
|
2590 | + $this->set_total_discount($value); |
|
2591 | 2591 | } |
2592 | 2592 | |
2593 | 2593 | /** |
@@ -2596,8 +2596,8 @@ discard block |
||
2596 | 2596 | * @since 1.0.19 |
2597 | 2597 | * @param float $value tax total. |
2598 | 2598 | */ |
2599 | - public function set_total_tax( $value ) { |
|
2600 | - $this->set_prop( 'total_tax', $value ); |
|
2599 | + public function set_total_tax($value) { |
|
2600 | + $this->set_prop('total_tax', $value); |
|
2601 | 2601 | } |
2602 | 2602 | |
2603 | 2603 | /** |
@@ -2606,8 +2606,8 @@ discard block |
||
2606 | 2606 | * @since 1.0.19 |
2607 | 2607 | * @param float $value tax total. |
2608 | 2608 | */ |
2609 | - public function set_tax_total( $value ) { |
|
2610 | - $this->set_total_tax( $value ); |
|
2609 | + public function set_tax_total($value) { |
|
2610 | + $this->set_total_tax($value); |
|
2611 | 2611 | } |
2612 | 2612 | |
2613 | 2613 | /** |
@@ -2616,8 +2616,8 @@ discard block |
||
2616 | 2616 | * @since 1.0.19 |
2617 | 2617 | * @param float $value fees total. |
2618 | 2618 | */ |
2619 | - public function set_total_fees( $value ) { |
|
2620 | - $this->set_prop( 'total_fees', $value ); |
|
2619 | + public function set_total_fees($value) { |
|
2620 | + $this->set_prop('total_fees', $value); |
|
2621 | 2621 | } |
2622 | 2622 | |
2623 | 2623 | /** |
@@ -2626,8 +2626,8 @@ discard block |
||
2626 | 2626 | * @since 1.0.19 |
2627 | 2627 | * @param float $value fees total. |
2628 | 2628 | */ |
2629 | - public function set_fees_total( $value ) { |
|
2630 | - $this->set_total_fees( $value ); |
|
2629 | + public function set_fees_total($value) { |
|
2630 | + $this->set_total_fees($value); |
|
2631 | 2631 | } |
2632 | 2632 | |
2633 | 2633 | /** |
@@ -2636,18 +2636,18 @@ discard block |
||
2636 | 2636 | * @since 1.0.19 |
2637 | 2637 | * @param array $value fees. |
2638 | 2638 | */ |
2639 | - public function set_fees( $value ) { |
|
2639 | + public function set_fees($value) { |
|
2640 | 2640 | |
2641 | - $this->set_prop( 'fees', array() ); |
|
2641 | + $this->set_prop('fees', array()); |
|
2642 | 2642 | |
2643 | 2643 | // Ensure that we have an array. |
2644 | - if ( ! is_array( $value ) ) { |
|
2644 | + if (!is_array($value)) { |
|
2645 | 2645 | return; |
2646 | 2646 | } |
2647 | 2647 | |
2648 | - foreach ( $value as $name => $data ) { |
|
2649 | - if ( isset( $data['amount'] ) ) { |
|
2650 | - $this->add_fee( $name, $data['amount'], $data['recurring'] ); |
|
2648 | + foreach ($value as $name => $data) { |
|
2649 | + if (isset($data['amount'])) { |
|
2650 | + $this->add_fee($name, $data['amount'], $data['recurring']); |
|
2651 | 2651 | } |
2652 | 2652 | } |
2653 | 2653 | |
@@ -2659,8 +2659,8 @@ discard block |
||
2659 | 2659 | * @since 1.0.19 |
2660 | 2660 | * @param array $value taxes. |
2661 | 2661 | */ |
2662 | - public function set_taxes( $value ) { |
|
2663 | - $this->set_prop( 'taxes', $value ); |
|
2662 | + public function set_taxes($value) { |
|
2663 | + $this->set_prop('taxes', $value); |
|
2664 | 2664 | } |
2665 | 2665 | |
2666 | 2666 | /** |
@@ -2669,17 +2669,17 @@ discard block |
||
2669 | 2669 | * @since 1.0.19 |
2670 | 2670 | * @param array $value discounts. |
2671 | 2671 | */ |
2672 | - public function set_discounts( $value ) { |
|
2673 | - $this->set_prop( 'discounts', array() ); |
|
2672 | + public function set_discounts($value) { |
|
2673 | + $this->set_prop('discounts', array()); |
|
2674 | 2674 | |
2675 | 2675 | // Ensure that we have an array. |
2676 | - if ( ! is_array( $value ) ) { |
|
2676 | + if (!is_array($value)) { |
|
2677 | 2677 | return; |
2678 | 2678 | } |
2679 | 2679 | |
2680 | - foreach ( $value as $name => $data ) { |
|
2681 | - if ( isset( $data['amount'] ) ) { |
|
2682 | - $this->add_discount( $name, $data['amount'], $data['recurring'] ); |
|
2680 | + foreach ($value as $name => $data) { |
|
2681 | + if (isset($data['amount'])) { |
|
2682 | + $this->add_discount($name, $data['amount'], $data['recurring']); |
|
2683 | 2683 | } |
2684 | 2684 | } |
2685 | 2685 | } |
@@ -2690,18 +2690,18 @@ discard block |
||
2690 | 2690 | * @since 1.0.19 |
2691 | 2691 | * @param GetPaid_Form_Item[] $value items. |
2692 | 2692 | */ |
2693 | - public function set_items( $value ) { |
|
2693 | + public function set_items($value) { |
|
2694 | 2694 | |
2695 | 2695 | // Remove existing items. |
2696 | - $this->set_prop( 'items', array() ); |
|
2696 | + $this->set_prop('items', array()); |
|
2697 | 2697 | |
2698 | 2698 | // Ensure that we have an array. |
2699 | - if ( ! is_array( $value ) ) { |
|
2699 | + if (!is_array($value)) { |
|
2700 | 2700 | return; |
2701 | 2701 | } |
2702 | 2702 | |
2703 | - foreach ( $value as $item ) { |
|
2704 | - $this->add_item( $item ); |
|
2703 | + foreach ($value as $item) { |
|
2704 | + $this->add_item($item); |
|
2705 | 2705 | } |
2706 | 2706 | |
2707 | 2707 | } |
@@ -2712,8 +2712,8 @@ discard block |
||
2712 | 2712 | * @since 1.0.19 |
2713 | 2713 | * @param int $value payment form. |
2714 | 2714 | */ |
2715 | - public function set_payment_form( $value ) { |
|
2716 | - $this->set_prop( 'payment_form', $value ); |
|
2715 | + public function set_payment_form($value) { |
|
2716 | + $this->set_prop('payment_form', $value); |
|
2717 | 2717 | } |
2718 | 2718 | |
2719 | 2719 | /** |
@@ -2722,8 +2722,8 @@ discard block |
||
2722 | 2722 | * @since 1.0.19 |
2723 | 2723 | * @param string $value submission id. |
2724 | 2724 | */ |
2725 | - public function set_submission_id( $value ) { |
|
2726 | - $this->set_prop( 'submission_id', $value ); |
|
2725 | + public function set_submission_id($value) { |
|
2726 | + $this->set_prop('submission_id', $value); |
|
2727 | 2727 | } |
2728 | 2728 | |
2729 | 2729 | /** |
@@ -2732,8 +2732,8 @@ discard block |
||
2732 | 2732 | * @since 1.0.19 |
2733 | 2733 | * @param string $value discount code. |
2734 | 2734 | */ |
2735 | - public function set_discount_code( $value ) { |
|
2736 | - $this->set_prop( 'discount_code', $value ); |
|
2735 | + public function set_discount_code($value) { |
|
2736 | + $this->set_prop('discount_code', $value); |
|
2737 | 2737 | } |
2738 | 2738 | |
2739 | 2739 | /** |
@@ -2742,8 +2742,8 @@ discard block |
||
2742 | 2742 | * @since 1.0.19 |
2743 | 2743 | * @param string $value gateway. |
2744 | 2744 | */ |
2745 | - public function set_gateway( $value ) { |
|
2746 | - $this->set_prop( 'gateway', $value ); |
|
2745 | + public function set_gateway($value) { |
|
2746 | + $this->set_prop('gateway', $value); |
|
2747 | 2747 | } |
2748 | 2748 | |
2749 | 2749 | /** |
@@ -2752,8 +2752,8 @@ discard block |
||
2752 | 2752 | * @since 1.0.19 |
2753 | 2753 | * @param string $value transaction id. |
2754 | 2754 | */ |
2755 | - public function set_transaction_id( $value ) { |
|
2756 | - $this->set_prop( 'transaction_id', $value ); |
|
2755 | + public function set_transaction_id($value) { |
|
2756 | + $this->set_prop('transaction_id', $value); |
|
2757 | 2757 | } |
2758 | 2758 | |
2759 | 2759 | /** |
@@ -2762,8 +2762,8 @@ discard block |
||
2762 | 2762 | * @since 1.0.19 |
2763 | 2763 | * @param string $value currency id. |
2764 | 2764 | */ |
2765 | - public function set_currency( $value ) { |
|
2766 | - $this->set_prop( 'currency', $value ); |
|
2765 | + public function set_currency($value) { |
|
2766 | + $this->set_prop('currency', $value); |
|
2767 | 2767 | } |
2768 | 2768 | |
2769 | 2769 | /** |
@@ -2772,8 +2772,8 @@ discard block |
||
2772 | 2772 | * @since 1.0.19 |
2773 | 2773 | * @param bool $value value. |
2774 | 2774 | */ |
2775 | - public function set_disable_taxes( $value ) { |
|
2776 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2775 | + public function set_disable_taxes($value) { |
|
2776 | + $this->set_prop('disable_taxes', (bool) $value); |
|
2777 | 2777 | } |
2778 | 2778 | |
2779 | 2779 | /** |
@@ -2782,8 +2782,8 @@ discard block |
||
2782 | 2782 | * @since 1.0.19 |
2783 | 2783 | * @param string $value subscription id. |
2784 | 2784 | */ |
2785 | - public function set_subscription_id( $value ) { |
|
2786 | - $this->set_prop( 'subscription_id', $value ); |
|
2785 | + public function set_subscription_id($value) { |
|
2786 | + $this->set_prop('subscription_id', $value); |
|
2787 | 2787 | } |
2788 | 2788 | |
2789 | 2789 | /* |
@@ -2800,21 +2800,21 @@ discard block |
||
2800 | 2800 | */ |
2801 | 2801 | public function is_parent() { |
2802 | 2802 | $parent = $this->get_parent_id(); |
2803 | - return apply_filters( 'wpinv_invoice_is_parent', empty( $parent ), $this ); |
|
2803 | + return apply_filters('wpinv_invoice_is_parent', empty($parent), $this); |
|
2804 | 2804 | } |
2805 | 2805 | |
2806 | 2806 | /** |
2807 | 2807 | * Checks if this is a renewal invoice. |
2808 | 2808 | */ |
2809 | 2809 | public function is_renewal() { |
2810 | - return ! $this->is_parent(); |
|
2810 | + return !$this->is_parent(); |
|
2811 | 2811 | } |
2812 | 2812 | |
2813 | 2813 | /** |
2814 | 2814 | * Checks if this is a recurring invoice. |
2815 | 2815 | */ |
2816 | 2816 | public function is_recurring() { |
2817 | - return $this->is_renewal() || ! empty( $this->recurring_item ); |
|
2817 | + return $this->is_renewal() || !empty($this->recurring_item); |
|
2818 | 2818 | } |
2819 | 2819 | |
2820 | 2820 | /** |
@@ -2832,72 +2832,72 @@ discard block |
||
2832 | 2832 | |
2833 | 2833 | $requires_vat = false; |
2834 | 2834 | |
2835 | - if ( $this->country ) { |
|
2835 | + if ($this->country) { |
|
2836 | 2836 | $wpi_country = $this->country; |
2837 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2837 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2838 | 2838 | } |
2839 | 2839 | |
2840 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2840 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2841 | 2841 | } |
2842 | 2842 | |
2843 | 2843 | /** |
2844 | 2844 | * Checks to see if the invoice requires payment. |
2845 | 2845 | */ |
2846 | 2846 | public function is_free() { |
2847 | - $is_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
|
2847 | + $is_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0); |
|
2848 | 2848 | |
2849 | - if ( $is_free && $this->is_recurring() ) { |
|
2850 | - $is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 ); |
|
2849 | + if ($is_free && $this->is_recurring()) { |
|
2850 | + $is_free = !((float) wpinv_round_amount($this->get_recurring_total()) > 0); |
|
2851 | 2851 | } |
2852 | 2852 | |
2853 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
2853 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
2854 | 2854 | } |
2855 | 2855 | |
2856 | 2856 | /** |
2857 | 2857 | * Checks if the invoice is paid. |
2858 | 2858 | */ |
2859 | 2859 | public function is_paid() { |
2860 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
2861 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
2860 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
2861 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
2862 | 2862 | } |
2863 | 2863 | |
2864 | 2864 | /** |
2865 | 2865 | * Checks if the invoice needs payment. |
2866 | 2866 | */ |
2867 | 2867 | public function needs_payment() { |
2868 | - $needs_payment = ! $this->is_paid() && ! $this->is_free(); |
|
2869 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
|
2868 | + $needs_payment = !$this->is_paid() && !$this->is_free(); |
|
2869 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this); |
|
2870 | 2870 | } |
2871 | 2871 | |
2872 | 2872 | /** |
2873 | 2873 | * Checks if the invoice is refunded. |
2874 | 2874 | */ |
2875 | 2875 | public function is_refunded() { |
2876 | - $is_refunded = $this->has_status( 'wpi-refunded' ); |
|
2877 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
2876 | + $is_refunded = $this->has_status('wpi-refunded'); |
|
2877 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
2878 | 2878 | } |
2879 | 2879 | |
2880 | 2880 | /** |
2881 | 2881 | * Checks if the invoice is draft. |
2882 | 2882 | */ |
2883 | 2883 | public function is_draft() { |
2884 | - return $this->has_status( 'draft, auto-draft' ); |
|
2884 | + return $this->has_status('draft, auto-draft'); |
|
2885 | 2885 | } |
2886 | 2886 | |
2887 | 2887 | /** |
2888 | 2888 | * Checks if the invoice has a given status. |
2889 | 2889 | */ |
2890 | - public function has_status( $status ) { |
|
2891 | - $status = wpinv_parse_list( $status ); |
|
2892 | - return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
|
2890 | + public function has_status($status) { |
|
2891 | + $status = wpinv_parse_list($status); |
|
2892 | + return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status); |
|
2893 | 2893 | } |
2894 | 2894 | |
2895 | 2895 | /** |
2896 | 2896 | * Checks if the invoice is of a given type. |
2897 | 2897 | */ |
2898 | - public function is_type( $type ) { |
|
2899 | - $type = wpinv_parse_list( $type ); |
|
2900 | - return in_array( $this->get_type(), $type ); |
|
2898 | + public function is_type($type) { |
|
2899 | + $type = wpinv_parse_list($type); |
|
2900 | + return in_array($this->get_type(), $type); |
|
2901 | 2901 | } |
2902 | 2902 | |
2903 | 2903 | /** |
@@ -2906,7 +2906,7 @@ discard block |
||
2906 | 2906 | * @since 1.0.15 |
2907 | 2907 | */ |
2908 | 2908 | public function is_quote() { |
2909 | - return $this->has_status( 'wpi_quote' ); |
|
2909 | + return $this->has_status('wpi_quote'); |
|
2910 | 2910 | } |
2911 | 2911 | |
2912 | 2912 | /** |
@@ -2929,8 +2929,8 @@ discard block |
||
2929 | 2929 | * |
2930 | 2930 | */ |
2931 | 2931 | public function is_initial_free() { |
2932 | - $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
|
2933 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
|
2932 | + $is_initial_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0); |
|
2933 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this); |
|
2934 | 2934 | } |
2935 | 2935 | |
2936 | 2936 | /** |
@@ -2940,11 +2940,11 @@ discard block |
||
2940 | 2940 | public function item_has_free_trial() { |
2941 | 2941 | |
2942 | 2942 | // Ensure we have a recurring item. |
2943 | - if ( ! $this->is_recurring() ) { |
|
2943 | + if (!$this->is_recurring()) { |
|
2944 | 2944 | return false; |
2945 | 2945 | } |
2946 | 2946 | |
2947 | - $item = new WPInv_Item( $this->recurring_item ); |
|
2947 | + $item = new WPInv_Item($this->recurring_item); |
|
2948 | 2948 | return $item->has_free_trial(); |
2949 | 2949 | } |
2950 | 2950 | |
@@ -2952,7 +2952,7 @@ discard block |
||
2952 | 2952 | * Check if the free trial is a result of a discount. |
2953 | 2953 | */ |
2954 | 2954 | public function is_free_trial_from_discount() { |
2955 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
2955 | + return $this->has_free_trial() && !$this->item_has_free_trial(); |
|
2956 | 2956 | } |
2957 | 2957 | |
2958 | 2958 | /** |
@@ -2961,17 +2961,17 @@ discard block |
||
2961 | 2961 | public function discount_first_payment_only() { |
2962 | 2962 | |
2963 | 2963 | $discount_code = $this->get_discount_code(); |
2964 | - if ( empty( $this->discount_code ) || ! $this->is_recurring() ) { |
|
2964 | + if (empty($this->discount_code) || !$this->is_recurring()) { |
|
2965 | 2965 | return true; |
2966 | 2966 | } |
2967 | 2967 | |
2968 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
2968 | + $discount = wpinv_get_discount_obj($discount_code); |
|
2969 | 2969 | |
2970 | - if ( ! $discount || ! $discount->exists() ) { |
|
2970 | + if (!$discount || !$discount->exists()) { |
|
2971 | 2971 | return true; |
2972 | 2972 | } |
2973 | 2973 | |
2974 | - return ! $discount->get_is_recurring(); |
|
2974 | + return !$discount->get_is_recurring(); |
|
2975 | 2975 | } |
2976 | 2976 | |
2977 | 2977 | /* |
@@ -2989,18 +2989,18 @@ discard block |
||
2989 | 2989 | * @param GetPaid_Form_Item $item |
2990 | 2990 | * @return WP_Error|Bool |
2991 | 2991 | */ |
2992 | - public function add_item( $item ) { |
|
2992 | + public function add_item($item) { |
|
2993 | 2993 | |
2994 | 2994 | // Make sure that it is available for purchase. |
2995 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
2996 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
2995 | + if ($item->get_id() > 0 && !$item->can_purchase()) { |
|
2996 | + return new WP_Error('invalid_item', __('This item is not available for purchase', 'invoicing')); |
|
2997 | 2997 | } |
2998 | 2998 | |
2999 | 2999 | // Do we have a recurring item? |
3000 | - if ( $item->is_recurring() ) { |
|
3000 | + if ($item->is_recurring()) { |
|
3001 | 3001 | |
3002 | 3002 | // An invoice can only contain one recurring item. |
3003 | - if ( ! empty( $this->recurring_item ) ) { |
|
3003 | + if (!empty($this->recurring_item)) { |
|
3004 | 3004 | return false; |
3005 | 3005 | } |
3006 | 3006 | |
@@ -3012,9 +3012,9 @@ discard block |
||
3012 | 3012 | |
3013 | 3013 | // Retrieve all items. |
3014 | 3014 | $items = $this->get_items(); |
3015 | - $items[ $item->get_id() ] = $item; |
|
3015 | + $items[$item->get_id()] = $item; |
|
3016 | 3016 | |
3017 | - $this->set_prop( 'items', $items ); |
|
3017 | + $this->set_prop('items', $items); |
|
3018 | 3018 | return true; |
3019 | 3019 | } |
3020 | 3020 | |
@@ -3023,9 +3023,9 @@ discard block |
||
3023 | 3023 | * |
3024 | 3024 | * @since 1.0.19 |
3025 | 3025 | */ |
3026 | - public function get_item( $item_id ) { |
|
3026 | + public function get_item($item_id) { |
|
3027 | 3027 | $items = $this->get_items(); |
3028 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3028 | + return (!empty($item_id) && isset($items[$item_id])) ? $items[$item_id] : null; |
|
3029 | 3029 | } |
3030 | 3030 | |
3031 | 3031 | /** |
@@ -3033,16 +3033,16 @@ discard block |
||
3033 | 3033 | * |
3034 | 3034 | * @since 1.0.19 |
3035 | 3035 | */ |
3036 | - public function remove_item( $item_id ) { |
|
3036 | + public function remove_item($item_id) { |
|
3037 | 3037 | $items = $this->get_items(); |
3038 | 3038 | |
3039 | - if ( $item_id == $this->recurring_item ) { |
|
3039 | + if ($item_id == $this->recurring_item) { |
|
3040 | 3040 | $this->recurring_item = null; |
3041 | 3041 | } |
3042 | 3042 | |
3043 | - if ( isset( $items[ $item_id ] ) ) { |
|
3044 | - unset( $items[ $item_id ] ); |
|
3045 | - $this->set_prop( 'items', $items ); |
|
3043 | + if (isset($items[$item_id])) { |
|
3044 | + unset($items[$item_id]); |
|
3045 | + $this->set_prop('items', $items); |
|
3046 | 3046 | } |
3047 | 3047 | } |
3048 | 3048 | |
@@ -3053,27 +3053,27 @@ discard block |
||
3053 | 3053 | * @param float $value |
3054 | 3054 | * @return WP_Error|Bool |
3055 | 3055 | */ |
3056 | - public function add_fee( $fee, $value, $recurring = false ) { |
|
3056 | + public function add_fee($fee, $value, $recurring = false) { |
|
3057 | 3057 | |
3058 | - $amount = wpinv_sanitize_amount( $value ); |
|
3058 | + $amount = wpinv_sanitize_amount($value); |
|
3059 | 3059 | $fees = $this->get_fees(); |
3060 | 3060 | |
3061 | - if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) { |
|
3061 | + if (isset($fees[$fee]) && isset($fees[$fee]['amount'])) { |
|
3062 | 3062 | |
3063 | - $amount = $fees[ $fee ]['amount'] += $amount; |
|
3064 | - $fees[ $fee ] = array( |
|
3063 | + $amount = $fees[$fee]['amount'] += $amount; |
|
3064 | + $fees[$fee] = array( |
|
3065 | 3065 | 'amount' => $amount, |
3066 | 3066 | 'recurring' => (bool) $recurring, |
3067 | 3067 | ); |
3068 | 3068 | |
3069 | 3069 | } else { |
3070 | - $fees[ $fee ] = array( |
|
3070 | + $fees[$fee] = array( |
|
3071 | 3071 | 'amount' => $amount, |
3072 | 3072 | 'recurring' => (bool) $recurring, |
3073 | 3073 | ); |
3074 | 3074 | } |
3075 | 3075 | |
3076 | - $this->set_prop( 'fees', $fee ); |
|
3076 | + $this->set_prop('fees', $fee); |
|
3077 | 3077 | |
3078 | 3078 | } |
3079 | 3079 | |
@@ -3082,9 +3082,9 @@ discard block |
||
3082 | 3082 | * |
3083 | 3083 | * @since 1.0.19 |
3084 | 3084 | */ |
3085 | - public function get_fee( $fee ) { |
|
3085 | + public function get_fee($fee) { |
|
3086 | 3086 | $fees = $this->get_fees(); |
3087 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3087 | + return isset($fees[$fee]) ? $fees[$fee] : null; |
|
3088 | 3088 | } |
3089 | 3089 | |
3090 | 3090 | /** |
@@ -3092,11 +3092,11 @@ discard block |
||
3092 | 3092 | * |
3093 | 3093 | * @since 1.0.19 |
3094 | 3094 | */ |
3095 | - public function remove_fee( $fee ) { |
|
3095 | + public function remove_fee($fee) { |
|
3096 | 3096 | $fees = $this->get_fees(); |
3097 | - if ( isset( $fees[ $fee ] ) ) { |
|
3098 | - unset( $fees[ $fee ] ); |
|
3099 | - $this->set_prop( 'fees', $fees ); |
|
3097 | + if (isset($fees[$fee])) { |
|
3098 | + unset($fees[$fee]); |
|
3099 | + $this->set_prop('fees', $fees); |
|
3100 | 3100 | } |
3101 | 3101 | } |
3102 | 3102 | |
@@ -3107,27 +3107,27 @@ discard block |
||
3107 | 3107 | * @param float $value |
3108 | 3108 | * @return WP_Error|Bool |
3109 | 3109 | */ |
3110 | - public function add_discount( $discount, $value, $recurring = false ) { |
|
3110 | + public function add_discount($discount, $value, $recurring = false) { |
|
3111 | 3111 | |
3112 | - $amount = wpinv_sanitize_amount( $value ); |
|
3112 | + $amount = wpinv_sanitize_amount($value); |
|
3113 | 3113 | $discounts = $this->get_discounts(); |
3114 | 3114 | |
3115 | - if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) { |
|
3115 | + if (isset($discounts[$discount]) && isset($discounts[$discount]['amount'])) { |
|
3116 | 3116 | |
3117 | - $amount = $discounts[ $discount ]['amount'] += $amount; |
|
3118 | - $discounts[ $discount ] = array( |
|
3117 | + $amount = $discounts[$discount]['amount'] += $amount; |
|
3118 | + $discounts[$discount] = array( |
|
3119 | 3119 | 'amount' => $amount, |
3120 | 3120 | 'recurring' => (bool) $recurring, |
3121 | 3121 | ); |
3122 | 3122 | |
3123 | 3123 | } else { |
3124 | - $discounts[ $discount ] = array( |
|
3124 | + $discounts[$discount] = array( |
|
3125 | 3125 | 'amount' => $amount, |
3126 | 3126 | 'recurring' => (bool) $recurring, |
3127 | 3127 | ); |
3128 | 3128 | } |
3129 | 3129 | |
3130 | - $this->set_prop( 'discounts', $discount ); |
|
3130 | + $this->set_prop('discounts', $discount); |
|
3131 | 3131 | |
3132 | 3132 | } |
3133 | 3133 | |
@@ -3136,15 +3136,15 @@ discard block |
||
3136 | 3136 | * |
3137 | 3137 | * @since 1.0.19 |
3138 | 3138 | */ |
3139 | - public function get_discount( $discount = false ) { |
|
3139 | + public function get_discount($discount = false) { |
|
3140 | 3140 | |
3141 | 3141 | // Backwards compatibilty. |
3142 | - if ( empty( $discount ) ) { |
|
3142 | + if (empty($discount)) { |
|
3143 | 3143 | return $this->get_total_discount(); |
3144 | 3144 | } |
3145 | 3145 | |
3146 | 3146 | $discounts = $this->get_discounts(); |
3147 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3147 | + return isset($discounts[$discount]) ? $discounts[$discount] : null; |
|
3148 | 3148 | } |
3149 | 3149 | |
3150 | 3150 | /** |
@@ -3152,11 +3152,11 @@ discard block |
||
3152 | 3152 | * |
3153 | 3153 | * @since 1.0.19 |
3154 | 3154 | */ |
3155 | - public function remove_discount( $discount ) { |
|
3155 | + public function remove_discount($discount) { |
|
3156 | 3156 | $discounts = $this->get_discounts(); |
3157 | - if ( isset( $discounts[ $discount ] ) ) { |
|
3158 | - unset( $discounts[ $discount ] ); |
|
3159 | - $this->set_prop( 'discounts', $discounts ); |
|
3157 | + if (isset($discounts[$discount])) { |
|
3158 | + unset($discounts[$discount]); |
|
3159 | + $this->set_prop('discounts', $discounts); |
|
3160 | 3160 | } |
3161 | 3161 | } |
3162 | 3162 | |
@@ -3166,31 +3166,31 @@ discard block |
||
3166 | 3166 | * @param string $tax |
3167 | 3167 | * @param float $value |
3168 | 3168 | */ |
3169 | - public function add_tax( $tax, $value, $recurring = true ) { |
|
3169 | + public function add_tax($tax, $value, $recurring = true) { |
|
3170 | 3170 | |
3171 | - if ( ! $this->is_taxable() ) { |
|
3171 | + if (!$this->is_taxable()) { |
|
3172 | 3172 | return; |
3173 | 3173 | } |
3174 | 3174 | |
3175 | - $amount = wpinv_sanitize_amount( $value ); |
|
3175 | + $amount = wpinv_sanitize_amount($value); |
|
3176 | 3176 | $taxes = $this->get_taxes(); |
3177 | 3177 | |
3178 | - if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) { |
|
3178 | + if (isset($taxes[$tax]) && isset($taxes[$tax]['amount'])) { |
|
3179 | 3179 | |
3180 | - $amount = $taxes[ $tax ]['amount'] += $amount; |
|
3181 | - $taxes[ $tax ] = array( |
|
3180 | + $amount = $taxes[$tax]['amount'] += $amount; |
|
3181 | + $taxes[$tax] = array( |
|
3182 | 3182 | 'amount' => $amount, |
3183 | 3183 | 'recurring' => (bool) $recurring, |
3184 | 3184 | ); |
3185 | 3185 | |
3186 | 3186 | } else { |
3187 | - $taxes[ $tax ] = array( |
|
3187 | + $taxes[$tax] = array( |
|
3188 | 3188 | 'amount' => $amount, |
3189 | 3189 | 'recurring' => (bool) $recurring, |
3190 | 3190 | ); |
3191 | 3191 | } |
3192 | 3192 | |
3193 | - $this->set_prop( 'taxes', $tax ); |
|
3193 | + $this->set_prop('taxes', $tax); |
|
3194 | 3194 | |
3195 | 3195 | } |
3196 | 3196 | |
@@ -3199,9 +3199,9 @@ discard block |
||
3199 | 3199 | * |
3200 | 3200 | * @since 1.0.19 |
3201 | 3201 | */ |
3202 | - public function get_tax( $tax ) { |
|
3202 | + public function get_tax($tax) { |
|
3203 | 3203 | $taxes = $this->get_taxes(); |
3204 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3204 | + return isset($taxes[$tax]) ? $taxes[$tax] : null; |
|
3205 | 3205 | } |
3206 | 3206 | |
3207 | 3207 | /** |
@@ -3209,11 +3209,11 @@ discard block |
||
3209 | 3209 | * |
3210 | 3210 | * @since 1.0.19 |
3211 | 3211 | */ |
3212 | - public function remove_tax( $tax ) { |
|
3212 | + public function remove_tax($tax) { |
|
3213 | 3213 | $taxes = $this->get_discounts(); |
3214 | - if ( isset( $taxes[ $tax ] ) ) { |
|
3215 | - unset( $taxes[ $tax ] ); |
|
3216 | - $this->set_prop( 'taxes', $taxes ); |
|
3214 | + if (isset($taxes[$tax])) { |
|
3215 | + unset($taxes[$tax]); |
|
3216 | + $this->set_prop('taxes', $taxes); |
|
3217 | 3217 | } |
3218 | 3218 | } |
3219 | 3219 | |
@@ -3224,19 +3224,19 @@ discard block |
||
3224 | 3224 | * @return float The recalculated subtotal |
3225 | 3225 | */ |
3226 | 3226 | public function recalculate_subtotal() { |
3227 | - $items = $this->get_items(); |
|
3227 | + $items = $this->get_items(); |
|
3228 | 3228 | $subtotal = 0; |
3229 | 3229 | $recurring = 0; |
3230 | 3230 | |
3231 | - foreach ( $items as $item ) { |
|
3231 | + foreach ($items as $item) { |
|
3232 | 3232 | $subtotal += $item->get_sub_total(); |
3233 | 3233 | $recurring += $item->get_recurring_sub_total(); |
3234 | 3234 | } |
3235 | 3235 | |
3236 | - if ( $this->is_renewal() ) { |
|
3237 | - $this->set_subtotal( $recurring ); |
|
3236 | + if ($this->is_renewal()) { |
|
3237 | + $this->set_subtotal($recurring); |
|
3238 | 3238 | } else { |
3239 | - $this->set_subtotal( $subtotal ); |
|
3239 | + $this->set_subtotal($subtotal); |
|
3240 | 3240 | } |
3241 | 3241 | |
3242 | 3242 | $this->totals['subtotal'] = array( |
@@ -3258,9 +3258,9 @@ discard block |
||
3258 | 3258 | $discount = 0; |
3259 | 3259 | $recurring = 0; |
3260 | 3260 | |
3261 | - foreach ( $discounts as $data ) { |
|
3261 | + foreach ($discounts as $data) { |
|
3262 | 3262 | |
3263 | - if ( $data['recurring'] ) { |
|
3263 | + if ($data['recurring']) { |
|
3264 | 3264 | $recurring += $data['amount']; |
3265 | 3265 | } else { |
3266 | 3266 | $discount += $data['amount']; |
@@ -3268,10 +3268,10 @@ discard block |
||
3268 | 3268 | |
3269 | 3269 | } |
3270 | 3270 | |
3271 | - if ( $this->is_renewal() ) { |
|
3272 | - $this->set_total_discount( $recurring ); |
|
3271 | + if ($this->is_renewal()) { |
|
3272 | + $this->set_total_discount($recurring); |
|
3273 | 3273 | } else { |
3274 | - $this->set_total_discount( $discount ); |
|
3274 | + $this->set_total_discount($discount); |
|
3275 | 3275 | } |
3276 | 3276 | |
3277 | 3277 | $this->totals['discount'] = array( |
@@ -3290,13 +3290,13 @@ discard block |
||
3290 | 3290 | * @return float The recalculated tax |
3291 | 3291 | */ |
3292 | 3292 | public function recalculate_total_tax() { |
3293 | - $taxes = $this->get_taxes(); |
|
3293 | + $taxes = $this->get_taxes(); |
|
3294 | 3294 | $tax = 0; |
3295 | 3295 | $recurring = 0; |
3296 | 3296 | |
3297 | - foreach ( $taxes as $data ) { |
|
3297 | + foreach ($taxes as $data) { |
|
3298 | 3298 | |
3299 | - if ( $data['recurring'] ) { |
|
3299 | + if ($data['recurring']) { |
|
3300 | 3300 | $recurring += $data['amount']; |
3301 | 3301 | } else { |
3302 | 3302 | $tax += $data['amount']; |
@@ -3304,10 +3304,10 @@ discard block |
||
3304 | 3304 | |
3305 | 3305 | } |
3306 | 3306 | |
3307 | - if ( $this->is_renewal() ) { |
|
3308 | - $this->set_total_tax( $recurring ); |
|
3307 | + if ($this->is_renewal()) { |
|
3308 | + $this->set_total_tax($recurring); |
|
3309 | 3309 | } else { |
3310 | - $this->set_total_tax( $tax ); |
|
3310 | + $this->set_total_tax($tax); |
|
3311 | 3311 | } |
3312 | 3312 | |
3313 | 3313 | $this->totals['tax'] = array( |
@@ -3330,9 +3330,9 @@ discard block |
||
3330 | 3330 | $fee = 0; |
3331 | 3331 | $recurring = 0; |
3332 | 3332 | |
3333 | - foreach ( $fees as $data ) { |
|
3333 | + foreach ($fees as $data) { |
|
3334 | 3334 | |
3335 | - if ( $data['recurring'] ) { |
|
3335 | + if ($data['recurring']) { |
|
3336 | 3336 | $recurring += $data['amount']; |
3337 | 3337 | } else { |
3338 | 3338 | $fee += $data['amount']; |
@@ -3340,10 +3340,10 @@ discard block |
||
3340 | 3340 | |
3341 | 3341 | } |
3342 | 3342 | |
3343 | - if ( $this->is_renewal() ) { |
|
3344 | - $this->set_total_fees( $recurring ); |
|
3343 | + if ($this->is_renewal()) { |
|
3344 | + $this->set_total_fees($recurring); |
|
3345 | 3345 | } else { |
3346 | - $this->set_total_fees( $fee ); |
|
3346 | + $this->set_total_fees($fee); |
|
3347 | 3347 | } |
3348 | 3348 | |
3349 | 3349 | $this->totals['fee'] = array( |
@@ -3351,7 +3351,7 @@ discard block |
||
3351 | 3351 | 'recurring' => $recurring, |
3352 | 3352 | ); |
3353 | 3353 | |
3354 | - $this->set_total_fees( $fee ); |
|
3354 | + $this->set_total_fees($fee); |
|
3355 | 3355 | return $this->is_renewal() ? $recurring : $fee; |
3356 | 3356 | } |
3357 | 3357 | |
@@ -3372,9 +3372,9 @@ discard block |
||
3372 | 3372 | /** |
3373 | 3373 | * @deprecated |
3374 | 3374 | */ |
3375 | - public function recalculate_totals( $temp = false ) { |
|
3376 | - $this->update_items( $temp ); |
|
3377 | - $this->save( true ); |
|
3375 | + public function recalculate_totals($temp = false) { |
|
3376 | + $this->update_items($temp); |
|
3377 | + $this->save(true); |
|
3378 | 3378 | return $this; |
3379 | 3379 | } |
3380 | 3380 | |
@@ -3391,33 +3391,33 @@ discard block |
||
3391 | 3391 | * @param string $note The note being added. |
3392 | 3392 | * |
3393 | 3393 | */ |
3394 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
3394 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
3395 | 3395 | |
3396 | 3396 | // Bail if no note specified or this invoice is not yet saved. |
3397 | - if ( ! $note || $this->get_id() == 0 ) { |
|
3397 | + if (!$note || $this->get_id() == 0) { |
|
3398 | 3398 | return false; |
3399 | 3399 | } |
3400 | 3400 | |
3401 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
3402 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3401 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
3402 | + $user = get_user_by('id', get_current_user_id()); |
|
3403 | 3403 | $comment_author = $user->display_name; |
3404 | 3404 | $comment_author_email = $user->user_email; |
3405 | 3405 | } else { |
3406 | 3406 | $comment_author = 'System'; |
3407 | 3407 | $comment_author_email = 'system@'; |
3408 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
3409 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
3408 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
3409 | + $comment_author_email = sanitize_email($comment_author_email); |
|
3410 | 3410 | } |
3411 | 3411 | |
3412 | - do_action( 'wpinv_pre_insert_invoice_note', $this->get_id(), $note, $customer_type ); |
|
3412 | + do_action('wpinv_pre_insert_invoice_note', $this->get_id(), $note, $customer_type); |
|
3413 | 3413 | |
3414 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
3414 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
3415 | 3415 | 'comment_post_ID' => $this->get_id(), |
3416 | 3416 | 'comment_content' => $note, |
3417 | 3417 | 'comment_agent' => 'GetPaid', |
3418 | 3418 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
3419 | - 'comment_date' => current_time( 'mysql' ), |
|
3420 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
3419 | + 'comment_date' => current_time('mysql'), |
|
3420 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
3421 | 3421 | 'comment_approved' => 1, |
3422 | 3422 | 'comment_parent' => 0, |
3423 | 3423 | 'comment_author' => $comment_author, |
@@ -3425,13 +3425,13 @@ discard block |
||
3425 | 3425 | 'comment_author_url' => '', |
3426 | 3426 | 'comment_author_email' => $comment_author_email, |
3427 | 3427 | 'comment_type' => 'wpinv_note' |
3428 | - ) ) ); |
|
3428 | + ))); |
|
3429 | 3429 | |
3430 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->get_id(), $note ); |
|
3430 | + do_action('wpinv_insert_payment_note', $note_id, $this->get_id(), $note); |
|
3431 | 3431 | |
3432 | - if ( $customer_type ) { |
|
3433 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
3434 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->get_id(), 'user_note' => $note ) ); |
|
3432 | + if ($customer_type) { |
|
3433 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
3434 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->get_id(), 'user_note' => $note)); |
|
3435 | 3435 | } |
3436 | 3436 | |
3437 | 3437 | return $note_id; |
@@ -3440,10 +3440,10 @@ discard block |
||
3440 | 3440 | /** |
3441 | 3441 | * Generates a unique key for the invoice. |
3442 | 3442 | */ |
3443 | - public function generate_key( $string = '' ) { |
|
3444 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
3443 | + public function generate_key($string = '') { |
|
3444 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
3445 | 3445 | return strtolower( |
3446 | - md5( $this->get_id() . $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) |
|
3446 | + md5($this->get_id() . $string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true)) |
|
3447 | 3447 | ); |
3448 | 3448 | } |
3449 | 3449 | |
@@ -3453,12 +3453,12 @@ discard block |
||
3453 | 3453 | public function generate_number() { |
3454 | 3454 | $number = $this->get_id(); |
3455 | 3455 | |
3456 | - if ( $this->has_status( 'auto-draft' ) && wpinv_sequential_number_active( $this->post_type ) ) { |
|
3457 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
3456 | + if ($this->has_status('auto-draft') && wpinv_sequential_number_active($this->post_type)) { |
|
3457 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
3458 | 3458 | $number = $next_number; |
3459 | 3459 | } |
3460 | 3460 | |
3461 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
3461 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
3462 | 3462 | |
3463 | 3463 | return $number; |
3464 | 3464 | } |
@@ -3472,47 +3472,47 @@ discard block |
||
3472 | 3472 | // Reset status transition variable. |
3473 | 3473 | $this->status_transition = false; |
3474 | 3474 | |
3475 | - if ( $status_transition ) { |
|
3475 | + if ($status_transition) { |
|
3476 | 3476 | try { |
3477 | 3477 | |
3478 | 3478 | // Fire a hook for the status change. |
3479 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
3479 | + do_action('getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
3480 | 3480 | |
3481 | 3481 | // @deprecated this is deprecated and will be removed in the future. |
3482 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3482 | + do_action('wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from']); |
|
3483 | 3483 | |
3484 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3484 | + if (!empty($status_transition['from'])) { |
|
3485 | 3485 | |
3486 | 3486 | /* translators: 1: old invoice status 2: new invoice status */ |
3487 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3487 | + $transition_note = sprintf(__('Status changed from %1$s to %2$s.', 'invoicing'), wpinv_status_nicename($status_transition['from']), wpinv_status_nicename($status_transition['to'])); |
|
3488 | 3488 | |
3489 | 3489 | // Fire another hook. |
3490 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
3491 | - do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
3490 | + do_action('getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
3491 | + do_action('getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this); |
|
3492 | 3492 | |
3493 | 3493 | // @deprecated this is deprecated and will be removed in the future. |
3494 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from'] ); |
|
3494 | + do_action('wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from']); |
|
3495 | 3495 | |
3496 | 3496 | // Note the transition occurred. |
3497 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3497 | + $this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']); |
|
3498 | 3498 | |
3499 | 3499 | // Work out if this was for a payment, and trigger a payment_status hook instead. |
3500 | 3500 | if ( |
3501 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true ) |
|
3502 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3501 | + in_array($status_transition['from'], array('wpi-cancelled', 'wpi-pending', 'wpi-failed'), true) |
|
3502 | + && in_array($status_transition['to'], array('publish', 'wpi-processing', 'wpi-renewal'), true) |
|
3503 | 3503 | ) { |
3504 | - do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
3504 | + do_action('getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition); |
|
3505 | 3505 | } |
3506 | 3506 | } else { |
3507 | 3507 | /* translators: %s: new invoice status */ |
3508 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3508 | + $transition_note = sprintf(__('Status set to %s.', 'invoicing'), wpinv_status_nicename($status_transition['to'])); |
|
3509 | 3509 | |
3510 | 3510 | // Note the transition occurred. |
3511 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3511 | + $this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']); |
|
3512 | 3512 | |
3513 | 3513 | } |
3514 | - } catch ( Exception $e ) { |
|
3515 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3514 | + } catch (Exception $e) { |
|
3515 | + $this->add_note(__('Error during status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
3516 | 3516 | } |
3517 | 3517 | } |
3518 | 3518 | } |
@@ -3520,13 +3520,13 @@ discard block |
||
3520 | 3520 | /** |
3521 | 3521 | * Updates an invoice status. |
3522 | 3522 | */ |
3523 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3523 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
3524 | 3524 | |
3525 | 3525 | // Fires before updating a status. |
3526 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status( 'edit' ) ); |
|
3526 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status('edit')); |
|
3527 | 3527 | |
3528 | 3528 | // Update the status. |
3529 | - $this->set_status( $new_status, $note, $manual ); |
|
3529 | + $this->set_status($new_status, $note, $manual); |
|
3530 | 3530 | |
3531 | 3531 | // Save the order. |
3532 | 3532 | return $this->save(); |
@@ -3537,18 +3537,18 @@ discard block |
||
3537 | 3537 | * @deprecated |
3538 | 3538 | */ |
3539 | 3539 | public function refresh_item_ids() { |
3540 | - $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
|
3541 | - update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
|
3540 | + $item_ids = implode(',', array_unique(array_keys($this->get_items()))); |
|
3541 | + update_post_meta($this->get_id(), '_wpinv_item_ids', $item_ids); |
|
3542 | 3542 | } |
3543 | 3543 | |
3544 | 3544 | /** |
3545 | 3545 | * @deprecated |
3546 | 3546 | */ |
3547 | - public function update_items( $temp = false ) { |
|
3547 | + public function update_items($temp = false) { |
|
3548 | 3548 | |
3549 | - $this->set_items( $this->get_items() ); |
|
3549 | + $this->set_items($this->get_items()); |
|
3550 | 3550 | |
3551 | - if ( ! $temp ) { |
|
3551 | + if (!$temp) { |
|
3552 | 3552 | $this->save(); |
3553 | 3553 | } |
3554 | 3554 | |
@@ -3562,11 +3562,11 @@ discard block |
||
3562 | 3562 | |
3563 | 3563 | $discount_code = $this->get_discount_code(); |
3564 | 3564 | |
3565 | - if ( empty( $discount_code ) ) { |
|
3565 | + if (empty($discount_code)) { |
|
3566 | 3566 | return false; |
3567 | 3567 | } |
3568 | 3568 | |
3569 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
3569 | + $discount = wpinv_get_discount_obj($discount_code); |
|
3570 | 3570 | |
3571 | 3571 | // Ensure it is active. |
3572 | 3572 | return $discount->exists(); |
@@ -3577,7 +3577,7 @@ discard block |
||
3577 | 3577 | * Refunds an invoice. |
3578 | 3578 | */ |
3579 | 3579 | public function refund() { |
3580 | - $this->set_status( 'wpi-refunded' ); |
|
3580 | + $this->set_status('wpi-refunded'); |
|
3581 | 3581 | $this->save(); |
3582 | 3582 | } |
3583 | 3583 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param string $context View or edit context. |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
90 | + public function get_name($context = 'view') { |
|
91 | + $name = parent::get_name($context); |
|
92 | + return $name . wpinv_get_item_suffix($this); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @param string $context View or edit context. |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - public function get_description( $context = 'view' ) { |
|
102 | + public function get_description($context = 'view') { |
|
103 | 103 | |
104 | - if ( ! empty( $this->custom_description ) ) { |
|
104 | + if (!empty($this->custom_description)) { |
|
105 | 105 | return $this->custom_description; |
106 | 106 | } |
107 | 107 | |
108 | - return parent::get_description( $context ); |
|
108 | + return parent::get_description($context); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @param string $context View or edit context. |
116 | 116 | * @return int |
117 | 117 | */ |
118 | - public function get_sub_total( $context = 'view' ) { |
|
119 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
118 | + public function get_sub_total($context = 'view') { |
|
119 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | * @param string $context View or edit context. |
127 | 127 | * @return int |
128 | 128 | */ |
129 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
129 | + public function get_recurring_sub_total($context = 'view') { |
|
130 | + return $this->get_quantity($context) * $this->get_price($context); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @deprecated |
135 | 135 | */ |
136 | - public function get_qantity( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ); |
|
136 | + public function get_qantity($context = 'view') { |
|
137 | + return $this->get_quantity($context); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | * @param string $context View or edit context. |
145 | 145 | * @return int |
146 | 146 | */ |
147 | - public function get_quantity( $context = 'view' ) { |
|
147 | + public function get_quantity($context = 'view') { |
|
148 | 148 | $quantity = (int) $this->quantity; |
149 | 149 | |
150 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
150 | + if (empty($quantity) || 1 > $quantity) { |
|
151 | 151 | $quantity = 1; |
152 | 152 | } |
153 | 153 | |
154 | - if ( 'view' == $context ) { |
|
155 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
154 | + if ('view' == $context) { |
|
155 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return $quantity; |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | * @param string $context View or edit context. |
167 | 167 | * @return meta |
168 | 168 | */ |
169 | - public function get_item_meta( $context = 'view' ) { |
|
169 | + public function get_item_meta($context = 'view') { |
|
170 | 170 | $meta = $this->meta; |
171 | 171 | |
172 | - if ( 'view' == $context ) { |
|
173 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
172 | + if ('view' == $context) { |
|
173 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $meta; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * @param string $context View or edit context. |
185 | 185 | * @return bool |
186 | 186 | */ |
187 | - public function get_allow_quantities( $context = 'view' ) { |
|
187 | + public function get_allow_quantities($context = 'view') { |
|
188 | 188 | $allow_quantities = (bool) $this->allow_quantities; |
189 | 189 | |
190 | - if ( 'view' == $context ) { |
|
191 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
190 | + if ('view' == $context) { |
|
191 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return $allow_quantities; |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | * @param string $context View or edit context. |
203 | 203 | * @return bool |
204 | 204 | */ |
205 | - public function get_is_required( $context = 'view' ) { |
|
205 | + public function get_is_required($context = 'view') { |
|
206 | 206 | $is_required = (bool) $this->is_required; |
207 | 207 | |
208 | - if ( 'view' == $context ) { |
|
209 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
208 | + if ('view' == $context) { |
|
209 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | return $is_required; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | public function prepare_data_for_use() { |
223 | 223 | |
224 | 224 | return array( |
225 | - 'title' => sanitize_text_field( $this->get_name() ), |
|
225 | + 'title' => sanitize_text_field($this->get_name()), |
|
226 | 226 | 'id' => $this->get_id(), |
227 | 227 | 'price' => $this->get_price(), |
228 | 228 | 'recurring' => $this->is_recurring(), |
@@ -244,17 +244,17 @@ discard block |
||
244 | 244 | return array( |
245 | 245 | 'id' => $this->get_id(), |
246 | 246 | 'texts' => array( |
247 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
248 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
249 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
250 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ) ), |
|
251 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ) ), |
|
247 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
248 | + 'item-description' => wp_kses_post($this->get_description()), |
|
249 | + 'item-quantity' => absint($this->get_quantity()), |
|
250 | + 'item-price' => wpinv_price(wpinv_format_amount($this->get_price())), |
|
251 | + 'item-total' => wpinv_price(wpinv_format_amount($this->get_sub_total())), |
|
252 | 252 | ), |
253 | 253 | 'inputs' => array( |
254 | 254 | 'item-id' => $this->get_id(), |
255 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
256 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
257 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
255 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
256 | + 'item-description' => wp_kses_post($this->get_description()), |
|
257 | + 'item-quantity' => absint($this->get_quantity()), |
|
258 | 258 | 'item-price' => $this->get_price(), |
259 | 259 | ) |
260 | 260 | ); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | return array( |
273 | 273 | 'post_id' => $this->invoice_id, |
274 | 274 | 'item_id' => $this->get_id(), |
275 | - 'item_name' => sanitize_text_field( $this->get_name() ), |
|
275 | + 'item_name' => sanitize_text_field($this->get_name()), |
|
276 | 276 | 'item_description' => $this->get_description(), |
277 | 277 | 'tax' => $this->item_tax, |
278 | 278 | 'item_price' => $this->get_price(), |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | * @since 1.0.19 |
301 | 301 | * @param int $quantity The item quantity. |
302 | 302 | */ |
303 | - public function set_quantity( $quantity ) { |
|
303 | + public function set_quantity($quantity) { |
|
304 | 304 | |
305 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
305 | + if (empty($quantity) || !is_numeric($quantity)) { |
|
306 | 306 | $quantity = 1; |
307 | 307 | } |
308 | 308 | |
@@ -316,8 +316,8 @@ discard block |
||
316 | 316 | * @since 1.0.19 |
317 | 317 | * @param array $meta The item meta data. |
318 | 318 | */ |
319 | - public function set_item_meta( $meta ) { |
|
320 | - $this->meta = maybe_unserialize( $meta ); |
|
319 | + public function set_item_meta($meta) { |
|
320 | + $this->meta = maybe_unserialize($meta); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @since 1.0.19 |
327 | 327 | * @param bool $allow_quantities |
328 | 328 | */ |
329 | - public function set_allow_quantities( $allow_quantities ) { |
|
329 | + public function set_allow_quantities($allow_quantities) { |
|
330 | 330 | $this->allow_quantities = (bool) $allow_quantities; |
331 | 331 | } |
332 | 332 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * @since 1.0.19 |
337 | 337 | * @param bool $is_required |
338 | 338 | */ |
339 | - public function set_is_required( $is_required ) { |
|
339 | + public function set_is_required($is_required) { |
|
340 | 340 | $this->is_required = (bool) $is_required; |
341 | 341 | } |
342 | 342 | |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @since 1.0.19 |
347 | 347 | * @param string $description |
348 | 348 | */ |
349 | - public function set_custom_description( $description ) { |
|
349 | + public function set_custom_description($description) { |
|
350 | 350 | $this->custom_description = $description; |
351 | 351 | } |
352 | 352 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return int item id |
357 | 357 | */ |
358 | - public function save( $data = array() ) { |
|
358 | + public function save($data = array()) { |
|
359 | 359 | return $this->get_id(); |
360 | 360 | } |
361 | 361 |
@@ -7,8 +7,8 @@ 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 | /** |
@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | */ |
17 | 17 | function getpaid_get_invoice_post_types() { |
18 | 18 | $post_types = array( |
19 | - 'wpi_quote' => __( 'Quote', 'invoicing' ), |
|
20 | - 'wpi_invoice' => __( 'Invoice', 'invoicing' ), |
|
19 | + 'wpi_quote' => __('Quote', 'invoicing'), |
|
20 | + 'wpi_invoice' => __('Invoice', 'invoicing'), |
|
21 | 21 | ); |
22 | 22 | |
23 | - return apply_filters( 'getpaid_invoice_post_types', $post_types ); |
|
23 | + return apply_filters('getpaid_invoice_post_types', $post_types); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Checks if this is an invocing post type. |
28 | 28 | */ |
29 | -function getpaid_is_invoice_post_type( $post_type ) { |
|
30 | - return $post_type && array_key_exists( $post_type, getpaid_get_invoice_post_types() ); |
|
29 | +function getpaid_is_invoice_post_type($post_type) { |
|
30 | + return $post_type && array_key_exists($post_type, getpaid_get_invoice_post_types()); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_get_invoice_cart_id() { |
34 | 34 | $wpinv_checkout = wpinv_get_checkout_session(); |
35 | 35 | |
36 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
36 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
37 | 37 | return $wpinv_checkout['invoice_id']; |
38 | 38 | } |
39 | 39 | |
@@ -47,48 +47,48 @@ discard block |
||
47 | 47 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
48 | 48 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
49 | 49 | */ |
50 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
51 | - if ( empty( $invoice_data ) ) { |
|
50 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
51 | + if (empty($invoice_data)) { |
|
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
55 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
56 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0; |
|
55 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
56 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // If no user id is provided, default to the current user id |
60 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
60 | + if (empty($invoice_data['user_id'])) { |
|
61 | 61 | $invoice_data['user_id'] = get_current_user_id(); |
62 | 62 | } |
63 | 63 | |
64 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
64 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0; |
|
65 | 65 | |
66 | - if ( empty( $invoice_data['status'] ) ) { |
|
66 | + if (empty($invoice_data['status'])) { |
|
67 | 67 | $invoice_data['status'] = 'wpi-pending'; |
68 | 68 | } |
69 | 69 | |
70 | - if ( empty( $invoice_data['post_type'] ) ) { |
|
70 | + if (empty($invoice_data['post_type'])) { |
|
71 | 71 | $invoice_data['post_type'] = 'wpi_invoice'; |
72 | 72 | } |
73 | 73 | |
74 | - if ( empty( $invoice_data['ip'] ) ) { |
|
74 | + if (empty($invoice_data['ip'])) { |
|
75 | 75 | $invoice_data['ip'] = wpinv_get_ip(); |
76 | 76 | } |
77 | 77 | |
78 | 78 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
79 | 79 | $default_args = array( |
80 | - 'invoice_id' => (int)$invoice_data['invoice_id'], |
|
81 | - 'user_id' => (int)$invoice_data['user_id'], |
|
80 | + 'invoice_id' => (int) $invoice_data['invoice_id'], |
|
81 | + 'user_id' => (int) $invoice_data['user_id'], |
|
82 | 82 | 'status' => $invoice_data['status'], |
83 | 83 | 'post_type' => $invoice_data['post_type'], |
84 | 84 | ); |
85 | 85 | |
86 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
87 | - if ( is_wp_error( $invoice ) ) { |
|
86 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
87 | + if (is_wp_error($invoice)) { |
|
88 | 88 | return $wp_error ? $invoice : 0; |
89 | 89 | } |
90 | 90 | |
91 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
91 | + if (empty($invoice_data['invoice_id'])) { |
|
92 | 92 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
93 | 93 | } |
94 | 94 | |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | 'discount' => array(), |
112 | 112 | ); |
113 | 113 | |
114 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
115 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
116 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
114 | + if ($user_id = (int) $invoice->get_user_id()) { |
|
115 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
116 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
120 | + if (empty($invoice_data['user_info'])) { |
|
121 | 121 | $invoice_data['user_info'] = array(); |
122 | 122 | } |
123 | 123 | |
124 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
124 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
125 | 125 | |
126 | - if ( empty( $user_info['first_name'] ) ) { |
|
126 | + if (empty($user_info['first_name'])) { |
|
127 | 127 | $user_info['first_name'] = $default_user_info['first_name']; |
128 | 128 | $user_info['last_name'] = $default_user_info['last_name']; |
129 | 129 | } |
130 | 130 | |
131 | - if ( empty( $user_info['country'] ) ) { |
|
131 | + if (empty($user_info['country'])) { |
|
132 | 132 | $user_info['country'] = $default_user_info['country']; |
133 | 133 | $user_info['state'] = $default_user_info['state']; |
134 | 134 | $user_info['city'] = $default_user_info['city']; |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | $user_info['phone'] = $default_user_info['phone']; |
138 | 138 | } |
139 | 139 | |
140 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
141 | - $user_info['discount'] = (array)$user_info['discount']; |
|
140 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
141 | + $user_info['discount'] = (array) $user_info['discount']; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // Payment details |
145 | 145 | $payment_details = array(); |
146 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
146 | + if (!empty($invoice_data['payment_details'])) { |
|
147 | 147 | $default_payment_details = array( |
148 | 148 | 'gateway' => 'manual', |
149 | 149 | 'gateway_title' => '', |
@@ -151,56 +151,56 @@ discard block |
||
151 | 151 | 'transaction_id' => '', |
152 | 152 | ); |
153 | 153 | |
154 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
154 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
155 | 155 | |
156 | - if ( empty( $payment_details['gateway'] ) ) { |
|
156 | + if (empty($payment_details['gateway'])) { |
|
157 | 157 | $payment_details['gateway'] = 'manual'; |
158 | 158 | } |
159 | 159 | |
160 | - if ( empty( $payment_details['currency'] ) ) { |
|
160 | + if (empty($payment_details['currency'])) { |
|
161 | 161 | $payment_details['currency'] = wpinv_get_default_country(); |
162 | 162 | } |
163 | 163 | |
164 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
165 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
164 | + if (empty($payment_details['gateway_title'])) { |
|
165 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
170 | - |
|
171 | - if ( !empty( $payment_details ) ) { |
|
172 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
173 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
174 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
175 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
176 | - } |
|
177 | - |
|
178 | - $invoice->set( 'user_info', $user_info ); |
|
179 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
180 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
181 | - $invoice->set( 'address', $user_info['address'] ); |
|
182 | - $invoice->set( 'company', $user_info['company'] ); |
|
183 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
184 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
185 | - $invoice->set( 'city', $user_info['city'] ); |
|
186 | - $invoice->set( 'country', $user_info['country'] ); |
|
187 | - $invoice->set( 'state', $user_info['state'] ); |
|
188 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
189 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
190 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
191 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
192 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
193 | - |
|
194 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
195 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
196 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
197 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
198 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
199 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
169 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
170 | + |
|
171 | + if (!empty($payment_details)) { |
|
172 | + $invoice->set('currency', $payment_details['currency']); |
|
173 | + $invoice->set('gateway', $payment_details['gateway']); |
|
174 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
175 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
176 | + } |
|
177 | + |
|
178 | + $invoice->set('user_info', $user_info); |
|
179 | + $invoice->set('first_name', $user_info['first_name']); |
|
180 | + $invoice->set('last_name', $user_info['last_name']); |
|
181 | + $invoice->set('address', $user_info['address']); |
|
182 | + $invoice->set('company', $user_info['company']); |
|
183 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
184 | + $invoice->set('phone', $user_info['phone']); |
|
185 | + $invoice->set('city', $user_info['city']); |
|
186 | + $invoice->set('country', $user_info['country']); |
|
187 | + $invoice->set('state', $user_info['state']); |
|
188 | + $invoice->set('zip', $user_info['zip']); |
|
189 | + $invoice->set('discounts', $user_info['discount']); |
|
190 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
191 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
192 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
193 | + |
|
194 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
195 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
196 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
197 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
198 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
199 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
200 | 200 | |
201 | - $post_item = new WPInv_Item( $item_id ); |
|
202 | - if ( !empty( $post_item ) ) { |
|
203 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
201 | + $post_item = new WPInv_Item($item_id); |
|
202 | + if (!empty($post_item)) { |
|
203 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
204 | 204 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
205 | 205 | } else { |
206 | 206 | continue; |
@@ -210,266 +210,266 @@ discard block |
||
210 | 210 | 'name' => $name, |
211 | 211 | 'quantity' => $quantity, |
212 | 212 | 'item_price' => $item_price, |
213 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
214 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
215 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
216 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
217 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
213 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
214 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
215 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
216 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
217 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
218 | 218 | ); |
219 | 219 | |
220 | - $invoice->add_item( $item_id, $args ); |
|
220 | + $invoice->add_item($item_id, $args); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
224 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
225 | 225 | |
226 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
227 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
226 | + if (isset($invoice_data['post_date'])) { |
|
227 | + $invoice->set('date', $invoice_data['post_date']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Invoice due date |
231 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
232 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
231 | + if (isset($invoice_data['due_date'])) { |
|
232 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | $invoice->save(); |
236 | 236 | |
237 | 237 | // Add notes |
238 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
239 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
238 | + if (!empty($invoice_data['private_note'])) { |
|
239 | + $invoice->add_note($invoice_data['private_note']); |
|
240 | 240 | } |
241 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
242 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
241 | + if (!empty($invoice_data['user_note'])) { |
|
242 | + $invoice->add_note($invoice_data['user_note'], true); |
|
243 | 243 | } |
244 | 244 | |
245 | - if ( $invoice->is_quote() ) { |
|
245 | + if ($invoice->is_quote()) { |
|
246 | 246 | |
247 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
248 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
247 | + if (isset($invoice_data['valid_until'])) { |
|
248 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
249 | 249 | } |
250 | 250 | return $invoice; |
251 | 251 | |
252 | 252 | } |
253 | 253 | |
254 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
254 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
255 | 255 | |
256 | - if ( ! empty( $invoice->ID ) ) { |
|
256 | + if (!empty($invoice->ID)) { |
|
257 | 257 | global $wpi_userID, $wpinv_ip_address_country; |
258 | 258 | |
259 | - if ( isset( $invoice_data['created_via'] ) ) { |
|
260 | - update_post_meta( $invoice->ID, 'wpinv_created_via', $invoice_data['created_via'] ); |
|
259 | + if (isset($invoice_data['created_via'])) { |
|
260 | + update_post_meta($invoice->ID, 'wpinv_created_via', $invoice_data['created_via']); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | $checkout_session = wpinv_get_checkout_session(); |
264 | 264 | |
265 | 265 | $data_session = array(); |
266 | 266 | $data_session['invoice_id'] = $invoice->ID; |
267 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
267 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
268 | 268 | |
269 | - wpinv_set_checkout_session( $data_session ); |
|
269 | + wpinv_set_checkout_session($data_session); |
|
270 | 270 | |
271 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
271 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
272 | 272 | |
273 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
273 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
274 | 274 | $_POST['state'] = $invoice->state; |
275 | 275 | |
276 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
277 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
276 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
277 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
278 | 278 | |
279 | 279 | $wpinv_ip_address_country = $invoice->country; |
280 | 280 | |
281 | - $invoice = $invoice->recalculate_totals( true ); |
|
281 | + $invoice = $invoice->recalculate_totals(true); |
|
282 | 282 | |
283 | - wpinv_set_checkout_session( $checkout_session ); |
|
283 | + wpinv_set_checkout_session($checkout_session); |
|
284 | 284 | |
285 | 285 | return $invoice; |
286 | 286 | } |
287 | 287 | |
288 | - if ( $wp_error ) { |
|
289 | - if ( is_wp_error( $invoice ) ) { |
|
288 | + if ($wp_error) { |
|
289 | + if (is_wp_error($invoice)) { |
|
290 | 290 | return $invoice; |
291 | 291 | } else { |
292 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
292 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
293 | 293 | } |
294 | 294 | } else { |
295 | 295 | return 0; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
300 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
299 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
300 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
301 | 301 | |
302 | - if ( !$invoice_ID ) { |
|
303 | - if ( $wp_error ) { |
|
304 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
302 | + if (!$invoice_ID) { |
|
303 | + if ($wp_error) { |
|
304 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
305 | 305 | } |
306 | 306 | return 0; |
307 | 307 | } |
308 | 308 | |
309 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
309 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
310 | 310 | |
311 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
311 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
312 | 312 | |
313 | - if ( empty( $invoice->ID ) ) { |
|
314 | - if ( $wp_error ) { |
|
315 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
313 | + if (empty($invoice->ID)) { |
|
314 | + if ($wp_error) { |
|
315 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
316 | 316 | } |
317 | 317 | return 0; |
318 | 318 | } |
319 | 319 | |
320 | - if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote() ) { |
|
321 | - if ( $wp_error ) { |
|
322 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
320 | + if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) { |
|
321 | + if ($wp_error) { |
|
322 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
323 | 323 | } |
324 | 324 | return 0; |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Invoice status |
328 | - if ( !empty( $invoice_data['status'] ) ) { |
|
329 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
328 | + if (!empty($invoice_data['status'])) { |
|
329 | + $invoice->set('status', $invoice_data['status']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Invoice date |
333 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
334 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
333 | + if (!empty($invoice_data['post_date'])) { |
|
334 | + $invoice->set('date', $invoice_data['post_date']); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | // Invoice due date |
338 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
339 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
338 | + if (isset($invoice_data['due_date'])) { |
|
339 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | // Invoice IP address |
343 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
344 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
343 | + if (!empty($invoice_data['ip'])) { |
|
344 | + $invoice->set('ip', $invoice_data['ip']); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // User info |
348 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
349 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
348 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
349 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
350 | 350 | |
351 | - if ( $discounts = $invoice->get_discounts() ) { |
|
351 | + if ($discounts = $invoice->get_discounts()) { |
|
352 | 352 | $set_discount = $discounts; |
353 | 353 | } else { |
354 | 354 | $set_discount = ''; |
355 | 355 | } |
356 | 356 | |
357 | 357 | // Manage discount |
358 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
358 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
359 | 359 | // Remove discount |
360 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
360 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
361 | 361 | $set_discount = ''; |
362 | 362 | } else { |
363 | 363 | $set_discount = $invoice_data['user_info']['discount']; |
364 | 364 | } |
365 | 365 | |
366 | - $invoice->set( 'discounts', $set_discount ); |
|
366 | + $invoice->set('discounts', $set_discount); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $user_info['discount'] = $set_discount; |
370 | 370 | |
371 | - $invoice->set( 'user_info', $user_info ); |
|
371 | + $invoice->set('user_info', $user_info); |
|
372 | 372 | } |
373 | 373 | |
374 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
375 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
374 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
375 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
376 | 376 | |
377 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
378 | - foreach ( $remove_items as $item ) { |
|
379 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
380 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
381 | - if ( empty( $item_id ) ) { |
|
377 | + if (!empty($remove_items[0]['id'])) { |
|
378 | + foreach ($remove_items as $item) { |
|
379 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
380 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
381 | + if (empty($item_id)) { |
|
382 | 382 | continue; |
383 | 383 | } |
384 | 384 | |
385 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
386 | - if ( $item_id == $cart_item['id'] ) { |
|
385 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
386 | + if ($item_id == $cart_item['id']) { |
|
387 | 387 | $args = array( |
388 | 388 | 'id' => $item_id, |
389 | 389 | 'quantity' => $quantity, |
390 | 390 | 'cart_index' => $cart_index |
391 | 391 | ); |
392 | 392 | |
393 | - $invoice->remove_item( $item_id, $args ); |
|
393 | + $invoice->remove_item($item_id, $args); |
|
394 | 394 | break; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
400 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
401 | 401 | |
402 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
403 | - foreach ( $add_items as $item ) { |
|
404 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
405 | - $post_item = new WPInv_Item( $item_id ); |
|
406 | - if ( empty( $post_item ) ) { |
|
402 | + if (!empty($add_items[0]['id'])) { |
|
403 | + foreach ($add_items as $item) { |
|
404 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
405 | + $post_item = new WPInv_Item($item_id); |
|
406 | + if (empty($post_item)) { |
|
407 | 407 | continue; |
408 | 408 | } |
409 | 409 | |
410 | 410 | $valid_item = true; |
411 | - if ( !empty( $recurring_item ) ) { |
|
412 | - if ( $recurring_item->ID != $item_id ) { |
|
411 | + if (!empty($recurring_item)) { |
|
412 | + if ($recurring_item->ID != $item_id) { |
|
413 | 413 | $valid_item = false; |
414 | 414 | } |
415 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
415 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
416 | 416 | $valid_item = false; |
417 | 417 | } |
418 | 418 | |
419 | - if ( !$valid_item ) { |
|
420 | - if ( $wp_error ) { |
|
421 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
419 | + if (!$valid_item) { |
|
420 | + if ($wp_error) { |
|
421 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
422 | 422 | } |
423 | 423 | return 0; |
424 | 424 | } |
425 | 425 | |
426 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
427 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
428 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
426 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
427 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
428 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
429 | 429 | |
430 | 430 | $args = array( |
431 | 431 | 'name' => $name, |
432 | 432 | 'quantity' => $quantity, |
433 | 433 | 'item_price' => $item_price, |
434 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
435 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
436 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
437 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
438 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
434 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
435 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
436 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
437 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
438 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
439 | 439 | ); |
440 | 440 | |
441 | - $invoice->add_item( $item_id, $args ); |
|
441 | + $invoice->add_item($item_id, $args); |
|
442 | 442 | } |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Payment details |
447 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
448 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
449 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
447 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
448 | + if (!empty($payment_details['gateway'])) { |
|
449 | + $invoice->set('gateway', $payment_details['gateway']); |
|
450 | 450 | } |
451 | 451 | |
452 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
453 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
452 | + if (!empty($payment_details['transaction_id'])) { |
|
453 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
457 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
457 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
458 | 458 | |
459 | 459 | // Parent invoice |
460 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
461 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
460 | + if (!empty($invoice_data['parent'])) { |
|
461 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | // Save invoice data. |
465 | 465 | $invoice->save(); |
466 | 466 | |
467 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
468 | - if ( $wp_error ) { |
|
469 | - if ( is_wp_error( $invoice ) ) { |
|
467 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
468 | + if ($wp_error) { |
|
469 | + if (is_wp_error($invoice)) { |
|
470 | 470 | return $invoice; |
471 | 471 | } else { |
472 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
472 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
473 | 473 | } |
474 | 474 | } else { |
475 | 475 | return 0; |
@@ -477,19 +477,19 @@ discard block |
||
477 | 477 | } |
478 | 478 | |
479 | 479 | // Add private note |
480 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
481 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
480 | + if (!empty($invoice_data['private_note'])) { |
|
481 | + $invoice->add_note($invoice_data['private_note']); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | // Add user note |
485 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
486 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
485 | + if (!empty($invoice_data['user_note'])) { |
|
486 | + $invoice->add_note($invoice_data['user_note'], true); |
|
487 | 487 | } |
488 | 488 | |
489 | - if ( $invoice->is_quote() ) { |
|
489 | + if ($invoice->is_quote()) { |
|
490 | 490 | |
491 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
492 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
491 | + if (isset($invoice_data['valid_until'])) { |
|
492 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
493 | 493 | } |
494 | 494 | return $invoice; |
495 | 495 | |
@@ -501,466 +501,466 @@ discard block |
||
501 | 501 | |
502 | 502 | $data_session = array(); |
503 | 503 | $data_session['invoice_id'] = $invoice->ID; |
504 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
504 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
505 | 505 | |
506 | - wpinv_set_checkout_session( $data_session ); |
|
506 | + wpinv_set_checkout_session($data_session); |
|
507 | 507 | |
508 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
508 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
509 | 509 | |
510 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
510 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
511 | 511 | $_POST['state'] = $invoice->state; |
512 | 512 | |
513 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
514 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
513 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
514 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
515 | 515 | |
516 | 516 | $wpinv_ip_address_country = $invoice->country; |
517 | 517 | |
518 | - $invoice = $invoice->recalculate_totals( true ); |
|
518 | + $invoice = $invoice->recalculate_totals(true); |
|
519 | 519 | |
520 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
520 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
521 | 521 | |
522 | - wpinv_set_checkout_session( $checkout_session ); |
|
522 | + wpinv_set_checkout_session($checkout_session); |
|
523 | 523 | |
524 | 524 | return $invoice; |
525 | 525 | } |
526 | 526 | |
527 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
528 | - if ( $cart && empty( $invoice_id ) ) { |
|
529 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
527 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
528 | + if ($cart && empty($invoice_id)) { |
|
529 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
530 | 530 | } |
531 | 531 | |
532 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
532 | + $invoice = new WPInv_Invoice($invoice_id); |
|
533 | 533 | |
534 | - if ( $invoice->get_id() != 0 ) { |
|
534 | + if ($invoice->get_id() != 0) { |
|
535 | 535 | return $invoice; |
536 | 536 | } |
537 | 537 | |
538 | 538 | return NULL; |
539 | 539 | } |
540 | 540 | |
541 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
542 | - return wpinv_get_invoice( $invoice_id, true ); |
|
541 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
542 | + return wpinv_get_invoice($invoice_id, true); |
|
543 | 543 | } |
544 | 544 | |
545 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
546 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
545 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
546 | + $invoice = new WPInv_Invoice($invoice_id); |
|
547 | 547 | return $invoice->get_description(); |
548 | 548 | } |
549 | 549 | |
550 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
551 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
550 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
551 | + $invoice = new WPInv_Invoice($invoice_id); |
|
552 | 552 | return $invoice->get_currency(); |
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
556 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
555 | +function wpinv_get_payment_user_email($invoice_id) { |
|
556 | + $invoice = new WPInv_Invoice($invoice_id); |
|
557 | 557 | return $invoice->get_email(); |
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_get_user_id( $invoice_id ) { |
|
561 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
560 | +function wpinv_get_user_id($invoice_id) { |
|
561 | + $invoice = new WPInv_Invoice($invoice_id); |
|
562 | 562 | return $invoice->get_user_id(); |
563 | 563 | } |
564 | 564 | |
565 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
566 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
565 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
566 | + $invoice = new WPInv_Invoice($invoice_id); |
|
567 | 567 | |
568 | - return $invoice->get_status( $return_label ); |
|
568 | + return $invoice->get_status($return_label); |
|
569 | 569 | } |
570 | 570 | |
571 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
572 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
571 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
572 | + $invoice = new WPInv_Invoice($invoice_id); |
|
573 | 573 | |
574 | - return $invoice->get_gateway( $return_label ); |
|
574 | + return $invoice->get_gateway($return_label); |
|
575 | 575 | } |
576 | 576 | |
577 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
578 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
577 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
578 | + $invoice = new WPInv_Invoice($invoice_id); |
|
579 | 579 | |
580 | 580 | return $invoice->get_gateway_title(); |
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
584 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
583 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
584 | + $invoice = new WPInv_Invoice($invoice_id); |
|
585 | 585 | |
586 | 586 | return $invoice->get_transaction_id(); |
587 | 587 | } |
588 | 588 | |
589 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
589 | +function wpinv_get_id_by_transaction_id($key) { |
|
590 | 590 | global $wpdb; |
591 | 591 | |
592 | - $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 ) ); |
|
592 | + $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)); |
|
593 | 593 | |
594 | - if ( $invoice_id != NULL ) |
|
594 | + if ($invoice_id != NULL) |
|
595 | 595 | return $invoice_id; |
596 | 596 | |
597 | 597 | return 0; |
598 | 598 | } |
599 | 599 | |
600 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
601 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
600 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
601 | + $invoice = new WPInv_Invoice($invoice_id); |
|
602 | 602 | |
603 | - return $invoice->get_meta( $meta_key, $single ); |
|
603 | + return $invoice->get_meta($meta_key, $single); |
|
604 | 604 | } |
605 | 605 | |
606 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
607 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
606 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
607 | + $invoice = new WPInv_Invoice($invoice_id); |
|
608 | 608 | |
609 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
609 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
610 | 610 | } |
611 | 611 | |
612 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
613 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
612 | +function wpinv_get_items($invoice_id = 0) { |
|
613 | + $invoice = wpinv_get_invoice($invoice_id); |
|
614 | 614 | |
615 | 615 | $items = $invoice->get_items(); |
616 | 616 | $invoice_currency = $invoice->get_currency(); |
617 | 617 | |
618 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
619 | - foreach ( $items as $key => $item ) { |
|
618 | + if (!empty($items) && is_array($items)) { |
|
619 | + foreach ($items as $key => $item) { |
|
620 | 620 | $items[$key]['currency'] = $invoice_currency; |
621 | 621 | |
622 | - if ( !isset( $item['subtotal'] ) ) { |
|
622 | + if (!isset($item['subtotal'])) { |
|
623 | 623 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
624 | 624 | } |
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
628 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
628 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
632 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
631 | +function wpinv_get_fees($invoice_id = 0) { |
|
632 | + $invoice = wpinv_get_invoice($invoice_id); |
|
633 | 633 | $fees = $invoice->get_fees(); |
634 | 634 | |
635 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
635 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
639 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
638 | +function wpinv_get_invoice_ip($invoice_id) { |
|
639 | + $invoice = new WPInv_Invoice($invoice_id); |
|
640 | 640 | return $invoice->get_ip(); |
641 | 641 | } |
642 | 642 | |
643 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
644 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
643 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
644 | + $invoice = new WPInv_Invoice($invoice_id); |
|
645 | 645 | return $invoice->get_user_info(); |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
649 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
648 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
649 | + $invoice = new WPInv_Invoice($invoice_id); |
|
650 | 650 | |
651 | - return $invoice->get_subtotal( $currency ); |
|
651 | + return $invoice->get_subtotal($currency); |
|
652 | 652 | } |
653 | 653 | |
654 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
655 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
654 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
655 | + $invoice = new WPInv_Invoice($invoice_id); |
|
656 | 656 | |
657 | - return $invoice->get_tax( $currency ); |
|
657 | + return $invoice->get_tax($currency); |
|
658 | 658 | } |
659 | 659 | |
660 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
661 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
660 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
661 | + $invoice = wpinv_get_invoice($invoice_id); |
|
662 | 662 | |
663 | - return $invoice->get_discount( $currency, $dash ); |
|
663 | + return $invoice->get_discount($currency, $dash); |
|
664 | 664 | } |
665 | 665 | |
666 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
667 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
666 | +function wpinv_discount_code($invoice_id = 0) { |
|
667 | + $invoice = new WPInv_Invoice($invoice_id); |
|
668 | 668 | |
669 | 669 | return $invoice->get_discount_code(); |
670 | 670 | } |
671 | 671 | |
672 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
673 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
672 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
673 | + $invoice = new WPInv_Invoice($invoice_id); |
|
674 | 674 | |
675 | - return $invoice->get_total( $currency ); |
|
675 | + return $invoice->get_total($currency); |
|
676 | 676 | } |
677 | 677 | |
678 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
679 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
678 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
679 | + $invoice = new WPInv_Invoice($invoice_id); |
|
680 | 680 | |
681 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
681 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
682 | 682 | $date_created = $invoice->get_created_date(); |
683 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
683 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
684 | 684 | |
685 | 685 | return $date_created; |
686 | 686 | } |
687 | 687 | |
688 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
689 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
688 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
689 | + $invoice = new WPInv_Invoice($invoice_id); |
|
690 | 690 | |
691 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
691 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
692 | 692 | $date_completed = $invoice->get_completed_date(); |
693 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
694 | - if ( $invoice_date == '' && $default ) { |
|
695 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
693 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
694 | + if ($invoice_date == '' && $default) { |
|
695 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | return $invoice_date; |
699 | 699 | } |
700 | 700 | |
701 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
702 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
701 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
702 | + $invoice = new WPInv_Invoice($invoice_id); |
|
703 | 703 | |
704 | 704 | return $invoice->vat_number; |
705 | 705 | } |
706 | 706 | |
707 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
708 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
707 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
708 | + $invoice = new WPInv_Invoice($invoice_id); |
|
709 | 709 | |
710 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
710 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
711 | 711 | } |
712 | 712 | |
713 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
713 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
714 | 714 | global $invoicing; |
715 | 715 | |
716 | - if ( empty( $invoice_id ) ) { |
|
716 | + if (empty($invoice_id)) { |
|
717 | 717 | return NULL; |
718 | 718 | } |
719 | 719 | |
720 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
720 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
721 | 721 | |
722 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
722 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
723 | 723 | } |
724 | 724 | |
725 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
726 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
725 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
726 | + $invoice = new WPInv_Invoice($invoice_id); |
|
727 | 727 | return $invoice->get_key(); |
728 | 728 | } |
729 | 729 | |
730 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
731 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
730 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
731 | + $invoice = new WPInv_Invoice($invoice_id); |
|
732 | 732 | return $invoice->get_number(); |
733 | 733 | } |
734 | 734 | |
735 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
735 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
736 | 736 | $cart_items = wpinv_get_cart_content_details(); |
737 | 737 | $items = array(); |
738 | 738 | |
739 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
739 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
740 | 740 | |
741 | - if( $cart_items ) { |
|
741 | + if ($cart_items) { |
|
742 | 742 | |
743 | - foreach( $cart_items as $item ) { |
|
743 | + foreach ($cart_items as $item) { |
|
744 | 744 | |
745 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
746 | - $items[] = $item; |
|
745 | + if (!in_array($item['id'], $excluded_items)) { |
|
746 | + $items[] = $item; |
|
747 | 747 | } |
748 | 748 | } |
749 | 749 | } |
750 | 750 | |
751 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
751 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
752 | 752 | |
753 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
753 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
754 | 754 | } |
755 | 755 | |
756 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
756 | +function wpinv_get_cart_items_subtotal($items) { |
|
757 | 757 | $subtotal = 0.00; |
758 | 758 | |
759 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
760 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
759 | + if (is_array($items) && !empty($items)) { |
|
760 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
761 | 761 | |
762 | - if( is_array( $prices ) ) { |
|
763 | - $subtotal = array_sum( $prices ); |
|
762 | + if (is_array($prices)) { |
|
763 | + $subtotal = array_sum($prices); |
|
764 | 764 | } else { |
765 | 765 | $subtotal = 0.00; |
766 | 766 | } |
767 | 767 | |
768 | - if( $subtotal < 0 ) { |
|
768 | + if ($subtotal < 0) { |
|
769 | 769 | $subtotal = 0.00; |
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
773 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
774 | 774 | } |
775 | 775 | |
776 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
777 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
778 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
776 | +function wpinv_get_cart_subtotal($items = array()) { |
|
777 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
778 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
779 | 779 | |
780 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
780 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
781 | 781 | } |
782 | 782 | |
783 | -function wpinv_cart_subtotal( $items = array(), $currency = '' ) { |
|
783 | +function wpinv_cart_subtotal($items = array(), $currency = '') { |
|
784 | 784 | |
785 | - if( empty( $currency ) ) { |
|
785 | + if (empty($currency)) { |
|
786 | 786 | $currency = wpinv_get_currency(); |
787 | 787 | } |
788 | 788 | |
789 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency ); |
|
789 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency); |
|
790 | 790 | |
791 | 791 | return $price; |
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
795 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
796 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
797 | - $cart_tax = (float)wpinv_get_cart_tax( $items, $invoice ); |
|
798 | - $fees = (float)wpinv_get_cart_fee_total(); |
|
799 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
794 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
795 | + $subtotal = (float) wpinv_get_cart_subtotal($items); |
|
796 | + $discounts = (float) wpinv_get_cart_discounted_amount($items); |
|
797 | + $cart_tax = (float) wpinv_get_cart_tax($items, $invoice); |
|
798 | + $fees = (float) wpinv_get_cart_fee_total(); |
|
799 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
800 | 800 | $total = 0; |
801 | 801 | } else { |
802 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
802 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
803 | 803 | } |
804 | 804 | |
805 | - if ( $total < 0 ) { |
|
805 | + if ($total < 0) { |
|
806 | 806 | $total = 0.00; |
807 | 807 | } |
808 | 808 | |
809 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
809 | + $total = (float) apply_filters('wpinv_get_cart_total', $total, $items); |
|
810 | 810 | |
811 | - return wpinv_sanitize_amount( $total ); |
|
811 | + return wpinv_sanitize_amount($total); |
|
812 | 812 | } |
813 | 813 | |
814 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
814 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
815 | 815 | global $cart_total; |
816 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() ); |
|
817 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
816 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency()); |
|
817 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
818 | 818 | |
819 | 819 | $cart_total = $total; |
820 | 820 | |
821 | - if ( !$echo ) { |
|
821 | + if (!$echo) { |
|
822 | 822 | return $total; |
823 | 823 | } |
824 | 824 | |
825 | 825 | echo $total; |
826 | 826 | } |
827 | 827 | |
828 | -function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) { |
|
828 | +function wpinv_get_cart_tax($items = array(), $invoice = 0) { |
|
829 | 829 | |
830 | - if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) { |
|
830 | + if (!empty($invoice) && !$invoice->is_taxable()) { |
|
831 | 831 | return 0; |
832 | 832 | } |
833 | 833 | |
834 | 834 | $cart_tax = 0; |
835 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
835 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
836 | 836 | |
837 | - if ( $items ) { |
|
838 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
837 | + if ($items) { |
|
838 | + $taxes = wp_list_pluck($items, 'tax'); |
|
839 | 839 | |
840 | - if( is_array( $taxes ) ) { |
|
841 | - $cart_tax = array_sum( $taxes ); |
|
840 | + if (is_array($taxes)) { |
|
841 | + $cart_tax = array_sum($taxes); |
|
842 | 842 | } |
843 | 843 | } |
844 | 844 | |
845 | 845 | $cart_tax += wpinv_get_cart_fee_tax(); |
846 | 846 | |
847 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
847 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
848 | 848 | } |
849 | 849 | |
850 | -function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) { |
|
850 | +function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) { |
|
851 | 851 | |
852 | - if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) { |
|
853 | - echo wpinv_price( wpinv_format_amount( 0 ), $currency ); |
|
852 | + if (!empty($invoice && !$invoice->is_taxable())) { |
|
853 | + echo wpinv_price(wpinv_format_amount(0), $currency); |
|
854 | 854 | return; |
855 | 855 | } |
856 | 856 | |
857 | - $cart_tax = wpinv_get_cart_tax( $items, $invoice ); |
|
858 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency ); |
|
857 | + $cart_tax = wpinv_get_cart_tax($items, $invoice); |
|
858 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency); |
|
859 | 859 | |
860 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
860 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
861 | 861 | |
862 | - if ( !$echo ) { |
|
862 | + if (!$echo) { |
|
863 | 863 | return $tax; |
864 | 864 | } |
865 | 865 | |
866 | 866 | echo $tax; |
867 | 867 | } |
868 | 868 | |
869 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
869 | +function wpinv_get_cart_discount_code($items = array()) { |
|
870 | 870 | $invoice = wpinv_get_invoice_cart(); |
871 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
871 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
872 | 872 | |
873 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
873 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
874 | 874 | } |
875 | 875 | |
876 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
877 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
876 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
877 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
878 | 878 | |
879 | - if ( $cart_discount_code != '' ) { |
|
879 | + if ($cart_discount_code != '') { |
|
880 | 880 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
881 | 881 | } |
882 | 882 | |
883 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
883 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
884 | 884 | |
885 | - if ( !$echo ) { |
|
885 | + if (!$echo) { |
|
886 | 886 | return $discount_code; |
887 | 887 | } |
888 | 888 | |
889 | 889 | echo $discount_code; |
890 | 890 | } |
891 | 891 | |
892 | -function wpinv_get_cart_discount( $items = array() ) { |
|
892 | +function wpinv_get_cart_discount($items = array()) { |
|
893 | 893 | $invoice = wpinv_get_invoice_cart(); |
894 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
894 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
895 | 895 | |
896 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
896 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
897 | 897 | } |
898 | 898 | |
899 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
900 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
901 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
899 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
900 | + $cart_discount = wpinv_get_cart_discount($items); |
|
901 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
902 | 902 | |
903 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
903 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
904 | 904 | |
905 | - if ( !$echo ) { |
|
905 | + if (!$echo) { |
|
906 | 906 | return $discount; |
907 | 907 | } |
908 | 908 | |
909 | 909 | echo $discount; |
910 | 910 | } |
911 | 911 | |
912 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
913 | - $item = new WPInv_Item( $item_id ); |
|
912 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
913 | + $item = new WPInv_Item($item_id); |
|
914 | 914 | |
915 | - return $item->get_fees( $type, $item_id ); |
|
915 | + return $item->get_fees($type, $item_id); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | function wpinv_get_cart_fee_total() { |
919 | - $total = 0; |
|
919 | + $total = 0; |
|
920 | 920 | $fees = wpinv_get_cart_fees(); |
921 | 921 | |
922 | - if ( $fees ) { |
|
923 | - foreach ( $fees as $fee_id => $fee ) { |
|
922 | + if ($fees) { |
|
923 | + foreach ($fees as $fee_id => $fee) { |
|
924 | 924 | $total += $fee['amount']; |
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
928 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | function wpinv_get_cart_fee_tax() { |
932 | 932 | $tax = 0; |
933 | 933 | $fees = wpinv_get_cart_fees(); |
934 | 934 | |
935 | - if ( $fees ) { |
|
936 | - foreach ( $fees as $fee_id => $fee ) { |
|
937 | - if( ! empty( $fee['no_tax'] ) ) { |
|
935 | + if ($fees) { |
|
936 | + foreach ($fees as $fee_id => $fee) { |
|
937 | + if (!empty($fee['no_tax'])) { |
|
938 | 938 | continue; |
939 | 939 | } |
940 | 940 | |
941 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
941 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
945 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
945 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | function wpinv_cart_has_recurring_item() { |
949 | 949 | $cart_items = wpinv_get_cart_contents(); |
950 | 950 | |
951 | - if ( empty( $cart_items ) ) { |
|
951 | + if (empty($cart_items)) { |
|
952 | 952 | return false; |
953 | 953 | } |
954 | 954 | |
955 | 955 | $has_subscription = false; |
956 | - foreach( $cart_items as $cart_item ) { |
|
957 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
956 | + foreach ($cart_items as $cart_item) { |
|
957 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
958 | 958 | $has_subscription = true; |
959 | 959 | break; |
960 | 960 | } |
961 | 961 | } |
962 | 962 | |
963 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
963 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | function wpinv_cart_has_free_trial() { |
@@ -968,100 +968,100 @@ discard block |
||
968 | 968 | |
969 | 969 | $free_trial = false; |
970 | 970 | |
971 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
971 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
972 | 972 | $free_trial = true; |
973 | 973 | } |
974 | 974 | |
975 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
975 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | function wpinv_get_cart_contents() { |
979 | 979 | $cart_details = wpinv_get_cart_details(); |
980 | 980 | |
981 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
981 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | function wpinv_get_cart_content_details() { |
985 | 985 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
986 | 986 | $cart_items = wpinv_get_cart_contents(); |
987 | 987 | |
988 | - if ( empty( $cart_items ) ) { |
|
988 | + if (empty($cart_items)) { |
|
989 | 989 | return false; |
990 | 990 | } |
991 | 991 | $invoice = wpinv_get_invoice_cart(); |
992 | - if ( empty( $invoice ) ) { |
|
992 | + if (empty($invoice)) { |
|
993 | 993 | return false; |
994 | 994 | } |
995 | 995 | |
996 | 996 | $details = array(); |
997 | - $length = count( $cart_items ) - 1; |
|
997 | + $length = count($cart_items) - 1; |
|
998 | 998 | |
999 | - if ( empty( $_POST['country'] ) ) { |
|
999 | + if (empty($_POST['country'])) { |
|
1000 | 1000 | $_POST['country'] = $invoice->country; |
1001 | 1001 | } |
1002 | - if ( !isset( $_POST['state'] ) ) { |
|
1002 | + if (!isset($_POST['state'])) { |
|
1003 | 1003 | $_POST['state'] = $invoice->state; |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - foreach( $cart_items as $key => $item ) { |
|
1007 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
1008 | - if ( empty( $item_id ) ) { |
|
1006 | + foreach ($cart_items as $key => $item) { |
|
1007 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
1008 | + if (empty($item_id)) { |
|
1009 | 1009 | continue; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | $wpi_current_id = $invoice->ID; |
1013 | 1013 | $wpi_item_id = $item_id; |
1014 | 1014 | |
1015 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
1015 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
1016 | 1016 | $item_price = $item['custom_price']; |
1017 | 1017 | } else { |
1018 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
1018 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
1019 | 1019 | $item_price = $item['item_price']; |
1020 | 1020 | } else { |
1021 | - $item_price = wpinv_get_item_price( $item_id ); |
|
1021 | + $item_price = wpinv_get_item_price($item_id); |
|
1022 | 1022 | } |
1023 | 1023 | } |
1024 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
1025 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
1026 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
1027 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
1024 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
1025 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
1026 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
1027 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
1028 | 1028 | |
1029 | 1029 | $subtotal = $item_price * $quantity; |
1030 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
1031 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
1032 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
1030 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
1031 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
1032 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
1033 | 1033 | |
1034 | - if ( ! $invoice->is_taxable() ) { |
|
1034 | + if (!$invoice->is_taxable()) { |
|
1035 | 1035 | $tax = 0; |
1036 | 1036 | } |
1037 | - if ( wpinv_prices_include_tax() ) { |
|
1038 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1037 | + if (wpinv_prices_include_tax()) { |
|
1038 | + $subtotal -= wpinv_round_amount($tax); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $total = $subtotal - $discount + $tax; |
|
1041 | + $total = $subtotal - $discount + $tax; |
|
1042 | 1042 | |
1043 | 1043 | // Do not allow totals to go negatve |
1044 | - if( $total < 0 ) { |
|
1044 | + if ($total < 0) { |
|
1045 | 1045 | $total = 0; |
1046 | 1046 | } |
1047 | 1047 | |
1048 | - $details[ $key ] = array( |
|
1048 | + $details[$key] = array( |
|
1049 | 1049 | 'id' => $item_id, |
1050 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
1051 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1052 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
1050 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
1051 | + 'item_price' => wpinv_round_amount($item_price), |
|
1052 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
1053 | 1053 | 'quantity' => $quantity, |
1054 | - 'discount' => wpinv_round_amount( $discount ), |
|
1055 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1056 | - 'tax' => wpinv_round_amount( $tax ), |
|
1057 | - 'price' => wpinv_round_amount( $total ), |
|
1054 | + 'discount' => wpinv_round_amount($discount), |
|
1055 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1056 | + 'tax' => wpinv_round_amount($tax), |
|
1057 | + 'price' => wpinv_round_amount($total), |
|
1058 | 1058 | 'vat_rates_class' => $tax_class, |
1059 | 1059 | 'vat_rate' => $tax_rate, |
1060 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
1060 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
1061 | 1061 | 'fees' => $fees, |
1062 | 1062 | ); |
1063 | 1063 | |
1064 | - if ( $wpinv_is_last_cart_item ) { |
|
1064 | + if ($wpinv_is_last_cart_item) { |
|
1065 | 1065 | $wpinv_is_last_cart_item = false; |
1066 | 1066 | $wpinv_flat_discount_total = 0.00; |
1067 | 1067 | } |
@@ -1070,74 +1070,74 @@ discard block |
||
1070 | 1070 | return $details; |
1071 | 1071 | } |
1072 | 1072 | |
1073 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
1073 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
1074 | 1074 | global $ajax_cart_details; |
1075 | 1075 | |
1076 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1076 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1077 | 1077 | $cart_details = $ajax_cart_details; |
1078 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
1078 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
1079 | 1079 | $cart_details = $invoice->cart_details; |
1080 | 1080 | } |
1081 | 1081 | |
1082 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
1083 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
1082 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
1083 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
1084 | 1084 | |
1085 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1086 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
1085 | + foreach ($cart_details as $key => $cart_item) { |
|
1086 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
1087 | 1087 | |
1088 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
1089 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
1088 | + if (!isset($cart_item['subtotal'])) { |
|
1089 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
1090 | 1090 | } |
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | |
1094 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
1094 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
1098 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
1097 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
1098 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
1099 | 1099 | return; |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
1102 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
1103 | 1103 | return; |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1106 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1107 | 1107 | |
1108 | - if ( wpinv_use_taxes() && $new_status == 'publish' ) { |
|
1108 | + if (wpinv_use_taxes() && $new_status == 'publish') { |
|
1109 | 1109 | |
1110 | - if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->country ) ) { |
|
1111 | - $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true ); |
|
1110 | + if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->country)) { |
|
1111 | + $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true); |
|
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | |
1115 | - $old_status = wpinv_status_nicename( $old_status ); |
|
1116 | - $new_status = wpinv_status_nicename( $new_status ); |
|
1115 | + $old_status = wpinv_status_nicename($old_status); |
|
1116 | + $new_status = wpinv_status_nicename($new_status); |
|
1117 | 1117 | |
1118 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
1118 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
1119 | 1119 | |
1120 | 1120 | // Add note |
1121 | - return $invoice->add_note( $status_change, false, false, true ); |
|
1121 | + return $invoice->add_note($status_change, false, false, true); |
|
1122 | 1122 | } |
1123 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
1123 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
1124 | 1124 | |
1125 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
1125 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
1126 | 1126 | global $wpi_has_free_trial; |
1127 | 1127 | |
1128 | 1128 | $wpi_has_free_trial = false; |
1129 | 1129 | |
1130 | - if ( $old_status == 'publish' ) { |
|
1130 | + if ($old_status == 'publish') { |
|
1131 | 1131 | return; // Make sure that payments are only paid once |
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | // Make sure the payment completion is only processed when new status is paid |
1135 | - if ( $new_status != 'publish' ) { |
|
1135 | + if ($new_status != 'publish') { |
|
1136 | 1136 | return; |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1140 | - if ( empty( $invoice ) ) { |
|
1139 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1140 | + if (empty($invoice)) { |
|
1141 | 1141 | return; |
1142 | 1142 | } |
1143 | 1143 | |
@@ -1145,58 +1145,58 @@ discard block |
||
1145 | 1145 | $completed_date = $invoice->completed_date; |
1146 | 1146 | $cart_details = $invoice->cart_details; |
1147 | 1147 | |
1148 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
1148 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
1149 | 1149 | |
1150 | - if ( is_array( $cart_details ) ) { |
|
1150 | + if (is_array($cart_details)) { |
|
1151 | 1151 | // Increase purchase count and earnings |
1152 | - foreach ( $cart_details as $cart_index => $item ) { |
|
1152 | + foreach ($cart_details as $cart_index => $item) { |
|
1153 | 1153 | // Ensure these actions only run once, ever |
1154 | - if ( empty( $completed_date ) ) { |
|
1155 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
1154 | + if (empty($completed_date)) { |
|
1155 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
1156 | 1156 | } |
1157 | 1157 | } |
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | // Check for discount codes and increment their use counts |
1161 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
1162 | - if( ! empty( $discounts ) ) { |
|
1163 | - foreach( $discounts as $code ) { |
|
1164 | - wpinv_increase_discount_usage( $code ); |
|
1161 | + if ($discounts = $invoice->get_discounts(true)) { |
|
1162 | + if (!empty($discounts)) { |
|
1163 | + foreach ($discounts as $code) { |
|
1164 | + wpinv_increase_discount_usage($code); |
|
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | // Ensure this action only runs once ever |
1170 | - if( empty( $completed_date ) ) { |
|
1170 | + if (empty($completed_date)) { |
|
1171 | 1171 | // Save the completed date |
1172 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
1172 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
1173 | 1173 | $invoice->save(); |
1174 | 1174 | |
1175 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
1175 | + do_action('wpinv_complete_payment', $invoice_id); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | // Empty the shopping cart |
1179 | 1179 | wpinv_empty_cart(); |
1180 | 1180 | } |
1181 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
1181 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
1182 | 1182 | |
1183 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
1184 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
1183 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
1184 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id); |
|
1185 | 1185 | |
1186 | - if ( empty( $invoice ) ) { |
|
1186 | + if (empty($invoice)) { |
|
1187 | 1187 | return false; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - return $invoice->update_status( $new_status ); |
|
1190 | + return $invoice->update_status($new_status); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
1193 | +function wpinv_cart_has_fees($type = 'all') { |
|
1194 | 1194 | return false; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | function wpinv_validate_checkout_fields() { |
1198 | 1198 | // Check if there is $_POST |
1199 | - if ( empty( $_POST ) ) { |
|
1199 | + if (empty($_POST)) { |
|
1200 | 1200 | return false; |
1201 | 1201 | } |
1202 | 1202 | |
@@ -1219,28 +1219,28 @@ discard block |
||
1219 | 1219 | |
1220 | 1220 | $invoice = wpinv_get_invoice_cart(); |
1221 | 1221 | $has_subscription = $invoice->is_recurring(); |
1222 | - if ( empty( $invoice ) ) { |
|
1223 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
1222 | + if (empty($invoice)) { |
|
1223 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
1224 | 1224 | return $gateway; |
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | // Check if a gateway value is present |
1228 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
1229 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
1228 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
1229 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
1230 | 1230 | |
1231 | - if ( $invoice->is_free() ) { |
|
1231 | + if ($invoice->is_free()) { |
|
1232 | 1232 | $gateway = 'manual'; |
1233 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
1234 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
1235 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
1236 | - if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) { |
|
1237 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) ); |
|
1233 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
1234 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
1235 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
1236 | + if (apply_filters('wpinv_reject_non_recurring_gateway', true)) { |
|
1237 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing')); |
|
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | } |
1241 | 1241 | |
1242 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
1243 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
1242 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
1243 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | return $gateway; |
@@ -1252,41 +1252,41 @@ discard block |
||
1252 | 1252 | // Retrieve the discount stored in cookies |
1253 | 1253 | $discounts = wpinv_get_cart_discounts(); |
1254 | 1254 | |
1255 | - if ( ! is_array( $discounts ) ) { |
|
1255 | + if (!is_array($discounts)) { |
|
1256 | 1256 | return NULL; |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - $discounts = array_filter( $discounts ); |
|
1260 | - $error = false; |
|
1259 | + $discounts = array_filter($discounts); |
|
1260 | + $error = false; |
|
1261 | 1261 | |
1262 | - if ( empty( $discounts ) ) { |
|
1262 | + if (empty($discounts)) { |
|
1263 | 1263 | return NULL; |
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | // If we have discounts, loop through them |
1267 | - foreach ( $discounts as $discount ) { |
|
1267 | + foreach ($discounts as $discount) { |
|
1268 | 1268 | // Check if valid |
1269 | - if ( ! wpinv_is_discount_valid( $discount, (int) $wpi_cart->get_user_id() ) ) { |
|
1269 | + if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) { |
|
1270 | 1270 | // Discount is not valid |
1271 | 1271 | $error = true; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | } |
1275 | 1275 | |
1276 | - if ( $error && ! wpinv_get_errors() ) { |
|
1277 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
1276 | + if ($error && !wpinv_get_errors()) { |
|
1277 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
1278 | 1278 | } |
1279 | 1279 | |
1280 | - return implode( ',', $discounts ); |
|
1280 | + return implode(',', $discounts); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | 1283 | function wpinv_checkout_validate_cc() { |
1284 | 1284 | $card_data = wpinv_checkout_get_cc_info(); |
1285 | 1285 | |
1286 | 1286 | // Validate the card zip |
1287 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
1288 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
1289 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
1287 | + if (!empty($card_data['wpinv_zip'])) { |
|
1288 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
1289 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
1290 | 1290 | } |
1291 | 1291 | } |
1292 | 1292 | |
@@ -1296,28 +1296,28 @@ discard block |
||
1296 | 1296 | |
1297 | 1297 | function wpinv_checkout_get_cc_info() { |
1298 | 1298 | $cc_info = array(); |
1299 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1300 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1301 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1302 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1303 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1304 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1305 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1306 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1307 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1308 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1299 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
1300 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
1301 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
1302 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
1303 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
1304 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
1305 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
1306 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
1307 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
1308 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
1309 | 1309 | |
1310 | 1310 | // Return cc info |
1311 | 1311 | return $cc_info; |
1312 | 1312 | } |
1313 | 1313 | |
1314 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
1314 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
1315 | 1315 | $ret = false; |
1316 | 1316 | |
1317 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
1317 | + if (empty($zip) || empty($country_code)) |
|
1318 | 1318 | return $ret; |
1319 | 1319 | |
1320 | - $country_code = strtoupper( $country_code ); |
|
1320 | + $country_code = strtoupper($country_code); |
|
1321 | 1321 | |
1322 | 1322 | $zip_regex = array( |
1323 | 1323 | "AD" => "AD\d{3}", |
@@ -1477,72 +1477,72 @@ discard block |
||
1477 | 1477 | "ZM" => "\d{5}" |
1478 | 1478 | ); |
1479 | 1479 | |
1480 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1480 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1481 | 1481 | $ret = true; |
1482 | 1482 | |
1483 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1483 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1484 | 1484 | } |
1485 | 1485 | |
1486 | 1486 | function wpinv_checkout_validate_agree_to_terms() { |
1487 | 1487 | // Validate agree to terms |
1488 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1488 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1489 | 1489 | // User did not agree |
1490 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1490 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1491 | 1491 | } |
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | function wpinv_checkout_validate_invoice_user() { |
1495 | 1495 | global $wpi_cart, $user_ID; |
1496 | 1496 | |
1497 | - if(empty($wpi_cart)){ |
|
1497 | + if (empty($wpi_cart)) { |
|
1498 | 1498 | $wpi_cart = wpinv_get_invoice_cart(); |
1499 | 1499 | } |
1500 | 1500 | |
1501 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
1501 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
1502 | 1502 | $valid_user_data = array( |
1503 | 1503 | 'user_id' => $invoice_user |
1504 | 1504 | ); |
1505 | 1505 | |
1506 | 1506 | // If guest checkout allowed |
1507 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1507 | + if (!wpinv_require_login_to_checkout()) { |
|
1508 | 1508 | return $valid_user_data; |
1509 | 1509 | } |
1510 | 1510 | |
1511 | 1511 | // Verify there is a user_ID |
1512 | - if ( $user_ID == $invoice_user ) { |
|
1512 | + if ($user_ID == $invoice_user) { |
|
1513 | 1513 | // Get the logged in user data |
1514 | - $user_data = get_userdata( $user_ID ); |
|
1515 | - $required_fields = wpinv_checkout_required_fields(); |
|
1514 | + $user_data = get_userdata($user_ID); |
|
1515 | + $required_fields = wpinv_checkout_required_fields(); |
|
1516 | 1516 | |
1517 | 1517 | // Loop through required fields and show error messages |
1518 | - if ( !empty( $required_fields ) ) { |
|
1519 | - foreach ( $required_fields as $field_name => $value ) { |
|
1520 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1521 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1518 | + if (!empty($required_fields)) { |
|
1519 | + foreach ($required_fields as $field_name => $value) { |
|
1520 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1521 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1522 | 1522 | } |
1523 | 1523 | } |
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | // Verify data |
1527 | - if ( $user_data ) { |
|
1527 | + if ($user_data) { |
|
1528 | 1528 | // Collected logged in user data |
1529 | 1529 | $valid_user_data = array( |
1530 | 1530 | 'user_id' => $user_ID, |
1531 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1532 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1533 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1531 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1532 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1533 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1534 | 1534 | ); |
1535 | 1535 | |
1536 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1537 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1536 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1537 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1538 | 1538 | } |
1539 | 1539 | } else { |
1540 | 1540 | // Set invalid user error |
1541 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1541 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1542 | 1542 | } |
1543 | 1543 | } else { |
1544 | 1544 | // Set invalid user error |
1545 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
1545 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | // Return user data |
@@ -1554,27 +1554,27 @@ discard block |
||
1554 | 1554 | |
1555 | 1555 | $data = array(); |
1556 | 1556 | |
1557 | - if ( is_user_logged_in() ) { |
|
1558 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
1559 | - $data['user_id'] = (int)get_current_user_id(); |
|
1557 | + if (is_user_logged_in()) { |
|
1558 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
1559 | + $data['user_id'] = (int) get_current_user_id(); |
|
1560 | 1560 | } else { |
1561 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
1561 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
1562 | 1562 | } |
1563 | 1563 | } else { |
1564 | 1564 | // If guest checkout allowed |
1565 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1565 | + if (!wpinv_require_login_to_checkout()) { |
|
1566 | 1566 | $data['user_id'] = 0; |
1567 | 1567 | } else { |
1568 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
1568 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
1569 | 1569 | } |
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | return $data; |
1573 | 1573 | } |
1574 | 1574 | |
1575 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1575 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1576 | 1576 | |
1577 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
1577 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
1578 | 1578 | $user = $valid_data['current_user']; |
1579 | 1579 | } else { |
1580 | 1580 | // Set the valid invoice user |
@@ -1582,7 +1582,7 @@ discard block |
||
1582 | 1582 | } |
1583 | 1583 | |
1584 | 1584 | // Verify invoice have an user |
1585 | - if ( false === $user || empty( $user ) ) { |
|
1585 | + if (false === $user || empty($user)) { |
|
1586 | 1586 | return false; |
1587 | 1587 | } |
1588 | 1588 | |
@@ -1599,11 +1599,11 @@ discard block |
||
1599 | 1599 | 'zip', |
1600 | 1600 | ); |
1601 | 1601 | |
1602 | - foreach ( $address_fields as $field ) { |
|
1603 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1602 | + foreach ($address_fields as $field) { |
|
1603 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1604 | 1604 | |
1605 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
1606 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1605 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
1606 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1607 | 1607 | } |
1608 | 1608 | } |
1609 | 1609 | |
@@ -1611,26 +1611,26 @@ discard block |
||
1611 | 1611 | return $user; |
1612 | 1612 | } |
1613 | 1613 | |
1614 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1614 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1615 | 1615 | global $wpi_session; |
1616 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1616 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1617 | 1617 | } |
1618 | 1618 | |
1619 | 1619 | function wpinv_get_checkout_session() { |
1620 | 1620 | global $wpi_session; |
1621 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1621 | + return $wpi_session->get('wpinv_checkout'); |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | 1624 | function wpinv_empty_cart() { |
1625 | 1625 | global $wpi_session; |
1626 | 1626 | |
1627 | 1627 | // Remove cart contents |
1628 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1628 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1629 | 1629 | |
1630 | 1630 | // Remove all cart fees |
1631 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1631 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1632 | 1632 | |
1633 | - do_action( 'wpinv_empty_cart' ); |
|
1633 | + do_action('wpinv_empty_cart'); |
|
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | function wpinv_process_checkout() { |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | wpinv_clear_errors(); |
1640 | 1640 | |
1641 | 1641 | $invoice = wpinv_get_invoice_cart(); |
1642 | - if ( empty( $invoice ) ) { |
|
1642 | + if (empty($invoice)) { |
|
1643 | 1643 | return false; |
1644 | 1644 | } |
1645 | 1645 | |
@@ -1647,42 +1647,42 @@ discard block |
||
1647 | 1647 | |
1648 | 1648 | $wpi_checkout_id = $invoice->ID; |
1649 | 1649 | |
1650 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1650 | + do_action('wpinv_pre_process_checkout'); |
|
1651 | 1651 | |
1652 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1652 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1653 | 1653 | $valid_data = false; |
1654 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1654 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1655 | 1655 | } else { |
1656 | 1656 | // Validate the form $_POST data |
1657 | 1657 | $valid_data = wpinv_validate_checkout_fields(); |
1658 | 1658 | |
1659 | 1659 | // Allow themes and plugins to hook to errors |
1660 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1660 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1661 | 1661 | } |
1662 | 1662 | |
1663 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1663 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1664 | 1664 | |
1665 | 1665 | // Validate the user |
1666 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1666 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1667 | 1667 | |
1668 | 1668 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1669 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1669 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1670 | 1670 | |
1671 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1672 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
1673 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1671 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1672 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
1673 | + do_action('wpinv_ajax_checkout_errors'); |
|
1674 | 1674 | die(); |
1675 | 1675 | } else { |
1676 | 1676 | return false; |
1677 | 1677 | } |
1678 | 1678 | } |
1679 | 1679 | |
1680 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
1680 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
1681 | 1681 | // Save address fields. |
1682 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1683 | - foreach ( $address_fields as $field ) { |
|
1684 | - if ( isset( $user[$field] ) ) { |
|
1685 | - $invoice->set( $field, $user[$field] ); |
|
1682 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1683 | + foreach ($address_fields as $field) { |
|
1684 | + if (isset($user[$field])) { |
|
1685 | + $invoice->set($field, $user[$field]); |
|
1686 | 1686 | } |
1687 | 1687 | |
1688 | 1688 | $invoice->save(); |
@@ -1690,16 +1690,16 @@ discard block |
||
1690 | 1690 | |
1691 | 1691 | $response['success'] = true; |
1692 | 1692 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1693 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1693 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1694 | 1694 | $response['data']['discount'] = $invoice->get_discount(); |
1695 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1695 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1696 | 1696 | $response['data']['tax'] = $invoice->get_tax(); |
1697 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1697 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1698 | 1698 | $response['data']['total'] = $invoice->get_total(); |
1699 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1700 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1699 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1700 | + $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false; |
|
1701 | 1701 | |
1702 | - wp_send_json( $response ); |
|
1702 | + wp_send_json($response); |
|
1703 | 1703 | } |
1704 | 1704 | |
1705 | 1705 | $user_info = array( |
@@ -1721,42 +1721,42 @@ discard block |
||
1721 | 1721 | |
1722 | 1722 | // Setup invoice information |
1723 | 1723 | $invoice_data = array( |
1724 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1724 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1725 | 1725 | 'items' => $cart_items, |
1726 | 1726 | 'cart_discounts' => $discounts, |
1727 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1728 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1729 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1730 | - 'tax' => wpinv_get_cart_tax( $cart_items, $invoice ), // Taxed amount |
|
1731 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1727 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1728 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1729 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1730 | + 'tax' => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount |
|
1731 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1732 | 1732 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1733 | 1733 | 'user_email' => $invoice->get_email(), |
1734 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1735 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1734 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1735 | + 'user_info' => stripslashes_deep($user_info), |
|
1736 | 1736 | 'post_data' => $_POST, |
1737 | 1737 | 'cart_details' => $cart_items, |
1738 | 1738 | 'gateway' => $valid_data['gateway'], |
1739 | 1739 | 'card_info' => $valid_data['cc_info'] |
1740 | 1740 | ); |
1741 | 1741 | |
1742 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1743 | - if ( is_array( $vat_info ) ) { |
|
1742 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1743 | + if (is_array($vat_info)) { |
|
1744 | 1744 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1745 | 1745 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1746 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1746 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1747 | 1747 | |
1748 | 1748 | // Add the VAT rate to each item in the cart |
1749 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1749 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1750 | 1750 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1751 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1751 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1752 | 1752 | } |
1753 | 1753 | } |
1754 | 1754 | |
1755 | 1755 | // Save vat fields. |
1756 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1757 | - foreach ( $address_fields as $field ) { |
|
1758 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1759 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1756 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1757 | + foreach ($address_fields as $field) { |
|
1758 | + if (isset($invoice_data['user_info'][$field])) { |
|
1759 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1760 | 1760 | } |
1761 | 1761 | } |
1762 | 1762 | $invoice->save(); |
@@ -1765,54 +1765,54 @@ discard block |
||
1765 | 1765 | $valid_data['user'] = $user; |
1766 | 1766 | |
1767 | 1767 | // Allow themes and plugins to hook before the gateway |
1768 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1768 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1769 | 1769 | |
1770 | 1770 | // If it is free, abort. |
1771 | - if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 == $invoice->get_recurring_details( 'total' ) ) ) { |
|
1771 | + if ($invoice->is_free() && (!$invoice->is_recurring() || 0 == $invoice->get_recurring_details('total'))) { |
|
1772 | 1772 | $invoice_data['gateway'] = 'manual'; |
1773 | 1773 | $_POST['wpi-gateway'] = 'manual'; |
1774 | 1774 | } |
1775 | 1775 | |
1776 | 1776 | // Allow the invoice data to be modified before it is sent to the gateway |
1777 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1777 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1778 | 1778 | |
1779 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
1779 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
1780 | 1780 | $mode = 'test'; |
1781 | 1781 | } else { |
1782 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
1782 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
1783 | 1783 | } |
1784 | 1784 | |
1785 | 1785 | // Setup the data we're storing in the purchase session |
1786 | 1786 | $session_data = $invoice_data; |
1787 | 1787 | // Make sure credit card numbers are never stored in sessions |
1788 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1789 | - unset( $session_data['card_info']['card_number'] ); |
|
1788 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1789 | + unset($session_data['card_info']['card_number']); |
|
1790 | 1790 | } |
1791 | 1791 | |
1792 | 1792 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1793 | - wpinv_set_checkout_session( $invoice_data ); |
|
1793 | + wpinv_set_checkout_session($invoice_data); |
|
1794 | 1794 | |
1795 | 1795 | // Set gateway |
1796 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1797 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
1798 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
1796 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1797 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
1798 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
1799 | 1799 | |
1800 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1800 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1801 | 1801 | |
1802 | 1802 | // Send info to the gateway for payment processing |
1803 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1803 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1804 | 1804 | die(); |
1805 | 1805 | } |
1806 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1806 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1807 | 1807 | |
1808 | -function wpinv_get_invoices( $args ) { |
|
1809 | - $args = wp_parse_args( $args, array( |
|
1810 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1808 | +function wpinv_get_invoices($args) { |
|
1809 | + $args = wp_parse_args($args, array( |
|
1810 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1811 | 1811 | 'type' => 'wpi_invoice', |
1812 | 1812 | 'parent' => null, |
1813 | 1813 | 'user' => null, |
1814 | 1814 | 'email' => '', |
1815 | - 'limit' => get_option( 'posts_per_page' ), |
|
1815 | + 'limit' => get_option('posts_per_page'), |
|
1816 | 1816 | 'offset' => null, |
1817 | 1817 | 'page' => 1, |
1818 | 1818 | 'exclude' => array(), |
@@ -1820,7 +1820,7 @@ discard block |
||
1820 | 1820 | 'order' => 'DESC', |
1821 | 1821 | 'return' => 'objects', |
1822 | 1822 | 'paginate' => false, |
1823 | - ) ); |
|
1823 | + )); |
|
1824 | 1824 | |
1825 | 1825 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1826 | 1826 | $map_legacy = array( |
@@ -1833,18 +1833,18 @@ discard block |
||
1833 | 1833 | 'paged' => 'page', |
1834 | 1834 | ); |
1835 | 1835 | |
1836 | - foreach ( $map_legacy as $from => $to ) { |
|
1837 | - if ( isset( $args[ $from ] ) ) { |
|
1838 | - $args[ $to ] = $args[ $from ]; |
|
1836 | + foreach ($map_legacy as $from => $to) { |
|
1837 | + if (isset($args[$from])) { |
|
1838 | + $args[$to] = $args[$from]; |
|
1839 | 1839 | } |
1840 | 1840 | } |
1841 | 1841 | |
1842 | - if ( get_query_var( 'paged' ) ) |
|
1842 | + if (get_query_var('paged')) |
|
1843 | 1843 | $args['page'] = get_query_var('paged'); |
1844 | - else if ( get_query_var( 'page' ) ) |
|
1845 | - $args['page'] = get_query_var( 'page' ); |
|
1846 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1847 | - $args['page'] = $args[ 'page' ]; |
|
1844 | + else if (get_query_var('page')) |
|
1845 | + $args['page'] = get_query_var('page'); |
|
1846 | + else if (!empty($args['page'])) |
|
1847 | + $args['page'] = $args['page']; |
|
1848 | 1848 | else |
1849 | 1849 | $args['page'] = 1; |
1850 | 1850 | |
@@ -1857,48 +1857,48 @@ discard block |
||
1857 | 1857 | 'post_status' => $args['status'], |
1858 | 1858 | 'posts_per_page' => $args['limit'], |
1859 | 1859 | 'meta_query' => array(), |
1860 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1860 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1861 | 1861 | 'fields' => 'ids', |
1862 | 1862 | 'orderby' => $args['orderby'], |
1863 | 1863 | 'order' => $args['order'], |
1864 | 1864 | ); |
1865 | 1865 | |
1866 | - if ( !empty( $args['user'] ) ) { |
|
1867 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1866 | + if (!empty($args['user'])) { |
|
1867 | + $wp_query_args['author'] = absint($args['user']); |
|
1868 | 1868 | } |
1869 | 1869 | |
1870 | - if ( ! is_null( $args['parent'] ) ) { |
|
1871 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1870 | + if (!is_null($args['parent'])) { |
|
1871 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1872 | 1872 | } |
1873 | 1873 | |
1874 | - if ( ! is_null( $args['offset'] ) ) { |
|
1875 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1874 | + if (!is_null($args['offset'])) { |
|
1875 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1876 | 1876 | } else { |
1877 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1877 | + $wp_query_args['paged'] = absint($args['page']); |
|
1878 | 1878 | } |
1879 | 1879 | |
1880 | - if ( ! empty( $args['exclude'] ) ) { |
|
1881 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1880 | + if (!empty($args['exclude'])) { |
|
1881 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1882 | 1882 | } |
1883 | 1883 | |
1884 | - if ( ! $args['paginate' ] ) { |
|
1884 | + if (!$args['paginate']) { |
|
1885 | 1885 | $wp_query_args['no_found_rows'] = true; |
1886 | 1886 | } |
1887 | 1887 | |
1888 | 1888 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
1889 | 1889 | |
1890 | 1890 | // Get results. |
1891 | - $invoices = new WP_Query( $wp_query_args ); |
|
1891 | + $invoices = new WP_Query($wp_query_args); |
|
1892 | 1892 | |
1893 | - if ( 'objects' === $args['return'] ) { |
|
1894 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1895 | - } elseif ( 'self' === $args['return'] ) { |
|
1893 | + if ('objects' === $args['return']) { |
|
1894 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1895 | + } elseif ('self' === $args['return']) { |
|
1896 | 1896 | return $invoices; |
1897 | 1897 | } else { |
1898 | 1898 | $return = $invoices->posts; |
1899 | 1899 | } |
1900 | 1900 | |
1901 | - if ( $args['paginate' ] ) { |
|
1901 | + if ($args['paginate']) { |
|
1902 | 1902 | return (object) array( |
1903 | 1903 | 'invoices' => $return, |
1904 | 1904 | 'total' => $invoices->found_posts, |
@@ -1911,22 +1911,22 @@ discard block |
||
1911 | 1911 | |
1912 | 1912 | function wpinv_get_user_invoices_columns() { |
1913 | 1913 | $columns = array( |
1914 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1915 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1916 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1917 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1918 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1919 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1914 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1915 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
1916 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
1917 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1918 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1919 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1920 | 1920 | ); |
1921 | 1921 | |
1922 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1922 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1923 | 1923 | } |
1924 | 1924 | |
1925 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1925 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1926 | 1926 | global $wpinv_receipt_args; |
1927 | 1927 | |
1928 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1929 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1928 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1929 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1930 | 1930 | 'price' => true, |
1931 | 1931 | 'discount' => true, |
1932 | 1932 | 'items' => true, |
@@ -1935,45 +1935,45 @@ discard block |
||
1935 | 1935 | 'invoice_key' => false, |
1936 | 1936 | 'payment_method' => true, |
1937 | 1937 | 'invoice_id' => true |
1938 | - ), $atts, 'wpinv_receipt' ); |
|
1938 | + ), $atts, 'wpinv_receipt'); |
|
1939 | 1939 | |
1940 | 1940 | // Find the invoice. |
1941 | 1941 | $session = wpinv_get_checkout_session(); |
1942 | 1942 | |
1943 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1944 | - $invoice_id = wpinv_get_invoice_id_by_key( urldecode( $_GET['invoice_key'] ) ); |
|
1945 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1943 | + if (isset($_GET['invoice_key'])) { |
|
1944 | + $invoice_id = wpinv_get_invoice_id_by_key(urldecode($_GET['invoice_key'])); |
|
1945 | + } else if (isset($_GET['invoice-id'])) { |
|
1946 | 1946 | $invoice_id = (int) $_GET['invoice-id']; |
1947 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1948 | - $invoice_id = wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
1949 | - } else if ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1950 | - $invoice_id = wpinv_get_invoice_id_by_key( $wpinv_receipt_args['invoice_key'] ); |
|
1947 | + } else if ($session && isset($session['invoice_key'])) { |
|
1948 | + $invoice_id = wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
1949 | + } else if (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1950 | + $invoice_id = wpinv_get_invoice_id_by_key($wpinv_receipt_args['invoice_key']); |
|
1951 | 1951 | } |
1952 | 1952 | |
1953 | 1953 | // Did we find the invoice? |
1954 | - if ( empty( $invoice_id ) || ! $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1955 | - return '<p class="alert alert-error">' . __( 'We could not find your invoice.', 'invoicing' ) . '</p>'; |
|
1954 | + if (empty($invoice_id) || !$invoice = wpinv_get_invoice($invoice_id)) { |
|
1955 | + return '<p class="alert alert-error">' . __('We could not find your invoice.', 'invoicing') . '</p>'; |
|
1956 | 1956 | } |
1957 | 1957 | |
1958 | 1958 | $invoice_key = $invoice->get_key(); |
1959 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1960 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1961 | - $user_can_view = $_GET['invoice-id'] == $invoice->ID; |
|
1959 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1960 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1961 | + $user_can_view = $_GET['invoice-id'] == $invoice->ID; |
|
1962 | 1962 | } |
1963 | 1963 | |
1964 | 1964 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1965 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1965 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1966 | 1966 | // login redirect |
1967 | - return '<p class="alert alert-error">' . __( 'You must be logged in to view this receipt', 'invoicing' ) . '</p>'; |
|
1967 | + return '<p class="alert alert-error">' . __('You must be logged in to view this receipt', 'invoicing') . '</p>'; |
|
1968 | 1968 | } |
1969 | 1969 | |
1970 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1970 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1971 | 1971 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1972 | 1972 | } |
1973 | 1973 | |
1974 | 1974 | ob_start(); |
1975 | 1975 | |
1976 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1976 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1977 | 1977 | |
1978 | 1978 | $display = ob_get_clean(); |
1979 | 1979 | |
@@ -1983,148 +1983,148 @@ discard block |
||
1983 | 1983 | /** |
1984 | 1984 | * Given an invoice key, this function returns the id. |
1985 | 1985 | */ |
1986 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1986 | +function wpinv_get_invoice_id_by_key($key) { |
|
1987 | 1987 | global $wpdb; |
1988 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1989 | - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
1988 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1989 | + return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key)); |
|
1990 | 1990 | } |
1991 | 1991 | |
1992 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1993 | - $return = current_user_can( 'manage_options' ); |
|
1992 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1993 | + $return = current_user_can('manage_options'); |
|
1994 | 1994 | |
1995 | - if ( empty( $invoice_key ) ) { |
|
1995 | + if (empty($invoice_key)) { |
|
1996 | 1996 | return false; |
1997 | 1997 | } |
1998 | 1998 | |
1999 | 1999 | global $wpinv_receipt_args; |
2000 | 2000 | |
2001 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
2002 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
2003 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
2001 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
2002 | + if (isset($_GET['invoice-id'])) { |
|
2003 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0; |
|
2004 | 2004 | } |
2005 | 2005 | |
2006 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
2006 | + if (empty($wpinv_receipt_args['id'])) { |
|
2007 | 2007 | return $return; |
2008 | 2008 | } |
2009 | 2009 | |
2010 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
2011 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
2010 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
2011 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
2012 | 2012 | return $return; |
2013 | 2013 | } |
2014 | 2014 | |
2015 | - if ( is_user_logged_in() ) { |
|
2016 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
2015 | + if (is_user_logged_in()) { |
|
2016 | + if ((int) $invoice->get_user_id() === (int) get_current_user_id()) { |
|
2017 | 2017 | $return = true; |
2018 | 2018 | } |
2019 | 2019 | } |
2020 | 2020 | |
2021 | 2021 | $session = wpinv_get_checkout_session(); |
2022 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
2023 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
2022 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
2023 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
2024 | 2024 | |
2025 | - if ( wpinv_require_login_to_checkout() ) { |
|
2025 | + if (wpinv_require_login_to_checkout()) { |
|
2026 | 2026 | $return = $return && $check_key == $invoice_key; |
2027 | 2027 | } else { |
2028 | 2028 | $return = $check_key == $invoice_key; |
2029 | 2029 | } |
2030 | 2030 | } |
2031 | 2031 | |
2032 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
2032 | + return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | function wpinv_pay_for_invoice() { |
2036 | 2036 | global $wpinv_euvat; |
2037 | 2037 | |
2038 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
2038 | + if (isset($_GET['invoice_key'])) { |
|
2039 | 2039 | $checkout_uri = wpinv_get_checkout_uri(); |
2040 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
2040 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
2041 | 2041 | |
2042 | - if ( empty( $invoice_key ) ) { |
|
2043 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
2044 | - wp_redirect( $checkout_uri ); |
|
2042 | + if (empty($invoice_key)) { |
|
2043 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
2044 | + wp_redirect($checkout_uri); |
|
2045 | 2045 | exit(); |
2046 | 2046 | } |
2047 | 2047 | |
2048 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
2048 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
2049 | 2049 | |
2050 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
2051 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
2052 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
2053 | - $invoice_id = (int)$_GET['invoice-id']; |
|
2054 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
2050 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2051 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
2052 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
2053 | + $invoice_id = (int) $_GET['invoice-id']; |
|
2054 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
2055 | 2055 | } |
2056 | 2056 | |
2057 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
2058 | - if ( $invoice->needs_payment() ) { |
|
2057 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
2058 | + if ($invoice->needs_payment()) { |
|
2059 | 2059 | $data = array(); |
2060 | 2060 | $data['invoice_id'] = $invoice_id; |
2061 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
2061 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
2062 | 2062 | |
2063 | - wpinv_set_checkout_session( $data ); |
|
2063 | + wpinv_set_checkout_session($data); |
|
2064 | 2064 | |
2065 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
2065 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
2066 | 2066 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
2067 | 2067 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
2068 | 2068 | |
2069 | - wpinv_recalculate_tax( true ); |
|
2069 | + wpinv_recalculate_tax(true); |
|
2070 | 2070 | } |
2071 | 2071 | |
2072 | 2072 | } else { |
2073 | 2073 | $checkout_uri = $invoice->get_view_url(); |
2074 | 2074 | } |
2075 | 2075 | } else { |
2076 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
2076 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
2077 | 2077 | |
2078 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
2078 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
2079 | 2079 | } |
2080 | 2080 | |
2081 | - if(wp_redirect( $checkout_uri )){ |
|
2081 | + if (wp_redirect($checkout_uri)) { |
|
2082 | 2082 | exit; |
2083 | 2083 | }; |
2084 | 2084 | wpinv_die(); |
2085 | 2085 | } |
2086 | 2086 | } |
2087 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
2087 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
2088 | 2088 | |
2089 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
2090 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
2091 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
2089 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
2090 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
2091 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
2092 | 2092 | $user_id = $invoice->get_user_id(); |
2093 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
2093 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
2094 | 2094 | |
2095 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
2096 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
2095 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
2096 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
2097 | 2097 | |
2098 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
2098 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
2099 | 2099 | exit(); |
2100 | 2100 | } |
2101 | 2101 | } |
2102 | 2102 | } |
2103 | 2103 | } |
2104 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
2104 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
2105 | 2105 | |
2106 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
2107 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
2106 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
2107 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
2108 | 2108 | |
2109 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
2109 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
2110 | 2110 | return false; |
2111 | 2111 | } |
2112 | 2112 | |
2113 | - if ( empty( $transaction_id ) ) { |
|
2113 | + if (empty($transaction_id)) { |
|
2114 | 2114 | $transaction_id = $invoice_id; |
2115 | 2115 | } |
2116 | 2116 | |
2117 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
2117 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
2118 | 2118 | |
2119 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
2119 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
2120 | 2120 | } |
2121 | 2121 | |
2122 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
2123 | - if ( empty( $status_display ) ) { |
|
2124 | - $status_display = wpinv_status_nicename( $status ); |
|
2122 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
2123 | + if (empty($status_display)) { |
|
2124 | + $status_display = wpinv_status_nicename($status); |
|
2125 | 2125 | } |
2126 | 2126 | |
2127 | - switch ( $status ) { |
|
2127 | + switch ($status) { |
|
2128 | 2128 | case 'publish' : |
2129 | 2129 | case 'wpi-renewal' : |
2130 | 2130 | $class = 'label-success'; |
@@ -2149,201 +2149,201 @@ discard block |
||
2149 | 2149 | |
2150 | 2150 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
2151 | 2151 | |
2152 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
2152 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
2153 | 2153 | } |
2154 | 2154 | |
2155 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
2156 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
2157 | - if ( null !== $check ) { |
|
2155 | +function wpinv_format_invoice_number($number, $type = '') { |
|
2156 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
2157 | + if (null !== $check) { |
|
2158 | 2158 | return $check; |
2159 | 2159 | } |
2160 | 2160 | |
2161 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
2161 | + if (!empty($number) && !is_numeric($number)) { |
|
2162 | 2162 | return $number; |
2163 | 2163 | } |
2164 | 2164 | |
2165 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
2166 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2167 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2165 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
2166 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2167 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2168 | 2168 | |
2169 | - $padd = absint( $padd ); |
|
2170 | - $formatted_number = absint( $number ); |
|
2169 | + $padd = absint($padd); |
|
2170 | + $formatted_number = absint($number); |
|
2171 | 2171 | |
2172 | - if ( $padd > 0 ) { |
|
2173 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
2172 | + if ($padd > 0) { |
|
2173 | + $formatted_number = zeroise($formatted_number, $padd); |
|
2174 | 2174 | } |
2175 | 2175 | |
2176 | 2176 | $formatted_number = $prefix . $formatted_number . $postfix; |
2177 | 2177 | |
2178 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
2178 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
2179 | 2179 | } |
2180 | 2180 | |
2181 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
2182 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
2183 | - if ( null !== $check ) { |
|
2181 | +function wpinv_get_next_invoice_number($type = '') { |
|
2182 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
2183 | + if (null !== $check) { |
|
2184 | 2184 | return $check; |
2185 | 2185 | } |
2186 | 2186 | |
2187 | - if ( !wpinv_sequential_number_active() ) { |
|
2187 | + if (!wpinv_sequential_number_active()) { |
|
2188 | 2188 | return false; |
2189 | 2189 | } |
2190 | 2190 | |
2191 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
2192 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
2193 | - if ( !absint( $start ) > 0 ) { |
|
2191 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
2192 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
2193 | + if (!absint($start) > 0) { |
|
2194 | 2194 | $start = 1; |
2195 | 2195 | } |
2196 | 2196 | $increment_number = true; |
2197 | 2197 | $save_number = false; |
2198 | 2198 | |
2199 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
2200 | - $number = wpinv_clean_invoice_number( $number ); |
|
2199 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
2200 | + $number = wpinv_clean_invoice_number($number); |
|
2201 | 2201 | } |
2202 | 2202 | |
2203 | - if ( empty( $number ) ) { |
|
2204 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
2205 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
2203 | + if (empty($number)) { |
|
2204 | + if (!($last_number === 0 || $last_number === '0')) { |
|
2205 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
2206 | 2206 | |
2207 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
2208 | - if ( is_numeric( $invoice_number ) ) { |
|
2207 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
2208 | + if (is_numeric($invoice_number)) { |
|
2209 | 2209 | $number = $invoice_number; |
2210 | 2210 | } else { |
2211 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
2211 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
2212 | 2212 | } |
2213 | 2213 | } |
2214 | 2214 | |
2215 | - if ( empty( $number ) ) { |
|
2215 | + if (empty($number)) { |
|
2216 | 2216 | $increment_number = false; |
2217 | 2217 | $number = $start; |
2218 | - $save_number = ( $number - 1 ); |
|
2218 | + $save_number = ($number - 1); |
|
2219 | 2219 | } else { |
2220 | 2220 | $save_number = $number; |
2221 | 2221 | } |
2222 | 2222 | } |
2223 | 2223 | } |
2224 | 2224 | |
2225 | - if ( $start > $number ) { |
|
2225 | + if ($start > $number) { |
|
2226 | 2226 | $increment_number = false; |
2227 | 2227 | $number = $start; |
2228 | - $save_number = ( $number - 1 ); |
|
2228 | + $save_number = ($number - 1); |
|
2229 | 2229 | } |
2230 | 2230 | |
2231 | - if ( $save_number !== false ) { |
|
2232 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
2231 | + if ($save_number !== false) { |
|
2232 | + update_option('wpinv_last_invoice_number', $save_number); |
|
2233 | 2233 | } |
2234 | 2234 | |
2235 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
2235 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
2236 | 2236 | |
2237 | - if ( $increment_number ) { |
|
2237 | + if ($increment_number) { |
|
2238 | 2238 | $number++; |
2239 | 2239 | } |
2240 | 2240 | |
2241 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
2241 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
2242 | 2242 | } |
2243 | 2243 | |
2244 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
2245 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
2246 | - if ( null !== $check ) { |
|
2244 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
2245 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
2246 | + if (null !== $check) { |
|
2247 | 2247 | return $check; |
2248 | 2248 | } |
2249 | 2249 | |
2250 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2251 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2250 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2251 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2252 | 2252 | |
2253 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
2253 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
2254 | 2254 | |
2255 | - $length = strlen( $number ); |
|
2256 | - $postfix_pos = strrpos( $number, $postfix ); |
|
2255 | + $length = strlen($number); |
|
2256 | + $postfix_pos = strrpos($number, $postfix); |
|
2257 | 2257 | |
2258 | - if ( false !== $postfix_pos ) { |
|
2259 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
2258 | + if (false !== $postfix_pos) { |
|
2259 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
2260 | 2260 | } |
2261 | 2261 | |
2262 | - $number = intval( $number ); |
|
2262 | + $number = intval($number); |
|
2263 | 2263 | |
2264 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
2264 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
2265 | 2265 | } |
2266 | 2266 | |
2267 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
2267 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
2268 | 2268 | global $wpdb; |
2269 | 2269 | |
2270 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
2271 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
2270 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
2271 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
2272 | 2272 | } |
2273 | 2273 | |
2274 | - if ( !$update ) { |
|
2275 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
2276 | - clean_post_cache( $post_ID ); |
|
2274 | + if (!$update) { |
|
2275 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
2276 | + clean_post_cache($post_ID); |
|
2277 | 2277 | } |
2278 | 2278 | } |
2279 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
2279 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
2280 | 2280 | |
2281 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
2282 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
2283 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
2281 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
2282 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
2283 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
2284 | 2284 | } |
2285 | 2285 | } |
2286 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
2286 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
2287 | 2287 | |
2288 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
2288 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
2289 | 2289 | global $wpdb; |
2290 | 2290 | |
2291 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
2292 | - if ( null !== $check ) { |
|
2291 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
2292 | + if (null !== $check) { |
|
2293 | 2293 | return $check; |
2294 | 2294 | } |
2295 | 2295 | |
2296 | - if ( wpinv_sequential_number_active() ) { |
|
2296 | + if (wpinv_sequential_number_active()) { |
|
2297 | 2297 | $number = wpinv_get_next_invoice_number(); |
2298 | 2298 | |
2299 | - if ( $save_sequential ) { |
|
2300 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
2299 | + if ($save_sequential) { |
|
2300 | + update_option('wpinv_last_invoice_number', $number); |
|
2301 | 2301 | } |
2302 | 2302 | } else { |
2303 | 2303 | $number = $post_ID; |
2304 | 2304 | } |
2305 | 2305 | |
2306 | - $number = wpinv_format_invoice_number( $number ); |
|
2306 | + $number = wpinv_format_invoice_number($number); |
|
2307 | 2307 | |
2308 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
2308 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
2309 | 2309 | |
2310 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
2310 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
2311 | 2311 | |
2312 | - clean_post_cache( $post_ID ); |
|
2312 | + clean_post_cache($post_ID); |
|
2313 | 2313 | |
2314 | 2314 | return $number; |
2315 | 2315 | } |
2316 | 2316 | |
2317 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
2318 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
2317 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
2318 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
2319 | 2319 | } |
2320 | 2320 | |
2321 | -function wpinv_generate_post_name( $post_ID ) { |
|
2322 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
2323 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
2321 | +function wpinv_generate_post_name($post_ID) { |
|
2322 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
2323 | + $post_name = sanitize_title($prefix . $post_ID); |
|
2324 | 2324 | |
2325 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
2325 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
2326 | 2326 | } |
2327 | 2327 | |
2328 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
2329 | - if ( empty( $invoice_id ) ) { |
|
2328 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
2329 | + if (empty($invoice_id)) { |
|
2330 | 2330 | return false; |
2331 | 2331 | } |
2332 | 2332 | |
2333 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
2333 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
2334 | 2334 | |
2335 | - return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id ); |
|
2335 | + return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id); |
|
2336 | 2336 | } |
2337 | 2337 | |
2338 | 2338 | function wpinv_mark_invoice_viewed() { |
2339 | 2339 | |
2340 | - if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
|
2341 | - $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
|
2340 | + if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) { |
|
2341 | + $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : ''; |
|
2342 | 2342 | global $post; |
2343 | 2343 | |
2344 | - if(!empty($invoice_key)){ |
|
2344 | + if (!empty($invoice_key)) { |
|
2345 | 2345 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
2346 | - } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2346 | + } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2347 | 2347 | $invoice_id = $post->ID; |
2348 | 2348 | } else { |
2349 | 2349 | return; |
@@ -2351,73 +2351,73 @@ discard block |
||
2351 | 2351 | |
2352 | 2352 | $invoice = new WPInv_Invoice($invoice_id); |
2353 | 2353 | |
2354 | - if(!$invoice_id){ |
|
2354 | + if (!$invoice_id) { |
|
2355 | 2355 | return; |
2356 | 2356 | } |
2357 | 2357 | |
2358 | - if ( is_user_logged_in() ) { |
|
2359 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2360 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2361 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2362 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2358 | + if (is_user_logged_in()) { |
|
2359 | + if ((int) $invoice->get_user_id() === get_current_user_id()) { |
|
2360 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2361 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2362 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2363 | 2363 | } |
2364 | 2364 | } else { |
2365 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2366 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2365 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2366 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2367 | 2367 | } |
2368 | 2368 | } |
2369 | 2369 | } |
2370 | 2370 | |
2371 | 2371 | } |
2372 | -add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' ); |
|
2372 | +add_action('template_redirect', 'wpinv_mark_invoice_viewed'); |
|
2373 | 2373 | |
2374 | 2374 | /** |
2375 | 2375 | * Fetch a subscription given an invoice. |
2376 | 2376 | * |
2377 | 2377 | * @return WPInv_Subscription|bool |
2378 | 2378 | */ |
2379 | -function wpinv_get_subscription( $invoice ) { |
|
2379 | +function wpinv_get_subscription($invoice) { |
|
2380 | 2380 | |
2381 | 2381 | // Abort if we do not have an invoice. |
2382 | - if ( empty( $invoice ) ) { |
|
2382 | + if (empty($invoice)) { |
|
2383 | 2383 | return false; |
2384 | 2384 | } |
2385 | 2385 | |
2386 | 2386 | // Retrieve the invoice. |
2387 | - $invoice = new WPInv_Invoice( $invoice ); |
|
2387 | + $invoice = new WPInv_Invoice($invoice); |
|
2388 | 2388 | |
2389 | 2389 | // Ensure it is a recurring invoice. |
2390 | - if ( ! $invoice->is_recurring() ) { |
|
2390 | + if (!$invoice->is_recurring()) { |
|
2391 | 2391 | return false; |
2392 | 2392 | } |
2393 | 2393 | |
2394 | 2394 | // Fetch the subscription handler. |
2395 | - $subs_db = new WPInv_Subscriptions_DB(); |
|
2395 | + $subs_db = new WPInv_Subscriptions_DB(); |
|
2396 | 2396 | |
2397 | 2397 | // Fetch the parent in case it is a renewal. |
2398 | - if ( $invoice->is_renewal() ) { |
|
2399 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_parent_id(), 'number' => 1 ) ); |
|
2398 | + if ($invoice->is_renewal()) { |
|
2399 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_parent_id(), 'number' => 1)); |
|
2400 | 2400 | } else { |
2401 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_id(), 'number' => 1 ) ); |
|
2401 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_id(), 'number' => 1)); |
|
2402 | 2402 | } |
2403 | 2403 | |
2404 | 2404 | // Return the subscription if it exists. |
2405 | - if ( ! empty( $subs ) ) { |
|
2406 | - return reset( $subs ); |
|
2405 | + if (!empty($subs)) { |
|
2406 | + return reset($subs); |
|
2407 | 2407 | } |
2408 | 2408 | |
2409 | 2409 | return false; |
2410 | 2410 | } |
2411 | 2411 | |
2412 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
2412 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
2413 | 2413 | global $wpdb; |
2414 | 2414 | |
2415 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
2416 | - if ( !empty( $clauses['join'] ) ) { |
|
2415 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
2416 | + if (!empty($clauses['join'])) { |
|
2417 | 2417 | $clauses['join'] .= " "; |
2418 | 2418 | } |
2419 | 2419 | |
2420 | - if ( !empty( $clauses['fields'] ) ) { |
|
2420 | + if (!empty($clauses['fields'])) { |
|
2421 | 2421 | $clauses['fields'] .= ", "; |
2422 | 2422 | } |
2423 | 2423 | |
@@ -2428,7 +2428,7 @@ discard block |
||
2428 | 2428 | |
2429 | 2429 | return $clauses; |
2430 | 2430 | } |
2431 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
2431 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
2432 | 2432 | |
2433 | 2433 | /** |
2434 | 2434 | * Processes an invoice refund. |
@@ -2438,27 +2438,27 @@ discard block |
||
2438 | 2438 | * @param array $status_transition |
2439 | 2439 | * @todo: descrease customer/store earnings |
2440 | 2440 | */ |
2441 | -function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) { |
|
2441 | +function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) { |
|
2442 | 2442 | |
2443 | - if ( empty( $status_transition['from'] ) || ! $invoice->has_status( 'wpi-refunded' ) || in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
2443 | + if (empty($status_transition['from']) || !$invoice->has_status('wpi-refunded') || in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
2444 | 2444 | return; |
2445 | 2445 | } |
2446 | 2446 | |
2447 | 2447 | $discount_code = $invoice->get_discount_code(); |
2448 | - if ( ! empty( $discount_code ) ) { |
|
2449 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
2448 | + if (!empty($discount_code)) { |
|
2449 | + $discount = wpinv_get_discount_obj($discount_code); |
|
2450 | 2450 | |
2451 | - if ( $discount->exists() ) { |
|
2451 | + if ($discount->exists()) { |
|
2452 | 2452 | $discount->increase_usage( -1 ); |
2453 | 2453 | } |
2454 | 2454 | |
2455 | 2455 | } |
2456 | 2456 | |
2457 | - do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id ); |
|
2458 | - do_action( 'wpinv_refund_invoice', $invoice, $invoice_id ); |
|
2459 | - do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id ); |
|
2457 | + do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id); |
|
2458 | + do_action('wpinv_refund_invoice', $invoice, $invoice_id); |
|
2459 | + do_action('wpinv_post_refund_invoice', $invoice, $invoice_id); |
|
2460 | 2460 | } |
2461 | -add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 ); |
|
2461 | +add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3); |
|
2462 | 2462 | |
2463 | 2463 | /** |
2464 | 2464 | * Fires when a payment fails. |
@@ -2466,22 +2466,22 @@ discard block |
||
2466 | 2466 | * @param int $invoice_id |
2467 | 2467 | * @param WPInv_Invoice $invoice |
2468 | 2468 | */ |
2469 | -function getpaid_maybe_process_failure( $invoice_id, $invoice ) { |
|
2469 | +function getpaid_maybe_process_failure($invoice_id, $invoice) { |
|
2470 | 2470 | |
2471 | - if ( ! $invoice->has_status( 'wpi-failed' ) ) { |
|
2471 | + if (!$invoice->has_status('wpi-failed')) { |
|
2472 | 2472 | return; |
2473 | 2473 | } |
2474 | 2474 | |
2475 | 2475 | $discount_code = $invoice->get_discount_code(); |
2476 | - if ( ! empty( $discount_code ) ) { |
|
2477 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
2476 | + if (!empty($discount_code)) { |
|
2477 | + $discount = wpinv_get_discount_obj($discount_code); |
|
2478 | 2478 | |
2479 | - if ( $discount->exists() ) { |
|
2479 | + if ($discount->exists()) { |
|
2480 | 2480 | $discount->increase_usage( -1 ); |
2481 | 2481 | } |
2482 | 2482 | |
2483 | 2483 | } |
2484 | 2484 | |
2485 | - do_action( 'wpinv_invoice_payment_failed', $invoice, $invoice_id ); |
|
2485 | + do_action('wpinv_invoice_payment_failed', $invoice, $invoice_id); |
|
2486 | 2486 | } |
2487 | -add_action( 'getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2 ); |
|
2488 | 2487 | \ No newline at end of file |
2488 | +add_action('getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2); |
|
2489 | 2489 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Payment_Form_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -56,37 +56,37 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param GetPaid_Payment_Form $form Form object. |
58 | 58 | */ |
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
59 | + public function create(&$form) { |
|
60 | + $form->set_version(WPINV_VERSION); |
|
61 | + $form->set_date_created(current_time('mysql')); |
|
62 | 62 | |
63 | 63 | // Create a new post. |
64 | 64 | $id = wp_insert_post( |
65 | 65 | apply_filters( |
66 | 66 | 'getpaid_new_payment_form_data', |
67 | 67 | array( |
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
68 | + 'post_date' => $form->get_date_created('edit'), |
|
69 | 69 | 'post_type' => 'wpi_payment_form', |
70 | - 'post_status' => $this->get_post_status( $form ), |
|
70 | + 'post_status' => $this->get_post_status($form), |
|
71 | 71 | 'ping_status' => 'closed', |
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
72 | + 'post_author' => $form->get_author('edit'), |
|
73 | + 'post_title' => $form->get_name('edit'), |
|
74 | 74 | ) |
75 | 75 | ), |
76 | 76 | true |
77 | 77 | ); |
78 | 78 | |
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
79 | + if ($id && !is_wp_error($id)) { |
|
80 | + $form->set_id($id); |
|
81 | + $this->update_post_meta($form); |
|
82 | 82 | $form->save_meta_data(); |
83 | 83 | $form->apply_changes(); |
84 | - $this->clear_caches( $form ); |
|
85 | - do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
84 | + $this->clear_caches($form); |
|
85 | + do_action('getpaid_create_payment_form', $form->get_id(), $form); |
|
86 | 86 | return true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( is_wp_error( $id ) ) { |
|
89 | + if (is_wp_error($id)) { |
|
90 | 90 | $form->last_error = $id->get_error_message(); |
91 | 91 | } |
92 | 92 | |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * @param GetPaid_Payment_Form $form Form object. |
100 | 100 | * |
101 | 101 | */ |
102 | - public function read( &$form ) { |
|
102 | + public function read(&$form) { |
|
103 | 103 | |
104 | 104 | $form->set_defaults(); |
105 | - $form_object = get_post( $form->get_id() ); |
|
105 | + $form_object = get_post($form->get_id()); |
|
106 | 106 | |
107 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | - $form->set_id( 0 ); |
|
107 | + if (!$form->get_id() || !$form_object || $form_object->post_type != 'wpi_payment_form') { |
|
108 | + $form->last_error = __('Invalid form.', 'invoicing'); |
|
109 | + $form->set_id(0); |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | ) |
121 | 121 | ); |
122 | 122 | |
123 | - $this->read_object_data( $form, $form_object ); |
|
123 | + $this->read_object_data($form, $form_object); |
|
124 | 124 | $form->read_meta_data(); |
125 | - $form->set_object_read( true ); |
|
126 | - do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
125 | + $form->set_object_read(true); |
|
126 | + do_action('getpaid_read_payment_form', $form->get_id(), $form); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
@@ -132,27 +132,27 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param GetPaid_Payment_Form $form Form object. |
134 | 134 | */ |
135 | - public function update( &$form ) { |
|
135 | + public function update(&$form) { |
|
136 | 136 | $form->save_meta_data(); |
137 | - $form->set_version( WPINV_VERSION ); |
|
137 | + $form->set_version(WPINV_VERSION); |
|
138 | 138 | |
139 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | - $form->set_date_created( current_time('mysql') ); |
|
139 | + if (null === $form->get_date_created('edit')) { |
|
140 | + $form->set_date_created(current_time('mysql')); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | // Grab the current status so we can compare. |
144 | - $previous_status = get_post_status( $form->get_id() ); |
|
144 | + $previous_status = get_post_status($form->get_id()); |
|
145 | 145 | |
146 | 146 | $changes = $form->get_changes(); |
147 | 147 | |
148 | 148 | // Only update the post when the post data changes. |
149 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
149 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author'), array_keys($changes))) { |
|
150 | 150 | $post_data = array( |
151 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | - 'post_status' => $form->get_status( 'edit' ), |
|
153 | - 'post_title' => $form->get_name( 'edit' ), |
|
154 | - 'post_author' => $form->get_author( 'edit' ), |
|
155 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
151 | + 'post_date' => $form->get_date_created('edit'), |
|
152 | + 'post_status' => $form->get_status('edit'), |
|
153 | + 'post_title' => $form->get_name('edit'), |
|
154 | + 'post_author' => $form->get_author('edit'), |
|
155 | + 'post_modified' => $form->get_date_modified('edit'), |
|
156 | 156 | ); |
157 | 157 | |
158 | 158 | /** |
@@ -163,25 +163,25 @@ discard block |
||
163 | 163 | * This ensures hooks are fired by either WP itself (admin screen save), |
164 | 164 | * or an update purely from CRUD. |
165 | 165 | */ |
166 | - if ( doing_action( 'save_post' ) ) { |
|
167 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | - clean_post_cache( $form->get_id() ); |
|
166 | + if (doing_action('save_post')) { |
|
167 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $form->get_id())); |
|
168 | + clean_post_cache($form->get_id()); |
|
169 | 169 | } else { |
170 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
170 | + wp_update_post(array_merge(array('ID' => $form->get_id()), $post_data)); |
|
171 | 171 | } |
172 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
172 | + $form->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | 173 | } |
174 | - $this->update_post_meta( $form ); |
|
174 | + $this->update_post_meta($form); |
|
175 | 175 | $form->apply_changes(); |
176 | - $this->clear_caches( $form ); |
|
176 | + $this->clear_caches($form); |
|
177 | 177 | |
178 | 178 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
179 | - $new_status = $form->get_status( 'edit' ); |
|
179 | + $new_status = $form->get_status('edit'); |
|
180 | 180 | |
181 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | - do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
181 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
182 | + do_action('getpaid_new_payment_form', $form->get_id(), $form); |
|
183 | 183 | } else { |
184 | - do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
184 | + do_action('getpaid_update_payment_form', $form->get_id(), $form); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Discount_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -71,38 +71,38 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param WPInv_Discount $discount Discount object. |
73 | 73 | */ |
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
74 | + public function create(&$discount) { |
|
75 | + $discount->set_version(WPINV_VERSION); |
|
76 | + $discount->set_date_created(current_time('mysql')); |
|
77 | 77 | |
78 | 78 | // Create a new post. |
79 | 79 | $id = wp_insert_post( |
80 | 80 | apply_filters( |
81 | 81 | 'getpaid_new_discount_data', |
82 | 82 | array( |
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
83 | + 'post_date' => $discount->get_date_created('edit'), |
|
84 | 84 | 'post_type' => 'wpi_discount', |
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
85 | + 'post_status' => $this->get_post_status($discount), |
|
86 | 86 | 'ping_status' => 'closed', |
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
87 | + 'post_author' => $discount->get_author('edit'), |
|
88 | + 'post_title' => $discount->get_name('edit'), |
|
89 | + 'post_excerpt' => $discount->get_description('edit'), |
|
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | true |
93 | 93 | ); |
94 | 94 | |
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
95 | + if ($id && !is_wp_error($id)) { |
|
96 | + $discount->set_id($id); |
|
97 | + $this->update_post_meta($discount); |
|
98 | 98 | $discount->save_meta_data(); |
99 | 99 | $discount->apply_changes(); |
100 | - $this->clear_caches( $discount ); |
|
101 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
100 | + $this->clear_caches($discount); |
|
101 | + do_action('getpaid_new_discount', $discount->get_id(), $discount); |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_wp_error( $id ) ) { |
|
105 | + if (is_wp_error($id)) { |
|
106 | 106 | $discount->last_error = $id->get_error_message(); |
107 | 107 | } |
108 | 108 | |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * @param WPInv_Discount $discount Discount object. |
116 | 116 | * |
117 | 117 | */ |
118 | - public function read( &$discount ) { |
|
118 | + public function read(&$discount) { |
|
119 | 119 | |
120 | 120 | $discount->set_defaults(); |
121 | - $discount_object = get_post( $discount->get_id() ); |
|
121 | + $discount_object = get_post($discount->get_id()); |
|
122 | 122 | |
123 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | - $discount->set_id( 0 ); |
|
123 | + if (!$discount->get_id() || !$discount_object || $discount_object->post_type != 'wpi_discount') { |
|
124 | + $discount->last_error = __('Invalid discount.', 'invoicing'); |
|
125 | + $discount->set_id(0); |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | |
140 | - $this->read_object_data( $discount, $discount_object ); |
|
140 | + $this->read_object_data($discount, $discount_object); |
|
141 | 141 | $discount->read_meta_data(); |
142 | - $discount->set_object_read( true ); |
|
143 | - do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
142 | + $discount->set_object_read(true); |
|
143 | + do_action('getpaid_read_discount', $discount->get_id(), $discount); |
|
144 | 144 | |
145 | 145 | } |
146 | 146 | |
@@ -149,28 +149,28 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param WPInv_Discount $discount Discount object. |
151 | 151 | */ |
152 | - public function update( &$discount ) { |
|
152 | + public function update(&$discount) { |
|
153 | 153 | $discount->save_meta_data(); |
154 | - $discount->set_version( WPINV_VERSION ); |
|
154 | + $discount->set_version(WPINV_VERSION); |
|
155 | 155 | |
156 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | - $discount->set_date_created( current_time('mysql') ); |
|
156 | + if (null === $discount->get_date_created('edit')) { |
|
157 | + $discount->set_date_created(current_time('mysql')); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Grab the current status so we can compare. |
161 | - $previous_status = get_post_status( $discount->get_id() ); |
|
161 | + $previous_status = get_post_status($discount->get_id()); |
|
162 | 162 | |
163 | 163 | $changes = $discount->get_changes(); |
164 | 164 | |
165 | 165 | // Only update the post when the post data changes. |
166 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
166 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) { |
|
167 | 167 | $post_data = array( |
168 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | - 'post_status' => $discount->get_status( 'edit' ), |
|
170 | - 'post_title' => $discount->get_name( 'edit' ), |
|
171 | - 'post_author' => $discount->get_author( 'edit' ), |
|
172 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
168 | + 'post_date' => $discount->get_date_created('edit'), |
|
169 | + 'post_status' => $discount->get_status('edit'), |
|
170 | + 'post_title' => $discount->get_name('edit'), |
|
171 | + 'post_author' => $discount->get_author('edit'), |
|
172 | + 'post_modified' => $discount->get_date_modified('edit'), |
|
173 | + 'post_excerpt' => $discount->get_description('edit'), |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | /** |
@@ -181,25 +181,25 @@ discard block |
||
181 | 181 | * This ensures hooks are fired by either WP itself (admin screen save), |
182 | 182 | * or an update purely from CRUD. |
183 | 183 | */ |
184 | - if ( doing_action( 'save_post' ) ) { |
|
185 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | - clean_post_cache( $discount->get_id() ); |
|
184 | + if (doing_action('save_post')) { |
|
185 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id())); |
|
186 | + clean_post_cache($discount->get_id()); |
|
187 | 187 | } else { |
188 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
188 | + wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data)); |
|
189 | 189 | } |
190 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
190 | + $discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | 191 | } |
192 | - $this->update_post_meta( $discount ); |
|
192 | + $this->update_post_meta($discount); |
|
193 | 193 | $discount->apply_changes(); |
194 | - $this->clear_caches( $discount ); |
|
194 | + $this->clear_caches($discount); |
|
195 | 195 | |
196 | 196 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
197 | - $new_status = $discount->get_status( 'edit' ); |
|
197 | + $new_status = $discount->get_status('edit'); |
|
198 | 198 | |
199 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
199 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
200 | + do_action('getpaid_new_discount', $discount->get_id(), $discount); |
|
201 | 201 | } else { |
202 | - do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
202 | + do_action('getpaid_update_discount', $discount->get_id(), $discount); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if (!defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
119 | 119 | */ |
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
120 | + public function __construct($read = 0) { |
|
121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
122 | 122 | $this->default_data = $this->data; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array |
129 | 129 | */ |
130 | 130 | public function __sleep() { |
131 | - return array( 'id' ); |
|
131 | + return array('id'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function __wakeup() { |
140 | 140 | try { |
141 | - $this->__construct( absint( $this->id ) ); |
|
142 | - } catch ( Exception $e ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - $this->set_object_read( true ); |
|
141 | + $this->__construct(absint($this->id)); |
|
142 | + } catch (Exception $e) { |
|
143 | + $this->set_id(0); |
|
144 | + $this->set_object_read(true); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __clone() { |
154 | 154 | $this->maybe_read_meta_data(); |
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
155 | + if (!empty($this->meta_data)) { |
|
156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
157 | + $this->meta_data[$array_key] = clone $meta; |
|
158 | + if (!empty($meta->id)) { |
|
159 | + $this->meta_data[$array_key]->id = null; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
202 | + public function get_status($context = 'view') { |
|
203 | + return $this->get_prop('status', $context); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
211 | 211 | * @return bool result |
212 | 212 | */ |
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
213 | + public function delete($force_delete = false) { |
|
214 | + if ($this->data_store) { |
|
215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
216 | + $this->set_id(0); |
|
217 | 217 | return true; |
218 | 218 | } |
219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return int |
227 | 227 | */ |
228 | 228 | public function save() { |
229 | - if ( ! $this->data_store ) { |
|
229 | + if (!$this->data_store) { |
|
230 | 230 | return $this->get_id(); |
231 | 231 | } |
232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | * @param GetPaid_Data $this The object being saved. |
237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
238 | 238 | */ |
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
240 | 240 | |
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
241 | + if ($this->get_id()) { |
|
242 | + $this->data_store->update($this); |
|
243 | 243 | } else { |
244 | - $this->data_store->create( $this ); |
|
244 | + $this->data_store->create($this); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param GetPaid_Data $this The object being saved. |
251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
252 | 252 | */ |
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
254 | 254 | |
255 | 255 | return $this->get_id(); |
256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @return string Data in JSON format. |
263 | 263 | */ |
264 | 264 | public function __toString() { |
265 | - return wp_json_encode( $this->get_data() ); |
|
265 | + return wp_json_encode($this->get_data()); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return array |
273 | 273 | */ |
274 | 274 | public function get_data() { |
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | public function get_data_keys() { |
285 | - return array_keys( $this->data ); |
|
285 | + return array_keys($this->data); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | public function get_extra_data_keys() { |
295 | - return array_keys( $this->extra_data ); |
|
295 | + return array_keys($this->extra_data); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param mixed $meta Meta value to check. |
303 | 303 | * @return bool |
304 | 304 | */ |
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
305 | + protected function filter_null_meta($meta) { |
|
306 | + return !is_null($meta->value); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function get_meta_data() { |
316 | 316 | $this->maybe_read_meta_data(); |
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
324 | 324 | * @param string $key Key to check. |
325 | 325 | * @return bool true if it's an internal key, false otherwise |
326 | 326 | */ |
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
327 | + protected function is_internal_meta_key($key) { |
|
328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
329 | 329 | |
330 | - if ( ! $internal_meta_key ) { |
|
330 | + if (!$internal_meta_key) { |
|
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
335 | 335 | |
336 | - if ( ! $has_setter_or_getter ) { |
|
336 | + if (!$has_setter_or_getter) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | 340 | /* translators: %s: $key Key to check */ |
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
342 | 342 | |
343 | 343 | return true; |
344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | * @access public |
353 | 353 | * |
354 | 354 | */ |
355 | - public function __set( $key, $value ) { |
|
355 | + public function __set($key, $value) { |
|
356 | 356 | |
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
357 | + if ('id' == strtolower($key)) { |
|
358 | + return $this->set_id($value); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( method_exists( $this, "set_$key") ) { |
|
361 | + if (method_exists($this, "set_$key")) { |
|
362 | 362 | |
363 | 363 | /* translators: %s: $key Key to set */ |
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
364 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
365 | 365 | |
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
366 | + call_user_func(array($this, "set_$key"), $value); |
|
367 | 367 | } else { |
368 | - $this->set_prop( $key, $value ); |
|
368 | + $this->set_prop($key, $value); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | } |
@@ -373,25 +373,25 @@ discard block |
||
373 | 373 | /** |
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | - public function __get( $key ) { |
|
376 | + public function __get($key) { |
|
377 | 377 | |
378 | 378 | // Check if we have a helper method for that. |
379 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
379 | + if (method_exists($this, 'get_' . $key)) { |
|
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
381 | + if ('post_type' != $key) { |
|
382 | 382 | /* translators: %s: $key Key to set */ |
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
383 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
384 | 384 | } |
385 | 385 | |
386 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
386 | + return call_user_func(array($this, 'get_' . $key)); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | // Check if the key is in the associated $post object. |
390 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
390 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
394 | + return $this->get_prop($key); |
|
395 | 395 | |
396 | 396 | } |
397 | 397 | |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | * @param string $context What the value is for. Valid values are view and edit. |
405 | 405 | * @return mixed |
406 | 406 | */ |
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
407 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
408 | 408 | |
409 | 409 | // Check if this is an internal meta key. |
410 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
410 | + if ($this->is_internal_meta_key($key)) { |
|
411 | 411 | $function = 'get_' . $key; |
412 | 412 | |
413 | - if ( is_callable( array( $this, $function ) ) ) { |
|
413 | + if (is_callable(array($this, $function))) { |
|
414 | 414 | return $this->{$function}(); |
415 | 415 | } |
416 | 416 | } |
@@ -418,20 +418,20 @@ discard block |
||
418 | 418 | // Read the meta data if not yet read. |
419 | 419 | $this->maybe_read_meta_data(); |
420 | 420 | $meta_data = $this->get_meta_data(); |
421 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
421 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
422 | 422 | $value = $single ? '' : array(); |
423 | 423 | |
424 | - if ( ! empty( $array_keys ) ) { |
|
424 | + if (!empty($array_keys)) { |
|
425 | 425 | // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
426 | - if ( $single ) { |
|
427 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
426 | + if ($single) { |
|
427 | + $value = $meta_data[current($array_keys)]->value; |
|
428 | 428 | } else { |
429 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
429 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - if ( 'view' === $context ) { |
|
434 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
433 | + if ('view' === $context) { |
|
434 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | return $value; |
@@ -444,10 +444,10 @@ discard block |
||
444 | 444 | * @param string $key Meta Key. |
445 | 445 | * @return boolean |
446 | 446 | */ |
447 | - public function meta_exists( $key = '' ) { |
|
447 | + public function meta_exists($key = '') { |
|
448 | 448 | $this->maybe_read_meta_data(); |
449 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
450 | - return in_array( $key, $array_keys, true ); |
|
449 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
450 | + return in_array($key, $array_keys, true); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -456,12 +456,12 @@ discard block |
||
456 | 456 | * @since 1.0.19 |
457 | 457 | * @param array $data Key/Value pairs. |
458 | 458 | */ |
459 | - public function set_meta_data( $data ) { |
|
460 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
459 | + public function set_meta_data($data) { |
|
460 | + if (!empty($data) && is_array($data)) { |
|
461 | 461 | $this->maybe_read_meta_data(); |
462 | - foreach ( $data as $meta ) { |
|
462 | + foreach ($data as $meta) { |
|
463 | 463 | $meta = (array) $meta; |
464 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
464 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
465 | 465 | $this->meta_data[] = new GetPaid_Meta_Data( |
466 | 466 | array( |
467 | 467 | 'id' => $meta['id'], |
@@ -483,18 +483,18 @@ discard block |
||
483 | 483 | * @param string|array $value Meta value. |
484 | 484 | * @param bool $unique Should this be a unique key?. |
485 | 485 | */ |
486 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
487 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
486 | + public function add_meta_data($key, $value, $unique = false) { |
|
487 | + if ($this->is_internal_meta_key($key)) { |
|
488 | 488 | $function = 'set_' . $key; |
489 | 489 | |
490 | - if ( is_callable( array( $this, $function ) ) ) { |
|
491 | - return $this->{$function}( $value ); |
|
490 | + if (is_callable(array($this, $function))) { |
|
491 | + return $this->{$function}($value); |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
495 | 495 | $this->maybe_read_meta_data(); |
496 | - if ( $unique ) { |
|
497 | - $this->delete_meta_data( $key ); |
|
496 | + if ($unique) { |
|
497 | + $this->delete_meta_data($key); |
|
498 | 498 | } |
499 | 499 | $this->meta_data[] = new GetPaid_Meta_Data( |
500 | 500 | array( |
@@ -513,12 +513,12 @@ discard block |
||
513 | 513 | * @param string|array $value Meta value. |
514 | 514 | * @param int $meta_id Meta ID. |
515 | 515 | */ |
516 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
517 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
516 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
517 | + if ($this->is_internal_meta_key($key)) { |
|
518 | 518 | $function = 'set_' . $key; |
519 | 519 | |
520 | - if ( is_callable( array( $this, $function ) ) ) { |
|
521 | - return $this->{$function}( $value ); |
|
520 | + if (is_callable(array($this, $function))) { |
|
521 | + return $this->{$function}($value); |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
@@ -526,33 +526,33 @@ discard block |
||
526 | 526 | |
527 | 527 | $array_key = false; |
528 | 528 | |
529 | - if ( $meta_id ) { |
|
530 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
531 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
529 | + if ($meta_id) { |
|
530 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
531 | + $array_key = $array_keys ? current($array_keys) : false; |
|
532 | 532 | } else { |
533 | 533 | // Find matches by key. |
534 | 534 | $matches = array(); |
535 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
536 | - if ( $meta->key === $key ) { |
|
535 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
536 | + if ($meta->key === $key) { |
|
537 | 537 | $matches[] = $meta_data_array_key; |
538 | 538 | } |
539 | 539 | } |
540 | 540 | |
541 | - if ( ! empty( $matches ) ) { |
|
541 | + if (!empty($matches)) { |
|
542 | 542 | // Set matches to null so only one key gets the new value. |
543 | - foreach ( $matches as $meta_data_array_key ) { |
|
544 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
543 | + foreach ($matches as $meta_data_array_key) { |
|
544 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
545 | 545 | } |
546 | - $array_key = current( $matches ); |
|
546 | + $array_key = current($matches); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | |
550 | - if ( false !== $array_key ) { |
|
551 | - $meta = $this->meta_data[ $array_key ]; |
|
550 | + if (false !== $array_key) { |
|
551 | + $meta = $this->meta_data[$array_key]; |
|
552 | 552 | $meta->key = $key; |
553 | 553 | $meta->value = $value; |
554 | 554 | } else { |
555 | - $this->add_meta_data( $key, $value, true ); |
|
555 | + $this->add_meta_data($key, $value, true); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
@@ -562,13 +562,13 @@ discard block |
||
562 | 562 | * @since 1.0.19 |
563 | 563 | * @param string $key Meta key. |
564 | 564 | */ |
565 | - public function delete_meta_data( $key ) { |
|
565 | + public function delete_meta_data($key) { |
|
566 | 566 | $this->maybe_read_meta_data(); |
567 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
567 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
568 | 568 | |
569 | - if ( $array_keys ) { |
|
570 | - foreach ( $array_keys as $array_key ) { |
|
571 | - $this->meta_data[ $array_key ]->value = null; |
|
569 | + if ($array_keys) { |
|
570 | + foreach ($array_keys as $array_key) { |
|
571 | + $this->meta_data[$array_key]->value = null; |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | } |
@@ -579,13 +579,13 @@ discard block |
||
579 | 579 | * @since 1.0.19 |
580 | 580 | * @param int $mid Meta ID. |
581 | 581 | */ |
582 | - public function delete_meta_data_by_mid( $mid ) { |
|
582 | + public function delete_meta_data_by_mid($mid) { |
|
583 | 583 | $this->maybe_read_meta_data(); |
584 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
584 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
585 | 585 | |
586 | - if ( $array_keys ) { |
|
587 | - foreach ( $array_keys as $array_key ) { |
|
588 | - $this->meta_data[ $array_key ]->value = null; |
|
586 | + if ($array_keys) { |
|
587 | + foreach ($array_keys as $array_key) { |
|
588 | + $this->meta_data[$array_key]->value = null; |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | } |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @since 1.0.19 |
597 | 597 | */ |
598 | 598 | protected function maybe_read_meta_data() { |
599 | - if ( is_null( $this->meta_data ) ) { |
|
599 | + if (is_null($this->meta_data)) { |
|
600 | 600 | $this->read_meta_data(); |
601 | 601 | } |
602 | 602 | } |
@@ -608,43 +608,43 @@ discard block |
||
608 | 608 | * @since 1.0.19 |
609 | 609 | * @param bool $force_read True to force a new DB read (and update cache). |
610 | 610 | */ |
611 | - public function read_meta_data( $force_read = false ) { |
|
611 | + public function read_meta_data($force_read = false) { |
|
612 | 612 | $this->meta_data = array(); |
613 | 613 | $cache_loaded = false; |
614 | 614 | |
615 | - if ( ! $this->get_id() ) { |
|
615 | + if (!$this->get_id()) { |
|
616 | 616 | return; |
617 | 617 | } |
618 | 618 | |
619 | - if ( ! $this->data_store ) { |
|
619 | + if (!$this->data_store) { |
|
620 | 620 | return; |
621 | 621 | } |
622 | 622 | |
623 | - if ( ! empty( $this->cache_group ) ) { |
|
624 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
623 | + if (!empty($this->cache_group)) { |
|
624 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
625 | 625 | } |
626 | 626 | |
627 | - if ( ! $force_read ) { |
|
628 | - if ( ! empty( $this->cache_group ) ) { |
|
629 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - $cache_loaded = ! empty( $cached_meta ); |
|
627 | + if (!$force_read) { |
|
628 | + if (!empty($this->cache_group)) { |
|
629 | + $cached_meta = wp_cache_get($cache_key, $this->cache_group); |
|
630 | + $cache_loaded = !empty($cached_meta); |
|
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
634 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
635 | - if ( $raw_meta_data ) { |
|
636 | - foreach ( $raw_meta_data as $meta ) { |
|
634 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this); |
|
635 | + if ($raw_meta_data) { |
|
636 | + foreach ($raw_meta_data as $meta) { |
|
637 | 637 | $this->meta_data[] = new GetPaid_Meta_Data( |
638 | 638 | array( |
639 | 639 | 'id' => (int) $meta->meta_id, |
640 | 640 | 'key' => $meta->meta_key, |
641 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
641 | + 'value' => maybe_unserialize($meta->meta_value), |
|
642 | 642 | ) |
643 | 643 | ); |
644 | 644 | } |
645 | 645 | |
646 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
647 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
646 | + if (!$cache_loaded && !empty($this->cache_group)) { |
|
647 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 | } |
@@ -655,28 +655,28 @@ discard block |
||
655 | 655 | * @since 1.0.19 |
656 | 656 | */ |
657 | 657 | public function save_meta_data() { |
658 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
658 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
659 | 659 | return; |
660 | 660 | } |
661 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
662 | - if ( is_null( $meta->value ) ) { |
|
663 | - if ( ! empty( $meta->id ) ) { |
|
664 | - $this->data_store->delete_meta( $this, $meta ); |
|
665 | - unset( $this->meta_data[ $array_key ] ); |
|
661 | + foreach ($this->meta_data as $array_key => $meta) { |
|
662 | + if (is_null($meta->value)) { |
|
663 | + if (!empty($meta->id)) { |
|
664 | + $this->data_store->delete_meta($this, $meta); |
|
665 | + unset($this->meta_data[$array_key]); |
|
666 | 666 | } |
667 | - } elseif ( empty( $meta->id ) ) { |
|
668 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
667 | + } elseif (empty($meta->id)) { |
|
668 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
669 | 669 | $meta->apply_changes(); |
670 | 670 | } else { |
671 | - if ( $meta->get_changes() ) { |
|
672 | - $this->data_store->update_meta( $this, $meta ); |
|
671 | + if ($meta->get_changes()) { |
|
672 | + $this->data_store->update_meta($this, $meta); |
|
673 | 673 | $meta->apply_changes(); |
674 | 674 | } |
675 | 675 | } |
676 | 676 | } |
677 | - if ( ! empty( $this->cache_group ) ) { |
|
678 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
679 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
677 | + if (!empty($this->cache_group)) { |
|
678 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
679 | + wp_cache_delete($cache_key, $this->cache_group); |
|
680 | 680 | } |
681 | 681 | } |
682 | 682 | |
@@ -686,8 +686,8 @@ discard block |
||
686 | 686 | * @since 1.0.19 |
687 | 687 | * @param int $id ID. |
688 | 688 | */ |
689 | - public function set_id( $id ) { |
|
690 | - $this->id = absint( $id ); |
|
689 | + public function set_id($id) { |
|
690 | + $this->id = absint($id); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -697,10 +697,10 @@ discard block |
||
697 | 697 | * @param string $status New status. |
698 | 698 | * @return array details of change. |
699 | 699 | */ |
700 | - public function set_status( $status ) { |
|
700 | + public function set_status($status) { |
|
701 | 701 | $old_status = $this->get_status(); |
702 | 702 | |
703 | - $this->set_prop( 'status', $status ); |
|
703 | + $this->set_prop('status', $status); |
|
704 | 704 | |
705 | 705 | return array( |
706 | 706 | 'from' => $old_status, |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | public function set_defaults() { |
717 | 717 | $this->data = $this->default_data; |
718 | 718 | $this->changes = array(); |
719 | - $this->set_object_read( false ); |
|
719 | + $this->set_object_read(false); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * @since 1.0.19 |
726 | 726 | * @param boolean $read Should read?. |
727 | 727 | */ |
728 | - public function set_object_read( $read = true ) { |
|
728 | + public function set_object_read($read = true) { |
|
729 | 729 | $this->object_read = (bool) $read; |
730 | 730 | } |
731 | 731 | |
@@ -750,32 +750,32 @@ discard block |
||
750 | 750 | * |
751 | 751 | * @return bool|WP_Error |
752 | 752 | */ |
753 | - public function set_props( $props, $context = 'set' ) { |
|
753 | + public function set_props($props, $context = 'set') { |
|
754 | 754 | $errors = false; |
755 | 755 | |
756 | - foreach ( $props as $prop => $value ) { |
|
756 | + foreach ($props as $prop => $value) { |
|
757 | 757 | try { |
758 | 758 | /** |
759 | 759 | * Checks if the prop being set is allowed, and the value is not null. |
760 | 760 | */ |
761 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
761 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
762 | 762 | continue; |
763 | 763 | } |
764 | 764 | $setter = "set_$prop"; |
765 | 765 | |
766 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
767 | - $this->{$setter}( $value ); |
|
766 | + if (is_callable(array($this, $setter))) { |
|
767 | + $this->{$setter}($value); |
|
768 | 768 | } |
769 | - } catch ( Exception $e ) { |
|
770 | - if ( ! $errors ) { |
|
769 | + } catch (Exception $e) { |
|
770 | + if (!$errors) { |
|
771 | 771 | $errors = new WP_Error(); |
772 | 772 | } |
773 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
773 | + $errors->add($e->getCode(), $e->getMessage()); |
|
774 | 774 | $this->last_error = $e->getMessage(); |
775 | 775 | } |
776 | 776 | } |
777 | 777 | |
778 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
778 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | /** |
@@ -788,14 +788,14 @@ discard block |
||
788 | 788 | * @param string $prop Name of prop to set. |
789 | 789 | * @param mixed $value Value of the prop. |
790 | 790 | */ |
791 | - protected function set_prop( $prop, $value ) { |
|
792 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
793 | - if ( true === $this->object_read ) { |
|
794 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
795 | - $this->changes[ $prop ] = maybe_unserialize( $value ); |
|
791 | + protected function set_prop($prop, $value) { |
|
792 | + if (array_key_exists($prop, $this->data)) { |
|
793 | + if (true === $this->object_read) { |
|
794 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
795 | + $this->changes[$prop] = maybe_unserialize($value); |
|
796 | 796 | } |
797 | 797 | } else { |
798 | - $this->data[ $prop ] = maybe_unserialize( $value ); |
|
798 | + $this->data[$prop] = maybe_unserialize($value); |
|
799 | 799 | } |
800 | 800 | } |
801 | 801 | } |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * @since 1.0.19 |
817 | 817 | */ |
818 | 818 | public function apply_changes() { |
819 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
819 | + $this->data = array_replace_recursive($this->data, $this->changes); |
|
820 | 820 | $this->changes = array(); |
821 | 821 | } |
822 | 822 | |
@@ -841,14 +841,14 @@ discard block |
||
841 | 841 | * @param string $context What the value is for. Valid values are view and edit. |
842 | 842 | * @return mixed |
843 | 843 | */ |
844 | - protected function get_prop( $prop, $context = 'view' ) { |
|
844 | + protected function get_prop($prop, $context = 'view') { |
|
845 | 845 | $value = null; |
846 | 846 | |
847 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
848 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
847 | + if (array_key_exists($prop, $this->data)) { |
|
848 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
849 | 849 | |
850 | - if ( 'view' === $context ) { |
|
851 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
850 | + if ('view' === $context) { |
|
851 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
852 | 852 | } |
853 | 853 | } |
854 | 854 | |
@@ -862,13 +862,13 @@ discard block |
||
862 | 862 | * @param string $prop Name of prop to set. |
863 | 863 | * @param string|integer $value Value of the prop. |
864 | 864 | */ |
865 | - protected function set_date_prop( $prop, $value ) { |
|
865 | + protected function set_date_prop($prop, $value) { |
|
866 | 866 | |
867 | - if ( empty( $value ) ) { |
|
868 | - $this->set_prop( $prop, null ); |
|
867 | + if (empty($value)) { |
|
868 | + $this->set_prop($prop, null); |
|
869 | 869 | return; |
870 | 870 | } |
871 | - $this->set_prop( $prop, $value ); |
|
871 | + $this->set_prop($prop, $value); |
|
872 | 872 | |
873 | 873 | } |
874 | 874 | |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param string $code Error code. |
881 | 881 | * @param string $message Error message. |
882 | 882 | */ |
883 | - protected function error( $code, $message ) { |
|
884 | - throw new Exception( $message, $code ); |
|
883 | + protected function error($code, $message) { |
|
884 | + throw new Exception($message, $code); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Item_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -80,39 +80,39 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param WPInv_Item $item Item object. |
82 | 82 | */ |
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
83 | + public function create(&$item) { |
|
84 | + $item->set_version(WPINV_VERSION); |
|
85 | + $item->set_date_created(current_time('mysql')); |
|
86 | 86 | |
87 | 87 | // Create a new post. |
88 | 88 | $id = wp_insert_post( |
89 | 89 | apply_filters( |
90 | 90 | 'getpaid_new_item_data', |
91 | 91 | array( |
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
92 | + 'post_date' => $item->get_date_created('edit'), |
|
93 | 93 | 'post_type' => 'wpi_item', |
94 | - 'post_status' => $this->get_post_status( $item ), |
|
94 | + 'post_status' => $this->get_post_status($item), |
|
95 | 95 | 'ping_status' => 'closed', |
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
96 | + 'post_author' => $item->get_author('edit'), |
|
97 | + 'post_title' => $item->get_name('edit'), |
|
98 | 98 | 'post_parent' => 0, |
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
99 | + 'post_excerpt' => $item->get_description('edit'), |
|
100 | 100 | ) |
101 | 101 | ), |
102 | 102 | true |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
105 | + if ($id && !is_wp_error($id)) { |
|
106 | + $item->set_id($id); |
|
107 | + $this->update_post_meta($item); |
|
108 | 108 | $item->save_meta_data(); |
109 | 109 | $item->apply_changes(); |
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
110 | + $this->clear_caches($item); |
|
111 | + do_action('getpaid_new_item', $item->get_id(), $item); |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - if ( is_wp_error( $id ) ) { |
|
115 | + if (is_wp_error($id)) { |
|
116 | 116 | $item->last_error = $id->get_error_message(); |
117 | 117 | } |
118 | 118 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * @param WPInv_Item $item Item object. |
126 | 126 | * |
127 | 127 | */ |
128 | - public function read( &$item ) { |
|
128 | + public function read(&$item) { |
|
129 | 129 | |
130 | 130 | $item->set_defaults(); |
131 | - $item_object = get_post( $item->get_id() ); |
|
131 | + $item_object = get_post($item->get_id()); |
|
132 | 132 | |
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
133 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
134 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
135 | + $item->set_id(0); |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - $this->read_object_data( $item, $item_object ); |
|
151 | + $this->read_object_data($item, $item_object); |
|
152 | 152 | $item->read_meta_data(); |
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
153 | + $item->set_object_read(true); |
|
154 | + do_action('getpaid_read_item', $item->get_id(), $item); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -160,29 +160,29 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param WPInv_Item $item Item object. |
162 | 162 | */ |
163 | - public function update( &$item ) { |
|
163 | + public function update(&$item) { |
|
164 | 164 | $item->save_meta_data(); |
165 | - $item->set_version( WPINV_VERSION ); |
|
165 | + $item->set_version(WPINV_VERSION); |
|
166 | 166 | |
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
167 | + if (null === $item->get_date_created('edit')) { |
|
168 | + $item->set_date_created(current_time('mysql')); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Grab the current status so we can compare. |
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
172 | + $previous_status = get_post_status($item->get_id()); |
|
173 | 173 | |
174 | 174 | $changes = $item->get_changes(); |
175 | 175 | |
176 | 176 | // Only update the post when the post data changes. |
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
177 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author'), array_keys($changes))) { |
|
178 | 178 | $post_data = array( |
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
179 | + 'post_date' => $item->get_date_created('edit'), |
|
180 | + 'post_status' => $item->get_status('edit'), |
|
181 | + 'post_parent' => $item->get_parent_id('edit'), |
|
182 | + 'post_excerpt' => $item->get_description('edit'), |
|
183 | + 'post_modified' => $item->get_date_modified('edit'), |
|
184 | + 'post_title' => $item->get_name('edit'), |
|
185 | + 'post_author' => $item->get_author('edit'), |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | /** |
@@ -193,25 +193,25 @@ discard block |
||
193 | 193 | * This ensures hooks are fired by either WP itself (admin screen save), |
194 | 194 | * or an update purely from CRUD. |
195 | 195 | */ |
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
196 | + if (doing_action('save_post')) { |
|
197 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
198 | + clean_post_cache($item->get_id()); |
|
199 | 199 | } else { |
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
200 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
201 | 201 | } |
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
202 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | 203 | } |
204 | - $this->update_post_meta( $item ); |
|
204 | + $this->update_post_meta($item); |
|
205 | 205 | $item->apply_changes(); |
206 | - $this->clear_caches( $item ); |
|
206 | + $this->clear_caches($item); |
|
207 | 207 | |
208 | 208 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
209 | - $new_status = $item->get_status( 'edit' ); |
|
209 | + $new_status = $item->get_status('edit'); |
|
210 | 210 | |
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
211 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
212 | + do_action('getpaid_new_item', $item->get_id(), $item); |
|
213 | 213 | } else { |
214 | - do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
214 | + do_action('getpaid_update_item', $item->get_id(), $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | * @param WPInv_Item $item WPInv_Item object. |
229 | 229 | * @since 1.0.19 |
230 | 230 | */ |
231 | - protected function update_post_meta( &$item ) { |
|
231 | + protected function update_post_meta(&$item) { |
|
232 | 232 | |
233 | 233 | // Ensure that we have a custom id. |
234 | - if ( ! $item->get_custom_id() ) { |
|
235 | - $item->set_custom_id( $item->get_id() ); |
|
234 | + if (!$item->get_custom_id()) { |
|
235 | + $item->set_custom_id($item->get_id()); |
|
236 | 236 | } |
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
238 | + parent::update_post_meta($item); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Invoice_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @param WPInv_Invoice $invoice Invoice object. |
105 | 105 | */ |
106 | - public function create( &$invoice ) { |
|
107 | - $invoice->set_version( WPINV_VERSION ); |
|
108 | - $invoice->set_date_created( current_time('mysql') ); |
|
106 | + public function create(&$invoice) { |
|
107 | + $invoice->set_version(WPINV_VERSION); |
|
108 | + $invoice->set_date_created(current_time('mysql')); |
|
109 | 109 | |
110 | 110 | // Ensure both the key and number are set. |
111 | 111 | $invoice->get_key(); |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | apply_filters( |
117 | 117 | 'getpaid_new_invoice_data', |
118 | 118 | array( |
119 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
120 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
121 | - 'post_status' => $this->get_post_status( $invoice ), |
|
119 | + 'post_date' => $invoice->get_date_created('edit'), |
|
120 | + 'post_type' => $invoice->get_post_type('edit'), |
|
121 | + 'post_status' => $this->get_post_status($invoice), |
|
122 | 122 | 'ping_status' => 'closed', |
123 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
124 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
125 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
126 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
127 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
123 | + 'post_author' => $invoice->get_user_id('edit'), |
|
124 | + 'post_title' => $invoice->get_number('edit'), |
|
125 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
126 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
127 | + 'post_name' => $invoice->get_path('edit'), |
|
128 | 128 | ) |
129 | 129 | ), |
130 | 130 | true |
131 | 131 | ); |
132 | 132 | |
133 | - if ( $id && ! is_wp_error( $id ) ) { |
|
134 | - $invoice->set_id( $id ); |
|
135 | - getpaid_save_invoice_user_address( $invoice ); |
|
136 | - $this->save_special_fields( $invoice ); |
|
137 | - $this->save_items( $invoice ); |
|
138 | - $this->update_post_meta( $invoice ); |
|
133 | + if ($id && !is_wp_error($id)) { |
|
134 | + $invoice->set_id($id); |
|
135 | + getpaid_save_invoice_user_address($invoice); |
|
136 | + $this->save_special_fields($invoice); |
|
137 | + $this->save_items($invoice); |
|
138 | + $this->update_post_meta($invoice); |
|
139 | 139 | $invoice->save_meta_data(); |
140 | 140 | $invoice->apply_changes(); |
141 | - $this->clear_caches( $invoice ); |
|
142 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
141 | + $this->clear_caches($invoice); |
|
142 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | |
146 | - if ( is_wp_error( $id ) ) { |
|
146 | + if (is_wp_error($id)) { |
|
147 | 147 | $invoice->last_error = $id->get_error_message(); |
148 | 148 | } |
149 | 149 | |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | * @param WPInv_Invoice $invoice Invoice object. |
157 | 157 | * |
158 | 158 | */ |
159 | - public function read( &$invoice ) { |
|
159 | + public function read(&$invoice) { |
|
160 | 160 | |
161 | 161 | $invoice->set_defaults(); |
162 | - $invoice_object = get_post( $invoice->get_id() ); |
|
162 | + $invoice_object = get_post($invoice->get_id()); |
|
163 | 163 | |
164 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
165 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
166 | - $invoice->set_id( 0 ); |
|
164 | + if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) { |
|
165 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
166 | + $invoice->set_id(0); |
|
167 | 167 | return false; |
168 | 168 | } |
169 | 169 | |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | ) |
182 | 182 | ); |
183 | 183 | |
184 | - $invoice->set_type( $invoice_object->post_type ); |
|
184 | + $invoice->set_type($invoice_object->post_type); |
|
185 | 185 | |
186 | - $this->read_object_data( $invoice, $invoice_object ); |
|
187 | - $this->add_special_fields( $invoice ); |
|
188 | - $this->add_items( $invoice ); |
|
186 | + $this->read_object_data($invoice, $invoice_object); |
|
187 | + $this->add_special_fields($invoice); |
|
188 | + $this->add_items($invoice); |
|
189 | 189 | $invoice->read_meta_data(); |
190 | - $invoice->set_object_read( true ); |
|
191 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
190 | + $invoice->set_object_read(true); |
|
191 | + do_action('getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @param WPInv_Invoice $invoice Invoice object. |
199 | 199 | */ |
200 | - public function update( &$invoice ) { |
|
200 | + public function update(&$invoice) { |
|
201 | 201 | $invoice->save_meta_data(); |
202 | - $invoice->set_version( WPINV_VERSION ); |
|
202 | + $invoice->set_version(WPINV_VERSION); |
|
203 | 203 | |
204 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
205 | - $invoice->set_date_created( current_time('mysql') ); |
|
204 | + if (null === $invoice->get_date_created('edit')) { |
|
205 | + $invoice->set_date_created(current_time('mysql')); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // Ensure both the key and number are set. |
@@ -210,22 +210,22 @@ discard block |
||
210 | 210 | $invoice->get_number(); |
211 | 211 | |
212 | 212 | // Grab the current status so we can compare. |
213 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
213 | + $previous_status = get_post_status($invoice->get_id()); |
|
214 | 214 | |
215 | 215 | $changes = $invoice->get_changes(); |
216 | 216 | |
217 | 217 | // Only update the post when the post data changes. |
218 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
218 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) { |
|
219 | 219 | $post_data = array( |
220 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
221 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
222 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
223 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
224 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
225 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
226 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
227 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
228 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
220 | + 'post_date' => $invoice->get_date_created('edit'), |
|
221 | + 'post_status' => $invoice->get_status('edit'), |
|
222 | + 'post_title' => $invoice->get_name('edit'), |
|
223 | + 'post_author' => $invoice->get_user_id('edit'), |
|
224 | + 'post_modified' => $invoice->get_date_modified('edit'), |
|
225 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
226 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
227 | + 'post_name' => $invoice->get_path('edit'), |
|
228 | + 'post_type' => $invoice->get_post_type('edit'), |
|
229 | 229 | ); |
230 | 230 | |
231 | 231 | /** |
@@ -236,28 +236,28 @@ discard block |
||
236 | 236 | * This ensures hooks are fired by either WP itself (admin screen save), |
237 | 237 | * or an update purely from CRUD. |
238 | 238 | */ |
239 | - if ( doing_action( 'save_post' ) ) { |
|
240 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
241 | - clean_post_cache( $invoice->get_id() ); |
|
239 | + if (doing_action('save_post')) { |
|
240 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id())); |
|
241 | + clean_post_cache($invoice->get_id()); |
|
242 | 242 | } else { |
243 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
243 | + wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data)); |
|
244 | 244 | } |
245 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
245 | + $invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
246 | 246 | } |
247 | - $this->update_post_meta( $invoice ); |
|
248 | - $this->save_special_fields( $invoice ); |
|
249 | - $this->save_items( $invoice ); |
|
247 | + $this->update_post_meta($invoice); |
|
248 | + $this->save_special_fields($invoice); |
|
249 | + $this->save_items($invoice); |
|
250 | 250 | $invoice->apply_changes(); |
251 | - getpaid_save_invoice_user_address( $invoice ); |
|
252 | - $this->clear_caches( $invoice ); |
|
251 | + getpaid_save_invoice_user_address($invoice); |
|
252 | + $this->clear_caches($invoice); |
|
253 | 253 | |
254 | 254 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
255 | - $new_status = $invoice->get_status( 'edit' ); |
|
255 | + $new_status = $invoice->get_status('edit'); |
|
256 | 256 | |
257 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
258 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
257 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
258 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
259 | 259 | } else { |
260 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
260 | + do_action('getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
@@ -273,43 +273,43 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - public function add_special_fields( &$invoice ) { |
|
276 | + public function add_special_fields(&$invoice) { |
|
277 | 277 | global $wpdb; |
278 | 278 | |
279 | 279 | // Maybe retrieve from the cache. |
280 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
280 | + $data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
281 | 281 | |
282 | 282 | // If not found, retrieve from the db. |
283 | - if ( false === $data ) { |
|
284 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
283 | + if (false === $data) { |
|
284 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
285 | 285 | |
286 | 286 | $data = $wpdb->get_row( |
287 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
287 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()), |
|
288 | 288 | ARRAY_A |
289 | 289 | ); |
290 | 290 | |
291 | 291 | // Update the cache with our data |
292 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
292 | + wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields'); |
|
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | // Abort if the data does not exist. |
297 | - if ( empty( $data ) ) { |
|
297 | + if (empty($data)) { |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $props = array(); |
302 | 302 | |
303 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
303 | + foreach ($this->database_fields_to_props as $db_field => $prop) { |
|
304 | 304 | |
305 | - if ( $db_field == 'post_id' ) { |
|
305 | + if ($db_field == 'post_id') { |
|
306 | 306 | continue; |
307 | 307 | } |
308 | 308 | |
309 | - $props[ $prop ] = $data[ $db_field ]; |
|
309 | + $props[$prop] = $data[$db_field]; |
|
310 | 310 | } |
311 | 311 | |
312 | - $invoice->set_props( $props ); |
|
312 | + $invoice->set_props($props); |
|
313 | 313 | |
314 | 314 | } |
315 | 315 | |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | * @param WPInv_Invoice $invoice The Invoice object. |
321 | 321 | * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
322 | 322 | */ |
323 | - protected function get_special_fields_to_update( $invoice ) { |
|
323 | + protected function get_special_fields_to_update($invoice) { |
|
324 | 324 | $fields_to_update = array(); |
325 | - $changed_props = $invoice->get_changes(); |
|
325 | + $changed_props = $invoice->get_changes(); |
|
326 | 326 | |
327 | 327 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
328 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
329 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
330 | - $fields_to_update[ $database_field ] = $prop; |
|
328 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
329 | + if (array_key_exists($prop, $changed_props)) { |
|
330 | + $fields_to_update[$database_field] = $prop; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -340,25 +340,25 @@ discard block |
||
340 | 340 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
341 | 341 | * @since 1.0.19 |
342 | 342 | */ |
343 | - protected function update_special_fields( &$invoice ) { |
|
343 | + protected function update_special_fields(&$invoice) { |
|
344 | 344 | global $wpdb; |
345 | 345 | |
346 | 346 | $updated_props = array(); |
347 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
347 | + $fields_to_update = $this->get_special_fields_to_update($invoice); |
|
348 | 348 | |
349 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
350 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
351 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
352 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
353 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
349 | + foreach ($fields_to_update as $database_field => $prop) { |
|
350 | + $value = $invoice->{"get_$prop"}('edit'); |
|
351 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
352 | + $value = is_bool($value) ? (int) $value : $value; |
|
353 | + $updated_props[$database_field] = maybe_serialize($value); |
|
354 | 354 | } |
355 | 355 | |
356 | - if ( ! empty( $updated_props ) ) { |
|
356 | + if (!empty($updated_props)) { |
|
357 | 357 | |
358 | 358 | $table = $wpdb->prefix . 'getpaid_invoices'; |
359 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
360 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
361 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
359 | + $wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id())); |
|
360 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
361 | + do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props); |
|
362 | 362 | |
363 | 363 | } |
364 | 364 | |
@@ -370,22 +370,22 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
371 | 371 | * @since 1.0.19 |
372 | 372 | */ |
373 | - protected function insert_special_fields( &$invoice ) { |
|
373 | + protected function insert_special_fields(&$invoice) { |
|
374 | 374 | global $wpdb; |
375 | 375 | |
376 | - $updated_props = array(); |
|
376 | + $updated_props = array(); |
|
377 | 377 | |
378 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
379 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
380 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
381 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
382 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
378 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
379 | + $value = $invoice->{"get_$prop"}('edit'); |
|
380 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
381 | + $value = is_bool($value) ? (int) $value : $value; |
|
382 | + $updated_props[$database_field] = maybe_serialize($value); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $table = $wpdb->prefix . 'getpaid_invoices'; |
386 | - $wpdb->insert( $table, $updated_props ); |
|
387 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
388 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
386 | + $wpdb->insert($table, $updated_props); |
|
387 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
388 | + do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props); |
|
389 | 389 | |
390 | 390 | } |
391 | 391 | |
@@ -394,20 +394,20 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @param WPInv_Invoice $invoice Invoice object. |
396 | 396 | */ |
397 | - public function save_special_fields( $invoice ) { |
|
397 | + public function save_special_fields($invoice) { |
|
398 | 398 | global $wpdb; |
399 | 399 | |
400 | 400 | // The invoices table. |
401 | 401 | $table = $wpdb->prefix . 'getpaid_invoices'; |
402 | 402 | $id = (int) $invoice->get_id(); |
403 | 403 | |
404 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
404 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) { |
|
405 | 405 | |
406 | - $this->update_special_fields( $invoice ); |
|
406 | + $this->update_special_fields($invoice); |
|
407 | 407 | |
408 | 408 | } else { |
409 | 409 | |
410 | - $this->insert_special_fields( $invoice ); |
|
410 | + $this->insert_special_fields($invoice); |
|
411 | 411 | |
412 | 412 | } |
413 | 413 | |
@@ -418,43 +418,43 @@ discard block |
||
418 | 418 | * |
419 | 419 | * @param WPInv_Invoice $invoice Invoice object. |
420 | 420 | */ |
421 | - public function add_items( &$invoice ) { |
|
421 | + public function add_items(&$invoice) { |
|
422 | 422 | global $wpdb; |
423 | 423 | |
424 | 424 | // Maybe retrieve from the cache. |
425 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
425 | + $items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
426 | 426 | |
427 | 427 | // If not found, retrieve from the db. |
428 | - if ( false === $items ) { |
|
429 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
428 | + if (false === $items) { |
|
429 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
430 | 430 | |
431 | 431 | $items = $wpdb->get_results( |
432 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
432 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id()) |
|
433 | 433 | ); |
434 | 434 | |
435 | 435 | // Update the cache with our data |
436 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
436 | + wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details'); |
|
437 | 437 | |
438 | 438 | } |
439 | 439 | |
440 | 440 | // Abort if no items found. |
441 | - if ( empty( $items ) ) { |
|
441 | + if (empty($items)) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | - foreach ( $items as $item_data ) { |
|
446 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
445 | + foreach ($items as $item_data) { |
|
446 | + $item = new GetPaid_Form_Item($item_data->item_id); |
|
447 | 447 | |
448 | 448 | // Set item data. |
449 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
450 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
451 | - $item->set_name( $item_data->item_name ); |
|
452 | - $item->set_description( $item_data->item_description ); |
|
453 | - $item->set_price( $item_data->item_price ); |
|
454 | - $item->set_quantity( $item_data->quantity ); |
|
455 | - $item->set_item_meta( $item_data->meta ); |
|
456 | - |
|
457 | - $invoice->add_item( $item ); |
|
449 | + $item->item_tax = wpinv_sanitize_amount($item_data->tax); |
|
450 | + $item->item_discount = wpinv_sanitize_amount($item_data->discount); |
|
451 | + $item->set_name($item_data->item_name); |
|
452 | + $item->set_description($item_data->item_description); |
|
453 | + $item->set_price($item_data->item_price); |
|
454 | + $item->set_quantity($item_data->quantity); |
|
455 | + $item->set_item_meta($item_data->meta); |
|
456 | + |
|
457 | + $invoice->add_item($item); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | } |
@@ -464,20 +464,20 @@ discard block |
||
464 | 464 | * |
465 | 465 | * @param WPInv_Invoice $invoice Invoice object. |
466 | 466 | */ |
467 | - public function save_items( $invoice ) { |
|
467 | + public function save_items($invoice) { |
|
468 | 468 | |
469 | 469 | // Delete previously existing items. |
470 | - $this->delete_items( $invoice ); |
|
470 | + $this->delete_items($invoice); |
|
471 | 471 | |
472 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
472 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
473 | 473 | |
474 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
475 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
476 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
474 | + foreach ($invoice->get_cart_details() as $item_data) { |
|
475 | + $item_data = array_map('maybe_serialize', $item_data); |
|
476 | + $GLOBALS['wpdb']->insert($table, $item_data); |
|
477 | 477 | } |
478 | 478 | |
479 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
480 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
479 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
480 | + do_action("getpaid_invoice_save_items", $invoice); |
|
481 | 481 | |
482 | 482 | } |
483 | 483 | |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * |
487 | 487 | * @param WPInv_Invoice $invoice Invoice object. |
488 | 488 | */ |
489 | - public function delete_items( $invoice ) { |
|
490 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
489 | + public function delete_items($invoice) { |
|
490 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @param WPInv_Invoice $invoice Invoice object. |
498 | 498 | */ |
499 | - public function delete_special_fields( $invoice ) { |
|
500 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
499 | + public function delete_special_fields($invoice) { |
|
500 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | } |
@@ -7,46 +7,46 @@ |
||
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 | |
15 | 15 | function wpinv_get_default_labels() { |
16 | 16 | $defaults = array( |
17 | - 'singular' => __( 'Invoice', 'invoicing' ), |
|
18 | - 'plural' => __( 'Invoices', 'invoicing' ) |
|
17 | + 'singular' => __('Invoice', 'invoicing'), |
|
18 | + 'plural' => __('Invoices', 'invoicing') |
|
19 | 19 | ); |
20 | 20 | |
21 | - return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
21 | + return apply_filters('wpinv_default_invoices_name', $defaults); |
|
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_get_label_singular( $lowercase = false ) { |
|
24 | +function wpinv_get_label_singular($lowercase = false) { |
|
25 | 25 | $defaults = wpinv_get_default_labels(); |
26 | 26 | |
27 | - return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
27 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
28 | 28 | } |
29 | 29 | |
30 | -function wpinv_get_label_plural( $lowercase = false ) { |
|
30 | +function wpinv_get_label_plural($lowercase = false) { |
|
31 | 31 | $defaults = wpinv_get_default_labels(); |
32 | 32 | |
33 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
33 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
34 | 34 | } |
35 | 35 | |
36 | -function wpinv_change_default_title( $title ) { |
|
37 | - if ( !is_admin() ) { |
|
36 | +function wpinv_change_default_title($title) { |
|
37 | + if (!is_admin()) { |
|
38 | 38 | $label = wpinv_get_label_singular(); |
39 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
39 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
40 | 40 | return $title; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $screen = get_current_screen(); |
44 | 44 | |
45 | - if ( 'wpi_invoice' == $screen->post_type ) { |
|
45 | + if ('wpi_invoice' == $screen->post_type) { |
|
46 | 46 | $label = wpinv_get_label_singular(); |
47 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
47 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $title; |
51 | 51 | } |
52 | -add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
52 | +add_filter('enter_title_here', 'wpinv_change_default_title'); |