@@ -31,6 +31,9 @@ discard block |
||
| 31 | 31 | return apply_filters( 'wpinv_get_ip', $ip ); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | +/** |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 34 | 37 | function wpinv_get_user_agent() { |
| 35 | 38 | if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
| 36 | 39 | $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
@@ -41,6 +44,9 @@ discard block |
||
| 41 | 44 | return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
| 42 | 45 | } |
| 43 | 46 | |
| 47 | +/** |
|
| 48 | + * @param integer $decimals |
|
| 49 | + */ |
|
| 44 | 50 | function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
| 45 | 51 | $is_negative = false; |
| 46 | 52 | $thousands_sep = wpinv_thousands_separator(); |
@@ -79,6 +85,9 @@ discard block |
||
| 79 | 85 | } |
| 80 | 86 | add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
| 81 | 87 | |
| 88 | +/** |
|
| 89 | + * @param integer $decimals |
|
| 90 | + */ |
|
| 82 | 91 | function wpinv_round_amount( $amount, $decimals = NULL ) { |
| 83 | 92 | if ( $decimals === NULL ) { |
| 84 | 93 | $decimals = wpinv_decimals(); |
@@ -117,6 +126,9 @@ discard block |
||
| 117 | 126 | return $status; |
| 118 | 127 | } |
| 119 | 128 | |
| 129 | +/** |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 120 | 132 | function wpinv_get_currency() { |
| 121 | 133 | $currency = wpinv_get_option( 'currency', 'USD' ); |
| 122 | 134 | |
@@ -187,6 +199,9 @@ discard block |
||
| 187 | 199 | return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
| 188 | 200 | } |
| 189 | 201 | |
| 202 | +/** |
|
| 203 | + * @return string |
|
| 204 | + */ |
|
| 190 | 205 | function wpinv_currency_position() { |
| 191 | 206 | $position = wpinv_get_option( 'currency_position', 'left' ); |
| 192 | 207 | |
@@ -315,6 +330,9 @@ discard block |
||
| 315 | 330 | return $price; |
| 316 | 331 | } |
| 317 | 332 | |
| 333 | +/** |
|
| 334 | + * @return string |
|
| 335 | + */ |
|
| 318 | 336 | function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
| 319 | 337 | $thousands_sep = wpinv_thousands_separator(); |
| 320 | 338 | $decimal_sep = wpinv_decimal_separator(); |
@@ -365,6 +383,9 @@ discard block |
||
| 365 | 383 | return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
| 366 | 384 | } |
| 367 | 385 | |
| 386 | +/** |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 368 | 389 | function wpinv_get_file_extension( $str ) { |
| 369 | 390 | $parts = explode( '.', $str ); |
| 370 | 391 | return end( $parts ); |
@@ -569,6 +590,9 @@ discard block |
||
| 569 | 590 | return strlen( $str ); |
| 570 | 591 | } |
| 571 | 592 | |
| 593 | +/** |
|
| 594 | + * @param string $str |
|
| 595 | + */ |
|
| 572 | 596 | function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
| 573 | 597 | if ( function_exists( 'mb_strtolower' ) ) { |
| 574 | 598 | return mb_strtolower( $str, $encoding ); |
@@ -577,6 +601,9 @@ discard block |
||
| 577 | 601 | return strtolower( $str ); |
| 578 | 602 | } |
| 579 | 603 | |
| 604 | +/** |
|
| 605 | + * @param string $str |
|
| 606 | + */ |
|
| 580 | 607 | function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
| 581 | 608 | if ( function_exists( 'mb_strtoupper' ) ) { |
| 582 | 609 | return mb_strtoupper( $str, $encoding ); |
@@ -654,7 +681,7 @@ discard block |
||
| 654 | 681 | * |
| 655 | 682 | * @param string $str The string being decoded. |
| 656 | 683 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 657 | - * @return string The width of string. |
|
| 684 | + * @return integer The width of string. |
|
| 658 | 685 | */ |
| 659 | 686 | function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
| 660 | 687 | if ( function_exists( 'mb_strwidth' ) ) { |
@@ -708,6 +735,12 @@ discard block |
||
| 708 | 735 | if ( ! function_exists( 'cal_days_in_month' ) ) { |
| 709 | 736 | // Fallback in case the calendar extension is not loaded in PHP |
| 710 | 737 | // Only supports Gregorian calendar |
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * @param integer $calendar |
|
| 741 | + * @param string $month |
|
| 742 | + * @param string $year |
|
| 743 | + */ |
|
| 711 | 744 | function cal_days_in_month( $calendar, $month, $year ) { |
| 712 | 745 | return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
| 713 | 746 | } |
@@ -7,89 +7,89 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_item_quantities_enabled() { |
| 15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
| 15 | + $ret = wpinv_get_option('item_quantities', true); |
|
| 16 | 16 | |
| 17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
| 17 | + return (bool)apply_filters('wpinv_item_quantities_enabled', $ret); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function wpinv_get_ip() { |
| 21 | 21 | $ip = '127.0.0.1'; |
| 22 | 22 | |
| 23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
| 24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
| 25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
| 26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
| 27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
| 28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
| 23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
| 25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
| 28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
| 31 | + return apply_filters('wpinv_get_ip', $ip); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function wpinv_get_user_agent() { |
| 35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
| 35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
| 36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
| 37 | 37 | } else { |
| 38 | 38 | $user_agent = ''; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
| 41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | -function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
|
| 44 | +function wpinv_sanitize_amount($amount, $decimals = NULL) { |
|
| 45 | 45 | $is_negative = false; |
| 46 | 46 | $thousands_sep = wpinv_thousands_separator(); |
| 47 | 47 | $decimal_sep = wpinv_decimal_separator(); |
| 48 | - if ( $decimals === NULL ) { |
|
| 48 | + if ($decimals === NULL) { |
|
| 49 | 49 | $decimals = wpinv_decimals(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Sanitize the amount |
| 53 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 54 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 55 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
| 56 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
| 57 | - $amount = str_replace( '.', '', $amount ); |
|
| 53 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
| 54 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 55 | + $amount = str_replace($thousands_sep, '', $amount); |
|
| 56 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
| 57 | + $amount = str_replace('.', '', $amount); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
| 61 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 62 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
| 60 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
| 61 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 62 | + $amount = str_replace($thousands_sep, '', $amount); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if( $amount < 0 ) { |
|
| 65 | + if ($amount < 0) { |
|
| 66 | 66 | $is_negative = true; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
| 69 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
| 70 | 70 | |
| 71 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount ); |
|
| 72 | - $amount = number_format( (double) $amount, absint( $decimals ), '.', '' ); |
|
| 71 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount); |
|
| 72 | + $amount = number_format((double)$amount, absint($decimals), '.', ''); |
|
| 73 | 73 | |
| 74 | - if( $is_negative ) { |
|
| 74 | + if ($is_negative) { |
|
| 75 | 75 | $amount *= -1; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals ); |
|
| 78 | + return apply_filters('wpinv_sanitize_amount', $amount, $decimals); |
|
| 79 | 79 | } |
| 80 | -add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 80 | +add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 81 | 81 | |
| 82 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
| 83 | - if ( $decimals === NULL ) { |
|
| 82 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
| 83 | + if ($decimals === NULL) { |
|
| 84 | 84 | $decimals = wpinv_decimals(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
| 87 | + $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
| 88 | 88 | |
| 89 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
| 89 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | -function wpinv_get_invoice_statuses( $trashed = false ) { |
|
| 92 | +function wpinv_get_invoice_statuses($trashed = false) { |
|
| 93 | 93 | global $post; |
| 94 | 94 | $invoice_statuses = array(); |
| 95 | 95 | $invoice_statuses = array( |
@@ -103,32 +103,32 @@ discard block |
||
| 103 | 103 | 'wpi-renewal' => __('Renewal Payment', 'invoicing') |
| 104 | 104 | ); |
| 105 | 105 | |
| 106 | - if ( $trashed ) { |
|
| 107 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 106 | + if ($trashed) { |
|
| 107 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
| 110 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | -function wpinv_status_nicename( $status ) { |
|
| 113 | +function wpinv_status_nicename($status) { |
|
| 114 | 114 | $statuses = wpinv_get_invoice_statuses(); |
| 115 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
| 115 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
| 116 | 116 | |
| 117 | 117 | return $status; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | function wpinv_get_currency() { |
| 121 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
| 121 | + $currency = wpinv_get_option('currency', 'USD'); |
|
| 122 | 122 | |
| 123 | - return apply_filters( 'wpinv_currency', $currency ); |
|
| 123 | + return apply_filters('wpinv_currency', $currency); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | -function wpinv_currency_symbol( $currency = '' ) { |
|
| 127 | - if ( empty( $currency ) ) { |
|
| 126 | +function wpinv_currency_symbol($currency = '') { |
|
| 127 | + if (empty($currency)) { |
|
| 128 | 128 | $currency = wpinv_get_currency(); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
| 131 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
| 132 | 132 | 'AED' => 'د.إ', |
| 133 | 133 | 'AFN' => '؋', |
| 134 | 134 | 'ALL' => 'L', |
@@ -291,208 +291,208 @@ discard block |
||
| 291 | 291 | 'YER' => '﷼', |
| 292 | 292 | 'ZAR' => 'R', |
| 293 | 293 | 'ZMW' => 'ZK', |
| 294 | - ) ); |
|
| 294 | + )); |
|
| 295 | 295 | |
| 296 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
| 296 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
| 297 | 297 | |
| 298 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 298 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | function wpinv_currency_position() { |
| 302 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 302 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 303 | 303 | |
| 304 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 304 | + return apply_filters('wpinv_currency_position', $position); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | function wpinv_thousands_separator() { |
| 308 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 308 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
| 309 | 309 | |
| 310 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
| 310 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | function wpinv_decimal_separator() { |
| 314 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 314 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
| 315 | 315 | |
| 316 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
| 316 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | function wpinv_decimals() { |
| 320 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
| 320 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
| 321 | 321 | |
| 322 | - return absint( $decimals ); |
|
| 322 | + return absint($decimals); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | function wpinv_get_currencies() { |
| 326 | 326 | $currencies = array( |
| 327 | - 'USD' => __( 'US Dollar', 'invoicing' ), |
|
| 328 | - 'EUR' => __( 'Euro', 'invoicing' ), |
|
| 329 | - 'GBP' => __( 'Pound Sterling', 'invoicing' ), |
|
| 330 | - 'AFN' => __( 'Afghan Afghani', 'invoicing' ), |
|
| 331 | - 'ALL' => __( 'Albanian Lek', 'invoicing' ), |
|
| 332 | - 'AMD' => __( 'Armenian Dram', 'invoicing' ), |
|
| 333 | - 'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ), |
|
| 334 | - 'AOA' => __( 'Angolan Kwanza', 'invoicing' ), |
|
| 335 | - 'ARS' => __( 'Argentine Peso', 'invoicing' ), |
|
| 336 | - 'AUD' => __( 'Australian Dollar', 'invoicing' ), |
|
| 337 | - 'AWG' => __( 'Aruban Florin', 'invoicing' ), |
|
| 338 | - 'AZN' => __( 'Azerbaijani Manat', 'invoicing' ), |
|
| 339 | - 'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ), |
|
| 340 | - 'BBD' => __( 'Barbadian Dollar', 'invoicing' ), |
|
| 341 | - 'BDT' => __( 'Bangladeshi Taka', 'invoicing' ), |
|
| 342 | - 'BGN' => __( 'Bulgarian Lev', 'invoicing' ), |
|
| 343 | - 'BHD' => __( 'Bahraini Dinar', 'invoicing' ), |
|
| 344 | - 'BIF' => __( 'Burundian Franc', 'invoicing' ), |
|
| 345 | - 'BMD' => __( 'Bermudian Dollar', 'invoicing' ), |
|
| 346 | - 'BND' => __( 'Brunei Dollar', 'invoicing' ), |
|
| 347 | - 'BOB' => __( 'Bolivian Boliviano', 'invoicing' ), |
|
| 348 | - 'BRL' => __( 'Brazilian Real', 'invoicing' ), |
|
| 349 | - 'BSD' => __( 'Bahamian Dollar', 'invoicing' ), |
|
| 350 | - 'BTC' => __( 'Bitcoin', 'invoicing' ), |
|
| 351 | - 'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ), |
|
| 352 | - 'BWP' => __( 'Botswana Pula', 'invoicing' ), |
|
| 353 | - 'BYR' => __( 'Belarusian Ruble', 'invoicing' ), |
|
| 354 | - 'BZD' => __( 'Belize Dollar', 'invoicing' ), |
|
| 355 | - 'CAD' => __( 'Canadian Dollar', 'invoicing' ), |
|
| 356 | - 'CDF' => __( 'Congolese Franc', 'invoicing' ), |
|
| 357 | - 'CHF' => __( 'Swiss Franc', 'invoicing' ), |
|
| 358 | - 'CLP' => __( 'Chilean Peso', 'invoicing' ), |
|
| 359 | - 'CNY' => __( 'Chinese Yuan', 'invoicing' ), |
|
| 360 | - 'COP' => __( 'Colombian Peso', 'invoicing' ), |
|
| 361 | - 'CRC' => __( 'Costa Rican Colon', 'invoicing' ), |
|
| 362 | - 'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ), |
|
| 363 | - 'CUP' => __( 'Cuban Peso', 'invoicing' ), |
|
| 364 | - 'CVE' => __( 'Cape Verdean escudo', 'invoicing' ), |
|
| 365 | - 'CZK' => __( 'Czech Koruna', 'invoicing' ), |
|
| 366 | - 'DJF' => __( 'Djiboutian Franc', 'invoicing' ), |
|
| 367 | - 'DKK' => __( 'Danish Krone', 'invoicing' ), |
|
| 368 | - 'DOP' => __( 'Dominican Peso', 'invoicing' ), |
|
| 369 | - 'DZD' => __( 'Algerian Dinar', 'invoicing' ), |
|
| 370 | - 'EGP' => __( 'Egyptian Pound', 'invoicing' ), |
|
| 371 | - 'ERN' => __( 'Eritrean Nakfa', 'invoicing' ), |
|
| 372 | - 'ETB' => __( 'Ethiopian irr', 'invoicing' ), |
|
| 373 | - 'FJD' => __( 'Fijian Dollar', 'invoicing' ), |
|
| 374 | - 'FKP' => __( 'Falkland Islands Pound', 'invoicing' ), |
|
| 375 | - 'GEL' => __( 'Georgian lari', 'invoicing' ), |
|
| 376 | - 'GGP' => __( 'Guernsey Pound', 'invoicing' ), |
|
| 377 | - 'GHS' => __( 'Ghana cedi', 'invoicing' ), |
|
| 378 | - 'GIP' => __( 'Gibraltar Pound', 'invoicing' ), |
|
| 379 | - 'GMD' => __( 'Gambian Dalasi', 'invoicing' ), |
|
| 380 | - 'GNF' => __( 'Guinean Franc', 'invoicing' ), |
|
| 381 | - 'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ), |
|
| 382 | - 'GYD' => __( 'Guyanese Dollar', 'invoicing' ), |
|
| 383 | - 'HKD' => __( 'Hong Kong Dollar', 'invoicing' ), |
|
| 384 | - 'HNL' => __( 'Honduran Lempira', 'invoicing' ), |
|
| 385 | - 'HRK' => __( 'Croatian Kuna', 'invoicing' ), |
|
| 386 | - 'HTG' => __( 'Haitian Gourde', 'invoicing' ), |
|
| 387 | - 'HUF' => __( 'Hungarian Forint', 'invoicing' ), |
|
| 388 | - 'IDR' => __( 'Indonesian Rupiah', 'invoicing' ), |
|
| 389 | - 'ILS' => __( 'Israeli New Shekel', 'invoicing' ), |
|
| 390 | - 'IMP' => __( 'Manx Pound', 'invoicing' ), |
|
| 391 | - 'INR' => __( 'Indian Rupee', 'invoicing' ), |
|
| 392 | - 'IQD' => __( 'Iraqi Dinar', 'invoicing' ), |
|
| 393 | - 'IRR' => __( 'Iranian Rial', 'invoicing' ), |
|
| 394 | - 'IRT' => __( 'Iranian Toman', 'invoicing' ), |
|
| 395 | - 'ISK' => __( 'Icelandic Krona', 'invoicing' ), |
|
| 396 | - 'JEP' => __( 'Jersey Pound', 'invoicing' ), |
|
| 397 | - 'JMD' => __( 'Jamaican Dollar', 'invoicing' ), |
|
| 398 | - 'JOD' => __( 'Jordanian Dinar', 'invoicing' ), |
|
| 399 | - 'JPY' => __( 'Japanese Yen', 'invoicing' ), |
|
| 400 | - 'KES' => __( 'Kenyan Shilling', 'invoicing' ), |
|
| 401 | - 'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ), |
|
| 402 | - 'KHR' => __( 'Cambodian Riel', 'invoicing' ), |
|
| 403 | - 'KMF' => __( 'Comorian Franc', 'invoicing' ), |
|
| 404 | - 'KPW' => __( 'North Korean Won', 'invoicing' ), |
|
| 405 | - 'KRW' => __( 'South Korean Won', 'invoicing' ), |
|
| 406 | - 'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ), |
|
| 407 | - 'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ), |
|
| 408 | - 'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ), |
|
| 409 | - 'LAK' => __( 'Lao Kip', 'invoicing' ), |
|
| 410 | - 'LBP' => __( 'Lebanese Pound', 'invoicing' ), |
|
| 411 | - 'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ), |
|
| 412 | - 'LRD' => __( 'Liberian Dollar', 'invoicing' ), |
|
| 413 | - 'LSL' => __( 'Lesotho Loti', 'invoicing' ), |
|
| 414 | - 'LYD' => __( 'Libyan Dinar', 'invoicing' ), |
|
| 415 | - 'MAD' => __( 'Moroccan Dirham', 'invoicing' ), |
|
| 416 | - 'MDL' => __( 'Moldovan Leu', 'invoicing' ), |
|
| 417 | - 'MGA' => __( 'Malagasy Ariary', 'invoicing' ), |
|
| 418 | - 'MKD' => __( 'Macedonian Denar', 'invoicing' ), |
|
| 419 | - 'MMK' => __( 'Burmese Kyat', 'invoicing' ), |
|
| 420 | - 'MNT' => __( 'Mongolian Tughrik', 'invoicing' ), |
|
| 421 | - 'MOP' => __( 'Macanese Pataca', 'invoicing' ), |
|
| 422 | - 'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ), |
|
| 423 | - 'MUR' => __( 'Mauritian Rupee', 'invoicing' ), |
|
| 424 | - 'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ), |
|
| 425 | - 'MWK' => __( 'Malawian Kwacha', 'invoicing' ), |
|
| 426 | - 'MXN' => __( 'Mexican Peso', 'invoicing' ), |
|
| 427 | - 'MYR' => __( 'Malaysian Ringgit', 'invoicing' ), |
|
| 428 | - 'MZN' => __( 'Mozambican Metical', 'invoicing' ), |
|
| 429 | - 'NAD' => __( 'Namibian Dollar', 'invoicing' ), |
|
| 430 | - 'NGN' => __( 'Nigerian Naira', 'invoicing' ), |
|
| 431 | - 'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ), |
|
| 432 | - 'NOK' => __( 'Norwegian Krone', 'invoicing' ), |
|
| 433 | - 'NPR' => __( 'Nepalese Rupee', 'invoicing' ), |
|
| 434 | - 'NZD' => __( 'New Zealand Dollar', 'invoicing' ), |
|
| 435 | - 'OMR' => __( 'Omani Rial', 'invoicing' ), |
|
| 436 | - 'PAB' => __( 'Panamanian Balboa', 'invoicing' ), |
|
| 437 | - 'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ), |
|
| 438 | - 'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ), |
|
| 439 | - 'PHP' => __( 'Philippine Peso', 'invoicing' ), |
|
| 440 | - 'PKR' => __( 'Pakistani Rupee', 'invoicing' ), |
|
| 441 | - 'PLN' => __( 'Polish Zloty', 'invoicing' ), |
|
| 442 | - 'PRB' => __( 'Transnistrian Ruble', 'invoicing' ), |
|
| 443 | - 'PYG' => __( 'Paraguayan Guarani', 'invoicing' ), |
|
| 444 | - 'QAR' => __( 'Qatari Riyal', 'invoicing' ), |
|
| 445 | - 'RON' => __( 'Romanian Leu', 'invoicing' ), |
|
| 446 | - 'RSD' => __( 'Serbian Dinar', 'invoicing' ), |
|
| 447 | - 'RUB' => __( 'Russian Ruble', 'invoicing' ), |
|
| 448 | - 'RWF' => __( 'Rwandan Franc', 'invoicing' ), |
|
| 449 | - 'SAR' => __( 'Saudi Riyal', 'invoicing' ), |
|
| 450 | - 'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ), |
|
| 451 | - 'SCR' => __( 'Seychellois Rupee', 'invoicing' ), |
|
| 452 | - 'SDG' => __( 'Sudanese Pound', 'invoicing' ), |
|
| 453 | - 'SEK' => __( 'Swedish Krona', 'invoicing' ), |
|
| 454 | - 'SGD' => __( 'Singapore Dollar', 'invoicing' ), |
|
| 455 | - 'SHP' => __( 'Saint Helena Pound', 'invoicing' ), |
|
| 456 | - 'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ), |
|
| 457 | - 'SOS' => __( 'Somali Shilling', 'invoicing' ), |
|
| 458 | - 'SRD' => __( 'Surinamese Dollar', 'invoicing' ), |
|
| 459 | - 'SSP' => __( 'South Sudanese Pound', 'invoicing' ), |
|
| 460 | - 'STD' => __( 'Sao Tomean Dobra', 'invoicing' ), |
|
| 461 | - 'SYP' => __( 'Syrian Pound', 'invoicing' ), |
|
| 462 | - 'SZL' => __( 'Swazi Lilangeni', 'invoicing' ), |
|
| 463 | - 'THB' => __( 'Thai Baht', 'invoicing' ), |
|
| 464 | - 'TJS' => __( 'Tajikistani Somoni', 'invoicing' ), |
|
| 465 | - 'TMT' => __( 'Turkmenistan Manat', 'invoicing' ), |
|
| 466 | - 'TND' => __( 'Tunisian Dinar', 'invoicing' ), |
|
| 467 | - 'TOP' => __( 'Tongan Paʻanga', 'invoicing' ), |
|
| 468 | - 'TRY' => __( 'Turkish Lira', 'invoicing' ), |
|
| 469 | - 'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ), |
|
| 470 | - 'TWD' => __( 'New Taiwan Dollar', 'invoicing' ), |
|
| 471 | - 'TZS' => __( 'Tanzanian Shilling', 'invoicing' ), |
|
| 472 | - 'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ), |
|
| 473 | - 'UGX' => __( 'Ugandan Shilling', 'invoicing' ), |
|
| 474 | - 'UYU' => __( 'Uruguayan Peso', 'invoicing' ), |
|
| 475 | - 'UZS' => __( 'Uzbekistani Som', 'invoicing' ), |
|
| 476 | - 'VEF' => __( 'Venezuelan Bolívar', 'invoicing' ), |
|
| 477 | - 'VND' => __( 'Vietnamese Dong', 'invoicing' ), |
|
| 478 | - 'VUV' => __( 'Vanuatu Vatu', 'invoicing' ), |
|
| 479 | - 'WST' => __( 'Samoan Tala', 'invoicing' ), |
|
| 480 | - 'XAF' => __( 'Central African CFA Franc', 'invoicing' ), |
|
| 481 | - 'XCD' => __( 'East Caribbean Dollar', 'invoicing' ), |
|
| 482 | - 'XOF' => __( 'West African CFA Franc', 'invoicing' ), |
|
| 483 | - 'XPF' => __( 'CFP Franc', 'invoicing' ), |
|
| 484 | - 'YER' => __( 'Yemeni Rial', 'invoicing' ), |
|
| 485 | - 'ZAR' => __( 'South African Rand', 'invoicing' ), |
|
| 486 | - 'ZMW' => __( 'Zambian Kwacha', 'invoicing' ), |
|
| 327 | + 'USD' => __('US Dollar', 'invoicing'), |
|
| 328 | + 'EUR' => __('Euro', 'invoicing'), |
|
| 329 | + 'GBP' => __('Pound Sterling', 'invoicing'), |
|
| 330 | + 'AFN' => __('Afghan Afghani', 'invoicing'), |
|
| 331 | + 'ALL' => __('Albanian Lek', 'invoicing'), |
|
| 332 | + 'AMD' => __('Armenian Dram', 'invoicing'), |
|
| 333 | + 'ANG' => __('Netherlands Antillean Guilder', 'invoicing'), |
|
| 334 | + 'AOA' => __('Angolan Kwanza', 'invoicing'), |
|
| 335 | + 'ARS' => __('Argentine Peso', 'invoicing'), |
|
| 336 | + 'AUD' => __('Australian Dollar', 'invoicing'), |
|
| 337 | + 'AWG' => __('Aruban Florin', 'invoicing'), |
|
| 338 | + 'AZN' => __('Azerbaijani Manat', 'invoicing'), |
|
| 339 | + 'BAM' => __('Bosnia and Herzegovina Convertible Marka', 'invoicing'), |
|
| 340 | + 'BBD' => __('Barbadian Dollar', 'invoicing'), |
|
| 341 | + 'BDT' => __('Bangladeshi Taka', 'invoicing'), |
|
| 342 | + 'BGN' => __('Bulgarian Lev', 'invoicing'), |
|
| 343 | + 'BHD' => __('Bahraini Dinar', 'invoicing'), |
|
| 344 | + 'BIF' => __('Burundian Franc', 'invoicing'), |
|
| 345 | + 'BMD' => __('Bermudian Dollar', 'invoicing'), |
|
| 346 | + 'BND' => __('Brunei Dollar', 'invoicing'), |
|
| 347 | + 'BOB' => __('Bolivian Boliviano', 'invoicing'), |
|
| 348 | + 'BRL' => __('Brazilian Real', 'invoicing'), |
|
| 349 | + 'BSD' => __('Bahamian Dollar', 'invoicing'), |
|
| 350 | + 'BTC' => __('Bitcoin', 'invoicing'), |
|
| 351 | + 'BTN' => __('Bhutanese Ngultrum', 'invoicing'), |
|
| 352 | + 'BWP' => __('Botswana Pula', 'invoicing'), |
|
| 353 | + 'BYR' => __('Belarusian Ruble', 'invoicing'), |
|
| 354 | + 'BZD' => __('Belize Dollar', 'invoicing'), |
|
| 355 | + 'CAD' => __('Canadian Dollar', 'invoicing'), |
|
| 356 | + 'CDF' => __('Congolese Franc', 'invoicing'), |
|
| 357 | + 'CHF' => __('Swiss Franc', 'invoicing'), |
|
| 358 | + 'CLP' => __('Chilean Peso', 'invoicing'), |
|
| 359 | + 'CNY' => __('Chinese Yuan', 'invoicing'), |
|
| 360 | + 'COP' => __('Colombian Peso', 'invoicing'), |
|
| 361 | + 'CRC' => __('Costa Rican Colon', 'invoicing'), |
|
| 362 | + 'CUC' => __('Cuban Convertible Peso', 'invoicing'), |
|
| 363 | + 'CUP' => __('Cuban Peso', 'invoicing'), |
|
| 364 | + 'CVE' => __('Cape Verdean escudo', 'invoicing'), |
|
| 365 | + 'CZK' => __('Czech Koruna', 'invoicing'), |
|
| 366 | + 'DJF' => __('Djiboutian Franc', 'invoicing'), |
|
| 367 | + 'DKK' => __('Danish Krone', 'invoicing'), |
|
| 368 | + 'DOP' => __('Dominican Peso', 'invoicing'), |
|
| 369 | + 'DZD' => __('Algerian Dinar', 'invoicing'), |
|
| 370 | + 'EGP' => __('Egyptian Pound', 'invoicing'), |
|
| 371 | + 'ERN' => __('Eritrean Nakfa', 'invoicing'), |
|
| 372 | + 'ETB' => __('Ethiopian irr', 'invoicing'), |
|
| 373 | + 'FJD' => __('Fijian Dollar', 'invoicing'), |
|
| 374 | + 'FKP' => __('Falkland Islands Pound', 'invoicing'), |
|
| 375 | + 'GEL' => __('Georgian lari', 'invoicing'), |
|
| 376 | + 'GGP' => __('Guernsey Pound', 'invoicing'), |
|
| 377 | + 'GHS' => __('Ghana cedi', 'invoicing'), |
|
| 378 | + 'GIP' => __('Gibraltar Pound', 'invoicing'), |
|
| 379 | + 'GMD' => __('Gambian Dalasi', 'invoicing'), |
|
| 380 | + 'GNF' => __('Guinean Franc', 'invoicing'), |
|
| 381 | + 'GTQ' => __('Guatemalan Quetzal', 'invoicing'), |
|
| 382 | + 'GYD' => __('Guyanese Dollar', 'invoicing'), |
|
| 383 | + 'HKD' => __('Hong Kong Dollar', 'invoicing'), |
|
| 384 | + 'HNL' => __('Honduran Lempira', 'invoicing'), |
|
| 385 | + 'HRK' => __('Croatian Kuna', 'invoicing'), |
|
| 386 | + 'HTG' => __('Haitian Gourde', 'invoicing'), |
|
| 387 | + 'HUF' => __('Hungarian Forint', 'invoicing'), |
|
| 388 | + 'IDR' => __('Indonesian Rupiah', 'invoicing'), |
|
| 389 | + 'ILS' => __('Israeli New Shekel', 'invoicing'), |
|
| 390 | + 'IMP' => __('Manx Pound', 'invoicing'), |
|
| 391 | + 'INR' => __('Indian Rupee', 'invoicing'), |
|
| 392 | + 'IQD' => __('Iraqi Dinar', 'invoicing'), |
|
| 393 | + 'IRR' => __('Iranian Rial', 'invoicing'), |
|
| 394 | + 'IRT' => __('Iranian Toman', 'invoicing'), |
|
| 395 | + 'ISK' => __('Icelandic Krona', 'invoicing'), |
|
| 396 | + 'JEP' => __('Jersey Pound', 'invoicing'), |
|
| 397 | + 'JMD' => __('Jamaican Dollar', 'invoicing'), |
|
| 398 | + 'JOD' => __('Jordanian Dinar', 'invoicing'), |
|
| 399 | + 'JPY' => __('Japanese Yen', 'invoicing'), |
|
| 400 | + 'KES' => __('Kenyan Shilling', 'invoicing'), |
|
| 401 | + 'KGS' => __('Kyrgyzstani Som', 'invoicing'), |
|
| 402 | + 'KHR' => __('Cambodian Riel', 'invoicing'), |
|
| 403 | + 'KMF' => __('Comorian Franc', 'invoicing'), |
|
| 404 | + 'KPW' => __('North Korean Won', 'invoicing'), |
|
| 405 | + 'KRW' => __('South Korean Won', 'invoicing'), |
|
| 406 | + 'KWD' => __('Kuwaiti Dinar', 'invoicing'), |
|
| 407 | + 'KYD' => __('Cayman Islands Dollar', 'invoicing'), |
|
| 408 | + 'KZT' => __('Kazakhstani Tenge', 'invoicing'), |
|
| 409 | + 'LAK' => __('Lao Kip', 'invoicing'), |
|
| 410 | + 'LBP' => __('Lebanese Pound', 'invoicing'), |
|
| 411 | + 'LKR' => __('Sri Lankan Rupee', 'invoicing'), |
|
| 412 | + 'LRD' => __('Liberian Dollar', 'invoicing'), |
|
| 413 | + 'LSL' => __('Lesotho Loti', 'invoicing'), |
|
| 414 | + 'LYD' => __('Libyan Dinar', 'invoicing'), |
|
| 415 | + 'MAD' => __('Moroccan Dirham', 'invoicing'), |
|
| 416 | + 'MDL' => __('Moldovan Leu', 'invoicing'), |
|
| 417 | + 'MGA' => __('Malagasy Ariary', 'invoicing'), |
|
| 418 | + 'MKD' => __('Macedonian Denar', 'invoicing'), |
|
| 419 | + 'MMK' => __('Burmese Kyat', 'invoicing'), |
|
| 420 | + 'MNT' => __('Mongolian Tughrik', 'invoicing'), |
|
| 421 | + 'MOP' => __('Macanese Pataca', 'invoicing'), |
|
| 422 | + 'MRO' => __('Mauritanian Ouguiya', 'invoicing'), |
|
| 423 | + 'MUR' => __('Mauritian Rupee', 'invoicing'), |
|
| 424 | + 'MVR' => __('Maldivian Rufiyaa', 'invoicing'), |
|
| 425 | + 'MWK' => __('Malawian Kwacha', 'invoicing'), |
|
| 426 | + 'MXN' => __('Mexican Peso', 'invoicing'), |
|
| 427 | + 'MYR' => __('Malaysian Ringgit', 'invoicing'), |
|
| 428 | + 'MZN' => __('Mozambican Metical', 'invoicing'), |
|
| 429 | + 'NAD' => __('Namibian Dollar', 'invoicing'), |
|
| 430 | + 'NGN' => __('Nigerian Naira', 'invoicing'), |
|
| 431 | + 'NIO' => __('Nicaraguan Cordoba', 'invoicing'), |
|
| 432 | + 'NOK' => __('Norwegian Krone', 'invoicing'), |
|
| 433 | + 'NPR' => __('Nepalese Rupee', 'invoicing'), |
|
| 434 | + 'NZD' => __('New Zealand Dollar', 'invoicing'), |
|
| 435 | + 'OMR' => __('Omani Rial', 'invoicing'), |
|
| 436 | + 'PAB' => __('Panamanian Balboa', 'invoicing'), |
|
| 437 | + 'PEN' => __('Peruvian Nuevo Sol', 'invoicing'), |
|
| 438 | + 'PGK' => __('Papua New Guinean Kina', 'invoicing'), |
|
| 439 | + 'PHP' => __('Philippine Peso', 'invoicing'), |
|
| 440 | + 'PKR' => __('Pakistani Rupee', 'invoicing'), |
|
| 441 | + 'PLN' => __('Polish Zloty', 'invoicing'), |
|
| 442 | + 'PRB' => __('Transnistrian Ruble', 'invoicing'), |
|
| 443 | + 'PYG' => __('Paraguayan Guarani', 'invoicing'), |
|
| 444 | + 'QAR' => __('Qatari Riyal', 'invoicing'), |
|
| 445 | + 'RON' => __('Romanian Leu', 'invoicing'), |
|
| 446 | + 'RSD' => __('Serbian Dinar', 'invoicing'), |
|
| 447 | + 'RUB' => __('Russian Ruble', 'invoicing'), |
|
| 448 | + 'RWF' => __('Rwandan Franc', 'invoicing'), |
|
| 449 | + 'SAR' => __('Saudi Riyal', 'invoicing'), |
|
| 450 | + 'SBD' => __('Solomon Islands Dollar', 'invoicing'), |
|
| 451 | + 'SCR' => __('Seychellois Rupee', 'invoicing'), |
|
| 452 | + 'SDG' => __('Sudanese Pound', 'invoicing'), |
|
| 453 | + 'SEK' => __('Swedish Krona', 'invoicing'), |
|
| 454 | + 'SGD' => __('Singapore Dollar', 'invoicing'), |
|
| 455 | + 'SHP' => __('Saint Helena Pound', 'invoicing'), |
|
| 456 | + 'SLL' => __('Sierra Leonean Leone', 'invoicing'), |
|
| 457 | + 'SOS' => __('Somali Shilling', 'invoicing'), |
|
| 458 | + 'SRD' => __('Surinamese Dollar', 'invoicing'), |
|
| 459 | + 'SSP' => __('South Sudanese Pound', 'invoicing'), |
|
| 460 | + 'STD' => __('Sao Tomean Dobra', 'invoicing'), |
|
| 461 | + 'SYP' => __('Syrian Pound', 'invoicing'), |
|
| 462 | + 'SZL' => __('Swazi Lilangeni', 'invoicing'), |
|
| 463 | + 'THB' => __('Thai Baht', 'invoicing'), |
|
| 464 | + 'TJS' => __('Tajikistani Somoni', 'invoicing'), |
|
| 465 | + 'TMT' => __('Turkmenistan Manat', 'invoicing'), |
|
| 466 | + 'TND' => __('Tunisian Dinar', 'invoicing'), |
|
| 467 | + 'TOP' => __('Tongan Paʻanga', 'invoicing'), |
|
| 468 | + 'TRY' => __('Turkish Lira', 'invoicing'), |
|
| 469 | + 'TTD' => __('Trinidad and Tobago Dollar', 'invoicing'), |
|
| 470 | + 'TWD' => __('New Taiwan Dollar', 'invoicing'), |
|
| 471 | + 'TZS' => __('Tanzanian Shilling', 'invoicing'), |
|
| 472 | + 'UAH' => __('Ukrainian Hryvnia', 'invoicing'), |
|
| 473 | + 'UGX' => __('Ugandan Shilling', 'invoicing'), |
|
| 474 | + 'UYU' => __('Uruguayan Peso', 'invoicing'), |
|
| 475 | + 'UZS' => __('Uzbekistani Som', 'invoicing'), |
|
| 476 | + 'VEF' => __('Venezuelan Bolívar', 'invoicing'), |
|
| 477 | + 'VND' => __('Vietnamese Dong', 'invoicing'), |
|
| 478 | + 'VUV' => __('Vanuatu Vatu', 'invoicing'), |
|
| 479 | + 'WST' => __('Samoan Tala', 'invoicing'), |
|
| 480 | + 'XAF' => __('Central African CFA Franc', 'invoicing'), |
|
| 481 | + 'XCD' => __('East Caribbean Dollar', 'invoicing'), |
|
| 482 | + 'XOF' => __('West African CFA Franc', 'invoicing'), |
|
| 483 | + 'XPF' => __('CFP Franc', 'invoicing'), |
|
| 484 | + 'YER' => __('Yemeni Rial', 'invoicing'), |
|
| 485 | + 'ZAR' => __('South African Rand', 'invoicing'), |
|
| 486 | + 'ZMW' => __('Zambian Kwacha', 'invoicing'), |
|
| 487 | 487 | ); |
| 488 | 488 | |
| 489 | 489 | //asort( $currencies ); // this |
| 490 | 490 | |
| 491 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
| 491 | + return apply_filters('wpinv_currencies', $currencies); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
| 495 | - if( empty( $currency ) ) { |
|
| 494 | +function wpinv_price($amount = '', $currency = '') { |
|
| 495 | + if (empty($currency)) { |
|
| 496 | 496 | $currency = wpinv_get_currency(); |
| 497 | 497 | } |
| 498 | 498 | |
@@ -500,14 +500,14 @@ discard block |
||
| 500 | 500 | |
| 501 | 501 | $negative = $amount < 0; |
| 502 | 502 | |
| 503 | - if ( $negative ) { |
|
| 504 | - $amount = substr( $amount, 1 ); |
|
| 503 | + if ($negative) { |
|
| 504 | + $amount = substr($amount, 1); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - $symbol = wpinv_currency_symbol( $currency ); |
|
| 507 | + $symbol = wpinv_currency_symbol($currency); |
|
| 508 | 508 | |
| 509 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
| 510 | - switch ( $currency ) { |
|
| 509 | + if ($position == 'left' || $position == 'left_space') { |
|
| 510 | + switch ($currency) { |
|
| 511 | 511 | case "GBP" : |
| 512 | 512 | case "BRL" : |
| 513 | 513 | case "EUR" : |
@@ -519,15 +519,15 @@ discard block |
||
| 519 | 519 | case "NZD" : |
| 520 | 520 | case "SGD" : |
| 521 | 521 | case "JPY" : |
| 522 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 522 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 523 | 523 | break; |
| 524 | 524 | default : |
| 525 | 525 | //$price = $currency . ' ' . $amount; |
| 526 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 526 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 527 | 527 | break; |
| 528 | 528 | } |
| 529 | 529 | } else { |
| 530 | - switch ( $currency ) { |
|
| 530 | + switch ($currency) { |
|
| 531 | 531 | case "GBP" : |
| 532 | 532 | case "BRL" : |
| 533 | 533 | case "EUR" : |
@@ -538,83 +538,83 @@ discard block |
||
| 538 | 538 | case "MXN" : |
| 539 | 539 | case "SGD" : |
| 540 | 540 | case "JPY" : |
| 541 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 541 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 542 | 542 | break; |
| 543 | 543 | default : |
| 544 | 544 | //$price = $amount . ' ' . $currency; |
| 545 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 545 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 546 | 546 | break; |
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - if ( $negative ) { |
|
| 550 | + if ($negative) { |
|
| 551 | 551 | $price = '-' . $price; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
| 554 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
| 555 | 555 | |
| 556 | 556 | return $price; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
| 559 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
| 560 | 560 | $thousands_sep = wpinv_thousands_separator(); |
| 561 | 561 | $decimal_sep = wpinv_decimal_separator(); |
| 562 | 562 | |
| 563 | - if ( $decimals === NULL ) { |
|
| 563 | + if ($decimals === NULL) { |
|
| 564 | 564 | $decimals = wpinv_decimals(); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 568 | - $whole = substr( $amount, 0, $sep_found ); |
|
| 569 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
| 567 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
| 568 | + $whole = substr($amount, 0, $sep_found); |
|
| 569 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
| 570 | 570 | $amount = $whole . '.' . $part; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 574 | - $amount = str_replace( ',', '', $amount ); |
|
| 573 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 574 | + $amount = str_replace(',', '', $amount); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 578 | - $amount = str_replace( ' ', '', $amount ); |
|
| 577 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 578 | + $amount = str_replace(' ', '', $amount); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - if ( empty( $amount ) ) { |
|
| 581 | + if (empty($amount)) { |
|
| 582 | 582 | $amount = 0; |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
| 586 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 585 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
| 586 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 587 | 587 | |
| 588 | - if ( $calculate ) { |
|
| 589 | - if ( $thousands_sep === "," ) { |
|
| 590 | - $formatted = str_replace( ",", "", $formatted ); |
|
| 588 | + if ($calculate) { |
|
| 589 | + if ($thousands_sep === ",") { |
|
| 590 | + $formatted = str_replace(",", "", $formatted); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - if ( $decimal_sep === "," ) { |
|
| 594 | - $formatted = str_replace( ",", ".", $formatted ); |
|
| 593 | + if ($decimal_sep === ",") { |
|
| 594 | + $formatted = str_replace(",", ".", $formatted); |
|
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
| 598 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
| 599 | 599 | } |
| 600 | -add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 600 | +add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 601 | 601 | |
| 602 | -function wpinv_sanitize_key( $key ) { |
|
| 602 | +function wpinv_sanitize_key($key) { |
|
| 603 | 603 | $raw_key = $key; |
| 604 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 604 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 605 | 605 | |
| 606 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 606 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | -function wpinv_get_file_extension( $str ) { |
|
| 610 | - $parts = explode( '.', $str ); |
|
| 611 | - return end( $parts ); |
|
| 609 | +function wpinv_get_file_extension($str) { |
|
| 610 | + $parts = explode('.', $str); |
|
| 611 | + return end($parts); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | -function wpinv_string_is_image_url( $str ) { |
|
| 615 | - $ext = wpinv_get_file_extension( $str ); |
|
| 614 | +function wpinv_string_is_image_url($str) { |
|
| 615 | + $ext = wpinv_get_file_extension($str); |
|
| 616 | 616 | |
| 617 | - switch ( strtolower( $ext ) ) { |
|
| 617 | + switch (strtolower($ext)) { |
|
| 618 | 618 | case 'jpeg'; |
| 619 | 619 | case 'jpg'; |
| 620 | 620 | $return = true; |
@@ -630,32 +630,32 @@ discard block |
||
| 630 | 630 | break; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
| 633 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
| 637 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
| 636 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
| 637 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
| 638 | 638 | |
| 639 | - if ( true === $should_log ) { |
|
| 639 | + if (true === $should_log) { |
|
| 640 | 640 | $label = ''; |
| 641 | - if ( $file && $file !== '' ) { |
|
| 642 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
| 641 | + if ($file && $file !== '') { |
|
| 642 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ( $title && $title !== '' ) { |
|
| 645 | + if ($title && $title !== '') { |
|
| 646 | 646 | $label = $label !== '' ? $label . ' ' : ''; |
| 647 | 647 | $label .= $title . ' '; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
| 650 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
| 651 | 651 | |
| 652 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
| 653 | - error_log( $label . print_r( $log, true ) ); |
|
| 652 | + if (is_array($log) || is_object($log)) { |
|
| 653 | + error_log($label . print_r($log, true)); |
|
| 654 | 654 | } else { |
| 655 | - error_log( $label . $log ); |
|
| 655 | + error_log($label . $log); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - if ( $exit ) { |
|
| 658 | + if ($exit) { |
|
| 659 | 659 | exit; |
| 660 | 660 | } |
| 661 | 661 | } |
@@ -663,65 +663,65 @@ discard block |
||
| 663 | 663 | |
| 664 | 664 | function wpinv_is_ajax_disabled() { |
| 665 | 665 | $retval = false; |
| 666 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
| 666 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
| 669 | +function wpinv_get_current_page_url($nocache = false) { |
|
| 670 | 670 | global $wp; |
| 671 | 671 | |
| 672 | - if ( get_option( 'permalink_structure' ) ) { |
|
| 673 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
| 672 | + if (get_option('permalink_structure')) { |
|
| 673 | + $base = trailingslashit(home_url($wp->request)); |
|
| 674 | 674 | } else { |
| 675 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
| 676 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
| 675 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
| 676 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | $scheme = is_ssl() ? 'https' : 'http'; |
| 680 | - $uri = set_url_scheme( $base, $scheme ); |
|
| 680 | + $uri = set_url_scheme($base, $scheme); |
|
| 681 | 681 | |
| 682 | - if ( is_front_page() ) { |
|
| 683 | - $uri = home_url( '/' ); |
|
| 684 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
| 682 | + if (is_front_page()) { |
|
| 683 | + $uri = home_url('/'); |
|
| 684 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
| 685 | 685 | $uri = wpinv_get_checkout_uri(); |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
| 688 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
| 689 | 689 | |
| 690 | - if ( $nocache ) { |
|
| 691 | - $uri = wpinv_add_cache_busting( $uri ); |
|
| 690 | + if ($nocache) { |
|
| 691 | + $uri = wpinv_add_cache_busting($uri); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | return $uri; |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | function wpinv_get_php_arg_separator_output() { |
| 698 | - return ini_get( 'arg_separator.output' ); |
|
| 698 | + return ini_get('arg_separator.output'); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | -function wpinv_rgb_from_hex( $color ) { |
|
| 702 | - $color = str_replace( '#', '', $color ); |
|
| 701 | +function wpinv_rgb_from_hex($color) { |
|
| 702 | + $color = str_replace('#', '', $color); |
|
| 703 | 703 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 704 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 704 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 705 | 705 | |
| 706 | 706 | $rgb = array(); |
| 707 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
| 708 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
| 709 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
| 707 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
| 708 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
| 709 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
| 710 | 710 | |
| 711 | 711 | return $rgb; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 715 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 714 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 715 | + $base = wpinv_rgb_from_hex($color); |
|
| 716 | 716 | $color = '#'; |
| 717 | 717 | |
| 718 | - foreach ( $base as $k => $v ) { |
|
| 718 | + foreach ($base as $k => $v) { |
|
| 719 | 719 | $amount = $v / 100; |
| 720 | - $amount = round( $amount * $factor ); |
|
| 720 | + $amount = round($amount * $factor); |
|
| 721 | 721 | $new_decimal = $v - $amount; |
| 722 | 722 | |
| 723 | - $new_hex_component = dechex( $new_decimal ); |
|
| 724 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 723 | + $new_hex_component = dechex($new_decimal); |
|
| 724 | + if (strlen($new_hex_component) < 2) { |
|
| 725 | 725 | $new_hex_component = "0" . $new_hex_component; |
| 726 | 726 | } |
| 727 | 727 | $color .= $new_hex_component; |
@@ -730,18 +730,18 @@ discard block |
||
| 730 | 730 | return $color; |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 734 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 733 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 734 | + $base = wpinv_rgb_from_hex($color); |
|
| 735 | 735 | $color = '#'; |
| 736 | 736 | |
| 737 | - foreach ( $base as $k => $v ) { |
|
| 737 | + foreach ($base as $k => $v) { |
|
| 738 | 738 | $amount = 255 - $v; |
| 739 | 739 | $amount = $amount / 100; |
| 740 | - $amount = round( $amount * $factor ); |
|
| 740 | + $amount = round($amount * $factor); |
|
| 741 | 741 | $new_decimal = $v + $amount; |
| 742 | 742 | |
| 743 | - $new_hex_component = dechex( $new_decimal ); |
|
| 744 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 743 | + $new_hex_component = dechex($new_decimal); |
|
| 744 | + if (strlen($new_hex_component) < 2) { |
|
| 745 | 745 | $new_hex_component = "0" . $new_hex_component; |
| 746 | 746 | } |
| 747 | 747 | $color .= $new_hex_component; |
@@ -750,22 +750,22 @@ discard block |
||
| 750 | 750 | return $color; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 754 | - $hex = str_replace( '#', '', $color ); |
|
| 753 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 754 | + $hex = str_replace('#', '', $color); |
|
| 755 | 755 | |
| 756 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 757 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 758 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 756 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 757 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 758 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 759 | 759 | |
| 760 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 760 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 761 | 761 | |
| 762 | 762 | return $brightness > 155 ? $dark : $light; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | -function wpinv_format_hex( $hex ) { |
|
| 766 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 765 | +function wpinv_format_hex($hex) { |
|
| 766 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 767 | 767 | |
| 768 | - if ( strlen( $hex ) == 3 ) { |
|
| 768 | + if (strlen($hex) == 3) { |
|
| 769 | 769 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 770 | 770 | } |
| 771 | 771 | |
@@ -785,12 +785,12 @@ discard block |
||
| 785 | 785 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 786 | 786 | * @return string |
| 787 | 787 | */ |
| 788 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 789 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 790 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 788 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 789 | + if (function_exists('mb_strimwidth')) { |
|
| 790 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 793 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
@@ -802,28 +802,28 @@ discard block |
||
| 802 | 802 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 803 | 803 | * @return int Returns the number of characters in string. |
| 804 | 804 | */ |
| 805 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 806 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 807 | - return mb_strlen( $str, $encoding ); |
|
| 805 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 806 | + if (function_exists('mb_strlen')) { |
|
| 807 | + return mb_strlen($str, $encoding); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - return strlen( $str ); |
|
| 810 | + return strlen($str); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 814 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 815 | - return mb_strtolower( $str, $encoding ); |
|
| 813 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 814 | + if (function_exists('mb_strtolower')) { |
|
| 815 | + return mb_strtolower($str, $encoding); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | - return strtolower( $str ); |
|
| 818 | + return strtolower($str); |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 822 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 823 | - return mb_strtoupper( $str, $encoding ); |
|
| 821 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 822 | + if (function_exists('mb_strtoupper')) { |
|
| 823 | + return mb_strtoupper($str, $encoding); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - return strtoupper( $str ); |
|
| 826 | + return strtoupper($str); |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | /** |
@@ -837,12 +837,12 @@ discard block |
||
| 837 | 837 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 838 | 838 | * @return int Returns the position of the first occurrence of search in the string. |
| 839 | 839 | */ |
| 840 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 841 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 842 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 840 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 841 | + if (function_exists('mb_strpos')) { |
|
| 842 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | - return strpos( $str, $find, $offset ); |
|
| 845 | + return strpos($str, $find, $offset); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
@@ -856,12 +856,12 @@ discard block |
||
| 856 | 856 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 857 | 857 | * @return int Returns the position of the last occurrence of search. |
| 858 | 858 | */ |
| 859 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 860 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 861 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 859 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 860 | + if (function_exists('mb_strrpos')) { |
|
| 861 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | - return strrpos( $str, $find, $offset ); |
|
| 864 | + return strrpos($str, $find, $offset); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | /** |
@@ -876,16 +876,16 @@ discard block |
||
| 876 | 876 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 877 | 877 | * @return string |
| 878 | 878 | */ |
| 879 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 880 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 881 | - if ( $length === null ) { |
|
| 882 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 879 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 880 | + if (function_exists('mb_substr')) { |
|
| 881 | + if ($length === null) { |
|
| 882 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 883 | 883 | } else { |
| 884 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 884 | + return mb_substr($str, $start, $length, $encoding); |
|
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - return substr( $str, $start, $length ); |
|
| 888 | + return substr($str, $start, $length); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | /** |
@@ -897,48 +897,48 @@ discard block |
||
| 897 | 897 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 898 | 898 | * @return string The width of string. |
| 899 | 899 | */ |
| 900 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 901 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 902 | - return mb_strwidth( $str, $encoding ); |
|
| 900 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 901 | + if (function_exists('mb_strwidth')) { |
|
| 902 | + return mb_strwidth($str, $encoding); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 905 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 909 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 910 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 908 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 909 | + if (function_exists('mb_strlen')) { |
|
| 910 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 911 | 911 | $str_end = ""; |
| 912 | 912 | |
| 913 | - if ( $lower_str_end ) { |
|
| 914 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 913 | + if ($lower_str_end) { |
|
| 914 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 915 | 915 | } else { |
| 916 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 916 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | return $first_letter . $str_end; |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | - return ucfirst( $str ); |
|
| 922 | + return ucfirst($str); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 926 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 927 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 925 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 926 | + if (function_exists('mb_convert_case')) { |
|
| 927 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | - return ucwords( $str ); |
|
| 930 | + return ucwords($str); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 934 | - $period = absint( $period ); |
|
| 933 | +function wpinv_period_in_days($period, $unit) { |
|
| 934 | + $period = absint($period); |
|
| 935 | 935 | |
| 936 | - if ( $period > 0 ) { |
|
| 937 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 936 | + if ($period > 0) { |
|
| 937 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 938 | 938 | $period = $period * 7; |
| 939 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 939 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 940 | 940 | $period = $period * 30; |
| 941 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 941 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 942 | 942 | $period = $period * 365; |
| 943 | 943 | } |
| 944 | 944 | } |
@@ -946,10 +946,10 @@ discard block |
||
| 946 | 946 | return $period; |
| 947 | 947 | } |
| 948 | 948 | |
| 949 | -if ( ! function_exists( 'cal_days_in_month' ) ) { |
|
| 949 | +if (!function_exists('cal_days_in_month')) { |
|
| 950 | 950 | // Fallback in case the calendar extension is not loaded in PHP |
| 951 | 951 | // Only supports Gregorian calendar |
| 952 | - function cal_days_in_month( $calendar, $month, $year ) { |
|
| 953 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
| 952 | + function cal_days_in_month($calendar, $month, $year) { |
|
| 953 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
| 954 | 954 | } |
| 955 | 955 | } |
| 956 | 956 | \ No newline at end of file |
@@ -488,6 +488,9 @@ discard block |
||
| 488 | 488 | return $invoice->get_description(); |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | +/** |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 491 | 494 | function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
| 492 | 495 | $invoice = new WPInv_Invoice( $invoice_id ); |
| 493 | 496 | return $invoice->get_currency(); |
@@ -521,6 +524,9 @@ discard block |
||
| 521 | 524 | return $invoice->get_gateway_title(); |
| 522 | 525 | } |
| 523 | 526 | |
| 527 | +/** |
|
| 528 | + * @return string |
|
| 529 | + */ |
|
| 524 | 530 | function wpinv_get_payment_transaction_id( $invoice_id ) { |
| 525 | 531 | $invoice = new WPInv_Invoice( $invoice_id ); |
| 526 | 532 | |
@@ -625,6 +631,9 @@ discard block |
||
| 625 | 631 | return $date_created; |
| 626 | 632 | } |
| 627 | 633 | |
| 634 | +/** |
|
| 635 | + * @return string |
|
| 636 | + */ |
|
| 628 | 637 | function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
| 629 | 638 | $invoice = new WPInv_Invoice( $invoice_id ); |
| 630 | 639 | |
@@ -1864,6 +1873,9 @@ discard block |
||
| 1864 | 1873 | return $display; |
| 1865 | 1874 | } |
| 1866 | 1875 | |
| 1876 | +/** |
|
| 1877 | + * @return integer |
|
| 1878 | + */ |
|
| 1867 | 1879 | function wpinv_get_invoice_id_by_key( $key ) { |
| 1868 | 1880 | global $wpdb; |
| 1869 | 1881 | |
@@ -7,40 +7,40 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_get_invoice_cart_id() { |
| 15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
| 16 | 16 | |
| 17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
| 17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
| 18 | 18 | return $wpinv_checkout['invoice_id']; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | return NULL; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 25 | - if ( empty( $invoice_data ) ) { |
|
| 24 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
| 25 | + if (empty($invoice_data)) { |
|
| 26 | 26 | return false; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
| 30 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0; |
|
| 29 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
| 30 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
| 33 | + if (empty($invoice_data['user_id'])) { |
|
| 34 | 34 | $invoice_data['user_id'] = get_current_user_id(); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 37 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 38 | 38 | |
| 39 | - if ( empty( $invoice_data['status'] ) ) { |
|
| 39 | + if (empty($invoice_data['status'])) { |
|
| 40 | 40 | $invoice_data['status'] = 'pending'; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ( empty( $invoice_data['ip'] ) ) { |
|
| 43 | + if (empty($invoice_data['ip'])) { |
|
| 44 | 44 | $invoice_data['ip'] = wpinv_get_ip(); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | 'status' => $invoice_data['status'], |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
| 55 | - if ( is_wp_error( $invoice ) ) { |
|
| 54 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
| 55 | + if (is_wp_error($invoice)) { |
|
| 56 | 56 | return $wp_error ? $invoice : 0; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
| 59 | + if (empty($invoice_data['invoice_id'])) { |
|
| 60 | 60 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -79,24 +79,24 @@ discard block |
||
| 79 | 79 | 'discount' => array(), |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
| 83 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
| 84 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
| 82 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
| 83 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
| 84 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
| 88 | + if (empty($invoice_data['user_info'])) { |
|
| 89 | 89 | $invoice_data['user_info'] = array(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
| 92 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
| 93 | 93 | |
| 94 | - if ( empty( $user_info['first_name'] ) ) { |
|
| 94 | + if (empty($user_info['first_name'])) { |
|
| 95 | 95 | $user_info['first_name'] = $default_user_info['first_name']; |
| 96 | 96 | $user_info['last_name'] = $default_user_info['last_name']; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ( empty( $user_info['country'] ) ) { |
|
| 99 | + if (empty($user_info['country'])) { |
|
| 100 | 100 | $user_info['country'] = $default_user_info['country']; |
| 101 | 101 | $user_info['state'] = $default_user_info['state']; |
| 102 | 102 | $user_info['city'] = $default_user_info['city']; |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | $user_info['phone'] = $default_user_info['phone']; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
| 108 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
| 109 | 109 | $user_info['discount'] = (array)$user_info['discount']; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Payment details |
| 113 | 113 | $payment_details = array(); |
| 114 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
| 114 | + if (!empty($invoice_data['payment_details'])) { |
|
| 115 | 115 | $default_payment_details = array( |
| 116 | 116 | 'gateway' => 'manual', |
| 117 | 117 | 'gateway_title' => '', |
@@ -119,56 +119,56 @@ discard block |
||
| 119 | 119 | 'transaction_id' => '', |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
| 122 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
| 123 | 123 | |
| 124 | - if ( empty( $payment_details['gateway'] ) ) { |
|
| 124 | + if (empty($payment_details['gateway'])) { |
|
| 125 | 125 | $payment_details['gateway'] = 'manual'; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( empty( $payment_details['currency'] ) ) { |
|
| 128 | + if (empty($payment_details['currency'])) { |
|
| 129 | 129 | $payment_details['currency'] = wpinv_get_default_country(); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
| 133 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
| 132 | + if (empty($payment_details['gateway_title'])) { |
|
| 133 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
| 138 | - |
|
| 139 | - if ( !empty( $payment_details ) ) { |
|
| 140 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
| 141 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 142 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
| 143 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $invoice->set( 'user_info', $user_info ); |
|
| 147 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
| 148 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
| 149 | - $invoice->set( 'address', $user_info['address'] ); |
|
| 150 | - $invoice->set( 'company', $user_info['company'] ); |
|
| 151 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
| 152 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
| 153 | - $invoice->set( 'city', $user_info['city'] ); |
|
| 154 | - $invoice->set( 'country', $user_info['country'] ); |
|
| 155 | - $invoice->set( 'state', $user_info['state'] ); |
|
| 156 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
| 157 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
| 158 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
| 159 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
| 160 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
| 161 | - |
|
| 162 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
| 163 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
| 164 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 165 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 166 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
| 167 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
| 137 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
| 138 | + |
|
| 139 | + if (!empty($payment_details)) { |
|
| 140 | + $invoice->set('currency', $payment_details['currency']); |
|
| 141 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 142 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
| 143 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $invoice->set('user_info', $user_info); |
|
| 147 | + $invoice->set('first_name', $user_info['first_name']); |
|
| 148 | + $invoice->set('last_name', $user_info['last_name']); |
|
| 149 | + $invoice->set('address', $user_info['address']); |
|
| 150 | + $invoice->set('company', $user_info['company']); |
|
| 151 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
| 152 | + $invoice->set('phone', $user_info['phone']); |
|
| 153 | + $invoice->set('city', $user_info['city']); |
|
| 154 | + $invoice->set('country', $user_info['country']); |
|
| 155 | + $invoice->set('state', $user_info['state']); |
|
| 156 | + $invoice->set('zip', $user_info['zip']); |
|
| 157 | + $invoice->set('discounts', $user_info['discount']); |
|
| 158 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
| 159 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
| 160 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
| 161 | + |
|
| 162 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
| 163 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
| 164 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 165 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 166 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
| 167 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
| 168 | 168 | |
| 169 | - $post_item = new WPInv_Item( $item_id ); |
|
| 170 | - if ( !empty( $post_item ) ) { |
|
| 171 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
| 169 | + $post_item = new WPInv_Item($item_id); |
|
| 170 | + if (!empty($post_item)) { |
|
| 171 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
| 172 | 172 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
| 173 | 173 | } else { |
| 174 | 174 | continue; |
@@ -178,253 +178,253 @@ discard block |
||
| 178 | 178 | 'name' => $name, |
| 179 | 179 | 'quantity' => $quantity, |
| 180 | 180 | 'item_price' => $item_price, |
| 181 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 182 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
| 183 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 184 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 185 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 181 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 182 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
| 183 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 184 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 185 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | - $invoice->add_item( $item_id, $args ); |
|
| 188 | + $invoice->add_item($item_id, $args); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
| 192 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
| 193 | 193 | |
| 194 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
| 195 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 194 | + if (isset($invoice_data['post_date'])) { |
|
| 195 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Invoice due date |
| 199 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 200 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 199 | + if (isset($invoice_data['due_date'])) { |
|
| 200 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $invoice->save(); |
| 204 | 204 | |
| 205 | 205 | // Add notes |
| 206 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 207 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 206 | + if (!empty($invoice_data['private_note'])) { |
|
| 207 | + $invoice->add_note($invoice_data['private_note']); |
|
| 208 | 208 | } |
| 209 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 210 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 209 | + if (!empty($invoice_data['user_note'])) { |
|
| 210 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
| 213 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
| 214 | 214 | |
| 215 | - if ( ! empty( $invoice->ID ) ) { |
|
| 215 | + if (!empty($invoice->ID)) { |
|
| 216 | 216 | global $wpi_userID, $wpinv_ip_address_country; |
| 217 | 217 | |
| 218 | 218 | $checkout_session = wpinv_get_checkout_session(); |
| 219 | 219 | |
| 220 | 220 | $data_session = array(); |
| 221 | 221 | $data_session['invoice_id'] = $invoice->ID; |
| 222 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 222 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 223 | 223 | |
| 224 | - wpinv_set_checkout_session( $data_session ); |
|
| 224 | + wpinv_set_checkout_session($data_session); |
|
| 225 | 225 | |
| 226 | 226 | $wpi_userID = (int)$invoice->get_user_id(); |
| 227 | 227 | |
| 228 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 228 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 229 | 229 | $_POST['state'] = $invoice->state; |
| 230 | 230 | |
| 231 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 232 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 231 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 232 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 233 | 233 | |
| 234 | 234 | $wpinv_ip_address_country = $invoice->country; |
| 235 | 235 | |
| 236 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 236 | + $invoice = $invoice->recalculate_totals(true); |
|
| 237 | 237 | |
| 238 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 238 | + wpinv_set_checkout_session($checkout_session); |
|
| 239 | 239 | |
| 240 | 240 | return $invoice; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if ( $wp_error ) { |
|
| 244 | - if ( is_wp_error( $invoice ) ) { |
|
| 243 | + if ($wp_error) { |
|
| 244 | + if (is_wp_error($invoice)) { |
|
| 245 | 245 | return $invoice; |
| 246 | 246 | } else { |
| 247 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
| 247 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
| 248 | 248 | } |
| 249 | 249 | } else { |
| 250 | 250 | return 0; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 255 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
| 254 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
| 255 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
| 256 | 256 | |
| 257 | - if ( !$invoice_ID ) { |
|
| 258 | - if ( $wp_error ) { |
|
| 259 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
| 257 | + if (!$invoice_ID) { |
|
| 258 | + if ($wp_error) { |
|
| 259 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
| 260 | 260 | } |
| 261 | 261 | return 0; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
| 264 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
| 265 | 265 | |
| 266 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
| 266 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
| 267 | 267 | |
| 268 | - if ( empty( $invoice->ID ) ) { |
|
| 269 | - if ( $wp_error ) { |
|
| 270 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
| 268 | + if (empty($invoice->ID)) { |
|
| 269 | + if ($wp_error) { |
|
| 270 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
| 271 | 271 | } |
| 272 | 272 | return 0; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) { |
|
| 276 | - if ( $wp_error ) { |
|
| 277 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
| 275 | + if (!$invoice->has_status(array('wpi-pending'))) { |
|
| 276 | + if ($wp_error) { |
|
| 277 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
| 278 | 278 | } |
| 279 | 279 | return 0; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // Invoice status |
| 283 | - if ( !empty( $invoice_data['status'] ) ) { |
|
| 284 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
| 283 | + if (!empty($invoice_data['status'])) { |
|
| 284 | + $invoice->set('status', $invoice_data['status']); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Invoice date |
| 288 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
| 289 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 288 | + if (!empty($invoice_data['post_date'])) { |
|
| 289 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Invoice due date |
| 293 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 294 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 293 | + if (isset($invoice_data['due_date'])) { |
|
| 294 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Invoice IP address |
| 298 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
| 299 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
| 298 | + if (!empty($invoice_data['ip'])) { |
|
| 299 | + $invoice->set('ip', $invoice_data['ip']); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // User info |
| 303 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
| 304 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
| 303 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
| 304 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
| 305 | 305 | |
| 306 | - if ( $discounts = $invoice->get_discounts() ) { |
|
| 306 | + if ($discounts = $invoice->get_discounts()) { |
|
| 307 | 307 | $set_discount = $discounts; |
| 308 | 308 | } else { |
| 309 | 309 | $set_discount = ''; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // Manage discount |
| 313 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
| 313 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
| 314 | 314 | // Remove discount |
| 315 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
| 315 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
| 316 | 316 | $set_discount = ''; |
| 317 | 317 | } else { |
| 318 | 318 | $set_discount = $invoice_data['user_info']['discount']; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $invoice->set( 'discounts', $set_discount ); |
|
| 321 | + $invoice->set('discounts', $set_discount); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | $user_info['discount'] = $set_discount; |
| 325 | 325 | |
| 326 | - $invoice->set( 'user_info', $user_info ); |
|
| 326 | + $invoice->set('user_info', $user_info); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
| 330 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
| 329 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
| 330 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
| 331 | 331 | |
| 332 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
| 333 | - foreach ( $remove_items as $item ) { |
|
| 334 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 335 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 336 | - if ( empty( $item_id ) ) { |
|
| 332 | + if (!empty($remove_items[0]['id'])) { |
|
| 333 | + foreach ($remove_items as $item) { |
|
| 334 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 335 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 336 | + if (empty($item_id)) { |
|
| 337 | 337 | continue; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
| 341 | - if ( $item_id == $cart_item['id'] ) { |
|
| 340 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
| 341 | + if ($item_id == $cart_item['id']) { |
|
| 342 | 342 | $args = array( |
| 343 | 343 | 'id' => $item_id, |
| 344 | 344 | 'quantity' => $quantity, |
| 345 | 345 | 'cart_index' => $cart_index |
| 346 | 346 | ); |
| 347 | 347 | |
| 348 | - $invoice->remove_item( $item_id, $args ); |
|
| 348 | + $invoice->remove_item($item_id, $args); |
|
| 349 | 349 | break; |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
| 355 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
| 356 | 356 | |
| 357 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
| 358 | - foreach ( $add_items as $item ) { |
|
| 359 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 360 | - $post_item = new WPInv_Item( $item_id ); |
|
| 361 | - if ( empty( $post_item ) ) { |
|
| 357 | + if (!empty($add_items[0]['id'])) { |
|
| 358 | + foreach ($add_items as $item) { |
|
| 359 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 360 | + $post_item = new WPInv_Item($item_id); |
|
| 361 | + if (empty($post_item)) { |
|
| 362 | 362 | continue; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | $valid_item = true; |
| 366 | - if ( !empty( $recurring_item ) ) { |
|
| 367 | - if ( $recurring_item->ID != $item_id ) { |
|
| 366 | + if (!empty($recurring_item)) { |
|
| 367 | + if ($recurring_item->ID != $item_id) { |
|
| 368 | 368 | $valid_item = false; |
| 369 | 369 | } |
| 370 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 370 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 371 | 371 | $valid_item = false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if ( !$valid_item ) { |
|
| 375 | - if ( $wp_error ) { |
|
| 376 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ) ); |
|
| 374 | + if (!$valid_item) { |
|
| 375 | + if ($wp_error) { |
|
| 376 | + return new WP_Error('invalid_invoice_item', __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing')); |
|
| 377 | 377 | } |
| 378 | 378 | return 0; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 382 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
| 383 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
| 381 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 382 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
| 383 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
| 384 | 384 | |
| 385 | 385 | $args = array( |
| 386 | 386 | 'name' => $name, |
| 387 | 387 | 'quantity' => $quantity, |
| 388 | 388 | 'item_price' => $item_price, |
| 389 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 390 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
| 391 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 392 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 393 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 389 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 390 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
| 391 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 392 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 393 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 394 | 394 | ); |
| 395 | 395 | |
| 396 | - $invoice->add_item( $item_id, $args ); |
|
| 396 | + $invoice->add_item($item_id, $args); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | // Payment details |
| 402 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
| 403 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
| 404 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 402 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
| 403 | + if (!empty($payment_details['gateway'])) { |
|
| 404 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
| 408 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 407 | + if (!empty($payment_details['transaction_id'])) { |
|
| 408 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
| 412 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
| 413 | 413 | |
| 414 | 414 | // Parent invoice |
| 415 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
| 416 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
| 415 | + if (!empty($invoice_data['parent'])) { |
|
| 416 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | // Save invoice data. |
| 420 | 420 | $invoice->save(); |
| 421 | 421 | |
| 422 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
| 423 | - if ( $wp_error ) { |
|
| 424 | - if ( is_wp_error( $invoice ) ) { |
|
| 422 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
| 423 | + if ($wp_error) { |
|
| 424 | + if (is_wp_error($invoice)) { |
|
| 425 | 425 | return $invoice; |
| 426 | 426 | } else { |
| 427 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
| 427 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
| 428 | 428 | } |
| 429 | 429 | } else { |
| 430 | 430 | return 0; |
@@ -432,13 +432,13 @@ discard block |
||
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // Add private note |
| 435 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 436 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 435 | + if (!empty($invoice_data['private_note'])) { |
|
| 436 | + $invoice->add_note($invoice_data['private_note']); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Add user note |
| 440 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 441 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 440 | + if (!empty($invoice_data['user_note'])) { |
|
| 441 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | global $wpi_userID, $wpinv_ip_address_country; |
@@ -447,445 +447,445 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | $data_session = array(); |
| 449 | 449 | $data_session['invoice_id'] = $invoice->ID; |
| 450 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 450 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 451 | 451 | |
| 452 | - wpinv_set_checkout_session( $data_session ); |
|
| 452 | + wpinv_set_checkout_session($data_session); |
|
| 453 | 453 | |
| 454 | 454 | $wpi_userID = (int)$invoice->get_user_id(); |
| 455 | 455 | |
| 456 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 456 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 457 | 457 | $_POST['state'] = $invoice->state; |
| 458 | 458 | |
| 459 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 460 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 459 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 460 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 461 | 461 | |
| 462 | 462 | $wpinv_ip_address_country = $invoice->country; |
| 463 | 463 | |
| 464 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 464 | + $invoice = $invoice->recalculate_totals(true); |
|
| 465 | 465 | |
| 466 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
| 466 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
| 467 | 467 | |
| 468 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 468 | + wpinv_set_checkout_session($checkout_session); |
|
| 469 | 469 | |
| 470 | 470 | return $invoice; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
| 474 | - if ( $cart && empty( $invoice_id ) ) { |
|
| 473 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
| 474 | + if ($cart && empty($invoice_id)) { |
|
| 475 | 475 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 478 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 479 | 479 | return $invoice; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
| 483 | - return wpinv_get_invoice( $invoice_id, true ); |
|
| 482 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
| 483 | + return wpinv_get_invoice($invoice_id, true); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
| 487 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 486 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
| 487 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 488 | 488 | return $invoice->get_description(); |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
| 492 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 491 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
| 492 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 493 | 493 | return $invoice->get_currency(); |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
| 497 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 496 | +function wpinv_get_payment_user_email($invoice_id) { |
|
| 497 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 498 | 498 | return $invoice->get_email(); |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | -function wpinv_get_user_id( $invoice_id ) { |
|
| 502 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 501 | +function wpinv_get_user_id($invoice_id) { |
|
| 502 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 503 | 503 | return $invoice->get_user_id(); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
| 507 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 506 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
| 507 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 508 | 508 | |
| 509 | - return $invoice->get_status( $return_label ); |
|
| 509 | + return $invoice->get_status($return_label); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
| 513 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 512 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
| 513 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 514 | 514 | |
| 515 | - return $invoice->get_gateway( $return_label ); |
|
| 515 | + return $invoice->get_gateway($return_label); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
| 519 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 518 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
| 519 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 520 | 520 | |
| 521 | 521 | return $invoice->get_gateway_title(); |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
| 525 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 524 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
| 525 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 526 | 526 | |
| 527 | 527 | return $invoice->get_transaction_id(); |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
| 530 | +function wpinv_get_id_by_transaction_id($key) { |
|
| 531 | 531 | global $wpdb; |
| 532 | 532 | |
| 533 | - $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 ) ); |
|
| 533 | + $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)); |
|
| 534 | 534 | |
| 535 | - if ( $invoice_id != NULL ) |
|
| 535 | + if ($invoice_id != NULL) |
|
| 536 | 536 | return $invoice_id; |
| 537 | 537 | |
| 538 | 538 | return 0; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 542 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 541 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 542 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 543 | 543 | |
| 544 | - return $invoice->get_meta( $meta_key, $single ); |
|
| 544 | + return $invoice->get_meta($meta_key, $single); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 548 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 547 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 548 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 549 | 549 | |
| 550 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
| 550 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
| 554 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 553 | +function wpinv_get_items($invoice_id = 0) { |
|
| 554 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 555 | 555 | |
| 556 | 556 | $items = $invoice->get_items(); |
| 557 | 557 | $invoice_currency = $invoice->get_currency(); |
| 558 | 558 | |
| 559 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
| 560 | - foreach ( $items as $key => $item ) { |
|
| 559 | + if (!empty($items) && is_array($items)) { |
|
| 560 | + foreach ($items as $key => $item) { |
|
| 561 | 561 | $items[$key]['currency'] = $invoice_currency; |
| 562 | 562 | |
| 563 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
| 563 | + if (!isset($cart_item['subtotal'])) { |
|
| 564 | 564 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
| 569 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
| 573 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 572 | +function wpinv_get_fees($invoice_id = 0) { |
|
| 573 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 574 | 574 | $fees = $invoice->get_fees(); |
| 575 | 575 | |
| 576 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
| 576 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
| 580 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 579 | +function wpinv_get_invoice_ip($invoice_id) { |
|
| 580 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 581 | 581 | return $invoice->get_ip(); |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
| 585 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 584 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
| 585 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 586 | 586 | return $invoice->get_user_info(); |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
| 590 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 589 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
| 590 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 591 | 591 | |
| 592 | - return $invoice->get_subtotal( $currency ); |
|
| 592 | + return $invoice->get_subtotal($currency); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
| 596 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 595 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
| 596 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 597 | 597 | |
| 598 | - return $invoice->get_tax( $currency ); |
|
| 598 | + return $invoice->get_tax($currency); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
| 602 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 601 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
| 602 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 603 | 603 | |
| 604 | - return $invoice->get_discount( $currency, $dash ); |
|
| 604 | + return $invoice->get_discount($currency, $dash); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
| 608 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 607 | +function wpinv_discount_code($invoice_id = 0) { |
|
| 608 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 609 | 609 | |
| 610 | 610 | return $invoice->get_discount_code(); |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
| 614 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 613 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
| 614 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 615 | 615 | |
| 616 | - return $invoice->get_total( $currency ); |
|
| 616 | + return $invoice->get_total($currency); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
| 620 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 619 | +function wpinv_get_date_created($invoice_id = 0) { |
|
| 620 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 621 | 621 | |
| 622 | 622 | $date_created = $invoice->get_created_date(); |
| 623 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
| 623 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
| 624 | 624 | |
| 625 | 625 | return $date_created; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
| 629 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 628 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
| 629 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 630 | 630 | |
| 631 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 631 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 632 | 632 | $date_completed = $invoice->get_completed_date(); |
| 633 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
| 634 | - if ( $invoice_date == '' ) { |
|
| 633 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
| 634 | + if ($invoice_date == '') { |
|
| 635 | 635 | $date_created = $invoice->get_created_date(); |
| 636 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
| 636 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | return $invoice_date; |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
| 643 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 642 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
| 643 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 644 | 644 | |
| 645 | 645 | return $invoice->vat_number; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
| 649 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 648 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
| 649 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 650 | 650 | |
| 651 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
| 651 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 654 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 655 | 655 | global $invoicing; |
| 656 | 656 | |
| 657 | - if ( empty( $invoice_id ) ) { |
|
| 657 | + if (empty($invoice_id)) { |
|
| 658 | 658 | return NULL; |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
| 661 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
| 662 | 662 | |
| 663 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
| 663 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
| 667 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 666 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
| 667 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 668 | 668 | return $invoice->get_key(); |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
| 672 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 671 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
| 672 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 673 | 673 | return $invoice->get_number(); |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
| 676 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
| 677 | 677 | $cart_items = wpinv_get_cart_content_details(); |
| 678 | 678 | $items = array(); |
| 679 | 679 | |
| 680 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 680 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 681 | 681 | |
| 682 | - if( $cart_items ) { |
|
| 682 | + if ($cart_items) { |
|
| 683 | 683 | |
| 684 | - foreach( $cart_items as $item ) { |
|
| 684 | + foreach ($cart_items as $item) { |
|
| 685 | 685 | |
| 686 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
| 687 | - $items[] = $item; |
|
| 686 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 687 | + $items[] = $item; |
|
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 692 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 693 | 693 | |
| 694 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
| 694 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
| 697 | +function wpinv_get_cart_items_subtotal($items) { |
|
| 698 | 698 | $subtotal = 0.00; |
| 699 | 699 | |
| 700 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
| 701 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
| 700 | + if (is_array($items) && !empty($items)) { |
|
| 701 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
| 702 | 702 | |
| 703 | - if( is_array( $prices ) ) { |
|
| 704 | - $subtotal = array_sum( $prices ); |
|
| 703 | + if (is_array($prices)) { |
|
| 704 | + $subtotal = array_sum($prices); |
|
| 705 | 705 | } else { |
| 706 | 706 | $subtotal = 0.00; |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | - if( $subtotal < 0 ) { |
|
| 709 | + if ($subtotal < 0) { |
|
| 710 | 710 | $subtotal = 0.00; |
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
| 714 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
| 718 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 719 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 717 | +function wpinv_get_cart_subtotal($items = array()) { |
|
| 718 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 719 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 720 | 720 | |
| 721 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
| 721 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | -function wpinv_cart_subtotal( $items = array() ) { |
|
| 725 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
| 724 | +function wpinv_cart_subtotal($items = array()) { |
|
| 725 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
| 726 | 726 | |
| 727 | 727 | return $price; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
| 731 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
| 732 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
| 733 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
| 730 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
| 731 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
| 732 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
| 733 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
| 734 | 734 | $fees = (float)wpinv_get_cart_fee_total(); |
| 735 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 735 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 736 | 736 | $total = 0; |
| 737 | 737 | } else { |
| 738 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 738 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - if ( $total < 0 ) { |
|
| 741 | + if ($total < 0) { |
|
| 742 | 742 | $total = 0.00; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
| 745 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
| 746 | 746 | |
| 747 | - return wpinv_sanitize_amount( $total ); |
|
| 747 | + return wpinv_sanitize_amount($total); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
| 750 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
| 751 | 751 | global $cart_total; |
| 752 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
| 753 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
| 752 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
| 753 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
| 754 | 754 | |
| 755 | 755 | $cart_total = $total; |
| 756 | 756 | |
| 757 | - if ( !$echo ) { |
|
| 757 | + if (!$echo) { |
|
| 758 | 758 | return $total; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | echo $total; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | -function wpinv_get_cart_tax( $items = array() ) { |
|
| 764 | +function wpinv_get_cart_tax($items = array()) { |
|
| 765 | 765 | $cart_tax = 0; |
| 766 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 766 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 767 | 767 | |
| 768 | - if ( $items ) { |
|
| 769 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
| 768 | + if ($items) { |
|
| 769 | + $taxes = wp_list_pluck($items, 'tax'); |
|
| 770 | 770 | |
| 771 | - if( is_array( $taxes ) ) { |
|
| 772 | - $cart_tax = array_sum( $taxes ); |
|
| 771 | + if (is_array($taxes)) { |
|
| 772 | + $cart_tax = array_sum($taxes); |
|
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | $cart_tax += wpinv_get_cart_fee_tax(); |
| 777 | 777 | |
| 778 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
| 778 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
| 782 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
| 783 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
| 781 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
| 782 | + $cart_tax = wpinv_get_cart_tax($items); |
|
| 783 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
| 784 | 784 | |
| 785 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
| 785 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
| 786 | 786 | |
| 787 | - if ( !$echo ) { |
|
| 787 | + if (!$echo) { |
|
| 788 | 788 | return $tax; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | echo $tax; |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
| 794 | +function wpinv_get_cart_discount_code($items = array()) { |
|
| 795 | 795 | $invoice = wpinv_get_invoice_cart(); |
| 796 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
| 796 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
| 797 | 797 | |
| 798 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
| 798 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
| 802 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
| 801 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
| 802 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
| 803 | 803 | |
| 804 | - if ( $cart_discount_code != '' ) { |
|
| 804 | + if ($cart_discount_code != '') { |
|
| 805 | 805 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
| 808 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
| 809 | 809 | |
| 810 | - if ( !$echo ) { |
|
| 810 | + if (!$echo) { |
|
| 811 | 811 | return $discount_code; |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | echo $discount_code; |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | -function wpinv_get_cart_discount( $items = array() ) { |
|
| 817 | +function wpinv_get_cart_discount($items = array()) { |
|
| 818 | 818 | $invoice = wpinv_get_invoice_cart(); |
| 819 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
| 819 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
| 820 | 820 | |
| 821 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
| 821 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
| 825 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
| 826 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
| 824 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
| 825 | + $cart_discount = wpinv_get_cart_discount($items); |
|
| 826 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
| 827 | 827 | |
| 828 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
| 828 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
| 829 | 829 | |
| 830 | - if ( !$echo ) { |
|
| 830 | + if (!$echo) { |
|
| 831 | 831 | return $discount; |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | echo $discount; |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
| 838 | - $item = new WPInv_Item( $item_id ); |
|
| 837 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
| 838 | + $item = new WPInv_Item($item_id); |
|
| 839 | 839 | |
| 840 | - return $item->get_fees( $type, $item_id ); |
|
| 840 | + return $item->get_fees($type, $item_id); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | function wpinv_get_cart_fee_total() { |
| 844 | - $total = 0; |
|
| 844 | + $total = 0; |
|
| 845 | 845 | $fees = wpinv_get_cart_fees(); |
| 846 | 846 | |
| 847 | - if ( $fees ) { |
|
| 848 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 847 | + if ($fees) { |
|
| 848 | + foreach ($fees as $fee_id => $fee) { |
|
| 849 | 849 | $total += $fee['amount']; |
| 850 | 850 | } |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
| 853 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | function wpinv_get_cart_fee_tax() { |
| 857 | 857 | $tax = 0; |
| 858 | 858 | $fees = wpinv_get_cart_fees(); |
| 859 | 859 | |
| 860 | - if ( $fees ) { |
|
| 861 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 862 | - if( ! empty( $fee['no_tax'] ) ) { |
|
| 860 | + if ($fees) { |
|
| 861 | + foreach ($fees as $fee_id => $fee) { |
|
| 862 | + if (!empty($fee['no_tax'])) { |
|
| 863 | 863 | continue; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
| 866 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
| 867 | 867 | } |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
| 870 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | function wpinv_cart_has_recurring_item() { |
| 874 | 874 | $cart_items = wpinv_get_cart_contents(); |
| 875 | 875 | |
| 876 | - if ( empty( $cart_items ) ) { |
|
| 876 | + if (empty($cart_items)) { |
|
| 877 | 877 | return false; |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | $has_subscription = false; |
| 881 | - foreach( $cart_items as $cart_item ) { |
|
| 882 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 881 | + foreach ($cart_items as $cart_item) { |
|
| 882 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 883 | 883 | $has_subscription = true; |
| 884 | 884 | break; |
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
| 888 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | function wpinv_cart_has_free_trial() { |
@@ -893,94 +893,94 @@ discard block |
||
| 893 | 893 | |
| 894 | 894 | $free_trial = false; |
| 895 | 895 | |
| 896 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 896 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 897 | 897 | $free_trial = true; |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
| 900 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | function wpinv_get_cart_contents() { |
| 904 | 904 | $cart_details = wpinv_get_cart_details(); |
| 905 | 905 | |
| 906 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
| 906 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | function wpinv_get_cart_content_details() { |
| 910 | 910 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 911 | 911 | $cart_items = wpinv_get_cart_contents(); |
| 912 | 912 | |
| 913 | - if ( empty( $cart_items ) ) { |
|
| 913 | + if (empty($cart_items)) { |
|
| 914 | 914 | return false; |
| 915 | 915 | } |
| 916 | 916 | $invoice = wpinv_get_invoice_cart(); |
| 917 | 917 | |
| 918 | 918 | $details = array(); |
| 919 | - $length = count( $cart_items ) - 1; |
|
| 919 | + $length = count($cart_items) - 1; |
|
| 920 | 920 | |
| 921 | - if ( empty( $_POST['country'] ) ) { |
|
| 921 | + if (empty($_POST['country'])) { |
|
| 922 | 922 | $_POST['country'] = $invoice->country; |
| 923 | 923 | } |
| 924 | - if ( !isset( $_POST['state'] ) ) { |
|
| 924 | + if (!isset($_POST['state'])) { |
|
| 925 | 925 | $_POST['state'] = $invoice->state; |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | - foreach( $cart_items as $key => $item ) { |
|
| 929 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 930 | - if ( empty( $item_id ) ) { |
|
| 928 | + foreach ($cart_items as $key => $item) { |
|
| 929 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 930 | + if (empty($item_id)) { |
|
| 931 | 931 | continue; |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | $wpi_current_id = $invoice->ID; |
| 935 | 935 | $wpi_item_id = $item_id; |
| 936 | 936 | |
| 937 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
| 937 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
| 938 | 938 | $item_price = $item['custom_price']; |
| 939 | 939 | } else { |
| 940 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
| 940 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
| 941 | 941 | $item_price = $item['item_price']; |
| 942 | 942 | } else { |
| 943 | - $item_price = wpinv_get_item_price( $item_id ); |
|
| 943 | + $item_price = wpinv_get_item_price($item_id); |
|
| 944 | 944 | } |
| 945 | 945 | } |
| 946 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
| 947 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
| 948 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
| 949 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
| 946 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
| 947 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
| 948 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
| 949 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
| 950 | 950 | |
| 951 | 951 | $subtotal = $item_price * $quantity; |
| 952 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
| 953 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
| 954 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
| 952 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
| 953 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
| 954 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
| 955 | 955 | |
| 956 | - if ( wpinv_prices_include_tax() ) { |
|
| 957 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 956 | + if (wpinv_prices_include_tax()) { |
|
| 957 | + $subtotal -= wpinv_round_amount($tax); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - $total = $subtotal - $discount + $tax; |
|
| 960 | + $total = $subtotal - $discount + $tax; |
|
| 961 | 961 | |
| 962 | 962 | // Do not allow totals to go negatve |
| 963 | - if( $total < 0 ) { |
|
| 963 | + if ($total < 0) { |
|
| 964 | 964 | $total = 0; |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | - $details[ $key ] = array( |
|
| 967 | + $details[$key] = array( |
|
| 968 | 968 | 'id' => $item_id, |
| 969 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
| 970 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 971 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 969 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
| 970 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 971 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 972 | 972 | 'quantity' => $quantity, |
| 973 | - 'discount' => wpinv_round_amount( $discount ), |
|
| 974 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 975 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 976 | - 'price' => wpinv_round_amount( $total ), |
|
| 973 | + 'discount' => wpinv_round_amount($discount), |
|
| 974 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 975 | + 'tax' => wpinv_round_amount($tax), |
|
| 976 | + 'price' => wpinv_round_amount($total), |
|
| 977 | 977 | 'vat_rates_class' => $tax_class, |
| 978 | 978 | 'vat_rate' => $tax_rate, |
| 979 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 979 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 980 | 980 | 'fees' => $fees, |
| 981 | 981 | ); |
| 982 | 982 | |
| 983 | - if ( $wpinv_is_last_cart_item ) { |
|
| 983 | + if ($wpinv_is_last_cart_item) { |
|
| 984 | 984 | $wpinv_is_last_cart_item = false; |
| 985 | 985 | $wpinv_flat_discount_total = 0.00; |
| 986 | 986 | } |
@@ -989,60 +989,60 @@ discard block |
||
| 989 | 989 | return $details; |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
| 992 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
| 993 | 993 | global $ajax_cart_details; |
| 994 | 994 | |
| 995 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 996 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
| 995 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 996 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
| 997 | 997 | |
| 998 | 998 | $invoice_currency = $invoice->currency; |
| 999 | 999 | |
| 1000 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
| 1001 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1002 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
| 1000 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
| 1001 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1002 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
| 1003 | 1003 | |
| 1004 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
| 1005 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
| 1004 | + if (!isset($cart_item['subtotal'])) { |
|
| 1005 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
| 1010 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
| 1014 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
| 1013 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
| 1014 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
| 1015 | 1015 | return; |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1018 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1019 | 1019 | |
| 1020 | - $old_status = wpinv_status_nicename( $old_status ); |
|
| 1021 | - $new_status = wpinv_status_nicename( $new_status ); |
|
| 1020 | + $old_status = wpinv_status_nicename($old_status); |
|
| 1021 | + $new_status = wpinv_status_nicename($new_status); |
|
| 1022 | 1022 | |
| 1023 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
| 1023 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
| 1024 | 1024 | |
| 1025 | 1025 | // Add note |
| 1026 | - return $invoice->add_note( $status_change, false, false, true ); |
|
| 1026 | + return $invoice->add_note($status_change, false, false, true); |
|
| 1027 | 1027 | } |
| 1028 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
| 1028 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
| 1029 | 1029 | |
| 1030 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
| 1030 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
| 1031 | 1031 | global $wpi_has_free_trial; |
| 1032 | 1032 | |
| 1033 | 1033 | $wpi_has_free_trial = false; |
| 1034 | 1034 | |
| 1035 | - if ( $old_status == 'publish' ) { |
|
| 1035 | + if ($old_status == 'publish') { |
|
| 1036 | 1036 | return; // Make sure that payments are only paid once |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | // Make sure the payment completion is only processed when new status is paid |
| 1040 | - if ( $new_status != 'publish' ) { |
|
| 1040 | + if ($new_status != 'publish') { |
|
| 1041 | 1041 | return; |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 1045 | - if ( empty( $invoice ) ) { |
|
| 1044 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 1045 | + if (empty($invoice)) { |
|
| 1046 | 1046 | return; |
| 1047 | 1047 | } |
| 1048 | 1048 | |
@@ -1050,58 +1050,58 @@ discard block |
||
| 1050 | 1050 | $completed_date = $invoice->completed_date; |
| 1051 | 1051 | $cart_details = $invoice->cart_details; |
| 1052 | 1052 | |
| 1053 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
| 1053 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
| 1054 | 1054 | |
| 1055 | - if ( is_array( $cart_details ) ) { |
|
| 1055 | + if (is_array($cart_details)) { |
|
| 1056 | 1056 | // Increase purchase count and earnings |
| 1057 | - foreach ( $cart_details as $cart_index => $item ) { |
|
| 1057 | + foreach ($cart_details as $cart_index => $item) { |
|
| 1058 | 1058 | // Ensure these actions only run once, ever |
| 1059 | - if ( empty( $completed_date ) ) { |
|
| 1060 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
| 1059 | + if (empty($completed_date)) { |
|
| 1060 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
| 1061 | 1061 | } |
| 1062 | 1062 | } |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // Check for discount codes and increment their use counts |
| 1066 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
| 1067 | - if( ! empty( $discounts ) ) { |
|
| 1068 | - foreach( $discounts as $code ) { |
|
| 1069 | - wpinv_increase_discount_usage( $code ); |
|
| 1066 | + if ($discounts = $invoice->get_discounts(true)) { |
|
| 1067 | + if (!empty($discounts)) { |
|
| 1068 | + foreach ($discounts as $code) { |
|
| 1069 | + wpinv_increase_discount_usage($code); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | } |
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | // Ensure this action only runs once ever |
| 1075 | - if( empty( $completed_date ) ) { |
|
| 1075 | + if (empty($completed_date)) { |
|
| 1076 | 1076 | // Save the completed date |
| 1077 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
| 1077 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
| 1078 | 1078 | $invoice->save(); |
| 1079 | 1079 | |
| 1080 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
| 1080 | + do_action('wpinv_complete_payment', $invoice_id); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | // Empty the shopping cart |
| 1084 | 1084 | wpinv_empty_cart(); |
| 1085 | 1085 | } |
| 1086 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
| 1086 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
| 1087 | 1087 | |
| 1088 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
| 1089 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
| 1088 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
| 1089 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
| 1090 | 1090 | |
| 1091 | - if ( empty( $invoice ) ) { |
|
| 1091 | + if (empty($invoice)) { |
|
| 1092 | 1092 | return false; |
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | - return $invoice->update_status( $new_status ); |
|
| 1095 | + return $invoice->update_status($new_status); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
| 1098 | +function wpinv_cart_has_fees($type = 'all') { |
|
| 1099 | 1099 | return false; |
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | 1102 | function wpinv_validate_checkout_fields() { |
| 1103 | 1103 | // Check if there is $_POST |
| 1104 | - if ( empty( $_POST ) ) { |
|
| 1104 | + if (empty($_POST)) { |
|
| 1105 | 1105 | return false; |
| 1106 | 1106 | } |
| 1107 | 1107 | |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | ); |
| 1114 | 1114 | |
| 1115 | 1115 | // Validate agree to terms |
| 1116 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
| 1116 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
| 1117 | 1117 | wpinv_checkout_validate_agree_to_terms(); |
| 1118 | 1118 | } |
| 1119 | 1119 | |
@@ -1129,26 +1129,26 @@ discard block |
||
| 1129 | 1129 | |
| 1130 | 1130 | $invoice = wpinv_get_invoice_cart(); |
| 1131 | 1131 | $has_subscription = $invoice->is_recurring(); |
| 1132 | - if ( empty( $invoice ) ) { |
|
| 1133 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
| 1132 | + if (empty($invoice)) { |
|
| 1133 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
| 1134 | 1134 | return $gateway; |
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | // Check if a gateway value is present |
| 1138 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
| 1139 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
| 1138 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
| 1139 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
| 1140 | 1140 | |
| 1141 | - if ( $invoice->is_free() ) { |
|
| 1141 | + if ($invoice->is_free()) { |
|
| 1142 | 1142 | $gateway = 'manual'; |
| 1143 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
| 1144 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
| 1145 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 1146 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
| 1143 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
| 1144 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
| 1145 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
| 1146 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
| 1151 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
| 1150 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
| 1151 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | return $gateway; |
@@ -1162,10 +1162,10 @@ discard block |
||
| 1162 | 1162 | |
| 1163 | 1163 | $error = false; |
| 1164 | 1164 | // If we have discounts, loop through them |
| 1165 | - if ( ! empty( $discounts ) ) { |
|
| 1166 | - foreach ( $discounts as $discount ) { |
|
| 1165 | + if (!empty($discounts)) { |
|
| 1166 | + foreach ($discounts as $discount) { |
|
| 1167 | 1167 | // Check if valid |
| 1168 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
| 1168 | + if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) { |
|
| 1169 | 1169 | // Discount is not valid |
| 1170 | 1170 | $error = true; |
| 1171 | 1171 | } |
@@ -1175,20 +1175,20 @@ discard block |
||
| 1175 | 1175 | return NULL; |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | - if ( $error && !wpinv_get_errors() ) { |
|
| 1179 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
| 1178 | + if ($error && !wpinv_get_errors()) { |
|
| 1179 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | - return implode( ',', $discounts ); |
|
| 1182 | + return implode(',', $discounts); |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | function wpinv_checkout_validate_cc() { |
| 1186 | 1186 | $card_data = wpinv_checkout_get_cc_info(); |
| 1187 | 1187 | |
| 1188 | 1188 | // Validate the card zip |
| 1189 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
| 1190 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
| 1191 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
| 1189 | + if (!empty($card_data['wpinv_zip'])) { |
|
| 1190 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
| 1191 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
| 1192 | 1192 | } |
| 1193 | 1193 | } |
| 1194 | 1194 | |
@@ -1198,28 +1198,28 @@ discard block |
||
| 1198 | 1198 | |
| 1199 | 1199 | function wpinv_checkout_get_cc_info() { |
| 1200 | 1200 | $cc_info = array(); |
| 1201 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 1202 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 1203 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 1204 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 1205 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 1206 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 1207 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 1208 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 1209 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 1210 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 1201 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
| 1202 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
| 1203 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
| 1204 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
| 1205 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
| 1206 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
| 1207 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
| 1208 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
| 1209 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
| 1210 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
| 1211 | 1211 | |
| 1212 | 1212 | // Return cc info |
| 1213 | 1213 | return $cc_info; |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 1216 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 1217 | 1217 | $ret = false; |
| 1218 | 1218 | |
| 1219 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
| 1219 | + if (empty($zip) || empty($country_code)) |
|
| 1220 | 1220 | return $ret; |
| 1221 | 1221 | |
| 1222 | - $country_code = strtoupper( $country_code ); |
|
| 1222 | + $country_code = strtoupper($country_code); |
|
| 1223 | 1223 | |
| 1224 | 1224 | $zip_regex = array( |
| 1225 | 1225 | "AD" => "AD\d{3}", |
@@ -1379,17 +1379,17 @@ discard block |
||
| 1379 | 1379 | "ZM" => "\d{5}" |
| 1380 | 1380 | ); |
| 1381 | 1381 | |
| 1382 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
| 1382 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
| 1383 | 1383 | $ret = true; |
| 1384 | 1384 | |
| 1385 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1385 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | function wpinv_checkout_validate_agree_to_terms() { |
| 1389 | 1389 | // Validate agree to terms |
| 1390 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
| 1390 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
| 1391 | 1391 | // User did not agree |
| 1392 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
| 1392 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
| 1393 | 1393 | } |
| 1394 | 1394 | } |
| 1395 | 1395 | |
@@ -1401,40 +1401,40 @@ discard block |
||
| 1401 | 1401 | ); |
| 1402 | 1402 | |
| 1403 | 1403 | // Verify there is a user_ID |
| 1404 | - if ( $user_ID = (int)$wpi_cart->get_user_id() ) { |
|
| 1404 | + if ($user_ID = (int)$wpi_cart->get_user_id()) { |
|
| 1405 | 1405 | // Get the logged in user data |
| 1406 | - $user_data = get_userdata( $user_ID ); |
|
| 1407 | - $required_fields = wpinv_checkout_required_fields(); |
|
| 1406 | + $user_data = get_userdata($user_ID); |
|
| 1407 | + $required_fields = wpinv_checkout_required_fields(); |
|
| 1408 | 1408 | |
| 1409 | 1409 | // Loop through required fields and show error messages |
| 1410 | - if ( !empty( $required_fields ) ) { |
|
| 1411 | - foreach ( $required_fields as $field_name => $value ) { |
|
| 1412 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
| 1413 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
| 1410 | + if (!empty($required_fields)) { |
|
| 1411 | + foreach ($required_fields as $field_name => $value) { |
|
| 1412 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
| 1413 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | } |
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | 1418 | // Verify data |
| 1419 | - if ( $user_data ) { |
|
| 1419 | + if ($user_data) { |
|
| 1420 | 1420 | // Collected logged in user data |
| 1421 | 1421 | $valid_user_data = array( |
| 1422 | 1422 | 'user_id' => $user_ID, |
| 1423 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
| 1424 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
| 1425 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
| 1423 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
| 1424 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
| 1425 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
| 1426 | 1426 | ); |
| 1427 | 1427 | |
| 1428 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
| 1429 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
| 1428 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
| 1429 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
| 1430 | 1430 | } |
| 1431 | 1431 | } else { |
| 1432 | 1432 | // Set invalid user error |
| 1433 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
| 1433 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
| 1434 | 1434 | } |
| 1435 | 1435 | } else { |
| 1436 | 1436 | // Set invalid user error |
| 1437 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
| 1437 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | 1440 | // Return user data |
@@ -1446,30 +1446,30 @@ discard block |
||
| 1446 | 1446 | |
| 1447 | 1447 | $data = array(); |
| 1448 | 1448 | |
| 1449 | - if ( is_user_logged_in() ) { |
|
| 1450 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
| 1449 | + if (is_user_logged_in()) { |
|
| 1450 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) { |
|
| 1451 | 1451 | $data['user_id'] = (int)get_current_user_id(); |
| 1452 | 1452 | } else { |
| 1453 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
| 1453 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
| 1454 | 1454 | } |
| 1455 | 1455 | } else { |
| 1456 | 1456 | // If guest checkout allowed |
| 1457 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1457 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1458 | 1458 | $data['user_id'] = 0; |
| 1459 | 1459 | } else { |
| 1460 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
| 1460 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
| 1461 | 1461 | } |
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | 1464 | return $data; |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
| 1467 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
| 1468 | 1468 | // Initialize user |
| 1469 | 1469 | $user = false; |
| 1470 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1470 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1471 | 1471 | |
| 1472 | - if ( empty( $valid_data['current_user'] ) ) { |
|
| 1472 | + if (empty($valid_data['current_user'])) { |
|
| 1473 | 1473 | $user = false; |
| 1474 | 1474 | } else { |
| 1475 | 1475 | // Set the valid invoice user |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | } |
| 1478 | 1478 | |
| 1479 | 1479 | // Verify invoice have an user |
| 1480 | - if ( false === $user || empty( $user ) ) { |
|
| 1480 | + if (false === $user || empty($user)) { |
|
| 1481 | 1481 | return false; |
| 1482 | 1482 | } |
| 1483 | 1483 | |
@@ -1494,11 +1494,11 @@ discard block |
||
| 1494 | 1494 | 'zip', |
| 1495 | 1495 | ); |
| 1496 | 1496 | |
| 1497 | - foreach ( $address_fields as $field ) { |
|
| 1498 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
| 1497 | + foreach ($address_fields as $field) { |
|
| 1498 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
| 1499 | 1499 | |
| 1500 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $user['user_id'] ) { |
|
| 1501 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
| 1500 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $user['user_id']) { |
|
| 1501 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
| 1502 | 1502 | } |
| 1503 | 1503 | } |
| 1504 | 1504 | |
@@ -1506,28 +1506,28 @@ discard block |
||
| 1506 | 1506 | return $user; |
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
| 1509 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
| 1510 | 1510 | global $wpi_session; |
| 1511 | 1511 | |
| 1512 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
| 1512 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
| 1513 | 1513 | } |
| 1514 | 1514 | |
| 1515 | 1515 | function wpinv_get_checkout_session() { |
| 1516 | 1516 | global $wpi_session; |
| 1517 | 1517 | |
| 1518 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
| 1518 | + return $wpi_session->get('wpinv_checkout'); |
|
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | function wpinv_empty_cart() { |
| 1522 | 1522 | global $wpi_session; |
| 1523 | 1523 | |
| 1524 | 1524 | // Remove cart contents |
| 1525 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
| 1525 | + $wpi_session->set('wpinv_checkout', NULL); |
|
| 1526 | 1526 | |
| 1527 | 1527 | // Remove all cart fees |
| 1528 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
| 1528 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
| 1529 | 1529 | |
| 1530 | - do_action( 'wpinv_empty_cart' ); |
|
| 1530 | + do_action('wpinv_empty_cart'); |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | 1533 | function wpinv_process_checkout() { |
@@ -1540,42 +1540,42 @@ discard block |
||
| 1540 | 1540 | |
| 1541 | 1541 | $wpi_checkout_id = $invoice->ID; |
| 1542 | 1542 | |
| 1543 | - do_action( 'wpinv_pre_process_checkout' ); |
|
| 1543 | + do_action('wpinv_pre_process_checkout'); |
|
| 1544 | 1544 | |
| 1545 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
| 1545 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
| 1546 | 1546 | $valid_data = false; |
| 1547 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
| 1547 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
| 1548 | 1548 | } else { |
| 1549 | 1549 | // Validate the form $_POST data |
| 1550 | 1550 | $valid_data = wpinv_validate_checkout_fields(); |
| 1551 | 1551 | |
| 1552 | 1552 | // Allow themes and plugins to hook to errors |
| 1553 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
| 1553 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1556 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1557 | 1557 | |
| 1558 | 1558 | // Validate the user |
| 1559 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
| 1559 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
| 1560 | 1560 | |
| 1561 | 1561 | // Let extensions validate fields after user is logged in if user has used login/registration form |
| 1562 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
| 1562 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
| 1563 | 1563 | |
| 1564 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
| 1565 | - if ( $is_ajax ) { |
|
| 1566 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
| 1564 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
| 1565 | + if ($is_ajax) { |
|
| 1566 | + do_action('wpinv_ajax_checkout_errors'); |
|
| 1567 | 1567 | die(); |
| 1568 | 1568 | } else { |
| 1569 | 1569 | return false; |
| 1570 | 1570 | } |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - if ( $is_ajax ) { |
|
| 1573 | + if ($is_ajax) { |
|
| 1574 | 1574 | // Save address fields. |
| 1575 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
| 1576 | - foreach ( $address_fields as $field ) { |
|
| 1577 | - if ( isset( $user[$field] ) ) { |
|
| 1578 | - $invoice->set( $field, $user[$field] ); |
|
| 1575 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
| 1576 | + foreach ($address_fields as $field) { |
|
| 1577 | + if (isset($user[$field])) { |
|
| 1578 | + $invoice->set($field, $user[$field]); |
|
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | $invoice->save(); |
@@ -1583,15 +1583,15 @@ discard block |
||
| 1583 | 1583 | |
| 1584 | 1584 | $response['success'] = true; |
| 1585 | 1585 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 1586 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
| 1586 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
| 1587 | 1587 | $response['data']['discount'] = $invoice->get_discount(); |
| 1588 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
| 1588 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
| 1589 | 1589 | $response['data']['tax'] = $invoice->get_tax(); |
| 1590 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
| 1590 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
| 1591 | 1591 | $response['data']['total'] = $invoice->get_total(); |
| 1592 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
| 1592 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
| 1593 | 1593 | |
| 1594 | - wp_send_json( $response ); |
|
| 1594 | + wp_send_json($response); |
|
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | $user_info = array( |
@@ -1613,42 +1613,42 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | // Setup invoice information |
| 1615 | 1615 | $invoice_data = array( |
| 1616 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
| 1616 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
| 1617 | 1617 | 'items' => $cart_items, |
| 1618 | 1618 | 'cart_discounts' => $discounts, |
| 1619 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1620 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
| 1621 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
| 1622 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
| 1623 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
| 1619 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1620 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
| 1621 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
| 1622 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
| 1623 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
| 1624 | 1624 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
| 1625 | 1625 | 'user_email' => $user['email'], |
| 1626 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 1627 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 1626 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 1627 | + 'user_info' => stripslashes_deep($user_info), |
|
| 1628 | 1628 | 'post_data' => $_POST, |
| 1629 | 1629 | 'cart_details' => $cart_items, |
| 1630 | 1630 | 'gateway' => $valid_data['gateway'], |
| 1631 | 1631 | 'card_info' => $valid_data['cc_info'] |
| 1632 | 1632 | ); |
| 1633 | 1633 | |
| 1634 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1635 | - if ( is_array( $vat_info ) ) { |
|
| 1634 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1635 | + if (is_array($vat_info)) { |
|
| 1636 | 1636 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
| 1637 | 1637 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
| 1638 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1638 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1639 | 1639 | |
| 1640 | 1640 | // Add the VAT rate to each item in the cart |
| 1641 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
| 1641 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
| 1642 | 1642 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
| 1643 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
| 1643 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
| 1644 | 1644 | } |
| 1645 | 1645 | } |
| 1646 | 1646 | |
| 1647 | 1647 | // Save vat fields. |
| 1648 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
| 1649 | - foreach ( $address_fields as $field ) { |
|
| 1650 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
| 1651 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
| 1648 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
| 1649 | + foreach ($address_fields as $field) { |
|
| 1650 | + if (isset($invoice_data['user_info'][$field])) { |
|
| 1651 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | $invoice->save(); |
@@ -1658,49 +1658,49 @@ discard block |
||
| 1658 | 1658 | $valid_data['user'] = $user; |
| 1659 | 1659 | |
| 1660 | 1660 | // Allow themes and plugins to hook before the gateway |
| 1661 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
| 1661 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
| 1662 | 1662 | |
| 1663 | 1663 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
| 1664 | - if ( !$invoice_data['price'] ) { |
|
| 1664 | + if (!$invoice_data['price']) { |
|
| 1665 | 1665 | // Revert to manual |
| 1666 | 1666 | $invoice_data['gateway'] = 'manual'; |
| 1667 | 1667 | $_POST['wpi-gateway'] = 'manual'; |
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | // Allow the invoice data to be modified before it is sent to the gateway |
| 1671 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
| 1671 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
| 1672 | 1672 | |
| 1673 | 1673 | // Setup the data we're storing in the purchase session |
| 1674 | 1674 | $session_data = $invoice_data; |
| 1675 | 1675 | // Make sure credit card numbers are never stored in sessions |
| 1676 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
| 1677 | - unset( $session_data['card_info']['card_number'] ); |
|
| 1676 | + if (!empty($session_data['card_info']['card_number'])) { |
|
| 1677 | + unset($session_data['card_info']['card_number']); |
|
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | 1680 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
| 1681 | - wpinv_set_checkout_session( $invoice_data ); |
|
| 1681 | + wpinv_set_checkout_session($invoice_data); |
|
| 1682 | 1682 | |
| 1683 | 1683 | // Set gateway |
| 1684 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
| 1685 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
| 1686 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
| 1684 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
| 1685 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
| 1686 | + $invoice->update_meta('_wpinv_checkout', true); |
|
| 1687 | 1687 | |
| 1688 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
| 1688 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
| 1689 | 1689 | |
| 1690 | 1690 | // Send info to the gateway for payment processing |
| 1691 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
| 1691 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
| 1692 | 1692 | die(); |
| 1693 | 1693 | } |
| 1694 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
| 1694 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
| 1695 | 1695 | |
| 1696 | -function wpinv_get_invoices( $args ) { |
|
| 1697 | - $args = wp_parse_args( $args, array( |
|
| 1698 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 1696 | +function wpinv_get_invoices($args) { |
|
| 1697 | + $args = wp_parse_args($args, array( |
|
| 1698 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 1699 | 1699 | 'type' => 'wpi_invoice', |
| 1700 | 1700 | 'parent' => null, |
| 1701 | 1701 | 'user' => null, |
| 1702 | 1702 | 'email' => '', |
| 1703 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 1703 | + 'limit' => get_option('posts_per_page'), |
|
| 1704 | 1704 | 'offset' => null, |
| 1705 | 1705 | 'page' => 1, |
| 1706 | 1706 | 'exclude' => array(), |
@@ -1708,7 +1708,7 @@ discard block |
||
| 1708 | 1708 | 'order' => 'DESC', |
| 1709 | 1709 | 'return' => 'objects', |
| 1710 | 1710 | 'paginate' => false, |
| 1711 | - ) ); |
|
| 1711 | + )); |
|
| 1712 | 1712 | |
| 1713 | 1713 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
| 1714 | 1714 | $map_legacy = array( |
@@ -1721,18 +1721,18 @@ discard block |
||
| 1721 | 1721 | 'paged' => 'page', |
| 1722 | 1722 | ); |
| 1723 | 1723 | |
| 1724 | - foreach ( $map_legacy as $from => $to ) { |
|
| 1725 | - if ( isset( $args[ $from ] ) ) { |
|
| 1726 | - $args[ $to ] = $args[ $from ]; |
|
| 1724 | + foreach ($map_legacy as $from => $to) { |
|
| 1725 | + if (isset($args[$from])) { |
|
| 1726 | + $args[$to] = $args[$from]; |
|
| 1727 | 1727 | } |
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | - if ( get_query_var( 'paged' ) ) |
|
| 1730 | + if (get_query_var('paged')) |
|
| 1731 | 1731 | $args['page'] = get_query_var('paged'); |
| 1732 | - else if ( get_query_var( 'page' ) ) |
|
| 1733 | - $args['page'] = get_query_var( 'page' ); |
|
| 1734 | - else if ( !empty( $args[ 'page' ] ) ) |
|
| 1735 | - $args['page'] = $args[ 'page' ]; |
|
| 1732 | + else if (get_query_var('page')) |
|
| 1733 | + $args['page'] = get_query_var('page'); |
|
| 1734 | + else if (!empty($args['page'])) |
|
| 1735 | + $args['page'] = $args['page']; |
|
| 1736 | 1736 | else |
| 1737 | 1737 | $args['page'] = 1; |
| 1738 | 1738 | |
@@ -1745,47 +1745,47 @@ discard block |
||
| 1745 | 1745 | 'post_status' => $args['status'], |
| 1746 | 1746 | 'posts_per_page' => $args['limit'], |
| 1747 | 1747 | 'meta_query' => array(), |
| 1748 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
| 1748 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
| 1749 | 1749 | 'fields' => 'ids', |
| 1750 | 1750 | 'orderby' => $args['orderby'], |
| 1751 | 1751 | 'order' => $args['order'], |
| 1752 | 1752 | ); |
| 1753 | 1753 | |
| 1754 | - if ( !empty( $args['user'] ) ) { |
|
| 1755 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
| 1754 | + if (!empty($args['user'])) { |
|
| 1755 | + $wp_query_args['author'] = absint($args['user']); |
|
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | - if ( ! is_null( $args['parent'] ) ) { |
|
| 1759 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
| 1758 | + if (!is_null($args['parent'])) { |
|
| 1759 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | - if ( ! is_null( $args['offset'] ) ) { |
|
| 1763 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
| 1762 | + if (!is_null($args['offset'])) { |
|
| 1763 | + $wp_query_args['offset'] = absint($args['offset']); |
|
| 1764 | 1764 | } else { |
| 1765 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
| 1765 | + $wp_query_args['paged'] = absint($args['page']); |
|
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 1769 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 1768 | + if (!empty($args['exclude'])) { |
|
| 1769 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 1770 | 1770 | } |
| 1771 | 1771 | |
| 1772 | - if ( ! $args['paginate' ] ) { |
|
| 1772 | + if (!$args['paginate']) { |
|
| 1773 | 1773 | $wp_query_args['no_found_rows'] = true; |
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | 1776 | // Get results. |
| 1777 | - $invoices = new WP_Query( $wp_query_args ); |
|
| 1777 | + $invoices = new WP_Query($wp_query_args); |
|
| 1778 | 1778 | |
| 1779 | - if ( 'objects' === $args['return'] ) { |
|
| 1780 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 1781 | - } elseif ( 'self' === $args['return'] ) { |
|
| 1779 | + if ('objects' === $args['return']) { |
|
| 1780 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
| 1781 | + } elseif ('self' === $args['return']) { |
|
| 1782 | 1782 | return $invoices; |
| 1783 | 1783 | } else { |
| 1784 | 1784 | $return = $invoices->posts; |
| 1785 | 1785 | } |
| 1786 | 1786 | |
| 1787 | - if ( $args['paginate' ] ) { |
|
| 1788 | - return (object) array( |
|
| 1787 | + if ($args['paginate']) { |
|
| 1788 | + return (object)array( |
|
| 1789 | 1789 | 'invoices' => $return, |
| 1790 | 1790 | 'total' => $invoices->found_posts, |
| 1791 | 1791 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1797,21 +1797,21 @@ discard block |
||
| 1797 | 1797 | |
| 1798 | 1798 | function wpinv_get_user_invoices_columns() { |
| 1799 | 1799 | $columns = array( |
| 1800 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1801 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1802 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
| 1803 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
| 1804 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
| 1800 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
| 1801 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1802 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
| 1803 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
| 1804 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
| 1805 | 1805 | ); |
| 1806 | 1806 | |
| 1807 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
| 1807 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
| 1810 | +function wpinv_payment_receipt($atts, $content = null) { |
|
| 1811 | 1811 | global $wpinv_receipt_args; |
| 1812 | 1812 | |
| 1813 | - $wpinv_receipt_args = shortcode_atts( array( |
|
| 1814 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
| 1813 | + $wpinv_receipt_args = shortcode_atts(array( |
|
| 1814 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
| 1815 | 1815 | 'price' => true, |
| 1816 | 1816 | 'discount' => true, |
| 1817 | 1817 | 'items' => true, |
@@ -1820,195 +1820,195 @@ discard block |
||
| 1820 | 1820 | 'invoice_key' => false, |
| 1821 | 1821 | 'payment_method' => true, |
| 1822 | 1822 | 'invoice_id' => true |
| 1823 | - ), $atts, 'wpinv_receipt' ); |
|
| 1823 | + ), $atts, 'wpinv_receipt'); |
|
| 1824 | 1824 | |
| 1825 | 1825 | $session = wpinv_get_checkout_session(); |
| 1826 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1827 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
| 1828 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
| 1826 | + if (isset($_GET['invoice_key'])) { |
|
| 1827 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
| 1828 | + } else if ($session && isset($session['invoice_key'])) { |
|
| 1829 | 1829 | $invoice_key = $session['invoice_key']; |
| 1830 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
| 1830 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
| 1831 | 1831 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
| 1832 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1833 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
| 1832 | + } else if (isset($_GET['invoice-id'])) { |
|
| 1833 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
| 1834 | 1834 | } |
| 1835 | 1835 | |
| 1836 | 1836 | // No key found |
| 1837 | - if ( ! isset( $invoice_key ) ) { |
|
| 1837 | + if (!isset($invoice_key)) { |
|
| 1838 | 1838 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1842 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1843 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1841 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1842 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1843 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1844 | 1844 | $invoice_id = (int)$_GET['invoice-id']; |
| 1845 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1845 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | 1848 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
| 1849 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
| 1849 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
| 1850 | 1850 | // login redirect |
| 1851 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
| 1851 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
| 1854 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
| 1855 | 1855 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | 1858 | ob_start(); |
| 1859 | 1859 | |
| 1860 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
| 1860 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
| 1861 | 1861 | |
| 1862 | 1862 | $display = ob_get_clean(); |
| 1863 | 1863 | |
| 1864 | 1864 | return $display; |
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
| 1867 | +function wpinv_get_invoice_id_by_key($key) { |
|
| 1868 | 1868 | global $wpdb; |
| 1869 | 1869 | |
| 1870 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1870 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
| 1871 | 1871 | |
| 1872 | - if ( $invoice_id != NULL ) |
|
| 1872 | + if ($invoice_id != NULL) |
|
| 1873 | 1873 | return $invoice_id; |
| 1874 | 1874 | |
| 1875 | 1875 | return 0; |
| 1876 | 1876 | } |
| 1877 | 1877 | |
| 1878 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
| 1878 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
| 1879 | 1879 | $return = false; |
| 1880 | 1880 | |
| 1881 | - if ( empty( $invoice_key ) ) { |
|
| 1881 | + if (empty($invoice_key)) { |
|
| 1882 | 1882 | return $return; |
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | global $wpinv_receipt_args; |
| 1886 | 1886 | |
| 1887 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1888 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1889 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1887 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1888 | + if (isset($_GET['invoice-id'])) { |
|
| 1889 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
| 1890 | 1890 | } |
| 1891 | 1891 | |
| 1892 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
| 1892 | + if (empty($wpinv_receipt_args['id'])) { |
|
| 1893 | 1893 | return $return; |
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
| 1897 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
| 1896 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
| 1897 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
| 1898 | 1898 | return $return; |
| 1899 | 1899 | } |
| 1900 | 1900 | |
| 1901 | - if ( is_user_logged_in() ) { |
|
| 1902 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
| 1901 | + if (is_user_logged_in()) { |
|
| 1902 | + if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { |
|
| 1903 | 1903 | $return = true; |
| 1904 | 1904 | } |
| 1905 | 1905 | } |
| 1906 | 1906 | |
| 1907 | 1907 | $session = wpinv_get_checkout_session(); |
| 1908 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
| 1909 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1908 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
| 1909 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1910 | 1910 | |
| 1911 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 1911 | + if (wpinv_require_login_to_checkout()) { |
|
| 1912 | 1912 | $return = $return && $check_key === $invoice_key; |
| 1913 | 1913 | } else { |
| 1914 | 1914 | $return = $check_key === $invoice_key; |
| 1915 | 1915 | } |
| 1916 | 1916 | } |
| 1917 | 1917 | |
| 1918 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1918 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | function wpinv_pay_for_invoice() { |
| 1922 | 1922 | global $wpinv_euvat; |
| 1923 | 1923 | |
| 1924 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1924 | + if (isset($_GET['invoice_key'])) { |
|
| 1925 | 1925 | $checkout_uri = wpinv_get_checkout_uri(); |
| 1926 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
| 1926 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
| 1927 | 1927 | |
| 1928 | - if ( empty( $invoice_key ) ) { |
|
| 1929 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
| 1930 | - wp_redirect( $checkout_uri ); |
|
| 1928 | + if (empty($invoice_key)) { |
|
| 1929 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
| 1930 | + wp_redirect($checkout_uri); |
|
| 1931 | 1931 | wpinv_die(); |
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
| 1934 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
| 1935 | 1935 | |
| 1936 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1937 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1938 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1936 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1937 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1938 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1939 | 1939 | $invoice_id = (int)$_GET['invoice-id']; |
| 1940 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1940 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
| 1944 | - if ( $invoice->needs_payment() ) { |
|
| 1943 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
| 1944 | + if ($invoice->needs_payment()) { |
|
| 1945 | 1945 | $data = array(); |
| 1946 | 1946 | $data['invoice_id'] = $invoice_id; |
| 1947 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 1947 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 1948 | 1948 | |
| 1949 | - wpinv_set_checkout_session( $data ); |
|
| 1949 | + wpinv_set_checkout_session($data); |
|
| 1950 | 1950 | |
| 1951 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1951 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1952 | 1952 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
| 1953 | 1953 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
| 1954 | 1954 | |
| 1955 | - wpinv_recalculate_tax( true ); |
|
| 1955 | + wpinv_recalculate_tax(true); |
|
| 1956 | 1956 | } |
| 1957 | 1957 | |
| 1958 | 1958 | } else { |
| 1959 | 1959 | $checkout_uri = $invoice->get_view_url(); |
| 1960 | 1960 | } |
| 1961 | 1961 | } else { |
| 1962 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
| 1962 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
| 1963 | 1963 | |
| 1964 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 1964 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | - wp_redirect( $checkout_uri ); |
|
| 1967 | + wp_redirect($checkout_uri); |
|
| 1968 | 1968 | wpinv_die(); |
| 1969 | 1969 | } |
| 1970 | 1970 | } |
| 1971 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
| 1971 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
| 1972 | 1972 | |
| 1973 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
| 1974 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
| 1975 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 1973 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
| 1974 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
| 1975 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
| 1976 | 1976 | $user_id = $invoice->get_user_id(); |
| 1977 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 1977 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 1978 | 1978 | |
| 1979 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
| 1980 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 1979 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
| 1980 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 1981 | 1981 | |
| 1982 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 1982 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 1983 | 1983 | wpinv_die(); |
| 1984 | 1984 | } |
| 1985 | 1985 | } |
| 1986 | 1986 | } |
| 1987 | 1987 | } |
| 1988 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
| 1988 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
| 1989 | 1989 | |
| 1990 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
| 1991 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
| 1990 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
| 1991 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
| 1992 | 1992 | |
| 1993 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
| 1993 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
| 1994 | 1994 | return false; |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | - if ( empty( $transaction_id ) ) { |
|
| 1997 | + if (empty($transaction_id)) { |
|
| 1998 | 1998 | $transaction_id = $invoice_id; |
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
| 2001 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
| 2002 | 2002 | |
| 2003 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
| 2003 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
| 2004 | 2004 | } |
| 2005 | 2005 | |
| 2006 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
| 2007 | - if ( empty( $status_display ) ) { |
|
| 2008 | - $status_display = wpinv_status_nicename( $status ); |
|
| 2006 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
| 2007 | + if (empty($status_display)) { |
|
| 2008 | + $status_display = wpinv_status_nicename($status); |
|
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | - switch ( $status ) { |
|
| 2011 | + switch ($status) { |
|
| 2012 | 2012 | case 'publish' : |
| 2013 | 2013 | case 'wpi-renewal' : |
| 2014 | 2014 | $class = 'label-success'; |
@@ -2033,178 +2033,178 @@ discard block |
||
| 2033 | 2033 | |
| 2034 | 2034 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
| 2035 | 2035 | |
| 2036 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
| 2036 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
| 2037 | 2037 | } |
| 2038 | 2038 | |
| 2039 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
| 2040 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
| 2041 | - if ( null !== $check ) { |
|
| 2039 | +function wpinv_format_invoice_number($number, $type = '') { |
|
| 2040 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
| 2041 | + if (null !== $check) { |
|
| 2042 | 2042 | return $check; |
| 2043 | 2043 | } |
| 2044 | 2044 | |
| 2045 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
| 2045 | + if (!empty($number) && !is_numeric($number)) { |
|
| 2046 | 2046 | return $number; |
| 2047 | 2047 | } |
| 2048 | 2048 | |
| 2049 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
| 2050 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2051 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2049 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
| 2050 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2051 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2052 | 2052 | |
| 2053 | - $padd = absint( $padd ); |
|
| 2054 | - $formatted_number = absint( $number ); |
|
| 2053 | + $padd = absint($padd); |
|
| 2054 | + $formatted_number = absint($number); |
|
| 2055 | 2055 | |
| 2056 | - if ( $padd > 0 ) { |
|
| 2057 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
| 2056 | + if ($padd > 0) { |
|
| 2057 | + $formatted_number = zeroise($formatted_number, $padd); |
|
| 2058 | 2058 | } |
| 2059 | 2059 | |
| 2060 | 2060 | $formatted_number = $prefix . $formatted_number . $postfix; |
| 2061 | 2061 | |
| 2062 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
| 2062 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
| 2063 | 2063 | } |
| 2064 | 2064 | |
| 2065 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
| 2066 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
| 2067 | - if ( null !== $check ) { |
|
| 2065 | +function wpinv_get_next_invoice_number($type = '') { |
|
| 2066 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
| 2067 | + if (null !== $check) { |
|
| 2068 | 2068 | return $check; |
| 2069 | 2069 | } |
| 2070 | 2070 | |
| 2071 | - if ( !wpinv_sequential_number_active() ) { |
|
| 2071 | + if (!wpinv_sequential_number_active()) { |
|
| 2072 | 2072 | return false; |
| 2073 | 2073 | } |
| 2074 | 2074 | |
| 2075 | - $number = $last_number = get_option( 'wpinv_last_invoice_number' ); |
|
| 2076 | - $start = wpinv_get_option( 'invoice_sequence_start' ); |
|
| 2077 | - if ( !absint( $start ) > 0 ) { |
|
| 2075 | + $number = $last_number = get_option('wpinv_last_invoice_number'); |
|
| 2076 | + $start = wpinv_get_option('invoice_sequence_start'); |
|
| 2077 | + if (!absint($start) > 0) { |
|
| 2078 | 2078 | $start = 1; |
| 2079 | 2079 | } |
| 2080 | 2080 | $increment_number = true; |
| 2081 | 2081 | $save_number = false; |
| 2082 | 2082 | |
| 2083 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
| 2084 | - $number = wpinv_clean_invoice_number( $number ); |
|
| 2083 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
| 2084 | + $number = wpinv_clean_invoice_number($number); |
|
| 2085 | 2085 | } |
| 2086 | 2086 | |
| 2087 | - if ( empty( $number ) ) { |
|
| 2088 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
| 2089 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true ) ) ) ); |
|
| 2087 | + if (empty($number)) { |
|
| 2088 | + if (!($last_number === 0 || $last_number === '0')) { |
|
| 2089 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true)))); |
|
| 2090 | 2090 | |
| 2091 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
| 2092 | - if ( is_numeric( $invoice_number ) ) { |
|
| 2091 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
| 2092 | + if (is_numeric($invoice_number)) { |
|
| 2093 | 2093 | $number = $invoice_number; |
| 2094 | 2094 | } else { |
| 2095 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
| 2095 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
| 2096 | 2096 | } |
| 2097 | 2097 | } |
| 2098 | 2098 | |
| 2099 | - if ( empty( $number ) ) { |
|
| 2099 | + if (empty($number)) { |
|
| 2100 | 2100 | $increment_number = false; |
| 2101 | 2101 | $number = $start; |
| 2102 | - $save_number = ( $number - 1 ); |
|
| 2102 | + $save_number = ($number - 1); |
|
| 2103 | 2103 | } else { |
| 2104 | 2104 | $save_number = $number; |
| 2105 | 2105 | } |
| 2106 | 2106 | } |
| 2107 | 2107 | } |
| 2108 | 2108 | |
| 2109 | - if ( $start > $number ) { |
|
| 2109 | + if ($start > $number) { |
|
| 2110 | 2110 | $increment_number = false; |
| 2111 | 2111 | $number = $start; |
| 2112 | - $save_number = ( $number - 1 ); |
|
| 2112 | + $save_number = ($number - 1); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | - if ( $save_number !== false ) { |
|
| 2116 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
| 2115 | + if ($save_number !== false) { |
|
| 2116 | + update_option('wpinv_last_invoice_number', $save_number); |
|
| 2117 | 2117 | } |
| 2118 | 2118 | |
| 2119 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
| 2119 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
| 2120 | 2120 | |
| 2121 | - if ( $increment_number ) { |
|
| 2121 | + if ($increment_number) { |
|
| 2122 | 2122 | $number++; |
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
| 2125 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
| 2126 | 2126 | } |
| 2127 | 2127 | |
| 2128 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
| 2129 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
| 2130 | - if ( null !== $check ) { |
|
| 2128 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
| 2129 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
| 2130 | + if (null !== $check) { |
|
| 2131 | 2131 | return $check; |
| 2132 | 2132 | } |
| 2133 | 2133 | |
| 2134 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2135 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2134 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2135 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2136 | 2136 | |
| 2137 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
| 2137 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
| 2138 | 2138 | |
| 2139 | - $length = strlen( $number ); |
|
| 2140 | - $postfix_pos = strrpos( $number, $postfix ); |
|
| 2139 | + $length = strlen($number); |
|
| 2140 | + $postfix_pos = strrpos($number, $postfix); |
|
| 2141 | 2141 | |
| 2142 | - if ( false !== $postfix_pos ) { |
|
| 2143 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
| 2142 | + if (false !== $postfix_pos) { |
|
| 2143 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
| 2144 | 2144 | } |
| 2145 | 2145 | |
| 2146 | - $number = intval( $number ); |
|
| 2146 | + $number = intval($number); |
|
| 2147 | 2147 | |
| 2148 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
| 2148 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
| 2151 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
| 2152 | 2152 | global $wpdb; |
| 2153 | 2153 | |
| 2154 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
| 2155 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
| 2154 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
| 2155 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | - if ( !$update ) { |
|
| 2159 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
| 2160 | - clean_post_cache( $post_ID ); |
|
| 2158 | + if (!$update) { |
|
| 2159 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
| 2160 | + clean_post_cache($post_ID); |
|
| 2161 | 2161 | } |
| 2162 | 2162 | } |
| 2163 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
| 2163 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
| 2164 | 2164 | |
| 2165 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
| 2166 | - 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 ) { |
|
| 2167 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
| 2165 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
| 2166 | + 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) { |
|
| 2167 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
| 2168 | 2168 | } |
| 2169 | 2169 | } |
| 2170 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
| 2170 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
| 2171 | 2171 | |
| 2172 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
| 2172 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
| 2173 | 2173 | global $wpdb; |
| 2174 | 2174 | |
| 2175 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
| 2176 | - if ( null !== $check ) { |
|
| 2175 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
| 2176 | + if (null !== $check) { |
|
| 2177 | 2177 | return $check; |
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | - if ( wpinv_sequential_number_active() ) { |
|
| 2180 | + if (wpinv_sequential_number_active()) { |
|
| 2181 | 2181 | $number = wpinv_get_next_invoice_number(); |
| 2182 | 2182 | |
| 2183 | - if ( $save_sequential ) { |
|
| 2184 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
| 2183 | + if ($save_sequential) { |
|
| 2184 | + update_option('wpinv_last_invoice_number', $number); |
|
| 2185 | 2185 | } |
| 2186 | 2186 | } else { |
| 2187 | 2187 | $number = $post_ID; |
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | - $number = wpinv_format_invoice_number( $number ); |
|
| 2190 | + $number = wpinv_format_invoice_number($number); |
|
| 2191 | 2191 | |
| 2192 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
| 2192 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
| 2193 | 2193 | |
| 2194 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
| 2194 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
| 2195 | 2195 | |
| 2196 | - clean_post_cache( $post_ID ); |
|
| 2196 | + clean_post_cache($post_ID); |
|
| 2197 | 2197 | |
| 2198 | 2198 | return $number; |
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
| 2202 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
| 2201 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
| 2202 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | -function wpinv_generate_post_name( $post_ID ) { |
|
| 2206 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
| 2207 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
| 2205 | +function wpinv_generate_post_name($post_ID) { |
|
| 2206 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
| 2207 | + $post_name = sanitize_title($prefix . $post_ID); |
|
| 2208 | 2208 | |
| 2209 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
| 2209 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
| 2210 | 2210 | } |
| 2211 | 2211 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | /** |
| 6 | 8 | * The Subscriptions DB Class |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * The Subscriptions DB Class |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | 'transaction_id' => '', |
| 69 | 69 | 'parent_payment_id' => 0, |
| 70 | 70 | 'product_id' => 0, |
| 71 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
| 72 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
| 71 | + 'created' => date('Y-m-d H:i:s'), |
|
| 72 | + 'expiration' => date('Y-m-d H:i:s'), |
|
| 73 | 73 | 'trial_period' => '', |
| 74 | 74 | 'status' => '', |
| 75 | 75 | 'profile_id' => '', |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | * @access public |
| 83 | 83 | * @since 1.0.0 |
| 84 | 84 | */ |
| 85 | - public function get_subscriptions( $args = array() ) { |
|
| 85 | + public function get_subscriptions($args = array()) { |
|
| 86 | 86 | global $wpdb; |
| 87 | 87 | |
| 88 | 88 | $defaults = array( |
| 89 | - 'number' => get_option( 'posts_per_page' ), |
|
| 89 | + 'number' => get_option('posts_per_page'), |
|
| 90 | 90 | 'offset' => 0, |
| 91 | 91 | 'search' => '', |
| 92 | 92 | 'customer_id' => 0, |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | 'order' => 'DESC' |
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | - $args = wp_parse_args( $args, $defaults ); |
|
| 97 | + $args = wp_parse_args($args, $defaults); |
|
| 98 | 98 | |
| 99 | - if( $args['number'] < 1 ) { |
|
| 99 | + if ($args['number'] < 1) { |
|
| 100 | 100 | $args['number'] = 999999999999; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $where = ' WHERE 1=1 '; |
| 104 | 104 | |
| 105 | 105 | // specific customers |
| 106 | - if( ! empty( $args['id'] ) ) { |
|
| 106 | + if (!empty($args['id'])) { |
|
| 107 | 107 | |
| 108 | - if( is_array( $args['id'] ) ) { |
|
| 109 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
| 108 | + if (is_array($args['id'])) { |
|
| 109 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
| 110 | 110 | } else { |
| 111 | - $ids = intval( $args['id'] ); |
|
| 111 | + $ids = intval($args['id']); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Specific products |
| 119 | - if( ! empty( $args['product_id'] ) ) { |
|
| 119 | + if (!empty($args['product_id'])) { |
|
| 120 | 120 | |
| 121 | - if( is_array( $args['product_id'] ) ) { |
|
| 122 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
| 121 | + if (is_array($args['product_id'])) { |
|
| 122 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
| 123 | 123 | } else { |
| 124 | - $product_ids = intval( $args['product_id'] ); |
|
| 124 | + $product_ids = intval($args['product_id']); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Specific parent payments |
| 132 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
| 132 | + if (!empty($args['parent_payment_id'])) { |
|
| 133 | 133 | |
| 134 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
| 135 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
| 134 | + if (is_array($args['parent_payment_id'])) { |
|
| 135 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
| 136 | 136 | } else { |
| 137 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
| 137 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Specific transaction IDs |
| 145 | - if( ! empty( $args['transaction_id'] ) ) { |
|
| 145 | + if (!empty($args['transaction_id'])) { |
|
| 146 | 146 | |
| 147 | - if( is_array( $args['transaction_id'] ) ) { |
|
| 148 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
| 147 | + if (is_array($args['transaction_id'])) { |
|
| 148 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
| 149 | 149 | } else { |
| 150 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
| 150 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) "; |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Subscriptoins for specific customers |
| 158 | - if( ! empty( $args['customer_id'] ) ) { |
|
| 158 | + if (!empty($args['customer_id'])) { |
|
| 159 | 159 | |
| 160 | - if( is_array( $args['customer_id'] ) ) { |
|
| 161 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
| 160 | + if (is_array($args['customer_id'])) { |
|
| 161 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
| 162 | 162 | } else { |
| 163 | - $customer_ids = intval( $args['customer_id'] ); |
|
| 163 | + $customer_ids = intval($args['customer_id']); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Subscriptions for specific profile IDs |
| 171 | - if( ! empty( $args['profile_id'] ) ) { |
|
| 171 | + if (!empty($args['profile_id'])) { |
|
| 172 | 172 | |
| 173 | - if( is_array( $args['profile_id'] ) ) { |
|
| 174 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
| 173 | + if (is_array($args['profile_id'])) { |
|
| 174 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
| 175 | 175 | } else { |
| 176 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
| 176 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $where .= " AND `profile_id` IN( '{$profile_ids}' ) "; |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Subscriptions for specific statuses |
| 184 | - if( ! empty( $args['status'] ) ) { |
|
| 184 | + if (!empty($args['status'])) { |
|
| 185 | 185 | |
| 186 | - if( is_array( $args['status'] ) ) { |
|
| 187 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
| 186 | + if (is_array($args['status'])) { |
|
| 187 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
| 188 | 188 | } else { |
| 189 | - $statuses = sanitize_text_field( $args['status'] ); |
|
| 189 | + $statuses = sanitize_text_field($args['status']); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $where .= " AND `status` IN( '{$statuses}' ) "; |
@@ -194,21 +194,21 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // Subscriptions created for a specific date or in a date range |
| 197 | - if( ! empty( $args['date'] ) ) { |
|
| 197 | + if (!empty($args['date'])) { |
|
| 198 | 198 | |
| 199 | - if( is_array( $args['date'] ) ) { |
|
| 199 | + if (is_array($args['date'])) { |
|
| 200 | 200 | |
| 201 | - if( ! empty( $args['date']['start'] ) ) { |
|
| 201 | + if (!empty($args['date']['start'])) { |
|
| 202 | 202 | |
| 203 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
| 203 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
| 204 | 204 | |
| 205 | 205 | $where .= " AND `created` >= '{$start}'"; |
| 206 | 206 | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if( ! empty( $args['date']['end'] ) ) { |
|
| 209 | + if (!empty($args['date']['end'])) { |
|
| 210 | 210 | |
| 211 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
| 211 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
| 212 | 212 | |
| 213 | 213 | $where .= " AND `created` <= '{$end}'"; |
| 214 | 214 | |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | } else { |
| 218 | 218 | |
| 219 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
| 220 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
| 221 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
| 219 | + $year = date('Y', strtotime($args['date'])); |
|
| 220 | + $month = date('m', strtotime($args['date'])); |
|
| 221 | + $day = date('d', strtotime($args['date'])); |
|
| 222 | 222 | |
| 223 | 223 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
| 224 | 224 | } |
@@ -226,21 +226,21 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Subscriptions with a specific expiration date or in an expiration date range |
| 229 | - if( ! empty( $args['expiration'] ) ) { |
|
| 229 | + if (!empty($args['expiration'])) { |
|
| 230 | 230 | |
| 231 | - if( is_array( $args['expiration'] ) ) { |
|
| 231 | + if (is_array($args['expiration'])) { |
|
| 232 | 232 | |
| 233 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
| 233 | + if (!empty($args['expiration']['start'])) { |
|
| 234 | 234 | |
| 235 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
| 235 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
| 236 | 236 | |
| 237 | 237 | $where .= " AND `expiration` >= '{$start}'"; |
| 238 | 238 | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
| 241 | + if (!empty($args['expiration']['end'])) { |
|
| 242 | 242 | |
| 243 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
| 243 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
| 244 | 244 | |
| 245 | 245 | $where .= " AND `expiration` <= '{$end}'"; |
| 246 | 246 | |
@@ -248,73 +248,73 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | } else { |
| 250 | 250 | |
| 251 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
| 252 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
| 253 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
| 251 | + $year = date('Y', strtotime($args['expiration'])); |
|
| 252 | + $month = date('m', strtotime($args['expiration'])); |
|
| 253 | + $day = date('d', strtotime($args['expiration'])); |
|
| 254 | 254 | |
| 255 | 255 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( ! empty( $args['search'] ) ) { |
|
| 260 | + if (!empty($args['search'])) { |
|
| 261 | 261 | |
| 262 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
| 262 | + if (false !== strpos('id:', $args['search'])) { |
|
| 263 | 263 | |
| 264 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
| 265 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 264 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
| 265 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
| 266 | 266 | |
| 267 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
| 267 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
| 268 | 268 | |
| 269 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
| 270 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 269 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
| 270 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
| 271 | 271 | |
| 272 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
| 272 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
| 273 | 273 | |
| 274 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
| 275 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 274 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
| 275 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
| 276 | 276 | |
| 277 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
| 277 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
| 278 | 278 | |
| 279 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
| 280 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 279 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
| 280 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
| 281 | 281 | |
| 282 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
| 282 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
| 283 | 283 | |
| 284 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
| 285 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 284 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
| 285 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
| 286 | 286 | |
| 287 | 287 | } else { |
| 288 | 288 | |
| 289 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
| 289 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby']; |
|
| 295 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby']; |
|
| 296 | 296 | |
| 297 | - if( 'amount' == $args['orderby'] ) { |
|
| 297 | + if ('amount' == $args['orderby']) { |
|
| 298 | 298 | $args['orderby'] = 'amount+0'; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) ); |
|
| 301 | + $cache_key = md5('wpinv_subscriptions_' . serialize($args)); |
|
| 302 | 302 | |
| 303 | - $subscriptions = wp_cache_get( $cache_key, 'subscriptions' ); |
|
| 303 | + $subscriptions = wp_cache_get($cache_key, 'subscriptions'); |
|
| 304 | 304 | |
| 305 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
| 306 | - $args['order'] = esc_sql( $args['order'] ); |
|
| 305 | + $args['orderby'] = esc_sql($args['orderby']); |
|
| 306 | + $args['order'] = esc_sql($args['order']); |
|
| 307 | 307 | |
| 308 | - if( $subscriptions === false ) { |
|
| 309 | - $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); |
|
| 308 | + if ($subscriptions === false) { |
|
| 309 | + $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); |
|
| 310 | 310 | |
| 311 | - if( ! empty( $subscriptions ) ) { |
|
| 311 | + if (!empty($subscriptions)) { |
|
| 312 | 312 | |
| 313 | - foreach( $subscriptions as $key => $subscription ) { |
|
| 314 | - $subscriptions[ $key ] = new WPInv_Subscription( $subscription ); |
|
| 313 | + foreach ($subscriptions as $key => $subscription) { |
|
| 314 | + $subscriptions[$key] = new WPInv_Subscription($subscription); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 ); |
|
| 317 | + wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600); |
|
| 318 | 318 | |
| 319 | 319 | } |
| 320 | 320 | |
@@ -329,19 +329,19 @@ discard block |
||
| 329 | 329 | * @access public |
| 330 | 330 | * @since 1.0.0 |
| 331 | 331 | */ |
| 332 | - public function count( $args = array() ) { |
|
| 332 | + public function count($args = array()) { |
|
| 333 | 333 | |
| 334 | 334 | global $wpdb; |
| 335 | 335 | |
| 336 | 336 | $where = ' WHERE 1=1 '; |
| 337 | 337 | |
| 338 | 338 | // specific customers |
| 339 | - if( ! empty( $args['id'] ) ) { |
|
| 339 | + if (!empty($args['id'])) { |
|
| 340 | 340 | |
| 341 | - if( is_array( $args['id'] ) ) { |
|
| 342 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
| 341 | + if (is_array($args['id'])) { |
|
| 342 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
| 343 | 343 | } else { |
| 344 | - $ids = intval( $args['id'] ); |
|
| 344 | + $ids = intval($args['id']); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -349,12 +349,12 @@ discard block |
||
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | // Specific products |
| 352 | - if( ! empty( $args['product_id'] ) ) { |
|
| 352 | + if (!empty($args['product_id'])) { |
|
| 353 | 353 | |
| 354 | - if( is_array( $args['product_id'] ) ) { |
|
| 355 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
| 354 | + if (is_array($args['product_id'])) { |
|
| 355 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
| 356 | 356 | } else { |
| 357 | - $product_ids = intval( $args['product_id'] ); |
|
| 357 | + $product_ids = intval($args['product_id']); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Specific parent payments |
| 365 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
| 365 | + if (!empty($args['parent_payment_id'])) { |
|
| 366 | 366 | |
| 367 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
| 368 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
| 367 | + if (is_array($args['parent_payment_id'])) { |
|
| 368 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
| 369 | 369 | } else { |
| 370 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
| 370 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Subscriptoins for specific customers |
| 378 | - if( ! empty( $args['customer_id'] ) ) { |
|
| 378 | + if (!empty($args['customer_id'])) { |
|
| 379 | 379 | |
| 380 | - if( is_array( $args['customer_id'] ) ) { |
|
| 381 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
| 380 | + if (is_array($args['customer_id'])) { |
|
| 381 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
| 382 | 382 | } else { |
| 383 | - $customer_ids = intval( $args['customer_id'] ); |
|
| 383 | + $customer_ids = intval($args['customer_id']); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -388,12 +388,12 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // Subscriptions for specific profile IDs |
| 391 | - if( ! empty( $args['profile_id'] ) ) { |
|
| 391 | + if (!empty($args['profile_id'])) { |
|
| 392 | 392 | |
| 393 | - if( is_array( $args['profile_id'] ) ) { |
|
| 394 | - $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) ); |
|
| 393 | + if (is_array($args['profile_id'])) { |
|
| 394 | + $profile_ids = implode(',', array_map('intval', $args['profile_id'])); |
|
| 395 | 395 | } else { |
| 396 | - $profile_ids = intval( $args['profile_id'] ); |
|
| 396 | + $profile_ids = intval($args['profile_id']); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | $where .= " AND `profile_id` IN( {$profile_ids} ) "; |
@@ -401,12 +401,12 @@ discard block |
||
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // Specific transaction IDs |
| 404 | - if( ! empty( $args['transaction_id'] ) ) { |
|
| 404 | + if (!empty($args['transaction_id'])) { |
|
| 405 | 405 | |
| 406 | - if( is_array( $args['transaction_id'] ) ) { |
|
| 407 | - $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
| 406 | + if (is_array($args['transaction_id'])) { |
|
| 407 | + $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id'])); |
|
| 408 | 408 | } else { |
| 409 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
| 409 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $where .= " AND `transaction_id` IN( {$transaction_ids} ) "; |
@@ -414,10 +414,10 @@ discard block |
||
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | // Subscriptions for specific statuses |
| 417 | - if( ! empty( $args['status'] ) ) { |
|
| 417 | + if (!empty($args['status'])) { |
|
| 418 | 418 | |
| 419 | - if( is_array( $args['status'] ) ) { |
|
| 420 | - $statuses = implode( ',', $args['status'] ); |
|
| 419 | + if (is_array($args['status'])) { |
|
| 420 | + $statuses = implode(',', $args['status']); |
|
| 421 | 421 | $where .= " AND `status` IN( {$statuses} ) "; |
| 422 | 422 | } else { |
| 423 | 423 | $statuses = $args['status']; |
@@ -429,21 +429,21 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // Subscriptions created for a specific date or in a date range |
| 432 | - if( ! empty( $args['date'] ) ) { |
|
| 432 | + if (!empty($args['date'])) { |
|
| 433 | 433 | |
| 434 | - if( is_array( $args['date'] ) ) { |
|
| 434 | + if (is_array($args['date'])) { |
|
| 435 | 435 | |
| 436 | - if( ! empty( $args['date']['start'] ) ) { |
|
| 436 | + if (!empty($args['date']['start'])) { |
|
| 437 | 437 | |
| 438 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
| 438 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
| 439 | 439 | |
| 440 | 440 | $where .= " AND `created` >= '{$start}'"; |
| 441 | 441 | |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if( ! empty( $args['date']['end'] ) ) { |
|
| 444 | + if (!empty($args['date']['end'])) { |
|
| 445 | 445 | |
| 446 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
| 446 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
| 447 | 447 | |
| 448 | 448 | $where .= " AND `created` <= '{$end}'"; |
| 449 | 449 | |
@@ -451,9 +451,9 @@ discard block |
||
| 451 | 451 | |
| 452 | 452 | } else { |
| 453 | 453 | |
| 454 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
| 455 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
| 456 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
| 454 | + $year = date('Y', strtotime($args['date'])); |
|
| 455 | + $month = date('m', strtotime($args['date'])); |
|
| 456 | + $day = date('d', strtotime($args['date'])); |
|
| 457 | 457 | |
| 458 | 458 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
| 459 | 459 | } |
@@ -461,21 +461,21 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Subscriptions with a specific expiration date or in an expiration date range |
| 464 | - if( ! empty( $args['expiration'] ) ) { |
|
| 464 | + if (!empty($args['expiration'])) { |
|
| 465 | 465 | |
| 466 | - if( is_array( $args['expiration'] ) ) { |
|
| 466 | + if (is_array($args['expiration'])) { |
|
| 467 | 467 | |
| 468 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
| 468 | + if (!empty($args['expiration']['start'])) { |
|
| 469 | 469 | |
| 470 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
| 470 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
| 471 | 471 | |
| 472 | 472 | $where .= " AND `expiration` >= '{$start}'"; |
| 473 | 473 | |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
| 476 | + if (!empty($args['expiration']['end'])) { |
|
| 477 | 477 | |
| 478 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
| 478 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
| 479 | 479 | |
| 480 | 480 | $where .= " AND `expiration` <= '{$end}'"; |
| 481 | 481 | |
@@ -483,64 +483,64 @@ discard block |
||
| 483 | 483 | |
| 484 | 484 | } else { |
| 485 | 485 | |
| 486 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
| 487 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
| 488 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
| 486 | + $year = date('Y', strtotime($args['expiration'])); |
|
| 487 | + $month = date('m', strtotime($args['expiration'])); |
|
| 488 | + $day = date('d', strtotime($args['expiration'])); |
|
| 489 | 489 | |
| 490 | 490 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - if ( ! empty( $args['search'] ) ) { |
|
| 495 | + if (!empty($args['search'])) { |
|
| 496 | 496 | |
| 497 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
| 497 | + if (false !== strpos('id:', $args['search'])) { |
|
| 498 | 498 | |
| 499 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
| 500 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 499 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
| 500 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
| 501 | 501 | |
| 502 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
| 502 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
| 503 | 503 | |
| 504 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
| 505 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 504 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
| 505 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
| 506 | 506 | |
| 507 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
| 507 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
| 508 | 508 | |
| 509 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
| 510 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 509 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
| 510 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
| 511 | 511 | |
| 512 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
| 512 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
| 513 | 513 | |
| 514 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
| 515 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 514 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
| 515 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
| 516 | 516 | |
| 517 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
| 517 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
| 518 | 518 | |
| 519 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
| 520 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 519 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
| 520 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
| 521 | 521 | |
| 522 | 522 | } else { |
| 523 | 523 | |
| 524 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
| 524 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
| 525 | 525 | |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) ); |
|
| 530 | + $cache_key = md5('wpinv_subscriptions_count' . serialize($args)); |
|
| 531 | 531 | |
| 532 | - $count = wp_cache_get( $cache_key, 'subscriptions' ); |
|
| 532 | + $count = wp_cache_get($cache_key, 'subscriptions'); |
|
| 533 | 533 | |
| 534 | - if( $count === false ) { |
|
| 534 | + if ($count === false) { |
|
| 535 | 535 | |
| 536 | 536 | $sql = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; |
| 537 | - $count = $wpdb->get_var( $sql ); |
|
| 537 | + $count = $wpdb->get_var($sql); |
|
| 538 | 538 | |
| 539 | - wp_cache_set( $cache_key, $count, 'subscriptions', 3600 ); |
|
| 539 | + wp_cache_set($cache_key, $count, 'subscriptions', 3600); |
|
| 540 | 540 | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - return absint( $count ); |
|
| 543 | + return absint($count); |
|
| 544 | 544 | |
| 545 | 545 | } |
| 546 | 546 | |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | global $wpdb; |
| 556 | 556 | |
| 557 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 557 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 558 | 558 | |
| 559 | 559 | $sql = "CREATE TABLE " . $this->table_name . " ( |
| 560 | 560 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -579,9 +579,9 @@ discard block |
||
| 579 | 579 | KEY customer_and_status ( customer_id, status) |
| 580 | 580 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
| 581 | 581 | |
| 582 | - dbDelta( $sql ); |
|
| 582 | + dbDelta($sql); |
|
| 583 | 583 | |
| 584 | - update_option( $this->table_name . '_wpinv_db_version', $this->version ); |
|
| 584 | + update_option($this->table_name . '_wpinv_db_version', $this->version); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | } |
| 588 | 588 | \ No newline at end of file |
@@ -8,7 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 11 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | + exit; |
|
| 13 | +} |
|
| 12 | 14 | |
| 13 | 15 | |
| 14 | 16 | // Load WP_List_Table if not loaded |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded |
| 15 | 15 | if( ! class_exists( 'WP_List_Table' ) ) { |
| 16 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 16 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,102 +23,102 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class WPInv_Subscription_Reports_Table extends WP_List_Table { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Number of results to show per page |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - */ |
|
| 31 | - |
|
| 32 | - public $per_page = 30; |
|
| 33 | - public $total_count = 0; |
|
| 34 | - public $active_count = 0; |
|
| 35 | - public $pending_count = 0; |
|
| 36 | - public $expired_count = 0; |
|
| 37 | - public $completed_count = 0; |
|
| 38 | - public $trialling_count = 0; |
|
| 39 | - public $cancelled_count = 0; |
|
| 40 | - public $failing_count = 0; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Get things started |
|
| 44 | - * |
|
| 45 | - * @access private |
|
| 46 | - * @since 1.0.0 |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - function __construct(){ |
|
| 50 | - global $status, $page; |
|
| 51 | - |
|
| 52 | - // Set parent defaults |
|
| 53 | - parent::__construct( array( |
|
| 54 | - 'singular' => 'subscription', |
|
| 55 | - 'plural' => 'subscriptions', |
|
| 56 | - 'ajax' => false |
|
| 57 | - ) ); |
|
| 58 | - |
|
| 59 | - $this->get_subscription_counts(); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Retrieve the view types |
|
| 65 | - * |
|
| 66 | - * @access public |
|
| 67 | - * @since 1.0.0 |
|
| 68 | - * @return array $views All the views available |
|
| 69 | - */ |
|
| 70 | - public function get_views() { |
|
| 71 | - |
|
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | - $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
| 75 | - $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
| 76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | - $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
| 78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | - |
|
| 82 | - $views = array( |
|
| 83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Show the search field |
|
| 98 | - * |
|
| 99 | - * @since 2.5 |
|
| 100 | - * @access public |
|
| 101 | - * |
|
| 102 | - * @param string $text Label for the search box |
|
| 103 | - * @param string $input_id ID of the search box |
|
| 104 | - * |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public function search_box( $text, $input_id ) { |
|
| 108 | - |
|
| 109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $input_id = $input_id . '-search-input'; |
|
| 114 | - |
|
| 115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 121 | - } |
|
| 26 | + /** |
|
| 27 | + * Number of results to show per page |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + */ |
|
| 31 | + |
|
| 32 | + public $per_page = 30; |
|
| 33 | + public $total_count = 0; |
|
| 34 | + public $active_count = 0; |
|
| 35 | + public $pending_count = 0; |
|
| 36 | + public $expired_count = 0; |
|
| 37 | + public $completed_count = 0; |
|
| 38 | + public $trialling_count = 0; |
|
| 39 | + public $cancelled_count = 0; |
|
| 40 | + public $failing_count = 0; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Get things started |
|
| 44 | + * |
|
| 45 | + * @access private |
|
| 46 | + * @since 1.0.0 |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + function __construct(){ |
|
| 50 | + global $status, $page; |
|
| 51 | + |
|
| 52 | + // Set parent defaults |
|
| 53 | + parent::__construct( array( |
|
| 54 | + 'singular' => 'subscription', |
|
| 55 | + 'plural' => 'subscriptions', |
|
| 56 | + 'ajax' => false |
|
| 57 | + ) ); |
|
| 58 | + |
|
| 59 | + $this->get_subscription_counts(); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Retrieve the view types |
|
| 65 | + * |
|
| 66 | + * @access public |
|
| 67 | + * @since 1.0.0 |
|
| 68 | + * @return array $views All the views available |
|
| 69 | + */ |
|
| 70 | + public function get_views() { |
|
| 71 | + |
|
| 72 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | + $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
| 75 | + $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
| 76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | + $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
| 78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | + |
|
| 82 | + $views = array( |
|
| 83 | + 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | + 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | + 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | + 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | + 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | + 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | + 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | + 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Show the search field |
|
| 98 | + * |
|
| 99 | + * @since 2.5 |
|
| 100 | + * @access public |
|
| 101 | + * |
|
| 102 | + * @param string $text Label for the search box |
|
| 103 | + * @param string $input_id ID of the search box |
|
| 104 | + * |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public function search_box( $text, $input_id ) { |
|
| 108 | + |
|
| 109 | + if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $input_id = $input_id . '-search-input'; |
|
| 114 | + |
|
| 115 | + if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 121 | + } |
|
| 122 | 122 | ?> |
| 123 | 123 | <p class="search-box"> |
| 124 | 124 | <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
| 128 | 128 | </p> |
| 129 | 129 | <?php |
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Render most columns |
|
| 134 | - * |
|
| 135 | - * @access private |
|
| 136 | - * @since 1.0.0 |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - function column_default( $item, $column_name ) { |
|
| 140 | - return $item->$column_name; |
|
| 141 | - } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Render most columns |
|
| 134 | + * |
|
| 135 | + * @access private |
|
| 136 | + * @since 1.0.0 |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + function column_default( $item, $column_name ) { |
|
| 140 | + return $item->$column_name; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * Subscription id column |
@@ -151,244 +151,244 @@ discard block |
||
| 151 | 151 | return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Customer column |
|
| 156 | - * |
|
| 157 | - * @access private |
|
| 158 | - * @since 1.0.0 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - function column_customer_id( $item ) { |
|
| 162 | - $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | - |
|
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Status column |
|
| 170 | - * |
|
| 171 | - * @access private |
|
| 172 | - * @since 1.0.0 |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - function column_status( $item ) { |
|
| 176 | - return $item->get_status_label(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Period column |
|
| 181 | - * |
|
| 182 | - * @access private |
|
| 183 | - * @since 1.0.0 |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - function column_period( $item ) { |
|
| 187 | - |
|
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 189 | - |
|
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Billing Times column |
|
| 195 | - * |
|
| 196 | - * @access private |
|
| 197 | - * @since 1.0.0 |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - function column_bill_times( $item ) { |
|
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Initial Amount column |
|
| 206 | - * |
|
| 207 | - * @access private |
|
| 208 | - * @since 1.0.0 |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - function column_initial_amount( $item ) { |
|
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Renewal date column |
|
| 217 | - * |
|
| 218 | - * @access private |
|
| 219 | - * @since 1.0.0 |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - function column_renewal_date( $item ) { |
|
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Payment column |
|
| 228 | - * |
|
| 229 | - * @access private |
|
| 230 | - * @since 1.0.0 |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - function column_parent_payment_id( $item ) { |
|
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . $item->parent_payment_id . '</a>'; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Product ID column |
|
| 239 | - * |
|
| 240 | - * @access private |
|
| 241 | - * @since 1.0.0 |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - function column_product_id( $item ) { |
|
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Render the edit column |
|
| 250 | - * |
|
| 251 | - * @access private |
|
| 252 | - * @since 2.0 |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - function column_actions( $item ) { |
|
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Retrieve the table columns |
|
| 262 | - * |
|
| 263 | - * @access private |
|
| 264 | - * @since 1.0.0 |
|
| 265 | - * @return array |
|
| 266 | - */ |
|
| 267 | - |
|
| 268 | - function get_columns(){ |
|
| 269 | - $columns = array( |
|
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
| 280 | - ); |
|
| 281 | - |
|
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Retrieve the current page number |
|
| 287 | - * |
|
| 288 | - * @access private |
|
| 289 | - * @since 1.0.0 |
|
| 290 | - * @return int |
|
| 291 | - */ |
|
| 292 | - function get_paged() { |
|
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Retrieve the subscription counts |
|
| 298 | - * |
|
| 299 | - * @access public |
|
| 300 | - * @since 1.4 |
|
| 301 | - * @return void |
|
| 302 | - */ |
|
| 303 | - public function get_subscription_counts() { |
|
| 304 | - |
|
| 305 | - global $wp_query; |
|
| 306 | - |
|
| 307 | - $db = new WPInv_Subscriptions_DB; |
|
| 308 | - |
|
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 310 | - |
|
| 311 | - $this->total_count = $db->count(); |
|
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 319 | - |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Setup the final data for the table |
|
| 324 | - * |
|
| 325 | - * @access private |
|
| 326 | - * @since 1.0.0 |
|
| 327 | - * @uses $this->_column_headers |
|
| 328 | - * @uses $this->items |
|
| 329 | - * @uses $this->get_columns() |
|
| 330 | - * @uses $this->get_sortable_columns() |
|
| 331 | - * @uses $this->get_pagenum() |
|
| 332 | - * @uses $this->set_pagination_args() |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - function prepare_items() { |
|
| 336 | - |
|
| 337 | - $columns = $this->get_columns(); |
|
| 338 | - $hidden = array(); // No hidden columns |
|
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 340 | - $sortable = $this->get_sortable_columns(); |
|
| 341 | - |
|
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 343 | - |
|
| 344 | - $current_page = $this->get_pagenum(); |
|
| 345 | - |
|
| 346 | - $db = new WPInv_Subscriptions_DB; |
|
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 348 | - $args = array( |
|
| 349 | - 'number' => $this->per_page, |
|
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 351 | - 'search' => $search |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - if ( 'any' !== $status ) { |
|
| 355 | - $args['status'] = $status; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $this->items = $db->get_subscriptions( $args ); |
|
| 359 | - |
|
| 360 | - switch ( $status ) { |
|
| 361 | - case 'active': |
|
| 362 | - $total_items = $this->active_count; |
|
| 363 | - break; |
|
| 364 | - case 'pending': |
|
| 365 | - $total_items = $this->pending_count; |
|
| 366 | - break; |
|
| 367 | - case 'expired': |
|
| 368 | - $total_items = $this->expired_count; |
|
| 369 | - break; |
|
| 370 | - case 'cancelled': |
|
| 371 | - $total_items = $this->cancelled_count; |
|
| 372 | - break; |
|
| 373 | - case 'failing': |
|
| 374 | - $total_items = $this->failing_count; |
|
| 375 | - break; |
|
| 376 | - case 'trialling': |
|
| 377 | - $total_items = $this->trialling_count; |
|
| 378 | - break; |
|
| 379 | - case 'completed': |
|
| 380 | - $total_items = $this->completed_count; |
|
| 381 | - break; |
|
| 382 | - case 'any': |
|
| 383 | - default: |
|
| 384 | - $total_items = $this->total_count; |
|
| 385 | - break; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $this->set_pagination_args( array( |
|
| 389 | - 'total_items' => $total_items, |
|
| 390 | - 'per_page' => $this->per_page, |
|
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | - ) ); |
|
| 393 | - } |
|
| 154 | + /** |
|
| 155 | + * Customer column |
|
| 156 | + * |
|
| 157 | + * @access private |
|
| 158 | + * @since 1.0.0 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + function column_customer_id( $item ) { |
|
| 162 | + $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | + $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | + |
|
| 165 | + return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Status column |
|
| 170 | + * |
|
| 171 | + * @access private |
|
| 172 | + * @since 1.0.0 |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + function column_status( $item ) { |
|
| 176 | + return $item->get_status_label(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Period column |
|
| 181 | + * |
|
| 182 | + * @access private |
|
| 183 | + * @since 1.0.0 |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + function column_period( $item ) { |
|
| 187 | + |
|
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 189 | + |
|
| 190 | + return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Billing Times column |
|
| 195 | + * |
|
| 196 | + * @access private |
|
| 197 | + * @since 1.0.0 |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + function column_bill_times( $item ) { |
|
| 201 | + return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Initial Amount column |
|
| 206 | + * |
|
| 207 | + * @access private |
|
| 208 | + * @since 1.0.0 |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + function column_initial_amount( $item ) { |
|
| 212 | + return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Renewal date column |
|
| 217 | + * |
|
| 218 | + * @access private |
|
| 219 | + * @since 1.0.0 |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + function column_renewal_date( $item ) { |
|
| 223 | + return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Payment column |
|
| 228 | + * |
|
| 229 | + * @access private |
|
| 230 | + * @since 1.0.0 |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + function column_parent_payment_id( $item ) { |
|
| 234 | + return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . $item->parent_payment_id . '</a>'; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Product ID column |
|
| 239 | + * |
|
| 240 | + * @access private |
|
| 241 | + * @since 1.0.0 |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + function column_product_id( $item ) { |
|
| 245 | + return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Render the edit column |
|
| 250 | + * |
|
| 251 | + * @access private |
|
| 252 | + * @since 2.0 |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + function column_actions( $item ) { |
|
| 256 | + return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Retrieve the table columns |
|
| 262 | + * |
|
| 263 | + * @access private |
|
| 264 | + * @since 1.0.0 |
|
| 265 | + * @return array |
|
| 266 | + */ |
|
| 267 | + |
|
| 268 | + function get_columns(){ |
|
| 269 | + $columns = array( |
|
| 270 | + 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | + 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | + 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | + 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | + 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | + 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | + 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | + 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | + 'actions' => __( 'Actions', 'invoicing' ), |
|
| 280 | + ); |
|
| 281 | + |
|
| 282 | + return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Retrieve the current page number |
|
| 287 | + * |
|
| 288 | + * @access private |
|
| 289 | + * @since 1.0.0 |
|
| 290 | + * @return int |
|
| 291 | + */ |
|
| 292 | + function get_paged() { |
|
| 293 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Retrieve the subscription counts |
|
| 298 | + * |
|
| 299 | + * @access public |
|
| 300 | + * @since 1.4 |
|
| 301 | + * @return void |
|
| 302 | + */ |
|
| 303 | + public function get_subscription_counts() { |
|
| 304 | + |
|
| 305 | + global $wp_query; |
|
| 306 | + |
|
| 307 | + $db = new WPInv_Subscriptions_DB; |
|
| 308 | + |
|
| 309 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 310 | + |
|
| 311 | + $this->total_count = $db->count(); |
|
| 312 | + $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | + $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | + $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | + $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | + $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | + $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | + $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 319 | + |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Setup the final data for the table |
|
| 324 | + * |
|
| 325 | + * @access private |
|
| 326 | + * @since 1.0.0 |
|
| 327 | + * @uses $this->_column_headers |
|
| 328 | + * @uses $this->items |
|
| 329 | + * @uses $this->get_columns() |
|
| 330 | + * @uses $this->get_sortable_columns() |
|
| 331 | + * @uses $this->get_pagenum() |
|
| 332 | + * @uses $this->set_pagination_args() |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + function prepare_items() { |
|
| 336 | + |
|
| 337 | + $columns = $this->get_columns(); |
|
| 338 | + $hidden = array(); // No hidden columns |
|
| 339 | + $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 340 | + $sortable = $this->get_sortable_columns(); |
|
| 341 | + |
|
| 342 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 343 | + |
|
| 344 | + $current_page = $this->get_pagenum(); |
|
| 345 | + |
|
| 346 | + $db = new WPInv_Subscriptions_DB; |
|
| 347 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 348 | + $args = array( |
|
| 349 | + 'number' => $this->per_page, |
|
| 350 | + 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 351 | + 'search' => $search |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + if ( 'any' !== $status ) { |
|
| 355 | + $args['status'] = $status; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $this->items = $db->get_subscriptions( $args ); |
|
| 359 | + |
|
| 360 | + switch ( $status ) { |
|
| 361 | + case 'active': |
|
| 362 | + $total_items = $this->active_count; |
|
| 363 | + break; |
|
| 364 | + case 'pending': |
|
| 365 | + $total_items = $this->pending_count; |
|
| 366 | + break; |
|
| 367 | + case 'expired': |
|
| 368 | + $total_items = $this->expired_count; |
|
| 369 | + break; |
|
| 370 | + case 'cancelled': |
|
| 371 | + $total_items = $this->cancelled_count; |
|
| 372 | + break; |
|
| 373 | + case 'failing': |
|
| 374 | + $total_items = $this->failing_count; |
|
| 375 | + break; |
|
| 376 | + case 'trialling': |
|
| 377 | + $total_items = $this->trialling_count; |
|
| 378 | + break; |
|
| 379 | + case 'completed': |
|
| 380 | + $total_items = $this->completed_count; |
|
| 381 | + break; |
|
| 382 | + case 'any': |
|
| 383 | + default: |
|
| 384 | + $total_items = $this->total_count; |
|
| 385 | + break; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $this->set_pagination_args( array( |
|
| 389 | + 'total_items' => $total_items, |
|
| 390 | + 'per_page' => $this->per_page, |
|
| 391 | + 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | + ) ); |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -8,11 +8,11 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 11 | +if (!defined('ABSPATH')) exit; |
|
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded |
| 15 | -if( ! class_exists( 'WP_List_Table' ) ) { |
|
| 15 | +if (!class_exists('WP_List_Table')) { |
|
| 16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public $pending_count = 0; |
| 36 | 36 | public $expired_count = 0; |
| 37 | 37 | public $completed_count = 0; |
| 38 | - public $trialling_count = 0; |
|
| 38 | + public $trialling_count = 0; |
|
| 39 | 39 | public $cancelled_count = 0; |
| 40 | 40 | public $failing_count = 0; |
| 41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | * @since 1.0.0 |
| 47 | 47 | * @return void |
| 48 | 48 | */ |
| 49 | - function __construct(){ |
|
| 49 | + function __construct() { |
|
| 50 | 50 | global $status, $page; |
| 51 | 51 | |
| 52 | 52 | // Set parent defaults |
| 53 | - parent::__construct( array( |
|
| 53 | + parent::__construct(array( |
|
| 54 | 54 | 'singular' => 'subscription', |
| 55 | 55 | 'plural' => 'subscriptions', |
| 56 | 56 | 'ajax' => false |
| 57 | - ) ); |
|
| 57 | + )); |
|
| 58 | 58 | |
| 59 | 59 | $this->get_subscription_counts(); |
| 60 | 60 | |
@@ -69,28 +69,28 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function get_views() { |
| 71 | 71 | |
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 72 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
| 73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | 74 | $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
| 75 | 75 | $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
| 76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | 77 | $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
| 78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | 81 | |
| 82 | 82 | $views = array( |
| 83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 83 | + 'all' => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), |
|
| 84 | + 'active' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), |
|
| 85 | + 'pending' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), |
|
| 86 | + 'expired' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), |
|
| 87 | + 'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), |
|
| 88 | + 'trialling' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), |
|
| 89 | + 'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), |
|
| 90 | + 'failing' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), |
|
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 93 | + return apply_filters('wpinv_recurring_subscriptions_table_views', $views); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -104,27 +104,27 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return void |
| 106 | 106 | */ |
| 107 | - public function search_box( $text, $input_id ) { |
|
| 107 | + public function search_box($text, $input_id) { |
|
| 108 | 108 | |
| 109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 109 | + if (empty($_REQUEST['s']) && !$this->has_items()) { |
|
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $input_id = $input_id . '-search-input'; |
| 114 | 114 | |
| 115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 115 | + if (!empty($_REQUEST['orderby'])) { |
|
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 119 | + if (!empty($_REQUEST['order'])) { |
|
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; |
|
| 121 | 121 | } |
| 122 | 122 | ?> |
| 123 | 123 | <p class="search-box"> |
| 124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
|
| 124 | + <?php do_action('wpinv_recurring_subscription_search_box'); ?> |
|
| 125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
| 126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
| 127 | - <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
|
| 127 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> |
|
| 128 | 128 | </p> |
| 129 | 129 | <?php |
| 130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @since 1.0.0 |
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | - function column_default( $item, $column_name ) { |
|
| 139 | + function column_default($item, $column_name) { |
|
| 140 | 140 | return $item->$column_name; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * @since 1.0.0 |
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | - function column_sub_id( $item ) { |
|
| 151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
|
| 150 | + function column_sub_id($item) { |
|
| 151 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | * @since 1.0.0 |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - function column_customer_id( $item ) { |
|
| 162 | - $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 161 | + function column_customer_id($item) { |
|
| 162 | + $subscriber = get_userdata($item->customer_id); |
|
| 163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | 164 | |
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @since 1.0.0 |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - function column_status( $item ) { |
|
| 175 | + function column_status($item) { |
|
| 176 | 176 | return $item->get_status_label(); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @since 1.0.0 |
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | - function column_period( $item ) { |
|
| 186 | + function column_period($item) { |
|
| 187 | 187 | |
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency); |
|
| 189 | 189 | |
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | * @since 1.0.0 |
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | - function column_bill_times( $item ) { |
|
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
| 200 | + function column_bill_times($item) { |
|
| 201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | * @since 1.0.0 |
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | - function column_initial_amount( $item ) { |
|
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 211 | + function column_initial_amount($item) { |
|
| 212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | * @since 1.0.0 |
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | - function column_renewal_date( $item ) { |
|
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 222 | + function column_renewal_date($item) { |
|
| 223 | + return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | * @since 1.0.0 |
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | - function column_parent_payment_id( $item ) { |
|
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . $item->parent_payment_id . '</a>'; |
|
| 233 | + function column_parent_payment_id($item) { |
|
| 234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . $item->parent_payment_id . '</a>'; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
| 241 | 241 | * @since 1.0.0 |
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | - function column_product_id( $item ) { |
|
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 244 | + function column_product_id($item) { |
|
| 245 | + return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | * @since 2.0 |
| 253 | 253 | * @return string |
| 254 | 254 | */ |
| 255 | - function column_actions( $item ) { |
|
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 255 | + function column_actions($item) { |
|
| 256 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -265,21 +265,21 @@ discard block |
||
| 265 | 265 | * @return array |
| 266 | 266 | */ |
| 267 | 267 | |
| 268 | - function get_columns(){ |
|
| 268 | + function get_columns() { |
|
| 269 | 269 | $columns = array( |
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
| 270 | + 'sub_id' => __('ID', 'invoicing'), |
|
| 271 | + 'customer_id' => __('Customer', 'invoicing'), |
|
| 272 | + 'status' => __('Status', 'invoicing'), |
|
| 273 | + 'period' => __('Billing Cycle', 'invoicing'), |
|
| 274 | + 'initial_amount' => __('Initial Amount', 'invoicing'), |
|
| 275 | + 'bill_times' => __('Times Billed', 'invoicing'), |
|
| 276 | + 'renewal_date' => __('Renewal Date', 'invoicing'), |
|
| 277 | + 'parent_payment_id' => __('Invoice', 'invoicing'), |
|
| 278 | + 'product_id' => __('Item', 'invoicing'), |
|
| 279 | + 'actions' => __('Actions', 'invoicing'), |
|
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 282 | + return apply_filters('wpinv_report_subscription_columns', $columns); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @return int |
| 291 | 291 | */ |
| 292 | 292 | function get_paged() { |
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -306,16 +306,16 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | $db = new WPInv_Subscriptions_DB; |
| 308 | 308 | |
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
| 310 | 310 | |
| 311 | 311 | $this->total_count = $db->count(); |
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 312 | + $this->active_count = $db->count(array('status' => 'active', 'search' => $search)); |
|
| 313 | + $this->pending_count = $db->count(array('status' => 'pending', 'search' => $search)); |
|
| 314 | + $this->expired_count = $db->count(array('status' => 'expired', 'search' => $search)); |
|
| 315 | + $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); |
|
| 316 | + $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); |
|
| 317 | + $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); |
|
| 318 | + $this->failing_count = $db->count(array('status' => 'failing', 'search' => $search)); |
|
| 319 | 319 | |
| 320 | 320 | } |
| 321 | 321 | |
@@ -336,28 +336,28 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | $columns = $this->get_columns(); |
| 338 | 338 | $hidden = array(); // No hidden columns |
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
| 340 | 340 | $sortable = $this->get_sortable_columns(); |
| 341 | 341 | |
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 343 | 343 | |
| 344 | 344 | $current_page = $this->get_pagenum(); |
| 345 | 345 | |
| 346 | 346 | $db = new WPInv_Subscriptions_DB; |
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
| 348 | 348 | $args = array( |
| 349 | 349 | 'number' => $this->per_page, |
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 350 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
| 351 | 351 | 'search' => $search |
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | - if ( 'any' !== $status ) { |
|
| 354 | + if ('any' !== $status) { |
|
| 355 | 355 | $args['status'] = $status; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $this->items = $db->get_subscriptions( $args ); |
|
| 358 | + $this->items = $db->get_subscriptions($args); |
|
| 359 | 359 | |
| 360 | - switch ( $status ) { |
|
| 360 | + switch ($status) { |
|
| 361 | 361 | case 'active': |
| 362 | 362 | $total_items = $this->active_count; |
| 363 | 363 | break; |
@@ -385,10 +385,10 @@ discard block |
||
| 385 | 385 | break; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $this->set_pagination_args( array( |
|
| 388 | + $this->set_pagination_args(array( |
|
| 389 | 389 | 'total_items' => $total_items, |
| 390 | 390 | 'per_page' => $this->per_page, |
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | - ) ); |
|
| 391 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
| 392 | + )); |
|
| 393 | 393 | } |
| 394 | 394 | } |
@@ -179,8 +179,11 @@ discard block |
||
| 179 | 179 | <label for="tablecell"> |
| 180 | 180 | <?php if( 'trialling' == $sub->status ) : ?> |
| 181 | 181 | <?php _e( 'Trialling Until:', 'invoicing' ); ?> |
| 182 | - <?php else: ?> |
|
| 183 | - <?php _e( 'Expiration Date:', 'invoicing' ); ?> |
|
| 182 | + <?php else { |
|
| 183 | + : ?> |
|
| 184 | + <?php _e( 'Expiration Date:', 'invoicing' ); |
|
| 185 | +} |
|
| 186 | +?> |
|
| 184 | 187 | <?php endif; ?> |
| 185 | 188 | </label> |
| 186 | 189 | </td> |
@@ -268,9 +271,12 @@ discard block |
||
| 268 | 271 | </td> |
| 269 | 272 | </tr> |
| 270 | 273 | <?php endforeach; ?> |
| 271 | - <?php else: ?> |
|
| 274 | + <?php else { |
|
| 275 | + : ?> |
|
| 272 | 276 | <tr> |
| 273 | - <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td> |
|
| 277 | + <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); |
|
| 278 | +} |
|
| 279 | +?></td> |
|
| 274 | 280 | </tr> |
| 275 | 281 | <?php endif; ?> |
| 276 | 282 | </tbody> |
@@ -8,23 +8,23 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function wpinv_subscriptions_page() { |
| 10 | 10 | |
| 11 | - if ( ! empty( $_GET['id'] ) ) { |
|
| 11 | + if ( ! empty( $_GET['id'] ) ) { |
|
| 12 | 12 | |
| 13 | 13 | wpinv_recurring_subscription_details(); |
| 14 | 14 | |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | |
| 17 | - } |
|
| 18 | - ?> |
|
| 17 | + } |
|
| 18 | + ?> |
|
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | |
| 21 | 21 | <h1> |
| 22 | 22 | <?php _e( 'Subscriptions', 'invoicing' ); ?> |
| 23 | 23 | </h1> |
| 24 | 24 | <?php |
| 25 | - $subscribers_table = new WPInv_Subscription_Reports_Table(); |
|
| 26 | - $subscribers_table->prepare_items(); |
|
| 27 | - ?> |
|
| 25 | + $subscribers_table = new WPInv_Subscription_Reports_Table(); |
|
| 26 | + $subscribers_table->prepare_items(); |
|
| 27 | + ?> |
|
| 28 | 28 | |
| 29 | 29 | <form id="subscribers-filter" method="get"> |
| 30 | 30 | |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | function wpinv_recurring_subscription_details() { |
| 49 | 49 | |
| 50 | - $render = true; |
|
| 50 | + $render = true; |
|
| 51 | 51 | |
| 52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 54 | - } |
|
| 52 | + if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | + die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 56 | + if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 57 | 57 | die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $sub_id = (int) $_GET['id']; |
|
| 61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
| 60 | + $sub_id = (int) $_GET['id']; |
|
| 61 | + $sub = new WPInv_Subscription( $sub_id ); |
|
| 62 | 62 | |
| 63 | - if ( empty( $sub ) ) { |
|
| 64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 65 | - } |
|
| 63 | + if ( empty( $sub ) ) { |
|
| 64 | + die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - ?> |
|
| 67 | + ?> |
|
| 68 | 68 | <div class="wrap"> |
| 69 | 69 | <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
| 70 | 70 | |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | </td> |
| 89 | 89 | <td> |
| 90 | 90 | <?php |
| 91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 95 | - ?> |
|
| 91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | + $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | + $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | + printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 95 | + ?> |
|
| 96 | 96 | </td> |
| 97 | 97 | </tr> |
| 98 | 98 | <tr> |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | ?> |
| 135 | 135 | <a href="<?php echo esc_url( add_query_arg( array( |
| 136 | - 'post' => $sub->product_id, |
|
| 137 | - 'action' => 'edit' |
|
| 138 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 136 | + 'post' => $sub->product_id, |
|
| 137 | + 'action' => 'edit' |
|
| 138 | + ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 139 | 139 | </td> |
| 140 | 140 | </tr> |
| 141 | 141 | <tr> |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | <td><?php echo wpinv_get_invoice_status( $payment->ID, true ); ?></td> |
| 262 | 262 | <td> |
| 263 | 263 | <a title="<?php _e( 'View Details for Invoice.', 'invoicing' ); |
| 264 | - echo ' ' . $payment->ID; ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"> |
|
| 264 | + echo ' ' . $payment->ID; ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"> |
|
| 265 | 265 | <?php _e( 'View Details', 'invoicing' ); ?> |
| 266 | 266 | </a> |
| 267 | 267 | <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
@@ -299,58 +299,58 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function wpinv_recurring_process_subscription_update() { |
| 301 | 301 | |
| 302 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 303 | - return; |
|
| 304 | - } |
|
| 302 | + if( empty( $_POST['sub_id'] ) ) { |
|
| 303 | + return; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 307 | - return; |
|
| 308 | - } |
|
| 306 | + if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 310 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 316 | - } |
|
| 314 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - $expiration = date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'] ) ); |
|
| 319 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 320 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 321 | - $product_id = absint( $_POST['product_id'] ); |
|
| 322 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 323 | - $subscription->update( array( |
|
| 324 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 325 | - 'expiration' => $expiration, |
|
| 326 | - 'profile_id' => $profile_id, |
|
| 327 | - 'product_id' => $product_id, |
|
| 328 | - 'transaction_id' => $transaction_id, |
|
| 329 | - ) ); |
|
| 318 | + $expiration = date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'] ) ); |
|
| 319 | + $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 320 | + $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 321 | + $product_id = absint( $_POST['product_id'] ); |
|
| 322 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 323 | + $subscription->update( array( |
|
| 324 | + 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 325 | + 'expiration' => $expiration, |
|
| 326 | + 'profile_id' => $profile_id, |
|
| 327 | + 'product_id' => $product_id, |
|
| 328 | + 'transaction_id' => $transaction_id, |
|
| 329 | + ) ); |
|
| 330 | 330 | |
| 331 | - $status = sanitize_text_field( $_POST['status'] ); |
|
| 331 | + $status = sanitize_text_field( $_POST['status'] ); |
|
| 332 | 332 | |
| 333 | - switch( $status ) { |
|
| 333 | + switch( $status ) { |
|
| 334 | 334 | |
| 335 | - case 'cancelled' : |
|
| 335 | + case 'cancelled' : |
|
| 336 | 336 | |
| 337 | - $subscription->cancel(); |
|
| 338 | - break; |
|
| 337 | + $subscription->cancel(); |
|
| 338 | + break; |
|
| 339 | 339 | |
| 340 | - case 'expired' : |
|
| 340 | + case 'expired' : |
|
| 341 | 341 | |
| 342 | - $subscription->expire(); |
|
| 343 | - break; |
|
| 342 | + $subscription->expire(); |
|
| 343 | + break; |
|
| 344 | 344 | |
| 345 | - case 'completed' : |
|
| 345 | + case 'completed' : |
|
| 346 | 346 | |
| 347 | - $subscription->complete(); |
|
| 348 | - break; |
|
| 347 | + $subscription->complete(); |
|
| 348 | + break; |
|
| 349 | 349 | |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 353 | - exit; |
|
| 352 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 353 | + exit; |
|
| 354 | 354 | |
| 355 | 355 | } |
| 356 | 356 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
@@ -364,30 +364,30 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | function wpinv_recurring_process_subscription_deletion() { |
| 366 | 366 | |
| 367 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 368 | - return; |
|
| 369 | - } |
|
| 367 | + if( empty( $_POST['sub_id'] ) ) { |
|
| 368 | + return; |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 372 | - return; |
|
| 373 | - } |
|
| 371 | + if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 372 | + return; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 376 | - return; |
|
| 377 | - } |
|
| 375 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
| 376 | + return; |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 380 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 381 | - } |
|
| 379 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 380 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 383 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 384 | 384 | |
| 385 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 385 | + delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 386 | 386 | |
| 387 | - $subscription->delete(); |
|
| 387 | + $subscription->delete(); |
|
| 388 | 388 | |
| 389 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 390 | - exit; |
|
| 389 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 390 | + exit; |
|
| 391 | 391 | |
| 392 | 392 | } |
| 393 | 393 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function wpinv_subscriptions_page() { |
| 10 | 10 | |
| 11 | - if ( ! empty( $_GET['id'] ) ) { |
|
| 11 | + if (!empty($_GET['id'])) { |
|
| 12 | 12 | |
| 13 | 13 | wpinv_recurring_subscription_details(); |
| 14 | 14 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | |
| 21 | 21 | <h1> |
| 22 | - <?php _e( 'Subscriptions', 'invoicing' ); ?> |
|
| 22 | + <?php _e('Subscriptions', 'invoicing'); ?> |
|
| 23 | 23 | </h1> |
| 24 | 24 | <?php |
| 25 | 25 | $subscribers_table = new WPInv_Subscription_Reports_Table(); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | <input type="hidden" name="post_type" value="download" /> |
| 32 | 32 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 33 | 33 | <?php $subscribers_table->views(); ?> |
| 34 | - <?php $subscribers_table->search_box( __( 'Search', 'wpinvoicing' ), 'subscriptions' ); ?> |
|
| 34 | + <?php $subscribers_table->search_box(__('Search', 'wpinvoicing'), 'subscriptions'); ?> |
|
| 35 | 35 | <?php $subscribers_table->display(); ?> |
| 36 | 36 | |
| 37 | 37 | </form> |
@@ -49,34 +49,34 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $render = true; |
| 51 | 51 | |
| 52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 52 | + if (!current_user_can('manage_invoicing')) { |
|
| 53 | + die(__('You are not permitted to view this data.', 'invoicing')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 57 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 56 | + if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { |
|
| 57 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $sub_id = (int) $_GET['id']; |
|
| 61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
| 60 | + $sub_id = (int)$_GET['id']; |
|
| 61 | + $sub = new WPInv_Subscription($sub_id); |
|
| 62 | 62 | |
| 63 | - if ( empty( $sub ) ) { |
|
| 64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 63 | + if (empty($sub)) { |
|
| 64 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | ?> |
| 68 | 68 | <div class="wrap"> |
| 69 | - <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
| 69 | + <h2><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
| 70 | 70 | |
| 71 | - <?php if ( $sub ) : ?> |
|
| 71 | + <?php if ($sub) : ?> |
|
| 72 | 72 | |
| 73 | 73 | <div id="wpinv-item-card-wrapper"> |
| 74 | 74 | |
| 75 | - <?php do_action( 'wpinv_subscription_card_top', $sub ); ?> |
|
| 75 | + <?php do_action('wpinv_subscription_card_top', $sub); ?> |
|
| 76 | 76 | |
| 77 | 77 | <div class="info-wrapper item-section"> |
| 78 | 78 | |
| 79 | - <form id="edit-item-info" method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $sub->id ); ?>"> |
|
| 79 | + <form id="edit-item-info" method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . $sub->id); ?>"> |
|
| 80 | 80 | |
| 81 | 81 | <div class="item-info"> |
| 82 | 82 | |
@@ -84,126 +84,126 @@ discard block |
||
| 84 | 84 | <tbody> |
| 85 | 85 | <tr> |
| 86 | 86 | <td class="row-title"> |
| 87 | - <label for="tablecell"><?php _e( 'Billing Cycle:', 'invoicing' ); ?></label> |
|
| 87 | + <label for="tablecell"><?php _e('Billing Cycle:', 'invoicing'); ?></label> |
|
| 88 | 88 | </td> |
| 89 | 89 | <td> |
| 90 | 90 | <?php |
| 91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($sub->period, $sub->frequency); |
|
| 92 | + $billing = wpinv_price(wpinv_format_amount($sub->recurring_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)) . ' / ' . $frequency; |
|
| 93 | + $initial = wpinv_price(wpinv_format_amount($sub->initial_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)); |
|
| 94 | + printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); |
|
| 95 | 95 | ?> |
| 96 | 96 | </td> |
| 97 | 97 | </tr> |
| 98 | 98 | <tr> |
| 99 | 99 | <td class="row-title"> |
| 100 | - <label for="tablecell"><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
| 100 | + <label for="tablecell"><?php _e('Times Billed:', 'invoicing'); ?></label> |
|
| 101 | 101 | </td> |
| 102 | - <td><?php echo $sub->get_times_billed() . ' / ' . ( ( $sub->bill_times == 0 ) ? 'Until Cancelled' : $sub->bill_times ); ?></td> |
|
| 102 | + <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? 'Until Cancelled' : $sub->bill_times); ?></td> |
|
| 103 | 103 | </tr> |
| 104 | 104 | <tr> |
| 105 | 105 | <td class="row-title"> |
| 106 | - <label for="tablecell"><?php _e( 'Customer:', 'invoicing' ); ?></label> |
|
| 106 | + <label for="tablecell"><?php _e('Customer:', 'invoicing'); ?></label> |
|
| 107 | 107 | </td> |
| 108 | 108 | <td> |
| 109 | - <?php $subscriber = get_userdata( $sub->customer_id ); ?> |
|
| 110 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&view=overview&id=' . $subscriber->ID ) ); ?>" target="_blank"><?php echo ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
| 109 | + <?php $subscriber = get_userdata($sub->customer_id); ?> |
|
| 110 | + <a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&view=overview&id=' . $subscriber->ID)); ?>" target="_blank"><?php echo !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
| 111 | 111 | </td> |
| 112 | 112 | </tr> |
| 113 | 113 | <tr> |
| 114 | 114 | <td class="row-title"> |
| 115 | - <label for="tablecell"><?php _e( 'Initial Purchase ID:', 'invoicing' ); ?></label> |
|
| 115 | + <label for="tablecell"><?php _e('Initial Purchase ID:', 'invoicing'); ?></label> |
|
| 116 | 116 | </td> |
| 117 | - <td><?php echo '<a href="' . get_edit_post_link( $sub->parent_payment_id ) . '" target="_blank">' . $sub->parent_payment_id . '</a>'; ?></td> |
|
| 117 | + <td><?php echo '<a href="' . get_edit_post_link($sub->parent_payment_id) . '" target="_blank">' . $sub->parent_payment_id . '</a>'; ?></td> |
|
| 118 | 118 | </tr> |
| 119 | 119 | <tr> |
| 120 | 120 | <td class="row-title"> |
| 121 | - <label for="tablecell"><?php _e( 'Item:', 'invoicing' ); ?></label> |
|
| 121 | + <label for="tablecell"><?php _e('Item:', 'invoicing'); ?></label> |
|
| 122 | 122 | </td> |
| 123 | 123 | <td> |
| 124 | 124 | <?php |
| 125 | - echo wpinv_item_dropdown( array( |
|
| 125 | + echo wpinv_item_dropdown(array( |
|
| 126 | 126 | 'name' => 'product_id', |
| 127 | 127 | 'id' => 'wpinv_invoice_item', |
| 128 | 128 | 'with_packages' => false, |
| 129 | 129 | 'show_recurring' => true, |
| 130 | 130 | 'selected' => $sub->product_id, |
| 131 | 131 | 'class' => 'wpinv-sub-product-id', |
| 132 | - ) ); |
|
| 132 | + )); |
|
| 133 | 133 | |
| 134 | 134 | ?> |
| 135 | - <a href="<?php echo esc_url( add_query_arg( array( |
|
| 135 | + <a href="<?php echo esc_url(add_query_arg(array( |
|
| 136 | 136 | 'post' => $sub->product_id, |
| 137 | 137 | 'action' => 'edit' |
| 138 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 138 | + ), admin_url('post.php'))); ?>" target="_blank"><?php _e('View Item', 'invoicing'); ?></a> |
|
| 139 | 139 | </td> |
| 140 | 140 | </tr> |
| 141 | 141 | <tr> |
| 142 | 142 | <td class="row-title"> |
| 143 | - <label for="tablecell"><?php _e( 'Payment Method:', 'invoicing' ); ?></label> |
|
| 143 | + <label for="tablecell"><?php _e('Payment Method:', 'invoicing'); ?></label> |
|
| 144 | 144 | </td> |
| 145 | - <td><?php echo wpinv_get_gateway_admin_label( wpinv_get_payment_gateway( $sub->parent_payment_id ) ); ?></td> |
|
| 145 | + <td><?php echo wpinv_get_gateway_admin_label(wpinv_get_payment_gateway($sub->parent_payment_id)); ?></td> |
|
| 146 | 146 | </tr> |
| 147 | 147 | <tr> |
| 148 | 148 | <td class="row-title"> |
| 149 | - <label for="tablecell"><?php _e( 'Profile ID:', 'invoicing' ); ?></label> |
|
| 149 | + <label for="tablecell"><?php _e('Profile ID:', 'invoicing'); ?></label> |
|
| 150 | 150 | </td> |
| 151 | 151 | <td> |
| 152 | 152 | <span class="wpinv-sub-profile-id"> |
| 153 | - <?php echo apply_filters( 'wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub ); ?> |
|
| 153 | + <?php echo apply_filters('wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub); ?> |
|
| 154 | 154 | </span> |
| 155 | - <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr( $sub->profile_id ); ?>" /> |
|
| 155 | + <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr($sub->profile_id); ?>" /> |
|
| 156 | 156 | <span> – </span> |
| 157 | - <a href="#" class="wpinv-edit-sub-profile-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 157 | + <a href="#" class="wpinv-edit-sub-profile-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 158 | 158 | </td> |
| 159 | 159 | </tr> |
| 160 | 160 | <tr> |
| 161 | 161 | <td class="row-title"> |
| 162 | - <label for="tablecell"><?php _e( 'Transaction ID:', 'invoicing' ); ?></label> |
|
| 162 | + <label for="tablecell"><?php _e('Transaction ID:', 'invoicing'); ?></label> |
|
| 163 | 163 | </td> |
| 164 | 164 | <td> |
| 165 | 165 | <span class="wpinv-sub-transaction-id"><?php echo $sub->get_transaction_id(); ?></span> |
| 166 | - <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr( $sub->get_transaction_id() ); ?>" /> |
|
| 166 | + <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr($sub->get_transaction_id()); ?>" /> |
|
| 167 | 167 | <span> – </span> |
| 168 | - <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 168 | + <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 169 | 169 | </td> |
| 170 | 170 | </tr> |
| 171 | 171 | <tr> |
| 172 | 172 | <td class="row-title"> |
| 173 | - <label for="tablecell"><?php _e( 'Date Created:', 'invoicing' ); ?></label> |
|
| 173 | + <label for="tablecell"><?php _e('Date Created:', 'invoicing'); ?></label> |
|
| 174 | 174 | </td> |
| 175 | - <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->created, current_time( 'timestamp' ) ) ); ?></td> |
|
| 175 | + <td><?php echo date_i18n(get_option('date_format'), strtotime($sub->created, current_time('timestamp'))); ?></td> |
|
| 176 | 176 | </tr> |
| 177 | 177 | <tr> |
| 178 | 178 | <td class="row-title"> |
| 179 | 179 | <label for="tablecell"> |
| 180 | - <?php if( 'trialling' == $sub->status ) : ?> |
|
| 181 | - <?php _e( 'Trialling Until:', 'invoicing' ); ?> |
|
| 180 | + <?php if ('trialling' == $sub->status) : ?> |
|
| 181 | + <?php _e('Trialling Until:', 'invoicing'); ?> |
|
| 182 | 182 | <?php else: ?> |
| 183 | - <?php _e( 'Expiration Date:', 'invoicing' ); ?> |
|
| 183 | + <?php _e('Expiration Date:', 'invoicing'); ?> |
|
| 184 | 184 | <?php endif; ?> |
| 185 | 185 | </label> |
| 186 | 186 | </td> |
| 187 | 187 | <td> |
| 188 | - <span class="wpinv-sub-expiration"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->expiration, current_time( 'timestamp' ) ) ); ?></span> |
|
| 189 | - <input type="text" name="expiration" class="wpiDatepicker hidden wpinv-sub-expiration" data-dateFormat="mm/dd/yy" value="<?php echo esc_attr( $sub->expiration ); ?>" /> |
|
| 188 | + <span class="wpinv-sub-expiration"><?php echo date_i18n(get_option('date_format'), strtotime($sub->expiration, current_time('timestamp'))); ?></span> |
|
| 189 | + <input type="text" name="expiration" class="wpiDatepicker hidden wpinv-sub-expiration" data-dateFormat="mm/dd/yy" value="<?php echo esc_attr($sub->expiration); ?>" /> |
|
| 190 | 190 | <span> – </span> |
| 191 | - <a href="#" class="wpinv-edit-sub-expiration"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 191 | + <a href="#" class="wpinv-edit-sub-expiration"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 192 | 192 | </td> |
| 193 | 193 | </tr> |
| 194 | 194 | <tr> |
| 195 | 195 | <td class="row-title"> |
| 196 | - <label for="tablecell"><?php _e( 'Subscription Status:', 'invoicing' ); ?></label> |
|
| 196 | + <label for="tablecell"><?php _e('Subscription Status:', 'invoicing'); ?></label> |
|
| 197 | 197 | </td> |
| 198 | 198 | <td> |
| 199 | 199 | <select name="status"> |
| 200 | - <option value="pending"<?php selected( 'pending', $sub->status ); ?>><?php _e( 'Pending', 'invoicing' ); ?></option> |
|
| 201 | - <option value="active"<?php selected( 'active', $sub->status ); ?>><?php _e( 'Active', 'invoicing' ); ?></option> |
|
| 202 | - <option value="cancelled"<?php selected( 'cancelled', $sub->status ); ?>><?php _e( 'Cancelled', 'invoicing' ); ?></option> |
|
| 203 | - <option value="expired"<?php selected( 'expired', $sub->status ); ?>><?php _e( 'Expired', 'invoicing' ); ?></option> |
|
| 204 | - <option value="trialling"<?php selected( 'trialling', $sub->status ); ?>><?php _e( 'Trialling', 'invoicing' ); ?></option> |
|
| 205 | - <option value="failing"<?php selected( 'failing', $sub->status ); ?>><?php _e( 'Failing', 'invoicing' ); ?></option> |
|
| 206 | - <option value="completed"<?php selected( 'completed', $sub->status ); ?>><?php _e( 'Completed', 'invoicing' ); ?></option> |
|
| 200 | + <option value="pending"<?php selected('pending', $sub->status); ?>><?php _e('Pending', 'invoicing'); ?></option> |
|
| 201 | + <option value="active"<?php selected('active', $sub->status); ?>><?php _e('Active', 'invoicing'); ?></option> |
|
| 202 | + <option value="cancelled"<?php selected('cancelled', $sub->status); ?>><?php _e('Cancelled', 'invoicing'); ?></option> |
|
| 203 | + <option value="expired"<?php selected('expired', $sub->status); ?>><?php _e('Expired', 'invoicing'); ?></option> |
|
| 204 | + <option value="trialling"<?php selected('trialling', $sub->status); ?>><?php _e('Trialling', 'invoicing'); ?></option> |
|
| 205 | + <option value="failing"<?php selected('failing', $sub->status); ?>><?php _e('Failing', 'invoicing'); ?></option> |
|
| 206 | + <option value="completed"<?php selected('completed', $sub->status); ?>><?php _e('Completed', 'invoicing'); ?></option> |
|
| 207 | 207 | </select> |
| 208 | 208 | </td> |
| 209 | 209 | </tr> |
@@ -211,77 +211,77 @@ discard block |
||
| 211 | 211 | </table> |
| 212 | 212 | </div> |
| 213 | 213 | <div id="wpinv-sub-notices"> |
| 214 | - <div class="notice notice-info inline hidden" id="wpinv-sub-expiration-update-notice"><p><?php _e( 'Changing the expiration date will not affect when renewal payments are processed.', 'invoicing' ); ?></p></div> |
|
| 215 | - <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e( 'Changing the product assigned will not automatically adjust any pricing.', 'invoicing' ); ?></p></div> |
|
| 216 | - <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e( 'Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing' ); ?></p></div> |
|
| 214 | + <div class="notice notice-info inline hidden" id="wpinv-sub-expiration-update-notice"><p><?php _e('Changing the expiration date will not affect when renewal payments are processed.', 'invoicing'); ?></p></div> |
|
| 215 | + <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e('Changing the product assigned will not automatically adjust any pricing.', 'invoicing'); ?></p></div> |
|
| 216 | + <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e('Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing'); ?></p></div> |
|
| 217 | 217 | </div> |
| 218 | 218 | <div id="item-edit-actions" class="edit-item" style="float:right; margin: 10px 0 0; display: block;"> |
| 219 | - <?php wp_nonce_field( 'wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true ); ?> |
|
| 220 | - <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e( 'Update Subscription', 'invoicing' ); ?>"/> |
|
| 221 | - <input type="hidden" name="sub_id" value="<?php echo absint( $sub->id ); ?>" /> |
|
| 222 | - <?php if( $sub->can_cancel() ) : ?> |
|
| 223 | - <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e( 'Cancel Subscription', 'invoicing' ); ?></a> |
|
| 219 | + <?php wp_nonce_field('wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true); ?> |
|
| 220 | + <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e('Update Subscription', 'invoicing'); ?>"/> |
|
| 221 | + <input type="hidden" name="sub_id" value="<?php echo absint($sub->id); ?>" /> |
|
| 222 | + <?php if ($sub->can_cancel()) : ?> |
|
| 223 | + <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e('Cancel Subscription', 'invoicing'); ?></a> |
|
| 224 | 224 | <?php endif; ?> |
| 225 | - <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e( 'Delete Subscription', 'invoicing' ); ?>"/> |
|
| 225 | + <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e('Delete Subscription', 'invoicing'); ?>"/> |
|
| 226 | 226 | </div> |
| 227 | 227 | |
| 228 | 228 | </form> |
| 229 | 229 | </div> |
| 230 | 230 | |
| 231 | - <?php do_action( 'wpinv_subscription_before_stats', $sub ); ?> |
|
| 231 | + <?php do_action('wpinv_subscription_before_stats', $sub); ?> |
|
| 232 | 232 | |
| 233 | - <?php do_action( 'wpinv_subscription_before_tables_wrapper', $sub ); ?> |
|
| 233 | + <?php do_action('wpinv_subscription_before_tables_wrapper', $sub); ?> |
|
| 234 | 234 | |
| 235 | 235 | <div id="item-tables-wrapper" class="item-section"> |
| 236 | 236 | |
| 237 | - <?php do_action( 'wpinv_subscription_before_tables', $sub ); ?> |
|
| 237 | + <?php do_action('wpinv_subscription_before_tables', $sub); ?> |
|
| 238 | 238 | |
| 239 | - <h3><?php _e( 'Renewal Invoices:', 'invoicing' ); ?></h3> |
|
| 239 | + <h3><?php _e('Renewal Invoices:', 'invoicing'); ?></h3> |
|
| 240 | 240 | <?php $payments = $sub->get_child_payments(); ?> |
| 241 | - <?php if( 'manual' == $sub->gateway ) : ?> |
|
| 242 | - <p><strong><?php _e( 'Note:', 'invoicing' ); ?></strong> <?php _e( 'Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing' ); ?></p> |
|
| 241 | + <?php if ('manual' == $sub->gateway) : ?> |
|
| 242 | + <p><strong><?php _e('Note:', 'invoicing'); ?></strong> <?php _e('Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing'); ?></p> |
|
| 243 | 243 | <?php endif; ?> |
| 244 | 244 | <table class="wp-list-table widefat striped payments"> |
| 245 | 245 | <thead> |
| 246 | 246 | <tr> |
| 247 | - <th><?php _e( 'ID', 'invoicing' ); ?></th> |
|
| 248 | - <th><?php _e( 'Amount', 'invoicing' ); ?></th> |
|
| 249 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
| 250 | - <th><?php _e( 'Status', 'invoicing' ); ?></th> |
|
| 251 | - <th><?php _e( 'Actions', 'invoicing' ); ?></th> |
|
| 247 | + <th><?php _e('ID', 'invoicing'); ?></th> |
|
| 248 | + <th><?php _e('Amount', 'invoicing'); ?></th> |
|
| 249 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 250 | + <th><?php _e('Status', 'invoicing'); ?></th> |
|
| 251 | + <th><?php _e('Actions', 'invoicing'); ?></th> |
|
| 252 | 252 | </tr> |
| 253 | 253 | </thead> |
| 254 | 254 | <tbody> |
| 255 | - <?php if ( ! empty( $payments ) ) : ?> |
|
| 256 | - <?php foreach ( $payments as $payment ) : ?> |
|
| 255 | + <?php if (!empty($payments)) : ?> |
|
| 256 | + <?php foreach ($payments as $payment) : ?> |
|
| 257 | 257 | <tr> |
| 258 | 258 | <td><?php echo $payment->ID; ?></td> |
| 259 | - <td><?php echo wpinv_payment_total( $payment->ID ); ?></td> |
|
| 260 | - <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $payment->post_date ) ); ?></td> |
|
| 261 | - <td><?php echo wpinv_get_invoice_status( $payment->ID, true ); ?></td> |
|
| 259 | + <td><?php echo wpinv_payment_total($payment->ID); ?></td> |
|
| 260 | + <td><?php echo date_i18n(get_option('date_format'), strtotime($payment->post_date)); ?></td> |
|
| 261 | + <td><?php echo wpinv_get_invoice_status($payment->ID, true); ?></td> |
|
| 262 | 262 | <td> |
| 263 | - <a title="<?php _e( 'View Details for Invoice.', 'invoicing' ); |
|
| 264 | - echo ' ' . $payment->ID; ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"> |
|
| 265 | - <?php _e( 'View Details', 'invoicing' ); ?> |
|
| 263 | + <a title="<?php _e('View Details for Invoice.', 'invoicing'); |
|
| 264 | + echo ' ' . $payment->ID; ?>" href="<?php echo get_edit_post_link($payment->ID); ?>"> |
|
| 265 | + <?php _e('View Details', 'invoicing'); ?> |
|
| 266 | 266 | </a> |
| 267 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
| 267 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
| 268 | 268 | </td> |
| 269 | 269 | </tr> |
| 270 | 270 | <?php endforeach; ?> |
| 271 | 271 | <?php else: ?> |
| 272 | 272 | <tr> |
| 273 | - <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td> |
|
| 273 | + <td colspan="5"><?php _e('No Invoices Found.', 'invoicing'); ?></td> |
|
| 274 | 274 | </tr> |
| 275 | 275 | <?php endif; ?> |
| 276 | 276 | </tbody> |
| 277 | 277 | <tfoot></tfoot> |
| 278 | 278 | </table> |
| 279 | 279 | |
| 280 | - <?php do_action( 'wpinv_subscription_after_tables', $sub ); ?> |
|
| 280 | + <?php do_action('wpinv_subscription_after_tables', $sub); ?> |
|
| 281 | 281 | |
| 282 | 282 | </div> |
| 283 | 283 | |
| 284 | - <?php do_action( 'wpinv_subscription_card_bottom', $sub ); ?> |
|
| 284 | + <?php do_action('wpinv_subscription_card_bottom', $sub); ?> |
|
| 285 | 285 | </div> |
| 286 | 286 | |
| 287 | 287 | <?php endif; ?> |
@@ -299,38 +299,38 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function wpinv_recurring_process_subscription_update() { |
| 301 | 301 | |
| 302 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 302 | + if (empty($_POST['sub_id'])) { |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 306 | + if (empty($_POST['wpinv_update_subscription'])) { |
|
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 310 | + if (!current_user_can('manage_invoicing')) { |
|
| 311 | 311 | return; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 314 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 315 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $expiration = date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'] ) ); |
|
| 319 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 320 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 321 | - $product_id = absint( $_POST['product_id'] ); |
|
| 322 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 323 | - $subscription->update( array( |
|
| 324 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 318 | + $expiration = date('Y-m-d 23:59:59', strtotime($_POST['expiration'])); |
|
| 319 | + $profile_id = sanitize_text_field($_POST['profile_id']); |
|
| 320 | + $transaction_id = sanitize_text_field($_POST['transaction_id']); |
|
| 321 | + $product_id = absint($_POST['product_id']); |
|
| 322 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 323 | + $subscription->update(array( |
|
| 324 | + 'status' => sanitize_text_field($_POST['status']), |
|
| 325 | 325 | 'expiration' => $expiration, |
| 326 | 326 | 'profile_id' => $profile_id, |
| 327 | 327 | 'product_id' => $product_id, |
| 328 | 328 | 'transaction_id' => $transaction_id, |
| 329 | - ) ); |
|
| 329 | + )); |
|
| 330 | 330 | |
| 331 | - $status = sanitize_text_field( $_POST['status'] ); |
|
| 331 | + $status = sanitize_text_field($_POST['status']); |
|
| 332 | 332 | |
| 333 | - switch( $status ) { |
|
| 333 | + switch ($status) { |
|
| 334 | 334 | |
| 335 | 335 | case 'cancelled' : |
| 336 | 336 | |
@@ -349,11 +349,11 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 352 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id)); |
|
| 353 | 353 | exit; |
| 354 | 354 | |
| 355 | 355 | } |
| 356 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
|
| 356 | +add_action('admin_init', 'wpinv_recurring_process_subscription_update', 1); |
|
| 357 | 357 | |
| 358 | 358 | /** |
| 359 | 359 | * Handles subscription deletion |
@@ -364,30 +364,30 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | function wpinv_recurring_process_subscription_deletion() { |
| 366 | 366 | |
| 367 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 367 | + if (empty($_POST['sub_id'])) { |
|
| 368 | 368 | return; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 371 | + if (empty($_POST['wpinv_delete_subscription'])) { |
|
| 372 | 372 | return; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 375 | + if (!current_user_can('manage_invoicing')) { |
|
| 376 | 376 | return; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 380 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 379 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 380 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 383 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 384 | 384 | |
| 385 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 385 | + delete_post_meta($subscription->parent_payment_id, '_wpinv_subscription_payment'); |
|
| 386 | 386 | |
| 387 | 387 | $subscription->delete(); |
| 388 | 388 | |
| 389 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 389 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted')); |
|
| 390 | 390 | exit; |
| 391 | 391 | |
| 392 | 392 | } |
| 393 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
|
| 393 | +add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2); |
|
@@ -1,6 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | function wpinv_subscription_init() { |
| 6 | 8 | return WPInv_Subscriptions::instance(); |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | function wpinv_subscription_init() { |
| 6 | 6 | return WPInv_Subscriptions::instance(); |
| 7 | 7 | } |
| 8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
| 8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * Main WPInv_Subscriptions Instance |
| 21 | 21 | */ |
| 22 | 22 | public static function instance() { |
| 23 | - if ( ! isset( self::$instance ) ) { |
|
| 23 | + if (!isset(self::$instance)) { |
|
| 24 | 24 | self::$instance = new WPInv_Subscriptions; |
| 25 | 25 | |
| 26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @since 1.0.0 |
| 36 | 36 | */ |
| 37 | - private function __construct(){ |
|
| 37 | + private function __construct() { |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | private function setup_constants() { |
| 64 | 64 | |
| 65 | 65 | // Make sure CAL_GREGORIAN is defined. |
| 66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
| 67 | - define( 'CAL_GREGORIAN', 1 ); |
|
| 66 | + if (!defined('CAL_GREGORIAN')) { |
|
| 67 | + define('CAL_GREGORIAN', 1); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | private function actions() { |
| 78 | 78 | |
| 79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 10 ); |
|
| 80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
| 81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
| 82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
| 83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
| 84 | - add_action( 'wpi-pending_wpi_invoice', array( $this, 'wpinv_add_update_subscription' ), 10, 2 ); |
|
| 85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
| 79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 10); |
|
| 80 | + add_action('admin_notices', array($this, 'notices')); |
|
| 81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
| 82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
| 83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
| 84 | + add_action('wpi-pending_wpi_invoice', array($this, 'wpinv_add_update_subscription'), 10, 2); |
|
| 85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | public function wpinv_subscriptions_list() { |
| 105 | 105 | add_submenu_page( |
| 106 | 106 | 'wpinv', |
| 107 | - __( 'Subscriptions', 'invoicing' ), |
|
| 108 | - __( 'Subscriptions', 'invoicing' ), |
|
| 107 | + __('Subscriptions', 'invoicing'), |
|
| 108 | + __('Subscriptions', 'invoicing'), |
|
| 109 | 109 | 'manage_invoicing', |
| 110 | 110 | 'wpinv-subscriptions', |
| 111 | 111 | 'wpinv_subscriptions_page' |
@@ -114,37 +114,37 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | public function notices() { |
| 116 | 116 | |
| 117 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
| 117 | + if (empty($_GET['wpinv-message'])) { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $type = 'updated'; |
| 122 | 122 | $message = ''; |
| 123 | 123 | |
| 124 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
| 124 | + switch (strtolower($_GET['wpinv-message'])) { |
|
| 125 | 125 | |
| 126 | 126 | case 'updated' : |
| 127 | 127 | |
| 128 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
| 128 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
| 129 | 129 | |
| 130 | 130 | break; |
| 131 | 131 | |
| 132 | 132 | case 'deleted' : |
| 133 | 133 | |
| 134 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
| 134 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
| 135 | 135 | |
| 136 | 136 | break; |
| 137 | 137 | |
| 138 | 138 | case 'cancelled' : |
| 139 | 139 | |
| 140 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
| 140 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
| 141 | 141 | |
| 142 | 142 | break; |
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( ! empty( $message ) ) { |
|
| 147 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
| 146 | + if (!empty($message)) { |
|
| 147 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | } |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * @return void |
| 158 | 158 | */ |
| 159 | 159 | function wpinv_get_actions() { |
| 160 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
| 161 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
| 160 | + if (isset($_GET['wpinv_action'])) { |
|
| 161 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | * @return void |
| 171 | 171 | */ |
| 172 | 172 | function wpinv_post_actions() { |
| 173 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
| 174 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
| 173 | + if (isset($_POST['wpinv_action'])) { |
|
| 174 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -182,24 +182,24 @@ discard block |
||
| 182 | 182 | * @param int $frequency_count The frequency of the period. |
| 183 | 183 | * @return mixed|string|void |
| 184 | 184 | */ |
| 185 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
| 185 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
| 186 | 186 | $frequency = ''; |
| 187 | 187 | //Format period details |
| 188 | - switch ( $period ) { |
|
| 188 | + switch ($period) { |
|
| 189 | 189 | case 'day' : |
| 190 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
| 190 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
| 191 | 191 | break; |
| 192 | 192 | case 'week' : |
| 193 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
| 193 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
| 194 | 194 | break; |
| 195 | 195 | case 'month' : |
| 196 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
| 196 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
| 197 | 197 | break; |
| 198 | 198 | case 'year' : |
| 199 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
| 199 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
| 200 | 200 | break; |
| 201 | 201 | default : |
| 202 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
| 202 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
| 203 | 203 | break; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -214,50 +214,50 @@ discard block |
||
| 214 | 214 | * @since 1.0.0 |
| 215 | 215 | * @return void |
| 216 | 216 | */ |
| 217 | - public function wpinv_process_cancellation( $data ) { |
|
| 217 | + public function wpinv_process_cancellation($data) { |
|
| 218 | 218 | |
| 219 | 219 | |
| 220 | - if( empty( $data['sub_id'] ) ) { |
|
| 220 | + if (empty($data['sub_id'])) { |
|
| 221 | 221 | return; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if( ! is_user_logged_in() ) { |
|
| 224 | + if (!is_user_logged_in()) { |
|
| 225 | 225 | return; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
| 229 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 228 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
| 229 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
| 233 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
| 232 | + $data['sub_id'] = absint($data['sub_id']); |
|
| 233 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
| 234 | 234 | |
| 235 | - if( ! $subscription->can_cancel() ) { |
|
| 236 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 235 | + if (!$subscription->can_cancel()) { |
|
| 236 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | try { |
| 240 | 240 | |
| 241 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
| 241 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
| 242 | 242 | |
| 243 | 243 | $subscription->cancel(); |
| 244 | 244 | |
| 245 | - if( is_admin() ) { |
|
| 245 | + if (is_admin()) { |
|
| 246 | 246 | |
| 247 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
| 247 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
| 248 | 248 | exit; |
| 249 | 249 | |
| 250 | 250 | } else { |
| 251 | 251 | |
| 252 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
| 253 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
| 254 | - wp_safe_redirect( $redirect ); |
|
| 252 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
| 253 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
| 254 | + wp_safe_redirect($redirect); |
|
| 255 | 255 | exit; |
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - } catch ( Exception $e ) { |
|
| 260 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
| 259 | + } catch (Exception $e) { |
|
| 260 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | } |
@@ -269,46 +269,46 @@ discard block |
||
| 269 | 269 | * @since 1.0.0 |
| 270 | 270 | * @return void |
| 271 | 271 | */ |
| 272 | - public function wpinv_add_update_subscription( $invoice_id, $invoice ) { |
|
| 272 | + public function wpinv_add_update_subscription($invoice_id, $invoice) { |
|
| 273 | 273 | |
| 274 | - remove_action( 'save_post', __FUNCTION__ ); |
|
| 274 | + remove_action('save_post', __FUNCTION__); |
|
| 275 | 275 | |
| 276 | - if(empty($invoice_id) || 'wpi_invoice' != get_post_type($invoice_id)){ |
|
| 276 | + if (empty($invoice_id) || 'wpi_invoice' != get_post_type($invoice_id)) { |
|
| 277 | 277 | return; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( defined( 'DOING_AUTOSAVE' ) ) { |
|
| 280 | + if (defined('DOING_AUTOSAVE')) { |
|
| 281 | 281 | return; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 284 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
| 285 | 285 | return; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $invoice_obj = new WPInv_Invoice($invoice_id); |
| 289 | 289 | |
| 290 | - if ( !$invoice_obj->is_recurring() ) { |
|
| 290 | + if (!$invoice_obj->is_recurring()) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $item_id = $invoice_obj->get_recurring(); |
| 295 | - $item = new WPInv_Item( $item_id ); |
|
| 295 | + $item = new WPInv_Item($item_id); |
|
| 296 | 296 | |
| 297 | 297 | $period = $item->get_recurring_period(true); |
| 298 | 298 | $interval = $item->get_recurring_interval(); |
| 299 | 299 | $bill_times = (int)$item->get_recurring_limit(); |
| 300 | - $initial_amount = wpinv_sanitize_amount( $invoice_obj->get_total(), 2 ); |
|
| 301 | - $recurring_amount = wpinv_sanitize_amount( $invoice_obj->get_recurring_details( 'total' ), 2 ); |
|
| 300 | + $initial_amount = wpinv_sanitize_amount($invoice_obj->get_total(), 2); |
|
| 301 | + $recurring_amount = wpinv_sanitize_amount($invoice_obj->get_recurring_details('total'), 2); |
|
| 302 | 302 | $status = 'pending'; |
| 303 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $interval . ' ' . $period . ' 23:59:59', current_time( 'timestamp' ) ) ); |
|
| 303 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $interval . ' ' . $period . ' 23:59:59', current_time('timestamp'))); |
|
| 304 | 304 | |
| 305 | 305 | |
| 306 | 306 | $trial_period = ''; |
| 307 | - if ( $invoice_obj->is_free_trial() && $item->has_free_trial() ) { |
|
| 307 | + if ($invoice_obj->is_free_trial() && $item->has_free_trial()) { |
|
| 308 | 308 | $trial_period = $item->get_trial_period(true); |
| 309 | 309 | $free_trial = $item->get_free_trial(); |
| 310 | - $trial_period = ! empty( $invoice_obj->is_free_trial() ) ? $free_trial . ' ' . $trial_period : ''; |
|
| 311 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $trial_period . ' 23:59:59', current_time( 'timestamp' ) ) ); |
|
| 310 | + $trial_period = !empty($invoice_obj->is_free_trial()) ? $free_trial . ' ' . $trial_period : ''; |
|
| 311 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $trial_period . ' 23:59:59', current_time('timestamp'))); |
|
| 312 | 312 | $status = 'trialling'; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | 'initial_amount' => $initial_amount, |
| 323 | 323 | 'recurring_amount' => $recurring_amount, |
| 324 | 324 | 'bill_times' => $bill_times, |
| 325 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
| 325 | + 'created' => date('Y-m-d H:i:s'), |
|
| 326 | 326 | 'expiration' => $expiration, |
| 327 | 327 | 'trial_period' => $trial_period, |
| 328 | 328 | 'profile_id' => '', |
@@ -330,13 +330,13 @@ discard block |
||
| 330 | 330 | ); |
| 331 | 331 | |
| 332 | 332 | $subs_db = new WPInv_Subscriptions_DB; |
| 333 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_obj->ID, 'number' => 1 ) ); |
|
| 334 | - $subscription = reset( $subs ); |
|
| 333 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_obj->ID, 'number' => 1)); |
|
| 334 | + $subscription = reset($subs); |
|
| 335 | 335 | |
| 336 | - if( !$subscription || $subscription->id <= 0 ) { |
|
| 336 | + if (!$subscription || $subscription->id <= 0) { |
|
| 337 | 337 | |
| 338 | 338 | $subscription = new WPInv_Subscription(); |
| 339 | - $subscription->create( $args ); |
|
| 339 | + $subscription->create($args); |
|
| 340 | 340 | |
| 341 | 341 | } |
| 342 | 342 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @since 2.4 |
| 259 | 259 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 260 | - * @return bool |
|
| 260 | + * @return false|string |
|
| 261 | 261 | */ |
| 262 | 262 | public function add_payment( $args = array() ) { |
| 263 | 263 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * Retrieves the transaction ID from the subscription |
| 287 | 287 | * |
| 288 | 288 | * @since 1.0.0 |
| 289 | - * @return bool |
|
| 289 | + * @return string |
|
| 290 | 290 | */ |
| 291 | 291 | public function get_transaction_id() { |
| 292 | 292 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | * Stores the transaction ID for the subscription purchase |
| 309 | 309 | * |
| 310 | 310 | * @since 1.0.0.4 |
| 311 | - * @return bool |
|
| 311 | + * @return boolean|null |
|
| 312 | 312 | */ |
| 313 | 313 | public function set_transaction_id( $txn_id = '' ) { |
| 314 | 314 | $this->update( array( 'transaction_id' => $txn_id ) ); |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * Renews a subscription |
| 320 | 320 | * |
| 321 | 321 | * @since 1.0.0 |
| 322 | - * @return bool |
|
| 322 | + * @return boolean|null |
|
| 323 | 323 | */ |
| 324 | 324 | public function renew() { |
| 325 | 325 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @since 1.0.0 |
| 410 | 410 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
| 411 | - * @return void |
|
| 411 | + * @return false|null |
|
| 412 | 412 | */ |
| 413 | 413 | public function expire( $check_expiration = false ) { |
| 414 | 414 | |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | * Retrieves the subscription status |
| 656 | 656 | * |
| 657 | 657 | * @since 1.0.0 |
| 658 | - * @return int |
|
| 658 | + * @return string |
|
| 659 | 659 | */ |
| 660 | 660 | public function get_status() { |
| 661 | 661 | |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | - exit; |
|
| 5 | + exit; |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -13,252 +13,252 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | class WPInv_Subscription { |
| 15 | 15 | |
| 16 | - private $subs_db; |
|
| 16 | + private $subs_db; |
|
| 17 | + |
|
| 18 | + public $id = 0; |
|
| 19 | + public $customer_id = 0; |
|
| 20 | + public $period = ''; |
|
| 21 | + public $initial_amount = ''; |
|
| 22 | + public $recurring_amount = ''; |
|
| 23 | + public $bill_times = 0; |
|
| 24 | + public $transaction_id = ''; |
|
| 25 | + public $parent_payment_id = 0; |
|
| 26 | + public $product_id = 0; |
|
| 27 | + public $created = '0000-00-00 00:00:00'; |
|
| 28 | + public $expiration = '0000-00-00 00:00:00'; |
|
| 29 | + public $trial_period = ''; |
|
| 30 | + public $status = 'pending'; |
|
| 31 | + public $profile_id = ''; |
|
| 32 | + public $gateway = ''; |
|
| 33 | + public $customer; |
|
| 17 | 34 | |
| 18 | - public $id = 0; |
|
| 19 | - public $customer_id = 0; |
|
| 20 | - public $period = ''; |
|
| 21 | - public $initial_amount = ''; |
|
| 22 | - public $recurring_amount = ''; |
|
| 23 | - public $bill_times = 0; |
|
| 24 | - public $transaction_id = ''; |
|
| 25 | - public $parent_payment_id = 0; |
|
| 26 | - public $product_id = 0; |
|
| 27 | - public $created = '0000-00-00 00:00:00'; |
|
| 28 | - public $expiration = '0000-00-00 00:00:00'; |
|
| 29 | - public $trial_period = ''; |
|
| 30 | - public $status = 'pending'; |
|
| 31 | - public $profile_id = ''; |
|
| 32 | - public $gateway = ''; |
|
| 33 | - public $customer; |
|
| 35 | + /** |
|
| 36 | + * Get us started |
|
| 37 | + * |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
| 34 | 42 | |
| 35 | - /** |
|
| 36 | - * Get us started |
|
| 37 | - * |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
| 43 | + $this->subs_db = new WPInv_Subscriptions_DB; |
|
| 42 | 44 | |
| 43 | - $this->subs_db = new WPInv_Subscriptions_DB; |
|
| 45 | + if( $_by_profile_id ) { |
|
| 44 | 46 | |
| 45 | - if( $_by_profile_id ) { |
|
| 47 | + $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
| 46 | 48 | |
| 47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
| 49 | + if( empty( $_sub ) ) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 48 | 52 | |
| 49 | - if( empty( $_sub ) ) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 53 | + $_id_or_object = $_sub; |
|
| 52 | 54 | |
| 53 | - $_id_or_object = $_sub; |
|
| 55 | + } |
|
| 54 | 56 | |
| 55 | - } |
|
| 57 | + return $this->setup_subscription( $_id_or_object ); |
|
| 58 | + } |
|
| 56 | 59 | |
| 57 | - return $this->setup_subscription( $_id_or_object ); |
|
| 58 | - } |
|
| 60 | + /** |
|
| 61 | + * Setup the subscription object |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + private function setup_subscription( $id_or_object = 0 ) { |
|
| 59 | 67 | |
| 60 | - /** |
|
| 61 | - * Setup the subscription object |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
| 68 | + if( empty( $id_or_object ) ) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 67 | 71 | |
| 68 | - if( empty( $id_or_object ) ) { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 72 | + if( is_numeric( $id_or_object ) ) { |
|
| 71 | 73 | |
| 72 | - if( is_numeric( $id_or_object ) ) { |
|
| 74 | + $sub = $this->subs_db->get( $id_or_object ); |
|
| 73 | 75 | |
| 74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
| 76 | + } elseif( is_object( $id_or_object ) ) { |
|
| 75 | 77 | |
| 76 | - } elseif( is_object( $id_or_object ) ) { |
|
| 78 | + $sub = $id_or_object; |
|
| 77 | 79 | |
| 78 | - $sub = $id_or_object; |
|
| 80 | + } |
|
| 79 | 81 | |
| 80 | - } |
|
| 82 | + if( empty( $sub ) ) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 81 | 85 | |
| 82 | - if( empty( $sub ) ) { |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 86 | + foreach( $sub as $key => $value ) { |
|
| 87 | + $this->$key = $value; |
|
| 88 | + } |
|
| 85 | 89 | |
| 86 | - foreach( $sub as $key => $value ) { |
|
| 87 | - $this->$key = $value; |
|
| 88 | - } |
|
| 90 | + $this->customer = get_userdata( $this->customer_id ); |
|
| 91 | + $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
| 89 | 92 | |
| 90 | - $this->customer = get_userdata( $this->customer_id ); |
|
| 91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
| 93 | + do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
| 92 | 94 | |
| 93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
| 95 | + return $this; |
|
| 96 | + } |
|
| 94 | 97 | |
| 95 | - return $this; |
|
| 96 | - } |
|
| 98 | + /** |
|
| 99 | + * Magic __get function to dispatch a call to retrieve a private property |
|
| 100 | + * |
|
| 101 | + * @since 1.0.0 |
|
| 102 | + */ |
|
| 103 | + public function __get( $key ) { |
|
| 97 | 104 | |
| 98 | - /** |
|
| 99 | - * Magic __get function to dispatch a call to retrieve a private property |
|
| 100 | - * |
|
| 101 | - * @since 1.0.0 |
|
| 102 | - */ |
|
| 103 | - public function __get( $key ) { |
|
| 105 | + if( method_exists( $this, 'get_' . $key ) ) { |
|
| 104 | 106 | |
| 105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
| 107 | + return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 106 | 108 | |
| 107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 109 | + } else { |
|
| 108 | 110 | |
| 109 | - } else { |
|
| 111 | + return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 110 | 112 | |
| 111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 113 | + } |
|
| 112 | 114 | |
| 113 | - } |
|
| 115 | + } |
|
| 114 | 116 | |
| 115 | - } |
|
| 117 | + /** |
|
| 118 | + * Creates a subscription |
|
| 119 | + * |
|
| 120 | + * @since 1.0.0 |
|
| 121 | + * @param array $data Array of attributes for a subscription |
|
| 122 | + * @return mixed false if data isn't passed and class not instantiated for creation |
|
| 123 | + */ |
|
| 124 | + public function create( $data = array() ) { |
|
| 116 | 125 | |
| 117 | - /** |
|
| 118 | - * Creates a subscription |
|
| 119 | - * |
|
| 120 | - * @since 1.0.0 |
|
| 121 | - * @param array $data Array of attributes for a subscription |
|
| 122 | - * @return mixed false if data isn't passed and class not instantiated for creation |
|
| 123 | - */ |
|
| 124 | - public function create( $data = array() ) { |
|
| 126 | + if ( $this->id != 0 ) { |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 125 | 129 | |
| 126 | - if ( $this->id != 0 ) { |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 130 | + $defaults = array( |
|
| 131 | + 'customer_id' => 0, |
|
| 132 | + 'frequency' => '', |
|
| 133 | + 'period' => '', |
|
| 134 | + 'initial_amount' => '', |
|
| 135 | + 'recurring_amount' => '', |
|
| 136 | + 'bill_times' => 0, |
|
| 137 | + 'parent_payment_id' => 0, |
|
| 138 | + 'product_id' => 0, |
|
| 139 | + 'created' => '', |
|
| 140 | + 'expiration' => '', |
|
| 141 | + 'status' => '', |
|
| 142 | + 'profile_id' => '', |
|
| 143 | + ); |
|
| 129 | 144 | |
| 130 | - $defaults = array( |
|
| 131 | - 'customer_id' => 0, |
|
| 132 | - 'frequency' => '', |
|
| 133 | - 'period' => '', |
|
| 134 | - 'initial_amount' => '', |
|
| 135 | - 'recurring_amount' => '', |
|
| 136 | - 'bill_times' => 0, |
|
| 137 | - 'parent_payment_id' => 0, |
|
| 138 | - 'product_id' => 0, |
|
| 139 | - 'created' => '', |
|
| 140 | - 'expiration' => '', |
|
| 141 | - 'status' => '', |
|
| 142 | - 'profile_id' => '', |
|
| 143 | - ); |
|
| 145 | + $args = wp_parse_args( $data, $defaults ); |
|
| 144 | 146 | |
| 145 | - $args = wp_parse_args( $data, $defaults ); |
|
| 147 | + if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 146 | 148 | |
| 147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 149 | + if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
| 148 | 150 | |
| 149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
| 151 | + // Force an active subscription to expired if expiration date is in the past |
|
| 152 | + $args['status'] = 'expired'; |
|
| 150 | 153 | |
| 151 | - // Force an active subscription to expired if expiration date is in the past |
|
| 152 | - $args['status'] = 'expired'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 153 | 156 | |
| 154 | - } |
|
| 155 | - } |
|
| 157 | + do_action( 'wpinv_subscription_pre_create', $args ); |
|
| 156 | 158 | |
| 157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
| 159 | + $id = $this->subs_db->insert( $args, 'subscription' ); |
|
| 158 | 160 | |
| 159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
| 161 | + do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
| 160 | 162 | |
| 161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
| 163 | + return $this->setup_subscription( $id ); |
|
| 162 | 164 | |
| 163 | - return $this->setup_subscription( $id ); |
|
| 165 | + } |
|
| 164 | 166 | |
| 165 | - } |
|
| 167 | + /** |
|
| 168 | + * Updates a subscription |
|
| 169 | + * |
|
| 170 | + * @since 1.0.0 |
|
| 171 | + * @param array $args Array of fields to update |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function update( $args = array() ) { |
|
| 175 | + |
|
| 176 | + $ret = $this->subs_db->update( $this->id, $args ); |
|
| 166 | 177 | |
| 167 | - /** |
|
| 168 | - * Updates a subscription |
|
| 169 | - * |
|
| 170 | - * @since 1.0.0 |
|
| 171 | - * @param array $args Array of fields to update |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function update( $args = array() ) { |
|
| 178 | + do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
| 175 | 179 | |
| 176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
| 180 | + return $ret; |
|
| 181 | + |
|
| 182 | + } |
|
| 177 | 183 | |
| 178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
| 184 | + /** |
|
| 185 | + * Delete the subscription |
|
| 186 | + * |
|
| 187 | + * @since 1.0.0 |
|
| 188 | + * @return bool |
|
| 189 | + */ |
|
| 190 | + public function delete() { |
|
| 191 | + return $this->subs_db->delete( $this->id ); |
|
| 192 | + } |
|
| 179 | 193 | |
| 180 | - return $ret; |
|
| 194 | + /** |
|
| 195 | + * Retrieves the parent payment ID |
|
| 196 | + * |
|
| 197 | + * @since 1.0.0 |
|
| 198 | + * @return int |
|
| 199 | + */ |
|
| 200 | + public function get_original_payment_id() { |
|
| 181 | 201 | |
| 182 | - } |
|
| 202 | + return $this->parent_payment_id; |
|
| 183 | 203 | |
| 184 | - /** |
|
| 185 | - * Delete the subscription |
|
| 186 | - * |
|
| 187 | - * @since 1.0.0 |
|
| 188 | - * @return bool |
|
| 189 | - */ |
|
| 190 | - public function delete() { |
|
| 191 | - return $this->subs_db->delete( $this->id ); |
|
| 192 | - } |
|
| 204 | + } |
|
| 193 | 205 | |
| 194 | - /** |
|
| 195 | - * Retrieves the parent payment ID |
|
| 196 | - * |
|
| 197 | - * @since 1.0.0 |
|
| 198 | - * @return int |
|
| 199 | - */ |
|
| 200 | - public function get_original_payment_id() { |
|
| 206 | + /** |
|
| 207 | + * Retrieve renewal payments for a subscription |
|
| 208 | + * |
|
| 209 | + * @since 1.0.0 |
|
| 210 | + * @return array |
|
| 211 | + */ |
|
| 212 | + public function get_child_payments() { |
|
| 201 | 213 | |
| 202 | - return $this->parent_payment_id; |
|
| 214 | + $payments = get_posts( array( |
|
| 215 | + 'post_parent' => (int) $this->parent_payment_id, |
|
| 216 | + 'posts_per_page' => '999', |
|
| 217 | + 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 218 | + 'post_type' => 'wpi_invoice' |
|
| 219 | + ) ); |
|
| 203 | 220 | |
| 204 | - } |
|
| 221 | + return $payments; |
|
| 205 | 222 | |
| 206 | - /** |
|
| 207 | - * Retrieve renewal payments for a subscription |
|
| 208 | - * |
|
| 209 | - * @since 1.0.0 |
|
| 210 | - * @return array |
|
| 211 | - */ |
|
| 212 | - public function get_child_payments() { |
|
| 213 | - |
|
| 214 | - $payments = get_posts( array( |
|
| 215 | - 'post_parent' => (int) $this->parent_payment_id, |
|
| 216 | - 'posts_per_page' => '999', |
|
| 217 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 218 | - 'post_type' => 'wpi_invoice' |
|
| 219 | - ) ); |
|
| 220 | - |
|
| 221 | - return $payments; |
|
| 222 | - |
|
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Counts the number of payments made to the subscription |
|
| 227 | - * |
|
| 228 | - * @since 2.4 |
|
| 229 | - * @return int |
|
| 230 | - */ |
|
| 231 | - public function get_total_payments() { |
|
| 225 | + /** |
|
| 226 | + * Counts the number of payments made to the subscription |
|
| 227 | + * |
|
| 228 | + * @since 2.4 |
|
| 229 | + * @return int |
|
| 230 | + */ |
|
| 231 | + public function get_total_payments() { |
|
| 232 | 232 | |
| 233 | - if('pending' != $this->status){ |
|
| 233 | + if('pending' != $this->status){ |
|
| 234 | 234 | return count( $this->get_child_payments() ) + 1; |
| 235 | 235 | } else { |
| 236 | 236 | return count($this->get_child_payments()); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - } |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Returns the number of times the subscription has been billed |
|
| 243 | - * |
|
| 244 | - * @since 2.6 |
|
| 245 | - * @return int |
|
| 246 | - */ |
|
| 247 | - public function get_times_billed() { |
|
| 241 | + /** |
|
| 242 | + * Returns the number of times the subscription has been billed |
|
| 243 | + * |
|
| 244 | + * @since 2.6 |
|
| 245 | + * @return int |
|
| 246 | + */ |
|
| 247 | + public function get_times_billed() { |
|
| 248 | 248 | |
| 249 | - $times_billed = $this->get_total_payments(); |
|
| 249 | + $times_billed = $this->get_total_payments(); |
|
| 250 | 250 | |
| 251 | - if( ! empty( $this->trial_period ) ) { |
|
| 251 | + if( ! empty( $this->trial_period ) ) { |
|
| 252 | 252 | if('pending' != $this->status){ |
| 253 | 253 | $times_billed = 0; |
| 254 | 254 | } else { |
| 255 | 255 | $times_billed -= 1; |
| 256 | 256 | } |
| 257 | - } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - return $times_billed; |
|
| 259 | + return $times_billed; |
|
| 260 | 260 | |
| 261 | - } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | 264 | * Records a new payment on the subscription |
@@ -294,203 +294,203 @@ discard block |
||
| 294 | 294 | return $invoice->ID; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Retrieves the transaction ID from the subscription |
|
| 299 | - * |
|
| 300 | - * @since 1.0.0 |
|
| 301 | - * @return bool |
|
| 302 | - */ |
|
| 303 | - public function get_transaction_id() { |
|
| 297 | + /** |
|
| 298 | + * Retrieves the transaction ID from the subscription |
|
| 299 | + * |
|
| 300 | + * @since 1.0.0 |
|
| 301 | + * @return bool |
|
| 302 | + */ |
|
| 303 | + public function get_transaction_id() { |
|
| 304 | 304 | |
| 305 | - if( empty( $this->transaction_id ) ) { |
|
| 305 | + if( empty( $this->transaction_id ) ) { |
|
| 306 | 306 | |
| 307 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
| 307 | + $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
| 308 | 308 | |
| 309 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
| 310 | - $this->set_transaction_id( $txn_id ); |
|
| 311 | - } |
|
| 309 | + if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
| 310 | + $this->set_transaction_id( $txn_id ); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - return $this->transaction_id; |
|
| 315 | + return $this->transaction_id; |
|
| 316 | 316 | |
| 317 | - } |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * Stores the transaction ID for the subscription purchase |
|
| 321 | - * |
|
| 322 | - * @since 1.0.0.4 |
|
| 323 | - * @return bool |
|
| 324 | - */ |
|
| 325 | - public function set_transaction_id( $txn_id = '' ) { |
|
| 326 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
| 327 | - $this->transaction_id = $txn_id; |
|
| 328 | - } |
|
| 319 | + /** |
|
| 320 | + * Stores the transaction ID for the subscription purchase |
|
| 321 | + * |
|
| 322 | + * @since 1.0.0.4 |
|
| 323 | + * @return bool |
|
| 324 | + */ |
|
| 325 | + public function set_transaction_id( $txn_id = '' ) { |
|
| 326 | + $this->update( array( 'transaction_id' => $txn_id ) ); |
|
| 327 | + $this->transaction_id = $txn_id; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Renews a subscription |
|
| 332 | - * |
|
| 333 | - * @since 1.0.0 |
|
| 334 | - * @return bool |
|
| 335 | - */ |
|
| 336 | - public function renew() { |
|
| 330 | + /** |
|
| 331 | + * Renews a subscription |
|
| 332 | + * |
|
| 333 | + * @since 1.0.0 |
|
| 334 | + * @return bool |
|
| 335 | + */ |
|
| 336 | + public function renew() { |
|
| 337 | 337 | |
| 338 | - $expires = $this->get_expiration_time(); |
|
| 338 | + $expires = $this->get_expiration_time(); |
|
| 339 | 339 | |
| 340 | 340 | |
| 341 | - // Determine what date to use as the start for the new expiration calculation |
|
| 342 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
| 341 | + // Determine what date to use as the start for the new expiration calculation |
|
| 342 | + if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
| 343 | 343 | |
| 344 | - $base_date = $expires; |
|
| 344 | + $base_date = $expires; |
|
| 345 | 345 | |
| 346 | - } else { |
|
| 346 | + } else { |
|
| 347 | 347 | |
| 348 | - $base_date = current_time( 'timestamp' ); |
|
| 348 | + $base_date = current_time( 'timestamp' ); |
|
| 349 | 349 | |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - $last_day = cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
| 352 | + $last_day = cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
| 356 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
| 355 | + $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
| 356 | + $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
| 357 | 357 | |
| 358 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
| 359 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
| 360 | - } |
|
| 358 | + if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
| 359 | + $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
| 362 | + $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
| 363 | 363 | |
| 364 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
| 364 | + do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
| 365 | 365 | |
| 366 | - $this->status = 'active'; |
|
| 367 | - $times_billed = $this->get_times_billed(); |
|
| 366 | + $this->status = 'active'; |
|
| 367 | + $times_billed = $this->get_times_billed(); |
|
| 368 | 368 | |
| 369 | - // Complete subscription if applicable |
|
| 370 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
| 371 | - $this->complete(); |
|
| 372 | - $this->status = 'completed'; |
|
| 373 | - } |
|
| 369 | + // Complete subscription if applicable |
|
| 370 | + if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
| 371 | + $this->complete(); |
|
| 372 | + $this->status = 'completed'; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - $args = array( |
|
| 376 | - 'expiration' => $expiration, |
|
| 377 | - 'status' => $this->status, |
|
| 378 | - ); |
|
| 375 | + $args = array( |
|
| 376 | + 'expiration' => $expiration, |
|
| 377 | + 'status' => $this->status, |
|
| 378 | + ); |
|
| 379 | 379 | |
| 380 | 380 | $this->subs_db->update( $this->id, $args ); |
| 381 | 381 | |
| 382 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
| 383 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
| 382 | + do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
| 383 | + do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
| 384 | 384 | |
| 385 | - } |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * Marks a subscription as completed |
|
| 389 | - * |
|
| 390 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 391 | - * |
|
| 392 | - * @since 1.0.0 |
|
| 393 | - * @return void |
|
| 394 | - */ |
|
| 395 | - public function complete() { |
|
| 387 | + /** |
|
| 388 | + * Marks a subscription as completed |
|
| 389 | + * |
|
| 390 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 391 | + * |
|
| 392 | + * @since 1.0.0 |
|
| 393 | + * @return void |
|
| 394 | + */ |
|
| 395 | + public function complete() { |
|
| 396 | 396 | |
| 397 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 398 | - if ( 'cancelled' === $this->status ) { |
|
| 399 | - return; |
|
| 400 | - } |
|
| 397 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 398 | + if ( 'cancelled' === $this->status ) { |
|
| 399 | + return; |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - $args = array( |
|
| 403 | - 'status' => 'completed' |
|
| 404 | - ); |
|
| 402 | + $args = array( |
|
| 403 | + 'status' => 'completed' |
|
| 404 | + ); |
|
| 405 | 405 | |
| 406 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 406 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 407 | 407 | |
| 408 | - $this->status = 'completed'; |
|
| 408 | + $this->status = 'completed'; |
|
| 409 | 409 | |
| 410 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
| 410 | + do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
| 411 | 411 | |
| 412 | - } |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - } |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - /** |
|
| 417 | - * Marks a subscription as expired |
|
| 418 | - * |
|
| 419 | - * Subscription is completed when the billing times is reached |
|
| 420 | - * |
|
| 421 | - * @since 1.0.0 |
|
| 422 | - * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
| 423 | - * @return void |
|
| 424 | - */ |
|
| 425 | - public function expire( $check_expiration = false ) { |
|
| 416 | + /** |
|
| 417 | + * Marks a subscription as expired |
|
| 418 | + * |
|
| 419 | + * Subscription is completed when the billing times is reached |
|
| 420 | + * |
|
| 421 | + * @since 1.0.0 |
|
| 422 | + * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
| 423 | + * @return void |
|
| 424 | + */ |
|
| 425 | + public function expire( $check_expiration = false ) { |
|
| 426 | 426 | |
| 427 | - $expiration = $this->expiration; |
|
| 427 | + $expiration = $this->expiration; |
|
| 428 | 428 | |
| 429 | - if( $check_expiration && $this->check_expiration() ) { |
|
| 429 | + if( $check_expiration && $this->check_expiration() ) { |
|
| 430 | 430 | |
| 431 | - // check_expiration() updates $this->expiration so compare to $expiration above |
|
| 431 | + // check_expiration() updates $this->expiration so compare to $expiration above |
|
| 432 | 432 | |
| 433 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
| 433 | + if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
| 434 | 434 | |
| 435 | - return false; // Do not mark as expired since real expiration date is in the future |
|
| 436 | - } |
|
| 435 | + return false; // Do not mark as expired since real expiration date is in the future |
|
| 436 | + } |
|
| 437 | 437 | |
| 438 | - } |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $args = array( |
|
| 441 | - 'status' => 'expired' |
|
| 442 | - ); |
|
| 440 | + $args = array( |
|
| 441 | + 'status' => 'expired' |
|
| 442 | + ); |
|
| 443 | 443 | |
| 444 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 444 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 445 | 445 | |
| 446 | - $this->status = 'expired'; |
|
| 446 | + $this->status = 'expired'; |
|
| 447 | 447 | |
| 448 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
| 448 | + do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
| 449 | 449 | |
| 450 | - } |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | - } |
|
| 452 | + } |
|
| 453 | 453 | |
| 454 | - /** |
|
| 455 | - * Marks a subscription as failing |
|
| 456 | - * |
|
| 457 | - * @since 2.4.2 |
|
| 458 | - * @return void |
|
| 459 | - */ |
|
| 460 | - public function failing() { |
|
| 454 | + /** |
|
| 455 | + * Marks a subscription as failing |
|
| 456 | + * |
|
| 457 | + * @since 2.4.2 |
|
| 458 | + * @return void |
|
| 459 | + */ |
|
| 460 | + public function failing() { |
|
| 461 | 461 | |
| 462 | - $args = array( |
|
| 463 | - 'status' => 'failing' |
|
| 464 | - ); |
|
| 462 | + $args = array( |
|
| 463 | + 'status' => 'failing' |
|
| 464 | + ); |
|
| 465 | 465 | |
| 466 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 466 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 467 | 467 | |
| 468 | - $this->status = 'failing'; |
|
| 468 | + $this->status = 'failing'; |
|
| 469 | 469 | |
| 470 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
| 470 | + do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
| 471 | 471 | |
| 472 | 472 | |
| 473 | - } |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | - } |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - /** |
|
| 478 | - * Marks a subscription as cancelled |
|
| 479 | - * |
|
| 480 | - * @since 1.0.0 |
|
| 481 | - * @return void |
|
| 482 | - */ |
|
| 483 | - public function cancel() { |
|
| 477 | + /** |
|
| 478 | + * Marks a subscription as cancelled |
|
| 479 | + * |
|
| 480 | + * @since 1.0.0 |
|
| 481 | + * @return void |
|
| 482 | + */ |
|
| 483 | + public function cancel() { |
|
| 484 | 484 | |
| 485 | - if( 'cancelled' === $this->status ) { |
|
| 486 | - return; // Already cancelled |
|
| 487 | - } |
|
| 485 | + if( 'cancelled' === $this->status ) { |
|
| 486 | + return; // Already cancelled |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - $args = array( |
|
| 490 | - 'status' => 'cancelled' |
|
| 491 | - ); |
|
| 489 | + $args = array( |
|
| 490 | + 'status' => 'cancelled' |
|
| 491 | + ); |
|
| 492 | 492 | |
| 493 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 493 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 494 | 494 | |
| 495 | 495 | if( is_user_logged_in() ) { |
| 496 | 496 | |
@@ -506,31 +506,31 @@ discard block |
||
| 506 | 506 | $note = sprintf( __( 'Subscription for Invoice #%d cancelled by %s', 'invoicing' ), $this->parent_payment_id, $user ); |
| 507 | 507 | wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
| 508 | 508 | |
| 509 | - $this->status = 'cancelled'; |
|
| 509 | + $this->status = 'cancelled'; |
|
| 510 | 510 | |
| 511 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
| 511 | + do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
| 512 | 512 | |
| 513 | 513 | |
| 514 | - } |
|
| 514 | + } |
|
| 515 | 515 | |
| 516 | - } |
|
| 516 | + } |
|
| 517 | 517 | |
| 518 | - /** |
|
| 519 | - * Determines if subscription can be cancelled |
|
| 520 | - * |
|
| 521 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 522 | - * that can be cancelled with a profile ID through the merchant processor |
|
| 523 | - * |
|
| 524 | - * @since 1.0.0 |
|
| 525 | - * @return bool |
|
| 526 | - */ |
|
| 527 | - public function can_cancel() { |
|
| 518 | + /** |
|
| 519 | + * Determines if subscription can be cancelled |
|
| 520 | + * |
|
| 521 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 522 | + * that can be cancelled with a profile ID through the merchant processor |
|
| 523 | + * |
|
| 524 | + * @since 1.0.0 |
|
| 525 | + * @return bool |
|
| 526 | + */ |
|
| 527 | + public function can_cancel() { |
|
| 528 | 528 | $ret = false; |
| 529 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
| 529 | + if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
| 530 | 530 | $ret = true; |
| 531 | 531 | } |
| 532 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
| 533 | - } |
|
| 532 | + return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
| 533 | + } |
|
| 534 | 534 | |
| 535 | 535 | /** |
| 536 | 536 | * Returns an array of subscription statuses that can be cancelled |
@@ -543,197 +543,197 @@ discard block |
||
| 543 | 543 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - /** |
|
| 547 | - * Retrieves the URL to cancel subscription |
|
| 548 | - * |
|
| 549 | - * @since 1.0.0 |
|
| 550 | - * @return string |
|
| 551 | - */ |
|
| 552 | - public function get_cancel_url() { |
|
| 546 | + /** |
|
| 547 | + * Retrieves the URL to cancel subscription |
|
| 548 | + * |
|
| 549 | + * @since 1.0.0 |
|
| 550 | + * @return string |
|
| 551 | + */ |
|
| 552 | + public function get_cancel_url() { |
|
| 553 | + |
|
| 554 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
| 553 | 555 | |
| 554 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
| 556 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Determines if subscription can be manually renewed |
|
| 561 | + * |
|
| 562 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 563 | + * that can be renewed manually |
|
| 564 | + * |
|
| 565 | + * @since 2.5 |
|
| 566 | + * @return bool |
|
| 567 | + */ |
|
| 568 | + public function can_renew() { |
|
| 569 | + |
|
| 570 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Retrieves the URL to renew a subscription |
|
| 575 | + * |
|
| 576 | + * @since 2.5 |
|
| 577 | + * @return string |
|
| 578 | + */ |
|
| 579 | + public function get_renew_url() { |
|
| 580 | + |
|
| 581 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
| 582 | + |
|
| 583 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Determines if subscription can have their payment method updated |
|
| 588 | + * |
|
| 589 | + * @since 1.0.0 |
|
| 590 | + * @return bool |
|
| 591 | + */ |
|
| 592 | + public function can_update() { |
|
| 593 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Retrieves the URL to update subscription |
|
| 598 | + * |
|
| 599 | + * @since 1.0.0 |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + public function get_update_url() { |
|
| 555 | 603 | |
| 556 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 557 | - } |
|
| 604 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
| 605 | + |
|
| 606 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Determines if subscription is active |
|
| 611 | + * |
|
| 612 | + * @since 1.0.0 |
|
| 613 | + * @return void |
|
| 614 | + */ |
|
| 615 | + public function is_active() { |
|
| 616 | + |
|
| 617 | + $ret = false; |
|
| 618 | + |
|
| 619 | + if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
| 620 | + $ret = true; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
| 624 | + |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Determines if subscription is expired |
|
| 629 | + * |
|
| 630 | + * @since 1.0.0 |
|
| 631 | + * @return void |
|
| 632 | + */ |
|
| 633 | + public function is_expired() { |
|
| 634 | + |
|
| 635 | + $ret = false; |
|
| 636 | + |
|
| 637 | + if ( $this->status == 'expired' ) { |
|
| 638 | + |
|
| 639 | + $ret = true; |
|
| 640 | + |
|
| 641 | + } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
| 642 | + |
|
| 643 | + $ret = false; |
|
| 644 | + $expiration = $this->get_expiration_time(); |
|
| 645 | + |
|
| 646 | + if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 647 | + $ret = true; |
|
| 648 | + |
|
| 649 | + if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
| 650 | + $this->expire(); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + } |
|
| 558 | 655 | |
| 559 | - /** |
|
| 560 | - * Determines if subscription can be manually renewed |
|
| 561 | - * |
|
| 562 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 563 | - * that can be renewed manually |
|
| 564 | - * |
|
| 565 | - * @since 2.5 |
|
| 566 | - * @return bool |
|
| 567 | - */ |
|
| 568 | - public function can_renew() { |
|
| 656 | + return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
| 569 | 657 | |
| 570 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Retrieves the URL to renew a subscription |
|
| 575 | - * |
|
| 576 | - * @since 2.5 |
|
| 577 | - * @return string |
|
| 578 | - */ |
|
| 579 | - public function get_renew_url() { |
|
| 580 | - |
|
| 581 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
| 582 | - |
|
| 583 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Determines if subscription can have their payment method updated |
|
| 588 | - * |
|
| 589 | - * @since 1.0.0 |
|
| 590 | - * @return bool |
|
| 591 | - */ |
|
| 592 | - public function can_update() { |
|
| 593 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Retrieves the URL to update subscription |
|
| 598 | - * |
|
| 599 | - * @since 1.0.0 |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - public function get_update_url() { |
|
| 603 | - |
|
| 604 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
| 605 | - |
|
| 606 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Determines if subscription is active |
|
| 611 | - * |
|
| 612 | - * @since 1.0.0 |
|
| 613 | - * @return void |
|
| 614 | - */ |
|
| 615 | - public function is_active() { |
|
| 616 | - |
|
| 617 | - $ret = false; |
|
| 618 | - |
|
| 619 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
| 620 | - $ret = true; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
| 624 | - |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Determines if subscription is expired |
|
| 629 | - * |
|
| 630 | - * @since 1.0.0 |
|
| 631 | - * @return void |
|
| 632 | - */ |
|
| 633 | - public function is_expired() { |
|
| 634 | - |
|
| 635 | - $ret = false; |
|
| 636 | - |
|
| 637 | - if ( $this->status == 'expired' ) { |
|
| 638 | - |
|
| 639 | - $ret = true; |
|
| 640 | - |
|
| 641 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
| 642 | - |
|
| 643 | - $ret = false; |
|
| 644 | - $expiration = $this->get_expiration_time(); |
|
| 645 | - |
|
| 646 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 647 | - $ret = true; |
|
| 648 | - |
|
| 649 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
| 650 | - $this->expire(); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
| 657 | - |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Retrieves the expiration date |
|
| 662 | - * |
|
| 663 | - * @since 1.0.0 |
|
| 664 | - * @return string |
|
| 665 | - */ |
|
| 666 | - public function get_expiration() { |
|
| 667 | - return $this->expiration; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Retrieves the expiration date in a timestamp |
|
| 672 | - * |
|
| 673 | - * @since 1.0.0 |
|
| 674 | - * @return int |
|
| 675 | - */ |
|
| 676 | - public function get_expiration_time() { |
|
| 677 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Retrieves the subscription status |
|
| 682 | - * |
|
| 683 | - * @since 1.0.0 |
|
| 684 | - * @return int |
|
| 685 | - */ |
|
| 686 | - public function get_status() { |
|
| 687 | - |
|
| 688 | - // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
| 689 | - $this->is_expired(); |
|
| 690 | - return $this->status; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Retrieves the subscription status label |
|
| 695 | - * |
|
| 696 | - * @since 1.0.0 |
|
| 697 | - * @return int |
|
| 698 | - */ |
|
| 699 | - public function get_status_label() { |
|
| 700 | - |
|
| 701 | - switch( $this->get_status() ) { |
|
| 702 | - case 'active' : |
|
| 703 | - $status = __( 'Active', 'invoicing' ); |
|
| 704 | - break; |
|
| 705 | - |
|
| 706 | - case 'cancelled' : |
|
| 707 | - $status = __( 'Cancelled', 'invoicing' ); |
|
| 708 | - break; |
|
| 709 | - |
|
| 710 | - case 'expired' : |
|
| 711 | - $status = __( 'Expired', 'invoicing' ); |
|
| 712 | - break; |
|
| 713 | - |
|
| 714 | - case 'pending' : |
|
| 715 | - $status = __( 'Pending', 'invoicing' ); |
|
| 716 | - break; |
|
| 717 | - |
|
| 718 | - case 'failing' : |
|
| 719 | - $status = __( 'Failing', 'invoicing' ); |
|
| 720 | - break; |
|
| 721 | - |
|
| 722 | - case 'trialling' : |
|
| 723 | - $status = __( 'Trialling', 'invoicing' ); |
|
| 724 | - break; |
|
| 725 | - |
|
| 726 | - case 'completed' : |
|
| 727 | - $status = __( 'Completed', 'invoicing' ); |
|
| 728 | - break; |
|
| 729 | - |
|
| 730 | - default: |
|
| 731 | - $status = ucfirst( $this->get_status() ); |
|
| 732 | - break; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - return $status; |
|
| 736 | - } |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Retrieves the expiration date |
|
| 662 | + * |
|
| 663 | + * @since 1.0.0 |
|
| 664 | + * @return string |
|
| 665 | + */ |
|
| 666 | + public function get_expiration() { |
|
| 667 | + return $this->expiration; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Retrieves the expiration date in a timestamp |
|
| 672 | + * |
|
| 673 | + * @since 1.0.0 |
|
| 674 | + * @return int |
|
| 675 | + */ |
|
| 676 | + public function get_expiration_time() { |
|
| 677 | + return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Retrieves the subscription status |
|
| 682 | + * |
|
| 683 | + * @since 1.0.0 |
|
| 684 | + * @return int |
|
| 685 | + */ |
|
| 686 | + public function get_status() { |
|
| 687 | + |
|
| 688 | + // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
| 689 | + $this->is_expired(); |
|
| 690 | + return $this->status; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Retrieves the subscription status label |
|
| 695 | + * |
|
| 696 | + * @since 1.0.0 |
|
| 697 | + * @return int |
|
| 698 | + */ |
|
| 699 | + public function get_status_label() { |
|
| 700 | + |
|
| 701 | + switch( $this->get_status() ) { |
|
| 702 | + case 'active' : |
|
| 703 | + $status = __( 'Active', 'invoicing' ); |
|
| 704 | + break; |
|
| 705 | + |
|
| 706 | + case 'cancelled' : |
|
| 707 | + $status = __( 'Cancelled', 'invoicing' ); |
|
| 708 | + break; |
|
| 709 | + |
|
| 710 | + case 'expired' : |
|
| 711 | + $status = __( 'Expired', 'invoicing' ); |
|
| 712 | + break; |
|
| 713 | + |
|
| 714 | + case 'pending' : |
|
| 715 | + $status = __( 'Pending', 'invoicing' ); |
|
| 716 | + break; |
|
| 717 | + |
|
| 718 | + case 'failing' : |
|
| 719 | + $status = __( 'Failing', 'invoicing' ); |
|
| 720 | + break; |
|
| 721 | + |
|
| 722 | + case 'trialling' : |
|
| 723 | + $status = __( 'Trialling', 'invoicing' ); |
|
| 724 | + break; |
|
| 725 | + |
|
| 726 | + case 'completed' : |
|
| 727 | + $status = __( 'Completed', 'invoicing' ); |
|
| 728 | + break; |
|
| 729 | + |
|
| 730 | + default: |
|
| 731 | + $status = ucfirst( $this->get_status() ); |
|
| 732 | + break; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + return $status; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | 738 | /** |
| 739 | 739 | * Retrieves the subscription status label |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 4 | +if (!defined('ABSPATH')) { |
|
| 5 | 5 | exit; |
| 6 | 6 | } |
| 7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | * @since 1.0.0 |
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
| 41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
| 42 | 42 | |
| 43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
| 44 | 44 | |
| 45 | - if( $_by_profile_id ) { |
|
| 45 | + if ($_by_profile_id) { |
|
| 46 | 46 | |
| 47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
| 47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
| 48 | 48 | |
| 49 | - if( empty( $_sub ) ) { |
|
| 49 | + if (empty($_sub)) { |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - return $this->setup_subscription( $_id_or_object ); |
|
| 57 | + return $this->setup_subscription($_id_or_object); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
| 63 | 63 | * @since 1.0.0 |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
| 66 | + private function setup_subscription($id_or_object = 0) { |
|
| 67 | 67 | |
| 68 | - if( empty( $id_or_object ) ) { |
|
| 68 | + if (empty($id_or_object)) { |
|
| 69 | 69 | return false; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if( is_numeric( $id_or_object ) ) { |
|
| 72 | + if (is_numeric($id_or_object)) { |
|
| 73 | 73 | |
| 74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
| 74 | + $sub = $this->subs_db->get($id_or_object); |
|
| 75 | 75 | |
| 76 | - } elseif( is_object( $id_or_object ) ) { |
|
| 76 | + } elseif (is_object($id_or_object)) { |
|
| 77 | 77 | |
| 78 | 78 | $sub = $id_or_object; |
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if( empty( $sub ) ) { |
|
| 82 | + if (empty($sub)) { |
|
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - foreach( $sub as $key => $value ) { |
|
| 86 | + foreach ($sub as $key => $value) { |
|
| 87 | 87 | $this->$key = $value; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $this->customer = get_userdata( $this->customer_id ); |
|
| 91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
| 90 | + $this->customer = get_userdata($this->customer_id); |
|
| 91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
| 92 | 92 | |
| 93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
| 93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
| 94 | 94 | |
| 95 | 95 | return $this; |
| 96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @since 1.0.0 |
| 102 | 102 | */ |
| 103 | - public function __get( $key ) { |
|
| 103 | + public function __get($key) { |
|
| 104 | 104 | |
| 105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
| 105 | + if (method_exists($this, 'get_' . $key)) { |
|
| 106 | 106 | |
| 107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 107 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 108 | 108 | |
| 109 | 109 | } else { |
| 110 | 110 | |
| 111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | * @param array $data Array of attributes for a subscription |
| 122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
| 123 | 123 | */ |
| 124 | - public function create( $data = array() ) { |
|
| 124 | + public function create($data = array()) { |
|
| 125 | 125 | |
| 126 | - if ( $this->id != 0 ) { |
|
| 126 | + if ($this->id != 0) { |
|
| 127 | 127 | return false; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | 'profile_id' => '', |
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - $args = wp_parse_args( $data, $defaults ); |
|
| 145 | + $args = wp_parse_args($data, $defaults); |
|
| 146 | 146 | |
| 147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
| 148 | 148 | |
| 149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
| 149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
| 150 | 150 | |
| 151 | 151 | // Force an active subscription to expired if expiration date is in the past |
| 152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
| 157 | + do_action('wpinv_subscription_pre_create', $args); |
|
| 158 | 158 | |
| 159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
| 159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
| 160 | 160 | |
| 161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
| 161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
| 162 | 162 | |
| 163 | - return $this->setup_subscription( $id ); |
|
| 163 | + return $this->setup_subscription($id); |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
| 171 | 171 | * @param array $args Array of fields to update |
| 172 | 172 | * @return bool |
| 173 | 173 | */ |
| 174 | - public function update( $args = array() ) { |
|
| 174 | + public function update($args = array()) { |
|
| 175 | 175 | |
| 176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
| 176 | + $ret = $this->subs_db->update($this->id, $args); |
|
| 177 | 177 | |
| 178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
| 178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
| 179 | 179 | |
| 180 | 180 | return $ret; |
| 181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @return bool |
| 189 | 189 | */ |
| 190 | 190 | public function delete() { |
| 191 | - return $this->subs_db->delete( $this->id ); |
|
| 191 | + return $this->subs_db->delete($this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | public function get_child_payments() { |
| 213 | 213 | |
| 214 | - $payments = get_posts( array( |
|
| 215 | - 'post_parent' => (int) $this->parent_payment_id, |
|
| 214 | + $payments = get_posts(array( |
|
| 215 | + 'post_parent' => (int)$this->parent_payment_id, |
|
| 216 | 216 | 'posts_per_page' => '999', |
| 217 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 217 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
| 218 | 218 | 'post_type' => 'wpi_invoice' |
| 219 | - ) ); |
|
| 219 | + )); |
|
| 220 | 220 | |
| 221 | 221 | return $payments; |
| 222 | 222 | |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function get_total_payments() { |
| 232 | 232 | |
| 233 | - if('pending' != $this->status){ |
|
| 234 | - return count( $this->get_child_payments() ) + 1; |
|
| 233 | + if ('pending' != $this->status) { |
|
| 234 | + return count($this->get_child_payments()) + 1; |
|
| 235 | 235 | } else { |
| 236 | 236 | return count($this->get_child_payments()); |
| 237 | 237 | } |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | $times_billed = $this->get_total_payments(); |
| 250 | 250 | |
| 251 | - if( ! empty( $this->trial_period ) ) { |
|
| 252 | - if('pending' != $this->status){ |
|
| 251 | + if (!empty($this->trial_period)) { |
|
| 252 | + if ('pending' != $this->status) { |
|
| 253 | 253 | $times_billed = 0; |
| 254 | 254 | } else { |
| 255 | 255 | $times_billed -= 1; |
@@ -267,29 +267,29 @@ discard block |
||
| 267 | 267 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 268 | 268 | * @return bool |
| 269 | 269 | */ |
| 270 | - public function add_payment( $args = array() ) { |
|
| 270 | + public function add_payment($args = array()) { |
|
| 271 | 271 | |
| 272 | - $args = wp_parse_args( $args, array( |
|
| 272 | + $args = wp_parse_args($args, array( |
|
| 273 | 273 | 'amount' => '', |
| 274 | 274 | 'transaction_id' => '', |
| 275 | 275 | 'gateway' => '' |
| 276 | - ) ); |
|
| 276 | + )); |
|
| 277 | 277 | |
| 278 | - if ( $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 278 | + if ($this->payment_exists($args['transaction_id'])) { |
|
| 279 | 279 | return false; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if(!$this->parent_payment_id){ |
|
| 282 | + if (!$this->parent_payment_id) { |
|
| 283 | 283 | return false; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $invoice = new WPInv_Invoice($this->parent_payment_id); |
| 287 | - $invoice->ID = $invoice->title = $invoice->number =''; |
|
| 287 | + $invoice->ID = $invoice->title = $invoice->number = ''; |
|
| 288 | 288 | $invoice->parent_invoice = $this->parent_payment_id; |
| 289 | 289 | $invoice->save(); |
| 290 | 290 | |
| 291 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 292 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
| 291 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 292 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
| 293 | 293 | |
| 294 | 294 | return $invoice->ID; |
| 295 | 295 | } |
@@ -302,12 +302,12 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public function get_transaction_id() { |
| 304 | 304 | |
| 305 | - if( empty( $this->transaction_id ) ) { |
|
| 305 | + if (empty($this->transaction_id)) { |
|
| 306 | 306 | |
| 307 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
| 307 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
| 308 | 308 | |
| 309 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
| 310 | - $this->set_transaction_id( $txn_id ); |
|
| 309 | + if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) { |
|
| 310 | + $this->set_transaction_id($txn_id); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | } |
@@ -322,8 +322,8 @@ discard block |
||
| 322 | 322 | * @since 1.0.0.4 |
| 323 | 323 | * @return bool |
| 324 | 324 | */ |
| 325 | - public function set_transaction_id( $txn_id = '' ) { |
|
| 326 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
| 325 | + public function set_transaction_id($txn_id = '') { |
|
| 326 | + $this->update(array('transaction_id' => $txn_id)); |
|
| 327 | 327 | $this->transaction_id = $txn_id; |
| 328 | 328 | } |
| 329 | 329 | |
@@ -339,35 +339,35 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | |
| 341 | 341 | // Determine what date to use as the start for the new expiration calculation |
| 342 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
| 342 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
| 343 | 343 | |
| 344 | - $base_date = $expires; |
|
| 344 | + $base_date = $expires; |
|
| 345 | 345 | |
| 346 | 346 | } else { |
| 347 | 347 | |
| 348 | - $base_date = current_time( 'timestamp' ); |
|
| 348 | + $base_date = current_time('timestamp'); |
|
| 349 | 349 | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $last_day = cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
| 352 | + $last_day = cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
| 356 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
| 356 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
| 357 | 357 | |
| 358 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
| 359 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
| 358 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
| 359 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
| 362 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
| 363 | 363 | |
| 364 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
| 364 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
| 365 | 365 | |
| 366 | 366 | $this->status = 'active'; |
| 367 | 367 | $times_billed = $this->get_times_billed(); |
| 368 | 368 | |
| 369 | 369 | // Complete subscription if applicable |
| 370 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
| 370 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
| 371 | 371 | $this->complete(); |
| 372 | 372 | $this->status = 'completed'; |
| 373 | 373 | } |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | 'status' => $this->status, |
| 378 | 378 | ); |
| 379 | 379 | |
| 380 | - $this->subs_db->update( $this->id, $args ); |
|
| 380 | + $this->subs_db->update($this->id, $args); |
|
| 381 | 381 | |
| 382 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
| 383 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
| 382 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
| 383 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
| 384 | 384 | |
| 385 | 385 | } |
| 386 | 386 | |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | public function complete() { |
| 396 | 396 | |
| 397 | 397 | // Only mark a subscription as complete if it's not already cancelled. |
| 398 | - if ( 'cancelled' === $this->status ) { |
|
| 398 | + if ('cancelled' === $this->status) { |
|
| 399 | 399 | return; |
| 400 | 400 | } |
| 401 | 401 | |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | 'status' => 'completed' |
| 404 | 404 | ); |
| 405 | 405 | |
| 406 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 406 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 407 | 407 | |
| 408 | 408 | $this->status = 'completed'; |
| 409 | 409 | |
| 410 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
| 410 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
| 411 | 411 | |
| 412 | 412 | } |
| 413 | 413 | |
@@ -422,15 +422,15 @@ discard block |
||
| 422 | 422 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
| 423 | 423 | * @return void |
| 424 | 424 | */ |
| 425 | - public function expire( $check_expiration = false ) { |
|
| 425 | + public function expire($check_expiration = false) { |
|
| 426 | 426 | |
| 427 | 427 | $expiration = $this->expiration; |
| 428 | 428 | |
| 429 | - if( $check_expiration && $this->check_expiration() ) { |
|
| 429 | + if ($check_expiration && $this->check_expiration()) { |
|
| 430 | 430 | |
| 431 | 431 | // check_expiration() updates $this->expiration so compare to $expiration above |
| 432 | 432 | |
| 433 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
| 433 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
| 434 | 434 | |
| 435 | 435 | return false; // Do not mark as expired since real expiration date is in the future |
| 436 | 436 | } |
@@ -441,11 +441,11 @@ discard block |
||
| 441 | 441 | 'status' => 'expired' |
| 442 | 442 | ); |
| 443 | 443 | |
| 444 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 444 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 445 | 445 | |
| 446 | 446 | $this->status = 'expired'; |
| 447 | 447 | |
| 448 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
| 448 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
| 449 | 449 | |
| 450 | 450 | } |
| 451 | 451 | |
@@ -463,11 +463,11 @@ discard block |
||
| 463 | 463 | 'status' => 'failing' |
| 464 | 464 | ); |
| 465 | 465 | |
| 466 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 466 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 467 | 467 | |
| 468 | 468 | $this->status = 'failing'; |
| 469 | 469 | |
| 470 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
| 470 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
| 471 | 471 | |
| 472 | 472 | |
| 473 | 473 | } |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | */ |
| 483 | 483 | public function cancel() { |
| 484 | 484 | |
| 485 | - if( 'cancelled' === $this->status ) { |
|
| 485 | + if ('cancelled' === $this->status) { |
|
| 486 | 486 | return; // Already cancelled |
| 487 | 487 | } |
| 488 | 488 | |
@@ -490,25 +490,25 @@ discard block |
||
| 490 | 490 | 'status' => 'cancelled' |
| 491 | 491 | ); |
| 492 | 492 | |
| 493 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 493 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 494 | 494 | |
| 495 | - if( is_user_logged_in() ) { |
|
| 495 | + if (is_user_logged_in()) { |
|
| 496 | 496 | |
| 497 | - $userdata = get_userdata( get_current_user_id() ); |
|
| 497 | + $userdata = get_userdata(get_current_user_id()); |
|
| 498 | 498 | $user = $userdata->display_name; |
| 499 | 499 | |
| 500 | 500 | } else { |
| 501 | 501 | |
| 502 | - $user = __( 'gateway', 'invoicing' ); |
|
| 502 | + $user = __('gateway', 'invoicing'); |
|
| 503 | 503 | |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $note = sprintf( __( 'Subscription for Invoice #%d cancelled by %s', 'invoicing' ), $this->parent_payment_id, $user ); |
|
| 507 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
| 506 | + $note = sprintf(__('Subscription for Invoice #%d cancelled by %s', 'invoicing'), $this->parent_payment_id, $user); |
|
| 507 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
| 508 | 508 | |
| 509 | 509 | $this->status = 'cancelled'; |
| 510 | 510 | |
| 511 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
| 511 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
| 512 | 512 | |
| 513 | 513 | |
| 514 | 514 | } |
@@ -526,10 +526,10 @@ discard block |
||
| 526 | 526 | */ |
| 527 | 527 | public function can_cancel() { |
| 528 | 528 | $ret = false; |
| 529 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
| 529 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
| 530 | 530 | $ret = true; |
| 531 | 531 | } |
| 532 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
| 532 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | * @return array |
| 541 | 541 | */ |
| 542 | 542 | public function get_cancellable_statuses() { |
| 543 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 543 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -551,9 +551,9 @@ discard block |
||
| 551 | 551 | */ |
| 552 | 552 | public function get_cancel_url() { |
| 553 | 553 | |
| 554 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
| 554 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
| 555 | 555 | |
| 556 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 556 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | public function can_renew() { |
| 569 | 569 | |
| 570 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 570 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -578,9 +578,9 @@ discard block |
||
| 578 | 578 | */ |
| 579 | 579 | public function get_renew_url() { |
| 580 | 580 | |
| 581 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
| 581 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
| 582 | 582 | |
| 583 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 583 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * @return bool |
| 591 | 591 | */ |
| 592 | 592 | public function can_update() { |
| 593 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 593 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -601,9 +601,9 @@ discard block |
||
| 601 | 601 | */ |
| 602 | 602 | public function get_update_url() { |
| 603 | 603 | |
| 604 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
| 604 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
| 605 | 605 | |
| 606 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 606 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -616,11 +616,11 @@ discard block |
||
| 616 | 616 | |
| 617 | 617 | $ret = false; |
| 618 | 618 | |
| 619 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
| 619 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
| 620 | 620 | $ret = true; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
| 623 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
| 624 | 624 | |
| 625 | 625 | } |
| 626 | 626 | |
@@ -634,26 +634,26 @@ discard block |
||
| 634 | 634 | |
| 635 | 635 | $ret = false; |
| 636 | 636 | |
| 637 | - if ( $this->status == 'expired' ) { |
|
| 637 | + if ($this->status == 'expired') { |
|
| 638 | 638 | |
| 639 | 639 | $ret = true; |
| 640 | 640 | |
| 641 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
| 641 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
| 642 | 642 | |
| 643 | 643 | $ret = false; |
| 644 | 644 | $expiration = $this->get_expiration_time(); |
| 645 | 645 | |
| 646 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 646 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
| 647 | 647 | $ret = true; |
| 648 | 648 | |
| 649 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
| 649 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
| 650 | 650 | $this->expire(); |
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
| 656 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
| 657 | 657 | |
| 658 | 658 | } |
| 659 | 659 | |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | * @return int |
| 675 | 675 | */ |
| 676 | 676 | public function get_expiration_time() { |
| 677 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
| 677 | + return strtotime($this->expiration, current_time('timestamp')); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -698,37 +698,37 @@ discard block |
||
| 698 | 698 | */ |
| 699 | 699 | public function get_status_label() { |
| 700 | 700 | |
| 701 | - switch( $this->get_status() ) { |
|
| 701 | + switch ($this->get_status()) { |
|
| 702 | 702 | case 'active' : |
| 703 | - $status = __( 'Active', 'invoicing' ); |
|
| 703 | + $status = __('Active', 'invoicing'); |
|
| 704 | 704 | break; |
| 705 | 705 | |
| 706 | 706 | case 'cancelled' : |
| 707 | - $status = __( 'Cancelled', 'invoicing' ); |
|
| 707 | + $status = __('Cancelled', 'invoicing'); |
|
| 708 | 708 | break; |
| 709 | 709 | |
| 710 | 710 | case 'expired' : |
| 711 | - $status = __( 'Expired', 'invoicing' ); |
|
| 711 | + $status = __('Expired', 'invoicing'); |
|
| 712 | 712 | break; |
| 713 | 713 | |
| 714 | 714 | case 'pending' : |
| 715 | - $status = __( 'Pending', 'invoicing' ); |
|
| 715 | + $status = __('Pending', 'invoicing'); |
|
| 716 | 716 | break; |
| 717 | 717 | |
| 718 | 718 | case 'failing' : |
| 719 | - $status = __( 'Failing', 'invoicing' ); |
|
| 719 | + $status = __('Failing', 'invoicing'); |
|
| 720 | 720 | break; |
| 721 | 721 | |
| 722 | 722 | case 'trialling' : |
| 723 | - $status = __( 'Trialling', 'invoicing' ); |
|
| 723 | + $status = __('Trialling', 'invoicing'); |
|
| 724 | 724 | break; |
| 725 | 725 | |
| 726 | 726 | case 'completed' : |
| 727 | - $status = __( 'Completed', 'invoicing' ); |
|
| 727 | + $status = __('Completed', 'invoicing'); |
|
| 728 | 728 | break; |
| 729 | 729 | |
| 730 | 730 | default: |
| 731 | - $status = ucfirst( $this->get_status() ); |
|
| 731 | + $status = ucfirst($this->get_status()); |
|
| 732 | 732 | break; |
| 733 | 733 | } |
| 734 | 734 | |
@@ -743,51 +743,51 @@ discard block |
||
| 743 | 743 | */ |
| 744 | 744 | public function get_status_label_html() { |
| 745 | 745 | |
| 746 | - switch( $get_status = $this->get_status() ) { |
|
| 746 | + switch ($get_status = $this->get_status()) { |
|
| 747 | 747 | case 'active' : |
| 748 | - $status = __( 'Active', 'invoicing' ); |
|
| 748 | + $status = __('Active', 'invoicing'); |
|
| 749 | 749 | $class = 'label-info'; |
| 750 | 750 | break; |
| 751 | 751 | |
| 752 | 752 | case 'cancelled' : |
| 753 | - $status = __( 'Cancelled', 'invoicing' ); |
|
| 753 | + $status = __('Cancelled', 'invoicing'); |
|
| 754 | 754 | $class = 'label-danger'; |
| 755 | 755 | break; |
| 756 | 756 | |
| 757 | 757 | case 'expired' : |
| 758 | - $status = __( 'Expired', 'invoicing' ); |
|
| 758 | + $status = __('Expired', 'invoicing'); |
|
| 759 | 759 | $class = 'label-default'; |
| 760 | 760 | break; |
| 761 | 761 | |
| 762 | 762 | case 'pending' : |
| 763 | - $status = __( 'Pending', 'invoicing' ); |
|
| 763 | + $status = __('Pending', 'invoicing'); |
|
| 764 | 764 | $class = 'label-primary'; |
| 765 | 765 | break; |
| 766 | 766 | |
| 767 | 767 | case 'failing' : |
| 768 | - $status = __( 'Failing', 'invoicing' ); |
|
| 768 | + $status = __('Failing', 'invoicing'); |
|
| 769 | 769 | $class = 'label-danger'; |
| 770 | 770 | break; |
| 771 | 771 | |
| 772 | 772 | case 'trialling' : |
| 773 | - $status = __( 'Trialling', 'invoicing' ); |
|
| 773 | + $status = __('Trialling', 'invoicing'); |
|
| 774 | 774 | $class = 'label-info'; |
| 775 | 775 | break; |
| 776 | 776 | |
| 777 | 777 | case 'completed' : |
| 778 | - $status = __( 'Completed', 'invoicing' ); |
|
| 778 | + $status = __('Completed', 'invoicing'); |
|
| 779 | 779 | $class = 'label-success'; |
| 780 | 780 | break; |
| 781 | 781 | |
| 782 | 782 | default: |
| 783 | - $status = ucfirst( $this->get_status() ); |
|
| 783 | + $status = ucfirst($this->get_status()); |
|
| 784 | 784 | $class = 'label-default'; |
| 785 | 785 | break; |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
| 789 | 789 | |
| 790 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
| 790 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
@@ -797,18 +797,18 @@ discard block |
||
| 797 | 797 | * @param string $txn_id The transaction ID from the merchant processor |
| 798 | 798 | * @return bool |
| 799 | 799 | */ |
| 800 | - public function payment_exists( $txn_id = '' ) { |
|
| 800 | + public function payment_exists($txn_id = '') { |
|
| 801 | 801 | global $wpdb; |
| 802 | 802 | |
| 803 | - if ( empty( $txn_id ) ) { |
|
| 803 | + if (empty($txn_id)) { |
|
| 804 | 804 | return false; |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | - $txn_id = esc_sql( $txn_id ); |
|
| 807 | + $txn_id = esc_sql($txn_id); |
|
| 808 | 808 | |
| 809 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
| 809 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
| 810 | 810 | |
| 811 | - if ( $purchase != null ) { |
|
| 811 | + if ($purchase != null) { |
|
| 812 | 812 | return true; |
| 813 | 813 | } |
| 814 | 814 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | 'wpinv_subscriptions' => __CLASS__ . '::subscriptions', |
| 17 | 17 | ); |
| 18 | 18 | |
| 19 | - foreach ( $shortcodes as $shortcode => $function ) { |
|
| 20 | - add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); |
|
| 19 | + foreach ($shortcodes as $shortcode => $function) { |
|
| 20 | + add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
|
| 23 | + add_shortcode('wpinv_messages', __CLASS__ . '::messages'); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public static function shortcode_wrapper( |
@@ -34,25 +34,25 @@ discard block |
||
| 34 | 34 | ) { |
| 35 | 35 | ob_start(); |
| 36 | 36 | |
| 37 | - echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before']; |
|
| 38 | - call_user_func( $function, $atts ); |
|
| 39 | - echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after']; |
|
| 37 | + echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before']; |
|
| 38 | + call_user_func($function, $atts); |
|
| 39 | + echo empty($wrapper['after']) ? '</div>' : $wrapper['after']; |
|
| 40 | 40 | |
| 41 | 41 | return ob_get_clean(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public static function checkout( $atts = array(), $content = null ) { |
|
| 45 | - return wpinv_checkout_form( $atts, $content ); |
|
| 44 | + public static function checkout($atts = array(), $content = null) { |
|
| 45 | + return wpinv_checkout_form($atts, $content); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function messages( $atts, $content = null ) { |
|
| 48 | + public static function messages($atts, $content = null) { |
|
| 49 | 49 | ob_start(); |
| 50 | 50 | wpinv_print_errors(); |
| 51 | 51 | return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public static function history( $atts, $content = null ) { |
|
| 55 | - return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts ); |
|
| 54 | + public static function history($atts, $content = null) { |
|
| 55 | + return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,28 +60,28 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param array $atts |
| 62 | 62 | */ |
| 63 | - public static function history_output( $atts ) { |
|
| 64 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
| 65 | - wpinv_get_template_part( 'wpinv-invoice-history', $atts ); |
|
| 66 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
| 63 | + public static function history_output($atts) { |
|
| 64 | + do_action('wpinv_before_user_invoice_history'); |
|
| 65 | + wpinv_get_template_part('wpinv-invoice-history', $atts); |
|
| 66 | + do_action('wpinv_after_user_invoice_history'); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public static function receipt( $atts, $content = null ) { |
|
| 70 | - return wpinv_payment_receipt( $atts, $content ); |
|
| 69 | + public static function receipt($atts, $content = null) { |
|
| 70 | + return wpinv_payment_receipt($atts, $content); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public static function buy( $atts, $content = null ) { |
|
| 74 | - $a = shortcode_atts( array( |
|
| 73 | + public static function buy($atts, $content = null) { |
|
| 74 | + $a = shortcode_atts(array( |
|
| 75 | 75 | 'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity |
| 76 | - 'title' => __('Buy Now', 'invoicing' ), // the button title |
|
| 76 | + 'title' => __('Buy Now', 'invoicing'), // the button title |
|
| 77 | 77 | 'post_id' => '', // any related post_id |
| 78 | - ), $atts ); |
|
| 78 | + ), $atts); |
|
| 79 | 79 | |
| 80 | 80 | $post_id = isset($a['post_id']) ? (int)$a['post_id'] : ''; |
| 81 | 81 | |
| 82 | 82 | $html = '<div class="wpi-buy-button-wrapper">'; |
| 83 | - $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="'.$a['title'].'" onclick="wpi_buy(\''.$a['items'].'\','.$post_id.');" />'; |
|
| 84 | - $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false ); |
|
| 83 | + $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="' . $a['title'] . '" onclick="wpi_buy(\'' . $a['items'] . '\',' . $post_id . ');" />'; |
|
| 84 | + $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false); |
|
| 85 | 85 | $html .= '</div>'; |
| 86 | 86 | |
| 87 | 87 | |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public static function subscriptions( $atts, $content = null ) { |
|
| 93 | - return self::shortcode_wrapper( array( __CLASS__, 'subscriptions_output' ), $atts ); |
|
| 92 | + public static function subscriptions($atts, $content = null) { |
|
| 93 | + return self::shortcode_wrapper(array(__CLASS__, 'subscriptions_output'), $atts); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @param array $atts |
| 100 | 100 | */ |
| 101 | - public static function subscriptions_output( $atts ) { |
|
| 102 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 103 | - wpinv_get_template_part( 'wpinv-subscriptions-history', $atts ); |
|
| 104 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 101 | + public static function subscriptions_output($atts) { |
|
| 102 | + do_action('wpinv_before_user_subscriptions'); |
|
| 103 | + wpinv_get_template_part('wpinv-subscriptions-history', $atts); |
|
| 104 | + do_action('wpinv_after_user_subscriptions'); |
|
| 105 | 105 | } |
| 106 | 106 | } |
@@ -9,58 +9,58 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | // If uninstall not called from WordPress, then exit. |
| 12 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
| 12 | +if (!defined('WP_UNINSTALL_PLUGIN')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | global $wpdb, $wp_version; |
| 17 | 17 | |
| 18 | -$remove_data = get_option( 'wpinv_remove_data_on_invoice_unistall' ); |
|
| 18 | +$remove_data = get_option('wpinv_remove_data_on_invoice_unistall'); |
|
| 19 | 19 | |
| 20 | 20 | /* |
| 21 | 21 | * Only remove ALL product and page data if WPINV_REMOVE_ALL_DATA constant is set to true in user's |
| 22 | 22 | * wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
| 23 | 23 | * and to ensure only the site owner can perform this action. |
| 24 | 24 | */ |
| 25 | -if ( defined( 'WPINV_REMOVE_ALL_DATA' ) ) { |
|
| 25 | +if (defined('WPINV_REMOVE_ALL_DATA')) { |
|
| 26 | 26 | $remove_data = true === WPINV_REMOVE_ALL_DATA ? true : false; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | -if ( $remove_data ) { |
|
| 29 | +if ($remove_data) { |
|
| 30 | 30 | // Load Invoicing file. |
| 31 | - include_once( 'invoicing.php' ); |
|
| 31 | + include_once('invoicing.php'); |
|
| 32 | 32 | |
| 33 | 33 | // Roles + caps. |
| 34 | - include_once( dirname( __FILE__ ) . '/includes/admin/install.php' ); |
|
| 34 | + include_once(dirname(__FILE__) . '/includes/admin/install.php'); |
|
| 35 | 35 | wpinv_remove_admin_caps(); |
| 36 | 36 | |
| 37 | - $settings = get_option( 'wpinv_settings' ); |
|
| 37 | + $settings = get_option('wpinv_settings'); |
|
| 38 | 38 | |
| 39 | 39 | // Delete pages. |
| 40 | - $wpi_pages = array( 'checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page', 'invoice_subscription_page' ); |
|
| 41 | - foreach ( $wpi_pages as $page ) { |
|
| 42 | - if ( !empty( $page ) && !empty( $settings[ $page ] ) ) { |
|
| 43 | - wp_delete_post( $settings[ $page ], true ); |
|
| 40 | + $wpi_pages = array('checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page', 'invoice_subscription_page'); |
|
| 41 | + foreach ($wpi_pages as $page) { |
|
| 42 | + if (!empty($page) && !empty($settings[$page])) { |
|
| 43 | + wp_delete_post($settings[$page], true); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Delete posts + data. |
| 48 | - $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );" ); |
|
| 49 | - $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); |
|
| 48 | + $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );"); |
|
| 49 | + $wpdb->query("DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;"); |
|
| 50 | 50 | |
| 51 | 51 | // Delete comments. |
| 52 | - $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';" ); |
|
| 53 | - $wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" ); |
|
| 52 | + $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';"); |
|
| 53 | + $wpdb->query("DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;"); |
|
| 54 | 54 | |
| 55 | 55 | // Delete user meta. |
| 56 | - $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';" ); |
|
| 56 | + $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';"); |
|
| 57 | 57 | |
| 58 | 58 | // Cleanup Cron Schedule |
| 59 | - wp_clear_scheduled_hook( 'wp_session_garbage_collection' ); |
|
| 60 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
| 59 | + wp_clear_scheduled_hook('wp_session_garbage_collection'); |
|
| 60 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
| 61 | 61 | |
| 62 | 62 | // Delete options. |
| 63 | - $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';" ); |
|
| 63 | + $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';"); |
|
| 64 | 64 | |
| 65 | 65 | // Clear any cached data that has been removed |
| 66 | 66 | wp_cache_flush(); |