@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_worldpay_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,120 +24,120 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
144 | 143 | \ No newline at end of file |
144 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
145 | 145 | \ No newline at end of file |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_init_transactional_emails() { |
15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
16 | 16 | 'wpinv_status_pending_to_processing', |
17 | 17 | 'wpinv_status_pending_to_publish', |
18 | 18 | 'wpinv_status_pending_to_cancelled', |
@@ -28,74 +28,74 @@ discard block |
||
28 | 28 | 'wpinv_fully_refunded', |
29 | 29 | 'wpinv_partially_refunded', |
30 | 30 | 'wpinv_new_invoice_note' |
31 | - ) ); |
|
31 | + )); |
|
32 | 32 | |
33 | - foreach ( $email_actions as $action ) { |
|
34 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
33 | + foreach ($email_actions as $action) { |
|
34 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
35 | 35 | } |
36 | 36 | } |
37 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
37 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
38 | 38 | |
39 | 39 | // New invoice email |
40 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
41 | -add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
42 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
43 | -add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
44 | -add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
45 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
40 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
41 | +add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
42 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
43 | +add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
44 | +add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
45 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
46 | 46 | |
47 | 47 | // Cancelled invoice email |
48 | -add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
49 | -add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
48 | +add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
49 | +add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
50 | 50 | |
51 | 51 | // Failed invoice email |
52 | -add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
53 | -add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
52 | +add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
53 | +add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
54 | 54 | |
55 | 55 | // On hold invoice email |
56 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
57 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
56 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
57 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
58 | 58 | |
59 | 59 | // Processing invoice email |
60 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' ); |
|
60 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification'); |
|
61 | 61 | |
62 | 62 | // Paid invoice email |
63 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
63 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
64 | 64 | |
65 | 65 | // Refunded invoice email |
66 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
67 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
66 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
67 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
68 | 68 | |
69 | 69 | // Invoice note |
70 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
70 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
71 | 71 | |
72 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
73 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
74 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
75 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
76 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
72 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
73 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
74 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
75 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
76 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
77 | 77 | |
78 | 78 | function wpinv_send_transactional_email() { |
79 | 79 | $args = func_get_args(); |
80 | 80 | $function = current_filter() . '_notification'; |
81 | - do_action_ref_array( $function, $args ); |
|
81 | + do_action_ref_array($function, $args); |
|
82 | 82 | } |
83 | 83 | |
84 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
84 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
85 | 85 | global $wpinv_email_search, $wpinv_email_replace; |
86 | 86 | |
87 | 87 | $email_type = 'new_invoice'; |
88 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
88 | + if (!wpinv_email_is_enabled($email_type)) { |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
93 | - if ( empty( $invoice ) ) { |
|
92 | + $invoice = wpinv_get_invoice($invoice_id); |
|
93 | + if (empty($invoice)) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
98 | - if ( !is_email( $recipient ) ) { |
|
97 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
98 | + if (!is_email($recipient)) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | |
@@ -112,37 +112,37 @@ discard block |
||
112 | 112 | $wpinv_email_search = $search; |
113 | 113 | $wpinv_email_replace = $replace; |
114 | 114 | |
115 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
116 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
117 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
118 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
115 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
116 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
117 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
118 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
119 | 119 | |
120 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
120 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
121 | 121 | 'invoice' => $invoice, |
122 | 122 | 'email_type' => $email_type, |
123 | 123 | 'email_heading' => $email_heading, |
124 | 124 | 'sent_to_admin' => true, |
125 | 125 | 'plain_text' => false, |
126 | - ) ); |
|
126 | + )); |
|
127 | 127 | |
128 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
128 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
129 | 129 | } |
130 | 130 | |
131 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
131 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
132 | 132 | global $wpinv_email_search, $wpinv_email_replace; |
133 | 133 | |
134 | 134 | $email_type = 'cancelled_invoice'; |
135 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
135 | + if (!wpinv_email_is_enabled($email_type)) { |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
139 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
140 | - if ( empty( $invoice ) ) { |
|
139 | + $invoice = wpinv_get_invoice($invoice_id); |
|
140 | + if (empty($invoice)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
145 | - if ( !is_email( $recipient ) ) { |
|
144 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
145 | + if (!is_email($recipient)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
@@ -159,37 +159,37 @@ discard block |
||
159 | 159 | $wpinv_email_search = $search; |
160 | 160 | $wpinv_email_replace = $replace; |
161 | 161 | |
162 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
163 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
164 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
165 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
162 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
163 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
164 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
165 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
166 | 166 | |
167 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
167 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
168 | 168 | 'invoice' => $invoice, |
169 | 169 | 'email_type' => $email_type, |
170 | 170 | 'email_heading' => $email_heading, |
171 | 171 | 'sent_to_admin' => true, |
172 | 172 | 'plain_text' => false, |
173 | - ) ); |
|
173 | + )); |
|
174 | 174 | |
175 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
175 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
176 | 176 | } |
177 | 177 | |
178 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
178 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
179 | 179 | global $wpinv_email_search, $wpinv_email_replace; |
180 | 180 | |
181 | 181 | $email_type = 'failed_invoice'; |
182 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
182 | + if (!wpinv_email_is_enabled($email_type)) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
186 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
187 | - if ( empty( $invoice ) ) { |
|
186 | + $invoice = wpinv_get_invoice($invoice_id); |
|
187 | + if (empty($invoice)) { |
|
188 | 188 | return false; |
189 | 189 | } |
190 | 190 | |
191 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
192 | - if ( !is_email( $recipient ) ) { |
|
191 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
192 | + if (!is_email($recipient)) { |
|
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
@@ -206,37 +206,37 @@ discard block |
||
206 | 206 | $wpinv_email_search = $search; |
207 | 207 | $wpinv_email_replace = $replace; |
208 | 208 | |
209 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
210 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
211 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
212 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
209 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
210 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
211 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
212 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
213 | 213 | |
214 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
214 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
215 | 215 | 'invoice' => $invoice, |
216 | 216 | 'email_type' => $email_type, |
217 | 217 | 'email_heading' => $email_heading, |
218 | 218 | 'sent_to_admin' => true, |
219 | 219 | 'plain_text' => false, |
220 | - ) ); |
|
220 | + )); |
|
221 | 221 | |
222 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
222 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
223 | 223 | } |
224 | 224 | |
225 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
225 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
226 | 226 | global $wpinv_email_search, $wpinv_email_replace; |
227 | 227 | |
228 | 228 | $email_type = 'onhold_invoice'; |
229 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
229 | + if (!wpinv_email_is_enabled($email_type)) { |
|
230 | 230 | return false; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
234 | - if ( empty( $invoice ) ) { |
|
233 | + $invoice = wpinv_get_invoice($invoice_id); |
|
234 | + if (empty($invoice)) { |
|
235 | 235 | return false; |
236 | 236 | } |
237 | 237 | |
238 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
239 | - if ( !is_email( $recipient ) ) { |
|
238 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
239 | + if (!is_email($recipient)) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
@@ -253,45 +253,45 @@ discard block |
||
253 | 253 | $wpinv_email_search = $search; |
254 | 254 | $wpinv_email_replace = $replace; |
255 | 255 | |
256 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
257 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
258 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
259 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
256 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
257 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
258 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
259 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
260 | 260 | |
261 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
261 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
262 | 262 | 'invoice' => $invoice, |
263 | 263 | 'email_type' => $email_type, |
264 | 264 | 'email_heading' => $email_heading, |
265 | 265 | 'sent_to_admin' => false, |
266 | 266 | 'plain_text' => false, |
267 | - ) ); |
|
267 | + )); |
|
268 | 268 | |
269 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
269 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
270 | 270 | |
271 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - $subject .= ' - ADMIN BCC COPY'; |
|
274 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
271 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + $subject .= ' - ADMIN BCC COPY'; |
|
274 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | return $sent; |
278 | 278 | } |
279 | 279 | |
280 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
280 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
281 | 281 | global $wpinv_email_search, $wpinv_email_replace; |
282 | 282 | |
283 | 283 | $email_type = 'processing_invoice'; |
284 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
284 | + if (!wpinv_email_is_enabled($email_type)) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
288 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
289 | - if ( empty( $invoice ) ) { |
|
288 | + $invoice = wpinv_get_invoice($invoice_id); |
|
289 | + if (empty($invoice)) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
294 | - if ( !is_email( $recipient ) ) { |
|
293 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
294 | + if (!is_email($recipient)) { |
|
295 | 295 | return false; |
296 | 296 | } |
297 | 297 | |
@@ -308,45 +308,45 @@ discard block |
||
308 | 308 | $wpinv_email_search = $search; |
309 | 309 | $wpinv_email_replace = $replace; |
310 | 310 | |
311 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
312 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
313 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
314 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
311 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
312 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
313 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
314 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
315 | 315 | |
316 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
316 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
317 | 317 | 'invoice' => $invoice, |
318 | 318 | 'email_type' => $email_type, |
319 | 319 | 'email_heading' => $email_heading, |
320 | 320 | 'sent_to_admin' => false, |
321 | 321 | 'plain_text' => false, |
322 | - ) ); |
|
322 | + )); |
|
323 | 323 | |
324 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
324 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
325 | 325 | |
326 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
327 | - $recipient = wpinv_get_admin_email(); |
|
328 | - $subject .= ' - ADMIN BCC COPY'; |
|
329 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
326 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
327 | + $recipient = wpinv_get_admin_email(); |
|
328 | + $subject .= ' - ADMIN BCC COPY'; |
|
329 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return $sent; |
333 | 333 | } |
334 | 334 | |
335 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
335 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
336 | 336 | global $wpinv_email_search, $wpinv_email_replace; |
337 | 337 | |
338 | 338 | $email_type = 'completed_invoice'; |
339 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
339 | + if (!wpinv_email_is_enabled($email_type)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
344 | - if ( empty( $invoice ) ) { |
|
343 | + $invoice = wpinv_get_invoice($invoice_id); |
|
344 | + if (empty($invoice)) { |
|
345 | 345 | return false; |
346 | 346 | } |
347 | 347 | |
348 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
349 | - if ( !is_email( $recipient ) ) { |
|
348 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
349 | + if (!is_email($recipient)) { |
|
350 | 350 | return false; |
351 | 351 | } |
352 | 352 | |
@@ -363,45 +363,45 @@ discard block |
||
363 | 363 | $wpinv_email_search = $search; |
364 | 364 | $wpinv_email_replace = $replace; |
365 | 365 | |
366 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
367 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
368 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
369 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
366 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
367 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
368 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
369 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
370 | 370 | |
371 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
371 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
372 | 372 | 'invoice' => $invoice, |
373 | 373 | 'email_type' => $email_type, |
374 | 374 | 'email_heading' => $email_heading, |
375 | 375 | 'sent_to_admin' => false, |
376 | 376 | 'plain_text' => false, |
377 | - ) ); |
|
377 | + )); |
|
378 | 378 | |
379 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
379 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
380 | 380 | |
381 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
382 | - $recipient = wpinv_get_admin_email(); |
|
383 | - $subject .= ' - ADMIN BCC COPY'; |
|
384 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
381 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
382 | + $recipient = wpinv_get_admin_email(); |
|
383 | + $subject .= ' - ADMIN BCC COPY'; |
|
384 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $sent; |
388 | 388 | } |
389 | 389 | |
390 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
390 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
391 | 391 | global $wpinv_email_search, $wpinv_email_replace; |
392 | 392 | |
393 | 393 | $email_type = 'refunded_invoice'; |
394 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
394 | + if (!wpinv_email_is_enabled($email_type)) { |
|
395 | 395 | return false; |
396 | 396 | } |
397 | 397 | |
398 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
399 | - if ( empty( $invoice ) ) { |
|
398 | + $invoice = wpinv_get_invoice($invoice_id); |
|
399 | + if (empty($invoice)) { |
|
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
404 | - if ( !is_email( $recipient ) ) { |
|
403 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
404 | + if (!is_email($recipient)) { |
|
405 | 405 | return false; |
406 | 406 | } |
407 | 407 | |
@@ -418,46 +418,46 @@ discard block |
||
418 | 418 | $wpinv_email_search = $search; |
419 | 419 | $wpinv_email_replace = $replace; |
420 | 420 | |
421 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
422 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
423 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
424 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
421 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
422 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
423 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
424 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
425 | 425 | |
426 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
426 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
427 | 427 | 'invoice' => $invoice, |
428 | 428 | 'email_type' => $email_type, |
429 | 429 | 'email_heading' => $email_heading, |
430 | 430 | 'sent_to_admin' => false, |
431 | 431 | 'plain_text' => false, |
432 | 432 | 'partial_refund' => false |
433 | - ) ); |
|
433 | + )); |
|
434 | 434 | |
435 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
435 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
436 | 436 | |
437 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
438 | - $recipient = wpinv_get_admin_email(); |
|
439 | - $subject .= ' - ADMIN BCC COPY'; |
|
440 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
437 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
438 | + $recipient = wpinv_get_admin_email(); |
|
439 | + $subject .= ' - ADMIN BCC COPY'; |
|
440 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | return $sent; |
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
446 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
447 | 447 | global $wpinv_email_search, $wpinv_email_replace; |
448 | 448 | |
449 | 449 | $email_type = 'refunded_invoice'; |
450 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
450 | + if (!wpinv_email_is_enabled($email_type)) { |
|
451 | 451 | return false; |
452 | 452 | } |
453 | 453 | |
454 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
455 | - if ( empty( $invoice ) ) { |
|
454 | + $invoice = wpinv_get_invoice($invoice_id); |
|
455 | + if (empty($invoice)) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | 458 | |
459 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
460 | - if ( !is_email( $recipient ) ) { |
|
459 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
460 | + if (!is_email($recipient)) { |
|
461 | 461 | return false; |
462 | 462 | } |
463 | 463 | |
@@ -474,49 +474,49 @@ discard block |
||
474 | 474 | $wpinv_email_search = $search; |
475 | 475 | $wpinv_email_replace = $replace; |
476 | 476 | |
477 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
478 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
479 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
480 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
477 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
478 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
479 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
480 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
481 | 481 | |
482 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
482 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
483 | 483 | 'invoice' => $invoice, |
484 | 484 | 'email_type' => $email_type, |
485 | 485 | 'email_heading' => $email_heading, |
486 | 486 | 'sent_to_admin' => false, |
487 | 487 | 'plain_text' => false, |
488 | 488 | 'partial_refund' => true |
489 | - ) ); |
|
489 | + )); |
|
490 | 490 | |
491 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
491 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
492 | 492 | |
493 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
494 | - $recipient = wpinv_get_admin_email(); |
|
495 | - $subject .= ' - ADMIN BCC COPY'; |
|
496 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
493 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
494 | + $recipient = wpinv_get_admin_email(); |
|
495 | + $subject .= ' - ADMIN BCC COPY'; |
|
496 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | return $sent; |
500 | 500 | } |
501 | 501 | |
502 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
502 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
503 | 503 | } |
504 | 504 | |
505 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
505 | +function wpinv_user_invoice_notification($invoice_id) { |
|
506 | 506 | global $wpinv_email_search, $wpinv_email_replace; |
507 | 507 | |
508 | 508 | $email_type = 'user_invoice'; |
509 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
509 | + if (!wpinv_email_is_enabled($email_type)) { |
|
510 | 510 | return false; |
511 | 511 | } |
512 | 512 | |
513 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
514 | - if ( empty( $invoice ) ) { |
|
513 | + $invoice = wpinv_get_invoice($invoice_id); |
|
514 | + if (empty($invoice)) { |
|
515 | 515 | return false; |
516 | 516 | } |
517 | 517 | |
518 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
519 | - if ( !is_email( $recipient ) ) { |
|
518 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
519 | + if (!is_email($recipient)) { |
|
520 | 520 | return false; |
521 | 521 | } |
522 | 522 | |
@@ -533,52 +533,52 @@ discard block |
||
533 | 533 | $wpinv_email_search = $search; |
534 | 534 | $wpinv_email_replace = $replace; |
535 | 535 | |
536 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
537 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
538 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
539 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
536 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
537 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
538 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
539 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
540 | 540 | |
541 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
541 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
542 | 542 | 'invoice' => $invoice, |
543 | 543 | 'email_type' => $email_type, |
544 | 544 | 'email_heading' => $email_heading, |
545 | 545 | 'sent_to_admin' => false, |
546 | 546 | 'plain_text' => false, |
547 | - ) ); |
|
547 | + )); |
|
548 | 548 | |
549 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
549 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
550 | 550 | |
551 | - if ( $sent ) { |
|
552 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
551 | + if ($sent) { |
|
552 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
553 | 553 | } else { |
554 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
554 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
555 | 555 | } |
556 | - $invoice->add_note( $note ); // Add private note. |
|
556 | + $invoice->add_note($note); // Add private note. |
|
557 | 557 | |
558 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
559 | - $recipient = wpinv_get_admin_email(); |
|
560 | - $subject .= ' - ADMIN BCC COPY'; |
|
561 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
558 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
559 | + $recipient = wpinv_get_admin_email(); |
|
560 | + $subject .= ' - ADMIN BCC COPY'; |
|
561 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | return $sent; |
565 | 565 | } |
566 | 566 | |
567 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
567 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
568 | 568 | global $wpinv_email_search, $wpinv_email_replace; |
569 | 569 | |
570 | 570 | $email_type = 'user_note'; |
571 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
571 | + if (!wpinv_email_is_enabled($email_type)) { |
|
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
576 | - if ( empty( $invoice ) ) { |
|
575 | + $invoice = wpinv_get_invoice($invoice_id); |
|
576 | + if (empty($invoice)) { |
|
577 | 577 | return false; |
578 | 578 | } |
579 | 579 | |
580 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
581 | - if ( !is_email( $recipient ) ) { |
|
580 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
581 | + if (!is_email($recipient)) { |
|
582 | 582 | return false; |
583 | 583 | } |
584 | 584 | |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | 'user_note' => '' |
587 | 587 | ); |
588 | 588 | |
589 | - $args = wp_parse_args( $args, $defaults ); |
|
589 | + $args = wp_parse_args($args, $defaults); |
|
590 | 590 | |
591 | 591 | $search = array(); |
592 | 592 | $search['invoice_number'] = '{invoice_number}'; |
@@ -603,46 +603,46 @@ discard block |
||
603 | 603 | $wpinv_email_search = $search; |
604 | 604 | $wpinv_email_replace = $replace; |
605 | 605 | |
606 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
607 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
608 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
609 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
606 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
607 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
608 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
609 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
610 | 610 | |
611 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
611 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
612 | 612 | 'invoice' => $invoice, |
613 | 613 | 'email_type' => $email_type, |
614 | 614 | 'email_heading' => $email_heading, |
615 | 615 | 'sent_to_admin' => false, |
616 | 616 | 'plain_text' => false, |
617 | 617 | 'customer_note' => $args['user_note'] |
618 | - ) ); |
|
618 | + )); |
|
619 | 619 | |
620 | - $content = wpinv_email_format_text( $content ); |
|
620 | + $content = wpinv_email_format_text($content); |
|
621 | 621 | |
622 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
622 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
623 | 623 | |
624 | 624 | return $sent; |
625 | 625 | } |
626 | 626 | |
627 | 627 | function wpinv_mail_get_from_address() { |
628 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
629 | - return sanitize_email( $from_address ); |
|
628 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
629 | + return sanitize_email($from_address); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | function wpinv_mail_get_from_name() { |
633 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
634 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
633 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
634 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
635 | 635 | } |
636 | 636 | |
637 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
638 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
639 | - return ( $active ? true : false ); |
|
637 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
638 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
639 | + return ($active ? true : false); |
|
640 | 640 | } |
641 | 641 | |
642 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
643 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
642 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
643 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
644 | 644 | |
645 | - switch ( $email_type ) { |
|
645 | + switch ($email_type) { |
|
646 | 646 | case 'html' : |
647 | 647 | $content_type = 'text/html'; |
648 | 648 | break; |
@@ -657,35 +657,35 @@ discard block |
||
657 | 657 | return $content_type; |
658 | 658 | } |
659 | 659 | |
660 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
661 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
662 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
663 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
660 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
661 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
662 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
663 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
664 | 664 | |
665 | - $message = wpinv_email_style_body( $message ); |
|
666 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
665 | + $message = wpinv_email_style_body($message); |
|
666 | + $message = apply_filters('wpinv_mail_content', $message); |
|
667 | 667 | |
668 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
668 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
669 | 669 | |
670 | - if ( !$sent ) { |
|
671 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
672 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
670 | + if (!$sent) { |
|
671 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
672 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
673 | 673 | } |
674 | 674 | |
675 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
676 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
677 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
675 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
676 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
677 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
678 | 678 | |
679 | 679 | return $sent; |
680 | 680 | } |
681 | 681 | |
682 | 682 | function wpinv_get_emails() { |
683 | 683 | $overdue_days_options = array(); |
684 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
685 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
684 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
685 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
686 | 686 | |
687 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
688 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
687 | + for ($i = 2; $i <= 10; $i++) { |
|
688 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | // Default, built-in gateways |
@@ -693,130 +693,130 @@ discard block |
||
693 | 693 | 'new_invoice' => array( |
694 | 694 | 'email_new_invoice_header' => array( |
695 | 695 | 'id' => 'email_new_invoice_header', |
696 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
697 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
696 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
697 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
698 | 698 | 'type' => 'header', |
699 | 699 | ), |
700 | 700 | 'email_new_invoice_active' => array( |
701 | 701 | 'id' => 'email_new_invoice_active', |
702 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
703 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
702 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
703 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
704 | 704 | 'type' => 'checkbox', |
705 | 705 | 'std' => 1 |
706 | 706 | ), |
707 | 707 | 'email_new_invoice_subject' => array( |
708 | 708 | 'id' => 'email_new_invoice_subject', |
709 | - 'name' => __( 'Subject', 'invoicing' ), |
|
710 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
709 | + 'name' => __('Subject', 'invoicing'), |
|
710 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
711 | 711 | 'type' => 'text', |
712 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
712 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
713 | 713 | 'size' => 'large' |
714 | 714 | ), |
715 | 715 | 'email_new_invoice_heading' => array( |
716 | 716 | 'id' => 'email_new_invoice_heading', |
717 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
718 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
717 | + 'name' => __('Email Heading', 'invoicing'), |
|
718 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
719 | 719 | 'type' => 'text', |
720 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
720 | + 'std' => __('New payment invoice', 'invoicing'), |
|
721 | 721 | 'size' => 'large' |
722 | 722 | ), |
723 | 723 | ), |
724 | 724 | 'cancelled_invoice' => array( |
725 | 725 | 'email_cancelled_invoice_header' => array( |
726 | 726 | 'id' => 'email_cancelled_invoice_header', |
727 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
728 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
727 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
728 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
729 | 729 | 'type' => 'header', |
730 | 730 | ), |
731 | 731 | 'email_cancelled_invoice_active' => array( |
732 | 732 | 'id' => 'email_cancelled_invoice_active', |
733 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
734 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
733 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
734 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
735 | 735 | 'type' => 'checkbox', |
736 | 736 | 'std' => 1 |
737 | 737 | ), |
738 | 738 | 'email_cancelled_invoice_subject' => array( |
739 | 739 | 'id' => 'email_cancelled_invoice_subject', |
740 | - 'name' => __( 'Subject', 'invoicing' ), |
|
741 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
740 | + 'name' => __('Subject', 'invoicing'), |
|
741 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
742 | 742 | 'type' => 'text', |
743 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
743 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
744 | 744 | 'size' => 'large' |
745 | 745 | ), |
746 | 746 | 'email_cancelled_invoice_heading' => array( |
747 | 747 | 'id' => 'email_cancelled_invoice_heading', |
748 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
749 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
748 | + 'name' => __('Email Heading', 'invoicing'), |
|
749 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
750 | 750 | 'type' => 'text', |
751 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
751 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
752 | 752 | 'size' => 'large' |
753 | 753 | ), |
754 | 754 | ), |
755 | 755 | 'failed_invoice' => array( |
756 | 756 | 'email_failed_invoice_header' => array( |
757 | 757 | 'id' => 'email_failed_invoice_header', |
758 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
759 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
758 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
759 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
760 | 760 | 'type' => 'header', |
761 | 761 | ), |
762 | 762 | 'email_failed_invoice_active' => array( |
763 | 763 | 'id' => 'email_failed_invoice_active', |
764 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
765 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
764 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
765 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
766 | 766 | 'type' => 'checkbox', |
767 | 767 | 'std' => 1 |
768 | 768 | ), |
769 | 769 | 'email_failed_invoice_subject' => array( |
770 | 770 | 'id' => 'email_failed_invoice_subject', |
771 | - 'name' => __( 'Subject', 'invoicing' ), |
|
772 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
771 | + 'name' => __('Subject', 'invoicing'), |
|
772 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
773 | 773 | 'type' => 'text', |
774 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
774 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
775 | 775 | 'size' => 'large' |
776 | 776 | ), |
777 | 777 | 'email_failed_invoice_heading' => array( |
778 | 778 | 'id' => 'email_failed_invoice_heading', |
779 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
780 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
779 | + 'name' => __('Email Heading', 'invoicing'), |
|
780 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
781 | 781 | 'type' => 'text', |
782 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
782 | + 'std' => __('Failed invoice', 'invoicing'), |
|
783 | 783 | 'size' => 'large' |
784 | 784 | ) |
785 | 785 | ), |
786 | 786 | 'onhold_invoice' => array( |
787 | 787 | 'email_onhold_invoice_header' => array( |
788 | 788 | 'id' => 'email_onhold_invoice_header', |
789 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
790 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
789 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
790 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
791 | 791 | 'type' => 'header', |
792 | 792 | ), |
793 | 793 | 'email_onhold_invoice_active' => array( |
794 | 794 | 'id' => 'email_onhold_invoice_active', |
795 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
796 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
795 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
796 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
797 | 797 | 'type' => 'checkbox', |
798 | 798 | 'std' => 1 |
799 | 799 | ), |
800 | 800 | 'email_onhold_invoice_subject' => array( |
801 | 801 | 'id' => 'email_onhold_invoice_subject', |
802 | - 'name' => __( 'Subject', 'invoicing' ), |
|
803 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
802 | + 'name' => __('Subject', 'invoicing'), |
|
803 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
804 | 804 | 'type' => 'text', |
805 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
805 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
806 | 806 | 'size' => 'large' |
807 | 807 | ), |
808 | 808 | 'email_onhold_invoice_heading' => array( |
809 | 809 | 'id' => 'email_onhold_invoice_heading', |
810 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
811 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
810 | + 'name' => __('Email Heading', 'invoicing'), |
|
811 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
812 | 812 | 'type' => 'text', |
813 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
813 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
814 | 814 | 'size' => 'large' |
815 | 815 | ), |
816 | 816 | 'email_onhold_invoice_admin_bcc' => array( |
817 | 817 | 'id' => 'email_onhold_invoice_admin_bcc', |
818 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
819 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
818 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
819 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
820 | 820 | 'type' => 'checkbox', |
821 | 821 | 'std' => 1 |
822 | 822 | ), |
@@ -824,37 +824,37 @@ discard block |
||
824 | 824 | 'processing_invoice' => array( |
825 | 825 | 'email_processing_invoice_header' => array( |
826 | 826 | 'id' => 'email_processing_invoice_header', |
827 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
828 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
827 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
828 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
829 | 829 | 'type' => 'header', |
830 | 830 | ), |
831 | 831 | 'email_processing_invoice_active' => array( |
832 | 832 | 'id' => 'email_processing_invoice_active', |
833 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
834 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
833 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
834 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
835 | 835 | 'type' => 'checkbox', |
836 | 836 | 'std' => 1 |
837 | 837 | ), |
838 | 838 | 'email_processing_invoice_subject' => array( |
839 | 839 | 'id' => 'email_processing_invoice_subject', |
840 | - 'name' => __( 'Subject', 'invoicing' ), |
|
841 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
840 | + 'name' => __('Subject', 'invoicing'), |
|
841 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
842 | 842 | 'type' => 'text', |
843 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
843 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
844 | 844 | 'size' => 'large' |
845 | 845 | ), |
846 | 846 | 'email_processing_invoice_heading' => array( |
847 | 847 | 'id' => 'email_processing_invoice_heading', |
848 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
849 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
848 | + 'name' => __('Email Heading', 'invoicing'), |
|
849 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
850 | 850 | 'type' => 'text', |
851 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
851 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
852 | 852 | 'size' => 'large' |
853 | 853 | ), |
854 | 854 | 'email_processing_invoice_admin_bcc' => array( |
855 | 855 | 'id' => 'email_processing_invoice_admin_bcc', |
856 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
857 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
856 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
857 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
858 | 858 | 'type' => 'checkbox', |
859 | 859 | 'std' => 1 |
860 | 860 | ), |
@@ -862,37 +862,37 @@ discard block |
||
862 | 862 | 'completed_invoice' => array( |
863 | 863 | 'email_completed_invoice_header' => array( |
864 | 864 | 'id' => 'email_completed_invoice_header', |
865 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
866 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
865 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
866 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
867 | 867 | 'type' => 'header', |
868 | 868 | ), |
869 | 869 | 'email_completed_invoice_active' => array( |
870 | 870 | 'id' => 'email_completed_invoice_active', |
871 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
872 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
871 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
872 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
873 | 873 | 'type' => 'checkbox', |
874 | 874 | 'std' => 1 |
875 | 875 | ), |
876 | 876 | 'email_completed_invoice_subject' => array( |
877 | 877 | 'id' => 'email_completed_invoice_subject', |
878 | - 'name' => __( 'Subject', 'invoicing' ), |
|
879 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
878 | + 'name' => __('Subject', 'invoicing'), |
|
879 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
880 | 880 | 'type' => 'text', |
881 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
881 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
882 | 882 | 'size' => 'large' |
883 | 883 | ), |
884 | 884 | 'email_completed_invoice_heading' => array( |
885 | 885 | 'id' => 'email_completed_invoice_heading', |
886 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
887 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
886 | + 'name' => __('Email Heading', 'invoicing'), |
|
887 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
888 | 888 | 'type' => 'text', |
889 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
889 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
890 | 890 | 'size' => 'large' |
891 | 891 | ), |
892 | 892 | 'email_completed_invoice_admin_bcc' => array( |
893 | 893 | 'id' => 'email_completed_invoice_admin_bcc', |
894 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
895 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
894 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
895 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
896 | 896 | 'type' => 'checkbox', |
897 | 897 | ), |
898 | 898 | 'std' => 1 |
@@ -900,37 +900,37 @@ discard block |
||
900 | 900 | 'refunded_invoice' => array( |
901 | 901 | 'email_refunded_invoice_header' => array( |
902 | 902 | 'id' => 'email_refunded_invoice_header', |
903 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
904 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
903 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
904 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
905 | 905 | 'type' => 'header', |
906 | 906 | ), |
907 | 907 | 'email_refunded_invoice_active' => array( |
908 | 908 | 'id' => 'email_refunded_invoice_active', |
909 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
910 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
909 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
910 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
911 | 911 | 'type' => 'checkbox', |
912 | 912 | 'std' => 1 |
913 | 913 | ), |
914 | 914 | 'email_refunded_invoice_subject' => array( |
915 | 915 | 'id' => 'email_refunded_invoice_subject', |
916 | - 'name' => __( 'Subject', 'invoicing' ), |
|
917 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
916 | + 'name' => __('Subject', 'invoicing'), |
|
917 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
918 | 918 | 'type' => 'text', |
919 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
919 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
920 | 920 | 'size' => 'large' |
921 | 921 | ), |
922 | 922 | 'email_refunded_invoice_heading' => array( |
923 | 923 | 'id' => 'email_refunded_invoice_heading', |
924 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
925 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
924 | + 'name' => __('Email Heading', 'invoicing'), |
|
925 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
926 | 926 | 'type' => 'text', |
927 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
927 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
928 | 928 | 'size' => 'large' |
929 | 929 | ), |
930 | 930 | 'email_refunded_invoice_admin_bcc' => array( |
931 | 931 | 'id' => 'email_refunded_invoice_admin_bcc', |
932 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
933 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
932 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
933 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
934 | 934 | 'type' => 'checkbox', |
935 | 935 | 'std' => 1 |
936 | 936 | ), |
@@ -938,37 +938,37 @@ discard block |
||
938 | 938 | 'user_invoice' => array( |
939 | 939 | 'email_user_invoice_header' => array( |
940 | 940 | 'id' => 'email_user_invoice_header', |
941 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
942 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
941 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
942 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
943 | 943 | 'type' => 'header', |
944 | 944 | ), |
945 | 945 | 'email_user_invoice_active' => array( |
946 | 946 | 'id' => 'email_user_invoice_active', |
947 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
948 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
947 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
948 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
949 | 949 | 'type' => 'checkbox', |
950 | 950 | 'std' => 1 |
951 | 951 | ), |
952 | 952 | 'email_user_invoice_subject' => array( |
953 | 953 | 'id' => 'email_user_invoice_subject', |
954 | - 'name' => __( 'Subject', 'invoicing' ), |
|
955 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
954 | + 'name' => __('Subject', 'invoicing'), |
|
955 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
956 | 956 | 'type' => 'text', |
957 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
957 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
958 | 958 | 'size' => 'large' |
959 | 959 | ), |
960 | 960 | 'email_user_invoice_heading' => array( |
961 | 961 | 'id' => 'email_user_invoice_heading', |
962 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
963 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
962 | + 'name' => __('Email Heading', 'invoicing'), |
|
963 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
964 | 964 | 'type' => 'text', |
965 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
965 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
966 | 966 | 'size' => 'large' |
967 | 967 | ), |
968 | 968 | 'email_user_invoice_admin_bcc' => array( |
969 | 969 | 'id' => 'email_user_invoice_admin_bcc', |
970 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
971 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
970 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
971 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
972 | 972 | 'type' => 'checkbox', |
973 | 973 | 'std' => 1 |
974 | 974 | ), |
@@ -976,177 +976,177 @@ discard block |
||
976 | 976 | 'user_note' => array( |
977 | 977 | 'email_user_note_header' => array( |
978 | 978 | 'id' => 'email_user_note_header', |
979 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
980 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ), |
|
979 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
980 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'), |
|
981 | 981 | 'type' => 'header', |
982 | 982 | ), |
983 | 983 | 'email_user_note_active' => array( |
984 | 984 | 'id' => 'email_user_note_active', |
985 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
986 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
985 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
986 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
987 | 987 | 'type' => 'checkbox', |
988 | 988 | 'std' => 1 |
989 | 989 | ), |
990 | 990 | 'email_user_note_subject' => array( |
991 | 991 | 'id' => 'email_user_note_subject', |
992 | - 'name' => __( 'Subject', 'invoicing' ), |
|
993 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
992 | + 'name' => __('Subject', 'invoicing'), |
|
993 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
994 | 994 | 'type' => 'text', |
995 | - 'std' => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
995 | + 'std' => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'), |
|
996 | 996 | 'size' => 'large' |
997 | 997 | ), |
998 | 998 | 'email_user_note_heading' => array( |
999 | 999 | 'id' => 'email_user_note_heading', |
1000 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1001 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
1000 | + 'name' => __('Email Heading', 'invoicing'), |
|
1001 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
1002 | 1002 | 'type' => 'text', |
1003 | - 'std' => __( 'A note has been added to your invoice', 'invoicing' ), |
|
1003 | + 'std' => __('A note has been added to your invoice', 'invoicing'), |
|
1004 | 1004 | 'size' => 'large' |
1005 | 1005 | ), |
1006 | 1006 | ), |
1007 | 1007 | 'overdue' => array( |
1008 | 1008 | 'email_overdue_header' => array( |
1009 | 1009 | 'id' => 'email_overdue_header', |
1010 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
1011 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
1010 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
1011 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
1012 | 1012 | 'type' => 'header', |
1013 | 1013 | ), |
1014 | 1014 | 'email_overdue_active' => array( |
1015 | 1015 | 'id' => 'email_overdue_active', |
1016 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1017 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1016 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1017 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1018 | 1018 | 'type' => 'checkbox', |
1019 | 1019 | 'std' => 1 |
1020 | 1020 | ), |
1021 | 1021 | 'email_due_reminder_days' => array( |
1022 | 1022 | 'id' => 'email_due_reminder_days', |
1023 | - 'name' => __( 'When to Send', 'sliced-invoices' ), |
|
1024 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
1023 | + 'name' => __('When to Send', 'sliced-invoices'), |
|
1024 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
1025 | 1025 | 'default' => '', |
1026 | 1026 | 'type' => 'multicheck', |
1027 | 1027 | 'options' => $overdue_days_options, |
1028 | 1028 | ), |
1029 | 1029 | 'email_overdue_subject' => array( |
1030 | 1030 | 'id' => 'email_overdue_subject', |
1031 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1032 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1031 | + 'name' => __('Subject', 'invoicing'), |
|
1032 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1033 | 1033 | 'type' => 'text', |
1034 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
1034 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
1035 | 1035 | 'size' => 'large' |
1036 | 1036 | ), |
1037 | 1037 | 'email_overdue_heading' => array( |
1038 | 1038 | 'id' => 'email_overdue_heading', |
1039 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1040 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
1039 | + 'name' => __('Email Heading', 'invoicing'), |
|
1040 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
1041 | 1041 | 'type' => 'text', |
1042 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
1042 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
1043 | 1043 | 'size' => 'large' |
1044 | 1044 | ), |
1045 | 1045 | 'email_overdue_body' => array( |
1046 | 1046 | 'id' => 'email_overdue_body', |
1047 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1048 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
1047 | + 'name' => __('Email Content', 'invoicing'), |
|
1048 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
1049 | 1049 | 'type' => 'rich_editor', |
1050 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ), |
|
1050 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'), |
|
1051 | 1051 | 'class' => 'large', |
1052 | 1052 | 'size' => 10, |
1053 | 1053 | ), |
1054 | 1054 | ), |
1055 | 1055 | ); |
1056 | 1056 | |
1057 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
1057 | + return apply_filters('wpinv_get_emails', $emails); |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | -function wpinv_settings_emails( $settings = array() ) { |
|
1060 | +function wpinv_settings_emails($settings = array()) { |
|
1061 | 1061 | $emails = wpinv_get_emails(); |
1062 | 1062 | |
1063 | - if ( !empty( $emails ) ) { |
|
1064 | - foreach ( $emails as $key => $email ) { |
|
1063 | + if (!empty($emails)) { |
|
1064 | + foreach ($emails as $key => $email) { |
|
1065 | 1065 | $settings[$key] = $email; |
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
1069 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
1070 | 1070 | } |
1071 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
1071 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
1072 | 1072 | |
1073 | -function wpinv_settings_sections_emails( $settings ) { |
|
1073 | +function wpinv_settings_sections_emails($settings) { |
|
1074 | 1074 | $emails = wpinv_get_emails(); |
1075 | 1075 | |
1076 | 1076 | if (!empty($emails)) { |
1077 | - foreach ($emails as $key => $email) { |
|
1078 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
1077 | + foreach ($emails as $key => $email) { |
|
1078 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
1079 | 1079 | } |
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | return $settings; |
1083 | 1083 | } |
1084 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
1084 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
1085 | 1085 | |
1086 | -function wpinv_email_is_enabled( $email_type ) { |
|
1086 | +function wpinv_email_is_enabled($email_type) { |
|
1087 | 1087 | $emails = wpinv_get_emails(); |
1088 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false; |
|
1088 | + $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false; |
|
1089 | 1089 | |
1090 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
1090 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1094 | - switch ( $email_type ) { |
|
1093 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1094 | + switch ($email_type) { |
|
1095 | 1095 | case 'new_invoice': |
1096 | 1096 | case 'cancelled_invoice': |
1097 | 1097 | case 'failed_invoice': |
1098 | 1098 | $recipient = wpinv_get_admin_email(); |
1099 | 1099 | break; |
1100 | 1100 | default: |
1101 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1102 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
1101 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1102 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
1103 | 1103 | break; |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
1106 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
1107 | 1107 | } |
1108 | 1108 | |
1109 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1110 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
1109 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1110 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
1111 | 1111 | |
1112 | - $subject = wpinv_email_format_text( $subject ); |
|
1112 | + $subject = wpinv_email_format_text($subject); |
|
1113 | 1113 | |
1114 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
1114 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1118 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
1117 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1118 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
1119 | 1119 | |
1120 | - $email_heading = wpinv_email_format_text( $email_heading ); |
|
1120 | + $email_heading = wpinv_email_format_text($email_heading); |
|
1121 | 1121 | |
1122 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
1122 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1126 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
1125 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1126 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
1127 | 1127 | |
1128 | - $content = wpinv_email_format_text( $content ); |
|
1128 | + $content = wpinv_email_format_text($content); |
|
1129 | 1129 | |
1130 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
1130 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1133 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1134 | 1134 | $from_name = wpinv_mail_get_from_address(); |
1135 | 1135 | $from_email = wpinv_mail_get_from_address(); |
1136 | 1136 | |
1137 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1137 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1138 | 1138 | |
1139 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
1140 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
1139 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
1140 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
1141 | 1141 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
1142 | 1142 | |
1143 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
1143 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
1144 | 1144 | } |
1145 | 1145 | |
1146 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1146 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1147 | 1147 | $attachments = array(); |
1148 | 1148 | |
1149 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
1149 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | function wpinv_email_global_vars() { |
@@ -1163,73 +1163,73 @@ discard block |
||
1163 | 1163 | $replace['sitename'] = $blogname; |
1164 | 1164 | $replace['site-title'] = $blogname; |
1165 | 1165 | |
1166 | - return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) ); |
|
1166 | + return apply_filters('wpinv_email_global_vars', array($search, $replace)); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | -function wpinv_email_format_text( $content ) { |
|
1169 | +function wpinv_email_format_text($content) { |
|
1170 | 1170 | global $wpinv_email_search, $wpinv_email_replace; |
1171 | 1171 | |
1172 | - if ( empty( $wpinv_email_search ) ) { |
|
1172 | + if (empty($wpinv_email_search)) { |
|
1173 | 1173 | $wpinv_email_search = array(); |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - if ( empty( $wpinv_email_replace ) ) { |
|
1176 | + if (empty($wpinv_email_replace)) { |
|
1177 | 1177 | $wpinv_email_replace = array(); |
1178 | 1178 | } |
1179 | 1179 | |
1180 | - $wpinv_email_search = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search ); |
|
1181 | - $wpinv_email_replace = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace ); |
|
1180 | + $wpinv_email_search = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search); |
|
1181 | + $wpinv_email_replace = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace); |
|
1182 | 1182 | |
1183 | 1183 | $global_vars = wpinv_email_global_vars(); |
1184 | 1184 | |
1185 | - $search = array_merge( $global_vars[0], $wpinv_email_search ); |
|
1186 | - $replace = array_merge( $global_vars[1], $wpinv_email_replace ); |
|
1185 | + $search = array_merge($global_vars[0], $wpinv_email_search); |
|
1186 | + $replace = array_merge($global_vars[1], $wpinv_email_replace); |
|
1187 | 1187 | |
1188 | - if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) { |
|
1188 | + if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) { |
|
1189 | 1189 | return $content; |
1190 | 1190 | } |
1191 | 1191 | |
1192 | - return str_replace( $search, $replace, $content ); |
|
1192 | + return str_replace($search, $replace, $content); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | -function wpinv_email_style_body( $content ) { |
|
1195 | +function wpinv_email_style_body($content) { |
|
1196 | 1196 | // make sure we only inline CSS for html emails |
1197 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
1197 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
1198 | 1198 | ob_start(); |
1199 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
1200 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
1199 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
1200 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
1201 | 1201 | |
1202 | 1202 | // apply CSS styles inline for picky email clients |
1203 | 1203 | try { |
1204 | - $emogrifier = new Emogrifier( $content, $css ); |
|
1204 | + $emogrifier = new Emogrifier($content, $css); |
|
1205 | 1205 | $content = $emogrifier->emogrify(); |
1206 | - } catch ( Exception $e ) { |
|
1207 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
1206 | + } catch (Exception $e) { |
|
1207 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
1208 | 1208 | } |
1209 | 1209 | } |
1210 | 1210 | return $content; |
1211 | 1211 | } |
1212 | 1212 | |
1213 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1214 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1213 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1214 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | /** |
1218 | 1218 | * Get the email footer. |
1219 | 1219 | */ |
1220 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1221 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1220 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1221 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | -function wpinv_email_wrap_message( $message ) { |
|
1224 | +function wpinv_email_wrap_message($message) { |
|
1225 | 1225 | // Buffer |
1226 | 1226 | ob_start(); |
1227 | 1227 | |
1228 | - do_action( 'wpinv_email_header' ); |
|
1228 | + do_action('wpinv_email_header'); |
|
1229 | 1229 | |
1230 | - echo wpautop( wptexturize( $message ) ); |
|
1230 | + echo wpautop(wptexturize($message)); |
|
1231 | 1231 | |
1232 | - do_action( 'wpinv_email_footer' ); |
|
1232 | + do_action('wpinv_email_footer'); |
|
1233 | 1233 | |
1234 | 1234 | // Get contents |
1235 | 1235 | $message = ob_get_clean(); |
@@ -1237,86 +1237,86 @@ discard block |
||
1237 | 1237 | return $message; |
1238 | 1238 | } |
1239 | 1239 | |
1240 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1241 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1240 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1241 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1245 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1244 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
1245 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1246 | 1246 | } |
1247 | 1247 | |
1248 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1249 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1248 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1249 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1250 | 1250 | } |
1251 | 1251 | |
1252 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
1253 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1252 | +function wpinv_send_customer_invoice($data = array()) { |
|
1253 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1254 | 1254 | |
1255 | - if ( empty( $invoice_id ) ) { |
|
1255 | + if (empty($invoice_id)) { |
|
1256 | 1256 | return; |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1260 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1259 | + if (!current_user_can('manage_options')) { |
|
1260 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1261 | 1261 | } |
1262 | 1262 | |
1263 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
1263 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
1264 | 1264 | |
1265 | 1265 | $status = $sent ? 'email_sent' : 'email_fail'; |
1266 | 1266 | |
1267 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1268 | - wp_redirect( $redirect ); |
|
1267 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1268 | + wp_redirect($redirect); |
|
1269 | 1269 | exit; |
1270 | 1270 | } |
1271 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
1271 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
1272 | 1272 | |
1273 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
1274 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1273 | +function wpinv_send_overdue_reminder($data = array()) { |
|
1274 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1275 | 1275 | |
1276 | - if ( empty( $invoice_id ) ) { |
|
1276 | + if (empty($invoice_id)) { |
|
1277 | 1277 | return; |
1278 | 1278 | } |
1279 | 1279 | |
1280 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1281 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1280 | + if (!current_user_can('manage_options')) { |
|
1281 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
1284 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
1285 | 1285 | |
1286 | 1286 | $status = $sent ? 'email_sent' : 'email_fail'; |
1287 | 1287 | |
1288 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1289 | - wp_redirect( $redirect ); |
|
1288 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1289 | + wp_redirect($redirect); |
|
1290 | 1290 | exit; |
1291 | 1291 | } |
1292 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
1292 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
1293 | 1293 | |
1294 | -function wpinv_send_customer_note_email( $data ) { |
|
1295 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1294 | +function wpinv_send_customer_note_email($data) { |
|
1295 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1296 | 1296 | |
1297 | - if ( empty( $invoice_id ) ) { |
|
1297 | + if (empty($invoice_id)) { |
|
1298 | 1298 | return; |
1299 | 1299 | } |
1300 | 1300 | |
1301 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
1301 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
1302 | 1302 | } |
1303 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
1303 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
1304 | 1304 | |
1305 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
1306 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
1307 | - $date_format = get_option( 'date_format' ); |
|
1308 | - $time_format = get_option( 'time_format' ); |
|
1305 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
1306 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
1307 | + $date_format = get_option('date_format'); |
|
1308 | + $time_format = get_option('time_format'); |
|
1309 | 1309 | ?> |
1310 | 1310 | <div id="wpinv-email-notes"> |
1311 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
1311 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
1312 | 1312 | <ol class="wpinv-notes-lists"> |
1313 | 1313 | <?php |
1314 | - foreach ( $invoice_notes as $note ) { |
|
1315 | - $note_time = strtotime( $note->comment_date ); |
|
1314 | + foreach ($invoice_notes as $note) { |
|
1315 | + $note_time = strtotime($note->comment_date); |
|
1316 | 1316 | ?> |
1317 | 1317 | <li class="comment wpinv-note"> |
1318 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
1319 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
1318 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
1319 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
1320 | 1320 | </li> |
1321 | 1321 | <?php |
1322 | 1322 | } |
@@ -1325,21 +1325,21 @@ discard block |
||
1325 | 1325 | <?php |
1326 | 1326 | } |
1327 | 1327 | } |
1328 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
1328 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
1329 | 1329 | |
1330 | 1330 | function wpinv_email_payment_reminders() { |
1331 | 1331 | global $wpi_auto_reminder; |
1332 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
1332 | + if (!wpinv_get_option('email_overdue_active')) { |
|
1333 | 1333 | return; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
1337 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
1336 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
1337 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
1338 | 1338 | |
1339 | - if ( empty( $reminder_days ) ) { |
|
1339 | + if (empty($reminder_days)) { |
|
1340 | 1340 | return; |
1341 | 1341 | } |
1342 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
1342 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
1343 | 1343 | |
1344 | 1344 | $args = array( |
1345 | 1345 | 'post_type' => 'wpi_invoice', |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | 'meta_query' => array( |
1350 | 1350 | array( |
1351 | 1351 | 'key' => '_wpinv_due_date', |
1352 | - 'value' => array( '', 'none' ), |
|
1352 | + 'value' => array('', 'none'), |
|
1353 | 1353 | 'compare' => 'NOT IN', |
1354 | 1354 | ) |
1355 | 1355 | ), |
@@ -1358,64 +1358,64 @@ discard block |
||
1358 | 1358 | 'order' => 'ASC', |
1359 | 1359 | ); |
1360 | 1360 | |
1361 | - $invoices = get_posts( $args ); |
|
1361 | + $invoices = get_posts($args); |
|
1362 | 1362 | |
1363 | - if ( empty( $invoices ) ) { |
|
1363 | + if (empty($invoices)) { |
|
1364 | 1364 | return; |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - $date_to_send = array(); |
|
1367 | + $date_to_send = array(); |
|
1368 | 1368 | |
1369 | - foreach ( $invoices as $id ) { |
|
1370 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
1369 | + foreach ($invoices as $id) { |
|
1370 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
1371 | 1371 | |
1372 | - foreach ( $reminder_days as $key => $days ) { |
|
1373 | - if ( $days !== '' ) { |
|
1374 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
1372 | + foreach ($reminder_days as $key => $days) { |
|
1373 | + if ($days !== '') { |
|
1374 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
1375 | 1375 | } |
1376 | 1376 | } |
1377 | 1377 | } |
1378 | 1378 | |
1379 | - $today = date_i18n( 'Y-m-d' ); |
|
1379 | + $today = date_i18n('Y-m-d'); |
|
1380 | 1380 | $wpi_auto_reminder = true; |
1381 | 1381 | |
1382 | - foreach ( $date_to_send as $id => $values ) { |
|
1383 | - if ( in_array( $today, $values ) ) { |
|
1384 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
1382 | + foreach ($date_to_send as $id => $values) { |
|
1383 | + if (in_array($today, $values)) { |
|
1384 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
1385 | 1385 | |
1386 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
1387 | - if ( !in_array( $today, $sent ) ) { |
|
1388 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1386 | + if (isset($sent) && !empty($sent)) { |
|
1387 | + if (!in_array($today, $sent)) { |
|
1388 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1389 | 1389 | } |
1390 | 1390 | } else { |
1391 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1391 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1392 | 1392 | } |
1393 | 1393 | } |
1394 | 1394 | } |
1395 | 1395 | |
1396 | - $wpi_auto_reminder = false; |
|
1396 | + $wpi_auto_reminder = false; |
|
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 | |
1400 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
1400 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
1401 | 1401 | global $wpinv_email_search, $wpinv_email_replace; |
1402 | 1402 | |
1403 | 1403 | $email_type = 'overdue'; |
1404 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
1404 | + if (!wpinv_email_is_enabled($email_type)) { |
|
1405 | 1405 | return false; |
1406 | 1406 | } |
1407 | 1407 | |
1408 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1409 | - if ( empty( $invoice ) ) { |
|
1408 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1409 | + if (empty($invoice)) { |
|
1410 | 1410 | return false; |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - if ( !$invoice->needs_payment() ) { |
|
1413 | + if (!$invoice->needs_payment()) { |
|
1414 | 1414 | return false; |
1415 | 1415 | } |
1416 | 1416 | |
1417 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
1418 | - if ( !is_email( $recipient ) ) { |
|
1417 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
1418 | + if (!is_email($recipient)) { |
|
1419 | 1419 | return false; |
1420 | 1420 | } |
1421 | 1421 | |
@@ -1431,60 +1431,60 @@ discard block |
||
1431 | 1431 | $replace = array(); |
1432 | 1432 | $replace['full_name'] = $invoice->get_user_full_name(); |
1433 | 1433 | $replace['invoice_number'] = $invoice->get_number(); |
1434 | - $replace['invoice_due_date']= $invoice->get_due_date( true ); |
|
1435 | - $replace['invoice_total'] = $invoice->get_total( true ); |
|
1436 | - $replace['invoice_link'] = $invoice->get_view_url( true ); |
|
1437 | - $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true ); |
|
1438 | - $replace['is_was'] = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ); |
|
1434 | + $replace['invoice_due_date'] = $invoice->get_due_date(true); |
|
1435 | + $replace['invoice_total'] = $invoice->get_total(true); |
|
1436 | + $replace['invoice_link'] = $invoice->get_view_url(true); |
|
1437 | + $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true); |
|
1438 | + $replace['is_was'] = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'); |
|
1439 | 1439 | |
1440 | 1440 | $wpinv_email_search = $search; |
1441 | 1441 | $wpinv_email_replace = $replace; |
1442 | 1442 | |
1443 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
1444 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
1445 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
1446 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
1443 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
1444 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
1445 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
1446 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
1447 | 1447 | |
1448 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
1448 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
1449 | 1449 | |
1450 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
1450 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
1451 | 1451 | 'invoice' => $invoice, |
1452 | 1452 | 'email_type' => $email_type, |
1453 | 1453 | 'email_heading' => $email_heading, |
1454 | 1454 | 'sent_to_admin' => false, |
1455 | 1455 | 'plain_text' => false, |
1456 | 1456 | 'message_body' => $message_body |
1457 | - ) ); |
|
1457 | + )); |
|
1458 | 1458 | |
1459 | - $content = wpinv_email_format_text( $content ); |
|
1459 | + $content = wpinv_email_format_text($content); |
|
1460 | 1460 | |
1461 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
1462 | - if ( $sent ) { |
|
1463 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
1461 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
1462 | + if ($sent) { |
|
1463 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | return $sent; |
1467 | 1467 | } |
1468 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
1468 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
1469 | 1469 | |
1470 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
1470 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
1471 | 1471 | global $wpi_auto_reminder; |
1472 | 1472 | |
1473 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
1473 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
1474 | 1474 | |
1475 | - if ( empty( $sent ) ) { |
|
1475 | + if (empty($sent)) { |
|
1476 | 1476 | $sent = array(); |
1477 | 1477 | } |
1478 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
1478 | + $sent[] = date_i18n('Y-m-d'); |
|
1479 | 1479 | |
1480 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
1480 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
1481 | 1481 | |
1482 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
1483 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1484 | - $invoice->add_note( $note, false, false, true ); |
|
1482 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
1483 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1484 | + $invoice->add_note($note, false, false, true); |
|
1485 | 1485 | } else { // Menual reminder note. |
1486 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1487 | - $invoice->add_note( $note ); |
|
1486 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1487 | + $invoice->add_note($note); |
|
1488 | 1488 | } |
1489 | 1489 | } |
1490 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
1491 | 1490 | \ No newline at end of file |
1491 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
|
1492 | 1492 | \ No newline at end of file |
@@ -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 | |
@@ -14,73 +14,73 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function init() { |
17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
17 | + do_action('wpinv_class_notes_init', $this); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function includes() { |
21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
21 | + do_action('wpinv_class_notes_includes', $this); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function actions() { |
25 | 25 | // Secure inovice notes |
26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
27 | 27 | |
28 | 28 | // Count comments |
29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 ); |
|
29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); |
|
30 | 30 | |
31 | 31 | // Delete comments count cache whenever there is a new comment or a comment status changes |
32 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
33 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
32 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
33 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
34 | 34 | |
35 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
35 | + do_action('wpinv_class_notes_actions', $this); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function set_invoice_note_type( $query ) { |
|
39 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
38 | + public function set_invoice_note_type($query) { |
|
39 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
40 | 40 | |
41 | - if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) { |
|
41 | + if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) { |
|
42 | 42 | $query->query_vars['type__in'] = $this->comment_type; |
43 | 43 | $query->query_vars['type__not_in'] = ''; |
44 | 44 | } else { |
45 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
46 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
47 | - $key = array_search( $this->comment_type, $type_in ); |
|
48 | - unset( $query->query_vars['type__in'][$key] ); |
|
49 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
45 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
46 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
47 | + $key = array_search($this->comment_type, $type_in); |
|
48 | + unset($query->query_vars['type__in'][$key]); |
|
49 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
50 | 50 | $query->query_vars['type__in'] = ''; |
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
55 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
54 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
55 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
56 | 56 | $query->query_vars['type__not_in'][] = $this->comment_type; |
57 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
57 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
58 | 58 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
59 | 59 | $query->query_vars['type__not_in'][] = $this->comment_type; |
60 | 60 | } |
61 | 61 | } else { |
62 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
62 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | 66 | return $query; |
67 | 67 | } |
68 | 68 | |
69 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
69 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
70 | 70 | $args = array( |
71 | 71 | 'post_id' => $invoice_id, |
72 | 72 | 'order' => 'comment_date_gmt', |
73 | 73 | 'order' => 'DESC', |
74 | 74 | ); |
75 | 75 | |
76 | - if ( $type == 'customer' ) { |
|
76 | + if ($type == 'customer') { |
|
77 | 77 | $args['meta_key'] = '_wpi_customer_note'; |
78 | 78 | $args['meta_value'] = 1; |
79 | 79 | } |
80 | 80 | |
81 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
81 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
82 | 82 | |
83 | - return get_comments( $args ); |
|
83 | + return get_comments($args); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return void |
92 | 92 | */ |
93 | 93 | public function delete_comments_count_cache() { |
94 | - delete_transient( 'wpinv_count_comments' ); |
|
94 | + delete_transient('wpinv_count_comments'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | * @param int $post_id Post ID. |
103 | 103 | * @return object |
104 | 104 | */ |
105 | - public function wp_count_comments( $stats, $post_id ) { |
|
105 | + public function wp_count_comments($stats, $post_id) { |
|
106 | 106 | global $wpdb; |
107 | 107 | |
108 | - if ( 0 === $post_id ) { |
|
109 | - $stats = get_transient( 'wpinv_count_comments' ); |
|
108 | + if (0 === $post_id) { |
|
109 | + $stats = get_transient('wpinv_count_comments'); |
|
110 | 110 | |
111 | - if ( ! $stats ) { |
|
111 | + if (!$stats) { |
|
112 | 112 | $stats = array(); |
113 | 113 | |
114 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); |
|
114 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); |
|
115 | 115 | |
116 | 116 | $total = 0; |
117 | 117 | $approved = array( |
@@ -122,26 +122,26 @@ discard block |
||
122 | 122 | 'post-trashed' => 'post-trashed', |
123 | 123 | ); |
124 | 124 | |
125 | - foreach ( (array) $count as $row ) { |
|
125 | + foreach ((array)$count as $row) { |
|
126 | 126 | // Do not count post-trashed toward totals. |
127 | - if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { |
|
127 | + if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { |
|
128 | 128 | $total += $row['num_comments']; |
129 | 129 | } |
130 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
131 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
130 | + if (isset($approved[$row['comment_approved']])) { |
|
131 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | $stats['total_comments'] = $total; |
136 | 136 | $stats['all'] = $total; |
137 | - foreach ( $approved as $key ) { |
|
138 | - if ( empty( $stats[ $key ] ) ) { |
|
139 | - $stats[ $key ] = 0; |
|
137 | + foreach ($approved as $key) { |
|
138 | + if (empty($stats[$key])) { |
|
139 | + $stats[$key] = 0; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - $stats = (object) $stats; |
|
144 | - set_transient( 'wpinv_count_comments', $stats ); |
|
143 | + $stats = (object)$stats; |
|
144 | + set_transient('wpinv_count_comments', $stats); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 |
@@ -1,30 +1,30 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Details { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | $currency_symbol = wpinv_currency_symbol(); |
10 | 10 | $statuses = wpinv_get_invoice_statuses(); |
11 | 11 | |
12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
13 | + $invoice = new WPInv_Invoice($post_id); |
|
14 | 14 | |
15 | - $status = $invoice->get_status( false ); // Current status |
|
15 | + $status = $invoice->get_status(false); // Current status |
|
16 | 16 | $discount = $invoice->get_discount(); |
17 | 17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
18 | 18 | $invoice_number = $invoice->get_number(); |
19 | 19 | |
20 | 20 | $date_created = $invoice->get_created_date(); |
21 | - $datetime_created = strtotime( $date_created ); |
|
22 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
21 | + $datetime_created = strtotime($date_created); |
|
22 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
23 | 23 | $date_completed = $invoice->get_completed_date(); |
24 | - $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
|
25 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
26 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
27 | - $mail_notice = esc_attr__( 'After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
|
24 | + $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a'; |
|
25 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
26 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
27 | + $mail_notice = esc_attr__('After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing'); |
|
28 | 28 | |
29 | 29 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
30 | 30 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | <div class="gdmbx2-wrap form-table"> |
35 | 35 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
36 | 36 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
37 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
38 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
37 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
38 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
39 | 39 | </div> |
40 | - <?php if ( wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?> |
|
40 | + <?php if (wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?> |
|
41 | 41 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
42 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
42 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
43 | 43 | <div class="gdmbx-td"> |
44 | - <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
|
44 | + <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd"> |
|
45 | 45 | </div> |
46 | 46 | </div> |
47 | 47 | <?php } ?> |
48 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
48 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
49 | 49 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
50 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
51 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
50 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
51 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
52 | 52 | </div> |
53 | 53 | <?php } ?> |
54 | 54 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
55 | 55 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
56 | 56 | <div class="gdmbx-td"> |
57 | 57 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select"> |
58 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
59 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
58 | + <?php foreach ($statuses as $value => $label) { ?> |
|
59 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
60 | 60 | <?php } ?> |
61 | 61 | </select> |
62 | 62 | </div> |
@@ -64,107 +64,107 @@ discard block |
||
64 | 64 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
65 | 65 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
66 | 66 | <div class="gdmbx-td"> |
67 | - <input type="text" placeholder="<?php echo esc_attr( wpinv_format_invoice_number( 1 ) ); ?>" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
67 | + <input type="text" placeholder="<?php echo esc_attr(wpinv_format_invoice_number(1)); ?>" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
68 | 68 | </div> |
69 | 69 | </div> |
70 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); ?> |
|
71 | - <?php if ( !( $is_paid = $invoice->is_paid() ) || $discount_code ) { ?> |
|
70 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); ?> |
|
71 | + <?php if (!($is_paid = $invoice->is_paid()) || $discount_code) { ?> |
|
72 | 72 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
73 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
73 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
74 | 74 | <div class="gdmbx-td"> |
75 | - <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
75 | + <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
76 | 76 | </div> |
77 | 77 | </div> |
78 | 78 | <?php } ?> |
79 | 79 | </div> |
80 | 80 | </div> |
81 | 81 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
82 | - <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label> |
|
82 | + <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label> |
|
83 | 83 | <select id="wpi_save_send" name="wpi_save_send"> |
84 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
85 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
84 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
85 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
86 | 86 | </select> |
87 | 87 | </p> |
88 | 88 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
89 | 89 | </div> |
90 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
90 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
91 | 91 | <?php |
92 | 92 | } |
93 | 93 | |
94 | - public static function resend_invoice( $post ) { |
|
94 | + public static function resend_invoice($post) { |
|
95 | 95 | global $wpi_mb_invoice; |
96 | 96 | |
97 | - if ( empty( $wpi_mb_invoice ) ) { |
|
97 | + if (empty($wpi_mb_invoice)) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $text = array( |
102 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the customer’s email address.', 'invoicing' ), |
|
103 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
102 | + 'message' => esc_attr__('This will send a copy of the invoice to the customer’s email address.', 'invoicing'), |
|
103 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
104 | 104 | ); |
105 | 105 | |
106 | 106 | $text = apply_filters('wpinv_resend_invoice_metabox_text', $text); |
107 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
107 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
108 | 108 | |
109 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
109 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
110 | 110 | $email_actions = array(); |
111 | - $email_actions['email_url'] = add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ); |
|
112 | - $email_actions['reminder_url'] = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
111 | + $email_actions['email_url'] = add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)); |
|
112 | + $email_actions['reminder_url'] = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
113 | 113 | |
114 | - $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions ); |
|
114 | + $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions); |
|
115 | 115 | ?> |
116 | 116 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
117 | - <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
118 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
119 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
117 | + <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
118 | + <?php if (wpinv_get_option('overdue_active') && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
119 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
120 | 120 | <?php } ?> |
121 | 121 | <?php |
122 | 122 | } |
123 | 123 | |
124 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
124 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
125 | 125 | } |
126 | 126 | |
127 | - public static function subscriptions( $post ) { |
|
127 | + public static function subscriptions($post) { |
|
128 | 128 | global $wpi_mb_invoice; |
129 | 129 | |
130 | 130 | $invoice = $wpi_mb_invoice; |
131 | 131 | |
132 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
132 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
133 | 133 | $payments = $invoice->get_child_payments(); |
134 | 134 | |
135 | 135 | $total_payments = (int)$invoice->get_total_payments(); |
136 | 136 | $subscription = $invoice->get_subscription_data(); |
137 | 137 | |
138 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
139 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
138 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
139 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
140 | 140 | $subscription_status = $invoice->get_subscription_status(); |
141 | 141 | ?> |
142 | - <p class="wpi-meta-row wpi-sub-label"><?php _e( 'Recurring Payment', 'invoicing' );?></p> |
|
143 | - <?php if ( $subscription_id = $invoice->get_subscription_id() ) { ?> |
|
144 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $subscription_id; ?></p> |
|
142 | + <p class="wpi-meta-row wpi-sub-label"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
|
143 | + <?php if ($subscription_id = $invoice->get_subscription_id()) { ?> |
|
144 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $subscription_id; ?></p> |
|
145 | 145 | <?php } ?> |
146 | - <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e( 'Billing Cycle:', 'invoicing' );?> </label><?php echo $billing_cycle; ?></p> |
|
147 | - <p class="wpi-meta-row wpi-billed-times"><label><?php _e( 'Times Billed:', 'invoicing' );?> </label><?php echo $times_billed; ?></p> |
|
148 | - <?php if ( !empty( $payments ) || $invoice->is_paid() ) { ?> |
|
149 | - <p class="wpi-meta-row wpi-start-date"><label><?php _e( 'Start Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
150 | - <p class="wpi-meta-row wpi-end-date"><label><?php _e( 'Expiration Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
151 | - <?php if ( $status_label = $invoice->get_subscription_status_label( $subscription_status ) ) { ?> |
|
152 | - <p class="wpi-meta-row wpi-sub-status"><label><?php _e( 'Subscription Status:', 'invoicing' );?> </label><?php echo $status_label; ?></p> |
|
146 | + <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php echo $billing_cycle; ?></p> |
|
147 | + <p class="wpi-meta-row wpi-billed-times"><label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $times_billed; ?></p> |
|
148 | + <?php if (!empty($payments) || $invoice->is_paid()) { ?> |
|
149 | + <p class="wpi-meta-row wpi-start-date"><label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
150 | + <p class="wpi-meta-row wpi-end-date"><label><?php _e('Expiration Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
151 | + <?php if ($status_label = $invoice->get_subscription_status_label($subscription_status)) { ?> |
|
152 | + <p class="wpi-meta-row wpi-sub-status"><label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $status_label; ?></p> |
|
153 | 153 | <?php } ?> |
154 | - <?php if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { ?> |
|
155 | - <p class="wpi-meta-row wpi-trial-date"><label><?php _e( 'Trial Until:', 'invoicing' );?> </label><?php echo $trial_end_date; ?></p> |
|
154 | + <?php if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { ?> |
|
155 | + <p class="wpi-meta-row wpi-trial-date"><label><?php _e('Trial Until:', 'invoicing'); ?> </label><?php echo $trial_end_date; ?></p> |
|
156 | 156 | <?php } ?> |
157 | - <?php if ( $cancelled_date = $invoice->get_cancelled_date() ) { ?> |
|
158 | - <p class="wpi-meta-row wpi-cancel-date"><label><?php _e( 'Cancelled On:', 'invoicing' );?> </label><?php echo $cancelled_date; ?></p> |
|
157 | + <?php if ($cancelled_date = $invoice->get_cancelled_date()) { ?> |
|
158 | + <p class="wpi-meta-row wpi-cancel-date"><label><?php _e('Cancelled On:', 'invoicing'); ?> </label><?php echo $cancelled_date; ?></p> |
|
159 | 159 | <?php } ?> |
160 | - <?php if ( !empty( $payments ) ) { ?> |
|
161 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
160 | + <?php if (!empty($payments)) { ?> |
|
161 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
162 | 162 | <ul id="wpi-sub-payments"> |
163 | - <?php foreach ( $payments as $invoice_id ) { ?> |
|
163 | + <?php foreach ($payments as $invoice_id) { ?> |
|
164 | 164 | <li> |
165 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
166 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
167 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
165 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
166 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
167 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
168 | 168 | </li> |
169 | 169 | <?php } ?> |
170 | 170 | </ul> |
@@ -172,47 +172,47 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - public static function renewals( $post ) { |
|
175 | + public static function renewals($post) { |
|
176 | 176 | global $wpi_mb_invoice; |
177 | 177 | |
178 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
179 | - $parent_url = get_edit_post_link( $wpi_mb_invoice->parent_invoice ); |
|
180 | - $parent_id = wpinv_get_invoice_number( $wpi_mb_invoice->parent_invoice ); |
|
178 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
179 | + $parent_url = get_edit_post_link($wpi_mb_invoice->parent_invoice); |
|
180 | + $parent_id = wpinv_get_invoice_number($wpi_mb_invoice->parent_invoice); |
|
181 | 181 | ?> |
182 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
183 | - <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
|
182 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
183 | + <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p> |
|
184 | 184 | <?php |
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - public static function payment_meta( $post ) { |
|
188 | + public static function payment_meta($post) { |
|
189 | 189 | global $wpi_mb_invoice; |
190 | 190 | |
191 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
192 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() ) { |
|
191 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
192 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid()) { |
|
193 | 193 | $set_dateway = true; |
194 | 194 | } |
195 | 195 | |
196 | 196 | ?> |
197 | 197 | <p class="wpi-meta-row"> |
198 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
199 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
198 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
199 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
200 | 200 | <select required="required" id="wpinv_gateway" name="wpinv_gateway"> |
201 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
202 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
201 | + <?php foreach ($gateways as $name => $gateway) { |
|
202 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | ?> |
206 | - <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
206 | + <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
207 | 207 | <?php } ?> |
208 | 208 | </select> |
209 | 209 | <?php } else { |
210 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_checkout_label( $wpi_mb_invoice->gateway ) ); |
|
210 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_checkout_label($wpi_mb_invoice->gateway)); |
|
211 | 211 | } ?> |
212 | 212 | </p> |
213 | - <?php if ( $wpi_mb_invoice->is_paid() ) { ?> |
|
214 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $wpi_mb_invoice->get_key() ); ?></p> |
|
215 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
213 | + <?php if ($wpi_mb_invoice->is_paid()) { ?> |
|
214 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $wpi_mb_invoice->get_key()); ?></p> |
|
215 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
216 | 216 | <?php } ?> |
217 | 217 | <?php |
218 | 218 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,49 +55,49 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | 77 | //$invoice->set( 'status', 'publish' ); |
78 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
79 | - $invoice->set( 'key', $parent_invoice->get_key() ); |
|
78 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
79 | + $invoice->set('key', $parent_invoice->get_key()); |
|
80 | 80 | |
81 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
82 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
83 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
84 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
81 | + $invoice->set('ip', $parent_invoice->ip); |
|
82 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
83 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
84 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
85 | 85 | ///$invoice->set( 'email', $parent_invoice->get_email() ); |
86 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
87 | - $invoice->set( 'address', $parent_invoice->address ); |
|
88 | - $invoice->set( 'city', $parent_invoice->city ); |
|
89 | - $invoice->set( 'country', $parent_invoice->country ); |
|
90 | - $invoice->set( 'state', $parent_invoice->state ); |
|
91 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
92 | - $invoice->set( 'company', $parent_invoice->company ); |
|
93 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
94 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
95 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
96 | - |
|
97 | - if ( empty( $args['gateway'] ) ) { |
|
98 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
86 | + $invoice->set('phone', $parent_invoice->phone); |
|
87 | + $invoice->set('address', $parent_invoice->address); |
|
88 | + $invoice->set('city', $parent_invoice->city); |
|
89 | + $invoice->set('country', $parent_invoice->country); |
|
90 | + $invoice->set('state', $parent_invoice->state); |
|
91 | + $invoice->set('zip', $parent_invoice->zip); |
|
92 | + $invoice->set('company', $parent_invoice->company); |
|
93 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
94 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
95 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
96 | + |
|
97 | + if (empty($args['gateway'])) { |
|
98 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
99 | 99 | } else { |
100 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
100 | + $invoice->set('gateway', $args['gateway']); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | // increase the earnings for each item in the subscription |
106 | 106 | $items = $recurring_details['cart_details']; |
107 | 107 | |
108 | - if ( $items ) { |
|
108 | + if ($items) { |
|
109 | 109 | $add_items = array(); |
110 | 110 | $cart_details = array(); |
111 | 111 | |
112 | - foreach ( $items as $item ) { |
|
112 | + foreach ($items as $item) { |
|
113 | 113 | $add_item = array(); |
114 | 114 | $add_item['id'] = $item['id']; |
115 | 115 | $add_item['quantity'] = $item['quantity']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - $invoice->set( 'items', $add_items ); |
|
122 | + $invoice->set('items', $add_items); |
|
123 | 123 | $invoice->cart_details = $cart_details; |
124 | 124 | } |
125 | 125 | |
@@ -129,277 +129,277 @@ discard block |
||
129 | 129 | $tax = $recurring_details['tax']; |
130 | 130 | $discount = $recurring_details['discount']; |
131 | 131 | |
132 | - if ( $discount > 0 ) { |
|
133 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
132 | + if ($discount > 0) { |
|
133 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
134 | 134 | } |
135 | 135 | |
136 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
137 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
138 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
139 | - $invoice->total = wpinv_round_amount( $total ); |
|
136 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
137 | + $invoice->tax = wpinv_round_amount($tax); |
|
138 | + $invoice->discount = wpinv_round_amount($discount); |
|
139 | + $invoice->total = wpinv_round_amount($total); |
|
140 | 140 | $invoice->save(); |
141 | 141 | |
142 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
142 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
143 | 143 | sleep(1); |
144 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
144 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
145 | 145 | |
146 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
146 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
147 | 147 | |
148 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
148 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
149 | 149 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
150 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
151 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
150 | + $subscription_data['created'] = current_time('mysql', 0); |
|
151 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
152 | 152 | |
153 | 153 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
154 | - $invoice->update_subscription( $subscription_data ); |
|
154 | + $invoice->update_subscription($subscription_data); |
|
155 | 155 | |
156 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
157 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
156 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
157 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
158 | 158 | |
159 | 159 | return $invoice; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
162 | +function wpinv_payment_exists($txn_id = '') { |
|
163 | 163 | global $wpdb; |
164 | 164 | |
165 | - if ( empty( $txn_id ) ) { |
|
165 | + if (empty($txn_id)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | - $txn_id = esc_sql( $txn_id ); |
|
169 | + $txn_id = esc_sql($txn_id); |
|
170 | 170 | |
171 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
171 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
172 | 172 | |
173 | - if ( $invoice != null ) { |
|
173 | + if ($invoice != null) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
181 | - if ( empty( $invoice ) ) { |
|
180 | +function wpinv_is_subscription_payment($invoice = '') { |
|
181 | + if (empty($invoice)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
186 | - $invoice = wpinv_get_invoice( $invoice ); |
|
185 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
186 | + $invoice = wpinv_get_invoice($invoice); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( empty( $invoice ) ) { |
|
189 | + if (empty($invoice)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( $invoice->is_renewal() ) { |
|
193 | + if ($invoice->is_renewal()) { |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
201 | - if ( empty( $invoice ) ) { |
|
200 | +function wpinv_payment_subscription_data($invoice = '') { |
|
201 | + if (empty($invoice)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $invoice ); |
|
205 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
206 | + $invoice = wpinv_get_invoice($invoice); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( empty( $invoice ) ) { |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $invoice->get_subscription_data(); |
214 | 214 | } |
215 | 215 | |
216 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
217 | - if ( empty( $invoice ) ) { |
|
216 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
217 | + if (empty($invoice)) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
222 | - $invoice = wpinv_get_invoice( $invoice ); |
|
221 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
222 | + $invoice = wpinv_get_invoice($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( empty( $invoice ) ) { |
|
225 | + if (empty($invoice)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
229 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
232 | +function wpinv_get_pretty_subscription_period($period) { |
|
233 | 233 | $frequency = ''; |
234 | 234 | //Format period details |
235 | - switch ( $period ) { |
|
235 | + switch ($period) { |
|
236 | 236 | case 'D' : |
237 | 237 | case 'day' : |
238 | - $frequency = __( 'Daily', 'invoicing' ); |
|
238 | + $frequency = __('Daily', 'invoicing'); |
|
239 | 239 | break; |
240 | 240 | case 'W' : |
241 | 241 | case 'week' : |
242 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
242 | + $frequency = __('Weekly', 'invoicing'); |
|
243 | 243 | break; |
244 | 244 | case 'M' : |
245 | 245 | case 'month' : |
246 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
246 | + $frequency = __('Monthly', 'invoicing'); |
|
247 | 247 | break; |
248 | 248 | case 'Y' : |
249 | 249 | case 'year' : |
250 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
250 | + $frequency = __('Yearly', 'invoicing'); |
|
251 | 251 | break; |
252 | 252 | default : |
253 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
253 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
254 | 254 | break; |
255 | 255 | } |
256 | 256 | |
257 | 257 | return $frequency; |
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
260 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
261 | 261 | $frequency = ''; |
262 | 262 | //Format period details |
263 | - switch ( $period ) { |
|
263 | + switch ($period) { |
|
264 | 264 | case 'D' : |
265 | 265 | case 'day' : |
266 | - $frequency = __( 'Day', 'invoicing' ); |
|
266 | + $frequency = __('Day', 'invoicing'); |
|
267 | 267 | break; |
268 | 268 | case 'W' : |
269 | 269 | case 'week' : |
270 | - $frequency = __( 'Week', 'invoicing' ); |
|
270 | + $frequency = __('Week', 'invoicing'); |
|
271 | 271 | break; |
272 | 272 | case 'M' : |
273 | 273 | case 'month' : |
274 | - $frequency = __( 'Month', 'invoicing' ); |
|
274 | + $frequency = __('Month', 'invoicing'); |
|
275 | 275 | break; |
276 | 276 | case 'Y' : |
277 | 277 | case 'year' : |
278 | - $frequency = __( 'Year', 'invoicing' ); |
|
278 | + $frequency = __('Year', 'invoicing'); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
281 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
282 | 282 | break; |
283 | 283 | } |
284 | 284 | |
285 | 285 | return $frequency; |
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
288 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
289 | 289 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
290 | 290 | |
291 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
292 | - $amount = __( 'Free', 'invoicing' ); |
|
291 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
292 | + $amount = __('Free', 'invoicing'); |
|
293 | 293 | $interval = $trial_interval; |
294 | 294 | $period = $trial_period; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $description = ''; |
298 | - switch ( $period ) { |
|
298 | + switch ($period) { |
|
299 | 299 | case 'D' : |
300 | 300 | case 'day' : |
301 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
301 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
302 | 302 | break; |
303 | 303 | case 'W' : |
304 | 304 | case 'week' : |
305 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
305 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
306 | 306 | break; |
307 | 307 | case 'M' : |
308 | 308 | case 'month' : |
309 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
309 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
310 | 310 | break; |
311 | 311 | case 'Y' : |
312 | 312 | case 'year' : |
313 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
313 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
314 | 314 | break; |
315 | 315 | } |
316 | 316 | |
317 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
317 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
320 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
321 | 321 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
322 | 322 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
323 | 323 | |
324 | 324 | $description = ''; |
325 | - switch ( $period ) { |
|
325 | + switch ($period) { |
|
326 | 326 | case 'D' : |
327 | 327 | case 'day' : |
328 | - if ( (int)$bill_times > 0 ) { |
|
329 | - if ( $interval > 1 ) { |
|
330 | - if ( $bill_times > 1 ) { |
|
331 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
328 | + if ((int)$bill_times > 0) { |
|
329 | + if ($interval > 1) { |
|
330 | + if ($bill_times > 1) { |
|
331 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
332 | 332 | } else { |
333 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
333 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
336 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
339 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'W' : |
343 | 343 | case 'week' : |
344 | - if ( (int)$bill_times > 0 ) { |
|
345 | - if ( $interval > 1 ) { |
|
346 | - if ( $bill_times > 1 ) { |
|
347 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
344 | + if ((int)$bill_times > 0) { |
|
345 | + if ($interval > 1) { |
|
346 | + if ($bill_times > 1) { |
|
347 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
348 | 348 | } else { |
349 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
349 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
352 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
355 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
356 | 356 | } |
357 | 357 | break; |
358 | 358 | case 'M' : |
359 | 359 | case 'month' : |
360 | - if ( (int)$bill_times > 0 ) { |
|
361 | - if ( $interval > 1 ) { |
|
362 | - if ( $bill_times > 1 ) { |
|
363 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
360 | + if ((int)$bill_times > 0) { |
|
361 | + if ($interval > 1) { |
|
362 | + if ($bill_times > 1) { |
|
363 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
364 | 364 | } else { |
365 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
365 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
368 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
371 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
372 | 372 | } |
373 | 373 | break; |
374 | 374 | case 'Y' : |
375 | 375 | case 'year' : |
376 | - if ( (int)$bill_times > 0 ) { |
|
377 | - if ( $interval > 1 ) { |
|
378 | - if ( $bill_times > 1 ) { |
|
379 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
376 | + if ((int)$bill_times > 0) { |
|
377 | + if ($interval > 1) { |
|
378 | + if ($bill_times > 1) { |
|
379 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
380 | 380 | } else { |
381 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
381 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
384 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
385 | 385 | } |
386 | 386 | } else { |
387 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
387 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
388 | 388 | } |
389 | 389 | break; |
390 | 390 | } |
391 | 391 | |
392 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
392 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
393 | 393 | } |
394 | 394 | |
395 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
396 | - if ( empty( $invoice ) ) { |
|
395 | +function wpinv_subscription_payment_desc($invoice) { |
|
396 | + if (empty($invoice)) { |
|
397 | 397 | return NULL; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $description = ''; |
401 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
402 | - if ( $item->has_free_trial() ) { |
|
401 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
402 | + if ($item->has_free_trial()) { |
|
403 | 403 | $trial_period = $item->get_trial_period(); |
404 | 404 | $trial_interval = $item->get_trial_interval(); |
405 | 405 | } else { |
@@ -407,45 +407,45 @@ discard block |
||
407 | 407 | $trial_interval = 0; |
408 | 408 | } |
409 | 409 | |
410 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
410 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
411 | 411 | } |
412 | 412 | |
413 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
413 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
417 | - $initial_total = wpinv_round_amount( $initial ); |
|
418 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_round_amount($initial); |
|
418 | + $recurring_total = wpinv_round_amount($recurring); |
|
419 | 419 | |
420 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
420 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
421 | 421 | // Free trial |
422 | 422 | } else { |
423 | - if ( $bill_times == 1 ) { |
|
423 | + if ($bill_times == 1) { |
|
424 | 424 | $recurring_total = $initial_total; |
425 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
425 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
426 | 426 | $bill_times--; |
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
431 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
430 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
431 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
432 | 432 | |
433 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
433 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - if ( $initial_total != $recurring_total ) { |
|
436 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
435 | + if ($initial_total != $recurring_total) { |
|
436 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
437 | 437 | |
438 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
438 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
439 | 439 | } else { |
440 | 440 | $description = $recurring; |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
443 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
447 | - if ( !empty( $invoice->ID ) ) { |
|
448 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
446 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
447 | + if (!empty($invoice->ID)) { |
|
448 | + wpinv_failed_invoice_notification($invoice->ID); |
|
449 | 449 | } |
450 | 450 | } |
451 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
452 | 451 | \ No newline at end of file |
452 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
453 | 453 | \ No newline at end of file |
@@ -7,109 +7,109 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | -if ( !is_admin() ) { |
|
15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
14 | +if (!is_admin()) { |
|
15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | function wpinv_template_path() { |
22 | - return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
26 | 26 | global $pagenow, $typenow; |
27 | 27 | |
28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
29 | 29 | $classes[] = 'wpi-gd-package'; |
30 | 30 | } |
31 | 31 | return $classes; |
32 | 32 | } |
33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
34 | 34 | |
35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
36 | - if ( empty( $invoice ) ) { |
|
35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
36 | + if (empty($invoice)) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | ?> |
40 | 40 | <div class="row wpinv-top-bar no-print"> |
41 | 41 | <div class="container"> |
42 | 42 | <div class="col-xs-6"> |
43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
44 | 44 | </div> |
45 | 45 | <div class="col-xs-6 text-right"> |
46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | <?php |
51 | 51 | } |
52 | 52 | |
53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
54 | - if ( empty( $invoice ) ) { |
|
53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
54 | + if (empty($invoice)) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if($invoice->post_type == 'wpi_invoice'){ |
|
58 | + if ($invoice->post_type == 'wpi_invoice') { |
|
59 | 59 | |
60 | 60 | $user_id = (int)$invoice->get_user_id(); |
61 | 61 | $current_user_id = (int)get_current_user_id(); |
62 | 62 | |
63 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
63 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
64 | 64 | ?> |
65 | - <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
65 | + <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a> |
|
66 | 66 | <?php |
67 | 67 | } |
68 | 68 | } |
69 | 69 | do_action('wpinv_invoice_display_left_actions', $invoice); |
70 | 70 | } |
71 | 71 | |
72 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
72 | +function wpinv_invoice_display_right_actions($invoice) { |
|
73 | + if (empty($invoice)) return; //Exit if invoice is not set. |
|
74 | 74 | |
75 | - if($invoice->post_type == 'wpi_invoice'){ |
|
75 | + if ($invoice->post_type == 'wpi_invoice') { |
|
76 | 76 | $user_id = (int)$invoice->get_user_id(); |
77 | 77 | $current_user_id = (int)get_current_user_id(); |
78 | 78 | |
79 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
79 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
80 | 80 | ?> |
81 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
82 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
81 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
82 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
83 | 83 | <?php } |
84 | 84 | } |
85 | 85 | do_action('wpinv_invoice_display_right_actions', $invoice); |
86 | 86 | } |
87 | 87 | |
88 | -function wpinv_before_invoice_content( $content ) { |
|
88 | +function wpinv_before_invoice_content($content) { |
|
89 | 89 | global $post; |
90 | 90 | |
91 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
91 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
92 | 92 | ob_start(); |
93 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
93 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
94 | 94 | $content = ob_get_clean() . $content; |
95 | 95 | } |
96 | 96 | |
97 | 97 | return $content; |
98 | 98 | } |
99 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
99 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
100 | 100 | |
101 | -function wpinv_after_invoice_content( $content ) { |
|
101 | +function wpinv_after_invoice_content($content) { |
|
102 | 102 | global $post; |
103 | 103 | |
104 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
104 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
105 | 105 | ob_start(); |
106 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
106 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
107 | 107 | $content .= ob_get_clean(); |
108 | 108 | } |
109 | 109 | |
110 | 110 | return $content; |
111 | 111 | } |
112 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
112 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_templates_dir() { |
115 | 115 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -119,105 +119,105 @@ discard block |
||
119 | 119 | return WPINV_PLUGIN_URL . 'templates'; |
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
123 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
124 | - extract( $args ); |
|
122 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
123 | + if (!empty($args) && is_array($args)) { |
|
124 | + extract($args); |
|
125 | 125 | } |
126 | 126 | |
127 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
127 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
128 | 128 | // Allow 3rd party plugin filter template file from their plugin. |
129 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
129 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
130 | 130 | |
131 | - if ( ! file_exists( $located ) ) { |
|
132 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
131 | + if (!file_exists($located)) { |
|
132 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
136 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
137 | 137 | |
138 | - include( $located ); |
|
138 | + include($located); |
|
139 | 139 | |
140 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
140 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
141 | 141 | } |
142 | 142 | |
143 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
144 | 144 | ob_start(); |
145 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
145 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
146 | 146 | return ob_get_clean(); |
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
150 | - if ( ! $template_path ) { |
|
149 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
150 | + if (!$template_path) { |
|
151 | 151 | $template_path = wpinv_template_path(); |
152 | 152 | } |
153 | 153 | |
154 | - if ( ! $default_path ) { |
|
154 | + if (!$default_path) { |
|
155 | 155 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Look within passed path within the theme - this is priority. |
159 | 159 | $template = locate_template( |
160 | 160 | array( |
161 | - trailingslashit( $template_path ) . $template_name, |
|
161 | + trailingslashit($template_path) . $template_name, |
|
162 | 162 | $template_name |
163 | 163 | ) |
164 | 164 | ); |
165 | 165 | |
166 | 166 | // Get default templates/ |
167 | - if ( !$template && $default_path ) { |
|
168 | - $template = trailingslashit( $default_path ) . $template_name; |
|
167 | + if (!$template && $default_path) { |
|
168 | + $template = trailingslashit($default_path) . $template_name; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Return what we found. |
172 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
172 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
173 | 173 | } |
174 | 174 | |
175 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
176 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
175 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
176 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
177 | 177 | |
178 | 178 | // Setup possible parts |
179 | 179 | $templates = array(); |
180 | - if ( isset( $name ) ) |
|
180 | + if (isset($name)) |
|
181 | 181 | $templates[] = $slug . '-' . $name . '.php'; |
182 | 182 | $templates[] = $slug . '.php'; |
183 | 183 | |
184 | 184 | // Allow template parts to be filtered |
185 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
185 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
186 | 186 | |
187 | 187 | // Return the part that is found |
188 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
188 | + return wpinv_locate_tmpl($templates, $load, false); |
|
189 | 189 | } |
190 | 190 | |
191 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
191 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
192 | 192 | // No file found yet |
193 | 193 | $located = false; |
194 | 194 | |
195 | 195 | // Try to find a template file |
196 | - foreach ( (array)$template_names as $template_name ) { |
|
196 | + foreach ((array)$template_names as $template_name) { |
|
197 | 197 | |
198 | 198 | // Continue if template is empty |
199 | - if ( empty( $template_name ) ) |
|
199 | + if (empty($template_name)) |
|
200 | 200 | continue; |
201 | 201 | |
202 | 202 | // Trim off any slashes from the template name |
203 | - $template_name = ltrim( $template_name, '/' ); |
|
203 | + $template_name = ltrim($template_name, '/'); |
|
204 | 204 | |
205 | 205 | // try locating this template file by looping through the template paths |
206 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
206 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
207 | 207 | |
208 | - if( file_exists( $template_path . $template_name ) ) { |
|
208 | + if (file_exists($template_path . $template_name)) { |
|
209 | 209 | $located = $template_path . $template_name; |
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if( !empty( $located ) ) { |
|
214 | + if (!empty($located)) { |
|
215 | 215 | break; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
220 | - load_template( $located, $require_once ); |
|
219 | + if ((true == $load) && !empty($located)) |
|
220 | + load_template($located, $require_once); |
|
221 | 221 | |
222 | 222 | return $located; |
223 | 223 | } |
@@ -226,143 +226,143 @@ discard block |
||
226 | 226 | $template_dir = wpinv_get_theme_template_dir_name(); |
227 | 227 | |
228 | 228 | $file_paths = array( |
229 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
230 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
229 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
230 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
231 | 231 | 100 => wpinv_get_templates_dir() |
232 | 232 | ); |
233 | 233 | |
234 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
234 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
235 | 235 | |
236 | 236 | // sort the file paths based on priority |
237 | - ksort( $file_paths, SORT_NUMERIC ); |
|
237 | + ksort($file_paths, SORT_NUMERIC); |
|
238 | 238 | |
239 | - return array_map( 'trailingslashit', $file_paths ); |
|
239 | + return array_map('trailingslashit', $file_paths); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | function wpinv_get_theme_template_dir_name() { |
243 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
243 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | function wpinv_checkout_meta_tags() { |
247 | 247 | |
248 | 248 | $pages = array(); |
249 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
249 | + $pages[] = wpinv_get_option('success_page'); |
|
250 | + $pages[] = wpinv_get_option('failure_page'); |
|
251 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
252 | 252 | |
253 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | 257 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
258 | 258 | } |
259 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
259 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
260 | 260 | |
261 | -function wpinv_add_body_classes( $class ) { |
|
261 | +function wpinv_add_body_classes($class) { |
|
262 | 262 | $classes = (array)$class; |
263 | 263 | |
264 | - if( wpinv_is_checkout() ) { |
|
264 | + if (wpinv_is_checkout()) { |
|
265 | 265 | $classes[] = 'wpinv-checkout'; |
266 | 266 | $classes[] = 'wpinv-page'; |
267 | 267 | } |
268 | 268 | |
269 | - if( wpinv_is_success_page() ) { |
|
269 | + if (wpinv_is_success_page()) { |
|
270 | 270 | $classes[] = 'wpinv-success'; |
271 | 271 | $classes[] = 'wpinv-page'; |
272 | 272 | } |
273 | 273 | |
274 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | + if (wpinv_is_failed_transaction_page()) { |
|
275 | 275 | $classes[] = 'wpinv-failed-transaction'; |
276 | 276 | $classes[] = 'wpinv-page'; |
277 | 277 | } |
278 | 278 | |
279 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | + if (wpinv_is_invoice_history_page()) { |
|
280 | 280 | $classes[] = 'wpinv-history'; |
281 | 281 | $classes[] = 'wpinv-page'; |
282 | 282 | } |
283 | 283 | |
284 | - if( wpinv_is_test_mode() ) { |
|
284 | + if (wpinv_is_test_mode()) { |
|
285 | 285 | $classes[] = 'wpinv-test-mode'; |
286 | 286 | $classes[] = 'wpinv-page'; |
287 | 287 | } |
288 | 288 | |
289 | - return array_unique( $classes ); |
|
289 | + return array_unique($classes); |
|
290 | 290 | } |
291 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
291 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
292 | 292 | |
293 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
294 | - $args = array( 'nopaging' => true ); |
|
293 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
294 | + $args = array('nopaging' => true); |
|
295 | 295 | |
296 | - if ( ! empty( $status ) ) |
|
296 | + if (!empty($status)) |
|
297 | 297 | $args['post_status'] = $status; |
298 | 298 | |
299 | - $discounts = wpinv_get_discounts( $args ); |
|
299 | + $discounts = wpinv_get_discounts($args); |
|
300 | 300 | $options = array(); |
301 | 301 | |
302 | - if ( $discounts ) { |
|
303 | - foreach ( $discounts as $discount ) { |
|
304 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
302 | + if ($discounts) { |
|
303 | + foreach ($discounts as $discount) { |
|
304 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
305 | 305 | } |
306 | 306 | } else { |
307 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
307 | + $options[0] = __('No discounts found', 'invoicing'); |
|
308 | 308 | } |
309 | 309 | |
310 | - $output = wpinv_html_select( array( |
|
310 | + $output = wpinv_html_select(array( |
|
311 | 311 | 'name' => $name, |
312 | 312 | 'selected' => $selected, |
313 | 313 | 'options' => $options, |
314 | 314 | 'show_option_all' => false, |
315 | 315 | 'show_option_none' => false, |
316 | - ) ); |
|
316 | + )); |
|
317 | 317 | |
318 | 318 | return $output; |
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
322 | - $current = date( 'Y' ); |
|
323 | - $start_year = $current - absint( $years_before ); |
|
324 | - $end_year = $current + absint( $years_after ); |
|
325 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
321 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
322 | + $current = date('Y'); |
|
323 | + $start_year = $current - absint($years_before); |
|
324 | + $end_year = $current + absint($years_after); |
|
325 | + $selected = empty($selected) ? date('Y') : $selected; |
|
326 | 326 | $options = array(); |
327 | 327 | |
328 | - while ( $start_year <= $end_year ) { |
|
329 | - $options[ absint( $start_year ) ] = $start_year; |
|
328 | + while ($start_year <= $end_year) { |
|
329 | + $options[absint($start_year)] = $start_year; |
|
330 | 330 | $start_year++; |
331 | 331 | } |
332 | 332 | |
333 | - $output = wpinv_html_select( array( |
|
333 | + $output = wpinv_html_select(array( |
|
334 | 334 | 'name' => $name, |
335 | 335 | 'selected' => $selected, |
336 | 336 | 'options' => $options, |
337 | 337 | 'show_option_all' => false, |
338 | 338 | 'show_option_none' => false |
339 | - ) ); |
|
339 | + )); |
|
340 | 340 | |
341 | 341 | return $output; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
344 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
345 | 345 | $month = 1; |
346 | 346 | $options = array(); |
347 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
347 | + $selected = empty($selected) ? date('n') : $selected; |
|
348 | 348 | |
349 | - while ( $month <= 12 ) { |
|
350 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
349 | + while ($month <= 12) { |
|
350 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
351 | 351 | $month++; |
352 | 352 | } |
353 | 353 | |
354 | - $output = wpinv_html_select( array( |
|
354 | + $output = wpinv_html_select(array( |
|
355 | 355 | 'name' => $name, |
356 | 356 | 'selected' => $selected, |
357 | 357 | 'options' => $options, |
358 | 358 | 'show_option_all' => false, |
359 | 359 | 'show_option_none' => false |
360 | - ) ); |
|
360 | + )); |
|
361 | 361 | |
362 | 362 | return $output; |
363 | 363 | } |
364 | 364 | |
365 | -function wpinv_html_select( $args = array() ) { |
|
365 | +function wpinv_html_select($args = array()) { |
|
366 | 366 | $defaults = array( |
367 | 367 | 'options' => array(), |
368 | 368 | 'name' => null, |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | 'chosen' => false, |
373 | 373 | 'placeholder' => null, |
374 | 374 | 'multiple' => false, |
375 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
376 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
375 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
376 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
377 | 377 | 'data' => array(), |
378 | 378 | 'onchange' => null, |
379 | 379 | 'required' => false, |
@@ -381,78 +381,78 @@ discard block |
||
381 | 381 | 'readonly' => false, |
382 | 382 | ); |
383 | 383 | |
384 | - $args = wp_parse_args( $args, $defaults ); |
|
384 | + $args = wp_parse_args($args, $defaults); |
|
385 | 385 | |
386 | 386 | $data_elements = ''; |
387 | - foreach ( $args['data'] as $key => $value ) { |
|
388 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
387 | + foreach ($args['data'] as $key => $value) { |
|
388 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
389 | 389 | } |
390 | 390 | |
391 | - if( $args['multiple'] ) { |
|
391 | + if ($args['multiple']) { |
|
392 | 392 | $multiple = ' MULTIPLE'; |
393 | 393 | } else { |
394 | 394 | $multiple = ''; |
395 | 395 | } |
396 | 396 | |
397 | - if( $args['chosen'] ) { |
|
397 | + if ($args['chosen']) { |
|
398 | 398 | $args['class'] .= ' wpinv-select-chosen'; |
399 | 399 | } |
400 | 400 | |
401 | - if( $args['placeholder'] ) { |
|
401 | + if ($args['placeholder']) { |
|
402 | 402 | $placeholder = $args['placeholder']; |
403 | 403 | } else { |
404 | 404 | $placeholder = ''; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $options = ''; |
408 | - if( !empty( $args['onchange'] ) ) { |
|
409 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
408 | + if (!empty($args['onchange'])) { |
|
409 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
410 | 410 | } |
411 | 411 | |
412 | - if( !empty( $args['required'] ) ) { |
|
412 | + if (!empty($args['required'])) { |
|
413 | 413 | $options .= ' required="required"'; |
414 | 414 | } |
415 | 415 | |
416 | - if( !empty( $args['disabled'] ) ) { |
|
416 | + if (!empty($args['disabled'])) { |
|
417 | 417 | $options .= ' disabled'; |
418 | 418 | } |
419 | 419 | |
420 | - if( !empty( $args['readonly'] ) ) { |
|
420 | + if (!empty($args['readonly'])) { |
|
421 | 421 | $options .= ' readonly'; |
422 | 422 | } |
423 | 423 | |
424 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
425 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
424 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
425 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
426 | 426 | |
427 | - if ( $args['show_option_all'] ) { |
|
428 | - if( $args['multiple'] ) { |
|
429 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
427 | + if ($args['show_option_all']) { |
|
428 | + if ($args['multiple']) { |
|
429 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
430 | 430 | } else { |
431 | - $selected = selected( $args['selected'], 0, false ); |
|
431 | + $selected = selected($args['selected'], 0, false); |
|
432 | 432 | } |
433 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
433 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
434 | 434 | } |
435 | 435 | |
436 | - if ( !empty( $args['options'] ) ) { |
|
436 | + if (!empty($args['options'])) { |
|
437 | 437 | |
438 | - if ( $args['show_option_none'] ) { |
|
439 | - if( $args['multiple'] ) { |
|
440 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
438 | + if ($args['show_option_none']) { |
|
439 | + if ($args['multiple']) { |
|
440 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
441 | 441 | } else { |
442 | - $selected = selected( $args['selected'] === "", true, false ); |
|
442 | + $selected = selected($args['selected'] === "", true, false); |
|
443 | 443 | } |
444 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
444 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
445 | 445 | } |
446 | 446 | |
447 | - foreach( $args['options'] as $key => $option ) { |
|
447 | + foreach ($args['options'] as $key => $option) { |
|
448 | 448 | |
449 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
450 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
449 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
450 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
451 | 451 | } else { |
452 | - $selected = selected( $args['selected'], $key, false ); |
|
452 | + $selected = selected($args['selected'], $key, false); |
|
453 | 453 | } |
454 | 454 | |
455 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
455 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | return $output; |
462 | 462 | } |
463 | 463 | |
464 | -function wpinv_item_dropdown( $args = array() ) { |
|
464 | +function wpinv_item_dropdown($args = array()) { |
|
465 | 465 | $defaults = array( |
466 | 466 | 'name' => 'wpi_item', |
467 | 467 | 'id' => 'wpi_item', |
@@ -470,15 +470,15 @@ discard block |
||
470 | 470 | 'selected' => 0, |
471 | 471 | 'chosen' => false, |
472 | 472 | 'number' => 100, |
473 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
474 | - 'data' => array( 'search-type' => 'item' ), |
|
473 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
474 | + 'data' => array('search-type' => 'item'), |
|
475 | 475 | 'show_option_all' => false, |
476 | 476 | 'show_option_none' => false, |
477 | 477 | 'with_packages' => true, |
478 | 478 | 'show_recurring' => false, |
479 | 479 | ); |
480 | 480 | |
481 | - $args = wp_parse_args( $args, $defaults ); |
|
481 | + $args = wp_parse_args($args, $defaults); |
|
482 | 482 | |
483 | 483 | $item_args = array( |
484 | 484 | 'post_type' => 'wpi_item', |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | 'posts_per_page' => $args['number'] |
488 | 488 | ); |
489 | 489 | |
490 | - if ( !$args['with_packages'] ) { |
|
490 | + if (!$args['with_packages']) { |
|
491 | 491 | $item_args['meta_query'] = array( |
492 | 492 | array( |
493 | 493 | 'key' => '_wpinv_type', |
@@ -497,42 +497,42 @@ discard block |
||
497 | 497 | ); |
498 | 498 | } |
499 | 499 | |
500 | - $items = get_posts( $item_args ); |
|
500 | + $items = get_posts($item_args); |
|
501 | 501 | $options = array(); |
502 | - if ( $items ) { |
|
503 | - foreach ( $items as $item ) { |
|
504 | - $title = esc_html( $item->post_title ); |
|
502 | + if ($items) { |
|
503 | + foreach ($items as $item) { |
|
504 | + $title = esc_html($item->post_title); |
|
505 | 505 | |
506 | - if ( !empty( $args['show_recurring'] ) ) { |
|
507 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
506 | + if (!empty($args['show_recurring'])) { |
|
507 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
508 | 508 | } |
509 | 509 | |
510 | - $options[ absint( $item->ID ) ] = $title; |
|
510 | + $options[absint($item->ID)] = $title; |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | 514 | // This ensures that any selected items are included in the drop down |
515 | - if( is_array( $args['selected'] ) ) { |
|
516 | - foreach( $args['selected'] as $item ) { |
|
517 | - if( ! in_array( $item, $options ) ) { |
|
518 | - $title = get_the_title( $item ); |
|
519 | - if ( !empty( $args['show_recurring'] ) ) { |
|
520 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
515 | + if (is_array($args['selected'])) { |
|
516 | + foreach ($args['selected'] as $item) { |
|
517 | + if (!in_array($item, $options)) { |
|
518 | + $title = get_the_title($item); |
|
519 | + if (!empty($args['show_recurring'])) { |
|
520 | + $title .= wpinv_get_item_suffix($item, false); |
|
521 | 521 | } |
522 | 522 | $options[$item] = $title; |
523 | 523 | } |
524 | 524 | } |
525 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
526 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
527 | - $title = get_the_title( $args['selected'] ); |
|
528 | - if ( !empty( $args['show_recurring'] ) ) { |
|
529 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
525 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
526 | + if (!in_array($args['selected'], $options)) { |
|
527 | + $title = get_the_title($args['selected']); |
|
528 | + if (!empty($args['show_recurring'])) { |
|
529 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
530 | 530 | } |
531 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
531 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | - $output = wpinv_html_select( array( |
|
535 | + $output = wpinv_html_select(array( |
|
536 | 536 | 'name' => $args['name'], |
537 | 537 | 'selected' => $args['selected'], |
538 | 538 | 'id' => $args['id'], |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | 'show_option_all' => $args['show_option_all'], |
545 | 545 | 'show_option_none' => $args['show_option_none'], |
546 | 546 | 'data' => $args['data'], |
547 | - ) ); |
|
547 | + )); |
|
548 | 548 | |
549 | 549 | return $output; |
550 | 550 | } |
551 | 551 | |
552 | -function wpinv_html_checkbox( $args = array() ) { |
|
552 | +function wpinv_html_checkbox($args = array()) { |
|
553 | 553 | $defaults = array( |
554 | 554 | 'name' => null, |
555 | 555 | 'current' => null, |
@@ -560,38 +560,38 @@ discard block |
||
560 | 560 | ) |
561 | 561 | ); |
562 | 562 | |
563 | - $args = wp_parse_args( $args, $defaults ); |
|
563 | + $args = wp_parse_args($args, $defaults); |
|
564 | 564 | |
565 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
565 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
566 | 566 | $options = ''; |
567 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
567 | + if (!empty($args['options']['disabled'])) { |
|
568 | 568 | $options .= ' disabled="disabled"'; |
569 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
569 | + } elseif (!empty($args['options']['readonly'])) { |
|
570 | 570 | $options .= ' readonly'; |
571 | 571 | } |
572 | 572 | |
573 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
573 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
574 | 574 | |
575 | 575 | return $output; |
576 | 576 | } |
577 | 577 | |
578 | -function wpinv_html_text( $args = array() ) { |
|
578 | +function wpinv_html_text($args = array()) { |
|
579 | 579 | // Backwards compatibility |
580 | - if ( func_num_args() > 1 ) { |
|
580 | + if (func_num_args() > 1) { |
|
581 | 581 | $args = func_get_args(); |
582 | 582 | |
583 | 583 | $name = $args[0]; |
584 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
585 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
586 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
584 | + $value = isset($args[1]) ? $args[1] : ''; |
|
585 | + $label = isset($args[2]) ? $args[2] : ''; |
|
586 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | $defaults = array( |
590 | 590 | 'id' => '', |
591 | - 'name' => isset( $name ) ? $name : 'text', |
|
592 | - 'value' => isset( $value ) ? $value : null, |
|
593 | - 'label' => isset( $label ) ? $label : null, |
|
594 | - 'desc' => isset( $desc ) ? $desc : null, |
|
591 | + 'name' => isset($name) ? $name : 'text', |
|
592 | + 'value' => isset($value) ? $value : null, |
|
593 | + 'label' => isset($label) ? $label : null, |
|
594 | + 'desc' => isset($desc) ? $desc : null, |
|
595 | 595 | 'placeholder' => '', |
596 | 596 | 'class' => 'regular-text', |
597 | 597 | 'disabled' => false, |
@@ -601,51 +601,51 @@ discard block |
||
601 | 601 | 'data' => false |
602 | 602 | ); |
603 | 603 | |
604 | - $args = wp_parse_args( $args, $defaults ); |
|
604 | + $args = wp_parse_args($args, $defaults); |
|
605 | 605 | |
606 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
606 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
607 | 607 | $options = ''; |
608 | - if( $args['required'] ) { |
|
608 | + if ($args['required']) { |
|
609 | 609 | $options .= ' required="required"'; |
610 | 610 | } |
611 | - if( $args['readonly'] ) { |
|
611 | + if ($args['readonly']) { |
|
612 | 612 | $options .= ' readonly'; |
613 | 613 | } |
614 | - if( $args['readonly'] ) { |
|
614 | + if ($args['readonly']) { |
|
615 | 615 | $options .= ' readonly'; |
616 | 616 | } |
617 | 617 | |
618 | 618 | $data = ''; |
619 | - if ( !empty( $args['data'] ) ) { |
|
620 | - foreach ( $args['data'] as $key => $value ) { |
|
621 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
619 | + if (!empty($args['data'])) { |
|
620 | + foreach ($args['data'] as $key => $value) { |
|
621 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
625 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
626 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
627 | - if ( ! empty( $args['desc'] ) ) { |
|
628 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
625 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
626 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
627 | + if (!empty($args['desc'])) { |
|
628 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
629 | 629 | } |
630 | 630 | |
631 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
631 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
632 | 632 | |
633 | 633 | $output .= '</span>'; |
634 | 634 | |
635 | 635 | return $output; |
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_html_date_field( $args = array() ) { |
|
639 | - if( empty( $args['class'] ) ) { |
|
638 | +function wpinv_html_date_field($args = array()) { |
|
639 | + if (empty($args['class'])) { |
|
640 | 640 | $args['class'] = 'wpiDatepicker'; |
641 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
641 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
642 | 642 | $args['class'] .= ' wpiDatepicker'; |
643 | 643 | } |
644 | 644 | |
645 | - return wpinv_html_text( $args ); |
|
645 | + return wpinv_html_text($args); |
|
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_html_textarea( $args = array() ) { |
|
648 | +function wpinv_html_textarea($args = array()) { |
|
649 | 649 | $defaults = array( |
650 | 650 | 'name' => 'textarea', |
651 | 651 | 'value' => null, |
@@ -655,31 +655,31 @@ discard block |
||
655 | 655 | 'disabled' => false |
656 | 656 | ); |
657 | 657 | |
658 | - $args = wp_parse_args( $args, $defaults ); |
|
658 | + $args = wp_parse_args($args, $defaults); |
|
659 | 659 | |
660 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
660 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
661 | 661 | $disabled = ''; |
662 | - if( $args['disabled'] ) { |
|
662 | + if ($args['disabled']) { |
|
663 | 663 | $disabled = ' disabled="disabled"'; |
664 | 664 | } |
665 | 665 | |
666 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
667 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
668 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
666 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
667 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
668 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
669 | 669 | |
670 | - if ( ! empty( $args['desc'] ) ) { |
|
671 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
670 | + if (!empty($args['desc'])) { |
|
671 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
672 | 672 | } |
673 | 673 | $output .= '</span>'; |
674 | 674 | |
675 | 675 | return $output; |
676 | 676 | } |
677 | 677 | |
678 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
678 | +function wpinv_html_ajax_user_search($args = array()) { |
|
679 | 679 | $defaults = array( |
680 | 680 | 'name' => 'user_id', |
681 | 681 | 'value' => null, |
682 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
682 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
683 | 683 | 'label' => null, |
684 | 684 | 'desc' => null, |
685 | 685 | 'class' => '', |
@@ -688,13 +688,13 @@ discard block |
||
688 | 688 | 'data' => false |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | 693 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
694 | 694 | |
695 | 695 | $output = '<span class="wpinv_user_search_wrap">'; |
696 | - $output .= wpinv_html_text( $args ); |
|
697 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
696 | + $output .= wpinv_html_text($args); |
|
697 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
698 | 698 | $output .= '</span>'; |
699 | 699 | |
700 | 700 | return $output; |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | function wpinv_ip_geolocation() { |
704 | 704 | global $wpinv_euvat; |
705 | 705 | |
706 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
706 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
707 | 707 | $content = ''; |
708 | 708 | $iso = ''; |
709 | 709 | $country = ''; |
@@ -714,69 +714,69 @@ discard block |
||
714 | 714 | $credit = ''; |
715 | 715 | $address = ''; |
716 | 716 | |
717 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
717 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
718 | 718 | try { |
719 | 719 | $iso = $geoip2_city->country->isoCode; |
720 | 720 | $country = $geoip2_city->country->name; |
721 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
721 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
722 | 722 | $city = $geoip2_city->city->name; |
723 | 723 | $longitude = $geoip2_city->location->longitude; |
724 | 724 | $latitude = $geoip2_city->location->latitude; |
725 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
726 | - } catch( Exception $e ) { } |
|
725 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
726 | + } catch (Exception $e) { } |
|
727 | 727 | } |
728 | 728 | |
729 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
729 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
730 | 730 | try { |
731 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
731 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
732 | 732 | |
733 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
733 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
734 | 734 | $iso = $load_xml->geoplugin_countryCode; |
735 | 735 | $country = $load_xml->geoplugin_countryName; |
736 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
737 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
736 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
737 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
738 | 738 | $longitude = $load_xml->geoplugin_longitude; |
739 | 739 | $latitude = $load_xml->geoplugin_latitude; |
740 | 740 | $credit = $load_xml->geoplugin_credit; |
741 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
741 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
742 | 742 | } |
743 | - } catch( Exception $e ) { } |
|
743 | + } catch (Exception $e) { } |
|
744 | 744 | } |
745 | 745 | |
746 | - if ( $iso && $longitude && $latitude ) { |
|
747 | - if ( $city ) { |
|
746 | + if ($iso && $longitude && $latitude) { |
|
747 | + if ($city) { |
|
748 | 748 | $address .= $city . ', '; |
749 | 749 | } |
750 | 750 | |
751 | - if ( $region ) { |
|
751 | + if ($region) { |
|
752 | 752 | $address .= $region . ', '; |
753 | 753 | } |
754 | 754 | |
755 | 755 | $address .= $country . ' (' . $iso . ')'; |
756 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
757 | - $content .= '<p>'. $credit . '</p>'; |
|
756 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
757 | + $content .= '<p>' . $credit . '</p>'; |
|
758 | 758 | } else { |
759 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
759 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
760 | 760 | } |
761 | 761 | ?> |
762 | 762 | <!DOCTYPE html> |
763 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
763 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
764 | 764 | <body> |
765 | - <?php if ( $latitude && $latitude ) { ?> |
|
765 | + <?php if ($latitude && $latitude) { ?> |
|
766 | 766 | <div id="map"></div> |
767 | 767 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
768 | 768 | <script type="text/javascript"> |
769 | 769 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
770 | 770 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
771 | 771 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
772 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
772 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
773 | 773 | |
774 | 774 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
775 | 775 | |
776 | 776 | var marker = new L.Marker(latlng); |
777 | 777 | map.addLayer(marker); |
778 | 778 | |
779 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
779 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
780 | 780 | </script> |
781 | 781 | <?php } ?> |
782 | 782 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -784,31 +784,31 @@ discard block |
||
784 | 784 | <?php |
785 | 785 | exit; |
786 | 786 | } |
787 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
788 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
787 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
788 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
789 | 789 | |
790 | 790 | // Set up the template for the invoice. |
791 | -function wpinv_template( $template ) { |
|
791 | +function wpinv_template($template) { |
|
792 | 792 | global $post, $wp_query; |
793 | 793 | |
794 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
795 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
796 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
794 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
795 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
796 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
797 | 797 | } else { |
798 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
798 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
799 | 799 | $user_id = $invoice->get_user_id(); |
800 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
800 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
801 | 801 | |
802 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
803 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
802 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
803 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
804 | 804 | |
805 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
805 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
806 | 806 | wpinv_die(); |
807 | 807 | } |
808 | 808 | } |
809 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
809 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
810 | 810 | |
811 | - wp_redirect( $redirect_to ); |
|
811 | + wp_redirect($redirect_to); |
|
812 | 812 | wpinv_die(); |
813 | 813 | } |
814 | 814 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | |
819 | 819 | function wpinv_get_business_address() { |
820 | 820 | $business_address = wpinv_store_address(); |
821 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
821 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
822 | 822 | |
823 | 823 | /* |
824 | 824 | $default_country = wpinv_get_default_country(); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
844 | 844 | |
845 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
845 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | function wpinv_display_from_address() { |
@@ -852,185 +852,185 @@ discard block |
||
852 | 852 | if (empty($from_name)) { |
853 | 853 | $from_name = wpinv_get_business_name(); |
854 | 854 | } |
855 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
855 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
856 | 856 | <div class="wrapper col-xs-10"> |
857 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
858 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
859 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
857 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
858 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
859 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
860 | 860 | <?php } ?> |
861 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
862 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
861 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
862 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
863 | 863 | <?php } ?> |
864 | 864 | </div> |
865 | 865 | <?php |
866 | 866 | } |
867 | 867 | |
868 | -function wpinv_watermark( $id = 0 ) { |
|
869 | - $output = wpinv_get_watermark( $id ); |
|
868 | +function wpinv_watermark($id = 0) { |
|
869 | + $output = wpinv_get_watermark($id); |
|
870 | 870 | |
871 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
871 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
872 | 872 | } |
873 | 873 | |
874 | -function wpinv_get_watermark( $id ) { |
|
875 | - if ( !$id > 0 ) { |
|
874 | +function wpinv_get_watermark($id) { |
|
875 | + if (!$id > 0) { |
|
876 | 876 | return NULL; |
877 | 877 | } |
878 | - $invoice = wpinv_get_invoice( $id ); |
|
878 | + $invoice = wpinv_get_invoice($id); |
|
879 | 879 | |
880 | - if ( !empty( $invoice ) ) { |
|
881 | - if ( $invoice->is_paid() ) { |
|
882 | - return __( 'Paid', 'invoicing' ); |
|
880 | + if (!empty($invoice)) { |
|
881 | + if ($invoice->is_paid()) { |
|
882 | + return __('Paid', 'invoicing'); |
|
883 | 883 | } |
884 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
885 | - return __( 'Cancelled', 'invoicing' ); |
|
884 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
885 | + return __('Cancelled', 'invoicing'); |
|
886 | 886 | } |
887 | 887 | } |
888 | 888 | |
889 | 889 | return NULL; |
890 | 890 | } |
891 | 891 | |
892 | -function wpinv_display_invoice_details( $invoice ) { |
|
892 | +function wpinv_display_invoice_details($invoice) { |
|
893 | 893 | global $wpinv_euvat; |
894 | 894 | |
895 | 895 | $invoice_id = $invoice->ID; |
896 | 896 | $vat_name = $wpinv_euvat->get_vat_name(); |
897 | 897 | $use_taxes = wpinv_use_taxes(); |
898 | 898 | |
899 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
899 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
900 | 900 | |
901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
901 | + if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | + elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
903 | 903 | ?> |
904 | 904 | <table class="table table-bordered table-sm"> |
905 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
905 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
906 | 906 | <tr class="wpi-row-number"> |
907 | - <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th> |
|
908 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
907 | + <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th> |
|
908 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
909 | 909 | </tr> |
910 | 910 | <?php } ?> |
911 | 911 | <tr class="wpi-row-status"> |
912 | - <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th> |
|
913 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
912 | + <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th> |
|
913 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
914 | 914 | </tr> |
915 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
915 | + <?php if ($invoice->is_renewal()) { ?> |
|
916 | 916 | <tr class="wpi-row-parent"> |
917 | - <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th> |
|
918 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
917 | + <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th> |
|
918 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
919 | 919 | </tr> |
920 | 920 | <?php } ?> |
921 | 921 | <tr class="wpi-row-gateway"> |
922 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
923 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
922 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
923 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
924 | 924 | </tr> |
925 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
925 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
926 | 926 | <tr class="wpi-row-date"> |
927 | - <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th> |
|
927 | + <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th> |
|
928 | 928 | <td><?php echo $invoice_date; ?></td> |
929 | 929 | </tr> |
930 | 930 | <?php } ?> |
931 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
931 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
932 | 932 | <tr class="wpi-row-date"> |
933 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
933 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
934 | 934 | <td><?php echo $due_date; ?></td> |
935 | 935 | </tr> |
936 | 936 | <?php } ?> |
937 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
937 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
938 | 938 | <tr class="wpi-row-ovatno"> |
939 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
939 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
940 | 940 | <td><?php echo $owner_vat_number; ?></td> |
941 | 941 | </tr> |
942 | 942 | <?php } ?> |
943 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
943 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
944 | 944 | <tr class="wpi-row-uvatno"> |
945 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
945 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
946 | 946 | <td><?php echo $user_vat_number; ?></td> |
947 | 947 | </tr> |
948 | 948 | <?php } ?> |
949 | 949 | <tr class="table-active tr-total wpi-row-total"> |
950 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
951 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
950 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
951 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
952 | 952 | </tr> |
953 | 953 | </table> |
954 | 954 | <?php |
955 | 955 | } |
956 | 956 | |
957 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
958 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
957 | +function wpinv_display_to_address($invoice_id = 0) { |
|
958 | + $invoice = wpinv_get_invoice($invoice_id); |
|
959 | 959 | |
960 | - if ( empty( $invoice ) ) { |
|
960 | + if (empty($invoice)) { |
|
961 | 961 | return NULL; |
962 | 962 | } |
963 | 963 | |
964 | 964 | $billing_details = $invoice->get_user_info(); |
965 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
965 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
966 | 966 | $output .= '<div class="wrapper col-xs-10">'; |
967 | 967 | |
968 | 968 | ob_start(); |
969 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
969 | + do_action('wpinv_display_to_address_top', $invoice); |
|
970 | 970 | $output .= ob_get_clean(); |
971 | 971 | |
972 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
973 | - if ( $company = $billing_details['company'] ) { |
|
974 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
972 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
973 | + if ($company = $billing_details['company']) { |
|
974 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
975 | 975 | } |
976 | 976 | $address_row = ''; |
977 | - if ( $address = $billing_details['address'] ) { |
|
978 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
977 | + if ($address = $billing_details['address']) { |
|
978 | + $address_row .= wpautop(wp_kses_post($address)); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | $address_fields = array(); |
982 | - if ( !empty( $billing_details['city'] ) ) { |
|
982 | + if (!empty($billing_details['city'])) { |
|
983 | 983 | $address_fields[] = $billing_details['city']; |
984 | 984 | } |
985 | 985 | |
986 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
987 | - if ( !empty( $billing_details['state'] ) ) { |
|
988 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
986 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
987 | + if (!empty($billing_details['state'])) { |
|
988 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
989 | 989 | } |
990 | 990 | |
991 | - if ( !empty( $billing_country ) ) { |
|
992 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
991 | + if (!empty($billing_country)) { |
|
992 | + $address_fields[] = wpinv_country_name($billing_country); |
|
993 | 993 | } |
994 | 994 | |
995 | - if ( !empty( $address_fields ) ) { |
|
996 | - $address_fields = implode( ", ", $address_fields ); |
|
995 | + if (!empty($address_fields)) { |
|
996 | + $address_fields = implode(", ", $address_fields); |
|
997 | 997 | |
998 | - if ( !empty( $billing_details['zip'] ) ) { |
|
998 | + if (!empty($billing_details['zip'])) { |
|
999 | 999 | $address_fields .= ' ' . $billing_details['zip']; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1002 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if ( $address_row ) { |
|
1005 | + if ($address_row) { |
|
1006 | 1006 | $output .= '<div class="address">' . $address_row . '</div>'; |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if ( $phone = $invoice->get_phone() ) { |
|
1010 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
1009 | + if ($phone = $invoice->get_phone()) { |
|
1010 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
1011 | 1011 | } |
1012 | - if ( $email = $invoice->get_email() ) { |
|
1013 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
1012 | + if ($email = $invoice->get_email()) { |
|
1013 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | ob_start(); |
1017 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1017 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
1018 | 1018 | $output .= ob_get_clean(); |
1019 | 1019 | |
1020 | 1020 | $output .= '</div>'; |
1021 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1021 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
1022 | 1022 | |
1023 | 1023 | echo $output; |
1024 | 1024 | } |
1025 | 1025 | |
1026 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1026 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1027 | 1027 | global $wpinv_euvat, $ajax_cart_details; |
1028 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1028 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1029 | 1029 | $quantities_enabled = wpinv_item_quantities_enabled(); |
1030 | 1030 | $use_taxes = wpinv_use_taxes(); |
1031 | 1031 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
1032 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1033 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1032 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
1033 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
1034 | 1034 | |
1035 | 1035 | $cart_details = $invoice->get_cart_details(); |
1036 | 1036 | $ajax_cart_details = $cart_details; |
@@ -1039,68 +1039,68 @@ discard block |
||
1039 | 1039 | <table class="table table-sm table-bordered table-responsive"> |
1040 | 1040 | <thead> |
1041 | 1041 | <tr> |
1042 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1043 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1042 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1043 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1044 | 1044 | <?php if ($quantities_enabled) { ?> |
1045 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1045 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1046 | 1046 | <?php } ?> |
1047 | 1047 | <?php if ($use_taxes && !$zero_tax) { ?> |
1048 | 1048 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1049 | 1049 | <?php } ?> |
1050 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1050 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1051 | 1051 | </tr> |
1052 | 1052 | </thead> |
1053 | 1053 | <tbody> |
1054 | 1054 | <?php |
1055 | - if ( !empty( $cart_details ) ) { |
|
1056 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1055 | + if (!empty($cart_details)) { |
|
1056 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1057 | 1057 | |
1058 | 1058 | $count = 0; |
1059 | 1059 | $cols = 3; |
1060 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1061 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1062 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
1063 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
1064 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1060 | + foreach ($cart_details as $key => $cart_item) { |
|
1061 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1062 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
1063 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
1064 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1065 | 1065 | |
1066 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1066 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1067 | 1067 | $summary = ''; |
1068 | 1068 | $cols = 3; |
1069 | - if ( !empty($item) ) { |
|
1069 | + if (!empty($item)) { |
|
1070 | 1070 | $item_name = $item->get_name(); |
1071 | 1071 | $summary = $item->get_summary(); |
1072 | 1072 | } |
1073 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1073 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1074 | 1074 | |
1075 | 1075 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1076 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1077 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link ); |
|
1076 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1077 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link); |
|
1078 | 1078 | } |
1079 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1079 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1080 | 1080 | |
1081 | 1081 | $item_tax = ''; |
1082 | 1082 | $tax_rate = ''; |
1083 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1084 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1085 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1086 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 2 ) : ''; |
|
1083 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1084 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1085 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1086 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 2) : ''; |
|
1087 | 1087 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | $line_item_tax = $item_tax . $tax_rate; |
1091 | 1091 | |
1092 | - if ( $line_item_tax === '' ) { |
|
1092 | + if ($line_item_tax === '') { |
|
1093 | 1093 | $line_item_tax = 0; // Zero tax |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1097 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1098 | - if ( $summary !== '' ) { |
|
1099 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1096 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1097 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1098 | + if ($summary !== '') { |
|
1099 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1100 | 1100 | } |
1101 | 1101 | $line_item .= '</td>'; |
1102 | 1102 | |
1103 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
1103 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
1104 | 1104 | if ($quantities_enabled) { |
1105 | 1105 | $cols++; |
1106 | 1106 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1109,55 +1109,55 @@ discard block |
||
1109 | 1109 | $cols++; |
1110 | 1110 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1111 | 1111 | } |
1112 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
1112 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
1113 | 1113 | $line_item .= '</tr>'; |
1114 | 1114 | |
1115 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1115 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1116 | 1116 | |
1117 | 1117 | $count++; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1120 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1121 | 1121 | ?> |
1122 | 1122 | <tr class="row-sub-total row_odd"> |
1123 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1124 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1123 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1124 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1125 | 1125 | </tr> |
1126 | 1126 | <?php |
1127 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1127 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1128 | 1128 | |
1129 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1130 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1129 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1130 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1131 | 1131 | ?> |
1132 | 1132 | <tr class="row-discount"> |
1133 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1134 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1133 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1134 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1135 | 1135 | </tr> |
1136 | 1136 | <?php |
1137 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1137 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | - if ( $use_taxes ) { |
|
1141 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1140 | + if ($use_taxes) { |
|
1141 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1142 | 1142 | ?> |
1143 | 1143 | <tr class="row-tax"> |
1144 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1145 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1144 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1145 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1146 | 1146 | </tr> |
1147 | 1147 | <?php |
1148 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1148 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1151 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1152 | 1152 | ?> |
1153 | 1153 | <tr class="table-active row-total"> |
1154 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1155 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1154 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1155 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1156 | 1156 | </tr> |
1157 | 1157 | <?php |
1158 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1158 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1159 | 1159 | |
1160 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1160 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1161 | 1161 | } |
1162 | 1162 | ?> |
1163 | 1163 | </tbody> |
@@ -1166,35 +1166,35 @@ discard block |
||
1166 | 1166 | echo ob_get_clean(); |
1167 | 1167 | } |
1168 | 1168 | |
1169 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1169 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1170 | 1170 | $use_taxes = wpinv_use_taxes(); |
1171 | 1171 | |
1172 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1172 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1173 | 1173 | ?> |
1174 | 1174 | <table class="table table-sm table-bordered table-responsive"> |
1175 | 1175 | <tbody> |
1176 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1176 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1177 | 1177 | <tr class="row-sub-total"> |
1178 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1179 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1178 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1179 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1180 | 1180 | </tr> |
1181 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1182 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1181 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1182 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1183 | 1183 | <tr class="row-discount"> |
1184 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1185 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1184 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1185 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1186 | 1186 | </tr> |
1187 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1187 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1188 | 1188 | <?php } ?> |
1189 | - <?php if ( $use_taxes ) { ?> |
|
1189 | + <?php if ($use_taxes) { ?> |
|
1190 | 1190 | <tr class="row-tax"> |
1191 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1192 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1191 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1192 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1193 | 1193 | </tr> |
1194 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1194 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1195 | 1195 | <?php } ?> |
1196 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1197 | - <?php foreach ( $fees as $fee ) { ?> |
|
1196 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1197 | + <?php foreach ($fees as $fee) { ?> |
|
1198 | 1198 | <tr class="row-fee"> |
1199 | 1199 | <td class="rate"><?php echo $fee['label']; ?></td> |
1200 | 1200 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1202,72 +1202,72 @@ discard block |
||
1202 | 1202 | <?php } ?> |
1203 | 1203 | <?php } ?> |
1204 | 1204 | <tr class="table-active row-total"> |
1205 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1206 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1205 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1206 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1207 | 1207 | </tr> |
1208 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1208 | + <?php do_action('wpinv_after_totals'); ?> |
|
1209 | 1209 | </tbody> |
1210 | 1210 | |
1211 | 1211 | </table> |
1212 | 1212 | |
1213 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1213 | + <?php do_action('wpinv_after_totals_table'); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1217 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1216 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1217 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1218 | 1218 | |
1219 | 1219 | ob_start(); |
1220 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1221 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
1220 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1221 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
1222 | 1222 | ?> |
1223 | 1223 | <div class="wpi-payment-info"> |
1224 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1225 | - <?php if ( $gateway_title ) { ?> |
|
1226 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1224 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1225 | + <?php if ($gateway_title) { ?> |
|
1226 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1227 | 1227 | <?php } ?> |
1228 | 1228 | </div> |
1229 | 1229 | <?php |
1230 | 1230 | } |
1231 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1231 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1232 | 1232 | $outout = ob_get_clean(); |
1233 | 1233 | |
1234 | - if ( $echo ) { |
|
1234 | + if ($echo) { |
|
1235 | 1235 | echo $outout; |
1236 | 1236 | } else { |
1237 | 1237 | return $outout; |
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | -function wpinv_display_style( $invoice ) { |
|
1242 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1241 | +function wpinv_display_style($invoice) { |
|
1242 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1243 | 1243 | |
1244 | - wp_print_styles( 'open-sans' ); |
|
1245 | - wp_print_styles( 'wpinv-single-style' ); |
|
1244 | + wp_print_styles('open-sans'); |
|
1245 | + wp_print_styles('wpinv-single-style'); |
|
1246 | 1246 | } |
1247 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1247 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1248 | 1248 | |
1249 | 1249 | function wpinv_checkout_billing_details() { |
1250 | 1250 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1251 | 1251 | if (empty($invoice_id)) { |
1252 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1252 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1253 | 1253 | return null; |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1256 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1257 | 1257 | if (empty($invoice)) { |
1258 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1258 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1259 | 1259 | return null; |
1260 | 1260 | } |
1261 | 1261 | $user_id = $invoice->get_user_id(); |
1262 | 1262 | $user_info = $invoice->get_user_info(); |
1263 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1263 | + $address_info = wpinv_get_user_address($user_id); |
|
1264 | 1264 | |
1265 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1265 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1266 | 1266 | $user_info['first_name'] = $user_info['first_name']; |
1267 | 1267 | $user_info['last_name'] = $user_info['last_name']; |
1268 | 1268 | } |
1269 | 1269 | |
1270 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1270 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1271 | 1271 | $user_info['country'] = $address_info['country']; |
1272 | 1272 | $user_info['state'] = $address_info['state']; |
1273 | 1273 | $user_info['city'] = $address_info['city']; |
@@ -1283,103 +1283,103 @@ discard block |
||
1283 | 1283 | 'address' |
1284 | 1284 | ); |
1285 | 1285 | |
1286 | - foreach ( $address_fields as $field ) { |
|
1287 | - if ( empty( $user_info[$field] ) ) { |
|
1286 | + foreach ($address_fields as $field) { |
|
1287 | + if (empty($user_info[$field])) { |
|
1288 | 1288 | $user_info[$field] = $address_info[$field]; |
1289 | 1289 | } |
1290 | 1290 | } |
1291 | 1291 | |
1292 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1292 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | function wpinv_admin_get_line_items($invoice = array()) { |
1296 | 1296 | $item_quantities = wpinv_item_quantities_enabled(); |
1297 | 1297 | $use_taxes = wpinv_use_taxes(); |
1298 | 1298 | |
1299 | - if ( empty( $invoice ) ) { |
|
1299 | + if (empty($invoice)) { |
|
1300 | 1300 | return NULL; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | $cart_items = $invoice->get_cart_details(); |
1304 | - if ( empty( $cart_items ) ) { |
|
1304 | + if (empty($cart_items)) { |
|
1305 | 1305 | return NULL; |
1306 | 1306 | } |
1307 | 1307 | ob_start(); |
1308 | 1308 | |
1309 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1309 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1310 | 1310 | |
1311 | 1311 | $count = 0; |
1312 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1312 | + foreach ($cart_items as $key => $cart_item) { |
|
1313 | 1313 | $item_id = $cart_item['id']; |
1314 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1314 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1315 | 1315 | |
1316 | 1316 | if (empty($wpi_item)) { |
1317 | 1317 | continue; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
1321 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
1320 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
1321 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
1323 | 1323 | $can_remove = true; |
1324 | 1324 | |
1325 | 1325 | $summary = ''; |
1326 | 1326 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1327 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1328 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link ); |
|
1327 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1328 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link); |
|
1329 | 1329 | } |
1330 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
1330 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
1331 | 1331 | |
1332 | 1332 | $item_tax = ''; |
1333 | 1333 | $tax_rate = ''; |
1334 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1335 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1336 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1337 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate ) : ''; |
|
1334 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1335 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1336 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1337 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate) : ''; |
|
1338 | 1338 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1339 | 1339 | } |
1340 | 1340 | $line_item_tax = $item_tax . $tax_rate; |
1341 | 1341 | |
1342 | - if ( $line_item_tax === '' ) { |
|
1342 | + if ($line_item_tax === '') { |
|
1343 | 1343 | $line_item_tax = 0; // Zero tax |
1344 | 1344 | } |
1345 | 1345 | |
1346 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1346 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1347 | 1347 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1348 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1349 | - if ( $summary !== '' ) { |
|
1350 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1348 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
1349 | + if ($summary !== '') { |
|
1350 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1351 | 1351 | } |
1352 | 1352 | $line_item .= '</td>'; |
1353 | 1353 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1354 | 1354 | |
1355 | - if ( $item_quantities ) { |
|
1356 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1355 | + if ($item_quantities) { |
|
1356 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1357 | 1357 | $can_remove = false; |
1358 | 1358 | } |
1359 | 1359 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1360 | 1360 | } else { |
1361 | - if ( count( $cart_items ) == 1 ) { |
|
1361 | + if (count($cart_items) == 1) { |
|
1362 | 1362 | $can_remove = false; |
1363 | 1363 | } |
1364 | 1364 | } |
1365 | 1365 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1366 | 1366 | |
1367 | - if ( $use_taxes ) { |
|
1367 | + if ($use_taxes) { |
|
1368 | 1368 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1369 | 1369 | } |
1370 | 1370 | $line_item .= '<td class="action">'; |
1371 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
1371 | + if (!$invoice->is_paid() && $can_remove) { |
|
1372 | 1372 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1373 | 1373 | } |
1374 | 1374 | $line_item .= '</td>'; |
1375 | 1375 | $line_item .= '</tr>'; |
1376 | 1376 | |
1377 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1377 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1378 | 1378 | |
1379 | 1379 | $count++; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1382 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1383 | 1383 | |
1384 | 1384 | return ob_get_clean(); |
1385 | 1385 | } |
@@ -1390,35 +1390,35 @@ discard block |
||
1390 | 1390 | // Set current invoice id. |
1391 | 1391 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1392 | 1392 | |
1393 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1393 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1394 | 1394 | |
1395 | 1395 | ob_start(); |
1396 | 1396 | echo '<div id="wpinv_checkout_wrap">'; |
1397 | 1397 | |
1398 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1398 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
1399 | 1399 | ?> |
1400 | 1400 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
1401 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1401 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
1402 | 1402 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
1403 | 1403 | <?php |
1404 | - do_action( 'wpinv_checkout_form_top' ); |
|
1405 | - do_action( 'wpinv_checkout_billing_info' ); |
|
1406 | - do_action( 'wpinv_checkout_cart' ); |
|
1407 | - do_action( 'wpinv_payment_mode_select' ); |
|
1408 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
1404 | + do_action('wpinv_checkout_form_top'); |
|
1405 | + do_action('wpinv_checkout_billing_info'); |
|
1406 | + do_action('wpinv_checkout_cart'); |
|
1407 | + do_action('wpinv_payment_mode_select'); |
|
1408 | + do_action('wpinv_checkout_form_bottom') |
|
1409 | 1409 | ?> |
1410 | 1410 | </form> |
1411 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1411 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
1412 | 1412 | </div><!--end #wpinv_checkout_form_wrap--> |
1413 | 1413 | <?php |
1414 | 1414 | } else { |
1415 | - do_action( 'wpinv_cart_empty' ); |
|
1415 | + do_action('wpinv_cart_empty'); |
|
1416 | 1416 | } |
1417 | 1417 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1418 | 1418 | return ob_get_clean(); |
1419 | 1419 | } |
1420 | 1420 | |
1421 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1421 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1422 | 1422 | global $ajax_cart_details; |
1423 | 1423 | $ajax_cart_details = $cart_details; |
1424 | 1424 | /* |
@@ -1433,25 +1433,25 @@ discard block |
||
1433 | 1433 | } |
1434 | 1434 | */ |
1435 | 1435 | ob_start(); |
1436 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1436 | + do_action('wpinv_before_checkout_cart'); |
|
1437 | 1437 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1438 | 1438 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1439 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1439 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1440 | 1440 | echo '</div>'; |
1441 | 1441 | echo '</div>'; |
1442 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1442 | + do_action('wpinv_after_checkout_cart'); |
|
1443 | 1443 | $content = ob_get_clean(); |
1444 | 1444 | |
1445 | - if ( $echo ) { |
|
1445 | + if ($echo) { |
|
1446 | 1446 | echo $content; |
1447 | 1447 | } else { |
1448 | 1448 | return $content; |
1449 | 1449 | } |
1450 | 1450 | } |
1451 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1451 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1452 | 1452 | |
1453 | 1453 | function wpinv_empty_cart_message() { |
1454 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1454 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1455 | 1455 | } |
1456 | 1456 | |
1457 | 1457 | /** |
@@ -1463,91 +1463,91 @@ discard block |
||
1463 | 1463 | function wpinv_empty_checkout_cart() { |
1464 | 1464 | echo wpinv_empty_cart_message(); |
1465 | 1465 | } |
1466 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1466 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1467 | 1467 | |
1468 | 1468 | function wpinv_save_cart_button() { |
1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1469 | + if (wpinv_is_cart_saving_disabled()) |
|
1470 | 1470 | return; |
1471 | 1471 | ?> |
1472 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1472 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
1473 | 1473 | <?php |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | function wpinv_update_cart_button() { |
1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
1477 | + if (!wpinv_item_quantities_enabled()) |
|
1478 | 1478 | return; |
1479 | 1479 | ?> |
1480 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1480 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1481 | 1481 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1482 | 1482 | <?php |
1483 | 1483 | } |
1484 | 1484 | |
1485 | 1485 | function wpinv_checkout_cart_columns() { |
1486 | 1486 | $default = 3; |
1487 | - if ( wpinv_item_quantities_enabled() ) { |
|
1487 | + if (wpinv_item_quantities_enabled()) { |
|
1488 | 1488 | $default++; |
1489 | 1489 | } |
1490 | 1490 | |
1491 | - if ( wpinv_use_taxes() ) { |
|
1491 | + if (wpinv_use_taxes()) { |
|
1492 | 1492 | $default++; |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1495 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1496 | 1496 | } |
1497 | 1497 | |
1498 | 1498 | function wpinv_display_cart_messages() { |
1499 | 1499 | global $wpi_session; |
1500 | 1500 | |
1501 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1501 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1502 | 1502 | |
1503 | - if ( $messages ) { |
|
1504 | - foreach ( $messages as $message_id => $message ) { |
|
1503 | + if ($messages) { |
|
1504 | + foreach ($messages as $message_id => $message) { |
|
1505 | 1505 | // Try and detect what type of message this is |
1506 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1506 | + if (strpos(strtolower($message), 'error')) { |
|
1507 | 1507 | $type = 'error'; |
1508 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1508 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1509 | 1509 | $type = 'success'; |
1510 | 1510 | } else { |
1511 | 1511 | $type = 'info'; |
1512 | 1512 | } |
1513 | 1513 | |
1514 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1514 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1515 | 1515 | |
1516 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1516 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1517 | 1517 | // Loop message codes and display messages |
1518 | 1518 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1519 | 1519 | echo '</div>'; |
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | // Remove all of the cart saving messages |
1523 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1523 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1524 | 1524 | } |
1525 | 1525 | } |
1526 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1526 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1527 | 1527 | |
1528 | 1528 | function wpinv_discount_field() { |
1529 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1529 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1530 | 1530 | return; // Only show before a payment method has been selected if ajax is disabled |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - if ( !wpinv_is_checkout() ) { |
|
1533 | + if (!wpinv_is_checkout()) { |
|
1534 | 1534 | return; |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1537 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1538 | 1538 | ?> |
1539 | 1539 | <div id="wpinv-discount-field" class="panel panel-default"> |
1540 | 1540 | <div class="panel-body"> |
1541 | 1541 | <p> |
1542 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1543 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1542 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1543 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1544 | 1544 | </p> |
1545 | 1545 | <div class="form-group row"> |
1546 | 1546 | <div class="col-sm-4"> |
1547 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1547 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1548 | 1548 | </div> |
1549 | 1549 | <div class="col-sm-3"> |
1550 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1550 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1551 | 1551 | </div> |
1552 | 1552 | <div class="col-sm-12 wpinv-discount-msg"> |
1553 | 1553 | <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div> |
@@ -1559,10 +1559,10 @@ discard block |
||
1559 | 1559 | <?php |
1560 | 1560 | } |
1561 | 1561 | } |
1562 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1562 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1563 | 1563 | |
1564 | 1564 | function wpinv_agree_to_terms_js() { |
1565 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1565 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1566 | 1566 | ?> |
1567 | 1567 | <script type="text/javascript"> |
1568 | 1568 | jQuery(document).ready(function($){ |
@@ -1577,125 +1577,125 @@ discard block |
||
1577 | 1577 | <?php |
1578 | 1578 | } |
1579 | 1579 | } |
1580 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1580 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1581 | 1581 | |
1582 | 1582 | function wpinv_payment_mode_select() { |
1583 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1584 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1583 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1584 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1585 | 1585 | $page_URL = wpinv_get_current_page_url(); |
1586 | - $invoice = wpinv_get_invoice( 0, true ); |
|
1586 | + $invoice = wpinv_get_invoice(0, true); |
|
1587 | 1587 | |
1588 | 1588 | do_action('wpinv_payment_mode_top'); |
1589 | 1589 | $invoice_id = (int)$invoice->ID; |
1590 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1590 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1591 | 1591 | ?> |
1592 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>> |
|
1593 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1592 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>> |
|
1593 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1594 | 1594 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1595 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1595 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
1596 | 1596 | <div class="panel-body list-group wpi-payment_methods"> |
1597 | 1597 | <?php |
1598 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1598 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1599 | 1599 | |
1600 | - if(!empty($gateways)){ |
|
1601 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1602 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1603 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1604 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1600 | + if (!empty($gateways)) { |
|
1601 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1602 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1603 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1604 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1605 | 1605 | ?> |
1606 | 1606 | <div class="list-group-item"> |
1607 | 1607 | <div class="radio"> |
1608 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
1608 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
1609 | 1609 | </div> |
1610 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1611 | - <?php if ( !empty( $description ) ) { ?> |
|
1612 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1610 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1611 | + <?php if (!empty($description)) { ?> |
|
1612 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
1613 | 1613 | <?php } ?> |
1614 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1614 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1615 | 1615 | </div> |
1616 | 1616 | </div> |
1617 | 1617 | <?php |
1618 | 1618 | } |
1619 | - }else{ |
|
1620 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
1619 | + } else { |
|
1620 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1621 | 1621 | } |
1622 | 1622 | |
1623 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1623 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1624 | 1624 | ?> |
1625 | 1625 | </div> |
1626 | 1626 | </div> |
1627 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1627 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1628 | 1628 | </div> |
1629 | 1629 | <?php |
1630 | 1630 | do_action('wpinv_payment_mode_bottom'); |
1631 | 1631 | } |
1632 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1632 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1633 | 1633 | |
1634 | 1634 | function wpinv_checkout_billing_info() { |
1635 | - if ( wpinv_is_checkout() ) { |
|
1635 | + if (wpinv_is_checkout()) { |
|
1636 | 1636 | $logged_in = is_user_logged_in(); |
1637 | 1637 | $billing_details = wpinv_checkout_billing_details(); |
1638 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1638 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1639 | 1639 | ?> |
1640 | 1640 | <div id="wpinv-fields" class="clearfix"> |
1641 | 1641 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1642 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1642 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1643 | 1643 | <div id="wpinv-fields-box" class="panel-body"> |
1644 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1644 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1645 | 1645 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1646 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1646 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1647 | 1647 | <?php |
1648 | - echo wpinv_html_text( array( |
|
1648 | + echo wpinv_html_text(array( |
|
1649 | 1649 | 'id' => 'wpinv_first_name', |
1650 | 1650 | 'name' => 'wpinv_first_name', |
1651 | 1651 | 'value' => $billing_details['first_name'], |
1652 | 1652 | 'class' => 'wpi-input form-control required', |
1653 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1653 | + 'placeholder' => __('First name', 'invoicing'), |
|
1654 | 1654 | 'required' => true, |
1655 | - ) ); |
|
1655 | + )); |
|
1656 | 1656 | ?> |
1657 | 1657 | </p> |
1658 | 1658 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1659 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label> |
|
1659 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label> |
|
1660 | 1660 | <?php |
1661 | - echo wpinv_html_text( array( |
|
1661 | + echo wpinv_html_text(array( |
|
1662 | 1662 | 'id' => 'wpinv_last_name', |
1663 | 1663 | 'name' => 'wpinv_last_name', |
1664 | 1664 | 'value' => $billing_details['last_name'], |
1665 | 1665 | 'class' => 'wpi-input form-control', |
1666 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1667 | - ) ); |
|
1666 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1667 | + )); |
|
1668 | 1668 | ?> |
1669 | 1669 | </p> |
1670 | 1670 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1671 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1671 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1672 | 1672 | <?php |
1673 | - echo wpinv_html_text( array( |
|
1673 | + echo wpinv_html_text(array( |
|
1674 | 1674 | 'id' => 'wpinv_address', |
1675 | 1675 | 'name' => 'wpinv_address', |
1676 | 1676 | 'value' => $billing_details['address'], |
1677 | 1677 | 'class' => 'wpi-input form-control required', |
1678 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1678 | + 'placeholder' => __('Address', 'invoicing'), |
|
1679 | 1679 | 'required' => true, |
1680 | - ) ); |
|
1680 | + )); |
|
1681 | 1681 | ?> |
1682 | 1682 | </p> |
1683 | 1683 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1684 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1684 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1685 | 1685 | <?php |
1686 | - echo wpinv_html_text( array( |
|
1686 | + echo wpinv_html_text(array( |
|
1687 | 1687 | 'id' => 'wpinv_city', |
1688 | 1688 | 'name' => 'wpinv_city', |
1689 | 1689 | 'value' => $billing_details['city'], |
1690 | 1690 | 'class' => 'wpi-input form-control required', |
1691 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1691 | + 'placeholder' => __('City', 'invoicing'), |
|
1692 | 1692 | 'required' => true, |
1693 | - ) ); |
|
1693 | + )); |
|
1694 | 1694 | ?> |
1695 | 1695 | </p> |
1696 | 1696 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1697 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1698 | - <?php echo wpinv_html_select( array( |
|
1697 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1698 | + <?php echo wpinv_html_select(array( |
|
1699 | 1699 | 'options' => wpinv_get_country_list(), |
1700 | 1700 | 'name' => 'wpinv_country', |
1701 | 1701 | 'id' => 'wpinv_country', |
@@ -1703,16 +1703,16 @@ discard block |
||
1703 | 1703 | 'show_option_all' => false, |
1704 | 1704 | 'show_option_none' => false, |
1705 | 1705 | 'class' => 'wpi-input form-control required', |
1706 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1706 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1707 | 1707 | 'required' => true, |
1708 | - ) ); ?> |
|
1708 | + )); ?> |
|
1709 | 1709 | </p> |
1710 | 1710 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1711 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1711 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1712 | 1712 | <?php |
1713 | - $states = wpinv_get_country_states( $selected_country ); |
|
1714 | - if( !empty( $states ) ) { |
|
1715 | - echo wpinv_html_select( array( |
|
1713 | + $states = wpinv_get_country_states($selected_country); |
|
1714 | + if (!empty($states)) { |
|
1715 | + echo wpinv_html_select(array( |
|
1716 | 1716 | 'options' => $states, |
1717 | 1717 | 'name' => 'wpinv_state', |
1718 | 1718 | 'id' => 'wpinv_state', |
@@ -1720,60 +1720,60 @@ discard block |
||
1720 | 1720 | 'show_option_all' => false, |
1721 | 1721 | 'show_option_none' => false, |
1722 | 1722 | 'class' => 'wpi-input form-control required', |
1723 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1723 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1724 | 1724 | 'required' => true, |
1725 | - ) ); |
|
1725 | + )); |
|
1726 | 1726 | } else { |
1727 | - echo wpinv_html_text( array( |
|
1727 | + echo wpinv_html_text(array( |
|
1728 | 1728 | 'name' => 'wpinv_state', |
1729 | 1729 | 'value' => $billing_details['state'], |
1730 | 1730 | 'id' => 'wpinv_state', |
1731 | 1731 | 'class' => 'wpi-input form-control required', |
1732 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1732 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1733 | 1733 | 'required' => true, |
1734 | - ) ); |
|
1734 | + )); |
|
1735 | 1735 | } |
1736 | 1736 | ?> |
1737 | 1737 | </p> |
1738 | 1738 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1739 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label> |
|
1739 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label> |
|
1740 | 1740 | <?php |
1741 | - echo wpinv_html_text( array( |
|
1741 | + echo wpinv_html_text(array( |
|
1742 | 1742 | 'name' => 'wpinv_zip', |
1743 | 1743 | 'value' => $billing_details['zip'], |
1744 | 1744 | 'id' => 'wpinv_zip', |
1745 | 1745 | 'class' => 'wpi-input form-control', |
1746 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1747 | - ) ); |
|
1746 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1747 | + )); |
|
1748 | 1748 | ?> |
1749 | 1749 | </p> |
1750 | 1750 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1751 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1751 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1752 | 1752 | <?php |
1753 | - echo wpinv_html_text( array( |
|
1753 | + echo wpinv_html_text(array( |
|
1754 | 1754 | 'id' => 'wpinv_phone', |
1755 | 1755 | 'name' => 'wpinv_phone', |
1756 | 1756 | 'value' => $billing_details['phone'], |
1757 | 1757 | 'class' => 'wpi-input form-control', |
1758 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1759 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1760 | - ) ); |
|
1758 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1759 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
1760 | + )); |
|
1761 | 1761 | ?> |
1762 | 1762 | </p> |
1763 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1763 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1764 | 1764 | <div class="clearfix"></div> |
1765 | 1765 | </div> |
1766 | 1766 | </div> |
1767 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1767 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1768 | 1768 | </div> |
1769 | 1769 | <?php |
1770 | 1770 | } |
1771 | 1771 | } |
1772 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1772 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1773 | 1773 | |
1774 | 1774 | function wpinv_checkout_hidden_fields() { |
1775 | 1775 | ?> |
1776 | - <?php if ( is_user_logged_in() ) { ?> |
|
1776 | + <?php if (is_user_logged_in()) { ?> |
|
1777 | 1777 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1778 | 1778 | <?php } ?> |
1779 | 1779 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1783,9 +1783,9 @@ discard block |
||
1783 | 1783 | function wpinv_checkout_button_purchase() { |
1784 | 1784 | ob_start(); |
1785 | 1785 | ?> |
1786 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1786 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
1787 | 1787 | <?php |
1788 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1788 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1789 | 1789 | } |
1790 | 1790 | |
1791 | 1791 | function wpinv_checkout_total() { |
@@ -1794,96 +1794,96 @@ discard block |
||
1794 | 1794 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1795 | 1795 | <div class="panel-body"> |
1796 | 1796 | <?php |
1797 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1797 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1798 | 1798 | ?> |
1799 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1799 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1800 | 1800 | <?php |
1801 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1801 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1802 | 1802 | ?> |
1803 | 1803 | </div> |
1804 | 1804 | </div> |
1805 | 1805 | <?php |
1806 | 1806 | } |
1807 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1807 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1808 | 1808 | |
1809 | 1809 | function wpinv_checkout_submit() { |
1810 | 1810 | ?> |
1811 | 1811 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1812 | 1812 | <div class="panel-body text-center"> |
1813 | 1813 | <?php |
1814 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1814 | + do_action('wpinv_purchase_form_before_submit'); |
|
1815 | 1815 | wpinv_checkout_hidden_fields(); |
1816 | 1816 | echo wpinv_checkout_button_purchase(); |
1817 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1817 | + do_action('wpinv_purchase_form_after_submit'); |
|
1818 | 1818 | ?> |
1819 | 1819 | </div> |
1820 | 1820 | </div> |
1821 | 1821 | <?php |
1822 | 1822 | } |
1823 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1823 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1824 | 1824 | |
1825 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1826 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1825 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1826 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1827 | 1827 | |
1828 | - if ( empty( $invoice ) ) { |
|
1828 | + if (empty($invoice)) { |
|
1829 | 1829 | return NULL; |
1830 | 1830 | } |
1831 | 1831 | |
1832 | 1832 | $billing_details = $invoice->get_user_info(); |
1833 | 1833 | $address_row = ''; |
1834 | - if ( $address = $billing_details['address'] ) { |
|
1835 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
1834 | + if ($address = $billing_details['address']) { |
|
1835 | + $address_row .= wpautop(wp_kses_post($address)); |
|
1836 | 1836 | } |
1837 | 1837 | |
1838 | 1838 | $address_fields = array(); |
1839 | - if ( !empty( $billing_details['city'] ) ) { |
|
1839 | + if (!empty($billing_details['city'])) { |
|
1840 | 1840 | $address_fields[] = $billing_details['city']; |
1841 | 1841 | } |
1842 | 1842 | |
1843 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1844 | - if ( !empty( $billing_details['state'] ) ) { |
|
1845 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1843 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
1844 | + if (!empty($billing_details['state'])) { |
|
1845 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
1846 | 1846 | } |
1847 | 1847 | |
1848 | - if ( !empty( $billing_country ) ) { |
|
1849 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
1848 | + if (!empty($billing_country)) { |
|
1849 | + $address_fields[] = wpinv_country_name($billing_country); |
|
1850 | 1850 | } |
1851 | 1851 | |
1852 | - if ( !empty( $address_fields ) ) { |
|
1853 | - $address_fields = implode( ", ", $address_fields ); |
|
1852 | + if (!empty($address_fields)) { |
|
1853 | + $address_fields = implode(", ", $address_fields); |
|
1854 | 1854 | |
1855 | - if ( !empty( $billing_details['zip'] ) ) { |
|
1855 | + if (!empty($billing_details['zip'])) { |
|
1856 | 1856 | $address_fields .= ' ' . $billing_details['zip']; |
1857 | 1857 | } |
1858 | 1858 | |
1859 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1859 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1860 | 1860 | } |
1861 | 1861 | ob_start(); |
1862 | 1862 | ?> |
1863 | 1863 | <table class="table table-bordered table-sm wpi-billing-details"> |
1864 | 1864 | <tbody> |
1865 | 1865 | <tr class="wpi-receipt-name"> |
1866 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1867 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1866 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1867 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1868 | 1868 | </tr> |
1869 | 1869 | <tr class="wpi-receipt-email"> |
1870 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1871 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1870 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1871 | + <td><?php echo $billing_details['email']; ?></td> |
|
1872 | 1872 | </tr> |
1873 | - <?php if ( $billing_details['company'] ) { ?> |
|
1873 | + <?php if ($billing_details['company']) { ?> |
|
1874 | 1874 | <tr class="wpi-receipt-company"> |
1875 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1876 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1875 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
1876 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
1877 | 1877 | </tr> |
1878 | 1878 | <?php } ?> |
1879 | 1879 | <tr class="wpi-receipt-address"> |
1880 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1881 | - <td><?php echo $address_row ;?></td> |
|
1880 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1881 | + <td><?php echo $address_row; ?></td> |
|
1882 | 1882 | </tr> |
1883 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1883 | + <?php if ($billing_details['phone']) { ?> |
|
1884 | 1884 | <tr class="wpi-receipt-phone"> |
1885 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1886 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1885 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1886 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1887 | 1887 | </tr> |
1888 | 1888 | <?php } ?> |
1889 | 1889 | </tbody> |
@@ -1891,98 +1891,98 @@ discard block |
||
1891 | 1891 | <?php |
1892 | 1892 | $output = ob_get_clean(); |
1893 | 1893 | |
1894 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1894 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1895 | 1895 | |
1896 | 1896 | echo $output; |
1897 | 1897 | } |
1898 | 1898 | |
1899 | -function wpinv_filter_success_page_content( $content ) { |
|
1900 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1901 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1902 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1899 | +function wpinv_filter_success_page_content($content) { |
|
1900 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1901 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1902 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1903 | 1903 | } |
1904 | 1904 | } |
1905 | 1905 | |
1906 | 1906 | return $content; |
1907 | 1907 | } |
1908 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1908 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1909 | 1909 | |
1910 | -function wpinv_receipt_actions( $invoice ) { |
|
1911 | - if ( !empty( $invoice ) ) { |
|
1910 | +function wpinv_receipt_actions($invoice) { |
|
1911 | + if (!empty($invoice)) { |
|
1912 | 1912 | $actions = array( |
1913 | 1913 | 'print' => array( |
1914 | 1914 | 'url' => $invoice->get_view_url(), |
1915 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1915 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1916 | 1916 | 'class' => 'btn-primary', |
1917 | 1917 | ), |
1918 | 1918 | 'history' => array( |
1919 | 1919 | 'url' => wpinv_get_history_page_uri(), |
1920 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1920 | + 'name' => __('Invoice History', 'invoicing'), |
|
1921 | 1921 | 'class' => 'btn-warning', |
1922 | 1922 | ) |
1923 | 1923 | ); |
1924 | 1924 | |
1925 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1925 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1926 | 1926 | |
1927 | - if ( !empty( $actions ) ) { |
|
1927 | + if (!empty($actions)) { |
|
1928 | 1928 | ?> |
1929 | 1929 | <div class="wpinv-receipt-actions text-right"> |
1930 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1931 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1930 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1931 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
1932 | 1932 | <?php } ?> |
1933 | 1933 | </div> |
1934 | 1934 | <?php |
1935 | 1935 | } |
1936 | 1936 | } |
1937 | 1937 | } |
1938 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1938 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1939 | 1939 | |
1940 | -function wpinv_invoice_link( $invoice_id ) { |
|
1941 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1940 | +function wpinv_invoice_link($invoice_id) { |
|
1941 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1942 | 1942 | |
1943 | - if ( empty( $invoice ) ) { |
|
1943 | + if (empty($invoice)) { |
|
1944 | 1944 | return NULL; |
1945 | 1945 | } |
1946 | 1946 | |
1947 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1947 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1948 | 1948 | |
1949 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1949 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1950 | 1950 | } |
1951 | 1951 | |
1952 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1953 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1952 | +function wpinv_invoice_subscription_details($invoice) { |
|
1953 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1954 | 1954 | $total_payments = (int)$invoice->get_total_payments(); |
1955 | 1955 | $payments = $invoice->get_child_payments(); |
1956 | 1956 | |
1957 | 1957 | $subscription = $invoice->get_subscription_data(); |
1958 | 1958 | |
1959 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
1959 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
1960 | 1960 | return; |
1961 | 1961 | } |
1962 | 1962 | |
1963 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
1964 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
1963 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
1964 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
1965 | 1965 | |
1966 | 1966 | $subscription_status = $invoice->get_subscription_status(); |
1967 | 1967 | |
1968 | 1968 | $status_desc = ''; |
1969 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
1970 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
1971 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
1972 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
1969 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
1970 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
1971 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
1972 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
1973 | 1973 | } |
1974 | 1974 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
1975 | 1975 | ?> |
1976 | 1976 | <div class="wpinv-subscriptions-details"> |
1977 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1977 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1978 | 1978 | <table class="table"> |
1979 | 1979 | <thead> |
1980 | 1980 | <tr> |
1981 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1982 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1983 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1984 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1985 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1981 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1982 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1983 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1984 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1985 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1986 | 1986 | </tr> |
1987 | 1987 | </thead> |
1988 | 1988 | <tbody> |
@@ -1991,32 +1991,32 @@ discard block |
||
1991 | 1991 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
1992 | 1992 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
1993 | 1993 | <td class="text-center"><?php echo $times_billed; ?></td> |
1994 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
1994 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
1995 | 1995 | <?php echo $status_desc; ?> |
1996 | 1996 | </td> |
1997 | 1997 | </tr> |
1998 | 1998 | </tbody> |
1999 | 1999 | </table> |
2000 | 2000 | </div> |
2001 | - <?php if ( !empty( $payments ) ) { ?> |
|
2001 | + <?php if (!empty($payments)) { ?> |
|
2002 | 2002 | <div class="wpinv-renewal-payments"> |
2003 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
2003 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
2004 | 2004 | <table class="table"> |
2005 | 2005 | <thead> |
2006 | 2006 | <tr> |
2007 | 2007 | <th>#</th> |
2008 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2009 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2010 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2008 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
2009 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
2010 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
2011 | 2011 | </tr> |
2012 | 2012 | </thead> |
2013 | 2013 | <tbody> |
2014 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
2014 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
2015 | 2015 | <tr> |
2016 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
2017 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2018 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2019 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2016 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
2017 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
2018 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
2019 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
2020 | 2020 | </tr> |
2021 | 2021 | <?php } ?> |
2022 | 2022 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2028,52 +2028,52 @@ discard block |
||
2028 | 2028 | } |
2029 | 2029 | } |
2030 | 2030 | |
2031 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
2032 | - if ( empty( $invoice ) ) { |
|
2031 | +function wpinv_cart_total_label($label, $invoice) { |
|
2032 | + if (empty($invoice)) { |
|
2033 | 2033 | return $label; |
2034 | 2034 | } |
2035 | 2035 | |
2036 | 2036 | $prefix_label = ''; |
2037 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2038 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2039 | - } else if ( $invoice->is_renewal() ) { |
|
2040 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2037 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
2038 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
2039 | + } else if ($invoice->is_renewal()) { |
|
2040 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2041 | 2041 | } |
2042 | 2042 | |
2043 | - if ( $prefix_label != '' ) { |
|
2044 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2043 | + if ($prefix_label != '') { |
|
2044 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2045 | 2045 | } |
2046 | 2046 | |
2047 | 2047 | return $label; |
2048 | 2048 | } |
2049 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2050 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2051 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2049 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2050 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2051 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2052 | 2052 | |
2053 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2053 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2054 | 2054 | |
2055 | -function wpinv_invoice_print_description( $invoice ) { |
|
2056 | - if ( empty( $invoice ) ) { |
|
2055 | +function wpinv_invoice_print_description($invoice) { |
|
2056 | + if (empty($invoice)) { |
|
2057 | 2057 | return NULL; |
2058 | 2058 | } |
2059 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2059 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2060 | 2060 | ?> |
2061 | 2061 | <div class="row wpinv-lower"> |
2062 | 2062 | <div class="col-sm-12 wpinv-description"> |
2063 | - <?php echo wpautop( $description ); ?> |
|
2063 | + <?php echo wpautop($description); ?> |
|
2064 | 2064 | </div> |
2065 | 2065 | </div> |
2066 | 2066 | <?php |
2067 | 2067 | } |
2068 | 2068 | } |
2069 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2069 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2070 | 2070 | |
2071 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2072 | - if ( empty( $invoice ) ) { |
|
2071 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2072 | + if (empty($invoice)) { |
|
2073 | 2073 | return NULL; |
2074 | 2074 | } |
2075 | 2075 | |
2076 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2076 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2077 | 2077 | ?> |
2078 | 2078 | <div class="row wpinv-payments"> |
2079 | 2079 | <div class="col-sm-12"> |
@@ -2085,40 +2085,40 @@ discard block |
||
2085 | 2085 | } |
2086 | 2086 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2087 | 2087 | |
2088 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2089 | - if ( empty( $note ) ) { |
|
2088 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2089 | + if (empty($note)) { |
|
2090 | 2090 | return NULL; |
2091 | 2091 | } |
2092 | 2092 | |
2093 | - if ( is_int( $note ) ) { |
|
2094 | - $note = get_comment( $note ); |
|
2093 | + if (is_int($note)) { |
|
2094 | + $note = get_comment($note); |
|
2095 | 2095 | } |
2096 | 2096 | |
2097 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2097 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2098 | 2098 | return NULL; |
2099 | 2099 | } |
2100 | 2100 | |
2101 | - $note_classes = array( 'note' ); |
|
2102 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2103 | - $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : ''; |
|
2104 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2105 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2101 | + $note_classes = array('note'); |
|
2102 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2103 | + $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : ''; |
|
2104 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2105 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2106 | 2106 | |
2107 | 2107 | ob_start(); |
2108 | 2108 | ?> |
2109 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2109 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2110 | 2110 | <div class="note_content"> |
2111 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2111 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2112 | 2112 | </div> |
2113 | 2113 | <p class="meta"> |
2114 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2114 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2115 | 2115 | </p> |
2116 | 2116 | </li> |
2117 | 2117 | <?php |
2118 | 2118 | $note_content = ob_get_clean(); |
2119 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2119 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2120 | 2120 | |
2121 | - if ( $echo ) { |
|
2121 | + if ($echo) { |
|
2122 | 2122 | echo $note_content; |
2123 | 2123 | } else { |
2124 | 2124 | return $note_content; |
@@ -7,90 +7,90 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!current_user_can('manage_options')) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!current_user_can('manage_options')) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!current_user_can('manage_options')) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = 'gd_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $discounts = wpinv_get_discounts(); |
104 | 104 | |
105 | - if ( $discounts) { |
|
106 | - foreach ( $discounts as $discount ) { |
|
107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
105 | + if ($discounts) { |
|
106 | + foreach ($discounts as $discount) { |
|
107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
108 | 108 | $has_active = true; |
109 | 109 | break; |
110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | return $has_active; |
114 | 114 | } |
115 | 115 | |
116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
117 | - if( empty( $discount_id ) ) { |
|
116 | +function wpinv_get_discount($discount_id = 0) { |
|
117 | + if (empty($discount_id)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | - $discount = get_post( $discount_id ); |
|
125 | + $discount = get_post($discount_id); |
|
126 | 126 | |
127 | 127 | return $discount; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
130 | +function wpinv_get_discount_by_code($code = '') { |
|
131 | + if (empty($code) || !is_string($code)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return wpinv_get_discount_by( 'code', $code ); |
|
135 | + return wpinv_get_discount_by('code', $code); |
|
136 | 136 | } |
137 | 137 | |
138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
139 | - if( empty( $field ) || empty( $value ) ) { |
|
138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
139 | + if (empty($field) || empty($value)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if( ! is_string( $field ) ) { |
|
143 | + if (!is_string($field)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - switch( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | |
149 | 149 | case 'code': |
150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | 'compare' => '=' |
155 | 155 | ); |
156 | 156 | |
157 | - $discount = wpinv_get_discounts( array( |
|
157 | + $discount = wpinv_get_discounts(array( |
|
158 | 158 | 'posts_per_page' => 1, |
159 | 159 | 'post_status' => 'any', |
160 | 160 | 'meta_query' => $meta_query, |
161 | - ) ); |
|
161 | + )); |
|
162 | 162 | |
163 | - if( $discount ) { |
|
163 | + if ($discount) { |
|
164 | 164 | $discount = $discount[0]; |
165 | 165 | } |
166 | 166 | |
167 | 167 | break; |
168 | 168 | |
169 | 169 | case 'id': |
170 | - $discount = wpinv_get_discount( $value ); |
|
170 | + $discount = wpinv_get_discount($value); |
|
171 | 171 | |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'name': |
175 | - $discount = get_posts( array( |
|
175 | + $discount = get_posts(array( |
|
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'name' => $value, |
178 | 178 | 'posts_per_page' => 1, |
179 | 179 | 'post_status' => 'any' |
180 | - ) ); |
|
180 | + )); |
|
181 | 181 | |
182 | - if( $discount ) { |
|
182 | + if ($discount) { |
|
183 | 183 | $discount = $discount[0]; |
184 | 184 | } |
185 | 185 | |
@@ -189,99 +189,99 @@ discard block |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - if( ! empty( $discount ) ) { |
|
192 | + if (!empty($discount)) { |
|
193 | 193 | return $discount; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
200 | 200 | $meta = array( |
201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
214 | 214 | ); |
215 | 215 | |
216 | - $start_timestamp = strtotime( $meta['start'] ); |
|
216 | + $start_timestamp = strtotime($meta['start']); |
|
217 | 217 | |
218 | - if ( !empty( $meta['start'] ) ) { |
|
219 | - $meta['start'] = date( 'Y-m-d H:i:s', $start_timestamp ); |
|
218 | + if (!empty($meta['start'])) { |
|
219 | + $meta['start'] = date('Y-m-d H:i:s', $start_timestamp); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
222 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
223 | 223 | $meta['amount'] = 100; |
224 | 224 | } |
225 | 225 | |
226 | - if ( !empty( $meta['expiration'] ) ) { |
|
227 | - $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) ); |
|
228 | - $end_timestamp = strtotime( $meta['expiration'] ); |
|
226 | + if (!empty($meta['expiration'])) { |
|
227 | + $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59')); |
|
228 | + $end_timestamp = strtotime($meta['expiration']); |
|
229 | 229 | |
230 | - if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) { |
|
230 | + if (!empty($meta['start']) && $start_timestamp > $end_timestamp) { |
|
231 | 231 | $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date. |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if ( $meta['uses'] === false ) { |
|
236 | - unset( $meta['uses'] ); |
|
235 | + if ($meta['uses'] === false) { |
|
236 | + unset($meta['uses']); |
|
237 | 237 | } |
238 | 238 | |
239 | - if ( ! empty( $meta['items'] ) ) { |
|
240 | - foreach ( $meta['items'] as $key => $item ) { |
|
241 | - if ( 0 === intval( $item ) ) { |
|
242 | - unset( $meta['items'][ $key ] ); |
|
239 | + if (!empty($meta['items'])) { |
|
240 | + foreach ($meta['items'] as $key => $item) { |
|
241 | + if (0 === intval($item)) { |
|
242 | + unset($meta['items'][$key]); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
248 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
249 | - if ( 0 === intval( $item ) ) { |
|
250 | - unset( $meta['excluded_items'][ $key ] ); |
|
247 | + if (!empty($meta['excluded_items'])) { |
|
248 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
249 | + if (0 === intval($item)) { |
|
250 | + unset($meta['excluded_items'][$key]); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
255 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
256 | 256 | |
257 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
257 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
258 | 258 | |
259 | - foreach( $meta as $key => $value ) { |
|
260 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
259 | + foreach ($meta as $key => $value) { |
|
260 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
261 | 261 | } |
262 | 262 | |
263 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
263 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
264 | 264 | |
265 | 265 | return $post_id; |
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
269 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
268 | +function wpinv_remove_discount($discount_id = 0) { |
|
269 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
270 | 270 | |
271 | - wp_delete_post( $discount_id, true ); |
|
271 | + wp_delete_post($discount_id, true); |
|
272 | 272 | |
273 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
273 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
274 | 274 | } |
275 | 275 | |
276 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
277 | - $discount = wpinv_get_discount( $code_id ); |
|
276 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
277 | + $discount = wpinv_get_discount($code_id); |
|
278 | 278 | |
279 | - if ( $discount ) { |
|
280 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
279 | + if ($discount) { |
|
280 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
281 | 281 | |
282 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
282 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
283 | 283 | |
284 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
284 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
285 | 285 | |
286 | 286 | return true; |
287 | 287 | } |
@@ -289,173 +289,173 @@ discard block |
||
289 | 289 | return false; |
290 | 290 | } |
291 | 291 | |
292 | -function wpinv_discount_exists( $code_id ) { |
|
293 | - if ( wpinv_get_discount( $code_id ) ) { |
|
292 | +function wpinv_discount_exists($code_id) { |
|
293 | + if (wpinv_get_discount($code_id)) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | -function wpinv_is_discount_active( $code_id = null ) { |
|
301 | - $discount = wpinv_get_discount( $code_id ); |
|
300 | +function wpinv_is_discount_active($code_id = null) { |
|
301 | + $discount = wpinv_get_discount($code_id); |
|
302 | 302 | $return = false; |
303 | 303 | |
304 | - if ( $discount ) { |
|
305 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
306 | - if( defined( 'DOING_AJAX' ) ) { |
|
307 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
304 | + if ($discount) { |
|
305 | + if (wpinv_is_discount_expired($code_id)) { |
|
306 | + if (defined('DOING_AJAX')) { |
|
307 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
308 | 308 | } |
309 | - } elseif ( $discount->post_status == 'publish' ) { |
|
309 | + } elseif ($discount->post_status == 'publish') { |
|
310 | 310 | $return = true; |
311 | 311 | } else { |
312 | - if( defined( 'DOING_AJAX' ) ) { |
|
313 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
312 | + if (defined('DOING_AJAX')) { |
|
313 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
318 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_get_discount_code( $code_id = null ) { |
|
322 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
321 | +function wpinv_get_discount_code($code_id = null) { |
|
322 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
323 | 323 | |
324 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
324 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
325 | 325 | } |
326 | 326 | |
327 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
328 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
327 | +function wpinv_get_discount_start_date($code_id = null) { |
|
328 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
329 | 329 | |
330 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
330 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
331 | 331 | } |
332 | 332 | |
333 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
334 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
333 | +function wpinv_get_discount_expiration($code_id = null) { |
|
334 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
335 | 335 | |
336 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
336 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
337 | 337 | } |
338 | 338 | |
339 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
340 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
339 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
340 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
341 | 341 | |
342 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
342 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
343 | 343 | } |
344 | 344 | |
345 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
346 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
345 | +function wpinv_get_discount_uses($code_id = null) { |
|
346 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
347 | 347 | |
348 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
348 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
352 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
351 | +function wpinv_get_discount_min_total($code_id = null) { |
|
352 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
353 | 353 | |
354 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
354 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
355 | 355 | } |
356 | 356 | |
357 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
358 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
357 | +function wpinv_get_discount_max_total($code_id = null) { |
|
358 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
359 | 359 | |
360 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
360 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
364 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
363 | +function wpinv_get_discount_amount($code_id = null) { |
|
364 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
365 | 365 | |
366 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
366 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
367 | 367 | } |
368 | 368 | |
369 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
370 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
369 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
370 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
371 | 371 | |
372 | - if ( $name ) { |
|
373 | - $name = wpinv_get_discount_type_name( $type ); |
|
372 | + if ($name) { |
|
373 | + $name = wpinv_get_discount_type_name($type); |
|
374 | 374 | |
375 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
375 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
376 | 376 | } |
377 | 377 | |
378 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
378 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
379 | 379 | } |
380 | 380 | |
381 | -function wpinv_discount_status( $status ) { |
|
382 | - switch( $status ){ |
|
381 | +function wpinv_discount_status($status) { |
|
382 | + switch ($status) { |
|
383 | 383 | case 'expired' : |
384 | - $name = __( 'Expired', 'invoicing' ); |
|
384 | + $name = __('Expired', 'invoicing'); |
|
385 | 385 | break; |
386 | 386 | case 'publish' : |
387 | 387 | case 'active' : |
388 | - $name = __( 'Active', 'invoicing' ); |
|
388 | + $name = __('Active', 'invoicing'); |
|
389 | 389 | break; |
390 | 390 | default : |
391 | - $name = __( 'Inactive', 'invoicing' ); |
|
391 | + $name = __('Inactive', 'invoicing'); |
|
392 | 392 | break; |
393 | 393 | } |
394 | 394 | return $name; |
395 | 395 | } |
396 | 396 | |
397 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
398 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
397 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
398 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
399 | 399 | |
400 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
400 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
401 | 401 | $excluded_items = array(); |
402 | 402 | } |
403 | 403 | |
404 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
404 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
408 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
407 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
408 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
409 | 409 | |
410 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
410 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
411 | 411 | $item_reqs = array(); |
412 | 412 | } |
413 | 413 | |
414 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
414 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
415 | 415 | } |
416 | 416 | |
417 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
418 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
417 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
418 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
422 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
421 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
422 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
426 | - $discount = wpinv_get_discount( $code_id ); |
|
425 | +function wpinv_is_discount_expired($code_id = null) { |
|
426 | + $discount = wpinv_get_discount($code_id); |
|
427 | 427 | $return = false; |
428 | 428 | |
429 | - if ( $discount ) { |
|
430 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
431 | - if ( $expiration ) { |
|
432 | - $expiration = strtotime( $expiration ); |
|
433 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
429 | + if ($discount) { |
|
430 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
431 | + if ($expiration) { |
|
432 | + $expiration = strtotime($expiration); |
|
433 | + if ($expiration < current_time('timestamp')) { |
|
434 | 434 | // Discount is expired |
435 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
435 | + wpinv_update_discount_status($code_id, 'pending'); |
|
436 | 436 | $return = true; |
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
441 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_is_discount_started( $code_id = null ) { |
|
445 | - $discount = wpinv_get_discount( $code_id ); |
|
444 | +function wpinv_is_discount_started($code_id = null) { |
|
445 | + $discount = wpinv_get_discount($code_id); |
|
446 | 446 | $return = false; |
447 | 447 | |
448 | - if ( $discount ) { |
|
449 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
448 | + if ($discount) { |
|
449 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
450 | 450 | |
451 | - if ( $start_date ) { |
|
452 | - $start_date = strtotime( $start_date ); |
|
451 | + if ($start_date) { |
|
452 | + $start_date = strtotime($start_date); |
|
453 | 453 | |
454 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
454 | + if ($start_date < current_time('timestamp')) { |
|
455 | 455 | // Discount has past the start date |
456 | 456 | $return = true; |
457 | 457 | } else { |
458 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
458 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
459 | 459 | } |
460 | 460 | } else { |
461 | 461 | // No start date for this discount, so has to be true |
@@ -463,159 +463,159 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
466 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
467 | 467 | } |
468 | 468 | |
469 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
470 | - $discount = wpinv_get_discount( $code_id ); |
|
469 | +function wpinv_check_discount_dates($code_id = null) { |
|
470 | + $discount = wpinv_get_discount($code_id); |
|
471 | 471 | $return = false; |
472 | 472 | |
473 | - if ( $discount ) { |
|
474 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
473 | + if ($discount) { |
|
474 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
475 | 475 | |
476 | - if ( $start_date ) { |
|
477 | - $start_date = strtotime( $start_date ); |
|
476 | + if ($start_date) { |
|
477 | + $start_date = strtotime($start_date); |
|
478 | 478 | |
479 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
479 | + if ($start_date < current_time('timestamp')) { |
|
480 | 480 | // Discount has past the start date |
481 | 481 | $return = true; |
482 | 482 | } else { |
483 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
483 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
484 | 484 | } |
485 | 485 | } else { |
486 | 486 | // No start date for this discount, so has to be true |
487 | 487 | $return = true; |
488 | 488 | } |
489 | 489 | |
490 | - if ( $return ) { |
|
491 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
490 | + if ($return) { |
|
491 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
492 | 492 | |
493 | - if ( $expiration ) { |
|
494 | - $expiration = strtotime( $expiration ); |
|
495 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
493 | + if ($expiration) { |
|
494 | + $expiration = strtotime($expiration); |
|
495 | + if ($expiration < current_time('timestamp')) { |
|
496 | 496 | // Discount is expired |
497 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
497 | + wpinv_update_discount_status($code_id, 'pending'); |
|
498 | 498 | $return = true; |
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | } |
503 | 503 | |
504 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
504 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
508 | - $discount = wpinv_get_discount( $code_id ); |
|
507 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
508 | + $discount = wpinv_get_discount($code_id); |
|
509 | 509 | $return = false; |
510 | 510 | |
511 | - if ( $discount ) { |
|
512 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
511 | + if ($discount) { |
|
512 | + $uses = wpinv_get_discount_uses($code_id); |
|
513 | 513 | // Large number that will never be reached |
514 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
514 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
515 | 515 | // Should never be greater than, but just in case |
516 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
516 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
517 | 517 | // Discount is maxed out |
518 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
518 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
519 | 519 | $return = true; |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
523 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
524 | 524 | } |
525 | 525 | |
526 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
527 | - $discount = wpinv_get_discount( $code_id ); |
|
526 | +function wpinv_discount_is_min_met($code_id = null) { |
|
527 | + $discount = wpinv_get_discount($code_id); |
|
528 | 528 | $return = false; |
529 | 529 | |
530 | - if ( $discount ) { |
|
531 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
532 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
530 | + if ($discount) { |
|
531 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
532 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
533 | 533 | |
534 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
534 | + if (!$min > 0 || $cart_amount >= $min) { |
|
535 | 535 | // Minimum has been met |
536 | 536 | $return = true; |
537 | 537 | } else { |
538 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
538 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
542 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
542 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
543 | 543 | } |
544 | 544 | |
545 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
546 | - $discount = wpinv_get_discount( $code_id ); |
|
545 | +function wpinv_discount_is_max_met($code_id = null) { |
|
546 | + $discount = wpinv_get_discount($code_id); |
|
547 | 547 | $return = false; |
548 | 548 | |
549 | - if ( $discount ) { |
|
550 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
551 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
549 | + if ($discount) { |
|
550 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
551 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
552 | 552 | |
553 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
553 | + if (!$max > 0 || $cart_amount <= $max) { |
|
554 | 554 | // Minimum has been met |
555 | 555 | $return = true; |
556 | 556 | } else { |
557 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
557 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
561 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
562 | 562 | } |
563 | 563 | |
564 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
565 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
566 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
564 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
565 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
566 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
567 | 567 | } |
568 | 568 | |
569 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
570 | - if ( $code ) { |
|
571 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
569 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
570 | + if ($code) { |
|
571 | + $discount = wpinv_get_discount_by_code($code_id); |
|
572 | 572 | |
573 | - if ( !empty( $discount ) ) { |
|
573 | + if (!empty($discount)) { |
|
574 | 574 | $code_id = $discount->ID; |
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
578 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
578 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
579 | 579 | |
580 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
580 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
584 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
585 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
586 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
583 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
584 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
585 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
586 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
587 | 587 | $cart_items = wpinv_get_cart_contents(); |
588 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
588 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
589 | 589 | $ret = false; |
590 | 590 | |
591 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
591 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
592 | 592 | $ret = true; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // Normalize our data for item requirements, exclusions and cart data |
596 | 596 | // First absint the items, then sort, and reset the array keys |
597 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
598 | - asort( $item_reqs ); |
|
599 | - $item_reqs = array_values( $item_reqs ); |
|
597 | + $item_reqs = array_map('absint', $item_reqs); |
|
598 | + asort($item_reqs); |
|
599 | + $item_reqs = array_values($item_reqs); |
|
600 | 600 | |
601 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
602 | - asort( $excluded_ps ); |
|
603 | - $excluded_ps = array_values( $excluded_ps ); |
|
601 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
602 | + asort($excluded_ps); |
|
603 | + $excluded_ps = array_values($excluded_ps); |
|
604 | 604 | |
605 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
606 | - asort( $cart_ids ); |
|
607 | - $cart_ids = array_values( $cart_ids ); |
|
605 | + $cart_ids = array_map('absint', $cart_ids); |
|
606 | + asort($cart_ids); |
|
607 | + $cart_ids = array_values($cart_ids); |
|
608 | 608 | |
609 | 609 | // Ensure we have requirements before proceeding |
610 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
611 | - switch( $condition ) { |
|
610 | + if (!$ret && !empty($item_reqs)) { |
|
611 | + switch ($condition) { |
|
612 | 612 | case 'all' : |
613 | 613 | // Default back to true |
614 | 614 | $ret = true; |
615 | 615 | |
616 | - foreach ( $item_reqs as $item_id ) { |
|
617 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
618 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
616 | + foreach ($item_reqs as $item_id) { |
|
617 | + if (!wpinv_item_in_cart($item_id)) { |
|
618 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
619 | 619 | $ret = false; |
620 | 620 | break; |
621 | 621 | } |
@@ -624,15 +624,15 @@ discard block |
||
624 | 624 | break; |
625 | 625 | |
626 | 626 | default : // Any |
627 | - foreach ( $item_reqs as $item_id ) { |
|
628 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
627 | + foreach ($item_reqs as $item_id) { |
|
628 | + if (wpinv_item_in_cart($item_id)) { |
|
629 | 629 | $ret = true; |
630 | 630 | break; |
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
634 | - if( ! $ret ) { |
|
635 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
634 | + if (!$ret) { |
|
635 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | break; |
@@ -641,68 +641,68 @@ discard block |
||
641 | 641 | $ret = true; |
642 | 642 | } |
643 | 643 | |
644 | - if( ! empty( $excluded_ps ) ) { |
|
644 | + if (!empty($excluded_ps)) { |
|
645 | 645 | // Check that there are items other than excluded ones in the cart |
646 | - if( $cart_ids == $excluded_ps ) { |
|
647 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
646 | + if ($cart_ids == $excluded_ps) { |
|
647 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
648 | 648 | $ret = false; |
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
652 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
652 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
655 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
656 | 656 | global $wpi_checkout_id; |
657 | 657 | |
658 | 658 | $return = false; |
659 | 659 | |
660 | - if ( empty( $code_id ) ) { |
|
661 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
660 | + if (empty($code_id)) { |
|
661 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
662 | 662 | |
663 | - if( empty( $code_id ) ) { |
|
663 | + if (empty($code_id)) { |
|
664 | 664 | return false; // No discount was found |
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
668 | + if (wpinv_discount_is_single_use($code_id)) { |
|
669 | 669 | $payments = array(); |
670 | 670 | |
671 | 671 | $user_id = 0; |
672 | - if ( is_int( $user ) ) { |
|
672 | + if (is_int($user)) { |
|
673 | 673 | $user_id = $user; |
674 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
674 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
675 | 675 | $user_id = $user_data->ID; |
676 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
676 | + } else if ($user_data = get_user_by('login', $user)) { |
|
677 | 677 | $user_id = $user_data->ID; |
678 | 678 | } |
679 | 679 | |
680 | - if ( !$user_id ) { |
|
681 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
682 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching email |
|
680 | + if (!$user_id) { |
|
681 | + $query = array('user' => $user_id, 'limit' => false); |
|
682 | + $payments = wpinv_get_invoices($query); // Get all payments with matching email |
|
683 | 683 | } |
684 | 684 | |
685 | - if ( $payments ) { |
|
686 | - foreach ( $payments as $payment ) { |
|
687 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
685 | + if ($payments) { |
|
686 | + foreach ($payments as $payment) { |
|
687 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | 691 | // Don't count discount used for current invoice chekcout. |
692 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
692 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
693 | 693 | continue; |
694 | 694 | } |
695 | 695 | |
696 | - $discounts = $payment->get_discounts( true ); |
|
697 | - if ( empty( $discounts ) ) { |
|
696 | + $discounts = $payment->get_discounts(true); |
|
697 | + if (empty($discounts)) { |
|
698 | 698 | continue; |
699 | 699 | } |
700 | 700 | |
701 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
701 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
702 | 702 | |
703 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
704 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
705 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
703 | + if (!empty($discounts) && is_array($discounts)) { |
|
704 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
705 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
706 | 706 | $return = true; |
707 | 707 | break; |
708 | 708 | } |
@@ -711,61 +711,61 @@ discard block |
||
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
714 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
715 | 715 | } |
716 | 716 | |
717 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
717 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
718 | 718 | $return = false; |
719 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
720 | - $user = trim( $user ); |
|
719 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
720 | + $user = trim($user); |
|
721 | 721 | |
722 | - if ( wpinv_get_cart_contents() ) { |
|
723 | - if ( $discount_id ) { |
|
722 | + if (wpinv_get_cart_contents()) { |
|
723 | + if ($discount_id) { |
|
724 | 724 | if ( |
725 | - wpinv_is_discount_active( $discount_id ) && |
|
726 | - wpinv_check_discount_dates( $discount_id ) && |
|
727 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
728 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
729 | - wpinv_discount_is_min_met( $discount_id ) && |
|
730 | - wpinv_discount_is_max_met( $discount_id ) && |
|
731 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
725 | + wpinv_is_discount_active($discount_id) && |
|
726 | + wpinv_check_discount_dates($discount_id) && |
|
727 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
728 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
729 | + wpinv_discount_is_min_met($discount_id) && |
|
730 | + wpinv_discount_is_max_met($discount_id) && |
|
731 | + wpinv_discount_item_reqs_met($discount_id) |
|
732 | 732 | ) { |
733 | 733 | $return = true; |
734 | 734 | } |
735 | - } elseif( $set_error ) { |
|
736 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
735 | + } elseif ($set_error) { |
|
736 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
740 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
741 | 741 | } |
742 | 742 | |
743 | -function wpinv_get_discount_id_by_code( $code ) { |
|
744 | - $discount = wpinv_get_discount_by_code( $code ); |
|
745 | - if( $discount ) { |
|
743 | +function wpinv_get_discount_id_by_code($code) { |
|
744 | + $discount = wpinv_get_discount_by_code($code); |
|
745 | + if ($discount) { |
|
746 | 746 | return $discount->ID; |
747 | 747 | } |
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
751 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
751 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
752 | 752 | $amount = $base_price; |
753 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
753 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
754 | 754 | |
755 | - if( $discount_id ) { |
|
756 | - $type = wpinv_get_discount_type( $discount_id ); |
|
757 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
755 | + if ($discount_id) { |
|
756 | + $type = wpinv_get_discount_type($discount_id); |
|
757 | + $rate = wpinv_get_discount_amount($discount_id); |
|
758 | 758 | |
759 | - if ( $type == 'flat' ) { |
|
759 | + if ($type == 'flat') { |
|
760 | 760 | // Set amount |
761 | 761 | $amount = $base_price - $rate; |
762 | - if ( $amount < 0 ) { |
|
762 | + if ($amount < 0) { |
|
763 | 763 | $amount = 0; |
764 | 764 | } |
765 | 765 | |
766 | 766 | } else { |
767 | 767 | // Percentage discount |
768 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
768 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | } else { |
@@ -774,108 +774,108 @@ discard block |
||
774 | 774 | |
775 | 775 | } |
776 | 776 | |
777 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
777 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
778 | 778 | } |
779 | 779 | |
780 | -function wpinv_increase_discount_usage( $code ) { |
|
780 | +function wpinv_increase_discount_usage($code) { |
|
781 | 781 | |
782 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
783 | - $uses = wpinv_get_discount_uses( $id ); |
|
782 | + $id = wpinv_get_discount_id_by_code($code); |
|
783 | + $uses = wpinv_get_discount_uses($id); |
|
784 | 784 | |
785 | - if ( $uses ) { |
|
785 | + if ($uses) { |
|
786 | 786 | $uses++; |
787 | 787 | } else { |
788 | 788 | $uses = 1; |
789 | 789 | } |
790 | 790 | |
791 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
791 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
792 | 792 | |
793 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
793 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
794 | 794 | |
795 | 795 | return $uses; |
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | -function wpinv_decrease_discount_usage( $code ) { |
|
799 | +function wpinv_decrease_discount_usage($code) { |
|
800 | 800 | |
801 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
802 | - $uses = wpinv_get_discount_uses( $id ); |
|
801 | + $id = wpinv_get_discount_id_by_code($code); |
|
802 | + $uses = wpinv_get_discount_uses($id); |
|
803 | 803 | |
804 | - if ( $uses ) { |
|
804 | + if ($uses) { |
|
805 | 805 | $uses--; |
806 | 806 | } |
807 | 807 | |
808 | - if ( $uses < 0 ) { |
|
808 | + if ($uses < 0) { |
|
809 | 809 | $uses = 0; |
810 | 810 | } |
811 | 811 | |
812 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
812 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
813 | 813 | |
814 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
814 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
815 | 815 | |
816 | 816 | return $uses; |
817 | 817 | |
818 | 818 | } |
819 | 819 | |
820 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
821 | - if ( $type == 'flat' ) { |
|
822 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
820 | +function wpinv_format_discount_rate($type, $amount) { |
|
821 | + if ($type == 'flat') { |
|
822 | + return wpinv_price(wpinv_format_amount($amount)); |
|
823 | 823 | } else { |
824 | 824 | return $amount . '%'; |
825 | 825 | } |
826 | 826 | } |
827 | 827 | |
828 | -function wpinv_set_cart_discount( $code = '' ) { |
|
829 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
828 | +function wpinv_set_cart_discount($code = '') { |
|
829 | + if (wpinv_multiple_discounts_allowed()) { |
|
830 | 830 | // Get all active cart discounts |
831 | 831 | $discounts = wpinv_get_cart_discounts(); |
832 | 832 | } else { |
833 | 833 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
834 | 834 | } |
835 | 835 | |
836 | - if ( $discounts ) { |
|
837 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
838 | - if( false !== $key ) { |
|
839 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
836 | + if ($discounts) { |
|
837 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
838 | + if (false !== $key) { |
|
839 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
840 | 840 | } |
841 | 841 | $discounts[] = $code; |
842 | 842 | } else { |
843 | 843 | $discounts = array(); |
844 | 844 | $discounts[] = $code; |
845 | 845 | } |
846 | - $discounts = array_values( $discounts ); |
|
846 | + $discounts = array_values($discounts); |
|
847 | 847 | |
848 | 848 | $data = wpinv_get_checkout_session(); |
849 | - if ( empty( $data ) ) { |
|
849 | + if (empty($data)) { |
|
850 | 850 | $data = array(); |
851 | 851 | } else { |
852 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
853 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
854 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
852 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
853 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
854 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | $data['cart_discounts'] = $discounts; |
858 | 858 | |
859 | - wpinv_set_checkout_session( $data ); |
|
859 | + wpinv_set_checkout_session($data); |
|
860 | 860 | |
861 | 861 | return $discounts; |
862 | 862 | } |
863 | 863 | |
864 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
864 | +function wpinv_unset_cart_discount($code = '') { |
|
865 | 865 | $discounts = wpinv_get_cart_discounts(); |
866 | 866 | |
867 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
868 | - $key = array_search( $code, $discounts ); |
|
869 | - unset( $discounts[ $key ] ); |
|
867 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
868 | + $key = array_search($code, $discounts); |
|
869 | + unset($discounts[$key]); |
|
870 | 870 | |
871 | 871 | $data = wpinv_get_checkout_session(); |
872 | 872 | $data['cart_discounts'] = $discounts; |
873 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
874 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
875 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
873 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
874 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
875 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
876 | 876 | } |
877 | 877 | |
878 | - wpinv_set_checkout_session( $data ); |
|
878 | + wpinv_set_checkout_session($data); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | return $discounts; |
@@ -884,27 +884,27 @@ discard block |
||
884 | 884 | function wpinv_unset_all_cart_discounts() { |
885 | 885 | $data = wpinv_get_checkout_session(); |
886 | 886 | |
887 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
888 | - unset( $data['cart_discounts'] ); |
|
887 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
888 | + unset($data['cart_discounts']); |
|
889 | 889 | |
890 | - wpinv_set_checkout_session( $data ); |
|
890 | + wpinv_set_checkout_session($data); |
|
891 | 891 | return true; |
892 | 892 | } |
893 | 893 | |
894 | 894 | return false; |
895 | 895 | } |
896 | 896 | |
897 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
897 | +function wpinv_get_cart_discounts($items = array()) { |
|
898 | 898 | $session = wpinv_get_checkout_session(); |
899 | 899 | |
900 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
900 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
901 | 901 | return $discounts; |
902 | 902 | } |
903 | 903 | |
904 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
904 | +function wpinv_cart_has_discounts($items = array()) { |
|
905 | 905 | $ret = false; |
906 | 906 | |
907 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
907 | + if (wpinv_get_cart_discounts($items)) { |
|
908 | 908 | $ret = true; |
909 | 909 | } |
910 | 910 | |
@@ -915,131 +915,131 @@ discard block |
||
915 | 915 | } |
916 | 916 | */ |
917 | 917 | |
918 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
918 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
919 | 919 | } |
920 | 920 | |
921 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
921 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
922 | 922 | $amount = 0.00; |
923 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
923 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
924 | 924 | |
925 | - if ( $items ) { |
|
926 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
925 | + if ($items) { |
|
926 | + $discounts = wp_list_pluck($items, 'discount'); |
|
927 | 927 | |
928 | - if ( is_array( $discounts ) ) { |
|
929 | - $discounts = array_map( 'floatval', $discounts ); |
|
930 | - $amount = array_sum( $discounts ); |
|
928 | + if (is_array($discounts)) { |
|
929 | + $discounts = array_map('floatval', $discounts); |
|
930 | + $amount = array_sum($discounts); |
|
931 | 931 | } |
932 | 932 | } |
933 | 933 | |
934 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
934 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
935 | 935 | } |
936 | 936 | |
937 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
938 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
937 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
938 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
939 | 939 | |
940 | - if ( empty( $discount ) || empty( $items ) ) { |
|
940 | + if (empty($discount) || empty($items)) { |
|
941 | 941 | return 0; |
942 | 942 | } |
943 | 943 | |
944 | 944 | $amount = 0; |
945 | 945 | |
946 | - foreach ( $items as $item ) { |
|
947 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
946 | + foreach ($items as $item) { |
|
947 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
948 | 948 | } |
949 | 949 | |
950 | - $amount = wpinv_round_amount( $amount ); |
|
950 | + $amount = wpinv_round_amount($amount); |
|
951 | 951 | |
952 | 952 | return $amount; |
953 | 953 | } |
954 | 954 | |
955 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
955 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
956 | 956 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
957 | 957 | |
958 | 958 | $amount = 0; |
959 | 959 | |
960 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
960 | + if (empty($item) || empty($item['id'])) { |
|
961 | 961 | return $amount; |
962 | 962 | } |
963 | 963 | |
964 | - if ( empty( $item['quantity'] ) ) { |
|
964 | + if (empty($item['quantity'])) { |
|
965 | 965 | return $amount; |
966 | 966 | } |
967 | 967 | |
968 | - if ( empty( $item['options'] ) ) { |
|
968 | + if (empty($item['options'])) { |
|
969 | 969 | $item['options'] = array(); |
970 | 970 | } |
971 | 971 | |
972 | - $price = wpinv_get_cart_item_price( $item['id'], $item['options'] ); |
|
972 | + $price = wpinv_get_cart_item_price($item['id'], $item['options']); |
|
973 | 973 | $discounted_price = $price; |
974 | 974 | |
975 | 975 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
976 | - if ( empty( $discounts ) ) { |
|
976 | + if (empty($discounts)) { |
|
977 | 977 | return $amount; |
978 | 978 | } |
979 | 979 | |
980 | - if ( $discounts ) { |
|
981 | - if ( is_array( $discounts ) ) { |
|
982 | - $discounts = array_values( $discounts ); |
|
980 | + if ($discounts) { |
|
981 | + if (is_array($discounts)) { |
|
982 | + $discounts = array_values($discounts); |
|
983 | 983 | } else { |
984 | - $discounts = explode( ',', $discounts ); |
|
984 | + $discounts = explode(',', $discounts); |
|
985 | 985 | } |
986 | 986 | } |
987 | 987 | |
988 | - if( $discounts ) { |
|
989 | - foreach ( $discounts as $discount ) { |
|
990 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
988 | + if ($discounts) { |
|
989 | + foreach ($discounts as $discount) { |
|
990 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
991 | 991 | |
992 | 992 | // Check discount exists |
993 | - if( ! $code_id ) { |
|
993 | + if (!$code_id) { |
|
994 | 994 | continue; |
995 | 995 | } |
996 | 996 | |
997 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
998 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
997 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
998 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
999 | 999 | |
1000 | 1000 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1001 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1002 | - foreach ( $reqs as $item_id ) { |
|
1003 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1004 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1001 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1002 | + foreach ($reqs as $item_id) { |
|
1003 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1004 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | } else { |
1008 | 1008 | // This is a global cart discount |
1009 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1010 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1009 | + if (!in_array($item['id'], $excluded_items)) { |
|
1010 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1011 | 1011 | $items_subtotal = 0.00; |
1012 | 1012 | $cart_items = wpinv_get_cart_contents(); |
1013 | 1013 | |
1014 | - foreach ( $cart_items as $cart_item ) { |
|
1015 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1016 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1017 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $options ); |
|
1014 | + foreach ($cart_items as $cart_item) { |
|
1015 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1016 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1017 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $options); |
|
1018 | 1018 | $items_subtotal += $item_price * $cart_item['quantity']; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1023 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1022 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1023 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1024 | 1024 | $discounted_amount = $code_amount * $subtotal_percent; |
1025 | 1025 | $discounted_price -= $discounted_amount; |
1026 | 1026 | |
1027 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1027 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1028 | 1028 | |
1029 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1029 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1030 | 1030 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1031 | 1031 | $discounted_price -= $adjustment; |
1032 | 1032 | } |
1033 | 1033 | } else { |
1034 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1034 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1040 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1041 | 1041 | |
1042 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1042 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1043 | 1043 | $amount = $amount * $item['quantity']; |
1044 | 1044 | } |
1045 | 1045 | } |
@@ -1047,59 +1047,59 @@ discard block |
||
1047 | 1047 | return $amount; |
1048 | 1048 | } |
1049 | 1049 | |
1050 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1051 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1050 | +function wpinv_cart_discounts_html($items = array()) { |
|
1051 | + echo wpinv_get_cart_discounts_html($items); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1054 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1055 | 1055 | global $wpi_cart_columns; |
1056 | 1056 | |
1057 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1057 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1058 | 1058 | |
1059 | - if ( !$discounts ) { |
|
1060 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1059 | + if (!$discounts) { |
|
1060 | + $discounts = wpinv_get_cart_discounts($items); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | - if ( !$discounts ) { |
|
1063 | + if (!$discounts) { |
|
1064 | 1064 | return; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1067 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1068 | 1068 | |
1069 | 1069 | $html = ''; |
1070 | 1070 | |
1071 | - foreach ( $discounts as $discount ) { |
|
1072 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1073 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1074 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1075 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1076 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1071 | + foreach ($discounts as $discount) { |
|
1072 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1073 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1074 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1075 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1076 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1077 | 1077 | |
1078 | 1078 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1079 | 1079 | ob_start(); |
1080 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1080 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1081 | 1081 | $html .= ob_get_clean(); |
1082 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
1082 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
1083 | 1083 | ob_start(); |
1084 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1084 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1085 | 1085 | $html .= ob_get_clean(); |
1086 | 1086 | $html .= '</tr>'; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1089 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
1092 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
1093 | 1093 | $discounts = wpinv_get_cart_discounts(); |
1094 | 1094 | |
1095 | - if ( empty( $discounts ) ) { |
|
1095 | + if (empty($discounts)) { |
|
1096 | 1096 | return false; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1100 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1099 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1100 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1101 | 1101 | |
1102 | - if ( $echo ) { |
|
1102 | + if ($echo) { |
|
1103 | 1103 | echo $amount; |
1104 | 1104 | } |
1105 | 1105 | |
@@ -1107,133 +1107,133 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | function wpinv_remove_cart_discount() { |
1110 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1110 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1111 | 1111 | return; |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1114 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1115 | 1115 | |
1116 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1116 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1117 | 1117 | |
1118 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1118 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1119 | 1119 | |
1120 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1120 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1121 | 1121 | } |
1122 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1122 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1123 | 1123 | |
1124 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
1124 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
1125 | 1125 | $discounts = wpinv_get_cart_discounts(); |
1126 | 1126 | |
1127 | - if ( !$discounts ) { |
|
1127 | + if (!$discounts) { |
|
1128 | 1128 | return; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - foreach ( $discounts as $discount ) { |
|
1132 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1133 | - wpinv_unset_cart_discount( $discount ); |
|
1131 | + foreach ($discounts as $discount) { |
|
1132 | + if (!wpinv_is_discount_valid($discount)) { |
|
1133 | + wpinv_unset_cart_discount($discount); |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1137 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1138 | 1138 | |
1139 | 1139 | function wpinv_multiple_discounts_allowed() { |
1140 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1141 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1140 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1141 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | function wpinv_listen_for_cart_discount() { |
1145 | 1145 | global $wpi_session; |
1146 | 1146 | |
1147 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
1147 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
1148 | 1148 | return; |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
1151 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
1152 | 1152 | |
1153 | - $wpi_session->set( 'preset_discount', $code ); |
|
1153 | + $wpi_session->set('preset_discount', $code); |
|
1154 | 1154 | } |
1155 | 1155 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
1156 | 1156 | |
1157 | 1157 | function wpinv_apply_preset_discount() { |
1158 | 1158 | global $wpi_session; |
1159 | 1159 | |
1160 | - $code = $wpi_session->get( 'preset_discount' ); |
|
1160 | + $code = $wpi_session->get('preset_discount'); |
|
1161 | 1161 | |
1162 | - if ( !$code ) { |
|
1162 | + if (!$code) { |
|
1163 | 1163 | return; |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
1166 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
1167 | 1167 | return; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
1170 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
1171 | 1171 | |
1172 | - wpinv_set_cart_discount( $code ); |
|
1172 | + wpinv_set_cart_discount($code); |
|
1173 | 1173 | |
1174 | - $wpi_session->set( 'preset_discount', null ); |
|
1174 | + $wpi_session->set('preset_discount', null); |
|
1175 | 1175 | } |
1176 | 1176 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1177 | 1177 | |
1178 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1179 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1180 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1178 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1179 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1180 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1181 | 1181 | |
1182 | - if ( $echo ) { |
|
1182 | + if ($echo) { |
|
1183 | 1183 | echo $label; |
1184 | 1184 | } else { |
1185 | 1185 | return $label; |
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | |
1189 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1190 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
1191 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1189 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1190 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
1191 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1192 | 1192 | |
1193 | - if ( $echo ) { |
|
1193 | + if ($echo) { |
|
1194 | 1194 | echo $label; |
1195 | 1195 | } else { |
1196 | 1196 | return $label; |
1197 | 1197 | } |
1198 | 1198 | } |
1199 | 1199 | |
1200 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
1201 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1200 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
1201 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1202 | 1202 | return true; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | return $check; |
1206 | 1206 | } |
1207 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
1207 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
1208 | 1208 | |
1209 | 1209 | function wpinv_checkout_form_validate_discounts() { |
1210 | 1210 | $discounts = wpinv_get_cart_discounts(); |
1211 | 1211 | |
1212 | - if ( !empty( $discounts ) ) { |
|
1212 | + if (!empty($discounts)) { |
|
1213 | 1213 | $invalid = false; |
1214 | 1214 | |
1215 | - foreach ( $discounts as $key => $code ) { |
|
1216 | - if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) { |
|
1215 | + foreach ($discounts as $key => $code) { |
|
1216 | + if (!wpinv_is_discount_valid($code, get_current_user_id())) { |
|
1217 | 1217 | $invalid = true; |
1218 | 1218 | |
1219 | - wpinv_unset_cart_discount( $code ); |
|
1219 | + wpinv_unset_cart_discount($code); |
|
1220 | 1220 | } |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - if ( $invalid ) { |
|
1223 | + if ($invalid) { |
|
1224 | 1224 | $errors = wpinv_get_errors(); |
1225 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1227 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1225 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1227 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1228 | 1228 | |
1229 | - wpinv_recalculate_tax( true ); |
|
1229 | + wpinv_recalculate_tax(true); |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1233 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1234 | 1234 | |
1235 | 1235 | function wpinv_discount_amount() { |
1236 | 1236 | $output = 0.00; |
1237 | 1237 | |
1238 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1238 | + return apply_filters('wpinv_discount_amount', $output); |
|
1239 | 1239 | } |
1240 | 1240 | \ No newline at end of file |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | self::$instance->reports = new WPInv_Reports(); |
24 | 24 | } |
25 | 25 | |
26 | - do_action( 'wpinv_loaded' ); |
|
26 | + do_action('wpinv_loaded'); |
|
27 | 27 | |
28 | 28 | return self::$instance; |
29 | 29 | } |
@@ -33,31 +33,31 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function define_constants() { |
36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function actions() { |
41 | 41 | /* Internationalize the text strings used. */ |
42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
43 | 43 | |
44 | 44 | /* Perform actions on admin initialization. */ |
45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
47 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
48 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
46 | + add_action('init', array(&$this, 'init'), 3); |
|
47 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
49 | 49 | |
50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
50 | + if (class_exists('BuddyPress')) { |
|
51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
52 | 52 | } |
53 | 53 | |
54 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
55 | 55 | |
56 | - if ( is_admin() ) { |
|
57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
56 | + if (is_admin()) { |
|
57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
59 | 59 | } else { |
60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
69 | 69 | */ |
70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
71 | 71 | |
72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function plugins_loaded() { |
@@ -83,189 +83,189 @@ discard block |
||
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | 85 | public function load_textdomain() { |
86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
87 | 87 | |
88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Define language constants. |
93 | 93 | */ |
94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | public function includes() { |
98 | 98 | global $wpinv_options; |
99 | 99 | |
100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
101 | 101 | $wpinv_options = wpinv_get_settings(); |
102 | 102 | |
103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
126 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
126 | + if (!class_exists('Geodir_EUVat')) { |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
128 | 128 | } |
129 | 129 | |
130 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
131 | - if ( !empty( $gateways ) ) { |
|
132 | - foreach ( $gateways as $gateway ) { |
|
133 | - if ( $gateway == 'manual' ) { |
|
130 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
131 | + if (!empty($gateways)) { |
|
132 | + foreach ($gateways as $gateway) { |
|
133 | + if ($gateway == 'manual') { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
138 | 138 | |
139 | - if ( file_exists( $gateway_file ) ) { |
|
140 | - require_once( $gateway_file ); |
|
139 | + if (file_exists($gateway_file)) { |
|
140 | + require_once($gateway_file); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
145 | - |
|
146 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
154 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
145 | + |
|
146 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
154 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
158 | 158 | // include css inliner |
159 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
160 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
159 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
160 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
161 | 161 | } |
162 | 162 | |
163 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
163 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | public function init() { |
167 | 167 | } |
168 | 168 | |
169 | 169 | public function admin_init() { |
170 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
170 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
171 | 171 | } |
172 | 172 | |
173 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
173 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | public function activation_redirect() { |
177 | 177 | // Bail if no activation redirect |
178 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
178 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Delete the redirect transient |
183 | - delete_transient( '_wpinv_activation_redirect' ); |
|
183 | + delete_transient('_wpinv_activation_redirect'); |
|
184 | 184 | |
185 | 185 | // Bail if activating from network, or bulk |
186 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
186 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
190 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
190 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
191 | 191 | exit; |
192 | 192 | } |
193 | 193 | |
194 | 194 | public function enqueue_scripts() { |
195 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
195 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
196 | 196 | |
197 | - wp_deregister_style( 'font-awesome' ); |
|
198 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
199 | - wp_enqueue_style( 'font-awesome' ); |
|
197 | + wp_deregister_style('font-awesome'); |
|
198 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
199 | + wp_enqueue_style('font-awesome'); |
|
200 | 200 | |
201 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
202 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
201 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
202 | + wp_enqueue_style('wpinv_front_style'); |
|
203 | 203 | |
204 | 204 | // Register scripts |
205 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
206 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
205 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
206 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
207 | 207 | |
208 | 208 | $localize = array(); |
209 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
210 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
209 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
210 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
211 | 211 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
212 | 212 | $localize['currency_pos'] = wpinv_currency_position(); |
213 | 213 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
214 | 214 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
215 | 215 | $localize['decimals'] = wpinv_decimals(); |
216 | 216 | |
217 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
217 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
218 | 218 | |
219 | - wp_enqueue_script( 'jquery-blockui' ); |
|
220 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
221 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
219 | + wp_enqueue_script('jquery-blockui'); |
|
220 | + wp_enqueue_script('wpinv-front-script'); |
|
221 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | public function admin_enqueue_scripts() { |
225 | 225 | global $post, $pagenow; |
226 | 226 | |
227 | 227 | $post_type = wpinv_admin_post_type(); |
228 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
228 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
229 | 229 | |
230 | - wp_deregister_style( 'font-awesome' ); |
|
231 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
232 | - wp_enqueue_style( 'font-awesome' ); |
|
230 | + wp_deregister_style('font-awesome'); |
|
231 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
232 | + wp_enqueue_style('font-awesome'); |
|
233 | 233 | |
234 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
235 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
234 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
235 | + wp_enqueue_style('jquery-ui-css'); |
|
236 | 236 | |
237 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
238 | - wp_enqueue_style( 'jquery-chosen' ); |
|
237 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
238 | + wp_enqueue_style('jquery-chosen'); |
|
239 | 239 | |
240 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
241 | - wp_enqueue_script( 'jquery-chosen' ); |
|
240 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
241 | + wp_enqueue_script('jquery-chosen'); |
|
242 | 242 | |
243 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
244 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
243 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
244 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
245 | 245 | |
246 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
247 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
246 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
247 | + wp_enqueue_style('wpinv_admin_style'); |
|
248 | 248 | |
249 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
250 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
249 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
250 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
251 | 251 | } |
252 | 252 | |
253 | - wp_enqueue_style( 'wp-color-picker' ); |
|
254 | - wp_enqueue_script( 'wp-color-picker' ); |
|
253 | + wp_enqueue_style('wp-color-picker'); |
|
254 | + wp_enqueue_script('wp-color-picker'); |
|
255 | 255 | |
256 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
256 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
257 | 257 | |
258 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), WPINV_VERSION ); |
|
259 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
258 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION); |
|
259 | + wp_enqueue_script('wpinv-admin-script'); |
|
260 | 260 | |
261 | 261 | $localize = array(); |
262 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
263 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
264 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
265 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
266 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
267 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
268 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
262 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
263 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
264 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
265 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
266 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
267 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
268 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
269 | 269 | $localize['tax'] = wpinv_tax_amount(); |
270 | 270 | $localize['discount'] = wpinv_discount_amount(); |
271 | 271 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -273,55 +273,55 @@ discard block |
||
273 | 273 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
274 | 274 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
275 | 275 | $localize['decimals'] = wpinv_decimals(); |
276 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
277 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
278 | - $localize['status_pending'] = wpinv_status_nicename( 'pending' ); |
|
279 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
280 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
281 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
282 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
283 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
284 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
285 | - $localize['hasGD'] = wpinv_gd_active();; |
|
276 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
277 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
278 | + $localize['status_pending'] = wpinv_status_nicename('pending'); |
|
279 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
280 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
281 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
282 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
283 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
284 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
285 | + $localize['hasGD'] = wpinv_gd_active(); ; |
|
286 | 286 | $localize['hasPM'] = wpinv_pm_active(); |
287 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
288 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
289 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
290 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
287 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
288 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
289 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
290 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
291 | 291 | |
292 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
292 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
293 | 293 | } |
294 | 294 | |
295 | - public function admin_body_class( $classes ) { |
|
295 | + public function admin_body_class($classes) { |
|
296 | 296 | global $pagenow; |
297 | 297 | |
298 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
298 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
299 | 299 | |
300 | 300 | $add_class = false; |
301 | - if ( $pagenow == 'admin.php' && $page ) { |
|
302 | - $add_class = strpos( $page, 'wpinv-' ); |
|
301 | + if ($pagenow == 'admin.php' && $page) { |
|
302 | + $add_class = strpos($page, 'wpinv-'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $settings_class = array(); |
306 | - if ( $page == 'wpinv-settings' ) { |
|
307 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
308 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
306 | + if ($page == 'wpinv-settings') { |
|
307 | + if (!empty($_REQUEST['tab'])) { |
|
308 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
312 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
311 | + if (!empty($_REQUEST['section'])) { |
|
312 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
313 | 313 | } |
314 | 314 | |
315 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
315 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
316 | 316 | } |
317 | 317 | |
318 | - if ( !empty( $settings_class ) ) { |
|
319 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
318 | + if (!empty($settings_class)) { |
|
319 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | $post_type = wpinv_admin_post_type(); |
323 | 323 | |
324 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
324 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
325 | 325 | return $classes .= ' wpinv'; |
326 | 326 | } else { |
327 | 327 | return $classes; |
@@ -333,26 +333,26 @@ discard block |
||
333 | 333 | public function admin_print_scripts_edit_php() { |
334 | 334 | $post_type = wpinv_admin_post_type(); |
335 | 335 | |
336 | - if ( $post_type == 'wpi_item' ) { |
|
337 | - wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); |
|
336 | + if ($post_type == 'wpi_item') { |
|
337 | + wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | 341 | public function wpinv_actions() { |
342 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
343 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
342 | + if (isset($_REQUEST['wpi_action'])) { |
|
343 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - public function pre_get_posts( $wp_query ) { |
|
348 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
349 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
347 | + public function pre_get_posts($wp_query) { |
|
348 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
349 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | return $wp_query; |
353 | 353 | } |
354 | 354 | |
355 | 355 | public function bp_invoicing_init() { |
356 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
356 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | \ No newline at end of file |
@@ -7,121 +7,121 @@ 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 ) { |
|
44 | +function wpinv_sanitize_amount($amount) { |
|
45 | 45 | $is_negative = false; |
46 | 46 | $thousands_sep = wpinv_thousands_separator(); |
47 | 47 | $decimal_sep = wpinv_decimal_separator(); |
48 | 48 | $decimals = wpinv_decimals(); |
49 | 49 | |
50 | 50 | // Sanitize the amount |
51 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
52 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
53 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
54 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
55 | - $amount = str_replace( '.', '', $amount ); |
|
51 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
52 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
53 | + $amount = str_replace($thousands_sep, '', $amount); |
|
54 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
55 | + $amount = str_replace('.', '', $amount); |
|
56 | 56 | } |
57 | 57 | |
58 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
59 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
60 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
58 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
59 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
60 | + $amount = str_replace($thousands_sep, '', $amount); |
|
61 | 61 | } |
62 | 62 | |
63 | - if( $amount < 0 ) { |
|
63 | + if ($amount < 0) { |
|
64 | 64 | $is_negative = true; |
65 | 65 | } |
66 | 66 | |
67 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
67 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
68 | 68 | |
69 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', $decimals, $amount ); |
|
70 | - $amount = number_format( (double) $amount, $decimals, '.', '' ); |
|
69 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', $decimals, $amount); |
|
70 | + $amount = number_format((double)$amount, $decimals, '.', ''); |
|
71 | 71 | |
72 | - if( $is_negative ) { |
|
72 | + if ($is_negative) { |
|
73 | 73 | $amount *= -1; |
74 | 74 | } |
75 | 75 | |
76 | - return apply_filters( 'wpinv_sanitize_amount', $amount ); |
|
76 | + return apply_filters('wpinv_sanitize_amount', $amount); |
|
77 | 77 | } |
78 | 78 | |
79 | -function wpinv_round_amount( $amount ) { |
|
79 | +function wpinv_round_amount($amount) { |
|
80 | 80 | $decimals = wpinv_decimals(); |
81 | 81 | |
82 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( $decimals ) ); |
|
82 | + $amount = round((double)$amount, wpinv_currency_decimal_filter($decimals)); |
|
83 | 83 | |
84 | - return apply_filters( 'wpinv_round_amount', $amount ); |
|
84 | + return apply_filters('wpinv_round_amount', $amount); |
|
85 | 85 | } |
86 | 86 | |
87 | -function wpinv_get_invoice_statuses( $trashed = false ) { |
|
87 | +function wpinv_get_invoice_statuses($trashed = false) { |
|
88 | 88 | $invoice_statuses = array( |
89 | - 'pending' => __( 'Pending Payment', 'invoicing' ), |
|
90 | - 'publish' => __( 'Paid', 'invoicing' ), |
|
91 | - 'wpi-processing' => __( 'Processing', 'invoicing' ), |
|
92 | - 'wpi-onhold' => __( 'On Hold', 'invoicing' ), |
|
93 | - 'wpi-refunded' => __( 'Refunded', 'invoicing' ), |
|
94 | - 'wpi-cancelled' => __( 'Cancelled', 'invoicing' ), |
|
95 | - 'wpi-failed' => __( 'Failed', 'invoicing' ), |
|
96 | - 'wpi-renewal' => __( 'Renewal Payment', 'invoicing' ) |
|
89 | + 'pending' => __('Pending Payment', 'invoicing'), |
|
90 | + 'publish' => __('Paid', 'invoicing'), |
|
91 | + 'wpi-processing' => __('Processing', 'invoicing'), |
|
92 | + 'wpi-onhold' => __('On Hold', 'invoicing'), |
|
93 | + 'wpi-refunded' => __('Refunded', 'invoicing'), |
|
94 | + 'wpi-cancelled' => __('Cancelled', 'invoicing'), |
|
95 | + 'wpi-failed' => __('Failed', 'invoicing'), |
|
96 | + 'wpi-renewal' => __('Renewal Payment', 'invoicing') |
|
97 | 97 | ); |
98 | 98 | |
99 | - if ( $trashed ) { |
|
100 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
99 | + if ($trashed) { |
|
100 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
101 | 101 | } |
102 | 102 | |
103 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
103 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
104 | 104 | } |
105 | 105 | |
106 | -function wpinv_status_nicename( $status ) { |
|
106 | +function wpinv_status_nicename($status) { |
|
107 | 107 | $statuses = wpinv_get_invoice_statuses(); |
108 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
108 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
109 | 109 | |
110 | 110 | return $status; |
111 | 111 | } |
112 | 112 | |
113 | 113 | function wpinv_get_currency() { |
114 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
114 | + $currency = wpinv_get_option('currency', 'USD'); |
|
115 | 115 | |
116 | - return apply_filters( 'wpinv_currency', $currency ); |
|
116 | + return apply_filters('wpinv_currency', $currency); |
|
117 | 117 | } |
118 | 118 | |
119 | -function wpinv_currency_symbol( $currency = '' ) { |
|
120 | - if ( empty( $currency ) ) { |
|
119 | +function wpinv_currency_symbol($currency = '') { |
|
120 | + if (empty($currency)) { |
|
121 | 121 | $currency = wpinv_get_currency(); |
122 | 122 | } |
123 | 123 | |
124 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
124 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
125 | 125 | 'AED' => 'د.إ', |
126 | 126 | 'ARS' => '$', |
127 | 127 | 'AUD' => '$', |
@@ -173,78 +173,78 @@ discard block |
||
173 | 173 | 'USD' => '$', |
174 | 174 | 'VND' => '₫', |
175 | 175 | 'ZAR' => 'R', |
176 | - ) ); |
|
176 | + )); |
|
177 | 177 | |
178 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '$'; |
|
178 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '$'; |
|
179 | 179 | |
180 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
180 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | function wpinv_currency_position() { |
184 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
184 | + $position = wpinv_get_option('currency_position', 'left'); |
|
185 | 185 | |
186 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
186 | + return apply_filters('wpinv_currency_position', $position); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | function wpinv_thousands_separator() { |
190 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
190 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
191 | 191 | |
192 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
192 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | function wpinv_decimal_separator() { |
196 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
196 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
197 | 197 | |
198 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
198 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | function wpinv_decimals() { |
202 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
202 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
203 | 203 | |
204 | - return absint( $decimals ); |
|
204 | + return absint($decimals); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_currencies() { |
208 | 208 | $currencies = array( |
209 | - 'USD' => __( 'US Dollars ($)', 'invoicing' ), |
|
210 | - 'EUR' => __( 'Euros (€)', 'invoicing' ), |
|
211 | - 'GBP' => __( 'Pounds Sterling (£)', 'invoicing' ), |
|
212 | - 'AUD' => __( 'Australian Dollars ($)', 'invoicing' ), |
|
213 | - 'BRL' => __( 'Brazilian Real (R$)', 'invoicing' ), |
|
214 | - 'CAD' => __( 'Canadian Dollars ($)', 'invoicing' ), |
|
215 | - 'CLP' => __( 'Chilean Peso ($)', 'invoicing' ), |
|
216 | - 'CNY' => __( 'Chinese Yuan (¥)', 'invoicing' ), |
|
217 | - 'CZK' => __( 'Czech Koruna (Kč)', 'invoicing' ), |
|
218 | - 'DKK' => __( 'Danish Krone (DKK)', 'invoicing' ), |
|
219 | - 'HKD' => __( 'Hong Kong Dollar ($)', 'invoicing' ), |
|
220 | - 'HUF' => __( 'Hungarian Forint (Ft)', 'invoicing' ), |
|
221 | - 'INR' => __( 'Indian Rupee (₹)', 'invoicing' ), |
|
222 | - 'ILS' => __( 'Israeli Shekel (₪)', 'invoicing' ), |
|
223 | - 'JPY' => __( 'Japanese Yen (¥)', 'invoicing' ), |
|
224 | - 'MYR' => __( 'Malaysian Ringgit (RM)', 'invoicing' ), |
|
225 | - 'MXN' => __( 'Mexican Peso ($)', 'invoicing' ), |
|
226 | - 'NZD' => __( 'New Zealand Dollar ($)', 'invoicing' ), |
|
227 | - 'NOK' => __( 'Norwegian Krone (kr)', 'invoicing' ), |
|
228 | - 'PHP' => __( 'Philippine Peso (₱)', 'invoicing' ), |
|
229 | - 'PLN' => __( 'Polish Zloty (zł)', 'invoicing' ), |
|
230 | - 'SGD' => __( 'Singapore Dollar ($)', 'invoicing' ), |
|
231 | - 'SEK' => __( 'Swedish Krona (kr)', 'invoicing' ), |
|
232 | - 'CHF' => __( 'Swiss Franc (CHF)', 'invoicing' ), |
|
233 | - 'TWD' => __( 'Taiwan New Dollar (NT$)', 'invoicing' ), |
|
234 | - 'THB' => __( 'Thai Baht (฿)', 'invoicing' ), |
|
235 | - 'TRY' => __( 'Turkish Lira (₺)', 'invoicing' ), |
|
236 | - 'RIAL' => __( 'Iranian Rial (﷼)', 'invoicing' ), |
|
237 | - 'RUB' => __( 'Russian Ruble (₽)', 'invoicing' ), |
|
238 | - 'ZAR' => __( 'South African Rand (R)', 'invoicing' ) |
|
209 | + 'USD' => __('US Dollars ($)', 'invoicing'), |
|
210 | + 'EUR' => __('Euros (€)', 'invoicing'), |
|
211 | + 'GBP' => __('Pounds Sterling (£)', 'invoicing'), |
|
212 | + 'AUD' => __('Australian Dollars ($)', 'invoicing'), |
|
213 | + 'BRL' => __('Brazilian Real (R$)', 'invoicing'), |
|
214 | + 'CAD' => __('Canadian Dollars ($)', 'invoicing'), |
|
215 | + 'CLP' => __('Chilean Peso ($)', 'invoicing'), |
|
216 | + 'CNY' => __('Chinese Yuan (¥)', 'invoicing'), |
|
217 | + 'CZK' => __('Czech Koruna (Kč)', 'invoicing'), |
|
218 | + 'DKK' => __('Danish Krone (DKK)', 'invoicing'), |
|
219 | + 'HKD' => __('Hong Kong Dollar ($)', 'invoicing'), |
|
220 | + 'HUF' => __('Hungarian Forint (Ft)', 'invoicing'), |
|
221 | + 'INR' => __('Indian Rupee (₹)', 'invoicing'), |
|
222 | + 'ILS' => __('Israeli Shekel (₪)', 'invoicing'), |
|
223 | + 'JPY' => __('Japanese Yen (¥)', 'invoicing'), |
|
224 | + 'MYR' => __('Malaysian Ringgit (RM)', 'invoicing'), |
|
225 | + 'MXN' => __('Mexican Peso ($)', 'invoicing'), |
|
226 | + 'NZD' => __('New Zealand Dollar ($)', 'invoicing'), |
|
227 | + 'NOK' => __('Norwegian Krone (kr)', 'invoicing'), |
|
228 | + 'PHP' => __('Philippine Peso (₱)', 'invoicing'), |
|
229 | + 'PLN' => __('Polish Zloty (zł)', 'invoicing'), |
|
230 | + 'SGD' => __('Singapore Dollar ($)', 'invoicing'), |
|
231 | + 'SEK' => __('Swedish Krona (kr)', 'invoicing'), |
|
232 | + 'CHF' => __('Swiss Franc (CHF)', 'invoicing'), |
|
233 | + 'TWD' => __('Taiwan New Dollar (NT$)', 'invoicing'), |
|
234 | + 'THB' => __('Thai Baht (฿)', 'invoicing'), |
|
235 | + 'TRY' => __('Turkish Lira (₺)', 'invoicing'), |
|
236 | + 'RIAL' => __('Iranian Rial (﷼)', 'invoicing'), |
|
237 | + 'RUB' => __('Russian Ruble (₽)', 'invoicing'), |
|
238 | + 'ZAR' => __('South African Rand (R)', 'invoicing') |
|
239 | 239 | ); |
240 | 240 | |
241 | - asort( $currencies ); |
|
241 | + asort($currencies); |
|
242 | 242 | |
243 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
243 | + return apply_filters('wpinv_currencies', $currencies); |
|
244 | 244 | } |
245 | 245 | |
246 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
247 | - if( empty( $currency ) ) { |
|
246 | +function wpinv_price($amount = '', $currency = '') { |
|
247 | + if (empty($currency)) { |
|
248 | 248 | $currency = wpinv_get_currency(); |
249 | 249 | } |
250 | 250 | |
@@ -252,14 +252,14 @@ discard block |
||
252 | 252 | |
253 | 253 | $negative = $amount < 0; |
254 | 254 | |
255 | - if ( $negative ) { |
|
256 | - $amount = substr( $amount, 1 ); |
|
255 | + if ($negative) { |
|
256 | + $amount = substr($amount, 1); |
|
257 | 257 | } |
258 | 258 | |
259 | - $symbol = wpinv_currency_symbol( $currency ); |
|
259 | + $symbol = wpinv_currency_symbol($currency); |
|
260 | 260 | |
261 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
262 | - switch ( $currency ) { |
|
261 | + if ($position == 'left' || $position == 'left_space') { |
|
262 | + switch ($currency) { |
|
263 | 263 | case "GBP" : |
264 | 264 | case "BRL" : |
265 | 265 | case "EUR" : |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | case "NZD" : |
272 | 272 | case "SGD" : |
273 | 273 | case "JPY" : |
274 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
274 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
275 | 275 | break; |
276 | 276 | default : |
277 | 277 | //$price = $currency . ' ' . $amount; |
278 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
278 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
279 | 279 | break; |
280 | 280 | } |
281 | 281 | } else { |
282 | - switch ( $currency ) { |
|
282 | + switch ($currency) { |
|
283 | 283 | case "GBP" : |
284 | 284 | case "BRL" : |
285 | 285 | case "EUR" : |
@@ -290,82 +290,82 @@ discard block |
||
290 | 290 | case "MXN" : |
291 | 291 | case "SGD" : |
292 | 292 | case "JPY" : |
293 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
293 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
294 | 294 | break; |
295 | 295 | default : |
296 | 296 | //$price = $amount . ' ' . $currency; |
297 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
297 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
298 | 298 | break; |
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
302 | - if ( $negative ) { |
|
302 | + if ($negative) { |
|
303 | 303 | $price = '-' . $price; |
304 | 304 | } |
305 | 305 | |
306 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
306 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
307 | 307 | |
308 | 308 | return $price; |
309 | 309 | } |
310 | 310 | |
311 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
311 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
312 | 312 | $thousands_sep = wpinv_thousands_separator(); |
313 | 313 | $decimal_sep = wpinv_decimal_separator(); |
314 | 314 | |
315 | - if ( $decimals === NULL ) { |
|
315 | + if ($decimals === NULL) { |
|
316 | 316 | $decimals = wpinv_decimals(); |
317 | 317 | } |
318 | 318 | |
319 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
320 | - $whole = substr( $amount, 0, $sep_found ); |
|
321 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
319 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
320 | + $whole = substr($amount, 0, $sep_found); |
|
321 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
322 | 322 | $amount = $whole . '.' . $part; |
323 | 323 | } |
324 | 324 | |
325 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
326 | - $amount = str_replace( ',', '', $amount ); |
|
325 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
326 | + $amount = str_replace(',', '', $amount); |
|
327 | 327 | } |
328 | 328 | |
329 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
330 | - $amount = str_replace( ' ', '', $amount ); |
|
329 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
330 | + $amount = str_replace(' ', '', $amount); |
|
331 | 331 | } |
332 | 332 | |
333 | - if ( empty( $amount ) ) { |
|
333 | + if (empty($amount)) { |
|
334 | 334 | $amount = 0; |
335 | 335 | } |
336 | 336 | |
337 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
338 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
337 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
338 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
339 | 339 | |
340 | - if ( $calculate ) { |
|
341 | - if ( $thousands_sep === "," ) { |
|
342 | - $formatted = str_replace( ",", "", $formatted ); |
|
340 | + if ($calculate) { |
|
341 | + if ($thousands_sep === ",") { |
|
342 | + $formatted = str_replace(",", "", $formatted); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $decimal_sep === "," ) { |
|
346 | - $formatted = str_replace( ",", ".", $formatted ); |
|
345 | + if ($decimal_sep === ",") { |
|
346 | + $formatted = str_replace(",", ".", $formatted); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
350 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
350 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
351 | 351 | } |
352 | 352 | |
353 | -function wpinv_sanitize_key( $key ) { |
|
353 | +function wpinv_sanitize_key($key) { |
|
354 | 354 | $raw_key = $key; |
355 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
355 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
356 | 356 | |
357 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
357 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_get_file_extension( $str ) { |
|
361 | - $parts = explode( '.', $str ); |
|
362 | - return end( $parts ); |
|
360 | +function wpinv_get_file_extension($str) { |
|
361 | + $parts = explode('.', $str); |
|
362 | + return end($parts); |
|
363 | 363 | } |
364 | 364 | |
365 | -function wpinv_string_is_image_url( $str ) { |
|
366 | - $ext = wpinv_get_file_extension( $str ); |
|
365 | +function wpinv_string_is_image_url($str) { |
|
366 | + $ext = wpinv_get_file_extension($str); |
|
367 | 367 | |
368 | - switch ( strtolower( $ext ) ) { |
|
368 | + switch (strtolower($ext)) { |
|
369 | 369 | case 'jpeg'; |
370 | 370 | case 'jpg'; |
371 | 371 | $return = true; |
@@ -381,32 +381,32 @@ discard block |
||
381 | 381 | break; |
382 | 382 | } |
383 | 383 | |
384 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
384 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
385 | 385 | } |
386 | 386 | |
387 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
388 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
387 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
388 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
389 | 389 | |
390 | - if ( true === $should_log ) { |
|
390 | + if (true === $should_log) { |
|
391 | 391 | $label = ''; |
392 | - if ( $file && $file !== '' ) { |
|
393 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
392 | + if ($file && $file !== '') { |
|
393 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( $title && $title !== '' ) { |
|
396 | + if ($title && $title !== '') { |
|
397 | 397 | $label = $label !== '' ? $label . ' ' : ''; |
398 | 398 | $label .= $title . ' '; |
399 | 399 | } |
400 | 400 | |
401 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
401 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
402 | 402 | |
403 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
404 | - error_log( $label . print_r( $log, true ) ); |
|
403 | + if (is_array($log) || is_object($log)) { |
|
404 | + error_log($label . print_r($log, true)); |
|
405 | 405 | } else { |
406 | - error_log( $label . $log ); |
|
406 | + error_log($label . $log); |
|
407 | 407 | } |
408 | 408 | |
409 | - if ( $exit ) { |
|
409 | + if ($exit) { |
|
410 | 410 | exit; |
411 | 411 | } |
412 | 412 | } |
@@ -414,65 +414,65 @@ discard block |
||
414 | 414 | |
415 | 415 | function wpinv_is_ajax_disabled() { |
416 | 416 | $retval = false; |
417 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
417 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
418 | 418 | } |
419 | 419 | |
420 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
420 | +function wpinv_get_current_page_url($nocache = false) { |
|
421 | 421 | global $wp; |
422 | 422 | |
423 | - if ( get_option( 'permalink_structure' ) ) { |
|
424 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
423 | + if (get_option('permalink_structure')) { |
|
424 | + $base = trailingslashit(home_url($wp->request)); |
|
425 | 425 | } else { |
426 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
427 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
426 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
427 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | $scheme = is_ssl() ? 'https' : 'http'; |
431 | - $uri = set_url_scheme( $base, $scheme ); |
|
431 | + $uri = set_url_scheme($base, $scheme); |
|
432 | 432 | |
433 | - if ( is_front_page() ) { |
|
434 | - $uri = home_url( '/' ); |
|
435 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
433 | + if (is_front_page()) { |
|
434 | + $uri = home_url('/'); |
|
435 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
436 | 436 | $uri = wpinv_get_checkout_uri(); |
437 | 437 | } |
438 | 438 | |
439 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
439 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
440 | 440 | |
441 | - if ( $nocache ) { |
|
442 | - $uri = wpinv_add_cache_busting( $uri ); |
|
441 | + if ($nocache) { |
|
442 | + $uri = wpinv_add_cache_busting($uri); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | return $uri; |
446 | 446 | } |
447 | 447 | |
448 | 448 | function wpinv_get_php_arg_separator_output() { |
449 | - return ini_get( 'arg_separator.output' ); |
|
449 | + return ini_get('arg_separator.output'); |
|
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_rgb_from_hex( $color ) { |
|
453 | - $color = str_replace( '#', '', $color ); |
|
452 | +function wpinv_rgb_from_hex($color) { |
|
453 | + $color = str_replace('#', '', $color); |
|
454 | 454 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
455 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
455 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
456 | 456 | |
457 | 457 | $rgb = array(); |
458 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
459 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
460 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
458 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
459 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
460 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
461 | 461 | |
462 | 462 | return $rgb; |
463 | 463 | } |
464 | 464 | |
465 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
466 | - $base = wpinv_rgb_from_hex( $color ); |
|
465 | +function wpinv_hex_darker($color, $factor = 30) { |
|
466 | + $base = wpinv_rgb_from_hex($color); |
|
467 | 467 | $color = '#'; |
468 | 468 | |
469 | - foreach ( $base as $k => $v ) { |
|
469 | + foreach ($base as $k => $v) { |
|
470 | 470 | $amount = $v / 100; |
471 | - $amount = round( $amount * $factor ); |
|
471 | + $amount = round($amount * $factor); |
|
472 | 472 | $new_decimal = $v - $amount; |
473 | 473 | |
474 | - $new_hex_component = dechex( $new_decimal ); |
|
475 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
474 | + $new_hex_component = dechex($new_decimal); |
|
475 | + if (strlen($new_hex_component) < 2) { |
|
476 | 476 | $new_hex_component = "0" . $new_hex_component; |
477 | 477 | } |
478 | 478 | $color .= $new_hex_component; |
@@ -481,18 +481,18 @@ discard block |
||
481 | 481 | return $color; |
482 | 482 | } |
483 | 483 | |
484 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
485 | - $base = wpinv_rgb_from_hex( $color ); |
|
484 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
485 | + $base = wpinv_rgb_from_hex($color); |
|
486 | 486 | $color = '#'; |
487 | 487 | |
488 | - foreach ( $base as $k => $v ) { |
|
488 | + foreach ($base as $k => $v) { |
|
489 | 489 | $amount = 255 - $v; |
490 | 490 | $amount = $amount / 100; |
491 | - $amount = round( $amount * $factor ); |
|
491 | + $amount = round($amount * $factor); |
|
492 | 492 | $new_decimal = $v + $amount; |
493 | 493 | |
494 | - $new_hex_component = dechex( $new_decimal ); |
|
495 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
494 | + $new_hex_component = dechex($new_decimal); |
|
495 | + if (strlen($new_hex_component) < 2) { |
|
496 | 496 | $new_hex_component = "0" . $new_hex_component; |
497 | 497 | } |
498 | 498 | $color .= $new_hex_component; |
@@ -501,22 +501,22 @@ discard block |
||
501 | 501 | return $color; |
502 | 502 | } |
503 | 503 | |
504 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
505 | - $hex = str_replace( '#', '', $color ); |
|
504 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
505 | + $hex = str_replace('#', '', $color); |
|
506 | 506 | |
507 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
508 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
509 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
507 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
508 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
509 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
510 | 510 | |
511 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
511 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
512 | 512 | |
513 | 513 | return $brightness > 155 ? $dark : $light; |
514 | 514 | } |
515 | 515 | |
516 | -function wpinv_format_hex( $hex ) { |
|
517 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
516 | +function wpinv_format_hex($hex) { |
|
517 | + $hex = trim(str_replace('#', '', $hex)); |
|
518 | 518 | |
519 | - if ( strlen( $hex ) == 3 ) { |
|
519 | + if (strlen($hex) == 3) { |
|
520 | 520 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
521 | 521 | } |
522 | 522 | |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
537 | 537 | * @return string |
538 | 538 | */ |
539 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
540 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
541 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
539 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
540 | + if (function_exists('mb_strimwidth')) { |
|
541 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
542 | 542 | } |
543 | 543 | |
544 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
544 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -553,28 +553,28 @@ discard block |
||
553 | 553 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
554 | 554 | * @return int Returns the number of characters in string. |
555 | 555 | */ |
556 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
557 | - if ( function_exists( 'mb_strlen' ) ) { |
|
558 | - return mb_strlen( $str, $encoding ); |
|
556 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
557 | + if (function_exists('mb_strlen')) { |
|
558 | + return mb_strlen($str, $encoding); |
|
559 | 559 | } |
560 | 560 | |
561 | - return strlen( $str ); |
|
561 | + return strlen($str); |
|
562 | 562 | } |
563 | 563 | |
564 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
565 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
566 | - return mb_strtolower( $str, $encoding ); |
|
564 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
565 | + if (function_exists('mb_strtolower')) { |
|
566 | + return mb_strtolower($str, $encoding); |
|
567 | 567 | } |
568 | 568 | |
569 | - return strtolower( $str ); |
|
569 | + return strtolower($str); |
|
570 | 570 | } |
571 | 571 | |
572 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
573 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
574 | - return mb_strtoupper( $str, $encoding ); |
|
572 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
573 | + if (function_exists('mb_strtoupper')) { |
|
574 | + return mb_strtoupper($str, $encoding); |
|
575 | 575 | } |
576 | 576 | |
577 | - return strtoupper( $str ); |
|
577 | + return strtoupper($str); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -588,12 +588,12 @@ discard block |
||
588 | 588 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
589 | 589 | * @return int Returns the position of the first occurrence of search in the string. |
590 | 590 | */ |
591 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
592 | - if ( function_exists( 'mb_strpos' ) ) { |
|
593 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
591 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
592 | + if (function_exists('mb_strpos')) { |
|
593 | + return mb_strpos($str, $find, $offset, $encoding); |
|
594 | 594 | } |
595 | 595 | |
596 | - return strpos( $str, $find, $offset ); |
|
596 | + return strpos($str, $find, $offset); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -607,12 +607,12 @@ discard block |
||
607 | 607 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
608 | 608 | * @return int Returns the position of the last occurrence of search. |
609 | 609 | */ |
610 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
611 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
612 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
610 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
611 | + if (function_exists('mb_strrpos')) { |
|
612 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
613 | 613 | } |
614 | 614 | |
615 | - return strrpos( $str, $find, $offset ); |
|
615 | + return strrpos($str, $find, $offset); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -627,16 +627,16 @@ discard block |
||
627 | 627 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
628 | 628 | * @return string |
629 | 629 | */ |
630 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
631 | - if ( function_exists( 'mb_substr' ) ) { |
|
632 | - if ( $length === null ) { |
|
633 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
630 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
631 | + if (function_exists('mb_substr')) { |
|
632 | + if ($length === null) { |
|
633 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
634 | 634 | } else { |
635 | - return mb_substr( $str, $start, $length, $encoding ); |
|
635 | + return mb_substr($str, $start, $length, $encoding); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
639 | - return substr( $str, $start, $length ); |
|
639 | + return substr($str, $start, $length); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -648,48 +648,48 @@ discard block |
||
648 | 648 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
649 | 649 | * @return string The width of string. |
650 | 650 | */ |
651 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
652 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
653 | - return mb_strwidth( $str, $encoding ); |
|
651 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
652 | + if (function_exists('mb_strwidth')) { |
|
653 | + return mb_strwidth($str, $encoding); |
|
654 | 654 | } |
655 | 655 | |
656 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
656 | + return wpinv_utf8_strlen($str, $encoding); |
|
657 | 657 | } |
658 | 658 | |
659 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
660 | - if ( function_exists( 'mb_strlen' ) ) { |
|
661 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
659 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
660 | + if (function_exists('mb_strlen')) { |
|
661 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
662 | 662 | $str_end = ""; |
663 | 663 | |
664 | - if ( $lower_str_end ) { |
|
665 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
664 | + if ($lower_str_end) { |
|
665 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
666 | 666 | } else { |
667 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
667 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | return $first_letter . $str_end; |
671 | 671 | } |
672 | 672 | |
673 | - return ucfirst( $str ); |
|
673 | + return ucfirst($str); |
|
674 | 674 | } |
675 | 675 | |
676 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
677 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
678 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
676 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
677 | + if (function_exists('mb_convert_case')) { |
|
678 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
679 | 679 | } |
680 | 680 | |
681 | - return ucwords( $str ); |
|
681 | + return ucwords($str); |
|
682 | 682 | } |
683 | 683 | |
684 | -function wpinv_period_in_days( $period, $unit ) { |
|
685 | - $period = absint( $period ); |
|
684 | +function wpinv_period_in_days($period, $unit) { |
|
685 | + $period = absint($period); |
|
686 | 686 | |
687 | - if ( $period > 0 ) { |
|
688 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
687 | + if ($period > 0) { |
|
688 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
689 | 689 | $period = $period * 7; |
690 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
690 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
691 | 691 | $period = $period * 30; |
692 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
692 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
693 | 693 | $period = $period * 365; |
694 | 694 | } |
695 | 695 | } |