@@ -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_manual_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_manual_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_manual_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 | /* |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | // Record the pending payment |
44 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
44 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
45 | 45 | |
46 | - if ( !empty( $invoice ) ) { |
|
47 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
48 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
46 | + if (!empty($invoice)) { |
|
47 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
48 | + wpinv_update_payment_status($invoice, 'publish'); |
|
49 | 49 | |
50 | 50 | // Empty the shopping cart |
51 | 51 | wpinv_empty_cart(); |
52 | 52 | |
53 | - do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
53 | + do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data); |
|
54 | 54 | |
55 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
55 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
56 | 56 | } else { |
57 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
57 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
58 | 58 | // If errors are present, send the user back to the purchase page so they can be corrected |
59 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
59 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
60 | 60 | } |
61 | 61 | } |
62 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
63 | 62 | \ No newline at end of file |
63 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
64 | 64 | \ No newline at end of file |
@@ -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,132 +24,132 @@ 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' ); |
|
143 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
144 | 144 | |
145 | 145 | function wpinv_is_worldpay_valid_for_use() { |
146 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ))); |
|
146 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'))); |
|
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_check_worldpay_currency_support( $gateway_list ) { |
|
150 | - if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) { |
|
151 | - unset( $gateway_list['worldpay'] ); |
|
149 | +function wpinv_check_worldpay_currency_support($gateway_list) { |
|
150 | + if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) { |
|
151 | + unset($gateway_list['worldpay']); |
|
152 | 152 | } |
153 | 153 | return $gateway_list; |
154 | 154 | } |
155 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 ); |
|
156 | 155 | \ No newline at end of file |
156 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1); |
|
157 | 157 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * The Subscriptions DB Class |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | 'transaction_id' => '', |
69 | 69 | 'parent_payment_id' => 0, |
70 | 70 | 'product_id' => 0, |
71 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
72 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
71 | + 'created' => date('Y-m-d H:i:s'), |
|
72 | + 'expiration' => date('Y-m-d H:i:s'), |
|
73 | 73 | 'trial_period' => '', |
74 | 74 | 'status' => '', |
75 | 75 | 'profile_id' => '', |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @access public |
83 | 83 | * @since 1.0.0 |
84 | 84 | */ |
85 | - public function get_subscriptions( $args = array() ) { |
|
85 | + public function get_subscriptions($args = array()) { |
|
86 | 86 | global $wpdb; |
87 | 87 | |
88 | 88 | $defaults = array( |
89 | - 'number' => get_option( 'posts_per_page' ), |
|
89 | + 'number' => get_option('posts_per_page'), |
|
90 | 90 | 'offset' => 0, |
91 | 91 | 'search' => '', |
92 | 92 | 'customer_id' => 0, |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | 'order' => 'DESC' |
95 | 95 | ); |
96 | 96 | |
97 | - $args = wp_parse_args( $args, $defaults ); |
|
97 | + $args = wp_parse_args($args, $defaults); |
|
98 | 98 | |
99 | - if( $args['number'] < 1 ) { |
|
99 | + if ($args['number'] < 1) { |
|
100 | 100 | $args['number'] = 999999999999; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $where = ' WHERE 1=1 '; |
104 | 104 | |
105 | 105 | // specific customers |
106 | - if( ! empty( $args['id'] ) ) { |
|
106 | + if (!empty($args['id'])) { |
|
107 | 107 | |
108 | - if( is_array( $args['id'] ) ) { |
|
109 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
108 | + if (is_array($args['id'])) { |
|
109 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
110 | 110 | } else { |
111 | - $ids = intval( $args['id'] ); |
|
111 | + $ids = intval($args['id']); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | // Specific products |
119 | - if( ! empty( $args['product_id'] ) ) { |
|
119 | + if (!empty($args['product_id'])) { |
|
120 | 120 | |
121 | - if( is_array( $args['product_id'] ) ) { |
|
122 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
121 | + if (is_array($args['product_id'])) { |
|
122 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
123 | 123 | } else { |
124 | - $product_ids = intval( $args['product_id'] ); |
|
124 | + $product_ids = intval($args['product_id']); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | } |
130 | 130 | |
131 | 131 | // Specific parent payments |
132 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
132 | + if (!empty($args['parent_payment_id'])) { |
|
133 | 133 | |
134 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
135 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
134 | + if (is_array($args['parent_payment_id'])) { |
|
135 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
136 | 136 | } else { |
137 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
137 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | // Specific transaction IDs |
145 | - if( ! empty( $args['transaction_id'] ) ) { |
|
145 | + if (!empty($args['transaction_id'])) { |
|
146 | 146 | |
147 | - if( is_array( $args['transaction_id'] ) ) { |
|
148 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
147 | + if (is_array($args['transaction_id'])) { |
|
148 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
149 | 149 | } else { |
150 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
150 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) "; |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | // Subscriptoins for specific customers |
158 | - if( ! empty( $args['customer_id'] ) ) { |
|
158 | + if (!empty($args['customer_id'])) { |
|
159 | 159 | |
160 | - if( is_array( $args['customer_id'] ) ) { |
|
161 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
160 | + if (is_array($args['customer_id'])) { |
|
161 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
162 | 162 | } else { |
163 | - $customer_ids = intval( $args['customer_id'] ); |
|
163 | + $customer_ids = intval($args['customer_id']); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // Subscriptions for specific profile IDs |
171 | - if( ! empty( $args['profile_id'] ) ) { |
|
171 | + if (!empty($args['profile_id'])) { |
|
172 | 172 | |
173 | - if( is_array( $args['profile_id'] ) ) { |
|
174 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
173 | + if (is_array($args['profile_id'])) { |
|
174 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
175 | 175 | } else { |
176 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
176 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | $where .= " AND `profile_id` IN( '{$profile_ids}' ) "; |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | // Subscriptions for specific statuses |
184 | - if( ! empty( $args['status'] ) ) { |
|
184 | + if (!empty($args['status'])) { |
|
185 | 185 | |
186 | - if( is_array( $args['status'] ) ) { |
|
187 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
186 | + if (is_array($args['status'])) { |
|
187 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
188 | 188 | } else { |
189 | - $statuses = sanitize_text_field( $args['status'] ); |
|
189 | + $statuses = sanitize_text_field($args['status']); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $where .= " AND `status` IN( '{$statuses}' ) "; |
@@ -194,21 +194,21 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | // Subscriptions created for a specific date or in a date range |
197 | - if( ! empty( $args['date'] ) ) { |
|
197 | + if (!empty($args['date'])) { |
|
198 | 198 | |
199 | - if( is_array( $args['date'] ) ) { |
|
199 | + if (is_array($args['date'])) { |
|
200 | 200 | |
201 | - if( ! empty( $args['date']['start'] ) ) { |
|
201 | + if (!empty($args['date']['start'])) { |
|
202 | 202 | |
203 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
203 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
204 | 204 | |
205 | 205 | $where .= " AND `created` >= '{$start}'"; |
206 | 206 | |
207 | 207 | } |
208 | 208 | |
209 | - if( ! empty( $args['date']['end'] ) ) { |
|
209 | + if (!empty($args['date']['end'])) { |
|
210 | 210 | |
211 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
211 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
212 | 212 | |
213 | 213 | $where .= " AND `created` <= '{$end}'"; |
214 | 214 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | |
217 | 217 | } else { |
218 | 218 | |
219 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
220 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
221 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
219 | + $year = date('Y', strtotime($args['date'])); |
|
220 | + $month = date('m', strtotime($args['date'])); |
|
221 | + $day = date('d', strtotime($args['date'])); |
|
222 | 222 | |
223 | 223 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
224 | 224 | } |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | // Subscriptions with a specific expiration date or in an expiration date range |
229 | - if( ! empty( $args['expiration'] ) ) { |
|
229 | + if (!empty($args['expiration'])) { |
|
230 | 230 | |
231 | - if( is_array( $args['expiration'] ) ) { |
|
231 | + if (is_array($args['expiration'])) { |
|
232 | 232 | |
233 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
233 | + if (!empty($args['expiration']['start'])) { |
|
234 | 234 | |
235 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
235 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
236 | 236 | |
237 | 237 | $where .= " AND `expiration` >= '{$start}'"; |
238 | 238 | |
239 | 239 | } |
240 | 240 | |
241 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
241 | + if (!empty($args['expiration']['end'])) { |
|
242 | 242 | |
243 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
243 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
244 | 244 | |
245 | 245 | $where .= " AND `expiration` <= '{$end}'"; |
246 | 246 | |
@@ -248,73 +248,73 @@ discard block |
||
248 | 248 | |
249 | 249 | } else { |
250 | 250 | |
251 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
252 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
253 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
251 | + $year = date('Y', strtotime($args['expiration'])); |
|
252 | + $month = date('m', strtotime($args['expiration'])); |
|
253 | + $day = date('d', strtotime($args['expiration'])); |
|
254 | 254 | |
255 | 255 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
259 | 259 | |
260 | - if ( ! empty( $args['search'] ) ) { |
|
260 | + if (!empty($args['search'])) { |
|
261 | 261 | |
262 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
262 | + if (false !== strpos('id:', $args['search'])) { |
|
263 | 263 | |
264 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
265 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
264 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
265 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
266 | 266 | |
267 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
267 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
268 | 268 | |
269 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
270 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
269 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
270 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
271 | 271 | |
272 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
272 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
273 | 273 | |
274 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
275 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
274 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
275 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
276 | 276 | |
277 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
277 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
278 | 278 | |
279 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
280 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
279 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
280 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
281 | 281 | |
282 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
282 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
283 | 283 | |
284 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
285 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
284 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
285 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
286 | 286 | |
287 | 287 | } else { |
288 | 288 | |
289 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
289 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | } |
294 | 294 | |
295 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby']; |
|
295 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby']; |
|
296 | 296 | |
297 | - if( 'amount' == $args['orderby'] ) { |
|
297 | + if ('amount' == $args['orderby']) { |
|
298 | 298 | $args['orderby'] = 'amount+0'; |
299 | 299 | } |
300 | 300 | |
301 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) ); |
|
301 | + $cache_key = md5('wpinv_subscriptions_' . serialize($args)); |
|
302 | 302 | |
303 | - $subscriptions = wp_cache_get( $cache_key, 'subscriptions' ); |
|
303 | + $subscriptions = wp_cache_get($cache_key, 'subscriptions'); |
|
304 | 304 | |
305 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
306 | - $args['order'] = esc_sql( $args['order'] ); |
|
305 | + $args['orderby'] = esc_sql($args['orderby']); |
|
306 | + $args['order'] = esc_sql($args['order']); |
|
307 | 307 | |
308 | - if( $subscriptions === false ) { |
|
309 | - $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); |
|
308 | + if ($subscriptions === false) { |
|
309 | + $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); |
|
310 | 310 | |
311 | - if( ! empty( $subscriptions ) ) { |
|
311 | + if (!empty($subscriptions)) { |
|
312 | 312 | |
313 | - foreach( $subscriptions as $key => $subscription ) { |
|
314 | - $subscriptions[ $key ] = new WPInv_Subscription( $subscription ); |
|
313 | + foreach ($subscriptions as $key => $subscription) { |
|
314 | + $subscriptions[$key] = new WPInv_Subscription($subscription); |
|
315 | 315 | } |
316 | 316 | |
317 | - wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 ); |
|
317 | + wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600); |
|
318 | 318 | |
319 | 319 | } |
320 | 320 | |
@@ -329,19 +329,19 @@ discard block |
||
329 | 329 | * @access public |
330 | 330 | * @since 1.0.0 |
331 | 331 | */ |
332 | - public function count( $args = array() ) { |
|
332 | + public function count($args = array()) { |
|
333 | 333 | |
334 | 334 | global $wpdb; |
335 | 335 | |
336 | 336 | $where = ' WHERE 1=1 '; |
337 | 337 | |
338 | 338 | // specific customers |
339 | - if( ! empty( $args['id'] ) ) { |
|
339 | + if (!empty($args['id'])) { |
|
340 | 340 | |
341 | - if( is_array( $args['id'] ) ) { |
|
342 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
341 | + if (is_array($args['id'])) { |
|
342 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
343 | 343 | } else { |
344 | - $ids = intval( $args['id'] ); |
|
344 | + $ids = intval($args['id']); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | } |
350 | 350 | |
351 | 351 | // Specific products |
352 | - if( ! empty( $args['product_id'] ) ) { |
|
352 | + if (!empty($args['product_id'])) { |
|
353 | 353 | |
354 | - if( is_array( $args['product_id'] ) ) { |
|
355 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
354 | + if (is_array($args['product_id'])) { |
|
355 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
356 | 356 | } else { |
357 | - $product_ids = intval( $args['product_id'] ); |
|
357 | + $product_ids = intval($args['product_id']); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -362,12 +362,12 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | // Specific parent payments |
365 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
365 | + if (!empty($args['parent_payment_id'])) { |
|
366 | 366 | |
367 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
368 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
367 | + if (is_array($args['parent_payment_id'])) { |
|
368 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
369 | 369 | } else { |
370 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
370 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | // Subscriptoins for specific customers |
378 | - if( ! empty( $args['customer_id'] ) ) { |
|
378 | + if (!empty($args['customer_id'])) { |
|
379 | 379 | |
380 | - if( is_array( $args['customer_id'] ) ) { |
|
381 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
380 | + if (is_array($args['customer_id'])) { |
|
381 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
382 | 382 | } else { |
383 | - $customer_ids = intval( $args['customer_id'] ); |
|
383 | + $customer_ids = intval($args['customer_id']); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -388,12 +388,12 @@ discard block |
||
388 | 388 | } |
389 | 389 | |
390 | 390 | // Subscriptions for specific profile IDs |
391 | - if( ! empty( $args['profile_id'] ) ) { |
|
391 | + if (!empty($args['profile_id'])) { |
|
392 | 392 | |
393 | - if( is_array( $args['profile_id'] ) ) { |
|
394 | - $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) ); |
|
393 | + if (is_array($args['profile_id'])) { |
|
394 | + $profile_ids = implode(',', array_map('intval', $args['profile_id'])); |
|
395 | 395 | } else { |
396 | - $profile_ids = intval( $args['profile_id'] ); |
|
396 | + $profile_ids = intval($args['profile_id']); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | $where .= " AND `profile_id` IN( {$profile_ids} ) "; |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | } |
402 | 402 | |
403 | 403 | // Specific transaction IDs |
404 | - if( ! empty( $args['transaction_id'] ) ) { |
|
404 | + if (!empty($args['transaction_id'])) { |
|
405 | 405 | |
406 | - if( is_array( $args['transaction_id'] ) ) { |
|
407 | - $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
406 | + if (is_array($args['transaction_id'])) { |
|
407 | + $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id'])); |
|
408 | 408 | } else { |
409 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
409 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $where .= " AND `transaction_id` IN( {$transaction_ids} ) "; |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | } |
415 | 415 | |
416 | 416 | // Subscriptions for specific statuses |
417 | - if( ! empty( $args['status'] ) ) { |
|
417 | + if (!empty($args['status'])) { |
|
418 | 418 | |
419 | - if( is_array( $args['status'] ) ) { |
|
420 | - $statuses = implode( ',', $args['status'] ); |
|
419 | + if (is_array($args['status'])) { |
|
420 | + $statuses = implode(',', $args['status']); |
|
421 | 421 | $where .= " AND `status` IN( {$statuses} ) "; |
422 | 422 | } else { |
423 | 423 | $statuses = $args['status']; |
@@ -429,21 +429,21 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | // Subscriptions created for a specific date or in a date range |
432 | - if( ! empty( $args['date'] ) ) { |
|
432 | + if (!empty($args['date'])) { |
|
433 | 433 | |
434 | - if( is_array( $args['date'] ) ) { |
|
434 | + if (is_array($args['date'])) { |
|
435 | 435 | |
436 | - if( ! empty( $args['date']['start'] ) ) { |
|
436 | + if (!empty($args['date']['start'])) { |
|
437 | 437 | |
438 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
438 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
439 | 439 | |
440 | 440 | $where .= " AND `created` >= '{$start}'"; |
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | - if( ! empty( $args['date']['end'] ) ) { |
|
444 | + if (!empty($args['date']['end'])) { |
|
445 | 445 | |
446 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
446 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
447 | 447 | |
448 | 448 | $where .= " AND `created` <= '{$end}'"; |
449 | 449 | |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | |
452 | 452 | } else { |
453 | 453 | |
454 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
455 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
456 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
454 | + $year = date('Y', strtotime($args['date'])); |
|
455 | + $month = date('m', strtotime($args['date'])); |
|
456 | + $day = date('d', strtotime($args['date'])); |
|
457 | 457 | |
458 | 458 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
459 | 459 | } |
@@ -461,21 +461,21 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | // Subscriptions with a specific expiration date or in an expiration date range |
464 | - if( ! empty( $args['expiration'] ) ) { |
|
464 | + if (!empty($args['expiration'])) { |
|
465 | 465 | |
466 | - if( is_array( $args['expiration'] ) ) { |
|
466 | + if (is_array($args['expiration'])) { |
|
467 | 467 | |
468 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
468 | + if (!empty($args['expiration']['start'])) { |
|
469 | 469 | |
470 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
470 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
471 | 471 | |
472 | 472 | $where .= " AND `expiration` >= '{$start}'"; |
473 | 473 | |
474 | 474 | } |
475 | 475 | |
476 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
476 | + if (!empty($args['expiration']['end'])) { |
|
477 | 477 | |
478 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
478 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
479 | 479 | |
480 | 480 | $where .= " AND `expiration` <= '{$end}'"; |
481 | 481 | |
@@ -483,64 +483,64 @@ discard block |
||
483 | 483 | |
484 | 484 | } else { |
485 | 485 | |
486 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
487 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
488 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
486 | + $year = date('Y', strtotime($args['expiration'])); |
|
487 | + $month = date('m', strtotime($args['expiration'])); |
|
488 | + $day = date('d', strtotime($args['expiration'])); |
|
489 | 489 | |
490 | 490 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
491 | 491 | } |
492 | 492 | |
493 | 493 | } |
494 | 494 | |
495 | - if ( ! empty( $args['search'] ) ) { |
|
495 | + if (!empty($args['search'])) { |
|
496 | 496 | |
497 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
497 | + if (false !== strpos('id:', $args['search'])) { |
|
498 | 498 | |
499 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
500 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
499 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
500 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
501 | 501 | |
502 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
502 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
503 | 503 | |
504 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
505 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
504 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
505 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
506 | 506 | |
507 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
507 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
508 | 508 | |
509 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
510 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
509 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
510 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
511 | 511 | |
512 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
512 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
513 | 513 | |
514 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
515 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
514 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
515 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
516 | 516 | |
517 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
517 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
518 | 518 | |
519 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
520 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
519 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
520 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
521 | 521 | |
522 | 522 | } else { |
523 | 523 | |
524 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
524 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
525 | 525 | |
526 | 526 | } |
527 | 527 | |
528 | 528 | } |
529 | 529 | |
530 | - $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) ); |
|
530 | + $cache_key = md5('wpinv_subscriptions_count' . serialize($args)); |
|
531 | 531 | |
532 | - $count = wp_cache_get( $cache_key, 'subscriptions' ); |
|
532 | + $count = wp_cache_get($cache_key, 'subscriptions'); |
|
533 | 533 | |
534 | - if( $count === false ) { |
|
534 | + if ($count === false) { |
|
535 | 535 | |
536 | 536 | $sql = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; |
537 | - $count = $wpdb->get_var( $sql ); |
|
537 | + $count = $wpdb->get_var($sql); |
|
538 | 538 | |
539 | - wp_cache_set( $cache_key, $count, 'subscriptions', 3600 ); |
|
539 | + wp_cache_set($cache_key, $count, 'subscriptions', 3600); |
|
540 | 540 | |
541 | 541 | } |
542 | 542 | |
543 | - return absint( $count ); |
|
543 | + return absint($count); |
|
544 | 544 | |
545 | 545 | } |
546 | 546 | |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | public function create_table() { |
554 | 554 | global $wpdb; |
555 | 555 | |
556 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
556 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
557 | 557 | |
558 | 558 | $sql = "CREATE TABLE " . $this->table_name . " ( |
559 | 559 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | KEY customer_and_status ( customer_id, status) |
579 | 579 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
580 | 580 | |
581 | - dbDelta( $sql ); |
|
581 | + dbDelta($sql); |
|
582 | 582 | |
583 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
583 | + update_option($this->table_name . '_db_version', $this->version); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | } |
587 | 587 | \ No newline at end of file |
@@ -1,73 +1,73 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'admin_menu', 'wpinv_add_options_link', 10 ); |
|
7 | +add_action('admin_menu', 'wpinv_add_options_link', 10); |
|
8 | 8 | function wpinv_add_options_link() { |
9 | 9 | global $menu; |
10 | 10 | |
11 | - if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) { |
|
11 | + if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) { |
|
12 | 12 | return; |
13 | 13 | } |
14 | 14 | |
15 | - $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' ); |
|
15 | + $capability = apply_filters('invoicing_capability', 'manage_invoicing'); |
|
16 | 16 | |
17 | - if ( current_user_can( 'manage_options' ) ) { |
|
18 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
17 | + if (current_user_can('manage_options')) { |
|
18 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
19 | 19 | } |
20 | 20 | |
21 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
21 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
22 | 22 | |
23 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
23 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
24 | 24 | |
25 | - $wpi_settings_page = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' ); |
|
25 | + $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page'); |
|
26 | 26 | } |
27 | 27 | |
28 | -add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 ); |
|
28 | +add_action('admin_menu', 'wpinv_remove_admin_submenus', 999); |
|
29 | 29 | function wpinv_remove_admin_submenus() { |
30 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
30 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
31 | 31 | } |
32 | 32 | |
33 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
34 | -function wpinv_discount_columns( $existing_columns ) { |
|
33 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
34 | +function wpinv_discount_columns($existing_columns) { |
|
35 | 35 | $columns = array(); |
36 | 36 | $columns['cb'] = $existing_columns['cb']; |
37 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
38 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
39 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
40 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
41 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
42 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
43 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
37 | + $columns['name'] = __('Name', 'invoicing'); |
|
38 | + $columns['code'] = __('Code', 'invoicing'); |
|
39 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
40 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
41 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
42 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
43 | + $columns['status'] = __('Status', 'invoicing'); |
|
44 | 44 | |
45 | 45 | return $columns; |
46 | 46 | } |
47 | 47 | |
48 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
49 | -function wpinv_discount_custom_column( $column ) { |
|
48 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
49 | +function wpinv_discount_custom_column($column) { |
|
50 | 50 | global $post; |
51 | 51 | |
52 | 52 | $discount = $post; |
53 | 53 | |
54 | - switch ( $column ) { |
|
54 | + switch ($column) { |
|
55 | 55 | case 'name' : |
56 | - echo get_the_title( $discount->ID ); |
|
56 | + echo get_the_title($discount->ID); |
|
57 | 57 | break; |
58 | 58 | case 'code' : |
59 | - echo wpinv_get_discount_code( $discount->ID ); |
|
59 | + echo wpinv_get_discount_code($discount->ID); |
|
60 | 60 | break; |
61 | 61 | case 'amount' : |
62 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
62 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
63 | 63 | break; |
64 | 64 | case 'usage_limit' : |
65 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
65 | + echo wpinv_get_discount_uses($discount->ID); |
|
66 | 66 | break; |
67 | 67 | case 'usage' : |
68 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
69 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
70 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
68 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
69 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
70 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
71 | 71 | } else { |
72 | 72 | $usage .= ' ∞'; |
73 | 73 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | echo $usage; |
76 | 76 | break; |
77 | 77 | case 'start_date' : |
78 | - if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) { |
|
79 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) ); |
|
78 | + if ($start_date = wpinv_get_discount_start_date($discount->ID)) { |
|
79 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date)); |
|
80 | 80 | } else { |
81 | 81 | $value = '-'; |
82 | 82 | } |
@@ -84,163 +84,163 @@ discard block |
||
84 | 84 | echo $value; |
85 | 85 | break; |
86 | 86 | case 'expiry_date' : |
87 | - if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) { |
|
88 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) ); |
|
87 | + if ($expiration = wpinv_get_discount_expiration($discount->ID)) { |
|
88 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration)); |
|
89 | 89 | } else { |
90 | - $value = __( 'Never', 'invoicing' ); |
|
90 | + $value = __('Never', 'invoicing'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | echo $value; |
94 | 94 | break; |
95 | 95 | break; |
96 | 96 | case 'description' : |
97 | - echo wp_kses_post( $post->post_excerpt ); |
|
97 | + echo wp_kses_post($post->post_excerpt); |
|
98 | 98 | break; |
99 | 99 | case 'status' : |
100 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
100 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
101 | 101 | |
102 | - echo wpinv_discount_status( $status ); |
|
102 | + echo wpinv_discount_status($status); |
|
103 | 103 | break; |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
108 | -function wpinv_post_row_actions( $actions, $post ) { |
|
109 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
107 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
108 | +function wpinv_post_row_actions($actions, $post) { |
|
109 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
110 | 110 | |
111 | - if ( $post_type == 'wpi_invoice' ) { |
|
111 | + if ($post_type == 'wpi_invoice') { |
|
112 | 112 | $actions = array(); |
113 | 113 | } |
114 | 114 | |
115 | - if ( $post_type == 'wpi_discount' ) { |
|
116 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
115 | + if ($post_type == 'wpi_discount') { |
|
116 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $actions; |
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
123 | - $row_actions = array(); |
|
124 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
125 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
122 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
123 | + $row_actions = array(); |
|
124 | + $edit_link = get_edit_post_link($discount->ID); |
|
125 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
126 | 126 | |
127 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
128 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
129 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
130 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
127 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
128 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
129 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
130 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
134 | - if ( isset( $row_actions['delete'] ) ) { |
|
135 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
133 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
134 | + if (isset($row_actions['delete'])) { |
|
135 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
136 | 136 | } |
137 | 137 | } else { |
138 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
138 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
142 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
142 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
143 | 143 | |
144 | 144 | return $row_actions; |
145 | 145 | } |
146 | 146 | |
147 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
148 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
149 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
147 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
148 | +function wpinv_table_primary_column($default, $screen_id) { |
|
149 | + if ('edit-wpi_invoice' === $screen_id) { |
|
150 | 150 | return 'name'; |
151 | 151 | } |
152 | 152 | |
153 | 153 | return $default; |
154 | 154 | } |
155 | 155 | |
156 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
157 | - if ( !$display ) { |
|
156 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
157 | + if (!$display) { |
|
158 | 158 | return array(); |
159 | 159 | } |
160 | 160 | |
161 | 161 | $actions = array( |
162 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
163 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
164 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
162 | + 'activate' => __('Activate', 'invoicing'), |
|
163 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
164 | + 'delete' => __('Delete', 'invoicing'), |
|
165 | 165 | ); |
166 | 166 | $two = ''; |
167 | 167 | $which = 'top'; |
168 | 168 | echo '</div><div class="alignleft actions bulkactions">'; |
169 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
170 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
171 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
169 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
170 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
171 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
172 | 172 | |
173 | - foreach ( $actions as $name => $title ) { |
|
173 | + foreach ($actions as $name => $title) { |
|
174 | 174 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
175 | 175 | |
176 | 176 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
177 | 177 | } |
178 | 178 | echo "</select>"; |
179 | 179 | |
180 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
180 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
181 | 181 | |
182 | 182 | echo '</div><div class="alignleft actions">'; |
183 | 183 | } |
184 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
184 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
185 | 185 | |
186 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
187 | - if ( $post_type == 'wpi_discount' ) { |
|
186 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
187 | + if ($post_type == 'wpi_discount') { |
|
188 | 188 | $disable = true; |
189 | 189 | } |
190 | 190 | |
191 | 191 | return $disable; |
192 | 192 | } |
193 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
193 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
194 | 194 | |
195 | 195 | function wpinv_restrict_manage_posts() { |
196 | 196 | global $typenow; |
197 | 197 | |
198 | - if( 'wpi_discount' == $typenow ) { |
|
198 | + if ('wpi_discount' == $typenow) { |
|
199 | 199 | wpinv_discount_filters(); |
200 | 200 | } |
201 | 201 | } |
202 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
202 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
203 | 203 | |
204 | 204 | function wpinv_discount_filters() { |
205 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
205 | + echo wpinv_discount_bulk_actions(array(), true); |
|
206 | 206 | |
207 | 207 | ?> |
208 | 208 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
209 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
209 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
210 | 210 | <?php |
211 | 211 | $types = wpinv_get_discount_types(); |
212 | 212 | |
213 | - foreach ( $types as $name => $type ) { |
|
214 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
213 | + foreach ($types as $name => $type) { |
|
214 | + echo '<option value="' . esc_attr($name) . '"'; |
|
215 | 215 | |
216 | - if ( isset( $_GET['discount_type'] ) ) |
|
217 | - selected( $name, $_GET['discount_type'] ); |
|
216 | + if (isset($_GET['discount_type'])) |
|
217 | + selected($name, $_GET['discount_type']); |
|
218 | 218 | |
219 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
219 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
220 | 220 | } |
221 | 221 | ?> |
222 | 222 | </select> |
223 | 223 | <?php |
224 | 224 | } |
225 | 225 | |
226 | -function wpinv_request( $vars ) { |
|
226 | +function wpinv_request($vars) { |
|
227 | 227 | global $typenow, $wp_query, $wp_post_statuses; |
228 | 228 | |
229 | - if ( 'wpi_invoice' === $typenow ) { |
|
230 | - if ( !isset( $vars['post_status'] ) ) { |
|
229 | + if ('wpi_invoice' === $typenow) { |
|
230 | + if (!isset($vars['post_status'])) { |
|
231 | 231 | $post_statuses = wpinv_get_invoice_statuses(); |
232 | 232 | |
233 | - foreach ( $post_statuses as $status => $value ) { |
|
234 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
235 | - unset( $post_statuses[ $status ] ); |
|
233 | + foreach ($post_statuses as $status => $value) { |
|
234 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
235 | + unset($post_statuses[$status]); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
239 | + $vars['post_status'] = array_keys($post_statuses); |
|
240 | 240 | } |
241 | 241 | |
242 | - if ( isset( $vars['orderby'] ) ) { |
|
243 | - if ( 'amount' == $vars['orderby'] ) { |
|
242 | + if (isset($vars['orderby'])) { |
|
243 | + if ('amount' == $vars['orderby']) { |
|
244 | 244 | $vars = array_merge( |
245 | 245 | $vars, |
246 | 246 | array( |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | 'orderby' => 'meta_value_num' |
249 | 249 | ) |
250 | 250 | ); |
251 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
251 | + } else if ('customer' == $vars['orderby']) { |
|
252 | 252 | $vars = array_merge( |
253 | 253 | $vars, |
254 | 254 | array( |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | 'orderby' => 'meta_value' |
257 | 257 | ) |
258 | 258 | ); |
259 | - } else if ( 'number' == $vars['orderby'] ) { |
|
259 | + } else if ('number' == $vars['orderby']) { |
|
260 | 260 | $vars = array_merge( |
261 | 261 | $vars, |
262 | 262 | array( |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | 'orderby' => 'meta_value' |
265 | 265 | ) |
266 | 266 | ); |
267 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
267 | + } else if ('payment_date' == $vars['orderby']) { |
|
268 | 268 | $vars = array_merge( |
269 | 269 | $vars, |
270 | 270 | array( |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | ); |
275 | 275 | } |
276 | 276 | } |
277 | - } else if ( 'wpi_item' == $typenow ) { |
|
277 | + } else if ('wpi_item' == $typenow) { |
|
278 | 278 | // Check if 'orderby' is set to "price" |
279 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
279 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
280 | 280 | $vars = array_merge( |
281 | 281 | $vars, |
282 | 282 | array( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Check if "orderby" is set to "vat_rule" |
290 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
290 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
291 | 291 | $vars = array_merge( |
292 | 292 | $vars, |
293 | 293 | array( |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | // Check if "orderby" is set to "vat_class" |
301 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
301 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
302 | 302 | $vars = array_merge( |
303 | 303 | $vars, |
304 | 304 | array( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | } |
310 | 310 | |
311 | 311 | // Check if "orderby" is set to "type" |
312 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
312 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
313 | 313 | $vars = array_merge( |
314 | 314 | $vars, |
315 | 315 | array( |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | // Check if "orderby" is set to "recurring" |
323 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
323 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
324 | 324 | $vars = array_merge( |
325 | 325 | $vars, |
326 | 326 | array( |
@@ -330,120 +330,120 @@ discard block |
||
330 | 330 | ); |
331 | 331 | } |
332 | 332 | |
333 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
333 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
334 | 334 | // Filter vat rule type |
335 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
335 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
336 | 336 | $meta_query[] = array( |
337 | 337 | 'key' => '_wpinv_vat_rule', |
338 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
338 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
339 | 339 | 'compare' => '=' |
340 | 340 | ); |
341 | 341 | } |
342 | 342 | |
343 | 343 | // Filter vat class |
344 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
344 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
345 | 345 | $meta_query[] = array( |
346 | 346 | 'key' => '_wpinv_vat_class', |
347 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
347 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
348 | 348 | 'compare' => '=' |
349 | 349 | ); |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Filter item type |
353 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
353 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
354 | 354 | $meta_query[] = array( |
355 | 355 | 'key' => '_wpinv_type', |
356 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
356 | + 'value' => sanitize_text_field($_GET['type']), |
|
357 | 357 | 'compare' => '=' |
358 | 358 | ); |
359 | 359 | } |
360 | 360 | |
361 | - if ( !empty( $meta_query ) ) { |
|
361 | + if (!empty($meta_query)) { |
|
362 | 362 | $vars['meta_query'] = $meta_query; |
363 | 363 | } |
364 | - } else if ( 'wpi_discount' == $typenow ) { |
|
365 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
364 | + } else if ('wpi_discount' == $typenow) { |
|
365 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
366 | 366 | // Filter vat rule type |
367 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
367 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
368 | 368 | $meta_query[] = array( |
369 | 369 | 'key' => '_wpi_discount_type', |
370 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
370 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
371 | 371 | 'compare' => '=' |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | |
375 | - if ( !empty( $meta_query ) ) { |
|
375 | + if (!empty($meta_query)) { |
|
376 | 376 | $vars['meta_query'] = $meta_query; |
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | 380 | return $vars; |
381 | 381 | } |
382 | -add_filter( 'request', 'wpinv_request' ); |
|
382 | +add_filter('request', 'wpinv_request'); |
|
383 | 383 | |
384 | 384 | function wpinv_options_page() { |
385 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
385 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
386 | 386 | |
387 | - if ( $page !== 'wpinv-settings' ) { |
|
387 | + if ($page !== 'wpinv-settings') { |
|
388 | 388 | return; |
389 | 389 | } |
390 | 390 | |
391 | 391 | $settings_tabs = wpinv_get_settings_tabs(); |
392 | 392 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
393 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
394 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
393 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
394 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
395 | 395 | $key = 'main'; |
396 | 396 | |
397 | - if ( is_array( $sections ) ) { |
|
398 | - $key = key( $sections ); |
|
397 | + if (is_array($sections)) { |
|
398 | + $key = key($sections); |
|
399 | 399 | } |
400 | 400 | |
401 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
402 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
401 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
402 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
403 | 403 | ob_start(); |
404 | 404 | ?> |
405 | 405 | <div class="wrap"> |
406 | 406 | <h1 class="nav-tab-wrapper"> |
407 | 407 | <?php |
408 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
409 | - $tab_url = add_query_arg( array( |
|
408 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
409 | + $tab_url = add_query_arg(array( |
|
410 | 410 | 'settings-updated' => false, |
411 | 411 | 'tab' => $tab_id, |
412 | - ) ); |
|
412 | + )); |
|
413 | 413 | |
414 | 414 | // Remove the section from the tabs so we always end up at the main section |
415 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
416 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
415 | + $tab_url = remove_query_arg('section', $tab_url); |
|
416 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
417 | 417 | |
418 | 418 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
419 | 419 | |
420 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
421 | - echo esc_html( $tab_name ); |
|
420 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
421 | + echo esc_html($tab_name); |
|
422 | 422 | echo '</a>'; |
423 | 423 | } |
424 | 424 | ?> |
425 | 425 | </h1> |
426 | 426 | <?php |
427 | - $number_of_sections = count( $sections ); |
|
427 | + $number_of_sections = count($sections); |
|
428 | 428 | $number = 0; |
429 | - if ( $number_of_sections > 1 ) { |
|
429 | + if ($number_of_sections > 1) { |
|
430 | 430 | echo '<div><ul class="subsubsub">'; |
431 | - foreach( $sections as $section_id => $section_name ) { |
|
431 | + foreach ($sections as $section_id => $section_name) { |
|
432 | 432 | echo '<li>'; |
433 | 433 | $number++; |
434 | - $tab_url = add_query_arg( array( |
|
434 | + $tab_url = add_query_arg(array( |
|
435 | 435 | 'settings-updated' => false, |
436 | 436 | 'tab' => $active_tab, |
437 | 437 | 'section' => $section_id |
438 | - ) ); |
|
439 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
438 | + )); |
|
439 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
440 | 440 | $class = ''; |
441 | - if ( $section == $section_id ) { |
|
441 | + if ($section == $section_id) { |
|
442 | 442 | $class = 'current'; |
443 | 443 | } |
444 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
444 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
445 | 445 | |
446 | - if ( $number != $number_of_sections ) { |
|
446 | + if ($number != $number_of_sections) { |
|
447 | 447 | echo ' | '; |
448 | 448 | } |
449 | 449 | echo '</li>'; |
@@ -455,19 +455,19 @@ discard block |
||
455 | 455 | <form method="post" action="options.php"> |
456 | 456 | <table class="form-table"> |
457 | 457 | <?php |
458 | - settings_fields( 'wpinv_settings' ); |
|
458 | + settings_fields('wpinv_settings'); |
|
459 | 459 | |
460 | - if ( 'main' === $section ) { |
|
461 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
460 | + if ('main' === $section) { |
|
461 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
462 | 462 | } |
463 | 463 | |
464 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
465 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
466 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
464 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
465 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
466 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
467 | 467 | |
468 | 468 | // For backwards compatibility |
469 | - if ( 'main' === $section ) { |
|
470 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
469 | + if ('main' === $section) { |
|
470 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
471 | 471 | } |
472 | 472 | ?> |
473 | 473 | </table> |
@@ -480,53 +480,53 @@ discard block |
||
480 | 480 | echo $content; |
481 | 481 | } |
482 | 482 | |
483 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
483 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
484 | 484 | global $pagenow, $typenow; |
485 | 485 | |
486 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
487 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
488 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
486 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
487 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
488 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
489 | 489 | } |
490 | 490 | |
491 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
491 | + if (!wpinv_item_is_editable($post_id)) { |
|
492 | 492 | $classes[] = 'wpi-editable-n'; |
493 | 493 | } |
494 | 494 | } |
495 | 495 | return $classes; |
496 | 496 | } |
497 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
497 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
498 | 498 | |
499 | 499 | function wpinv_check_quick_edit() { |
500 | 500 | global $pagenow, $current_screen, $wpinv_item_screen; |
501 | 501 | |
502 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
503 | - if ( empty( $wpinv_item_screen ) ) { |
|
504 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
502 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
503 | + if (empty($wpinv_item_screen)) { |
|
504 | + if ($current_screen->post_type == 'wpi_item') { |
|
505 | 505 | $wpinv_item_screen = 'y'; |
506 | 506 | } else { |
507 | 507 | $wpinv_item_screen = 'n'; |
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
511 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
512 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
513 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
511 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
512 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
513 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
517 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
517 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
518 | 518 | |
519 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
520 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
521 | - unset( $actions['inline hide-if-no-js'] ); |
|
519 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
520 | + if (isset($actions['inline hide-if-no-js'])) { |
|
521 | + unset($actions['inline hide-if-no-js']); |
|
522 | 522 | } |
523 | 523 | |
524 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
525 | - if ( isset( $actions['trash'] ) ) { |
|
526 | - unset( $actions['trash'] ); |
|
524 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
525 | + if (isset($actions['trash'])) { |
|
526 | + unset($actions['trash']); |
|
527 | 527 | } |
528 | - if ( isset( $actions['delete'] ) ) { |
|
529 | - unset( $actions['delete'] ); |
|
528 | + if (isset($actions['delete'])) { |
|
529 | + unset($actions['delete']); |
|
530 | 530 | } |
531 | 531 | } |
532 | 532 | |
@@ -543,19 +543,19 @@ discard block |
||
543 | 543 | * @param int $post_parent (default: 0) Parent for the new page |
544 | 544 | * @return int page ID |
545 | 545 | */ |
546 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
546 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
547 | 547 | global $wpdb; |
548 | 548 | |
549 | - $option_value = wpinv_get_option( $option ); |
|
549 | + $option_value = wpinv_get_option($option); |
|
550 | 550 | |
551 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
552 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
551 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
552 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
553 | 553 | // Valid page is already in place |
554 | 554 | return $page_object->ID; |
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - if(!empty($post_parent)){ |
|
558 | + if (!empty($post_parent)) { |
|
559 | 559 | $page = get_page_by_path($post_parent); |
560 | 560 | if ($page) { |
561 | 561 | $post_parent = $page->ID; |
@@ -564,40 +564,40 @@ discard block |
||
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
567 | - if ( strlen( $page_content ) > 0 ) { |
|
567 | + if (strlen($page_content) > 0) { |
|
568 | 568 | // Search for an existing page with the specified page content (typically a shortcode) |
569 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
569 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
570 | 570 | } else { |
571 | 571 | // Search for an existing page with the specified page slug |
572 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
572 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
573 | 573 | } |
574 | 574 | |
575 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
575 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
576 | 576 | |
577 | - if ( $valid_page_found ) { |
|
578 | - if ( $option ) { |
|
579 | - wpinv_update_option( $option, $valid_page_found ); |
|
577 | + if ($valid_page_found) { |
|
578 | + if ($option) { |
|
579 | + wpinv_update_option($option, $valid_page_found); |
|
580 | 580 | } |
581 | 581 | return $valid_page_found; |
582 | 582 | } |
583 | 583 | |
584 | 584 | // Search for a matching valid trashed page |
585 | - if ( strlen( $page_content ) > 0 ) { |
|
585 | + if (strlen($page_content) > 0) { |
|
586 | 586 | // Search for an existing page with the specified page content (typically a shortcode) |
587 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
587 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
588 | 588 | } else { |
589 | 589 | // Search for an existing page with the specified page slug |
590 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
590 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
591 | 591 | } |
592 | 592 | |
593 | - if ( $trashed_page_found ) { |
|
593 | + if ($trashed_page_found) { |
|
594 | 594 | $page_id = $trashed_page_found; |
595 | 595 | $page_data = array( |
596 | 596 | 'ID' => $page_id, |
597 | 597 | 'post_status' => 'publish', |
598 | 598 | 'post_parent' => $post_parent, |
599 | 599 | ); |
600 | - wp_update_post( $page_data ); |
|
600 | + wp_update_post($page_data); |
|
601 | 601 | } else { |
602 | 602 | $page_data = array( |
603 | 603 | 'post_status' => 'publish', |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | 'post_parent' => $post_parent, |
610 | 610 | 'comment_status' => 'closed', |
611 | 611 | ); |
612 | - $page_id = wp_insert_post( $page_data ); |
|
612 | + $page_id = wp_insert_post($page_data); |
|
613 | 613 | } |
614 | 614 | |
615 | - if ( $option ) { |
|
616 | - wpinv_update_option( $option, (int)$page_id ); |
|
615 | + if ($option) { |
|
616 | + wpinv_update_option($option, (int)$page_id); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | return $page_id; |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | |
9 | 9 | |
10 | 10 | // Exit if accessed directly |
11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
11 | +if (!defined('ABSPATH')) exit; |
|
12 | 12 | |
13 | 13 | |
14 | 14 | // Load WP_List_Table if not loaded |
15 | -if( ! class_exists( 'WP_List_Table' ) ) { |
|
15 | +if (!class_exists('WP_List_Table')) { |
|
16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
17 | 17 | } |
18 | 18 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public $pending_count = 0; |
36 | 36 | public $expired_count = 0; |
37 | 37 | public $completed_count = 0; |
38 | - public $trialling_count = 0; |
|
38 | + public $trialling_count = 0; |
|
39 | 39 | public $cancelled_count = 0; |
40 | 40 | public $failing_count = 0; |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * @since 1.0.0 |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - function __construct(){ |
|
49 | + function __construct() { |
|
50 | 50 | global $status, $page; |
51 | 51 | |
52 | 52 | // Set parent defaults |
53 | - parent::__construct( array( |
|
53 | + parent::__construct(array( |
|
54 | 54 | 'singular' => 'subscription', |
55 | 55 | 'plural' => 'subscriptions', |
56 | 56 | 'ajax' => false |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | |
59 | 59 | $this->get_subscription_counts(); |
60 | 60 | |
@@ -69,28 +69,28 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function get_views() { |
71 | 71 | |
72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
72 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | 74 | $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
75 | 75 | $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | 77 | $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | 81 | |
82 | 82 | $views = array( |
83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
83 | + 'all' => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), |
|
84 | + 'active' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), |
|
85 | + 'pending' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), |
|
86 | + 'expired' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), |
|
87 | + 'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), |
|
88 | + 'trialling' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), |
|
89 | + 'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), |
|
90 | + 'failing' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), |
|
91 | 91 | ); |
92 | 92 | |
93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
93 | + return apply_filters('wpinv_recurring_subscriptions_table_views', $views); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -104,27 +104,27 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function search_box( $text, $input_id ) { |
|
107 | + public function search_box($text, $input_id) { |
|
108 | 108 | |
109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
109 | + if (empty($_REQUEST['s']) && !$this->has_items()) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $input_id = $input_id . '-search-input'; |
114 | 114 | |
115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
115 | + if (!empty($_REQUEST['orderby'])) { |
|
116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
119 | + if (!empty($_REQUEST['order'])) { |
|
120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; |
|
121 | 121 | } |
122 | 122 | ?> |
123 | 123 | <p class="search-box"> |
124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
|
124 | + <?php do_action('wpinv_recurring_subscription_search_box'); ?> |
|
125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
127 | - <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
|
127 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> |
|
128 | 128 | </p> |
129 | 129 | <?php |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @since 1.0.0 |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - function column_default( $item, $column_name ) { |
|
139 | + function column_default($item, $column_name) { |
|
140 | 140 | return $item->$column_name; |
141 | 141 | } |
142 | 142 | |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * @since 1.0.0 |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - function column_sub_id( $item ) { |
|
151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
|
150 | + function column_sub_id($item) { |
|
151 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @since 1.0.0 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - function column_customer_id( $item ) { |
|
162 | - $subscriber = get_userdata( $item->customer_id ); |
|
163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
161 | + function column_customer_id($item) { |
|
162 | + $subscriber = get_userdata($item->customer_id); |
|
163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | 164 | |
165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @since 1.0.0 |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - function column_status( $item ) { |
|
175 | + function column_status($item) { |
|
176 | 176 | return $item->get_status_label(); |
177 | 177 | } |
178 | 178 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @since 1.0.0 |
184 | 184 | * @return string |
185 | 185 | */ |
186 | - function column_period( $item ) { |
|
186 | + function column_period($item) { |
|
187 | 187 | |
188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency); |
|
189 | 189 | |
190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @since 1.0.0 |
198 | 198 | * @return string |
199 | 199 | */ |
200 | - function column_bill_times( $item ) { |
|
201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
200 | + function column_bill_times($item) { |
|
201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @since 1.0.0 |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - function column_initial_amount( $item ) { |
|
212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
211 | + function column_initial_amount($item) { |
|
212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @since 1.0.0 |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - function column_renewal_date( $item ) { |
|
223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
222 | + function column_renewal_date($item) { |
|
223 | + return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @since 1.0.0 |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - function column_parent_payment_id( $item ) { |
|
234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
233 | + function column_parent_payment_id($item) { |
|
234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>'; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @since 1.0.0 |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - function column_product_id( $item ) { |
|
245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
244 | + function column_product_id($item) { |
|
245 | + return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @since 2.0 |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - function column_actions( $item ) { |
|
256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
255 | + function column_actions($item) { |
|
256 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @return array |
266 | 266 | */ |
267 | 267 | |
268 | - function get_columns(){ |
|
268 | + function get_columns() { |
|
269 | 269 | $columns = array( |
270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | - 'status' => __( 'Status', 'invoicing' ), |
|
273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
270 | + 'sub_id' => __('ID', 'invoicing'), |
|
271 | + 'customer_id' => __('Customer', 'invoicing'), |
|
272 | + 'status' => __('Status', 'invoicing'), |
|
273 | + 'period' => __('Billing Cycle', 'invoicing'), |
|
274 | + 'initial_amount' => __('Initial Amount', 'invoicing'), |
|
275 | + 'bill_times' => __('Times Billed', 'invoicing'), |
|
276 | + 'renewal_date' => __('Renewal Date', 'invoicing'), |
|
277 | + 'parent_payment_id' => __('Invoice', 'invoicing'), |
|
278 | + 'product_id' => __('Item', 'invoicing'), |
|
279 | + 'actions' => __('Actions', 'invoicing'), |
|
280 | 280 | ); |
281 | 281 | |
282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
282 | + return apply_filters('wpinv_report_subscription_columns', $columns); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @return int |
291 | 291 | */ |
292 | 292 | function get_paged() { |
293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -306,16 +306,16 @@ discard block |
||
306 | 306 | |
307 | 307 | $db = new WPInv_Subscriptions_DB; |
308 | 308 | |
309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
310 | 310 | |
311 | 311 | $this->total_count = $db->count(); |
312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
312 | + $this->active_count = $db->count(array('status' => 'active', 'search' => $search)); |
|
313 | + $this->pending_count = $db->count(array('status' => 'pending', 'search' => $search)); |
|
314 | + $this->expired_count = $db->count(array('status' => 'expired', 'search' => $search)); |
|
315 | + $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); |
|
316 | + $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); |
|
317 | + $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); |
|
318 | + $this->failing_count = $db->count(array('status' => 'failing', 'search' => $search)); |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | |
@@ -336,28 +336,28 @@ discard block |
||
336 | 336 | |
337 | 337 | $columns = $this->get_columns(); |
338 | 338 | $hidden = array(); // No hidden columns |
339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
340 | 340 | $sortable = $this->get_sortable_columns(); |
341 | 341 | |
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
343 | 343 | |
344 | 344 | $current_page = $this->get_pagenum(); |
345 | 345 | |
346 | 346 | $db = new WPInv_Subscriptions_DB; |
347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
348 | 348 | $args = array( |
349 | 349 | 'number' => $this->per_page, |
350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
350 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
351 | 351 | 'search' => $search |
352 | 352 | ); |
353 | 353 | |
354 | - if ( 'any' !== $status ) { |
|
354 | + if ('any' !== $status) { |
|
355 | 355 | $args['status'] = $status; |
356 | 356 | } |
357 | 357 | |
358 | - $this->items = $db->get_subscriptions( $args ); |
|
358 | + $this->items = $db->get_subscriptions($args); |
|
359 | 359 | |
360 | - switch ( $status ) { |
|
360 | + switch ($status) { |
|
361 | 361 | case 'active': |
362 | 362 | $total_items = $this->active_count; |
363 | 363 | break; |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | break; |
386 | 386 | } |
387 | 387 | |
388 | - $this->set_pagination_args( array( |
|
388 | + $this->set_pagination_args(array( |
|
389 | 389 | 'total_items' => $total_items, |
390 | 390 | 'per_page' => $this->per_page, |
391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | - ) ); |
|
391 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
392 | + )); |
|
393 | 393 | } |
394 | 394 | } |
@@ -1,47 +1,47 @@ 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_Items { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $wpinv_euvat, $ajax_cart_details; |
10 | 10 | |
11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
12 | - $invoice = new WPInv_Invoice( $post_id ); |
|
11 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
12 | + $invoice = new WPInv_Invoice($post_id); |
|
13 | 13 | $ajax_cart_details = $invoice->get_cart_details(); |
14 | - $subtotal = $invoice->get_subtotal( true ); |
|
14 | + $subtotal = $invoice->get_subtotal(true); |
|
15 | 15 | $discount_raw = $invoice->get_discount(); |
16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
18 | - $tax = $invoice->get_tax( true ); |
|
19 | - $total = $invoice->get_total( true ); |
|
18 | + $tax = $invoice->get_tax(true); |
|
19 | + $total = $invoice->get_total(true); |
|
20 | 20 | $item_quantities = wpinv_item_quantities_enabled(); |
21 | 21 | $use_taxes = wpinv_use_taxes(); |
22 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
22 | + if (!$use_taxes && (float)$invoice->get_tax() > 0) { |
|
23 | 23 | $use_taxes = true; |
24 | 24 | } |
25 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
25 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
26 | 26 | $is_recurring = $invoice->is_recurring(); |
27 | 27 | $post_type_object = get_post_type_object($invoice->post_type); |
28 | 28 | $type_title = $post_type_object->labels->singular_name; |
29 | 29 | |
30 | 30 | $cols = 5; |
31 | - if ( $item_quantities ) { |
|
31 | + if ($item_quantities) { |
|
32 | 32 | $cols++; |
33 | 33 | } |
34 | - if ( $use_taxes ) { |
|
34 | + if ($use_taxes) { |
|
35 | 35 | $cols++; |
36 | 36 | } |
37 | 37 | $class = ''; |
38 | - if ( $invoice->is_paid() ) { |
|
38 | + if ($invoice->is_paid()) { |
|
39 | 39 | $class .= ' wpinv-paid'; |
40 | 40 | } |
41 | - if ( $invoice->is_refunded() ) { |
|
41 | + if ($invoice->is_refunded()) { |
|
42 | 42 | $class .= ' wpinv-refunded'; |
43 | 43 | } |
44 | - if ( $is_recurring ) { |
|
44 | + if ($is_recurring) { |
|
45 | 45 | $class .= ' wpi-recurring'; |
46 | 46 | } |
47 | 47 | ?> |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
50 | 50 | <thead> |
51 | 51 | <tr> |
52 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
53 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
54 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
55 | - <?php if ( $item_quantities ) { ?> |
|
56 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
52 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
53 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
54 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
55 | + <?php if ($item_quantities) { ?> |
|
56 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
57 | 57 | <?php } ?> |
58 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
59 | - <?php if ( $use_taxes ) { ?> |
|
60 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
58 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
59 | + <?php if ($use_taxes) { ?> |
|
60 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
61 | 61 | <?php } ?> |
62 | 62 | <th class="action"></th> |
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody class="wpinv-line-items"> |
66 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
66 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
67 | 67 | </tbody> |
68 | 68 | <tfoot class="wpinv-totals"> |
69 | 69 | <tr> |
@@ -75,44 +75,44 @@ discard block |
||
75 | 75 | </td> |
76 | 76 | <td class="title"> |
77 | 77 | <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]"> |
78 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
78 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
79 | 79 | <div class="wp-clearfix"> |
80 | 80 | <label class="wpi-vat-rule"> |
81 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
81 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
82 | 82 | <span class="input-text-wrap"> |
83 | - <?php echo wpinv_html_select( array( |
|
83 | + <?php echo wpinv_html_select(array( |
|
84 | 84 | 'options' => $wpinv_euvat->get_rules(), |
85 | 85 | 'name' => '_wpinv_quick[vat_rule]', |
86 | 86 | 'id' => '_wpinv_quick_vat_rule', |
87 | 87 | 'show_option_all' => false, |
88 | 88 | 'show_option_none' => false, |
89 | 89 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
90 | - ) ); ?> |
|
90 | + )); ?> |
|
91 | 91 | </span> |
92 | 92 | </label> |
93 | 93 | </div> |
94 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
94 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
95 | 95 | <div class="wp-clearfix"> |
96 | 96 | <label class="wpi-vat-class"> |
97 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
97 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
98 | 98 | <span class="input-text-wrap"> |
99 | - <?php echo wpinv_html_select( array( |
|
99 | + <?php echo wpinv_html_select(array( |
|
100 | 100 | 'options' => $wpinv_euvat->get_all_classes(), |
101 | 101 | 'name' => '_wpinv_quick[vat_class]', |
102 | 102 | 'id' => '_wpinv_quick_vat_class', |
103 | 103 | 'show_option_all' => false, |
104 | 104 | 'show_option_none' => false, |
105 | 105 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
106 | - ) ); ?> |
|
106 | + )); ?> |
|
107 | 107 | </span> |
108 | 108 | </label> |
109 | 109 | </div> |
110 | 110 | <?php } ?> |
111 | 111 | <div class="wp-clearfix"> |
112 | 112 | <label class="wpi-item-type"> |
113 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
113 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
114 | 114 | <span class="input-text-wrap"> |
115 | - <?php echo wpinv_html_select( array( |
|
115 | + <?php echo wpinv_html_select(array( |
|
116 | 116 | 'options' => $item_types, |
117 | 117 | 'name' => '_wpinv_quick[type]', |
118 | 118 | 'id' => '_wpinv_quick_type', |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | 'show_option_all' => false, |
121 | 121 | 'show_option_none' => false, |
122 | 122 | 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
123 | - ) ); ?> |
|
123 | + )); ?> |
|
124 | 124 | </span> |
125 | 125 | </label> |
126 | 126 | </div> |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | </div> |
134 | 134 | </td> |
135 | 135 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
136 | - <?php if ( $item_quantities ) { ?> |
|
136 | + <?php if ($item_quantities) { ?> |
|
137 | 137 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
138 | 138 | <?php } ?> |
139 | 139 | <td class="total"></td> |
140 | - <?php if ( $use_taxes ) { ?> |
|
140 | + <?php if ($use_taxes) { ?> |
|
141 | 141 | <td class="tax"></td> |
142 | 142 | <?php } ?> |
143 | 143 | <td class="action"></td> |
@@ -150,29 +150,29 @@ discard block |
||
150 | 150 | <td colspan="<?php echo $cols; ?>"></td> |
151 | 151 | </tr> |
152 | 152 | <tr class="totals"> |
153 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
153 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
154 | 154 | <td colspan="4"> |
155 | 155 | <table cellspacing="0" cellpadding="0"> |
156 | 156 | <tr class="subtotal"> |
157 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
158 | - <td class="total"><?php echo $subtotal;?></td> |
|
157 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
158 | + <td class="total"><?php echo $subtotal; ?></td> |
|
159 | 159 | <td class="action"></td> |
160 | 160 | </tr> |
161 | 161 | <tr class="discount"> |
162 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
163 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
162 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
163 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
164 | 164 | <td class="action"></td> |
165 | 165 | </tr> |
166 | - <?php if ( $use_taxes ) { ?> |
|
166 | + <?php if ($use_taxes) { ?> |
|
167 | 167 | <tr class="tax"> |
168 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
169 | - <td class="total"><?php echo $tax;?></td> |
|
168 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
169 | + <td class="total"><?php echo $tax; ?></td> |
|
170 | 170 | <td class="action"></td> |
171 | 171 | </tr> |
172 | 172 | <?php } ?> |
173 | 173 | <tr class="total"> |
174 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
175 | - <td class="total"><?php echo $total;?></td> |
|
174 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
175 | + <td class="total"><?php echo $total; ?></td> |
|
176 | 176 | <td class="action"></td> |
177 | 177 | </tr> |
178 | 178 | </table> |
@@ -183,89 +183,89 @@ discard block |
||
183 | 183 | <div class="wpinv-actions"> |
184 | 184 | <?php ob_start(); ?> |
185 | 185 | <?php |
186 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
187 | - if ( !$invoice->is_recurring() ) { |
|
188 | - echo wpinv_item_dropdown( array( |
|
186 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
187 | + if (!$invoice->is_recurring()) { |
|
188 | + echo wpinv_item_dropdown(array( |
|
189 | 189 | 'name' => 'wpinv_invoice_item', |
190 | 190 | 'id' => 'wpinv_invoice_item', |
191 | 191 | 'show_recurring' => true, |
192 | - ) ); |
|
192 | + )); |
|
193 | 193 | ?> |
194 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
194 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
195 | 195 | <?php } ?> |
196 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
197 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
196 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
197 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
198 | 198 | </div> |
199 | 199 | </div> |
200 | 200 | <?php |
201 | 201 | } |
202 | 202 | |
203 | - public static function prices( $post ) { |
|
203 | + public static function prices($post) { |
|
204 | 204 | $symbol = wpinv_currency_symbol(); |
205 | 205 | $position = wpinv_currency_position(); |
206 | - $item = new WPInv_Item( $post->ID ); |
|
206 | + $item = new WPInv_Item($post->ID); |
|
207 | 207 | |
208 | 208 | $price = $item->get_price(); |
209 | 209 | $is_recurring = $item->is_recurring(); |
210 | 210 | $period = $item->get_recurring_period(); |
211 | - $interval = absint( $item->get_recurring_interval() ); |
|
212 | - $times = absint( $item->get_recurring_limit() ); |
|
211 | + $interval = absint($item->get_recurring_interval()); |
|
212 | + $times = absint($item->get_recurring_limit()); |
|
213 | 213 | $free_trial = $item->has_free_trial(); |
214 | 214 | $trial_interval = $item->get_trial_interval(); |
215 | 215 | $trial_period = $item->get_trial_period(); |
216 | 216 | |
217 | 217 | $intervals = array(); |
218 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
218 | + for ($i = 1; $i <= 90; $i++) { |
|
219 | 219 | $intervals[$i] = $i; |
220 | 220 | } |
221 | 221 | |
222 | - $interval = $interval > 0 ? $interval : 1; |
|
222 | + $interval = $interval > 0 ? $interval : 1; |
|
223 | 223 | |
224 | 224 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
225 | 225 | ?> |
226 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
227 | - <?php do_action( 'wpinv_prices_metabox_price', $item ); ?> |
|
226 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
227 | + <?php do_action('wpinv_prices_metabox_price', $item); ?> |
|
228 | 228 | </p> |
229 | 229 | <p class="wpinv-row-is-recurring"> |
230 | 230 | <label for="wpinv_is_recurring"> |
231 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
232 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
231 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
232 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
233 | 233 | </label> |
234 | - <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?> |
|
234 | + <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?> |
|
235 | 235 | </p> |
236 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
237 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
|
238 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
236 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
237 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> |
|
238 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
239 | 239 | 'options' => $intervals, |
240 | 240 | 'name' => 'wpinv_recurring_interval', |
241 | 241 | 'id' => 'wpinv_recurring_interval', |
242 | 242 | 'selected' => $interval, |
243 | 243 | 'show_option_all' => false, |
244 | 244 | 'show_option_none' => false |
245 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
246 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
|
245 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
246 | + <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> |
|
247 | 247 | <span class="clear wpi-trial-clr"></span> |
248 | 248 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
249 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
250 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
249 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> |
|
250 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
251 | 251 | </label> |
252 | 252 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
253 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
|
253 | + <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> |
|
254 | 254 | </label> |
255 | - <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?> |
|
255 | + <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?> |
|
256 | 256 | </p> |
257 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
258 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
257 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
258 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
259 | 259 | <?php |
260 | 260 | } |
261 | 261 | |
262 | - public static function vat_rules( $post ) { |
|
262 | + public static function vat_rules($post) { |
|
263 | 263 | global $wpinv_euvat; |
264 | 264 | |
265 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
265 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
266 | 266 | ?> |
267 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
268 | - <?php echo wpinv_html_select( array( |
|
267 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
268 | + <?php echo wpinv_html_select(array( |
|
269 | 269 | 'options' => $wpinv_euvat->get_rules(), |
270 | 270 | 'name' => 'wpinv_vat_rules', |
271 | 271 | 'id' => 'wpinv_vat_rules', |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | 'show_option_all' => false, |
274 | 274 | 'show_option_none' => false, |
275 | 275 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
276 | - ) ); ?> |
|
276 | + )); ?> |
|
277 | 277 | </p> |
278 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
|
279 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
|
278 | + <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> |
|
279 | + <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> |
|
280 | 280 | <?php |
281 | 281 | } |
282 | 282 | |
283 | - public static function vat_classes( $post ) { |
|
283 | + public static function vat_classes($post) { |
|
284 | 284 | global $wpinv_euvat; |
285 | 285 | |
286 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
286 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
287 | 287 | ?> |
288 | - <p><?php echo wpinv_html_select( array( |
|
288 | + <p><?php echo wpinv_html_select(array( |
|
289 | 289 | 'options' => $wpinv_euvat->get_all_classes(), |
290 | 290 | 'name' => 'wpinv_vat_class', |
291 | 291 | 'id' => 'wpinv_vat_class', |
@@ -293,18 +293,18 @@ discard block |
||
293 | 293 | 'show_option_all' => false, |
294 | 294 | 'show_option_none' => false, |
295 | 295 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
296 | - ) ); ?> |
|
296 | + )); ?> |
|
297 | 297 | </p> |
298 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
298 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
299 | 299 | <?php |
300 | 300 | } |
301 | 301 | |
302 | - public static function item_info( $post ) { |
|
303 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
304 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
302 | + public static function item_info($post) { |
|
303 | + $item_type = wpinv_get_item_type($post->ID); |
|
304 | + do_action('wpinv_item_info_metabox_before', $post); |
|
305 | 305 | ?> |
306 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
307 | - <?php echo wpinv_html_select( array( |
|
306 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
307 | + <?php echo wpinv_html_select(array( |
|
308 | 308 | 'options' => wpinv_get_item_types(), |
309 | 309 | 'name' => 'wpinv_item_type', |
310 | 310 | 'id' => 'wpinv_item_type', |
@@ -312,114 +312,114 @@ discard block |
||
312 | 312 | 'show_option_all' => false, |
313 | 313 | 'show_option_none' => false, |
314 | 314 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
315 | - ) ); ?> |
|
315 | + )); ?> |
|
316 | 316 | </p> |
317 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p> |
|
317 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p> |
|
318 | 318 | <?php |
319 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
319 | + do_action('wpinv_item_info_metabox_after', $post); |
|
320 | 320 | } |
321 | 321 | |
322 | - public static function meta_values( $post ) { |
|
323 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
322 | + public static function meta_values($post) { |
|
323 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
324 | 324 | 'type', |
325 | 325 | 'custom_id' |
326 | - ) ); |
|
326 | + )); |
|
327 | 327 | |
328 | - if ( empty( $meta_keys ) ) { |
|
328 | + if (empty($meta_keys)) { |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
332 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
333 | 333 | |
334 | - foreach ( $meta_keys as $meta_key ) { |
|
334 | + foreach ($meta_keys as $meta_key) { |
|
335 | 335 | ?> |
336 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
336 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
337 | 337 | <?php |
338 | 338 | } |
339 | 339 | |
340 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
340 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
341 | 341 | } |
342 | 342 | |
343 | - public static function save( $post_id, $data, $post ) { |
|
344 | - $invoice = new WPInv_Invoice( $post_id ); |
|
343 | + public static function save($post_id, $data, $post) { |
|
344 | + $invoice = new WPInv_Invoice($post_id); |
|
345 | 345 | |
346 | 346 | // Billing |
347 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
348 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
349 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
350 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
351 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
352 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
353 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
354 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
355 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
356 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
347 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
348 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
349 | + $company = sanitize_text_field($data['wpinv_company']); |
|
350 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
351 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
352 | + $address = sanitize_text_field($data['wpinv_address']); |
|
353 | + $city = sanitize_text_field($data['wpinv_city']); |
|
354 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
355 | + $country = sanitize_text_field($data['wpinv_country']); |
|
356 | + $state = sanitize_text_field($data['wpinv_state']); |
|
357 | 357 | |
358 | 358 | // Details |
359 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
360 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
361 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
362 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
359 | + $status = sanitize_text_field($data['wpinv_status']); |
|
360 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
361 | + $number = sanitize_text_field($data['wpinv_number']); |
|
362 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
363 | 363 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
364 | 364 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
365 | 365 | |
366 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
366 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
367 | 367 | |
368 | - $invoice->set( 'due_date', $due_date ); |
|
369 | - $invoice->set( 'first_name', $first_name ); |
|
370 | - $invoice->set( 'last_name', $last_name ); |
|
371 | - $invoice->set( 'company', $company ); |
|
372 | - $invoice->set( 'vat_number', $vat_number ); |
|
373 | - $invoice->set( 'phone', $phone ); |
|
374 | - $invoice->set( 'address', $address ); |
|
375 | - $invoice->set( 'city', $city ); |
|
376 | - $invoice->set( 'zip', $zip ); |
|
377 | - $invoice->set( 'country', $country ); |
|
378 | - $invoice->set( 'state', $state ); |
|
379 | - $invoice->set( 'status', $status ); |
|
368 | + $invoice->set('due_date', $due_date); |
|
369 | + $invoice->set('first_name', $first_name); |
|
370 | + $invoice->set('last_name', $last_name); |
|
371 | + $invoice->set('company', $company); |
|
372 | + $invoice->set('vat_number', $vat_number); |
|
373 | + $invoice->set('phone', $phone); |
|
374 | + $invoice->set('address', $address); |
|
375 | + $invoice->set('city', $city); |
|
376 | + $invoice->set('zip', $zip); |
|
377 | + $invoice->set('country', $country); |
|
378 | + $invoice->set('state', $state); |
|
379 | + $invoice->set('status', $status); |
|
380 | 380 | //$invoice->set( 'number', $number ); |
381 | 381 | //$invoice->set( 'discounts', $discounts ); |
382 | 382 | //$invoice->set( 'discount', $discount ); |
383 | - $invoice->set( 'ip', $ip ); |
|
383 | + $invoice->set('ip', $ip); |
|
384 | 384 | $invoice->old_status = $_POST['original_post_status']; |
385 | 385 | $invoice->currency = wpinv_get_currency(); |
386 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
387 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
386 | + if (!empty($data['wpinv_gateway'])) { |
|
387 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
388 | 388 | } |
389 | 389 | $saved = $invoice->save(); |
390 | 390 | |
391 | 391 | // Check for payment notes |
392 | - if ( !empty( $data['invoice_note'] ) ) { |
|
393 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
394 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
392 | + if (!empty($data['invoice_note'])) { |
|
393 | + $note = wp_kses($data['invoice_note'], array()); |
|
394 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
395 | 395 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
396 | 396 | |
397 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
397 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | // Update user address if empty. |
401 | - if ( $saved && !empty( $invoice ) ) { |
|
402 | - if ( $user_id = $invoice->get_user_id() ) { |
|
403 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
401 | + if ($saved && !empty($invoice)) { |
|
402 | + if ($user_id = $invoice->get_user_id()) { |
|
403 | + $user_address = wpinv_get_user_address($user_id, false); |
|
404 | 404 | |
405 | 405 | if (empty($user_address['first_name'])) { |
406 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
407 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
406 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
407 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
408 | 408 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
409 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
409 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
413 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
414 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
415 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
416 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
417 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
418 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
413 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
414 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
415 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
416 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
417 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
418 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | |
422 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
422 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | return $saved; |
@@ -1,65 +1,65 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
29 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
30 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
28 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
29 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
30 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
31 | 31 | } |
32 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
32 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
33 | 33 | |
34 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
35 | - remove_action( 'save_post', __FUNCTION__ ); |
|
34 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
35 | + remove_action('save_post', __FUNCTION__); |
|
36 | 36 | |
37 | 37 | // $post_id and $post are required |
38 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
38 | + if (empty($post_id) || empty($post)) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | |
42 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
42 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Dont' save meta boxes for revisions or autosaves |
47 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
47 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
52 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
51 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
52 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
57 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
56 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
57 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
58 | 58 | } |
59 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
59 | + } else if ($post->post_type == 'wpi_item') { |
|
60 | 60 | // verify nonce |
61 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
62 | - $fields = array(); |
|
61 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
62 | + $fields = array(); |
|
63 | 63 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
64 | 64 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
65 | 65 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -72,92 +72,92 @@ discard block |
||
72 | 72 | $fields['_wpinv_trial_period'] = 'wpinv_trial_period'; |
73 | 73 | $fields['_wpinv_trial_interval'] = 'wpinv_trial_interval'; |
74 | 74 | |
75 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
75 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
76 | 76 | $_POST['wpinv_is_recurring'] = 0; |
77 | 77 | } |
78 | 78 | |
79 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
79 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
80 | 80 | $_POST['wpinv_free_trial'] = 0; |
81 | 81 | } |
82 | 82 | |
83 | - foreach ( $fields as $field => $name ) { |
|
84 | - if ( isset( $_POST[ $name ] ) ) { |
|
85 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
83 | + foreach ($fields as $field => $name) { |
|
84 | + if (isset($_POST[$name])) { |
|
85 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
86 | 86 | |
87 | - if ( !$allowed ) { |
|
87 | + if (!$allowed) { |
|
88 | 88 | continue; |
89 | 89 | } |
90 | 90 | |
91 | - if ( $field == '_wpinv_price' ) { |
|
92 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
91 | + if ($field == '_wpinv_price') { |
|
92 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
93 | 93 | } else { |
94 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
94 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
95 | 95 | } |
96 | 96 | |
97 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
98 | - update_post_meta( $post_id, $field, $value ); |
|
97 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
98 | + update_post_meta($post_id, $field, $value); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
103 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
102 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
103 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
108 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
108 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
109 | 109 | |
110 | 110 | function wpinv_register_item_meta_boxes() { |
111 | 111 | global $wpinv_euvat; |
112 | 112 | |
113 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
113 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
114 | 114 | |
115 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
116 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
115 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
116 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
120 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
119 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
120 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
121 | 121 | } |
122 | 122 | |
123 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
124 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
123 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
124 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | function wpinv_register_discount_meta_boxes() { |
128 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
128 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
129 | 129 | } |
130 | 130 | |
131 | -function wpinv_discount_metabox_details( $post ) { |
|
131 | +function wpinv_discount_metabox_details($post) { |
|
132 | 132 | $discount_id = $post->ID; |
133 | - $discount = wpinv_get_discount( $discount_id ); |
|
133 | + $discount = wpinv_get_discount($discount_id); |
|
134 | 134 | |
135 | - $type = wpinv_get_discount_type( $discount_id ); |
|
136 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
137 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
138 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
139 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
140 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
141 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
142 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
143 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
144 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
135 | + $type = wpinv_get_discount_type($discount_id); |
|
136 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
137 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
138 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
139 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
140 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
141 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
142 | + $recurring = (bool)wpinv_discount_is_recurring($discount_id); |
|
143 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
144 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
145 | 145 | |
146 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
147 | - $start_time = strtotime( $start_date ); |
|
148 | - $start_h = date_i18n( 'H', $start_time ); |
|
149 | - $start_m = date_i18n( 'i', $start_time ); |
|
150 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
146 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
147 | + $start_time = strtotime($start_date); |
|
148 | + $start_h = date_i18n('H', $start_time); |
|
149 | + $start_m = date_i18n('i', $start_time); |
|
150 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
151 | 151 | } else { |
152 | 152 | $start_h = '00'; |
153 | 153 | $start_m = '00'; |
154 | 154 | } |
155 | 155 | |
156 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
157 | - $expiration_time = strtotime( $expiration_date ); |
|
158 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
159 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
160 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
156 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
157 | + $expiration_time = strtotime($expiration_date); |
|
158 | + $expiration_h = date_i18n('H', $expiration_time); |
|
159 | + $expiration_m = date_i18n('i', $expiration_time); |
|
160 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
161 | 161 | } else { |
162 | 162 | $expiration_h = '23'; |
163 | 163 | $expiration_m = '59'; |
@@ -167,207 +167,207 @@ discard block |
||
167 | 167 | $max_total = $max_total > 0 ? $max_total : ''; |
168 | 168 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
169 | 169 | ?> |
170 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
171 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
170 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
171 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
172 | 172 | <table class="form-table wpi-form-table"> |
173 | 173 | <tbody> |
174 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
175 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
174 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
175 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
176 | 176 | <tr> |
177 | 177 | <th valign="top" scope="row"> |
178 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
178 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
179 | 179 | </th> |
180 | 180 | <td> |
181 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
182 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
181 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
182 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
183 | 183 | </td> |
184 | 184 | </tr> |
185 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
185 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
186 | 186 | <tr> |
187 | 187 | <th valign="top" scope="row"> |
188 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
188 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
189 | 189 | </th> |
190 | 190 | <td> |
191 | 191 | <select id="wpinv_discount_type" name="type" class="medium-text"> |
192 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
193 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
192 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
193 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
194 | 194 | <?php } ?> |
195 | 195 | </select> |
196 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
196 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
197 | 197 | </td> |
198 | 198 | </tr> |
199 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
200 | 200 | <tr> |
201 | 201 | <th valign="top" scope="row"> |
202 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
202 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
203 | 203 | </th> |
204 | 204 | <td> |
205 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
206 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
207 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
205 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
206 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
207 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
208 | 208 | </td> |
209 | 209 | </tr> |
210 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
210 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
211 | 211 | <tr> |
212 | 212 | <th valign="top" scope="row"> |
213 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
213 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
214 | 214 | </th> |
215 | 215 | <td> |
216 | - <p><?php echo wpinv_item_dropdown( array( |
|
216 | + <p><?php echo wpinv_item_dropdown(array( |
|
217 | 217 | 'name' => 'items[]', |
218 | 218 | 'id' => 'items', |
219 | 219 | 'selected' => $item_reqs, |
220 | 220 | 'multiple' => true, |
221 | 221 | 'class' => 'medium-text', |
222 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
222 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
223 | 223 | 'show_recurring' => true, |
224 | - ) ); ?> |
|
224 | + )); ?> |
|
225 | 225 | </p> |
226 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
226 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
227 | 227 | </td> |
228 | 228 | </tr> |
229 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
230 | 230 | <tr> |
231 | 231 | <th valign="top" scope="row"> |
232 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
232 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
233 | 233 | </th> |
234 | 234 | <td> |
235 | - <p><?php echo wpinv_item_dropdown( array( |
|
235 | + <p><?php echo wpinv_item_dropdown(array( |
|
236 | 236 | 'name' => 'excluded_items[]', |
237 | 237 | 'id' => 'excluded_items', |
238 | 238 | 'selected' => $excluded_items, |
239 | 239 | 'multiple' => true, |
240 | 240 | 'class' => 'medium-text', |
241 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
241 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
242 | 242 | 'show_recurring' => true, |
243 | - ) ); ?> |
|
243 | + )); ?> |
|
244 | 244 | </p> |
245 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
245 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
246 | 246 | </td> |
247 | 247 | </tr> |
248 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
248 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
249 | 249 | <tr> |
250 | 250 | <th valign="top" scope="row"> |
251 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
251 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
252 | 252 | </th> |
253 | 253 | <td> |
254 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
255 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
256 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
254 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
255 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
256 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
257 | 257 | <?php } ?> |
258 | 258 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
259 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
260 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
259 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
260 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
261 | 261 | <?php } ?> |
262 | 262 | </select> |
263 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
263 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
264 | 264 | </td> |
265 | 265 | </tr> |
266 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
266 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
267 | 267 | <tr> |
268 | 268 | <th valign="top" scope="row"> |
269 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
269 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
270 | 270 | </th> |
271 | 271 | <td> |
272 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
273 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
274 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
272 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
273 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
274 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
275 | 275 | <?php } ?> |
276 | 276 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
277 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
278 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
277 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
278 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
279 | 279 | <?php } ?> |
280 | 280 | </select> |
281 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
281 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
282 | 282 | </td> |
283 | 283 | </tr> |
284 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
284 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
285 | 285 | <tr> |
286 | 286 | <th valign="top" scope="row"> |
287 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
287 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
288 | 288 | </th> |
289 | 289 | <td> |
290 | 290 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
291 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
291 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
292 | 292 | </td> |
293 | 293 | </tr> |
294 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
294 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
295 | 295 | <tr> |
296 | 296 | <th valign="top" scope="row"> |
297 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
297 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
298 | 298 | </th> |
299 | 299 | <td> |
300 | 300 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
301 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
301 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
302 | 302 | </td> |
303 | 303 | </tr> |
304 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
304 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
305 | 305 | <tr> |
306 | 306 | <th valign="top" scope="row"> |
307 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
307 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
308 | 308 | </th> |
309 | 309 | <td> |
310 | 310 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text"> |
311 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
312 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
311 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
312 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
313 | 313 | </select> |
314 | - <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
314 | + <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
315 | 315 | </td> |
316 | 316 | </tr> |
317 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
317 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
318 | 318 | <tr> |
319 | 319 | <th valign="top" scope="row"> |
320 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
320 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
321 | 321 | </th> |
322 | 322 | <td> |
323 | 323 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
324 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
324 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
325 | 325 | </td> |
326 | 326 | </tr> |
327 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
327 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
328 | 328 | <tr> |
329 | 329 | <th valign="top" scope="row"> |
330 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
330 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
331 | 331 | </th> |
332 | 332 | <td> |
333 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
334 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
333 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
334 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
335 | 335 | </td> |
336 | 336 | </tr> |
337 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
337 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
338 | 338 | </tbody> |
339 | 339 | </table> |
340 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
340 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
341 | 341 | <?php |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
345 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
344 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
345 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
346 | 346 | |
347 | - if ( $post_type != 'wpi_discount' ) { |
|
347 | + if ($post_type != 'wpi_discount') { |
|
348 | 348 | return; |
349 | 349 | } |
350 | 350 | |
351 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
351 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
355 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - if ( !current_user_can( 'manage_options', $post_id ) ) { |
|
359 | + if (!current_user_can('manage_options', $post_id)) { |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | |
363 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
363 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
364 | 364 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
365 | 365 | } |
366 | 366 | |
367 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
367 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
368 | 368 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
369 | 369 | } |
370 | 370 | |
371 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
371 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
372 | 372 | } |
373 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
374 | 373 | \ No newline at end of file |
374 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
375 | 375 | \ 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 | |
@@ -11,60 +11,60 @@ discard block |
||
11 | 11 | public function __construct() { |
12 | 12 | global $bp; |
13 | 13 | |
14 | - if ( !defined( 'WPINV_BP_SLUG' ) ) { |
|
15 | - define( 'WPINV_BP_SLUG', 'invoices' ); |
|
14 | + if (!defined('WPINV_BP_SLUG')) { |
|
15 | + define('WPINV_BP_SLUG', 'invoices'); |
|
16 | 16 | } |
17 | 17 | |
18 | - $position = wpinv_get_option( 'wpinv_menu_position' ); |
|
18 | + $position = wpinv_get_option('wpinv_menu_position'); |
|
19 | 19 | $position = $position !== '' && $position !== false ? $position : 91; |
20 | - $this->position = apply_filters( 'wpinv_bp_nav_position', $position ); |
|
20 | + $this->position = apply_filters('wpinv_bp_nav_position', $position); |
|
21 | 21 | $this->slug = WPINV_BP_SLUG; |
22 | 22 | |
23 | 23 | parent::start( |
24 | 24 | 'invoicing', |
25 | - _x( 'Invoices', 'Invoices screen page <title>', 'invoicing' ), |
|
26 | - trailingslashit( dirname( __FILE__ ) ), |
|
25 | + _x('Invoices', 'Invoices screen page <title>', 'invoicing'), |
|
26 | + trailingslashit(dirname(__FILE__)), |
|
27 | 27 | array( |
28 | 28 | 'adminbar_myaccount_order' => $this->position |
29 | 29 | ) |
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
33 | - public function includes( $includes = array() ) { |
|
34 | - parent::includes( $includes ); |
|
33 | + public function includes($includes = array()) { |
|
34 | + parent::includes($includes); |
|
35 | 35 | } |
36 | 36 | |
37 | - public function setup_globals( $args = array() ) { |
|
37 | + public function setup_globals($args = array()) { |
|
38 | 38 | global $bp; |
39 | 39 | |
40 | 40 | $args = array( |
41 | 41 | 'slug' => $this->slug, |
42 | 42 | ); |
43 | 43 | |
44 | - parent::setup_globals( $args ); |
|
44 | + parent::setup_globals($args); |
|
45 | 45 | } |
46 | 46 | |
47 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
48 | - if ( !bp_is_my_profile() ) { |
|
47 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
48 | + if (!bp_is_my_profile()) { |
|
49 | 49 | return; |
50 | 50 | } |
51 | 51 | |
52 | - if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) { |
|
52 | + if (wpinv_get_option('wpinv_bp_hide_menu')) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | 56 | $this->setup_invoice_count(); |
57 | 57 | |
58 | 58 | $user_domain = bp_loggedin_user_domain(); |
59 | - $invoices_link = trailingslashit( $user_domain . $this->slug ); |
|
60 | - $class = ( 0 === $this->count ) ? 'no-count' : 'count'; |
|
59 | + $invoices_link = trailingslashit($user_domain . $this->slug); |
|
60 | + $class = (0 === $this->count) ? 'no-count' : 'count'; |
|
61 | 61 | |
62 | 62 | $main_nav_name = sprintf( |
63 | - __( 'My Invoices %s', 'invoicing' ), |
|
63 | + __('My Invoices %s', 'invoicing'), |
|
64 | 64 | sprintf( |
65 | 65 | '<span class="%s">%s</span>', |
66 | - esc_attr( $class ), |
|
67 | - bp_core_number_format( $this->count ) |
|
66 | + esc_attr($class), |
|
67 | + bp_core_number_format($this->count) |
|
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | |
@@ -72,54 +72,54 @@ discard block |
||
72 | 72 | 'name' => $main_nav_name, |
73 | 73 | 'slug' => $this->slug, |
74 | 74 | 'position' => $this->position, |
75 | - 'screen_function' => array( $this, 'invoices_screen' ), |
|
75 | + 'screen_function' => array($this, 'invoices_screen'), |
|
76 | 76 | 'default_subnav_slug' => 'invoices', |
77 | 77 | 'item_css_id' => $this->id |
78 | 78 | ); |
79 | 79 | |
80 | 80 | $sub_nav[] = array( |
81 | - 'name' => _x( 'My Invoices', 'Invoices screen sub nav', 'invoicing' ), |
|
81 | + 'name' => _x('My Invoices', 'Invoices screen sub nav', 'invoicing'), |
|
82 | 82 | 'slug' => 'invoices', |
83 | 83 | 'parent_url' => $invoices_link, |
84 | 84 | 'parent_slug' => $this->slug, |
85 | - 'screen_function' => array( $this, 'invoices_screen' ), |
|
85 | + 'screen_function' => array($this, 'invoices_screen'), |
|
86 | 86 | 'position' => 10, |
87 | 87 | 'item_css_id' => 'invoices-my-invoices' |
88 | 88 | ); |
89 | 89 | |
90 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
90 | + parent::setup_nav($main_nav, $sub_nav); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | public function setup_title() { |
94 | 94 | // Adjust title. |
95 | - if ( (bool)bp_is_current_component( 'invoicing' ) ) { |
|
95 | + if ((bool)bp_is_current_component('invoicing')) { |
|
96 | 96 | global $bp; |
97 | 97 | |
98 | - $bp->bp_options_title = __( 'My Invoices', 'invoicing' ); |
|
98 | + $bp->bp_options_title = __('My Invoices', 'invoicing'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | parent::setup_title(); |
102 | 102 | } |
103 | 103 | |
104 | 104 | public function invoices_screen() { |
105 | - if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) { |
|
105 | + if (wpinv_get_option('wpinv_bp_hide_menu')) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | global $bp; |
110 | 110 | |
111 | - add_action( 'bp_template_content', array( $this, 'invoices_content' ) ); |
|
111 | + add_action('bp_template_content', array($this, 'invoices_content')); |
|
112 | 112 | |
113 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
113 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
114 | 114 | |
115 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
115 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function invoices_content() { |
119 | - if ( $this->has_invoices( bp_ajax_querystring( 'invoices' ) ) ) { |
|
119 | + if ($this->has_invoices(bp_ajax_querystring('invoices'))) { |
|
120 | 120 | global $invoices_template; |
121 | 121 | |
122 | - do_action( 'wpinv_bp_invoices_before_content' ); |
|
122 | + do_action('wpinv_bp_invoices_before_content'); |
|
123 | 123 | ?> |
124 | 124 | <div class="wpi-bp-invoices invoices invoicing" style="position:relative"> |
125 | 125 | <div id="pag-top" class="pagination"> |
@@ -133,61 +133,61 @@ discard block |
||
133 | 133 | <table class="table table-bordered table-hover wpi-user-invoices" style="margin:0"> |
134 | 134 | <thead> |
135 | 135 | <tr> |
136 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
137 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th> |
|
136 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
137 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th> |
|
138 | 138 | <?php endforeach; ?> |
139 | 139 | </tr> |
140 | 140 | </thead> |
141 | 141 | <tbody> |
142 | - <?php foreach ( $invoices_template->invoices as $invoice ) { |
|
142 | + <?php foreach ($invoices_template->invoices as $invoice) { |
|
143 | 143 | ?> |
144 | 144 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
145 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
146 | - <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>"> |
|
147 | - <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?> |
|
148 | - <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?> |
|
149 | - |
|
150 | - <?php elseif ( 'invoice-number' === $column_id ) : ?> |
|
151 | - <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>"> |
|
152 | - <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?> |
|
145 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
146 | + <td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>"> |
|
147 | + <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?> |
|
148 | + <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?> |
|
149 | + |
|
150 | + <?php elseif ('invoice-number' === $column_id) : ?> |
|
151 | + <a href="<?php echo esc_url($invoice->get_view_url()); ?>"> |
|
152 | + <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?> |
|
153 | 153 | </a> |
154 | 154 | |
155 | - <?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?> |
|
156 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
155 | + <?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?> |
|
156 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
157 | 157 | |
158 | - <?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?> |
|
159 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
158 | + <?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?> |
|
159 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
160 | 160 | |
161 | - <?php elseif ( 'invoice-status' === $column_id ) : ?> |
|
162 | - <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?> |
|
161 | + <?php elseif ('invoice-status' === $column_id) : ?> |
|
162 | + <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?> |
|
163 | 163 | |
164 | - <?php elseif ( 'invoice-total' === $column_id ) : ?> |
|
165 | - <?php echo $invoice->get_total( true ); ?> |
|
164 | + <?php elseif ('invoice-total' === $column_id) : ?> |
|
165 | + <?php echo $invoice->get_total(true); ?> |
|
166 | 166 | |
167 | - <?php elseif ( 'invoice-actions' === $column_id ) : ?> |
|
167 | + <?php elseif ('invoice-actions' === $column_id) : ?> |
|
168 | 168 | <?php |
169 | 169 | $actions = array( |
170 | 170 | 'pay' => array( |
171 | 171 | 'url' => $invoice->get_checkout_payment_url(), |
172 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
172 | + 'name' => __('Pay Now', 'invoicing'), |
|
173 | 173 | 'class' => 'btn-success' |
174 | 174 | ), |
175 | 175 | 'print' => array( |
176 | 176 | 'url' => $invoice->get_view_url(), |
177 | - 'name' => __( 'Print', 'invoicing' ), |
|
177 | + 'name' => __('Print', 'invoicing'), |
|
178 | 178 | 'class' => 'btn-primary', |
179 | 179 | 'attrs' => 'target="_blank"' |
180 | 180 | ) |
181 | 181 | ); |
182 | 182 | |
183 | - if ( ! $invoice->needs_payment() ) { |
|
184 | - unset( $actions['pay'] ); |
|
183 | + if (!$invoice->needs_payment()) { |
|
184 | + unset($actions['pay']); |
|
185 | 185 | } |
186 | 186 | |
187 | - if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
188 | - foreach ( $actions as $key => $action ) { |
|
187 | + if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) { |
|
188 | + foreach ($actions as $key => $action) { |
|
189 | 189 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
190 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
190 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | ?> |
@@ -215,64 +215,64 @@ discard block |
||
215 | 215 | </div> |
216 | 216 | <?php |
217 | 217 | |
218 | - do_action( 'wpinv_bp_invoices_after_content' ); |
|
218 | + do_action('wpinv_bp_invoices_after_content'); |
|
219 | 219 | } else { |
220 | 220 | ?> |
221 | 221 | <div id="message" class="info"> |
222 | - <p><?php _e( 'No invoice has been made yet.', 'invoicing' ); ?></p> |
|
222 | + <p><?php _e('No invoice has been made yet.', 'invoicing'); ?></p> |
|
223 | 223 | </div> |
224 | 224 | <?php |
225 | 225 | } |
226 | 226 | |
227 | - if ( defined( 'DOING_AJAX' ) ) { |
|
227 | + if (defined('DOING_AJAX')) { |
|
228 | 228 | exit; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - public function has_invoices( $args = '' ) { |
|
232 | + public function has_invoices($args = '') { |
|
233 | 233 | global $invoices_template; |
234 | 234 | |
235 | - $per_page = absint( wpinv_get_option( 'wpinv_bp_per_page' ) ); |
|
235 | + $per_page = absint(wpinv_get_option('wpinv_bp_per_page')); |
|
236 | 236 | // Parse arguments. |
237 | - $r = bp_parse_args( $args, array( |
|
237 | + $r = bp_parse_args($args, array( |
|
238 | 238 | 'status' => 'all', |
239 | 239 | 'page_arg' => 'bpage', |
240 | 240 | 'page' => 1, |
241 | 241 | 'per_page' => $per_page > 0 ? $per_page : 20, |
242 | 242 | 'max' => false, |
243 | 243 | 'user_id' => bp_loggedin_user_id(), |
244 | - ), 'has_invoices' ); |
|
244 | + ), 'has_invoices'); |
|
245 | 245 | |
246 | 246 | |
247 | - if ( ! empty( $r['max'] ) && ( (int)$r['per_page'] > (int)$r['max'] ) ) { |
|
247 | + if (!empty($r['max']) && ((int)$r['per_page'] > (int)$r['max'])) { |
|
248 | 248 | $r['per_page'] = (int)$r['max']; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Get the invoices. |
252 | - $invoices_template = new WPInv_BP_Invoices_Template( $r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg'] ); |
|
252 | + $invoices_template = new WPInv_BP_Invoices_Template($r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg']); |
|
253 | 253 | |
254 | - return apply_filters( 'wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r ); |
|
254 | + return apply_filters('wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | public function setup_invoice_count() { |
258 | - $query = apply_filters( 'wpinv_user_invoices_count_query', array( 'user' => bp_loggedin_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false ) ); |
|
259 | - $invoices = wpinv_get_invoices( $query ); |
|
258 | + $query = apply_filters('wpinv_user_invoices_count_query', array('user' => bp_loggedin_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false)); |
|
259 | + $invoices = wpinv_get_invoices($query); |
|
260 | 260 | |
261 | - $this->count = !empty( $invoices ) ? count( $invoices ) : 0; |
|
261 | + $this->count = !empty($invoices) ? count($invoices) : 0; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | public function pagination_count() { |
265 | 265 | global $invoices_template; |
266 | 266 | |
267 | - $start_num = intval( ( $invoices_template->pag_page - 1 ) * $invoices_template->pag_num ) + 1; |
|
268 | - $from_num = bp_core_number_format( $start_num ); |
|
269 | - $to_num = bp_core_number_format( ( $start_num + ( $invoices_template->pag_num - 1 ) > $invoices_template->total_invoice_count ) ? $invoices_template->total_invoice_count : $start_num + ( $invoices_template->pag_num - 1 ) ); |
|
270 | - $total = bp_core_number_format( $invoices_template->total_invoice_count ); |
|
267 | + $start_num = intval(($invoices_template->pag_page - 1) * $invoices_template->pag_num) + 1; |
|
268 | + $from_num = bp_core_number_format($start_num); |
|
269 | + $to_num = bp_core_number_format(($start_num + ($invoices_template->pag_num - 1) > $invoices_template->total_invoice_count) ? $invoices_template->total_invoice_count : $start_num + ($invoices_template->pag_num - 1)); |
|
270 | + $total = bp_core_number_format($invoices_template->total_invoice_count); |
|
271 | 271 | |
272 | - if ( 1 == $invoices_template->total_invoice_count ) { |
|
273 | - $message = __( 'Viewing 1 invoice', 'invoicing' ); |
|
272 | + if (1 == $invoices_template->total_invoice_count) { |
|
273 | + $message = __('Viewing 1 invoice', 'invoicing'); |
|
274 | 274 | } else { |
275 | - $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s invoice', 'Viewing %1$s - %2$s of %3$s invoices', $invoices_template->total_invoice_count, 'invoicing' ), $from_num, $to_num, $total ); |
|
275 | + $message = sprintf(_n('Viewing %1$s - %2$s of %3$s invoice', 'Viewing %1$s - %2$s of %3$s invoices', $invoices_template->total_invoice_count, 'invoicing'), $from_num, $to_num, $total); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $message; |
@@ -281,32 +281,32 @@ discard block |
||
281 | 281 | function pagination_links() { |
282 | 282 | global $invoices_template; |
283 | 283 | |
284 | - return apply_filters( 'wpinv_bp_get_pagination_links', $invoices_template->pag_links ); |
|
284 | + return apply_filters('wpinv_bp_get_pagination_links', $invoices_template->pag_links); |
|
285 | 285 | } |
286 | 286 | |
287 | - public function bp_section( $settings = array() ) { |
|
288 | - $settings['wpinv_bp'] = __( 'BuddyPress Integration', 'invoicing' ); |
|
287 | + public function bp_section($settings = array()) { |
|
288 | + $settings['wpinv_bp'] = __('BuddyPress Integration', 'invoicing'); |
|
289 | 289 | return $settings; |
290 | 290 | } |
291 | 291 | |
292 | - public function bp_settings( $settings = array() ) { |
|
292 | + public function bp_settings($settings = array()) { |
|
293 | 293 | $settings['wpinv_bp'] = array( |
294 | 294 | 'wpinv_bp_labels' => array( |
295 | 295 | 'id' => 'wpinv_bp_settings', |
296 | - 'name' => '<h3>' . __( 'BuddyPress Integration', 'invoicing' ) . '</h3>', |
|
296 | + 'name' => '<h3>' . __('BuddyPress Integration', 'invoicing') . '</h3>', |
|
297 | 297 | 'desc' => '', |
298 | 298 | 'type' => 'header', |
299 | 299 | ), |
300 | 300 | 'wpinv_bp_hide_menu' => array( |
301 | 301 | 'id' => 'wpinv_bp_hide_menu', |
302 | - 'name' => __( 'Hide Invoices link', 'invoicing' ), |
|
303 | - 'desc' => __( 'Hide Invoices link from BP Profile menu.', 'invoicing' ), |
|
302 | + 'name' => __('Hide Invoices link', 'invoicing'), |
|
303 | + 'desc' => __('Hide Invoices link from BP Profile menu.', 'invoicing'), |
|
304 | 304 | 'type' => 'checkbox', |
305 | 305 | ), |
306 | 306 | 'wpinv_menu_position' => array( |
307 | 307 | 'id' => 'wpinv_menu_position', |
308 | - 'name' => __( 'Menu position', 'invoicing' ), |
|
309 | - 'desc' => __( 'Menu position for the Invoices link in BP Profile menu.', 'invoicing' ), |
|
308 | + 'name' => __('Menu position', 'invoicing'), |
|
309 | + 'desc' => __('Menu position for the Invoices link in BP Profile menu.', 'invoicing'), |
|
310 | 310 | 'type' => 'number', |
311 | 311 | 'size' => 'small', |
312 | 312 | 'min' => '1', |
@@ -316,8 +316,8 @@ discard block |
||
316 | 316 | ), |
317 | 317 | 'wpinv_bp_per_page' => array( |
318 | 318 | 'id' => 'wpinv_bp_per_page', |
319 | - 'name' => __( 'Max invoices per page', 'invoicing' ), |
|
320 | - 'desc' => __( 'Enter a number to lists the invoices for each page.', 'invoicing' ), |
|
319 | + 'name' => __('Max invoices per page', 'invoicing'), |
|
320 | + 'desc' => __('Enter a number to lists the invoices for each page.', 'invoicing'), |
|
321 | 321 | 'type' => 'number', |
322 | 322 | 'size' => 'small', |
323 | 323 | 'min' => '1', |
@@ -342,25 +342,25 @@ discard block |
||
342 | 342 | public $pag_links = ''; |
343 | 343 | public $total_invoice_count = 0; |
344 | 344 | |
345 | - public function __construct( $status, $page, $per_page, $max, $user_id, $page_arg = 'bpage' ) { |
|
346 | - $this->invoices = array( 'invoices' => array(), 'total' => 0 ); |
|
345 | + public function __construct($status, $page, $per_page, $max, $user_id, $page_arg = 'bpage') { |
|
346 | + $this->invoices = array('invoices' => array(), 'total' => 0); |
|
347 | 347 | |
348 | - $this->pag_arg = sanitize_key( $page_arg ); |
|
349 | - $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page ); |
|
350 | - $this->pag_num = bp_sanitize_pagination_arg( 'num', $per_page ); |
|
348 | + $this->pag_arg = sanitize_key($page_arg); |
|
349 | + $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page); |
|
350 | + $this->pag_num = bp_sanitize_pagination_arg('num', $per_page); |
|
351 | 351 | |
352 | - $query_args = array( 'user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true ); |
|
353 | - if ( !empty( $status ) && $status != 'all' ) { |
|
352 | + $query_args = array('user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true); |
|
353 | + if (!empty($status) && $status != 'all') { |
|
354 | 354 | $query_args['status'] = $status; |
355 | 355 | } |
356 | - $invoices = wpinv_get_invoices( apply_filters( 'wpinv_bp_user_invoices_query', $query_args ) ); |
|
356 | + $invoices = wpinv_get_invoices(apply_filters('wpinv_bp_user_invoices_query', $query_args)); |
|
357 | 357 | |
358 | - if ( !empty( $invoices ) && !empty( $invoices->found_posts ) ) { |
|
359 | - $this->invoices['invoices'] = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
358 | + if (!empty($invoices) && !empty($invoices->found_posts)) { |
|
359 | + $this->invoices['invoices'] = array_map('wpinv_get_invoice', $invoices->posts); |
|
360 | 360 | $this->invoices['total'] = $invoices->found_posts; |
361 | 361 | } |
362 | 362 | |
363 | - if ( empty( $max ) || ( $max >= (int)$this->invoices['total'] ) ) { |
|
363 | + if (empty($max) || ($max >= (int)$this->invoices['total'])) { |
|
364 | 364 | $this->total_invoice_count = (int)$this->invoices['total']; |
365 | 365 | } else { |
366 | 366 | $this->total_invoice_count = (int)$max; |
@@ -368,52 +368,52 @@ discard block |
||
368 | 368 | |
369 | 369 | $this->invoices = $this->invoices['invoices']; |
370 | 370 | |
371 | - $invoice_count = count( $this->invoices ); |
|
371 | + $invoice_count = count($this->invoices); |
|
372 | 372 | |
373 | - if ( empty( $max ) || ( $max >= (int)$invoice_count ) ) { |
|
373 | + if (empty($max) || ($max >= (int)$invoice_count)) { |
|
374 | 374 | $this->invoice_count = (int)$invoice_count; |
375 | 375 | } else { |
376 | 376 | $this->invoice_count = (int)$max; |
377 | 377 | } |
378 | 378 | |
379 | - if ( ! empty( $this->total_invoice_count ) && ! empty( $this->pag_num ) ) { |
|
380 | - $this->pag_links = paginate_links( array( |
|
381 | - 'base' => add_query_arg( $this->pag_arg, '%#%' ), |
|
379 | + if (!empty($this->total_invoice_count) && !empty($this->pag_num)) { |
|
380 | + $this->pag_links = paginate_links(array( |
|
381 | + 'base' => add_query_arg($this->pag_arg, '%#%'), |
|
382 | 382 | 'format' => '', |
383 | - 'total' => ceil( (int)$this->total_invoice_count / (int)$this->pag_num ), |
|
383 | + 'total' => ceil((int)$this->total_invoice_count / (int)$this->pag_num), |
|
384 | 384 | 'current' => (int)$this->pag_page, |
385 | - 'prev_text' => _x( '←', 'Invoice pagination previous text', 'invoicing' ), |
|
386 | - 'next_text' => _x( '→', 'Invoice pagination next text', 'invoicing' ), |
|
385 | + 'prev_text' => _x('←', 'Invoice pagination previous text', 'invoicing'), |
|
386 | + 'next_text' => _x('→', 'Invoice pagination next text', 'invoicing'), |
|
387 | 387 | 'mid_size' => 1, |
388 | 388 | 'add_args' => array(), |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | 393 | public function has_invoices() { |
394 | - return (bool) ! empty( $this->invoice_count ); |
|
394 | + return (bool)!empty($this->invoice_count); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | public function next_invoice() { |
398 | 398 | $this->current_invoice++; |
399 | - $this->invoice = $this->invoices[ $this->current_invoice ]; |
|
399 | + $this->invoice = $this->invoices[$this->current_invoice]; |
|
400 | 400 | |
401 | 401 | return $this->invoice; |
402 | 402 | } |
403 | 403 | |
404 | 404 | public function rewind_invoices() { |
405 | 405 | $this->current_invoice = -1; |
406 | - if ( $this->invoice_count > 0 ) { |
|
406 | + if ($this->invoice_count > 0) { |
|
407 | 407 | $this->invoice = $this->invoices[0]; |
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
411 | 411 | public function invoices() { |
412 | - if ( ( $this->current_invoice + 1 ) < $this->invoice_count ) { |
|
412 | + if (($this->current_invoice + 1) < $this->invoice_count) { |
|
413 | 413 | return true; |
414 | - } elseif ( ( $this->current_invoice + 1 ) === $this->invoice_count ) { |
|
414 | + } elseif (($this->current_invoice + 1) === $this->invoice_count) { |
|
415 | 415 | |
416 | - do_action( 'wpinv_bp_invoice_loop_end' ); |
|
416 | + do_action('wpinv_bp_invoice_loop_end'); |
|
417 | 417 | |
418 | 418 | $this->rewind_invoices(); |
419 | 419 | } |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | $this->in_the_loop = true; |
428 | 428 | $this->invoice = $this->next_invoice(); |
429 | 429 | |
430 | - if ( 0 === $this->current_invoice ) { |
|
431 | - do_action( 'wpinv_bp_invoice_loop_start' ); |
|
430 | + if (0 === $this->current_invoice) { |
|
431 | + do_action('wpinv_bp_invoice_loop_start'); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | } |
@@ -438,9 +438,9 @@ discard block |
||
438 | 438 | |
439 | 439 | $bp->invoicing = new WPInv_BP_Component(); |
440 | 440 | |
441 | - add_action( 'wp_ajax_invoicing_filter', array( $bp->invoicing, 'invoices_content' ) ); |
|
442 | - add_action( 'wp_ajax_nopriv_invoicing_filter', array( $bp->invoicing, 'invoices_content' ) ); |
|
443 | - add_filter( 'wpinv_settings_sections_general', array( $bp->invoicing, 'bp_section' ), 10, 1 ); |
|
444 | - add_filter( 'wpinv_settings_general', array( $bp->invoicing, 'bp_settings' ), 10, 1 ); |
|
441 | + add_action('wp_ajax_invoicing_filter', array($bp->invoicing, 'invoices_content')); |
|
442 | + add_action('wp_ajax_nopriv_invoicing_filter', array($bp->invoicing, 'invoices_content')); |
|
443 | + add_filter('wpinv_settings_sections_general', array($bp->invoicing, 'bp_section'), 10, 1); |
|
444 | + add_filter('wpinv_settings_general', array($bp->invoicing, 'bp_settings'), 10, 1); |
|
445 | 445 | } |
446 | -add_action( 'bp_loaded', 'wpinv_bp_setup_component' ); |
|
447 | 446 | \ No newline at end of file |
447 | +add_action('bp_loaded', 'wpinv_bp_setup_component'); |
|
448 | 448 | \ No newline at end of file |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -77,39 +77,39 @@ discard block |
||
77 | 77 | 'buy_items' => true, |
78 | 78 | ); |
79 | 79 | |
80 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
80 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
81 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
82 | 82 | |
83 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
83 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
84 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( $nopriv ) { |
|
88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
87 | + if ($nopriv) { |
|
88 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
89 | 89 | |
90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
90 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | public static function add_note() { |
96 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
96 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
97 | 97 | |
98 | - if ( !current_user_can( 'manage_options' ) ) { |
|
98 | + if (!current_user_can('manage_options')) { |
|
99 | 99 | die(-1); |
100 | 100 | } |
101 | 101 | |
102 | - $post_id = absint( $_POST['post_id'] ); |
|
103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
104 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
102 | + $post_id = absint($_POST['post_id']); |
|
103 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
104 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
105 | 105 | |
106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
107 | 107 | |
108 | - if ( $post_id > 0 ) { |
|
109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
108 | + if ($post_id > 0) { |
|
109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
110 | 110 | |
111 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
112 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
111 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
112 | + wpinv_get_invoice_note_line_item($note_id); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | public static function delete_note() { |
120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
120 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
121 | 121 | |
122 | - if ( !current_user_can( 'manage_options' ) ) { |
|
122 | + if (!current_user_can('manage_options')) { |
|
123 | 123 | die(-1); |
124 | 124 | } |
125 | 125 | |
126 | 126 | $note_id = (int)$_POST['note_id']; |
127 | 127 | |
128 | - if ( $note_id > 0 ) { |
|
129 | - wp_delete_comment( $note_id, true ); |
|
128 | + if ($note_id > 0) { |
|
129 | + wp_delete_comment($note_id, true); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | die(); |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function checkout() { |
142 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
143 | - define( 'WPINV_CHECKOUT', true ); |
|
142 | + if (!defined('WPINV_CHECKOUT')) { |
|
143 | + define('WPINV_CHECKOUT', true); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | wpinv_process_checkout(); |
@@ -149,53 +149,53 @@ discard block |
||
149 | 149 | |
150 | 150 | public static function add_invoice_item() { |
151 | 151 | global $wpi_userID, $wpinv_ip_address_country; |
152 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
153 | - if ( !current_user_can( 'manage_options' ) ) { |
|
152 | + check_ajax_referer('invoice-item', '_nonce'); |
|
153 | + if (!current_user_can('manage_options')) { |
|
154 | 154 | die(-1); |
155 | 155 | } |
156 | 156 | |
157 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
158 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
157 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
158 | + $invoice_id = absint($_POST['invoice_id']); |
|
159 | 159 | |
160 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
160 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
161 | 161 | die(); |
162 | 162 | } |
163 | 163 | |
164 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
165 | - if ( empty( $invoice ) ) { |
|
164 | + $invoice = wpinv_get_invoice($invoice_id); |
|
165 | + if (empty($invoice)) { |
|
166 | 166 | die(); |
167 | 167 | } |
168 | 168 | |
169 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
169 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
170 | 170 | die(); // Don't allow modify items for paid invoice. |
171 | 171 | } |
172 | 172 | |
173 | - if ( !empty( $_POST['user_id'] ) ) { |
|
174 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
173 | + if (!empty($_POST['user_id'])) { |
|
174 | + $wpi_userID = absint($_POST['user_id']); |
|
175 | 175 | } |
176 | 176 | |
177 | - $item = new WPInv_Item( $item_id ); |
|
178 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
177 | + $item = new WPInv_Item($item_id); |
|
178 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
179 | 179 | die(); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually. |
183 | - if ( !empty( $invoice->cart_details ) ) { |
|
183 | + if (!empty($invoice->cart_details)) { |
|
184 | 184 | $valid = true; |
185 | 185 | |
186 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
187 | - if ( $recurring_item != $item_id ) { |
|
186 | + if ($recurring_item = $invoice->get_recurring()) { |
|
187 | + if ($recurring_item != $item_id) { |
|
188 | 188 | $valid = false; |
189 | 189 | } |
190 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
190 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
191 | 191 | $valid = false; |
192 | 192 | } |
193 | 193 | |
194 | - if ( !$valid ) { |
|
194 | + if (!$valid) { |
|
195 | 195 | $response = array(); |
196 | 196 | $response['success'] = false; |
197 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
198 | - wp_send_json( $response ); |
|
197 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
198 | + wp_send_json($response); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | |
204 | 204 | $data = array(); |
205 | 205 | $data['invoice_id'] = $invoice_id; |
206 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
206 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
207 | 207 | |
208 | - wpinv_set_checkout_session( $data ); |
|
208 | + wpinv_set_checkout_session($data); |
|
209 | 209 | |
210 | 210 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
211 | 211 | |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | 'fees' => array() |
221 | 221 | ); |
222 | 222 | |
223 | - $invoice->add_item( $item_id, $args ); |
|
223 | + $invoice->add_item($item_id, $args); |
|
224 | 224 | $invoice->save(); |
225 | 225 | |
226 | - if ( empty( $_POST['country'] ) ) { |
|
226 | + if (empty($_POST['country'])) { |
|
227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
228 | 228 | } |
229 | - if ( empty( $_POST['state'] ) ) { |
|
229 | + if (empty($_POST['state'])) { |
|
230 | 230 | $_POST['state'] = $invoice->state; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
234 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
233 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
234 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
235 | 235 | |
236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
236 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
237 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
238 | 238 | |
239 | 239 | $wpinv_ip_address_country = $invoice->country; |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $response = array(); |
244 | 244 | $response['success'] = true; |
245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
248 | 248 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -254,40 +254,40 @@ discard block |
||
254 | 254 | |
255 | 255 | wpinv_set_checkout_session($checkout_session); |
256 | 256 | |
257 | - wp_send_json( $response ); |
|
257 | + wp_send_json($response); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | public static function remove_invoice_item() { |
261 | 261 | global $wpi_userID, $wpinv_ip_address_country; |
262 | 262 | |
263 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
264 | - if ( !current_user_can( 'manage_options' ) ) { |
|
263 | + check_ajax_referer('invoice-item', '_nonce'); |
|
264 | + if (!current_user_can('manage_options')) { |
|
265 | 265 | die(-1); |
266 | 266 | } |
267 | 267 | |
268 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
269 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
268 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
269 | + $invoice_id = absint($_POST['invoice_id']); |
|
270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
271 | 271 | |
272 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
272 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
273 | 273 | die(); |
274 | 274 | } |
275 | 275 | |
276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
277 | - if ( empty( $invoice ) ) { |
|
276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
277 | + if (empty($invoice)) { |
|
278 | 278 | die(); |
279 | 279 | } |
280 | 280 | |
281 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
281 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
282 | 282 | die(); // Don't allow modify items for paid invoice. |
283 | 283 | } |
284 | 284 | |
285 | - if ( !empty( $_POST['user_id'] ) ) { |
|
286 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
285 | + if (!empty($_POST['user_id'])) { |
|
286 | + $wpi_userID = absint($_POST['user_id']); |
|
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
290 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
291 | 291 | die(); |
292 | 292 | } |
293 | 293 | |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | |
296 | 296 | $data = array(); |
297 | 297 | $data['invoice_id'] = $invoice_id; |
298 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
298 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
299 | 299 | |
300 | - wpinv_set_checkout_session( $data ); |
|
300 | + wpinv_set_checkout_session($data); |
|
301 | 301 | |
302 | 302 | $args = array( |
303 | 303 | 'id' => $item_id, |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | 'cart_index' => $cart_index |
306 | 306 | ); |
307 | 307 | |
308 | - $invoice->remove_item( $item_id, $args ); |
|
308 | + $invoice->remove_item($item_id, $args); |
|
309 | 309 | $invoice->save(); |
310 | 310 | |
311 | - if ( empty( $_POST['country'] ) ) { |
|
311 | + if (empty($_POST['country'])) { |
|
312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
313 | 313 | } |
314 | - if ( empty( $_POST['state'] ) ) { |
|
314 | + if (empty($_POST['state'])) { |
|
315 | 315 | $_POST['state'] = $invoice->state; |
316 | 316 | } |
317 | 317 | |
318 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
319 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
318 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
319 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
320 | 320 | |
321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
321 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
322 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
323 | 323 | |
324 | 324 | $wpinv_ip_address_country = $invoice->country; |
325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $response = array(); |
329 | 329 | $response['success'] = true; |
330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
333 | 333 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -339,40 +339,40 @@ discard block |
||
339 | 339 | |
340 | 340 | wpinv_set_checkout_session($checkout_session); |
341 | 341 | |
342 | - wp_send_json( $response ); |
|
342 | + wp_send_json($response); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | public static function create_invoice_item() { |
346 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
347 | - if ( !current_user_can( 'manage_options' ) ) { |
|
346 | + check_ajax_referer('invoice-item', '_nonce'); |
|
347 | + if (!current_user_can('manage_options')) { |
|
348 | 348 | die(-1); |
349 | 349 | } |
350 | 350 | |
351 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
351 | + $invoice_id = absint($_POST['invoice_id']); |
|
352 | 352 | |
353 | 353 | // Find the item |
354 | - if ( !is_numeric( $invoice_id ) ) { |
|
354 | + if (!is_numeric($invoice_id)) { |
|
355 | 355 | die(); |
356 | 356 | } |
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - if ( empty( $invoice ) ) { |
|
358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
359 | + if (empty($invoice)) { |
|
360 | 360 | die(); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually. |
364 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
364 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
365 | 365 | $response = array(); |
366 | 366 | $response['success'] = false; |
367 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
368 | - wp_send_json( $response ); |
|
367 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
368 | + wp_send_json($response); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | $save_item = $_POST['_wpinv_quick']; |
372 | 372 | |
373 | 373 | $meta = array(); |
374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
378 | 378 | |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | $data['meta'] = $meta; |
383 | 383 | |
384 | 384 | $item = new WPInv_Item(); |
385 | - $item->create( $data ); |
|
385 | + $item->create($data); |
|
386 | 386 | |
387 | - if ( !empty( $item ) ) { |
|
387 | + if (!empty($item)) { |
|
388 | 388 | $_POST['item_id'] = $item->ID; |
389 | 389 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
390 | 390 | |
@@ -394,15 +394,15 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | public static function get_billing_details() { |
397 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
397 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
398 | 398 | |
399 | - if ( !current_user_can( 'manage_options' ) ) { |
|
399 | + if (!current_user_can('manage_options')) { |
|
400 | 400 | die(-1); |
401 | 401 | } |
402 | 402 | |
403 | 403 | $user_id = (int)$_POST['user_id']; |
404 | 404 | $billing_details = wpinv_get_user_address($user_id); |
405 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
405 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
406 | 406 | |
407 | 407 | if (isset($billing_details['user_id'])) { |
408 | 408 | unset($billing_details['user_id']); |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | $response['success'] = true; |
417 | 417 | $response['data']['billing_details'] = $billing_details; |
418 | 418 | |
419 | - wp_send_json( $response ); |
|
419 | + wp_send_json($response); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | public static function admin_recalculate_totals() { |
423 | 423 | global $wpi_userID, $wpinv_ip_address_country; |
424 | 424 | |
425 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
426 | - if ( !current_user_can( 'manage_options' ) ) { |
|
425 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
426 | + if (!current_user_can('manage_options')) { |
|
427 | 427 | die(-1); |
428 | 428 | } |
429 | 429 | |
430 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
431 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
432 | - if ( empty( $invoice ) ) { |
|
430 | + $invoice_id = absint($_POST['invoice_id']); |
|
431 | + $invoice = wpinv_get_invoice($invoice_id); |
|
432 | + if (empty($invoice)) { |
|
433 | 433 | die(); |
434 | 434 | } |
435 | 435 | |
@@ -437,23 +437,23 @@ discard block |
||
437 | 437 | |
438 | 438 | $data = array(); |
439 | 439 | $data['invoice_id'] = $invoice_id; |
440 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
440 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
441 | 441 | |
442 | - wpinv_set_checkout_session( $data ); |
|
442 | + wpinv_set_checkout_session($data); |
|
443 | 443 | |
444 | - if ( !empty( $_POST['user_id'] ) ) { |
|
445 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
444 | + if (!empty($_POST['user_id'])) { |
|
445 | + $wpi_userID = absint($_POST['user_id']); |
|
446 | 446 | } |
447 | 447 | |
448 | - if ( empty( $_POST['country'] ) ) { |
|
448 | + if (empty($_POST['country'])) { |
|
449 | 449 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
450 | 450 | } |
451 | 451 | |
452 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
453 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
454 | - if ( isset( $_POST['state'] ) ) { |
|
455 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
456 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
452 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
453 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
454 | + if (isset($_POST['state'])) { |
|
455 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
456 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | $wpinv_ip_address_country = $invoice->country; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | |
463 | 463 | $response = array(); |
464 | 464 | $response['success'] = true; |
465 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
465 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
466 | 466 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
467 | 467 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
468 | 468 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -474,25 +474,25 @@ discard block |
||
474 | 474 | |
475 | 475 | wpinv_set_checkout_session($checkout_session); |
476 | 476 | |
477 | - wp_send_json( $response ); |
|
477 | + wp_send_json($response); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | public static function admin_apply_discount() { |
481 | 481 | global $wpi_userID; |
482 | 482 | |
483 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
484 | - if ( !current_user_can( 'manage_options' ) ) { |
|
483 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
484 | + if (!current_user_can('manage_options')) { |
|
485 | 485 | die(-1); |
486 | 486 | } |
487 | 487 | |
488 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
489 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
490 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
488 | + $invoice_id = absint($_POST['invoice_id']); |
|
489 | + $discount_code = sanitize_text_field($_POST['code']); |
|
490 | + if (empty($invoice_id) || empty($discount_code)) { |
|
491 | 491 | die(); |
492 | 492 | } |
493 | 493 | |
494 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
495 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
494 | + $invoice = wpinv_get_invoice($invoice_id); |
|
495 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
496 | 496 | die(); |
497 | 497 | } |
498 | 498 | |
@@ -500,49 +500,49 @@ discard block |
||
500 | 500 | |
501 | 501 | $data = array(); |
502 | 502 | $data['invoice_id'] = $invoice_id; |
503 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
503 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
504 | 504 | |
505 | - wpinv_set_checkout_session( $data ); |
|
505 | + wpinv_set_checkout_session($data); |
|
506 | 506 | |
507 | 507 | $response = array(); |
508 | 508 | $response['success'] = false; |
509 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
509 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
510 | 510 | $response['data']['code'] = $discount_code; |
511 | 511 | |
512 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
513 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
512 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
513 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
514 | 514 | |
515 | 515 | $response['success'] = true; |
516 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
517 | - } else { |
|
516 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
517 | + } else { |
|
518 | 518 | $errors = wpinv_get_errors(); |
519 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
519 | + if (!empty($errors['wpinv-discount-error'])) { |
|
520 | 520 | $response['msg'] = $errors['wpinv-discount-error']; |
521 | 521 | } |
522 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
522 | + wpinv_unset_error('wpinv-discount-error'); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | wpinv_set_checkout_session($checkout_session); |
526 | 526 | |
527 | - wp_send_json( $response ); |
|
527 | + wp_send_json($response); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | public static function admin_remove_discount() { |
531 | 531 | global $wpi_userID; |
532 | 532 | |
533 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
534 | - if ( !current_user_can( 'manage_options' ) ) { |
|
533 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
534 | + if (!current_user_can('manage_options')) { |
|
535 | 535 | die(-1); |
536 | 536 | } |
537 | 537 | |
538 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
539 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
540 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
538 | + $invoice_id = absint($_POST['invoice_id']); |
|
539 | + $discount_code = sanitize_text_field($_POST['code']); |
|
540 | + if (empty($invoice_id) || empty($discount_code)) { |
|
541 | 541 | die(); |
542 | 542 | } |
543 | 543 | |
544 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
545 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
544 | + $invoice = wpinv_get_invoice($invoice_id); |
|
545 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
546 | 546 | die(); |
547 | 547 | } |
548 | 548 | |
@@ -550,38 +550,38 @@ discard block |
||
550 | 550 | |
551 | 551 | $data = array(); |
552 | 552 | $data['invoice_id'] = $invoice_id; |
553 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
553 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
554 | 554 | |
555 | - wpinv_set_checkout_session( $data ); |
|
555 | + wpinv_set_checkout_session($data); |
|
556 | 556 | |
557 | 557 | $response = array(); |
558 | 558 | $response['success'] = false; |
559 | 559 | $response['msg'] = NULL; |
560 | 560 | |
561 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
561 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
562 | 562 | $response['success'] = true; |
563 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
563 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
564 | 564 | |
565 | 565 | wpinv_set_checkout_session($checkout_session); |
566 | 566 | |
567 | - wp_send_json( $response ); |
|
567 | + wp_send_json($response); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | public static function check_email() { |
571 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
572 | - if ( !current_user_can( 'manage_options' ) ) { |
|
571 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
572 | + if (!current_user_can('manage_options')) { |
|
573 | 573 | die(-1); |
574 | 574 | } |
575 | 575 | |
576 | - $email = sanitize_text_field( $_POST['email'] ); |
|
576 | + $email = sanitize_text_field($_POST['email']); |
|
577 | 577 | |
578 | 578 | $response = array(); |
579 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
579 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
580 | 580 | $user_id = $user_data->ID; |
581 | 581 | $user_login = $user_data->user_login; |
582 | 582 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
583 | 583 | $billing_details = wpinv_get_user_address($user_id); |
584 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
584 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
585 | 585 | |
586 | 586 | if (isset($billing_details['user_id'])) { |
587 | 587 | unset($billing_details['user_id']); |
@@ -597,54 +597,54 @@ discard block |
||
597 | 597 | $response['data']['billing_details'] = $billing_details; |
598 | 598 | } |
599 | 599 | |
600 | - wp_send_json( $response ); |
|
600 | + wp_send_json($response); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | public static function run_tool() { |
604 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
605 | - if ( !current_user_can( 'manage_options' ) ) { |
|
604 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
605 | + if (!current_user_can('manage_options')) { |
|
606 | 606 | die(-1); |
607 | 607 | } |
608 | 608 | |
609 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
609 | + $tool = sanitize_text_field($_POST['tool']); |
|
610 | 610 | |
611 | - do_action( 'wpinv_run_tool' ); |
|
611 | + do_action('wpinv_run_tool'); |
|
612 | 612 | |
613 | - if ( !empty( $tool ) ) { |
|
614 | - do_action( 'wpinv_tool_' . $tool ); |
|
613 | + if (!empty($tool)) { |
|
614 | + do_action('wpinv_tool_' . $tool); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
618 | 618 | public static function apply_discount() { |
619 | 619 | global $wpi_userID; |
620 | 620 | |
621 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
621 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
622 | 622 | |
623 | 623 | $response = array(); |
624 | 624 | |
625 | - if ( isset( $_POST['code'] ) ) { |
|
626 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
625 | + if (isset($_POST['code'])) { |
|
626 | + $discount_code = sanitize_text_field($_POST['code']); |
|
627 | 627 | |
628 | 628 | $response['success'] = false; |
629 | 629 | $response['msg'] = ''; |
630 | 630 | $response['data']['code'] = $discount_code; |
631 | 631 | |
632 | 632 | $invoice = wpinv_get_invoice_cart(); |
633 | - if ( empty( $invoice->ID ) ) { |
|
634 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
635 | - wp_send_json( $response ); |
|
633 | + if (empty($invoice->ID)) { |
|
634 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
635 | + wp_send_json($response); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | $wpi_userID = $invoice->get_user_id(); |
639 | 639 | |
640 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
641 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
642 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
643 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
644 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
645 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
640 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
641 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
642 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
643 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
644 | + $total = wpinv_get_cart_total(null, $discounts); |
|
645 | + $cart_totals = wpinv_recalculate_tax(true); |
|
646 | 646 | |
647 | - if ( !empty( $cart_totals ) ) { |
|
647 | + if (!empty($cart_totals)) { |
|
648 | 648 | $response['success'] = true; |
649 | 649 | $response['data'] = $cart_totals; |
650 | 650 | $response['data']['code'] = $discount_code; |
@@ -653,29 +653,29 @@ discard block |
||
653 | 653 | } |
654 | 654 | } else { |
655 | 655 | $errors = wpinv_get_errors(); |
656 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
656 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | + wpinv_unset_error('wpinv-discount-error'); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Allow for custom discount code handling |
661 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
661 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
662 | 662 | } |
663 | 663 | |
664 | - wp_send_json( $response ); |
|
664 | + wp_send_json($response); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function remove_discount() { |
668 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
668 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
669 | 669 | |
670 | 670 | $response = array(); |
671 | 671 | |
672 | - if ( isset( $_POST['code'] ) ) { |
|
673 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
674 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
675 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
676 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
672 | + if (isset($_POST['code'])) { |
|
673 | + $discount_code = sanitize_text_field($_POST['code']); |
|
674 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
675 | + $total = wpinv_get_cart_total(null, $discounts); |
|
676 | + $cart_totals = wpinv_recalculate_tax(true); |
|
677 | 677 | |
678 | - if ( !empty( $cart_totals ) ) { |
|
678 | + if (!empty($cart_totals)) { |
|
679 | 679 | $response['success'] = true; |
680 | 680 | $response['data'] = $cart_totals; |
681 | 681 | $response['data']['code'] = $discount_code; |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | // Allow for custom discount code handling |
687 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
687 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
688 | 688 | } |
689 | 689 | |
690 | - wp_send_json( $response ); |
|
690 | + wp_send_json($response); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | |
@@ -699,53 +699,53 @@ discard block |
||
699 | 699 | public static function buy_items() { |
700 | 700 | $user_id = get_current_user_id(); |
701 | 701 | |
702 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
703 | - wp_send_json( array( |
|
704 | - 'success' => wp_login_url( wp_get_referer() ) |
|
705 | - ) ); |
|
702 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
703 | + wp_send_json(array( |
|
704 | + 'success' => wp_login_url(wp_get_referer()) |
|
705 | + )); |
|
706 | 706 | } else { |
707 | 707 | // Only check nonce if logged in as it could be cached when logged out. |
708 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
709 | - wp_send_json( array( |
|
710 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
711 | - ) ); |
|
708 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
709 | + wp_send_json(array( |
|
710 | + 'error' => __('Security checks failed.', 'invoicing') |
|
711 | + )); |
|
712 | 712 | wp_die(); |
713 | 713 | } |
714 | 714 | |
715 | 715 | // allow to set a custom price through post_id |
716 | 716 | $items = $_POST['items']; |
717 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
718 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
717 | + $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0; |
|
718 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
719 | 719 | |
720 | 720 | $cart_items = array(); |
721 | - if ( $items ) { |
|
722 | - $items = explode( ',', $items ); |
|
721 | + if ($items) { |
|
722 | + $items = explode(',', $items); |
|
723 | 723 | |
724 | - foreach( $items as $item ) { |
|
724 | + foreach ($items as $item) { |
|
725 | 725 | $item_id = $item; |
726 | 726 | $quantity = 1; |
727 | 727 | |
728 | - if ( strpos( $item, '|' ) !== false ) { |
|
729 | - $item_parts = explode( '|', $item ); |
|
728 | + if (strpos($item, '|') !== false) { |
|
729 | + $item_parts = explode('|', $item); |
|
730 | 730 | $item_id = $item_parts[0]; |
731 | 731 | $quantity = $item_parts[1]; |
732 | 732 | } |
733 | 733 | |
734 | - if ( $item_id && $quantity ) { |
|
734 | + if ($item_id && $quantity) { |
|
735 | 735 | $cart_items_arr = array( |
736 | 736 | 'id' => (int)$item_id, |
737 | 737 | 'quantity' => (int)$quantity |
738 | 738 | ); |
739 | 739 | |
740 | 740 | // If there is a related post id then add it to meta |
741 | - if ( $related_post_id ) { |
|
741 | + if ($related_post_id) { |
|
742 | 742 | $cart_items_arr['meta'] = array( |
743 | 743 | 'post_id' => $related_post_id |
744 | 744 | ); |
745 | 745 | } |
746 | 746 | |
747 | 747 | // If there is a custom price then set it. |
748 | - if ( $custom_item_price ) { |
|
748 | + if ($custom_item_price) { |
|
749 | 749 | $cart_items_arr['custom_price'] = $custom_item_price; |
750 | 750 | } |
751 | 751 | |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | * @param int $related_post_id The related post id if any. |
762 | 762 | * @since 1.0.0 |
763 | 763 | */ |
764 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
764 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
765 | 765 | |
766 | 766 | // Make sure its not in the cart already, if it is then redirect to checkout. |
767 | 767 | $cart_invoice = wpinv_get_invoice_cart(); |
768 | 768 | |
769 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
770 | - wp_send_json( array( |
|
769 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
770 | + wp_send_json(array( |
|
771 | 771 | 'success' => $cart_invoice->get_checkout_payment_url() |
772 | - ) ); |
|
772 | + )); |
|
773 | 773 | wp_die(); |
774 | 774 | } |
775 | 775 | |
776 | 776 | // Check if user has invoice with same items waiting to be paid. |
777 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
778 | - if ( !empty( $user_invoices ) ) { |
|
779 | - foreach( $user_invoices as $user_invoice ) { |
|
777 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
778 | + if (!empty($user_invoices)) { |
|
779 | + foreach ($user_invoices as $user_invoice) { |
|
780 | 780 | $user_cart_details = array(); |
781 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
781 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
782 | 782 | $cart_details = $invoice->get_cart_details(); |
783 | 783 | |
784 | - if ( !empty( $cart_details ) ) { |
|
785 | - foreach ( $cart_details as $invoice_item ) { |
|
784 | + if (!empty($cart_details)) { |
|
785 | + foreach ($cart_details as $invoice_item) { |
|
786 | 786 | $ii_arr = array(); |
787 | 787 | $ii_arr['id'] = (int)$invoice_item['id']; |
788 | 788 | $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
789 | 789 | |
790 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
790 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
791 | 791 | $ii_arr['meta'] = $invoice_item['meta']; |
792 | 792 | } |
793 | 793 | |
794 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
794 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
795 | 795 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
796 | 796 | } |
797 | 797 | |
@@ -799,17 +799,17 @@ discard block |
||
799 | 799 | } |
800 | 800 | } |
801 | 801 | |
802 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
803 | - wp_send_json( array( |
|
802 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
803 | + wp_send_json(array( |
|
804 | 804 | 'success' => $invoice->get_checkout_payment_url() |
805 | - ) ); |
|
805 | + )); |
|
806 | 806 | wp_die(); |
807 | 807 | } |
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | 811 | // Create invoice and send user to checkout |
812 | - if ( !empty( $cart_items ) ) { |
|
812 | + if (!empty($cart_items)) { |
|
813 | 813 | $invoice_data = array( |
814 | 814 | 'status' => 'wpi-pending', |
815 | 815 | 'created_via' => 'wpi', |
@@ -817,21 +817,21 @@ discard block |
||
817 | 817 | 'cart_details' => $cart_items, |
818 | 818 | ); |
819 | 819 | |
820 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
820 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
821 | 821 | |
822 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
823 | - wp_send_json( array( |
|
822 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
823 | + wp_send_json(array( |
|
824 | 824 | 'success' => $invoice->get_checkout_payment_url() |
825 | - ) ); |
|
825 | + )); |
|
826 | 826 | } else { |
827 | - wp_send_json( array( |
|
828 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
829 | - ) ); |
|
827 | + wp_send_json(array( |
|
828 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
829 | + )); |
|
830 | 830 | } |
831 | 831 | } else { |
832 | - wp_send_json( array( |
|
833 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
834 | - ) ); |
|
832 | + wp_send_json(array( |
|
833 | + 'error' => __('Items not valid.', 'invoicing') |
|
834 | + )); |
|
835 | 835 | } |
836 | 836 | } |
837 | 837 |